Revert "[NFC] Reuse existing variables instead of re-requesting successors"
authorStefan Pintilie <stefanp@ca.ibm.com>
Fri, 28 May 2021 16:33:45 +0000 (11:33 -0500)
committerStefan Pintilie <stefanp@ca.ibm.com>
Fri, 28 May 2021 17:21:22 +0000 (12:21 -0500)
This reverts commit c467585682dcdda75e645ef3ab47c8b48440db12.

llvm/lib/Transforms/Scalar/LoopDeletion.cpp

index acc2056..cd2a3fc 100644 (file)
@@ -266,7 +266,7 @@ static bool canProveExitOnFirstIteration(Loop *L, DominatorTree &DT,
     using namespace PatternMatch;
     ICmpInst::Predicate Pred;
     Value *LHS, *RHS;
-    BasicBlock *IfTrue, *IfFalse;
+    const BasicBlock *IfTrue, *IfFalse;
     auto *Term = BB->getTerminator();
     // TODO: Handle switches.
     if (!match(Term, m_Br(m_ICmp(Pred, m_Value(LHS), m_Value(RHS)),
@@ -287,12 +287,13 @@ static bool canProveExitOnFirstIteration(Loop *L, DominatorTree &DT,
     // in-loop.
     // TODO: isKnownPredicateAt is more powerful, but it's too compile time
     // consuming. So we avoid using it here.
-    if (L->contains(IfFalse) && SE.isKnownPredicate(Pred, LHSS, RHSS))
-      MarkLiveEdge(BB, IfTrue);
-    else if (L->contains(IfTrue) &&
+    if (L->contains(Term->getSuccessor(1)) &&
+        SE.isKnownPredicate(Pred, LHSS, RHSS))
+      MarkLiveEdge(BB, Term->getSuccessor(0));
+    else if (L->contains(Term->getSuccessor(0)) &&
              SE.isKnownPredicate(ICmpInst::getInversePredicate(Pred), LHSS,
                                  RHSS))
-      MarkLiveEdge(BB, IfFalse);
+      MarkLiveEdge(BB, Term->getSuccessor(1));
     else
       MarkAllSuccessorsLive(BB);
   }