[llvm] 734abba - [SCEV] Defer all work from ea12c2cb as late as possible

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 18 17:19:59 PST 2021


Author: Philip Reames
Date: 2021-11-18T17:19:52-08:00
New Revision: 734abbad79dbcbd0e880510fbab1ef0e701cfc7b

URL: https://github.com/llvm/llvm-project/commit/734abbad79dbcbd0e880510fbab1ef0e701cfc7b
DIFF: https://github.com/llvm/llvm-project/commit/734abbad79dbcbd0e880510fbab1ef0e701cfc7b.diff

LOG: [SCEV] Defer all work from ea12c2cb as late as possible

This is a second speculative compile time optimization to address a reported regression.  My actual suspicion is that availability of no-self-wrap is making some *other* bit of code trigger, but let's rule this out.

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index adc4540bb2b7d..40bd1b593560e 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -8321,12 +8321,13 @@ ScalarEvolution::computeExitLimitFromICmp(const Loop *L,
   // the same values on self-wrap of the IV, then we can infer that IV
   // doesn't self wrap because if it did, we'd have an infinite (undefined)
   // loop.
-  if (ControlsExit && isLoopInvariant(RHS, L)) {
+  if (ControlsExit) {
     auto deferredLoopProperties = [&]() {
       // Conceptually, these two checks should be in the immediately guarding
       // if clause, but we defer their actual execution to after the cheaper
       // checks have all been done.
-      return loopHasNoAbnormalExits(L) && loopIsFiniteByAssumption(L);
+      return isLoopInvariant(RHS, L) && loopHasNoAbnormalExits(L) &&
+        loopIsFiniteByAssumption(L);
     };
 
     // TODO: We can peel off any functions which are invertible *in L*.  Loop
@@ -8335,15 +8336,16 @@ ScalarEvolution::computeExitLimitFromICmp(const Loop *L,
     if (auto *ZExt = dyn_cast<SCEVZeroExtendExpr>(LHS))
       InnerLHS = ZExt->getOperand();
     if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(InnerLHS)) {
-      auto *StrideC = dyn_cast<SCEVConstant>(AR->getStepRecurrence(*this));
-      if (!AR->hasNoSelfWrap() && AR->getLoop() == L && AR->isAffine() && 
-          StrideC && StrideC->getAPInt().isPowerOf2() &&
-          deferredLoopProperties()) {
-        auto Flags = AR->getNoWrapFlags();
-        Flags = setFlags(Flags, SCEV::FlagNW);
-        SmallVector<const SCEV*> Operands{AR->operands()};
-        Flags = StrengthenNoWrapFlags(this, scAddRecExpr, Operands, Flags);
-        setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), Flags);
+      if (!AR->hasNoSelfWrap() && AR->getLoop() == L && AR->isAffine()) {
+        auto *StrideC = dyn_cast<SCEVConstant>(AR->getStepRecurrence(*this));
+        if (StrideC && StrideC->getAPInt().isPowerOf2() &&
+            deferredLoopProperties()) {
+          auto Flags = AR->getNoWrapFlags();
+          Flags = setFlags(Flags, SCEV::FlagNW);
+          SmallVector<const SCEV*> Operands{AR->operands()};
+          Flags = StrengthenNoWrapFlags(this, scAddRecExpr, Operands, Flags);
+          setNoWrapFlags(const_cast<SCEVAddRecExpr *>(AR), Flags);
+        }
       }
     }
   }


        


More information about the llvm-commits mailing list