[PATCH] D87827: [SCEVExpander] Support expanding nonintegral pointers with constant base.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 18 15:54:25 PDT 2020


fhahn added inline comments.


================
Comment at: llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp:131
+  // inttoptr only works for integral pointers. For non-integral pointers, we
+  // can create a GEP on i8* null  with the integral value as index.
+  if (Op == Instruction::IntToPtr && DL.isNonIntegralPointerType(PtrTy)) {
----------------
efriedma wrote:
> It's probably worth noting the reason we know this is safe.  Semantically, a GEP from null is quite different from an inttoptr: a GEP from null can't be used to access memory.  I guess the reason this is safe is that we know the original IR must also have been a GEP from null.
Updated, thanks! I think in theory the user could also use `expandCodeFor` to expand a SCEV expression that does not originate from a pointer and force the result to be casted to a pointer (e.g. `expandCodeFor(2, PtrTy)`), but this seems like an invalid use of the API to me. (Which we unfortunately cannot easily catch/detect)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87827/new/

https://reviews.llvm.org/D87827



More information about the llvm-commits mailing list