llvm.org GIT mirror llvm / 1b53749
[LICM] Adjust how moving the re-hoist point works In some cases the order that we hoist instructions in means that when rehoisting (which uses the same order as hoisting) we can rehoist to a block A, then a block B, then block A again. This currently causes an assertion failure as it expects that when changing the hoist point it only ever moves to a block that dominates the hoist point being moved from. Fix this by moving the re-hoist point when it doesn't dominate the dominator of hoisted instruction, or in other words when it wouldn't dominate the uses of the instruction being rehoisted. Differential Revision: https://reviews.llvm.org/D55266 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350408 91177308-0d34-0410-b5e6-96231b3b80d8 John Brawn 8 months ago
2 changed file(s) with 168 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
808808 [&](Use &U) { return DT->dominates(I, U); })) {
809809 BasicBlock *Dominator =
810810 DT->getNode(I->getParent())->getIDom()->getBlock();
811 LLVM_DEBUG(dbgs() << "LICM rehoisting to " << Dominator->getName()
812 << ": " << *I << "\n");
813 if (!HoistPoint || HoistPoint->getParent() != Dominator) {
811 if (!HoistPoint || !DT->dominates(HoistPoint->getParent(), Dominator)) {
814812 if (HoistPoint)
815813 assert(DT->dominates(Dominator, HoistPoint->getParent()) &&
816814 "New hoist point expected to dominate old hoist point");
817815 HoistPoint = Dominator->getTerminator();
818816 }
817 LLVM_DEBUG(dbgs() << "LICM rehoisting to "
818 << HoistPoint->getParent()->getName()
819 << ": " << *I << "\n");
819820 moveInstructionBefore(*I, *HoistPoint, *SafetyInfo);
820821 HoistPoint = I;
821822 Changed = true;
13481348 loop.backedge:
13491349 br label %loop
13501350 }
1351
1352 ; The order that we hoist instructions from the loop is different to the textual
1353 ; order in the function. Check that we can rehoist this correctly.
1354 ; CHECK-LABEL: @rehoist_wrong_order_1
1355 define void @rehoist_wrong_order_1(i32* %ptr) {
1356 ; CHECK-LABEL: entry
1357 ; CHECK-DAG: %gep2 = getelementptr inbounds i32, i32* %ptr, i64 2
1358 ; CHECK-DAG: %gep3 = getelementptr inbounds i32, i32* %ptr, i64 3
1359 ; CHECK-DAG: %gep1 = getelementptr inbounds i32, i32* %ptr, i64 1
1360 ; CHECK-ENABLED: br i1 undef, label %[[IF1_LICM:.*]], label %[[ELSE1_LICM:.*]]
1361 entry:
1362 br label %loop
1363
1364 ; CHECK-ENABLED: [[IF1_LICM]]:
1365 ; CHECK-ENABLED: br label %[[LOOP_BACKEDGE_LICM:.*]]
1366
1367 ; CHECK-ENABLED: [[ELSE1_LICM]]:
1368 ; CHECK-ENABLED: br label %[[LOOP_BACKEDGE_LICM]]
1369
1370 ; CHECK-ENABLED: [[LOOP_BACKEDGE_LICM]]:
1371 ; CHECK-ENABLED: br i1 undef, label %[[IF3_LICM:.*]], label %[[END_LICM:.*]]
1372
1373 ; CHECK-ENABLED: [[IF3_LICM]]:
1374 ; CHECK-ENABLED: br label %[[END_LICM]]
1375
1376 ; CHECK-ENABLED: [[END_LICM]]:
1377 ; CHECK: br label %loop
1378
1379 loop:
1380 br i1 undef, label %if1, label %else1
1381
1382 if1:
1383 %gep1 = getelementptr inbounds i32, i32* %ptr, i64 1
1384 store i32 0, i32* %gep1, align 4
1385 br label %loop.backedge
1386
1387 else1:
1388 %gep2 = getelementptr inbounds i32, i32* %ptr, i64 2
1389 store i32 0, i32* %gep2, align 4
1390 br i1 undef, label %if2, label %loop.backedge
1391
1392 if2:
1393 br i1 undef, label %if3, label %end
1394
1395 if3:
1396 %gep3 = getelementptr inbounds i32, i32* %ptr, i64 3
1397 store i32 0, i32* %gep3, align 4
1398 br label %end
1399
1400 end:
1401 br label %loop.backedge
1402
1403 loop.backedge:
1404 br label %loop
1405
1406 }
1407
1408 ; CHECK-LABEL: @rehoist_wrong_order_2
1409 define void @rehoist_wrong_order_2(i32* %ptr) {
1410 ; CHECK-LABEL: entry
1411 ; CHECK-DAG: %gep2 = getelementptr inbounds i32, i32* %ptr, i64 2
1412 ; CHECK-DAG: %gep3 = getelementptr inbounds i32, i32* %gep2, i64 3
1413 ; CHECK-DAG: %gep1 = getelementptr inbounds i32, i32* %ptr, i64 1
1414 ; CHECK-ENABLED: br i1 undef, label %[[IF1_LICM:.*]], label %[[ELSE1_LICM:.*]]
1415 entry:
1416 br label %loop
1417
1418 ; CHECK-ENABLED: [[IF1_LICM]]:
1419 ; CHECK-ENABLED: br label %[[LOOP_BACKEDGE_LICM:.*]]
1420
1421 ; CHECK-ENABLED: [[ELSE1_LICM]]:
1422 ; CHECK-ENABLED: br label %[[LOOP_BACKEDGE_LICM]]
1423
1424 ; CHECK-ENABLED: [[LOOP_BACKEDGE_LICM]]:
1425 ; CHECK-ENABLED: br i1 undef, label %[[IF3_LICM:.*]], label %[[END_LICM:.*]]
1426
1427 ; CHECK-ENABLED: [[IF3_LICM]]:
1428 ; CHECK-ENABLED: br label %[[END_LICM]]
1429
1430 ; CHECK-ENABLED: [[END_LICM]]:
1431 ; CHECK: br label %loop
1432
1433 loop:
1434 br i1 undef, label %if1, label %else1
1435
1436 if1:
1437 %gep1 = getelementptr inbounds i32, i32* %ptr, i64 1
1438 store i32 0, i32* %gep1, align 4
1439 br label %loop.backedge
1440
1441 else1:
1442 %gep2 = getelementptr inbounds i32, i32* %ptr, i64 2
1443 store i32 0, i32* %gep2, align 4
1444 br i1 undef, label %if2, label %loop.backedge
1445
1446 if2:
1447 br i1 undef, label %if3, label %end
1448
1449 if3:
1450 %gep3 = getelementptr inbounds i32, i32* %gep2, i64 3
1451 store i32 0, i32* %gep3, align 4
1452 br label %end
1453
1454 end:
1455 br label %loop.backedge
1456
1457 loop.backedge:
1458 br label %loop
1459 }
1460
1461 ; CHECK-LABEL: @rehoist_wrong_order_3
1462 define void @rehoist_wrong_order_3(i32* %ptr) {
1463 ; CHECK-LABEL: entry
1464 ; CHECK-DAG: %gep2 = getelementptr inbounds i32, i32* %ptr, i64 2
1465 ; CHECK-DAG: %gep1 = getelementptr inbounds i32, i32* %ptr, i64 1
1466 ; CHECK-ENABLED: br i1 undef, label %[[IF1_LICM:.*]], label %[[ELSE1_LICM:.*]]
1467 entry:
1468 br label %loop
1469
1470 ; CHECK-ENABLED: [[IF1_LICM]]:
1471 ; CHECK-ENABLED: br label %[[IF2_LICM:.*]]
1472
1473 ; CHECK-ENABLED: [[ELSE1_LICM]]:
1474 ; CHECK-ENABLED: br label %[[IF2_LICM]]
1475
1476 ; CHECK-ENABLED: [[IF2_LICM]]:
1477 ; CHECK-ENABLED: %phi = phi i32* [ %gep1, %[[IF1_LICM]] ], [ %gep2, %[[ELSE1_LICM]] ]
1478 ; CHECK-ENABLED: %gep3 = getelementptr inbounds i32, i32* %phi, i64 3
1479 ; CHECK-ENABLED: br i1 undef, label %[[IF3_LICM:.*]], label %[[END_LICM:.*]]
1480
1481 ; CHECK-ENABLED: [[IF3_LICM]]:
1482 ; CHECK-ENABLED: br label %[[END_LICM]]
1483
1484 ; CHECK-ENABLED: [[END_LICM]]:
1485 ; CHECK: br label %loop
1486
1487 loop:
1488 br i1 undef, label %if1, label %else1
1489
1490 if1:
1491 %gep1 = getelementptr inbounds i32, i32* %ptr, i64 1
1492 store i32 0, i32* %gep1, align 4
1493 br label %if2
1494
1495 else1:
1496 %gep2 = getelementptr inbounds i32, i32* %ptr, i64 2
1497 store i32 0, i32* %gep2, align 4
1498 br i1 undef, label %if2, label %loop.backedge
1499
1500 if2:
1501 %phi = phi i32* [ %gep1, %if1 ], [ %gep2, %else1 ]
1502 br i1 undef, label %if3, label %end
1503
1504 if3:
1505 %gep3 = getelementptr inbounds i32, i32* %phi, i64 3
1506 store i32 0, i32* %gep3, align 4
1507 br label %end
1508
1509 end:
1510 br label %loop.backedge
1511
1512 loop.backedge:
1513 br label %loop
1514 }