@@ -1701,6 +1701,17 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(BasicBlock *BB,
1701
1701
auto OtherSuccIterPairRange =
1702
1702
iterator_range (SuccIterPairBegin, SuccIterPairs.end ());
1703
1703
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
+
1704
1715
bool HasIdenticalInst = true ;
1705
1716
1706
1717
// Check if there are identical instructions in all other successors
@@ -1835,7 +1846,7 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(BasicBlock *BB,
1835
1846
unsigned index = 0 ;
1836
1847
for (auto &PrevHash : PrevHashCodes) {
1837
1848
auto NewHash = getHash (PrevUsers[index]);
1838
- std::swap ( map[ NewHash] , map[PrevHash]);
1849
+ map. insert ({ NewHash, map[PrevHash]} );
1839
1850
map.erase (PrevHash);
1840
1851
index++;
1841
1852
}
@@ -1887,11 +1898,8 @@ bool SimplifyCFGOpt::hoistSuccIdenticalTerminatorToSwitchOrIf(
1887
1898
// Use only for an if statement.
1888
1899
auto *I2 = *OtherSuccTIs.begin ();
1889
1900
auto *BB2 = I2->getParent ();
1890
- if (BI) {
1901
+ if (BI)
1891
1902
assert (OtherSuccTIs.size () == 1 );
1892
- assert (BI->getSuccessor (0 ) == I1->getParent ());
1893
- assert (BI->getSuccessor (1 ) == I2->getParent ());
1894
- }
1895
1903
1896
1904
// In the case of an if statement, we try to hoist an invoke.
1897
1905
// FIXME: Can we define a safety predicate for CallBr?
@@ -1911,6 +1919,7 @@ bool SimplifyCFGOpt::hoistSuccIdenticalTerminatorToSwitchOrIf(
1911
1919
Value *BB2V = PN.getIncomingValueForBlock (OtherSuccTI->getParent ());
1912
1920
if (BB1V == BB2V)
1913
1921
continue ;
1922
+
1914
1923
// In the case of an if statement, check for
1915
1924
// passingValueIsAlwaysUndefined here because we would rather eliminate
1916
1925
// undefined control flow then converting it to a select.
@@ -3747,6 +3756,7 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
3747
3756
// Change the PHI node into a select instruction.
3748
3757
Value *TrueVal = PN->getIncomingValueForBlock (IfTrue);
3749
3758
Value *FalseVal = PN->getIncomingValueForBlock (IfFalse);
3759
+
3750
3760
Value *Sel = Builder.CreateSelect (IfCond, TrueVal, FalseVal, " " , DomBI);
3751
3761
PN->replaceAllUsesWith (Sel);
3752
3762
Sel->takeName (PN);
0 commit comments