diff options
author | Alexander Shaposhnikov <ashaposhnikov@google.com> | 2022-05-19 20:25:47 +0000 |
---|---|---|
committer | Alexander Shaposhnikov <ashaposhnikov@google.com> | 2022-05-19 21:39:19 +0000 |
commit | 6990e7477d24ff585ae86549f5280f0be65422a6 (patch) | |
tree | e39cae44afca4bd2bd441fd2ef9181910da625cd /llvm/lib/IR/ConstantRange.cpp | |
parent | 221b7a45833dcee19964924ec34fd2173c2b68a4 (diff) | |
download | llvm-6990e7477d24ff585ae86549f5280f0be65422a6.zip llvm-6990e7477d24ff585ae86549f5280f0be65422a6.tar.gz llvm-6990e7477d24ff585ae86549f5280f0be65422a6.tar.bz2 |
[ConstantRange] Improve the implementation of binaryOr
This diff adjusts binaryOr to take advantage of the analysis
based on KnownBits.
Differential revision: https://reviews.llvm.org/D125933
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.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp index c3915ce..be6386c 100644 --- a/llvm/lib/IR/ConstantRange.cpp +++ b/llvm/lib/IR/ConstantRange.cpp @@ -1410,14 +1410,13 @@ ConstantRange ConstantRange::binaryOr(const ConstantRange &Other) const { if (isEmptySet() || Other.isEmptySet()) return getEmpty(); - // Use APInt's implementation of OR for single element ranges. - if (isSingleElement() && Other.isSingleElement()) - return {*getSingleElement() | *Other.getSingleElement()}; - - // TODO: replace this with something less conservative - - APInt umax = APIntOps::umax(getUnsignedMin(), Other.getUnsignedMin()); - return getNonEmpty(std::move(umax), APInt::getZero(getBitWidth())); + ConstantRange KnownBitsRange = + fromKnownBits(toKnownBits() | Other.toKnownBits(), false); + // Upper wrapped range. + ConstantRange UMaxUMinRange = + getNonEmpty(APIntOps::umax(getUnsignedMin(), Other.getUnsignedMin()), + APInt::getZero(getBitWidth())); + return KnownBitsRange.intersectWith(UMaxUMinRange); } ConstantRange ConstantRange::binaryXor(const ConstantRange &Other) const { |