[llvm] [InstCombine] fold `sub(zext(ptrtoint), zext(ptrtoint))` (PR #115369)
Nikolay Panchenko via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 13 18:40:41 PST 2024
================
@@ -2631,6 +2631,21 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
/* IsNUW */ false))
return replaceInstUsesWith(I, Res);
+ if (match(Op0, m_ZExt(m_PtrToInt(m_Value(LHSOp)))) &&
+ match(Op1, m_ZExtOrSelf(m_PtrToInt(m_Value(RHSOp))))) {
+ if (auto *GEP = dyn_cast<GEPOperator>(LHSOp)) {
+ if (GEP->getPointerOperand() == RHSOp) {
+ if (GEP->hasNoUnsignedWrap() || GEP->hasNoUnsignedSignedWrap()) {
+ Value *Offset = EmitGEPOffset(GEP);
+ Value *Res = GEP->hasNoUnsignedWrap()
+ ? Builder.CreateZExt(Offset, I.getType())
----------------
npanchen wrote:
it's only possible if both nowrap flags are set: https://alive2.llvm.org/ce/z/QXHkTH
https://github.com/llvm/llvm-project/pull/115369
More information about the llvm-commits
mailing list