[PATCH] D57983: [ConstantRange] Shl of ConstantRanges considers full-set shifting to last bit position

Marcello Maggioni via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 29 01:38:04 PDT 2019


kariddi updated this revision to Diff 192784.
kariddi added a comment.

Thanks Nuno,

I updated my patch and tried the concept on the Z3 model.

I noticed that there might have been a bug

I think

(define-fun contains ((n Integer) (I Interval)) Bool

  (ite
    (= (L I) (H I))
    (isFullSet I)
    (ite
      (not (isWrappedSet I))
      (and (bvule (L I) n) (bvult n (H I)))
      (or (bvule (L I) n) (bvult n (H I)))
    )
  )

)

should have been

(define-fun contains ((n Integer) (I Interval)) Bool

  (ite
    (= (L I) (H I))
    (isFullSet I)
    (ite
      (not (isWrappedSet I))
      (and (bvuge (L I) n) (bvult n (H I)))
      (or (bvuge (L I) n) (bvult n (H I)))
    )
  )

)

right?


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57983/new/

https://reviews.llvm.org/D57983

Files:
  lib/IR/ConstantRange.cpp
  unittests/IR/ConstantRangeTest.cpp


Index: unittests/IR/ConstantRangeTest.cpp
===================================================================
--- unittests/IR/ConstantRangeTest.cpp
+++ unittests/IR/ConstantRangeTest.cpp
@@ -22,6 +22,7 @@
   static ConstantRange Empty;
   static ConstantRange One;
   static ConstantRange Some;
+  static ConstantRange Some2;
   static ConstantRange Wrap;
 };
 
@@ -53,6 +54,7 @@
 ConstantRange ConstantRangeTest::Empty(16, false);
 ConstantRange ConstantRangeTest::One(APInt(16, 0xa));
 ConstantRange ConstantRangeTest::Some(APInt(16, 0xa), APInt(16, 0xaaa));
+ConstantRange ConstantRangeTest::Some2(APInt(16, 0xfff), APInt(16, 0x8000));
 ConstantRange ConstantRangeTest::Wrap(APInt(16, 0xaaa), APInt(16, 0xa));
 
 TEST_F(ConstantRangeTest, Basics) {
@@ -720,6 +722,9 @@
   EXPECT_EQ(Some.shl(Some), Full);   // TODO: [0xa << 0xa, 0xfc01)
   EXPECT_EQ(Some.shl(Wrap), Full);   // TODO: [0xa, 0x7ff << 0x5 + 1)
   EXPECT_EQ(Wrap.shl(Wrap), Full);
+  EXPECT_EQ(
+      Some2.shl(ConstantRange(APInt(16, 0x1))),
+      ConstantRange(APInt(16, 0xfff << 0x1), APInt(16, 0x7fff << 0x1) + 1));
 }
 
 TEST_F(ConstantRangeTest, Lshr) {
Index: lib/IR/ConstantRange.cpp
===================================================================
--- lib/IR/ConstantRange.cpp
+++ lib/IR/ConstantRange.cpp
@@ -1006,8 +1006,12 @@
   APInt max = getUnsignedMax();
   APInt Other_umax = Other.getUnsignedMax();
 
+  // If we are shifting by maximum amount of
+  // zero return return the original range.
+  if (!Other.isWrappedSet() && Other_umax.isNullValue())
+    return *this;
   // there's overflow!
-  if (Other_umax.uge(max.countLeadingZeros()))
+  if (Other_umax.ugt(max.countLeadingZeros()))
     return getFull();
 
   // FIXME: implement the other tricky cases


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57983.192784.patch
Type: text/x-patch
Size: 1750 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190329/7552baa4/attachment.bin>


More information about the llvm-commits mailing list