Skip to content

Commit 8eba128

Browse files
authored
ConstRange: exhaustively test makeExactICmpRegion (#127058)
Exhaustively test makeExactICmpRegion by comparing makeAllowedICmpRegion against makeSatisfyingICmpRegion for all APInts.
1 parent 9c9157b commit 8eba128

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

llvm/lib/IR/ConstantRange.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,10 @@ ConstantRange ConstantRange::makeExactICmpRegion(CmpInst::Predicate Pred,
170170
const APInt &C) {
171171
// Computes the exact range that is equal to both the constant ranges returned
172172
// by makeAllowedICmpRegion and makeSatisfyingICmpRegion. This is always true
173-
// when RHS is a singleton such as an APInt and so the assert is valid.
174-
// However for non-singleton RHS, for example ult [2,5) makeAllowedICmpRegion
175-
// returns [0,4) but makeSatisfyICmpRegion returns [0,2).
173+
// when RHS is a singleton such as an APInt. However for non-singleton RHS,
174+
// for example ult [2,5) makeAllowedICmpRegion returns [0,4) but
175+
// makeSatisfyICmpRegion returns [0,2).
176176
//
177-
assert(makeAllowedICmpRegion(Pred, C) == makeSatisfyingICmpRegion(Pred, C));
178177
return makeAllowedICmpRegion(Pred, C);
179178
}
180179

llvm/unittests/IR/ConstantRangeTest.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,17 @@ TEST(ConstantRange, MakeAllowedICmpRegionEdgeCases) {
16621662
.isFullSet());
16631663
}
16641664

1665+
TEST(ConstantRange, MakeExactICmpRegion) {
1666+
for (unsigned Bits : {1, 4}) {
1667+
EnumerateAPInts(Bits, [](const APInt &N) {
1668+
for (auto Pred : ICmpInst::predicates()) {
1669+
EXPECT_EQ(ConstantRange::makeAllowedICmpRegion(Pred, N),
1670+
ConstantRange::makeSatisfyingICmpRegion(Pred, N));
1671+
};
1672+
});
1673+
}
1674+
}
1675+
16651676
TEST(ConstantRange, MakeSatisfyingICmpRegion) {
16661677
ConstantRange LowHalf(APInt(8, 0), APInt(8, 128));
16671678
ConstantRange HighHalf(APInt(8, 128), APInt(8, 0));

0 commit comments

Comments
 (0)