aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-03-21 12:14:53 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-03-21 13:42:10 +0100
commit7a62ea3889b94516f3886cec9e447f22b99856e3 (patch)
tree71cc2f6406bba581867125f70c966e8758b1a0a5 /llvm/lib/Analysis/ValueTracking.cpp
parent9ab0c9a64402359647660cf1e3eca6006d375cf5 (diff)
downloadllvm-7a62ea3889b94516f3886cec9e447f22b99856e3.zip
llvm-7a62ea3889b94516f3886cec9e447f22b99856e3.tar.gz
llvm-7a62ea3889b94516f3886cec9e447f22b99856e3.tar.bz2
[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%.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index d337371..9a93b55 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,