[llvm] 7a62ea3 - [ValueTracking] Short-circuit computeKnownBitsAddSub(); NFCI
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 21 05:42:31 PDT 2020
Author: Nikita Popov
Date: 2020-03-21T13:42:10+01:00
New Revision: 7a62ea3889b94516f3886cec9e447f22b99856e3
URL: https://github.com/llvm/llvm-project/commit/7a62ea3889b94516f3886cec9e447f22b99856e3
DIFF: https://github.com/llvm/llvm-project/commit/7a62ea3889b94516f3886cec9e447f22b99856e3.diff
LOG: [ValueTracking] Short-circuit computeKnownBitsAddSub(); NFCI
If one operand is unknown (and we don't have nowrap), don't compute
the second operand.
Also don't create an unnecessary extra KnownBits variable, it's
okay to reuse KnownOut.
This reduces instructions on libclamav_md5.c by 40%.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index d3373711b817..9a93b553b004 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -385,15 +385,15 @@ static void computeKnownBitsAddSub(bool Add, const Value *Op0, const Value *Op1,
bool NSW, const APInt &DemandedElts,
KnownBits &KnownOut, KnownBits &Known2,
unsigned Depth, const Query &Q) {
- unsigned BitWidth = KnownOut.getBitWidth();
+ computeKnownBits(Op1, DemandedElts, KnownOut, Depth + 1, Q);
- // If an initial sequence of bits in the result is not needed, the
- // corresponding bits in the operands are not needed.
- KnownBits LHSKnown(BitWidth);
- computeKnownBits(Op0, DemandedElts, LHSKnown, Depth + 1, Q);
- computeKnownBits(Op1, DemandedElts, Known2, Depth + 1, Q);
+ // If one operand is unknown and we have no nowrap information,
+ // the result will be unknown independently of the second operand.
+ if (KnownOut.isUnknown() && !NSW)
+ return;
- KnownOut = KnownBits::computeForAddSub(Add, NSW, LHSKnown, Known2);
+ computeKnownBits(Op0, DemandedElts, Known2, Depth + 1, Q);
+ KnownOut = KnownBits::computeForAddSub(Add, NSW, Known2, KnownOut);
}
static void computeKnownBitsMul(const Value *Op0, const Value *Op1, bool NSW,
More information about the llvm-commits
mailing list