[llvm] 5a327f3 - Revert "[NFC] Move code between functions as a preparation step for further improvement"

David Zarzycki via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 13 07:53:01 PST 2020


Author: David Zarzycki
Date: 2020-11-13T10:52:49-05:00
New Revision: 5a327f333763e164817a4e8318d9ab829a8f9246

URL: https://github.com/llvm/llvm-project/commit/5a327f333763e164817a4e8318d9ab829a8f9246
DIFF: https://github.com/llvm/llvm-project/commit/5a327f333763e164817a4e8318d9ab829a8f9246.diff

LOG: Revert "[NFC] Move code between functions as a preparation step for further improvement"

This reverts commit 08016ac32b746b27be43d92255bf22a12012e244.

A bunch of tests are failing my local two stage builder.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index 55993c0a1513..cc8a9976c303 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -1303,17 +1303,41 @@ enum ExitCondAnalysisResult {
 /// output parameters and return CanBeReplacedWithInvariant.
 /// Otherwise, return CannotOptimize.
 static ExitCondAnalysisResult
-analyzeCond(const Loop *L, ICmpInst::Predicate Pred, const SCEV *LHSS,
-            const SCEV *RHSS, BranchInst *Context, ScalarEvolution *SE,
-            const SCEV *MaxIter, ICmpInst::Predicate &InvariantPred,
-            const SCEV *&InvariantLHS, const SCEV *&InvariantRHS) {
+analyzeCond(const Loop *L, BranchInst *BI, ScalarEvolution *SE,
+            bool ProvingLoopExit, const SCEV *MaxIter,
+            ICmpInst::Predicate &InvariantPred, const SCEV *&InvariantLHS,
+            const SCEV *&InvariantRHS) {
+  ICmpInst::Predicate Pred;
+  Value *LHS, *RHS;
+  using namespace PatternMatch;
+  BasicBlock *TrueSucc, *FalseSucc;
+  if (!match(BI, m_Br(m_ICmp(Pred, m_Value(LHS), m_Value(RHS)),
+                      m_BasicBlock(TrueSucc), m_BasicBlock(FalseSucc))))
+    return CannotOptimize;
+
+  assert((L->contains(TrueSucc) != L->contains(FalseSucc)) &&
+         "Not a loop exit!");
+
+  // 'LHS pred RHS' should now mean that we stay in loop.
+  if (L->contains(FalseSucc))
+    Pred = CmpInst::getInversePredicate(Pred);
+
+  // If we are proving loop exit, invert the predicate.
+  if (ProvingLoopExit)
+    Pred = CmpInst::getInversePredicate(Pred);
+
+  const SCEV *LHSS = SE->getSCEVAtScope(LHS, L);
+  const SCEV *RHSS = SE->getSCEVAtScope(RHS, L);
   // Can we prove it to be trivially true?
-  if (SE->isKnownPredicateAt(Pred, LHSS, RHSS, Context))
+  if (SE->isKnownPredicateAt(Pred, LHSS, RHSS, BI))
     return CanBeRemoved;
 
+  if (ProvingLoopExit)
+    return CannotOptimize;
+
   // Check if there is a loop-invariant predicate equivalent to our check.
-  auto LIP = SE->getLoopInvariantExitCondDuringFirstIterations(
-      Pred, LHSS, RHSS, L, Context, MaxIter);
+  auto LIP = SE->getLoopInvariantExitCondDuringFirstIterations(Pred, LHSS, RHSS,
+                                                               L, BI, MaxIter);
   if (!LIP)
     return CannotOptimize;
   InvariantPred = LIP->Pred;
@@ -1321,8 +1345,7 @@ analyzeCond(const Loop *L, ICmpInst::Predicate Pred, const SCEV *LHSS,
   InvariantRHS = LIP->RHS;
 
   // Can we prove it to be trivially true?
-  if (SE->isKnownPredicateAt(InvariantPred, InvariantLHS, InvariantRHS,
-                             Context))
+  if (SE->isKnownPredicateAt(InvariantPred, InvariantLHS, InvariantRHS, BI))
     return CanBeRemoved;
   return CanBeReplacedWithInvariant;
 }
@@ -1367,36 +1390,14 @@ static bool optimizeLoopExitWithUnknownExitCount(
     const SCEV *MaxIter, bool Inverted, bool SkipLastIter,
     ScalarEvolution *SE, SCEVExpander &Rewriter,
     SmallVectorImpl<WeakTrackingVH> &DeadInsts) {
-  ICmpInst::Predicate Pred;
-  Value *LHS, *RHS;
-  using namespace PatternMatch;
-  BasicBlock *TrueSucc, *FalseSucc;
-  if (!match(BI, m_Br(m_ICmp(Pred, m_Value(LHS), m_Value(RHS)),
-                      m_BasicBlock(TrueSucc), m_BasicBlock(FalseSucc))))
-    return false;
-
-  assert((L->contains(TrueSucc) != L->contains(FalseSucc)) &&
-         "Not a loop exit!");
-
-  // 'LHS pred RHS' should now mean that we stay in loop.
-  if (L->contains(FalseSucc))
-    Pred = CmpInst::getInversePredicate(Pred);
-
-  // If we are proving loop exit, invert the predicate.
-  if (Inverted)
-    Pred = CmpInst::getInversePredicate(Pred);
-
-  const SCEV *LHSS = SE->getSCEVAtScope(LHS, L);
-  const SCEV *RHSS = SE->getSCEVAtScope(RHS, L);
-
   if (SkipLastIter) {
     const SCEV *One = SE->getOne(MaxIter->getType());
     MaxIter = SE->getMinusSCEV(MaxIter, One);
   }
   ICmpInst::Predicate InvariantPred;
   const SCEV *InvariantLHS, *InvariantRHS;
-  switch (analyzeCond(L, Pred, LHSS, RHSS, BI, SE, MaxIter, InvariantPred,
-                      InvariantLHS, InvariantRHS)) {
+  switch (analyzeCond(L, BI, SE, Inverted, MaxIter, InvariantPred, InvariantLHS,
+                      InvariantRHS)) {
   case CanBeRemoved:
     foldExit(L, ExitingBB, Inverted, DeadInsts);
     return true;


        


More information about the llvm-commits mailing list