[llvm] [NPM] Make "LoopStrengthReduce" function pass (PR #186312)
Vikram Hegde via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 13 05:09:02 PDT 2026
vikramRH wrote:
> Converting this to a function pass also probably means we want to just drop this late loop pipeline altogether and also convert `CanonicalizeFreezeInLoops` (which should be fine given it just hoists things to the preheader, but not sure if we end up with loops in loopsimplify form here without the PM guaranteeing it) along with `LoopTermFold`, which might need some work around using scoped SCEV.
>
> Needing to construct a worklist to iterate over all the loops for each function along with reconstructing most loop analyses, which would be duplicated across the three passes, would also be a bit unfortunate.
>
> It would be good if someone more familiar with loop optimizations could double check my thinking given I'm pretty new to this, but those are my thoughts on this.
1. LoopSimplify could be guaranteed by explicitly scheduling it in the pipeline
2. I don't think we are reconstructing analyses here (comparing to the current state) considering these passes preserve most of the analyses and we are mostly hitting cache.
3. LoopTermFold could still be a loop pass, only redundancy then would be an additional loopSimplify which the default canonicalization pipeline schedules i guess.
That said, I do think https://github.com/llvm/llvm-project/pull/185373 with https://github.com/llvm/llvm-project/pull/191684 could be a reasonable enough solution right now with couple of concerns.
1. With https://github.com/llvm/llvm-project/pull/191684, i see a regression for example in llvm/test/CodeGen/AMDGPU/machine-sink-loop-var-out-of-divergent-loop-swdev407790.ll. Probably SCEV in "non look through" case was simpler for LSR to analyze. Not sure how big an impact it would be.
2. not sure if there are additional cases in SCEVExpander LCSSA preservation that need to be handled. https://github.com/llvm/llvm-project/pull/185373 was sufficient for our downstream test suite which involved building most of rocm components.
https://github.com/llvm/llvm-project/pull/186312
More information about the llvm-commits
mailing list