[llvm] [LoopFusion] Reform LCSSA after peelFusionCandidate's peelLoop (PR #200442)
Ehsan Amiri via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 1 08:06:15 PDT 2026
================
@@ -665,7 +666,13 @@ struct LoopFuser {
<< " iterations of the first loop. \n");
ValueToValueMapTy VMap;
- peelLoop(FC0.L, PeelCount, false, &LI, &SE, DT, &AC, true, VMap);
+ // peelLoop can invalidate LCSSA on the surrounding nest; reform it
+ // explicitly below instead of asking peelLoop to preserve it.
+ peelLoop(FC0.L, PeelCount, /*PeelLast=*/false, &LI, &SE, DT, &AC,
+ /*PreserveLCSSA=*/false, VMap);
+ Loop *AffectedNest =
+ FC0.L->getParentLoop() ? FC0.L->getParentLoop() : FC0.L;
+ formLCSSARecursively(*AffectedNest, DT, &LI, &SE);
----------------
amehsan wrote:
The patch is likely fine, I just have a question, quite likely I am missing something here:
Why do we need to call `formLCSSARecursively`? This is what I know:
1. There is a call to simplifyLoop very early in loop fusion (in `LoopFusePass::run`) that I copy below. It seems that loop fusion doesn't assume incoming loops are in LCSSA form
```
for (auto &L : LI) {
Changed |=
simplifyLoop(L, &DT, &LI, &SE, &AC, nullptr, false /* PreserveLCSSA */);
}
```
2. I believe loop pass manager requires loop passes to preserve LCSSA. but loop fusion is not a loop pass, it is a function pass. So it has no commitment to preserve LCSSA and it doesn't expect the loops to be in LCSSA a form either.
So why do we need to call `formLCSSARecursively` and flipping the flag in line 672 is not enough?
https://github.com/llvm/llvm-project/pull/200442
More information about the llvm-commits
mailing list