@@ -293,7 +293,7 @@ static bool canProveExitOnFirstIteration(Loop *L, DominatorTree &DT,
293
293
using namespace PatternMatch ;
294
294
ICmpInst::Predicate Pred;
295
295
Value *LHS, *RHS;
296
- const BasicBlock *IfTrue, *IfFalse;
296
+ BasicBlock *IfTrue, *IfFalse;
297
297
auto *Term = BB->getTerminator ();
298
298
// TODO: Handle switches.
299
299
if (!match (Term, m_Br (m_ICmp (Pred, m_Value (LHS), m_Value (RHS)),
@@ -316,13 +316,12 @@ static bool canProveExitOnFirstIteration(Loop *L, DominatorTree &DT,
316
316
// in-loop.
317
317
// TODO: isKnownPredicateAt is more powerful, but it's too compile time
318
318
// consuming. So we avoid using it here.
319
- if (L->contains (Term->getSuccessor (1 )) &&
320
- SE.isKnownPredicate (Pred, LHSS, RHSS))
321
- MarkLiveEdge (BB, Term->getSuccessor (0 ));
322
- else if (L->contains (Term->getSuccessor (0 )) &&
319
+ if (L->contains (IfFalse) && SE.isKnownPredicate (Pred, LHSS, RHSS))
320
+ MarkLiveEdge (BB, IfTrue);
321
+ else if (L->contains (IfTrue) &&
323
322
SE.isKnownPredicate (ICmpInst::getInversePredicate (Pred), LHSS,
324
323
RHSS))
325
- MarkLiveEdge (BB, Term-> getSuccessor ( 1 ) );
324
+ MarkLiveEdge (BB, IfFalse );
326
325
else
327
326
MarkAllSuccessorsLive (BB);
328
327
}
0 commit comments