[llvm] [LoopPeel] LCSSA form is destroyed by LoopPeel, preserve it (PR #78696)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 20 07:33:01 PST 2024


================
@@ -644,6 +644,13 @@ bool SimplifyIndvar::replaceIVUserWithLoopInvariant(Instruction *I) {
 
   auto *Invariant = Rewriter.expandCodeFor(S, I->getType(), IP);
 
+  if (!LI->replacementPreservesLCSSAForm(I, Invariant)) {
+    LLVM_DEBUG(dbgs() << "INDVARS: Can not replace IV user: " << *I
+                      << " with loop invariant: " << *S
+                      << " as it breaks LCSSA form " << '\n');
+    return false;
+  }
----------------
nikic wrote:

Okay, I get the problem now. SCEVExpander insertion point is the loop-invariant location, but the actual use will be inside an exit block.

I think the options to fix this would be:
1. Make a check that LCSSA is not broken before calling Rewriter, under the assumption that the instruction will be inserted at the insertion point. (This may have some false positives if instruction reuse occurs, but I think it's fine.)
2. Fix up LCSSA form in this special case after the transform. So if `!replacementPreservesLCSSAForm` insert a phi node.

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


More information about the llvm-commits mailing list