aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/ConstantRangeTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r--llvm/unittests/IR/ConstantRangeTest.cpp49
1 files changed, 48 insertions, 1 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index 12362b9..f8816e4 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -6,9 +6,10 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/IR/ConstantRange.h"
#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/Sequence.h"
#include "llvm/ADT/SmallBitVector.h"
-#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Operator.h"
#include "llvm/Support/KnownBits.h"
@@ -1509,6 +1510,52 @@ TEST(ConstantRange, MakeSatisfyingICmpRegion) {
ConstantRange(APInt(8, 4), APInt(8, -128)));
}
+static bool icmp(CmpInst::Predicate Pred, const APInt &LHS, const APInt &RHS) {
+ switch (Pred) {
+ case CmpInst::Predicate::ICMP_EQ:
+ return LHS.eq(RHS);
+ case CmpInst::Predicate::ICMP_NE:
+ return LHS.ne(RHS);
+ case CmpInst::Predicate::ICMP_UGT:
+ return LHS.ugt(RHS);
+ case CmpInst::Predicate::ICMP_UGE:
+ return LHS.uge(RHS);
+ case CmpInst::Predicate::ICMP_ULT:
+ return LHS.ult(RHS);
+ case CmpInst::Predicate::ICMP_ULE:
+ return LHS.ule(RHS);
+ case CmpInst::Predicate::ICMP_SGT:
+ return LHS.sgt(RHS);
+ case CmpInst::Predicate::ICMP_SGE:
+ return LHS.sge(RHS);
+ case CmpInst::Predicate::ICMP_SLT:
+ return LHS.slt(RHS);
+ case CmpInst::Predicate::ICMP_SLE:
+ return LHS.sle(RHS);
+ default:
+ llvm_unreachable("Not an ICmp predicate!");
+ }
+}
+
+void ICmpTestImpl(CmpInst::Predicate Pred) {
+ unsigned Bits = 4;
+ EnumerateTwoConstantRanges(
+ Bits, [&](const ConstantRange &CR1, const ConstantRange &CR2) {
+ bool Exhaustive = true;
+ ForeachNumInConstantRange(CR1, [&](const APInt &N1) {
+ ForeachNumInConstantRange(
+ CR2, [&](const APInt &N2) { Exhaustive &= icmp(Pred, N1, N2); });
+ });
+ EXPECT_EQ(CR1.icmp(Pred, CR2), Exhaustive);
+ });
+}
+
+TEST(ConstantRange, ICmp) {
+ for (auto Pred : seq<unsigned>(CmpInst::Predicate::FIRST_ICMP_PREDICATE,
+ 1 + CmpInst::Predicate::LAST_ICMP_PREDICATE))
+ ICmpTestImpl((CmpInst::Predicate)Pred);
+}
+
TEST(ConstantRange, MakeGuaranteedNoWrapRegion) {
const int IntMin4Bits = 8;
const int IntMax4Bits = 7;