[llvm] 424b10d - [ValueTracking] Slight refactor to avoid unnecessary work; NFC
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 30 08:07:25 PDT 2023
Author: Noah Goldstein
Date: 2023-04-30T10:06:46-05:00
New Revision: 424b10d6cc0509054708d928cc3711b781610440
URL: https://github.com/llvm/llvm-project/commit/424b10d6cc0509054708d928cc3711b781610440
DIFF: https://github.com/llvm/llvm-project/commit/424b10d6cc0509054708d928cc3711b781610440.diff
LOG: [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
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 41fabbd48d8b..a5259ba7fbf3 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2796,8 +2796,8 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
I->getOperand(1));
case Instruction::Or:
// X | Y != 0 if X != 0 or Y != 0.
- return isKnownNonZero(I->getOperand(0), DemandedElts, Depth, Q) ||
- isKnownNonZero(I->getOperand(1), DemandedElts, Depth, Q);
+ return isKnownNonZero(I->getOperand(1), DemandedElts, Depth, Q) ||
+ isKnownNonZero(I->getOperand(0), DemandedElts, Depth, Q);
case Instruction::SExt:
case Instruction::ZExt:
// ext X != 0 if X != 0.
@@ -2862,8 +2862,8 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
// non-zero.
auto *BO = cast<OverflowingBinaryOperator>(V);
if (Q.IIQ.hasNoUnsignedWrap(BO))
- return isKnownNonZero(I->getOperand(0), DemandedElts, Depth, Q) ||
- isKnownNonZero(I->getOperand(1), DemandedElts, Depth, Q);
+ return isKnownNonZero(I->getOperand(1), DemandedElts, Depth, Q) ||
+ isKnownNonZero(I->getOperand(0), DemandedElts, Depth, Q);
return isNonZeroAdd(DemandedElts, Depth, Q, BitWidth, I->getOperand(0),
I->getOperand(1), Q.IIQ.hasNoSignedWrap(BO));
@@ -2939,9 +2939,7 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
case Intrinsic::bitreverse:
case Intrinsic::bswap:
case Intrinsic::ctpop:
- if (isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q))
- return true;
- break;
+ return isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q);
case Intrinsic::ssub_sat:
return isNonZeroSub(DemandedElts, Depth, Q, BitWidth,
II->getArgOperand(0), II->getArgOperand(1));
@@ -2951,10 +2949,8 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
/*NSW*/ true);
case Intrinsic::umax:
case Intrinsic::uadd_sat:
- if (isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q) ||
- isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q))
- return true;
- break;
+ return isKnownNonZero(II->getArgOperand(1), DemandedElts, Depth, Q) ||
+ isKnownNonZero(II->getArgOperand(0), DemandedElts, Depth, Q);
case Intrinsic::smin:
case Intrinsic::smax: {
auto KnownOpImpliesNonZero = [&](const KnownBits &K) {
More information about the llvm-commits
mailing list