[PATCH] D52930: [SCEV][NFC] Verify IR in isLoop[Entry, Backedge]GuardedByCond

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 5 03:22:47 PDT 2018


mkazantsev created this revision.
mkazantsev added reviewers: sanjoy, fhahn, hsaito, jlebar.
Herald added a subscriber: javed.absar.

We have a lot of various bugs that are caused by misuse of SCEV (in particular in LV),
all of them can simply be described as "we ask SCEV to prove some fact on invalid IR".
Some of examples of those are PR36311, PR37221, PR39160.

The problem is that these failues manifest differently (what we saw was failure of various
asserts across SCEV, but there can also be miscompiles). This patch adds an assert into two
SCEV methods that strongly rely on correctness of the IR and are involved in known failues.
This will at least allow us to have a clear indication of what was wrong in this case.

This patch also fixes a unit test with incorrect IR that fails this verification.


https://reviews.llvm.org/D52930

Files:
  lib/Analysis/ScalarEvolution.cpp
  unittests/Analysis/ScalarEvolutionTest.cpp


Index: unittests/Analysis/ScalarEvolutionTest.cpp
===================================================================
--- unittests/Analysis/ScalarEvolutionTest.cpp
+++ unittests/Analysis/ScalarEvolutionTest.cpp
@@ -701,7 +701,7 @@
     PN->addIncoming(Dec, IncBB);
     BranchInst::Create(CondBB, IncBB);
 
-    Accum = GetElementPtrInst::Create(I8Ty, Accum, Dec, "gep", EndBB);
+    Accum = GetElementPtrInst::Create(I8Ty, Accum, PN, "gep", EndBB);
 
     PrevBB = CondBB;
     CondBB = NextBB;
Index: lib/Analysis/ScalarEvolution.cpp
===================================================================
--- lib/Analysis/ScalarEvolution.cpp
+++ lib/Analysis/ScalarEvolution.cpp
@@ -112,6 +112,7 @@
 #include "llvm/IR/Use.h"
 #include "llvm/IR/User.h"
 #include "llvm/IR/Value.h"
+#include "llvm/IR/Verifier.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/CommandLine.h"
@@ -9369,6 +9370,9 @@
   // (interprocedural conditions notwithstanding).
   if (!L) return true;
 
+  assert(!verifyFunction(*L->getHeader()->getParent(), &dbgs()) &&
+         "This cannot be done on broken IR!");
+
   if (isKnownViaNonRecursiveReasoning(Pred, LHS, RHS))
     return true;
 
@@ -9473,7 +9477,8 @@
   // Interpret a null as meaning no loop, where there is obviously no guard
   // (interprocedural conditions notwithstanding).
   if (!L) return false;
-
+  assert(!verifyFunction(*L->getHeader()->getParent(), &dbgs()) &&
+         "This cannot be done on broken IR!");
   // Both LHS and RHS must be available at loop entry.
   assert(isAvailableAtLoopEntry(LHS, L) &&
          "LHS is not available at Loop Entry");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52930.168447.patch
Type: text/x-patch
Size: 1646 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181005/38c9c083/attachment.bin>


More information about the llvm-commits mailing list