[llvm] [InstCombine] Fold pointer adding in integer to arithmetic add (PR #91596)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun May 19 07:44:15 PDT 2024
================
@@ -2073,6 +2073,16 @@ Instruction *InstCombinerImpl::visitPtrToInt(PtrToIntInst &CI) {
return InsertElementInst::Create(Vec, NewCast, Index);
}
+ // (ptrtoint (gep (inttoptr Base), Offset)) -> Base + Offset
+ Value *Base, *Offset;
+ if (match(SrcOp, m_OneUse(m_PtrAdd(m_OneUse(m_IntToPtr(m_Value(Base))),
+ m_Value(Offset)))) &&
+ Base->getType() == Ty && Offset->getType() == Ty) {
+ auto *NewOp = BinaryOperator::CreateAdd(Base, Offset);
+ NewOp->setHasNoUnsignedWrap(true);
----------------
dtcxzyw wrote:
@YanWQ-monad Can you provide the alive proof?
https://github.com/llvm/llvm-project/pull/91596
More information about the llvm-commits
mailing list