[llvm] 54e3bf5 - Revert "[ConstantRange] Improve the implementation of binaryOr"

Douglas Yung via llvm-commits llvm-commits at lists.llvm.org
Fri May 20 10:24:31 PDT 2022


Author: Douglas Yung
Date: 2022-05-20T10:24:20-07:00
New Revision: 54e3bf5f37d67441dafbc66838a54a385293a2e1

URL: https://github.com/llvm/llvm-project/commit/54e3bf5f37d67441dafbc66838a54a385293a2e1
DIFF: https://github.com/llvm/llvm-project/commit/54e3bf5f37d67441dafbc66838a54a385293a2e1.diff

LOG: Revert "[ConstantRange] Improve the implementation of binaryOr"

This reverts commit 6990e7477d24ff585ae86549f5280f0be65422a6.

This change was causing the test compiler-rt/test/fuzzer/merge_two_step.test to fail on
our internal bot as well as other build bots such as https://lab.llvm.org/buildbot/#/builders/179/builds/3712.

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 be6386c571b59..c3915cee00476 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -1410,13 +1410,14 @@ ConstantRange ConstantRange::binaryOr(const ConstantRange &Other) const {
   if (isEmptySet() || Other.isEmptySet())
     return getEmpty();
 
-  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);
+  // 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 ConstantRange::binaryXor(const ConstantRange &Other) const {

diff  --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index 8a543b1f7df41..ffd0f004c7575 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -2560,44 +2560,6 @@ TEST_F(ConstantRangeTest, binaryAnd) {
       CheckSingleElementsOnly);
 }
 
-TEST_F(ConstantRangeTest, binaryOr) {
-  // Single element ranges.
-  ConstantRange R16(APInt(8, 16));
-  ConstantRange R20(APInt(8, 20));
-  EXPECT_EQ(*R16.binaryOr(R16).getSingleElement(), APInt(8, 16));
-  EXPECT_EQ(*R16.binaryOr(R20).getSingleElement(), APInt(8, 16 | 20));
-
-  ConstantRange R16_32(APInt(8, 16), APInt(8, 32));
-  // 'Or' with a high bits mask.
-  // KnownBits estimate is important, otherwise the maximum included element
-  // would be 2^8 - 1.
-  ConstantRange R32(APInt(8, 32));
-  ConstantRange R48_64(APInt(8, 48), APInt(8, 64));
-  EXPECT_EQ(R16_32.binaryOr(R32), R48_64);
-  EXPECT_EQ(R32.binaryOr(R16_32), R48_64);
-  // 'Or' with a low bits mask.
-  ConstantRange R4(APInt(8, 4));
-  ConstantRange R0_16(APInt(8, 0), APInt(8, 16));
-  ConstantRange R4_16(APInt(8, 4), APInt(8, 16));
-  EXPECT_EQ(R0_16.binaryOr(R4), R4_16);
-  EXPECT_EQ(R4.binaryOr(R0_16), R4_16);
-
-  // Ranges with more than one element. Handled conservatively for now.
-  // UMaxUMin estimate is important, otherwise the lower bound would be zero.
-  ConstantRange R0_64(APInt(8, 0), APInt(8, 64));
-  ConstantRange R5_32(APInt(8, 5), APInt(8, 32));
-  ConstantRange R5_64(APInt(8, 5), APInt(8, 64));
-  EXPECT_EQ(R0_64.binaryOr(R5_32), R5_64);
-  EXPECT_EQ(R5_32.binaryOr(R0_64), R5_64);
-
-  TestBinaryOpExhaustive(
-      [](const ConstantRange &CR1, const ConstantRange &CR2) {
-        return CR1.binaryOr(CR2);
-      },
-      [](const APInt &N1, const APInt &N2) { return N1 | N2; }, PreferSmallest,
-      CheckSingleElementsOnly);
-}
-
 TEST_F(ConstantRangeTest, binaryXor) {
   // Single element ranges.
   ConstantRange R16(APInt(8, 16));


        


More information about the llvm-commits mailing list