[PATCH] D124459: [InstCombine] Combine opaque pointer GEPs with mismatching element types

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 26 08:20:41 PDT 2022


nikic created this revision.
nikic added a reviewer: opaque-pointers.
Herald added subscribers: dexonsmith, hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Currently, two GEPs will only be combined if the result element type of one is the same as the source element type of the other. However, this means we may miss folding opportunities where the second GEP could be rewritten using a different element type. This is especially relevant for opaque pointers, where constant GEPs often use `i8` element type.

Address this by converting GEP indices to offsets, adding them, and then converting them back to indices. The first (inner) GEP is allowed to have variable indices as well, in which case only the constant suffix is converted into an offset.

I believe this should address the regression reported in https://reviews.llvm.org/D123300#3467615.


https://reviews.llvm.org/D124459

Files:
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/opaque-ptr.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124459.425225.patch
Type: text/x-patch
Size: 7129 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220426/c0429db7/attachment.bin>


More information about the llvm-commits mailing list