summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR/ConstantRangeTest.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2019-11-07 01:16:01 +0300
committerRoman Lebedev <lebedev.ri@gmail.com>2019-11-07 01:30:53 +0300
commitb5ddcb9f1e41b142f89110fc9be78b3c6997f090 (patch)
treec9384b9f8bc780e530a71cfc3bd648b568793e1b /llvm/unittests/IR/ConstantRangeTest.cpp
parent76aee8a389447409905c58b178b0554c9bae8a0a (diff)
downloadbcm5719-llvm-b5ddcb9f1e41b142f89110fc9be78b3c6997f090.tar.gz
bcm5719-llvm-b5ddcb9f1e41b142f89110fc9be78b3c6997f090.zip
[ConstantRange] TestAddWithNo*WrapExhaustive: check that all overflow means empty set
As disscussed in https://reviews.llvm.org/D69918 / https://reviews.llvm.org/D67339 that is an implied postcondition, but it's not really fully tested.
Diffstat (limited to 'llvm/unittests/IR/ConstantRangeTest.cpp')
-rw-r--r--llvm/unittests/IR/ConstantRangeTest.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index 742c5fa9fd9..eb79711250c 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -651,11 +651,13 @@ static void TestAddWithNoSignedWrapExhaustive(Fn1 RangeFn, Fn2 IntFn) {
ConstantRange CR = RangeFn(CR1, CR2);
APInt Min = APInt::getSignedMaxValue(Bits);
APInt Max = APInt::getSignedMinValue(Bits);
+ bool AllOverflow = true;
ForeachNumInConstantRange(CR1, [&](const APInt &N1) {
ForeachNumInConstantRange(CR2, [&](const APInt &N2) {
bool IsOverflow = false;
APInt N = IntFn(IsOverflow, N1, N2);
if (!IsOverflow) {
+ AllOverflow = false;
if (N.slt(Min))
Min = N;
if (N.sgt(Max))
@@ -664,6 +666,9 @@ static void TestAddWithNoSignedWrapExhaustive(Fn1 RangeFn, Fn2 IntFn) {
}
});
});
+
+ EXPECT_EQ(CR.isEmptySet(), AllOverflow);
+
if (!CR1.isSignWrappedSet() && !CR2.isSignWrappedSet()) {
if (Min.sgt(Max)) {
EXPECT_TRUE(CR.isEmptySet());
@@ -684,11 +689,13 @@ static void TestAddWithNoUnsignedWrapExhaustive(Fn1 RangeFn, Fn2 IntFn) {
ConstantRange CR = RangeFn(CR1, CR2);
APInt Min = APInt::getMaxValue(Bits);
APInt Max = APInt::getMinValue(Bits);
+ bool AllOverflow = true;
ForeachNumInConstantRange(CR1, [&](const APInt &N1) {
ForeachNumInConstantRange(CR2, [&](const APInt &N2) {
bool IsOverflow = false;
APInt N = IntFn(IsOverflow, N1, N2);
if (!IsOverflow) {
+ AllOverflow = false;
if (N.ult(Min))
Min = N;
if (N.ugt(Max))
@@ -698,6 +705,8 @@ static void TestAddWithNoUnsignedWrapExhaustive(Fn1 RangeFn, Fn2 IntFn) {
});
});
+ EXPECT_EQ(CR.isEmptySet(), AllOverflow);
+
if (!CR1.isWrappedSet() && !CR2.isWrappedSet()) {
if (Min.ugt(Max)) {
EXPECT_TRUE(CR.isEmptySet());
@@ -722,12 +731,14 @@ static void TestAddWithNoSignedUnsignedWrapExhaustive(Fn1 RangeFn,
APInt UMax = APInt::getMinValue(Bits);
APInt SMin = APInt::getSignedMaxValue(Bits);
APInt SMax = APInt::getSignedMinValue(Bits);
+ bool AllOverflow = true;
ForeachNumInConstantRange(CR1, [&](const APInt &N1) {
ForeachNumInConstantRange(CR2, [&](const APInt &N2) {
bool IsOverflow = false, IsSignedOverflow = false;
APInt N = IntFnSigned(IsSignedOverflow, N1, N2);
(void) IntFnUnsigned(IsOverflow, N1, N2);
if (!IsSignedOverflow && !IsOverflow) {
+ AllOverflow = false;
if (N.slt(SMin))
SMin = N;
if (N.sgt(SMax))
@@ -741,6 +752,8 @@ static void TestAddWithNoSignedUnsignedWrapExhaustive(Fn1 RangeFn,
});
});
+ EXPECT_EQ(CR.isEmptySet(), AllOverflow);
+
if (!CR1.isWrappedSet() && !CR2.isWrappedSet() &&
!CR1.isSignWrappedSet() && !CR2.isSignWrappedSet()) {
if (UMin.ugt(UMax) || SMin.sgt(SMax)) {
OpenPOWER on IntegriCloud