From: Nikita Popov Date: Tue, 23 Apr 2019 18:00:02 +0000 (+0000) Subject: [ConstantRangeTest] Move helper methods; NFC X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4a52397965b7fdd168cc0f96f82e859b6139ce4f;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp index 3306fe3..8e378ff 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 +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 +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 -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 -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) {