Bug ID: 36633
           Summary: Assert in SCEV: LHS is not available at Loop Entry
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer

Created attachment 20015
Failing test case reduced by bugpoint

Compiling the attached test case with either:
$ clang -O2 test.ll -S --target=x86_64-unknown-linux-gnu
$ clang -O2 test.ll -S --target=powerpc64le-unknown-linux-gnu

(and presumably other targets that I haven't checked)

Causes the following assert:
ScalarEvolution.cpp:9077: bool
llvm::ScalarEvolution::isLoopEntryGuardedByCond(const llvm::Loop*,
llvm::CmpInst::Predicate, const llvm::SCEV*, const llvm::SCEV*): Assertion
ailableAtLoopEntry(LHS, L) && "LHS is not available at Loop Entry"' failed.

The following patch fixes it and seems like a rather logical fix to someone
like me with no real understanding of how SCEV works. Mind you I only say it
seems to make sense because of the names of the function and the SCEV type
(i.e. if the SCEV is of type "unknown" it should imply that
isKnownOnEveryIteration() should return false).
However, the patch breaks lit test cases which leads me to believe that it is
overly conservative:

Index: lib/Analysis/ScalarEvolution.cpp
--- lib/Analysis/ScalarEvolution.cpp    (revision 326779)
+++ lib/Analysis/ScalarEvolution.cpp    (working copy)
@@ -8771,6 +8771,9 @@ bool ScalarEvolution::isKnownOnEveryIteration(ICmp
                                               const SCEVAddRecExpr *LHS,
                                               const SCEV *RHS) {
   const Loop *L = LHS->getLoop();
+  if (static_cast<SCEVTypes>(LHS->getStart()->getSCEVType()) == scUnknown ||
+      static_cast<SCEVTypes>(RHS->getSCEVType()) == scUnknown)
+    return false;
   return isLoopEntryGuardedByCond(L, Pred, LHS->getStart(), RHS) &&
          isLoopBackedgeGuardedByCond(L, Pred, LHS->getPostIncExpr(*this),

You are receiving this mail because:
You are on the CC list for the bug.
llvm-bugs mailing list

Reply via email to