[PATCH] D154055: [InstCombine] Preserve inbounds when folding select of GEP

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 29 02:05:11 PDT 2023


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

The `select base, (gep base, offset)` to `gep base, select (0, offset)` fold used to drop `inbounds`, because the `gep base, 0` this introduces might not be inbounds. After the semantics change in D154051 <https://reviews.llvm.org/D154051>, such a GEP is always considered inbounds, in which allows us to preserve the flag here.

As the PhaseOrdering test demonstrates, this can result in major optimization improvements.

Depends on: D154051 <https://reviews.llvm.org/D154051>


https://reviews.llvm.org/D154055

Files:
  llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
  llvm/test/Transforms/InstCombine/select-gep.ll
  llvm/test/Transforms/InstCombine/stpncpy-1.ll
  llvm/test/Transforms/PhaseOrdering/gep-null-compare-in-loop.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154055.535685.patch
Type: text/x-patch
Size: 6792 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230629/ef2e4721/attachment.bin>


More information about the llvm-commits mailing list