[PATCH] D99121: [IR][InstCombine] IntToPtr Produces Typeless Pointer To Byte

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 22 15:17:48 PDT 2021


lebedev.ri created this revision.
lebedev.ri added reviewers: spatel, arsenm, ruiling.
lebedev.ri added a project: LLVM.
Herald added subscribers: dexonsmith, arphaman, javed.absar, hiraditya, arichardson.
lebedev.ri requested review of this revision.
Herald added subscribers: llvm-commits, wdng.

While `ptrtoint` can and should be treated transparently by the passes,
`inttoptr` is a black box. SCEV does not, should not, and will not model it.
But that means, given two identical, but separate `inttoptr` instructions,
SROA won't be able to tell that they have the same pointer value.
Likewise for pointers with the same integer base but different pointee types.

Currently, InstCombine already ensures that `inttoptr`/`ptrtoint` don't change
the integer width, but it is performed separately before/after.

Let's do the same for target pointee type for `inttoptr`.
I.e. if it's not an `i8*`, reconstruct `inttoptr` + emit `bitcast`.
And let's rely on EarlyCSE to be able to CSE them,
thus making them somewhat less of a hurdle for SROA/etc.

Now, this causes some test regressions.
I've fixed SROA issue (D99051 <https://reviews.llvm.org/D99051>), and one InstCombine issue
(`p2i (?bitcast (ins (?bitcast (i2p Vec)), Scalar, Index)) --> ins Vec, (p2i Scalar), Index`),
but there may be few more in tests, i'll comment on them.
I'm not sure off-hand about what to do with them.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99121

Files:
  llvm/include/llvm/IR/PatternMatch.h
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
  llvm/test/Transforms/InstCombine/2009-02-20-InstCombine-SROA.ll
  llvm/test/Transforms/InstCombine/PR30597.ll
  llvm/test/Transforms/InstCombine/align-addr.ll
  llvm/test/Transforms/InstCombine/apint-call-cast-target.ll
  llvm/test/Transforms/InstCombine/cast_ptr.ll
  llvm/test/Transforms/InstCombine/indexed-gep-compares.ll
  llvm/test/Transforms/InstCombine/intptr1.ll
  llvm/test/Transforms/InstCombine/intptr3.ll
  llvm/test/Transforms/InstCombine/intptr7.ll
  llvm/test/Transforms/InstCombine/load-bitcast32.ll
  llvm/test/Transforms/InstCombine/load-bitcast64.ll
  llvm/test/Transforms/InstCombine/multi-use-load-casts.ll
  llvm/test/Transforms/InstCombine/ptr-int-cast.ll
  llvm/test/Transforms/InstCombine/type_pun-inseltpoison.ll
  llvm/test/Transforms/InstCombine/type_pun.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99121.332446.patch
Type: text/x-patch
Size: 53022 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210322/b10b87ea/attachment.bin>


More information about the llvm-commits mailing list