aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Support/KnownBits.cpp')
-rw-r--r--llvm/lib/Support/KnownBits.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/llvm/lib/Support/KnownBits.cpp b/llvm/lib/Support/KnownBits.cpp
index 423a908eed57..d997bd85f1e0 100644
--- a/llvm/lib/Support/KnownBits.cpp
+++ b/llvm/lib/Support/KnownBits.cpp
@@ -12,6 +12,8 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/KnownBits.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
#include <cassert>
using namespace llvm;
@@ -410,10 +412,11 @@ KnownBits KnownBits::abs(bool IntMinIsPoison) const {
return KnownAbs;
}
-KnownBits KnownBits::computeForMul(const KnownBits &LHS, const KnownBits &RHS) {
+KnownBits KnownBits::mul(const KnownBits &LHS, const KnownBits &RHS) {
unsigned BitWidth = LHS.getBitWidth();
+ assert(BitWidth == RHS.getBitWidth() && !LHS.hasConflict() &&
+ !RHS.hasConflict() && "Operand mismatch");
- assert(!LHS.hasConflict() && !RHS.hasConflict());
// Compute a conservative estimate for high known-0 bits.
unsigned LeadZ =
std::max(LHS.countMinLeadingZeros() + RHS.countMinLeadingZeros(),
@@ -495,7 +498,7 @@ KnownBits KnownBits::mulhs(const KnownBits &LHS, const KnownBits &RHS) {
!RHS.hasConflict() && "Operand mismatch");
KnownBits WideLHS = LHS.sext(2 * BitWidth);
KnownBits WideRHS = RHS.sext(2 * BitWidth);
- return computeForMul(WideLHS, WideRHS).extractBits(BitWidth, BitWidth);
+ return mul(WideLHS, WideRHS).extractBits(BitWidth, BitWidth);
}
KnownBits KnownBits::mulhu(const KnownBits &LHS, const KnownBits &RHS) {
@@ -504,7 +507,7 @@ KnownBits KnownBits::mulhu(const KnownBits &LHS, const KnownBits &RHS) {
!RHS.hasConflict() && "Operand mismatch");
KnownBits WideLHS = LHS.zext(2 * BitWidth);
KnownBits WideRHS = RHS.zext(2 * BitWidth);
- return computeForMul(WideLHS, WideRHS).extractBits(BitWidth, BitWidth);
+ return mul(WideLHS, WideRHS).extractBits(BitWidth, BitWidth);
}
KnownBits KnownBits::udiv(const KnownBits &LHS, const KnownBits &RHS) {
@@ -601,3 +604,11 @@ KnownBits &KnownBits::operator^=(const KnownBits &RHS) {
Zero = std::move(Z);
return *this;
}
+
+void KnownBits::print(raw_ostream &OS) const {
+ OS << "{Zero=" << Zero << ", One=" << One << "}";
+}
+void KnownBits::dump() const {
+ print(dbgs());
+ dbgs() << "\n";
+}