[clang] [llvm] [IndVarSimplify] Sink unused l-invariant loads in preheader. (PR #157559)
Vigneshwar Jayakumar via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 11 11:13:12 PDT 2025
VigneshwarJ wrote:
> I don't think IndVarSimplify is a good place to perform this transform. We could probably do this in LICM, which has access to MemorySSA. (LICM already sinks instructions from the loop to the exits, so doing it fore the preheader would be a somewhat natural extension of the scope of the pass.)
>
> It looks like the current patch miscompiles clang (stage2 build crashes on llvm-test-suite).
I agree that the whole logic of sinkUnusedInvariants can be removed from here and moved. I will try doing that in LICM, but LICM also hoists/sinks instructions from loop to preheader/exit block. So I have to add it at the end. I want to know if LoopSink.cpp would be a better place to move the logic to (it also has access to MemorySSA). It already sinks from preheader back to loop blocks. We could do the sinking to exit block there as well.
indvars is called before loop unrolling. So right now, the sinking happens before unrolling. Loopsink pass is called at much later stage.
The main reason I started looking at sinking loads is when the other invariant instructions that uses the load are sunk and the loop is unrolled, this increased the live range of load drastically.
https://github.com/llvm/llvm-project/pull/157559
More information about the llvm-commits
mailing list