[PATCH] D146811: [LSR] Preserve LCSSA when rewriting instruction with PHI user

Dmitry Makogon via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 28 01:15:17 PDT 2023


dmakogon added inline comments.


================
Comment at: llvm/test/Transforms/LoopStrengthReduce/depth-limit-overrun.ll:77
 ; LIMIT-NEXT:  entry:
+; LIMIT-NEXT:    [[TMP0:%.*]] = mul i32 [[C:%.*]], -3
 ; LIMIT-NEXT:    br label [[OUTER_LOOP:%.*]]
----------------
dmakogon wrote:
> mkazantsev wrote:
> > That's weird.
> I guess it's ok because we get exactly the same IR as with DEFAULT checks above which are generated by running the pass through new pass manager.
Ok, I found out why this happens. LSR here calculates the exit value of the inner loop IV (%i33) using SCEV, and it is able to do so because its only use is in loop exit block (in LCSSA PHI which is inserted in `outer_tail.loopexit` block because of my changes). Previously we wouldn't create this LCSSA PHI and the IV's use would be in a inner loop exit's successor. 
LSR checks for LCSSA form of the loop explicitly, and if the check fails, we don't even try this exit value calculation.
The corresponding code for that:
```
if (L->isRecursivelyLCSSAForm(DT, LI) && L->getExitBlock()) {
    ...
    int Rewrites = rewriteLoopExitValues(L, &LI, &TLI, &SE, &TTI, Rewriter, &DT,
                                             UnusedIndVarInLoop, DeadInsts);
```


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146811/new/

https://reviews.llvm.org/D146811



More information about the llvm-commits mailing list