[llvm] [LoopInterchange] Always create a new latch when interchanging (PR #194574)

Sjoerd Meijer via llvm-commits llvm-commits at lists.llvm.org
Mon May 18 05:45:54 PDT 2026


================
@@ -1934,75 +1934,72 @@ bool LoopInterchangeTransform::transform(
   if (InnerReductions.size() == 1)
     reduction2Memory();
 
-  if (InnerLoop->getSubLoops().empty()) {
-    LLVM_DEBUG(dbgs() << "Splitting the inner loop latch\n");
-    auto &InductionPHIs = LIL.getInnerLoopInductions();
-    if (InductionPHIs.empty()) {
-      LLVM_DEBUG(dbgs() << "Failed to find the point to split loop latch \n");
-      return false;
-    }
-
-    SmallVector<Instruction *, 8> InnerIndexVarList;
-    for (PHINode *CurInductionPHI : InductionPHIs) {
-      Instruction *IncomingValue = dyn_cast<Instruction>(
-          CurInductionPHI->getIncomingValueForBlock(InnerLoop->getLoopLatch()));
-      assert(IncomingValue &&
-             "Incoming value from loop latch doesn't an instruction");
-      if (is_contained(InductionPHIs, IncomingValue))
-        continue;
-      InnerIndexVarList.push_back(IncomingValue);
-    }
+  LLVM_DEBUG(dbgs() << "Splitting the inner loop latch\n");
+  auto &InductionPHIs = LIL.getInnerLoopInductions();
+  if (InductionPHIs.empty()) {
+    LLVM_DEBUG(dbgs() << "Failed to find the point to split loop latch \n");
+    return false;
----------------
sjoerdmeijer wrote:

Can we do this check earlier? 
`reduction2Memory()` modifies the IR, and this can bail out early. Before this was also possible, I think, but it was guarded and more restricted.

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


More information about the llvm-commits mailing list