diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2022-03-20 11:40:34 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2022-06-04 11:58:51 +0000 |
| commit | 4b6eb0e63c698094db5506763df44cc83c19f643 (patch) | |
| tree | f1d30b8c10bc6db323b91538745ae8ab8b593910 /contrib/llvm-project/llvm/lib/Support/KnownBits.cpp | |
| parent | 76886853f03395abb680824bcc74e98f83bd477a (diff) | |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/KnownBits.cpp')
| -rw-r--r-- | contrib/llvm-project/llvm/lib/Support/KnownBits.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/KnownBits.cpp b/contrib/llvm-project/llvm/lib/Support/KnownBits.cpp index d997bd85f1e0..90483817c302 100644 --- a/contrib/llvm-project/llvm/lib/Support/KnownBits.cpp +++ b/contrib/llvm-project/llvm/lib/Support/KnownBits.cpp @@ -404,7 +404,7 @@ KnownBits KnownBits::abs(bool IntMinIsPoison) const { // We only know that the absolute values's MSB will be zero if INT_MIN is // poison, or there is a set bit that isn't the sign bit (otherwise it could // be INT_MIN). - if (IntMinIsPoison || (!One.isNullValue() && !One.isMinSignedValue())) + if (IntMinIsPoison || (!One.isZero() && !One.isMinSignedValue())) KnownAbs.Zero.setSignBit(); // FIXME: Handle known negative input? @@ -412,10 +412,13 @@ KnownBits KnownBits::abs(bool IntMinIsPoison) const { return KnownAbs; } -KnownBits KnownBits::mul(const KnownBits &LHS, const KnownBits &RHS) { +KnownBits KnownBits::mul(const KnownBits &LHS, const KnownBits &RHS, + bool SelfMultiply) { 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"); // Compute a conservative estimate for high known-0 bits. unsigned LeadZ = @@ -489,6 +492,14 @@ KnownBits KnownBits::mul(const KnownBits &LHS, const KnownBits &RHS) { Res.Zero.setHighBits(LeadZ); Res.Zero |= (~BottomKnown).getLoBits(ResultBitsKnown); Res.One = BottomKnown.getLoBits(ResultBitsKnown); + + // If we're self-multiplying then bit[1] is guaranteed to be zero. + if (SelfMultiply && BitWidth > 1) { + assert(Res.One[1] == 0 && + "Self-multiplication failed Quadratic Reciprocity!"); + Res.Zero.setBit(1); + } + return Res; } |
