[PATCH] D110246: [InstSimplify][InstCombine] Fold ptrtoint(gep i8 null, x) -> x

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 22 06:58:18 PDT 2021


arichardson created this revision.
arichardson added reviewers: nikic, lebedev.ri, reames.
Herald added subscribers: jrtc27, hiraditya.
arichardson requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This commit is the InstSimplify follow-up to the previous constant-folding
change that enables noticeable optimizations for CHERI-enabled targets.

We could fold all ptrtoint(inbounds GEP) to zero here since that is the
only valid offset for an inbounds GEP. If the offset is not zero, that GEP
is poison so returning 0 is valid (https://alive2.llvm.org/ce/z/Gzb5iH).
However, Clang currentlygenerates inbounds GEPs on NULL for hand-written
offsetof expressions, so this risks miscompilation.

FIXME: is this transformation also valid for non-integral pointers?

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110246

Files:
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/test/Transforms/InstCombine/ptrtoint-nullgep.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110246.374216.patch
Type: text/x-patch
Size: 10759 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210922/db7daca6/attachment.bin>


More information about the llvm-commits mailing list