[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:11:05 PDT 2021


lebedev.ri added inline comments.


================
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);
----------------
arichardson wrote:
> lebedev.ri wrote:
> > This is surely broken
> In what way? It's here to ensure that the following isn't incorrectly folded to %val:
> ```
> ; We can't fold non-i8 GEPs in InstSimplify since that would require adding new arithmetic.
> ; TODO: handle this case in InstCombine
> define i64 @fold_ptrtoint_nullgep_i32_variable(i64 %val) {
>   %ptr = getelementptr i32, i32 addrspace(1)* null, i64 %val
>   %ret = ptrtoint i32 addrspace(1)* %ptr to i64
>   ret i64 %ret
> }
> ```
> 
Why 8 and not 42?


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