[llvm] Add a pass "SinkGEPConstOffset" (PR #140657)

via llvm-commits llvm-commits at lists.llvm.org
Wed May 21 01:33:30 PDT 2025


StevenYangCC wrote:

> Why is this needed?
> 
> Shouldn't this already be covered by SeparateConstOffsetFromGEP (specifically reorderGEP). Then CodeGenPrepare does the sinking of constant offset GEPs.
> 
> See
> 
> https://godbolt.org/z/836v864TM
> 
> Do we also need the CodeGenPrepare functionality in opt?

@jrbyrnes   The pass SeparateConstOffsetFromGEP will convert more add to gep, moving the constant in it to the offset of the last gep. But more geps are generated in the OPT phase, and the geps themselves are not candidate in this pass, so the offset of the constant type in the original gep will not be moved to the very end of the gep chain. Also, currently, this optimization is not done in CodeGenPrepare.
Please can you see the results first?
   [llvm/test/Transforms/SinkGEPConstOffset/AMDGPU/sink-gep-const-offset-llc.ll](https://github.com/llvm/llvm-project/pull/140657/commits/36d32aa79956add6d05162cb6dd50e4273e86b9c#diff-17210eb5cdfde42808d1310683d8e549f2384fb30e7df2154d714a689e468fe2)

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


More information about the llvm-commits mailing list