aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantRange.cpp
diff options
context:
space:
mode:
authorAlexander Shaposhnikov <ashaposhnikov@google.com>2022-05-17 21:30:44 +0000
committerAlexander Shaposhnikov <ashaposhnikov@google.com>2022-05-17 22:06:03 +0000
commit0f4d9f9b71be8a95cd24534bf914fc9a6fb0ff30 (patch)
tree51524f0afeaeecc61e3c99ef2a4767a91d5a9bcc /llvm/lib/IR/ConstantRange.cpp
parentc907d6e0e9fd8fafd49e4d0f9e584f58bbac5ead (diff)
downloadllvm-0f4d9f9b71be8a95cd24534bf914fc9a6fb0ff30.zip
llvm-0f4d9f9b71be8a95cd24534bf914fc9a6fb0ff30.tar.gz
llvm-0f4d9f9b71be8a95cd24534bf914fc9a6fb0ff30.tar.bz2
[ConstantRange] Improve the implementation of binaryAnd
This diff adjusts binaryAnd to take advantage of the analysis based on KnownBits. Differential revision: https://reviews.llvm.org/D125603 Test plan: 1/ ninja check-llvm 2/ ninja check-llvm-unit
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r--llvm/lib/IR/ConstantRange.cpp20
1 files changed, 8 insertions, 12 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index ce2e537..fb44ca9 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -1386,23 +1386,19 @@ ConstantRange ConstantRange::binaryNot() const {
return ConstantRange(APInt::getAllOnes(getBitWidth())).sub(*this);
}
-ConstantRange
-ConstantRange::binaryAnd(const ConstantRange &Other) const {
+ConstantRange ConstantRange::binaryAnd(const ConstantRange &Other) const {
if (isEmptySet() || Other.isEmptySet())
return getEmpty();
- // Use APInt's implementation of AND for single element ranges.
- if (isSingleElement() && Other.isSingleElement())
- return {*getSingleElement() & *Other.getSingleElement()};
-
- // TODO: replace this with something less conservative
-
- APInt umin = APIntOps::umin(Other.getUnsignedMax(), getUnsignedMax());
- return getNonEmpty(APInt::getZero(getBitWidth()), std::move(umin) + 1);
+ ConstantRange KnownBitsRange =
+ fromKnownBits(toKnownBits() & Other.toKnownBits(), false);
+ ConstantRange UMinUMaxRange =
+ getNonEmpty(APInt::getZero(getBitWidth()),
+ APIntOps::umin(Other.getUnsignedMax(), getUnsignedMax()) + 1);
+ return KnownBitsRange.intersectWith(UMinUMaxRange);
}
-ConstantRange
-ConstantRange::binaryOr(const ConstantRange &Other) const {
+ConstantRange ConstantRange::binaryOr(const ConstantRange &Other) const {
if (isEmptySet() || Other.isEmptySet())
return getEmpty();