Skip to content

Commit

Permalink
[KnownBits] Add support for X*X self-multiplication (update)
Browse files Browse the repository at this point in the history
Rename the SelfMultiply argument to make it clearer that the argument must not be undef

Differential Revision: https://reviews.llvm.org/D108992
  • Loading branch information
RKSimon committed Feb 6, 2022
1 parent b932877 commit 9445395
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion llvm/include/llvm/Support/KnownBits.h
Expand Up @@ -324,7 +324,7 @@ struct KnownBits {

/// Compute known bits resulting from multiplying LHS and RHS.
static KnownBits mul(const KnownBits &LHS, const KnownBits &RHS,
bool SelfMultiply = false);
bool NoUndefSelfMultiply = false);

/// Compute known bits from sign-extended multiply-hi.
static KnownBits mulhs(const KnownBits &LHS, const KnownBits &RHS);
Expand Down
9 changes: 5 additions & 4 deletions llvm/lib/Support/KnownBits.cpp
Expand Up @@ -413,12 +413,13 @@ KnownBits KnownBits::abs(bool IntMinIsPoison) const {
}

KnownBits KnownBits::mul(const KnownBits &LHS, const KnownBits &RHS,
bool SelfMultiply) {
bool NoUndefSelfMultiply) {
unsigned BitWidth = LHS.getBitWidth();
assert(BitWidth == RHS.getBitWidth() && !LHS.hasConflict() &&
!RHS.hasConflict() && "Operand mismatch");
assert((!SelfMultiply || (LHS.One == RHS.One && LHS.Zero == RHS.Zero)) &&
"Self multiplication knownbits mismatch");
assert(
(!NoUndefSelfMultiply || (LHS.One == RHS.One && LHS.Zero == RHS.Zero)) &&
"Self multiplication knownbits mismatch");

// Compute the high known-0 bits by multiplying the unsigned max of each side.
// Conservatively, M active bits * N active bits results in M + N bits in the
Expand Down Expand Up @@ -501,7 +502,7 @@ KnownBits KnownBits::mul(const KnownBits &LHS, const KnownBits &RHS,
Res.One = BottomKnown.getLoBits(ResultBitsKnown);

// If we're self-multiplying then bit[1] is guaranteed to be zero.
if (SelfMultiply && BitWidth > 1) {
if (NoUndefSelfMultiply && BitWidth > 1) {
assert(Res.One[1] == 0 &&
"Self-multiplication failed Quadratic Reciprocity!");
Res.Zero.setBit(1);
Expand Down

0 comments on commit 9445395

Please sign in to comment.