[PATCH] D140844: [InstCombine] Canonicalize gep of addrspacecast

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 2 07:34:09 PST 2023


nikic created this revision.
nikic added reviewers: arsenm, spatel.
Herald added a subscriber: hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

With typed pointers, InstCombine will often convert gep of addrspacecast into addrspacecast of gep, see e.g. https://llvm.godbolt.org/z/fYa3oKvdh. This isn't done consistently, because it happens as a side-effect of other folds. The most common one is trivial index descaling (where no descaling actually happens, and only the addrspacecast/gep end up being swapped). These folds are disabled for opaque pointers, so we don't canonicalize in either direction there.

This adds canonicalization of `gep(ac)` to `ac(gep)`. I've limited this to the case where index types match: While this is always legal, changing index types might introduced truncs/sexts, which might be non-profitable (test diffs were a wash).

After typed pointer support is dropped, we might want to consider inverting this canonicalization and going from `ac(gep)` to `gep(ac)` instead, which seems better to me. But for now I'm matching what typed pointers were (mostly) doing.


https://reviews.llvm.org/D140844

Files:
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/gep-addrspace.ll
  llvm/test/Transforms/InstCombine/gep-vector.ll
  llvm/test/Transforms/InstCombine/non-integral-pointers.ll
  llvm/test/Transforms/InstCombine/opaque-ptr.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140844.485862.patch
Type: text/x-patch
Size: 9306 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230102/1bf2fb77/attachment.bin>


More information about the llvm-commits mailing list