[llvm] b6088f7 - [ConstantRange] Handle wrapping range in binaryNot()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 20 12:46:16 PST 2021
Author: Nikita Popov
Date: 2021-02-20T21:45:59+01:00
New Revision: b6088f7465a9a6691d5d237e9c0eb002734da3bf
URL: https://github.com/llvm/llvm-project/commit/b6088f7465a9a6691d5d237e9c0eb002734da3bf
DIFF: https://github.com/llvm/llvm-project/commit/b6088f7465a9a6691d5d237e9c0eb002734da3bf.diff
LOG: [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.
Added:
Modified:
llvm/lib/IR/ConstantRange.cpp
llvm/unittests/IR/ConstantRangeTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index 4b0ad1bd25a0..275996dd02d8 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -1256,12 +1256,6 @@ ConstantRange ConstantRange::srem(const ConstantRange &RHS) const {
}
ConstantRange ConstantRange::binaryNot() const {
- if (isEmptySet())
- return getEmpty();
-
- if (isWrappedSet())
- return getFull();
-
return ConstantRange(APInt::getAllOnesValue(getBitWidth())).sub(*this);
}
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index 77f07a8729b3..2b9c56b4134f 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -2388,26 +2388,24 @@ TEST_F(ConstantRangeTest, binaryXor) {
}
TEST_F(ConstantRangeTest, binaryNot) {
- // TODO: Improve binaryNot() implementation to remove the need for
- // PreferSmallestUnsigned.
TestUnaryOpExhaustive(
[](const ConstantRange &CR) { return CR.binaryNot(); },
[](const APInt &N) { return ~N; },
- PreferSmallestUnsigned);
+ PreferSmallest);
TestUnaryOpExhaustive(
[](const ConstantRange &CR) {
return CR.binaryXor(
ConstantRange(APInt::getAllOnesValue(CR.getBitWidth())));
},
[](const APInt &N) { return ~N; },
- PreferSmallestUnsigned);
+ PreferSmallest);
TestUnaryOpExhaustive(
[](const ConstantRange &CR) {
return ConstantRange(APInt::getAllOnesValue(CR.getBitWidth()))
.binaryXor(CR);
},
[](const APInt &N) { return ~N; },
- PreferSmallestUnsigned);
+ PreferSmallest);
}
} // anonymous namespace
More information about the llvm-commits
mailing list