[llvm] [InstCombine] Refine nuw propagation in `OptimizePointerDifference` (PR #147059)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 4 07:14:42 PDT 2025
================
@@ -2164,10 +2164,13 @@ Value *InstCombinerImpl::OptimizePointerDifference(Value *LHS, Value *RHS,
// If this is a single inbounds GEP and the original sub was nuw,
// then the final multiplication is also nuw.
- if (auto *I = dyn_cast<Instruction>(Result))
+ if (auto *I = dyn_cast<OverflowingBinaryOperator>(Result))
if (IsNUW && match(Offset2, m_Zero()) && Base.LHSNW.isInBounds() &&
- I->getOpcode() == Instruction::Mul)
- I->setHasNoUnsignedWrap();
+ I->hasNoSignedWrap() && !I->hasNoUnsignedWrap() &&
----------------
nikic wrote:
I think we're also missing a one-use check? Otherwise there may be another use of the instruction that's not nuw.
https://github.com/llvm/llvm-project/pull/147059
More information about the llvm-commits
mailing list