Skip to content

Commit 424b10d

Browse files
committed
[ValueTracking] Slight refactor to avoid unnecessary work; NFC
Two changes: 1) Make some cases that conditionally returned unconditional. 2) In cases of `Op0 != 0 || Op1 != 0` its better check `Op1` first as its more likely to be a constant due to canonicalization (so faster to get knownbits of). Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D149419
1 parent 5eedfff commit 424b10d

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2796,8 +2796,8 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
27962796
I->getOperand(1));
27972797
case Instruction::Or:
27982798
// X | Y != 0 if X != 0 or Y != 0.
2799-
return isKnownNonZero(I->getOperand(0), DemandedElts, Depth, Q) ||
2800-
isKnownNonZero(I->getOperand(1), DemandedElts, Depth, Q);
2799+
return isKnownNonZero(I->getOperand(1), DemandedElts, Depth, Q) ||
2800+
isKnownNonZero(I->getOperand(0), DemandedElts, Depth, Q);
28012801
case Instruction::SExt:
28022802
case Instruction::ZExt:
28032803
// ext X != 0 if X != 0.
@@ -2862,8 +2862,8 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
28622862
// non-zero.
28632863
auto *BO = cast<OverflowingBinaryOperator>(V);
28642864
if (Q.IIQ.hasNoUnsignedWrap(BO))
2865-
return isKnownNonZero(I->getOperand(0), DemandedElts, Depth, Q) ||
2866-
isKnownNonZero(I->getOperand(1), DemandedElts, Depth, Q);
2865+
return isKnownNonZero(I->getOperand(1), DemandedElts, Depth, Q) ||
2866+
isKnownNonZero(I->getOperand(0), DemandedElts, Depth, Q);
28672867

28682868
return isNonZeroAdd(DemandedElts, Depth, Q, BitWidth, I->getOperand(0),
28692869
I->getOperand(1), Q.IIQ.hasNoSignedWrap(BO));
@@ -2939,9 +2939,7 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
29392939
case Intrinsic::bitreverse:
29402940
case Intrinsic::bswap:
29412941
case Intrinsic::ctpop:
2942-
if (isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q))
2943-
return true;
2944-
break;
2942+
return isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q);
29452943
case Intrinsic::ssub_sat:
29462944
return isNonZeroSub(DemandedElts, Depth, Q, BitWidth,
29472945
II->getArgOperand(0), II->getArgOperand(1));
@@ -2951,10 +2949,8 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
29512949
/*NSW*/ true);
29522950
case Intrinsic::umax:
29532951
case Intrinsic::uadd_sat:
2954-
if (isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q) ||
2955-
isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q))
2956-
return true;
2957-
break;
2952+
return isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q) ||
2953+
isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q);
29582954
case Intrinsic::smin:
29592955
case Intrinsic::smax: {
29602956
auto KnownOpImpliesNonZero = [&](const KnownBits &K) {

0 commit comments

Comments
 (0)