[PATCH] D110245: [ConstantFolding] Fold ptrtoint(gep i8 null, x) -> x
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 23 02:30:00 PDT 2021
lebedev.ri added a comment.
Looks reasonable with nits.
================
Comment at: llvm/lib/Analysis/ConstantFolding.cpp:1365
+ APInt BaseOffset(BitWidth, 0);
+ auto *Base = cast<Constant>(
+ GEP->stripAndAccumulateConstantOffsets(DL, BaseOffset, true));
----------------
arichardson wrote:
> arichardson wrote:
> > lebedev.ri wrote:
> > > How do you know the result is a constant?
> > Don't all inputs need to be constants if the GEP is a `ConstantExpr`? I couldn't think of a counter-example:
> >
> > Even for globals this cast works fine:
> > ```
> > @a = external addrspace(1) global i16
> >
> > define i64 @nofold_ptrtoint_gep_global(i32 %x) {
> > %ptr = getelementptr i16, i16 addrspace(1)* @a, i32 1
> > %ret = ptrtoint i16 addrspace(1)* %ptr to i64
> > ret i64 %ret
> > }
> > ```
> If this is not true, I'm obviously happy to change it to dyn_cast and add the check.
Err, right,
This also answers my further unanswered question as to why we need to special-handle this in instsimplify too.
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