@@ -58,6 +58,60 @@ static void ForeachNumInConstantRange(const ConstantRange &CR, Fn TestFn) {
58
58
}
59
59
}
60
60
61
+ template <typename Fn1, typename Fn2>
62
+ static void TestUnsignedBinOpExhaustive (Fn1 RangeFn, Fn2 IntFn) {
63
+ unsigned Bits = 4 ;
64
+ EnumerateTwoConstantRanges (Bits, [&](const ConstantRange &CR1,
65
+ const ConstantRange &CR2) {
66
+ ConstantRange CR = RangeFn (CR1, CR2);
67
+ if (CR1.isEmptySet () || CR2.isEmptySet ()) {
68
+ EXPECT_TRUE (CR.isEmptySet ());
69
+ return ;
70
+ }
71
+
72
+ APInt Min = APInt::getMaxValue (Bits);
73
+ APInt Max = APInt::getMinValue (Bits);
74
+ ForeachNumInConstantRange (CR1, [&](const APInt &N1) {
75
+ ForeachNumInConstantRange (CR2, [&](const APInt &N2) {
76
+ APInt N = IntFn (N1, N2);
77
+ if (N.ult (Min))
78
+ Min = N;
79
+ if (N.ugt (Max))
80
+ Max = N;
81
+ });
82
+ });
83
+
84
+ EXPECT_EQ (ConstantRange::getNonEmpty (Min, Max + 1 ), CR);
85
+ });
86
+ }
87
+
88
+ template <typename Fn1, typename Fn2>
89
+ static void TestSignedBinOpExhaustive (Fn1 RangeFn, Fn2 IntFn) {
90
+ unsigned Bits = 4 ;
91
+ EnumerateTwoConstantRanges (Bits, [&](const ConstantRange &CR1,
92
+ const ConstantRange &CR2) {
93
+ ConstantRange CR = RangeFn (CR1, CR2);
94
+ if (CR1.isEmptySet () || CR2.isEmptySet ()) {
95
+ EXPECT_TRUE (CR.isEmptySet ());
96
+ return ;
97
+ }
98
+
99
+ APInt Min = APInt::getSignedMaxValue (Bits);
100
+ APInt Max = APInt::getSignedMinValue (Bits);
101
+ ForeachNumInConstantRange (CR1, [&](const APInt &N1) {
102
+ ForeachNumInConstantRange (CR2, [&](const APInt &N2) {
103
+ APInt N = IntFn (N1, N2);
104
+ if (N.slt (Min))
105
+ Min = N;
106
+ if (N.sgt (Max))
107
+ Max = N;
108
+ });
109
+ });
110
+
111
+ EXPECT_EQ (ConstantRange::getNonEmpty (Min, Max + 1 ), CR);
112
+ });
113
+ }
114
+
61
115
ConstantRange ConstantRangeTest::Full (16 , true );
62
116
ConstantRange ConstantRangeTest::Empty (16 , false );
63
117
ConstantRange ConstantRangeTest::One (APInt(16 , 0xa ));
@@ -1647,60 +1701,6 @@ TEST_F(ConstantRangeTest, Negative) {
1647
1701
});
1648
1702
}
1649
1703
1650
- template <typename Fn1, typename Fn2>
1651
- static void TestUnsignedBinOpExhaustive (Fn1 RangeFn, Fn2 IntFn) {
1652
- unsigned Bits = 4 ;
1653
- EnumerateTwoConstantRanges (Bits, [&](const ConstantRange &CR1,
1654
- const ConstantRange &CR2) {
1655
- ConstantRange CR = RangeFn (CR1, CR2);
1656
- if (CR1.isEmptySet () || CR2.isEmptySet ()) {
1657
- EXPECT_TRUE (CR.isEmptySet ());
1658
- return ;
1659
- }
1660
-
1661
- APInt Min = APInt::getMaxValue (Bits);
1662
- APInt Max = APInt::getMinValue (Bits);
1663
- ForeachNumInConstantRange (CR1, [&](const APInt &N1) {
1664
- ForeachNumInConstantRange (CR2, [&](const APInt &N2) {
1665
- APInt N = IntFn (N1, N2);
1666
- if (N.ult (Min))
1667
- Min = N;
1668
- if (N.ugt (Max))
1669
- Max = N;
1670
- });
1671
- });
1672
-
1673
- EXPECT_EQ (ConstantRange::getNonEmpty (Min, Max + 1 ), CR);
1674
- });
1675
- }
1676
-
1677
- template <typename Fn1, typename Fn2>
1678
- static void TestSignedBinOpExhaustive (Fn1 RangeFn, Fn2 IntFn) {
1679
- unsigned Bits = 4 ;
1680
- EnumerateTwoConstantRanges (Bits, [&](const ConstantRange &CR1,
1681
- const ConstantRange &CR2) {
1682
- ConstantRange CR = RangeFn (CR1, CR2);
1683
- if (CR1.isEmptySet () || CR2.isEmptySet ()) {
1684
- EXPECT_TRUE (CR.isEmptySet ());
1685
- return ;
1686
- }
1687
-
1688
- APInt Min = APInt::getSignedMaxValue (Bits);
1689
- APInt Max = APInt::getSignedMinValue (Bits);
1690
- ForeachNumInConstantRange (CR1, [&](const APInt &N1) {
1691
- ForeachNumInConstantRange (CR2, [&](const APInt &N2) {
1692
- APInt N = IntFn (N1, N2);
1693
- if (N.slt (Min))
1694
- Min = N;
1695
- if (N.sgt (Max))
1696
- Max = N;
1697
- });
1698
- });
1699
-
1700
- EXPECT_EQ (ConstantRange::getNonEmpty (Min, Max + 1 ), CR);
1701
- });
1702
- }
1703
-
1704
1704
TEST_F (ConstantRangeTest, UAddSat) {
1705
1705
TestUnsignedBinOpExhaustive (
1706
1706
[](const ConstantRange &CR1, const ConstantRange &CR2) {
0 commit comments