Skip to content

Commit

Permalink
[ValueTracking] Short-circuit computeKnownBitsAddSub(); NFCI
Browse files Browse the repository at this point in the history
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%.
  • Loading branch information
nikic committed Mar 21, 2020
1 parent 9ab0c9a commit 7a62ea3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7a62ea3

Please sign in to comment.