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

Vedant Paranjape via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 20 06:31:03 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;
+  }
----------------
vedantparanjape-amd wrote:

@nikic I studied the code, I don't think SCEVExpander is the right place. As we don't pass the Instruction to be replaced by the expanded value to the SCEVExpander at any point. Either we need a expanded value which doesn't make changes to the IR so that we can safely check for the LCSSA, or we need to somehow pass Instruction to be replaced to SCEVExpander and then do the check inside ? (I don't think we should do this).

What do you think, would be the ideal way to make this change ?

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


More information about the llvm-commits mailing list