[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:51:00 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:
You can treat `inbounds` as `nsw + nuw`. See also https://discourse.llvm.org/t/rfc-add-nusw-and-nuw-flags-for-getelementptr/78672.
https://github.com/llvm/llvm-project/pull/91596
More information about the llvm-commits
mailing list