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

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 23 03:03:43 PDT 2021


lebedev.ri requested changes to this revision.
lebedev.ri added inline comments.
This revision now requires changes to proceed.


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:4673
+  } else if (CastOpc == Instruction::PtrToInt) {
+    // Fold (ptrtoint (gep i8 null, x)) -> x for non-inbounds GEPs.
+    // We don't perform this fold for non-integral pointers since the bitwise
----------------



================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:4679
+      if (isa<ConstantPointerNull>(GEP->getOperand(0)) &&
+          !Q.DL.isNonIntegralPointerType(GEP->getPointerOperandType())) {
+        // We can't create any zext/trunc instructions here, so this fold is
----------------
Doesn't this essentially call `->getType()` on a pointer?
You can't do that. Perhaps you want `getSourceElementType()`?


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:4680
+          !Q.DL.isNonIntegralPointerType(GEP->getPointerOperandType())) {
+        // We can't create any zext/trunc instructions here, so this fold is
+        // limited to cases where the result type matches the GEP index type.
----------------
What if it's a constant?


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:4685
+        if (GEP->getNumIndices() == 1 && GEP->getOperand(1)->getType() == Ty &&
+            Q.DL.getTypeAllocSize(GEP->getSourceElementType()) == 8)
+          return GEP->getOperand(1);
----------------
This is surely broken


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110246



More information about the llvm-commits mailing list