[llvm] 91790c6 - [indvars[ Fix pr49802 by checking for SCEVCouldNotCompute

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 1 17:56:12 PDT 2021


Author: Philip Reames
Date: 2021-04-01T17:53:44-07:00
New Revision: 91790c67850d588edb3a0e195a388c0e450f1723

URL: https://github.com/llvm/llvm-project/commit/91790c67850d588edb3a0e195a388c0e450f1723
DIFF: https://github.com/llvm/llvm-project/commit/91790c67850d588edb3a0e195a388c0e450f1723.diff

LOG: [indvars[ Fix pr49802 by checking for SCEVCouldNotCompute

The code is assuming that having an exact exit count for the loop implies that exit counts for every exit are known.  This used to be true, but when we added handling for dead exits we broke this invariant.  The new invariant is that an exact loop count implies that any exits non trivially dead have exit counts.

We could have fixed this by either a) explicitly checking for a dead exit, or b) just testing for SCEVCouldNotCompute.  I chose the second as it was simpler.

(Debugging this took longer than it should have since I'd mistyped the original assert and it wasn't checking what it was meant to...)

p.s. Sorry for the lack of test case.  Getting things into a state to actually hit this is difficult and fragile.  The original repro involves loop-deletion leaving SCEV in a slightly inprecise state which lets us bypass other transforms in IndVarSimplify on the way to this one.  All of my attempts to separate it into a standalone test failed.

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 ae1fff0fa844..fd90baf40a5a 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -1605,8 +1605,8 @@ bool IndVarSimplify::predicateLoopExits(Loop *L, SCEVExpander &Rewriter) {
       return true;
 
     const SCEV *ExitCount = SE->getExitCount(L, ExitingBB);
-    assert(!isa<SCEVCouldNotCompute>(ExactBTC) && "implied by having exact trip count");
-    if (!SE->isLoopInvariant(ExitCount, L) ||
+    if (isa<SCEVCouldNotCompute>(ExitCount) ||
+        !SE->isLoopInvariant(ExitCount, L) ||
         !isSafeToExpand(ExitCount, *SE))
       return true;
 


        


More information about the llvm-commits mailing list