[PATCH] D110245: [ConstantFolding] Fold ptrtoint(gep i8 null, x) -> x

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 22 07:13:22 PDT 2021


nikic added inline comments.


================
Comment at: llvm/lib/Analysis/ConstantFolding.cpp:1376
+          constexpr bool CanFoldNonzeroInboundsNullGEPToZero = false;
+          if (CanFoldNonzeroInboundsNullGEPToZero && GEP->isInBounds()) {
+            // Any non-zero inbounds GEP on NULL is poison, so we can return 0.
----------------
This doesn't belong here. If we'd like to make this fold, it should work directly on `gep null, x -> null`, without requiring a ptrtoint around it. (Also note that this fold is not correct if null is defined, e.g. in non-zero address space).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110245



More information about the llvm-commits mailing list