[llvm] r359018 - [ConstantRangeTest] Move helper methods; NFC
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 23 11:00:03 PDT 2019
Author: nikic
Date: Tue Apr 23 11:00:02 2019
New Revision: 359018
URL: http://llvm.org/viewvc/llvm-project?rev=359018&view=rev
Log:
[ConstantRangeTest] Move helper methods; NFC
Move Test(Unsigned|Signed)BinOpExhaustive() towards the top of the
file, so they're easier to reuse.
Modified:
llvm/trunk/unittests/IR/ConstantRangeTest.cpp
Modified: llvm/trunk/unittests/IR/ConstantRangeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ConstantRangeTest.cpp?rev=359018&r1=359017&r2=359018&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/ConstantRangeTest.cpp (original)
+++ llvm/trunk/unittests/IR/ConstantRangeTest.cpp Tue Apr 23 11:00:02 2019
@@ -58,6 +58,60 @@ static void ForeachNumInConstantRange(co
}
}
+template<typename Fn1, typename Fn2>
+static void TestUnsignedBinOpExhaustive(Fn1 RangeFn, Fn2 IntFn) {
+ unsigned Bits = 4;
+ EnumerateTwoConstantRanges(Bits, [&](const ConstantRange &CR1,
+ const ConstantRange &CR2) {
+ ConstantRange CR = RangeFn(CR1, CR2);
+ if (CR1.isEmptySet() || CR2.isEmptySet()) {
+ EXPECT_TRUE(CR.isEmptySet());
+ return;
+ }
+
+ APInt Min = APInt::getMaxValue(Bits);
+ APInt Max = APInt::getMinValue(Bits);
+ ForeachNumInConstantRange(CR1, [&](const APInt &N1) {
+ ForeachNumInConstantRange(CR2, [&](const APInt &N2) {
+ APInt N = IntFn(N1, N2);
+ if (N.ult(Min))
+ Min = N;
+ if (N.ugt(Max))
+ Max = N;
+ });
+ });
+
+ EXPECT_EQ(ConstantRange::getNonEmpty(Min, Max + 1), CR);
+ });
+}
+
+template<typename Fn1, typename Fn2>
+static void TestSignedBinOpExhaustive(Fn1 RangeFn, Fn2 IntFn) {
+ unsigned Bits = 4;
+ EnumerateTwoConstantRanges(Bits, [&](const ConstantRange &CR1,
+ const ConstantRange &CR2) {
+ ConstantRange CR = RangeFn(CR1, CR2);
+ if (CR1.isEmptySet() || CR2.isEmptySet()) {
+ EXPECT_TRUE(CR.isEmptySet());
+ return;
+ }
+
+ APInt Min = APInt::getSignedMaxValue(Bits);
+ APInt Max = APInt::getSignedMinValue(Bits);
+ ForeachNumInConstantRange(CR1, [&](const APInt &N1) {
+ ForeachNumInConstantRange(CR2, [&](const APInt &N2) {
+ APInt N = IntFn(N1, N2);
+ if (N.slt(Min))
+ Min = N;
+ if (N.sgt(Max))
+ Max = N;
+ });
+ });
+
+ EXPECT_EQ(ConstantRange::getNonEmpty(Min, Max + 1), CR);
+ });
+}
+
ConstantRange ConstantRangeTest::Full(16, true);
ConstantRange ConstantRangeTest::Empty(16, false);
ConstantRange ConstantRangeTest::One(APInt(16, 0xa));
@@ -1647,60 +1701,6 @@ TEST_F(ConstantRangeTest, Negative) {
});
}
-template<typename Fn1, typename Fn2>
-static void TestUnsignedBinOpExhaustive(Fn1 RangeFn, Fn2 IntFn) {
- unsigned Bits = 4;
- EnumerateTwoConstantRanges(Bits, [&](const ConstantRange &CR1,
- const ConstantRange &CR2) {
- ConstantRange CR = RangeFn(CR1, CR2);
- if (CR1.isEmptySet() || CR2.isEmptySet()) {
- EXPECT_TRUE(CR.isEmptySet());
- return;
- }
-
- APInt Min = APInt::getMaxValue(Bits);
- APInt Max = APInt::getMinValue(Bits);
- ForeachNumInConstantRange(CR1, [&](const APInt &N1) {
- ForeachNumInConstantRange(CR2, [&](const APInt &N2) {
- APInt N = IntFn(N1, N2);
- if (N.ult(Min))
- Min = N;
- if (N.ugt(Max))
- Max = N;
- });
- });
-
- EXPECT_EQ(ConstantRange::getNonEmpty(Min, Max + 1), CR);
- });
-}
-
-template<typename Fn1, typename Fn2>
-static void TestSignedBinOpExhaustive(Fn1 RangeFn, Fn2 IntFn) {
- unsigned Bits = 4;
- EnumerateTwoConstantRanges(Bits, [&](const ConstantRange &CR1,
- const ConstantRange &CR2) {
- ConstantRange CR = RangeFn(CR1, CR2);
- if (CR1.isEmptySet() || CR2.isEmptySet()) {
- EXPECT_TRUE(CR.isEmptySet());
- return;
- }
-
- APInt Min = APInt::getSignedMaxValue(Bits);
- APInt Max = APInt::getSignedMinValue(Bits);
- ForeachNumInConstantRange(CR1, [&](const APInt &N1) {
- ForeachNumInConstantRange(CR2, [&](const APInt &N2) {
- APInt N = IntFn(N1, N2);
- if (N.slt(Min))
- Min = N;
- if (N.sgt(Max))
- Max = N;
- });
- });
-
- EXPECT_EQ(ConstantRange::getNonEmpty(Min, Max + 1), CR);
- });
-}
-
TEST_F(ConstantRangeTest, UAddSat) {
TestUnsignedBinOpExhaustive(
[](const ConstantRange &CR1, const ConstantRange &CR2) {
More information about the llvm-commits
mailing list