Skip to content

Commit 1982871

Browse files
Fix bugs.
1 parent 6c33af2 commit 1982871

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,17 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(BasicBlock *BB,
17011701
auto OtherSuccIterPairRange =
17021702
iterator_range(SuccIterPairBegin, SuccIterPairs.end());
17031703
Instruction *I1 = &*BB1ItrPair.first;
1704+
1705+
// Skip debug info if it is not identical.
1706+
bool IdenticalDebugs = all_of(OtherSuccIterRange, [I1](auto &Iter) {
1707+
Instruction *I2 = &*Iter;
1708+
return I1->isIdenticalToWhenDefined(I2);
1709+
});
1710+
if (!IdenticalDebugs) {
1711+
while (isa<DbgInfoIntrinsic>(I1))
1712+
I1 = &*++BB1ItrPair.first;
1713+
}
1714+
17041715
bool HasIdenticalInst = true;
17051716

17061717
// Check if there are identical instructions in all other successors
@@ -1835,7 +1846,7 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(BasicBlock *BB,
18351846
unsigned index = 0;
18361847
for (auto &PrevHash : PrevHashCodes) {
18371848
auto NewHash = getHash(PrevUsers[index]);
1838-
std::swap(map[NewHash], map[PrevHash]);
1849+
map.insert({NewHash, map[PrevHash]});
18391850
map.erase(PrevHash);
18401851
index++;
18411852
}
@@ -1887,11 +1898,8 @@ bool SimplifyCFGOpt::hoistSuccIdenticalTerminatorToSwitchOrIf(
18871898
// Use only for an if statement.
18881899
auto *I2 = *OtherSuccTIs.begin();
18891900
auto *BB2 = I2->getParent();
1890-
if (BI) {
1901+
if (BI)
18911902
assert(OtherSuccTIs.size() == 1);
1892-
assert(BI->getSuccessor(0) == I1->getParent());
1893-
assert(BI->getSuccessor(1) == I2->getParent());
1894-
}
18951903

18961904
// In the case of an if statement, we try to hoist an invoke.
18971905
// FIXME: Can we define a safety predicate for CallBr?
@@ -1911,6 +1919,7 @@ bool SimplifyCFGOpt::hoistSuccIdenticalTerminatorToSwitchOrIf(
19111919
Value *BB2V = PN.getIncomingValueForBlock(OtherSuccTI->getParent());
19121920
if (BB1V == BB2V)
19131921
continue;
1922+
19141923
// In the case of an if statement, check for
19151924
// passingValueIsAlwaysUndefined here because we would rather eliminate
19161925
// undefined control flow then converting it to a select.
@@ -3747,6 +3756,7 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
37473756
// Change the PHI node into a select instruction.
37483757
Value *TrueVal = PN->getIncomingValueForBlock(IfTrue);
37493758
Value *FalseVal = PN->getIncomingValueForBlock(IfFalse);
3759+
37503760
Value *Sel = Builder.CreateSelect(IfCond, TrueVal, FalseVal, "", DomBI);
37513761
PN->replaceAllUsesWith(Sel);
37523762
Sel->takeName(PN);

0 commit comments

Comments
 (0)