[PATCH] D110246: [InstSimplify][InstCombine] Fold ptrtoint(gep i8 null, x) -> x
Alexander Richardson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 23 03:08:32 PDT 2021
arichardson marked an inline comment as done.
arichardson added inline comments.
================
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.
----------------
lebedev.ri wrote:
> What if it's a constant?
In that case it should have been handled by D110245? Will add a comment.
================
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);
----------------
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
}
```
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