[llvm] 4d5d725 - [SCEV] Add some asserts on availability of arguments of isLoopEntryGuardedByCond

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 21 03:09:34 PDT 2021


Author: Max Kazantsev
Date: 2021-09-21T17:08:52+07:00
New Revision: 4d5d72542839b11455a0c261b66a0426c1530d52

URL: https://github.com/llvm/llvm-project/commit/4d5d72542839b11455a0c261b66a0426c1530d52
DIFF: https://github.com/llvm/llvm-project/commit/4d5d72542839b11455a0c261b66a0426c1530d52.diff

LOG: [SCEV] Add some asserts on availability of arguments of isLoopEntryGuardedByCond

The logic in howManyLessThans is fishy. It first checks invariance of
RHS, and then uses OrigRHS as argument for isLoopEntryGuardedByCond, which
is, strictly saying, a different thing. We are seeing a very rare intermittent
failure of availability checks, and it looks like this precondition is
sometimes broken. Before we can figure out what's going on, adding asserts
that all involved values that may possibly to to isLoopEntryGuardedByCond
are available at loop entry.

If either of these asserts fails (OrigRHS is the most likely suspect), it
means that the logic here is flawed.

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index b9a319474ed6c..bf1a6e222d4e5 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -11836,6 +11836,9 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
   // so we get a backedge count of zero.
   const SCEV *BECount = nullptr;
   auto *OrigStartMinusStride = getMinusSCEV(OrigStart, Stride);
+  assert(isLoopInvariant(OrigStartMinusStride, L) && "Must be!");
+  assert(isLoopInvariant(OrigStart, L) && "Must be!");
+  assert(isLoopInvariant(OrigRHS, L) && "Must be!");
   // Can we prove (max(RHS,Start) > Start - Stride?
   if (isLoopEntryGuardedByCond(L, Cond, OrigStartMinusStride, OrigStart) &&
       isLoopEntryGuardedByCond(L, Cond, OrigStartMinusStride, OrigRHS)) {


        


More information about the llvm-commits mailing list