[NFC] Add assert to detect LCSSA breaches early
authorMax Kazantsev <max.kazantsev@azul.com>
Tue, 4 Sep 2018 06:34:40 +0000 (06:34 +0000)
committerMax Kazantsev <max.kazantsev@azul.com>
Tue, 4 Sep 2018 06:34:40 +0000 (06:34 +0000)
llvm-svn: 341347

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp

index 372ea61..0683636 100644 (file)
@@ -645,6 +645,16 @@ void IndVarSimplify::rewriteLoopExitValues(Loop *L, SCEVExpander &Rewriter) {
           continue;
         }
 
+#ifndef NDEBUG
+        // If we reuse an instruction from a loop which is neither L nor one of
+        // its containing loops, we end up breaking LCSSA form for this loop by
+        // creating a new use of its instruction.
+        if (auto *ExitInsn = dyn_cast<Instruction>(ExitVal))
+          if (auto *EVL = LI->getLoopFor(ExitInsn->getParent()))
+            if (EVL != L)
+              assert(EVL->contains(L) && "LCSSA breach detected!");
+#endif
+
         // Collect all the candidate PHINodes to be rewritten.
         RewritePhiSet.emplace_back(PN, i, ExitVal, HighCost);
       }