[llvm] [ValueTracking] Infer non-zero from shr (add nuw A, B), C (PR #203039)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 11 07:53:59 PDT 2026
================
@@ -3338,6 +3337,26 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
if (Known.isNegative())
return true;
+ // shr (add nuw A, B), C is non-zero if A or B has a known-one bit at
+ // position >= C, because the sum >= max(A, B).
+ const APInt *ShAmtC;
+ if (Depth + 1 < MaxAnalysisRecursionDepth &&
+ match(I->getOperand(1), m_APInt(ShAmtC)) && ShAmtC->ult(BitWidth)) {
+ Value *ShiftIn = I->getOperand(0);
+ if (auto *Add = dyn_cast<OverflowingBinaryOperator>(ShiftIn);
+ Add && Add->getOpcode() == Instruction::Add &&
+ Add->hasNoUnsignedWrap()) {
----------------
nikic wrote:
Replace this with a `m_NUWAdd()` match?
https://github.com/llvm/llvm-project/pull/203039
More information about the llvm-commits
mailing list