[llvm] [InstCombine] Fold pointer adding in integer to arithmetic add (PR #91596)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu May 9 07:03:56 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);
----------------
nikic wrote:
This nuw is incorrect. You need inbounds gep + non-negative offset for the add to be nuw.
https://github.com/llvm/llvm-project/pull/91596
More information about the llvm-commits
mailing list