[llvm] [LoopInterchange] Fix handling of PHI which refers to another PHI (PR #194364)

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 28 07:38:40 PDT 2026


================
@@ -1945,12 +1944,13 @@ bool LoopInterchangeTransform::transform(
 
     SmallVector<Instruction *, 8> InnerIndexVarList;
     for (PHINode *CurInductionPHI : InductionPHIs) {
-      if (CurInductionPHI->getIncomingBlock(0) == InnerLoopPreHeader)
-        InnerIndexVarList.push_back(
-            dyn_cast<Instruction>(CurInductionPHI->getIncomingValue(1)));
-      else
-        InnerIndexVarList.push_back(
-            dyn_cast<Instruction>(CurInductionPHI->getIncomingValue(0)));
+      Instruction *IncomingValue = dyn_cast<Instruction>(
+          CurInductionPHI->getIncomingValueForBlock(InnerLoop->getLoopLatch()));
+      if (any_of(InductionPHIs, [IncomingValue](PHINode *InductionPHI) {
+            return IncomingValue == InductionPHI;
+          }))
+        continue;
----------------
kasuga-fj wrote:

> maybe this becomes all trivial and unnecessary if we simplify this to:

Sounds good, replaced with that, thanks.

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


More information about the llvm-commits mailing list