@@ -25,26 +25,20 @@ using BinaryBitsFn =
25
25
using BinaryIntFn =
26
26
llvm::function_ref<std::optional<APInt>(const APInt &, const APInt &)>;
27
27
28
- static testing::AssertionResult isCorrect (const KnownBits &Exact,
29
- const KnownBits &Computed,
30
- ArrayRef<KnownBits> Inputs) {
31
- if (Computed.Zero .isSubsetOf (Exact.Zero ) &&
32
- Computed.One .isSubsetOf (Exact.One ))
33
- return testing::AssertionSuccess ();
34
-
35
- testing::AssertionResult Result = testing::AssertionFailure ();
36
- Result << " Inputs = " ;
37
- for (const KnownBits &Input : Inputs)
38
- Result << Input << " , " ;
39
- Result << " Computed = " << Computed << " , Exact = " << Exact;
40
- return Result;
41
- }
42
-
43
- static testing::AssertionResult isOptimal (const KnownBits &Exact,
44
- const KnownBits &Computed,
45
- ArrayRef<KnownBits> Inputs) {
46
- if (Computed == Exact)
47
- return testing::AssertionSuccess ();
28
+ static testing::AssertionResult checkResult (const KnownBits &Exact,
29
+ const KnownBits &Computed,
30
+ ArrayRef<KnownBits> Inputs,
31
+ bool CheckOptimality) {
32
+ if (CheckOptimality) {
33
+ // We generally don't want to return conflicting known bits, even if it is
34
+ // legal for always poison results.
35
+ if (Exact.hasConflict () || Computed == Exact)
36
+ return testing::AssertionSuccess ();
37
+ } else {
38
+ if (Computed.Zero .isSubsetOf (Exact.Zero ) &&
39
+ Computed.One .isSubsetOf (Exact.One ))
40
+ return testing::AssertionSuccess ();
41
+ }
48
42
49
43
testing::AssertionResult Result = testing::AssertionFailure ();
50
44
Result << " Inputs = " ;
@@ -71,12 +65,7 @@ static void testUnaryOpExhaustive(UnaryBitsFn BitsFn, UnaryIntFn IntFn,
71
65
});
72
66
73
67
EXPECT_TRUE (!Computed.hasConflict ());
74
- EXPECT_TRUE (isCorrect (Exact, Computed, Known));
75
- // We generally don't want to return conflicting known bits, even if it is
76
- // legal for always poison results.
77
- if (CheckOptimality && !Exact.hasConflict ()) {
78
- EXPECT_TRUE (isOptimal (Exact, Computed, Known));
79
- }
68
+ EXPECT_TRUE (checkResult (Exact, Computed, Known, CheckOptimality));
80
69
});
81
70
}
82
71
}
@@ -102,12 +91,8 @@ static void testBinaryOpExhaustive(BinaryBitsFn BitsFn, BinaryIntFn IntFn,
102
91
});
103
92
104
93
EXPECT_TRUE (!Computed.hasConflict ());
105
- EXPECT_TRUE (isCorrect (Exact, Computed, {Known1, Known2}));
106
- // We generally don't want to return conflicting known bits, even if it
107
- // is legal for always poison results.
108
- if (CheckOptimality && !Exact.hasConflict ()) {
109
- EXPECT_TRUE (isOptimal (Exact, Computed, {Known1, Known2}));
110
- }
94
+ EXPECT_TRUE (
95
+ checkResult (Exact, Computed, {Known1, Known2}, CheckOptimality));
111
96
// In some cases we choose to return zero if the result is always
112
97
// poison.
113
98
if (RefinePoisonToZero && Exact.hasConflict ()) {
@@ -201,23 +186,23 @@ static void TestAddSubExhaustive(bool IsAdd) {
201
186
202
187
KnownBits KnownComputed = KnownBits::computeForAddSub (
203
188
IsAdd, /* NSW=*/ false , /* NUW=*/ false , Known1, Known2);
204
- EXPECT_TRUE (isOptimal (Known, KnownComputed, {Known1, Known2}));
189
+ EXPECT_TRUE (checkResult (Known, KnownComputed, {Known1, Known2},
190
+ /* CheckOptimality=*/ true ));
205
191
206
192
KnownBits KnownNSWComputed = KnownBits::computeForAddSub (
207
193
IsAdd, /* NSW=*/ true , /* NUW=*/ false , Known1, Known2);
208
- if (!KnownNSW. hasConflict ())
209
- EXPECT_TRUE ( isOptimal (KnownNSW, KnownNSWComputed, {Known1, Known2} ));
194
+ EXPECT_TRUE ( checkResult (KnownNSW, KnownNSWComputed, {Known1, Known2},
195
+ /* CheckOptimality= */ true ));
210
196
211
197
KnownBits KnownNUWComputed = KnownBits::computeForAddSub (
212
198
IsAdd, /* NSW=*/ false , /* NUW=*/ true , Known1, Known2);
213
- if (!KnownNUW. hasConflict ())
214
- EXPECT_TRUE ( isOptimal (KnownNUW, KnownNUWComputed, {Known1, Known2} ));
199
+ EXPECT_TRUE ( checkResult (KnownNUW, KnownNUWComputed, {Known1, Known2},
200
+ /* CheckOptimality= */ true ));
215
201
216
202
KnownBits KnownNSWAndNUWComputed = KnownBits::computeForAddSub (
217
203
IsAdd, /* NSW=*/ true , /* NUW=*/ true , Known1, Known2);
218
- if (!KnownNSWAndNUW.hasConflict ())
219
- EXPECT_TRUE (isOptimal (KnownNSWAndNUW, KnownNSWAndNUWComputed,
220
- {Known1, Known2}));
204
+ EXPECT_TRUE (checkResult (KnownNSWAndNUW, KnownNSWAndNUWComputed,
205
+ {Known1, Known2}, /* CheckOptimality=*/ true ));
221
206
});
222
207
});
223
208
}
0 commit comments