[llvm] [LoopInterchange] Assume LCSSA PHI incoming value may not be instruction (PR #201069)

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 3 03:18:36 PDT 2026


================
@@ -2200,8 +2200,19 @@ static void moveLCSSAPhis(BasicBlock *InnerExit, BasicBlock *InnerHeader,
     assert(P.getNumIncomingValues() == 1 &&
            "Only loops with a single exit are supported!");
 
-    // Incoming values are guaranteed be instructions currently.
-    auto IncI = cast<Instruction>(P.getIncomingValueForBlock(InnerLatch));
+    Value *IncomingValue = P.getIncomingValueForBlock(InnerLatch);
+    if (!isa<Instruction>(IncomingValue)) {
+      // If the incoming value is not an instruction, it must be loop invariant.
+      // In that case, we can just replace the PHI with the incoming value and
+      // remove the PHI.
+      assert(InnerLoop->isLoopInvariant(IncomingValue) &&
+             "Expected non-instruction incoming value to be loop invariant");
+      P.replaceAllUsesWith(IncomingValue);
+      P.eraseFromParent();
+      continue;
+    }
+
+    auto *IncI = cast<Instruction>(IncomingValue);
----------------
kasuga-fj wrote:

It looks reasonable, fixed, thanks

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


More information about the llvm-commits mailing list