[llvm-bugs] [Bug 36633] New: Assert in SCEV: LHS is not available at Loop Entry

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 7 10:38:01 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=36633

            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
          Assignee: unassignedbugs at nondot.org
          Reporter: nemanja.i.ibm at gmail.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 20015
  --> https://bugs.llvm.org/attachment.cgi?id=20015&action=edit
Failing test case reduced by bugpoint

Compiling the attached test case with either:
$ clang -O2 test.ll -S --target=x86_64-unknown-linux-gnu
or
$ 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
`isAv
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),
RHS);
 }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180307/842a799f/attachment-0001.html>


More information about the llvm-bugs mailing list