[llvm] [LoopInterchange] Fix crash when followLCSSA returns constant (PR #203515)

Sjoerd Meijer via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 12 07:06:19 PDT 2026


================
@@ -2271,11 +2271,13 @@ static void moveLCSSAPhis(BasicBlock *InnerExit, BasicBlock *InnerHeader,
 
     // In case of multi-level nested loops, follow LCSSA to find the incoming
     // value defined from the innermost loop.
-    auto IncIInnerMost = cast<Instruction>(followLCSSA(IncI));
-    // Skip phis with incoming values from the inner loop body, excluding the
-    // header and latch.
-    if (IncIInnerMost->getParent() != InnerLatch &&
-        IncIInnerMost->getParent() != InnerHeader)
+    auto *IncIInnerMost = dyn_cast<Instruction>(followLCSSA(IncI));
+    // Skip phis when:
+    // - Constant incoming values.
----------------
sjoerdmeijer wrote:

Nit: maybe to be a bit more precise, you could say something along the lines of:

"they are not an instruction, e.g. incoming constant values"

https://github.com/llvm/llvm-project/pull/203515


More information about the llvm-commits mailing list