diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-23 18:00:02 +0000 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-04-23 18:00:02 +0000 |
commit | 4a52397965b7fdd168cc0f96f82e859b6139ce4f (patch) | |
tree | ee31e76a027ae944678db769212630a54ff24e91 | |
parent | c464dddccbd8b7cf4fc6cf51126ab559cd34749e (diff) | |
download | bcm5719-llvm-4a52397965b7fdd168cc0f96f82e859b6139ce4f.tar.gz bcm5719-llvm-4a52397965b7fdd168cc0f96f82e859b6139ce4f.zip |
[ConstantRangeTest] Move helper methods; NFC
Move Test(Unsigned|Signed)BinOpExhaustive() towards the top of the
file, so they're easier to reuse.
llvm-svn: 359018
-rw-r--r-- | llvm/unittests/IR/ConstantRangeTest.cpp | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp index 3306fe3ea69..8e378ff3c75 100644 --- a/llvm/unittests/IR/ConstantRangeTest.cpp +++ b/llvm/unittests/IR/ConstantRangeTest.cpp @@ -58,6 +58,60 @@ static void ForeachNumInConstantRange(const ConstantRange &CR, Fn TestFn) { } } +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) { |