[llvm] [SeparateConstOffsetFromGEP] propagate const offset through GEP chains (PR #143470)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 17 07:50:03 PDT 2025


nikic wrote:

> > This looks plausible, but I also feel like this is something we should be doing in InstCombine? (That is, trying to combine multiple constant offset GEPs into one, even if there are intermediate GEPs, as long as use-constraints allow.)
> 
> As things are currently divided I think it makes a lot of sense to keep this logic here. This pass isn't run by most targets and it's behavior is very dependent on TTI.isLegalAddressingMode. Since we assume that the constant offsets we're generating will be used in the addressing of some memory instruction we're also less concerned about use constrains then we would be in InstCombine. While I agree there are likely some limited ways to do similar transformations in IC, here I think its safe to be a bit more aggressive and rely on target-specific information.

I don't disagree. My general thinking here was more along the lines that we should try do canonicalize this as far as we can in InstCombine, and have SeparateConstOffsetFromGEP pick up the parts that InstCombine can't do (such as use constraints, as you mention.)

We're moving towards splitting up GEPs in InstCombine (see https://github.com/llvm/llvm-project/pull/137297 for a first step), which will increase our ability to make these kind of transforms at that level.

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


More information about the llvm-commits mailing list