Skip to content

Commit b6088f7

Browse files
committed
[ConstantRange] Handle wrapping range in binaryNot()
We don't need any special handling for wrapping ranges (or empty ranges for that matter). The sub() call will already compute a correct and precise range. We only need to adjust the test expectation: We're now computing an optimal result, rather than an unsigned envelope.
1 parent 1611e54 commit b6088f7

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

llvm/lib/IR/ConstantRange.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,12 +1256,6 @@ ConstantRange ConstantRange::srem(const ConstantRange &RHS) const {
12561256
}
12571257

12581258
ConstantRange ConstantRange::binaryNot() const {
1259-
if (isEmptySet())
1260-
return getEmpty();
1261-
1262-
if (isWrappedSet())
1263-
return getFull();
1264-
12651259
return ConstantRange(APInt::getAllOnesValue(getBitWidth())).sub(*this);
12661260
}
12671261

llvm/unittests/IR/ConstantRangeTest.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,26 +2388,24 @@ TEST_F(ConstantRangeTest, binaryXor) {
23882388
}
23892389

23902390
TEST_F(ConstantRangeTest, binaryNot) {
2391-
// TODO: Improve binaryNot() implementation to remove the need for
2392-
// PreferSmallestUnsigned.
23932391
TestUnaryOpExhaustive(
23942392
[](const ConstantRange &CR) { return CR.binaryNot(); },
23952393
[](const APInt &N) { return ~N; },
2396-
PreferSmallestUnsigned);
2394+
PreferSmallest);
23972395
TestUnaryOpExhaustive(
23982396
[](const ConstantRange &CR) {
23992397
return CR.binaryXor(
24002398
ConstantRange(APInt::getAllOnesValue(CR.getBitWidth())));
24012399
},
24022400
[](const APInt &N) { return ~N; },
2403-
PreferSmallestUnsigned);
2401+
PreferSmallest);
24042402
TestUnaryOpExhaustive(
24052403
[](const ConstantRange &CR) {
24062404
return ConstantRange(APInt::getAllOnesValue(CR.getBitWidth()))
24072405
.binaryXor(CR);
24082406
},
24092407
[](const APInt &N) { return ~N; },
2410-
PreferSmallestUnsigned);
2408+
PreferSmallest);
24112409
}
24122410

24132411
} // anonymous namespace

0 commit comments

Comments
 (0)