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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 02:52:52 PST 2024


================
@@ -643,10 +644,22 @@ bool SimplifyIndvar::replaceIVUserWithLoopInvariant(Instruction *I) {
   }
 
   auto *Invariant = Rewriter.expandCodeFor(S, I->getType(), IP);
+  bool NeedToEmitLCSSAPhis = false;
+  if (!LI->replacementPreservesLCSSAForm(I, Invariant))
+    NeedToEmitLCSSAPhis = true;
 
   I->replaceAllUsesWith(Invariant);
   LLVM_DEBUG(dbgs() << "INDVARS: Replace IV user: " << *I
                     << " with loop invariant: " << *S << '\n');
+
+  if (NeedToEmitLCSSAPhis) {
+    SmallVector<Instruction *, 1> NeedsLCSSAPhis;
+    NeedsLCSSAPhis.push_back(dyn_cast<Instruction>(Invariant));
----------------
nikic wrote:

```suggestion
    NeedsLCSSAPhis.push_back(cast<Instruction>(Invariant));
```
As you rely on the cast to succeed. The cast itself seems fine, as LCSSA would not be broken if this weren't an instruction.

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


More information about the llvm-commits mailing list