Skip to content

ConstRange: exhaustively test makeExactICmpRegion #127058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions llvm/lib/IR/ConstantRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,10 @@ ConstantRange ConstantRange::makeExactICmpRegion(CmpInst::Predicate Pred,
const APInt &C) {
// Computes the exact range that is equal to both the constant ranges returned
// by makeAllowedICmpRegion and makeSatisfyingICmpRegion. This is always true
// when RHS is a singleton such as an APInt and so the assert is valid.
// However for non-singleton RHS, for example ult [2,5) makeAllowedICmpRegion
// returns [0,4) but makeSatisfyICmpRegion returns [0,2).
// when RHS is a singleton such as an APInt. However for non-singleton RHS,
// for example ult [2,5) makeAllowedICmpRegion returns [0,4) but
// makeSatisfyICmpRegion returns [0,2).
//
assert(makeAllowedICmpRegion(Pred, C) == makeSatisfyingICmpRegion(Pred, C));
return makeAllowedICmpRegion(Pred, C);
}

Expand Down
11 changes: 11 additions & 0 deletions llvm/unittests/IR/ConstantRangeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,17 @@ TEST(ConstantRange, MakeAllowedICmpRegion) {
.isEmptySet());
}

TEST(ConstantRange, MakeExactICmpRegion) {
for (unsigned Bits : {1, 4}) {
EnumerateAPInts(Bits, [](const APInt &N) {
for (auto Pred : ICmpInst::predicates()) {
EXPECT_EQ(ConstantRange::makeAllowedICmpRegion(Pred, N),
ConstantRange::makeSatisfyingICmpRegion(Pred, N));
};
});
}
}

TEST(ConstantRange, MakeSatisfyingICmpRegion) {
ConstantRange LowHalf(APInt(8, 0), APInt(8, 128));
ConstantRange HighHalf(APInt(8, 128), APInt(8, 0));
Expand Down