@@ -593,11 +593,14 @@ static bool cmpExcludesZero(CmpInst::Predicate Pred, const Value *RHS) {
593
593
}
594
594
595
595
static void breakSelfRecursivePHI (const Use *U, const PHINode *PHI,
596
- Value *&ValOut, Instruction *&CtxIOut) {
596
+ Value *&ValOut, Instruction *&CtxIOut,
597
+ const PHINode **PhiOut = nullptr ) {
597
598
ValOut = U->get ();
598
599
if (ValOut == PHI)
599
600
return ;
600
601
CtxIOut = PHI->getIncomingBlock (*U)->getTerminator ();
602
+ if (PhiOut)
603
+ *PhiOut = PHI;
601
604
Value *V;
602
605
// If the Use is a select of this phi, compute analysis on other arm to break
603
606
// recursion.
@@ -610,11 +613,13 @@ static void breakSelfRecursivePHI(const Use *U, const PHINode *PHI,
610
613
// incoming value to break recursion.
611
614
// TODO: We could handle any number of incoming edges as long as we only have
612
615
// two unique values.
613
- else if (auto *IncPhi = dyn_cast<PHINode>(ValOut);
616
+ if (auto *IncPhi = dyn_cast<PHINode>(ValOut);
614
617
IncPhi && IncPhi->getNumIncomingValues () == 2 ) {
615
618
for (int Idx = 0 ; Idx < 2 ; ++Idx) {
616
619
if (IncPhi->getIncomingValue (Idx) == PHI) {
617
620
ValOut = IncPhi->getIncomingValue (1 - Idx);
621
+ if (PhiOut)
622
+ *PhiOut = IncPhi;
618
623
CtxIOut = IncPhi->getIncomingBlock (1 - Idx)->getTerminator ();
619
624
break ;
620
625
}
@@ -1673,8 +1678,9 @@ static void computeKnownBitsFromOperator(const Operator *I,
1673
1678
Known.One .setAllBits ();
1674
1679
for (const Use &U : P->operands ()) {
1675
1680
Value *IncValue;
1681
+ const PHINode *CxtPhi;
1676
1682
Instruction *CxtI;
1677
- breakSelfRecursivePHI (&U, P, IncValue, CxtI);
1683
+ breakSelfRecursivePHI (&U, P, IncValue, CxtI, &CxtPhi );
1678
1684
// Skip direct self references.
1679
1685
if (IncValue == P)
1680
1686
continue ;
@@ -1705,9 +1711,10 @@ static void computeKnownBitsFromOperator(const Operator *I,
1705
1711
m_Br (m_c_ICmp (Pred, m_Specific (IncValue), m_APInt (RHSC)),
1706
1712
m_BasicBlock (TrueSucc), m_BasicBlock (FalseSucc)))) {
1707
1713
// Check for cases of duplicate successors.
1708
- if ((TrueSucc == P->getParent ()) != (FalseSucc == P->getParent ())) {
1714
+ if ((TrueSucc == CxtPhi->getParent ()) !=
1715
+ (FalseSucc == CxtPhi->getParent ())) {
1709
1716
// If we're using the false successor, invert the predicate.
1710
- if (FalseSucc == P ->getParent ())
1717
+ if (FalseSucc == CxtPhi ->getParent ())
1711
1718
Pred = CmpInst::getInversePredicate (Pred);
1712
1719
// Get the knownbits implied by the incoming phi condition.
1713
1720
auto CR = ConstantRange::makeExactICmpRegion (Pred, *RHSC);
0 commit comments