]> granicus.if.org Git - llvm/commitdiff
[ConstantRange] Rename isWrappedSet() to isUpperWrapped()
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 27 Mar 2019 18:19:33 +0000 (18:19 +0000)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 27 Mar 2019 18:19:33 +0000 (18:19 +0000)
Split out from D59749. The current implementation of isWrappedSet()
doesn't do what it says on the tin, and treats ranges like
[X, Max] as wrapping, because they are represented as [X, 0) when
using half-inclusive ranges. This also makes it inconsistent with
the semantics of isSignWrappedSet().

This patch renames isWrappedSet() to isUpperWrapped(), in preparation
for the introduction of a new isWrappedSet() method with corrected
behavior.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357107 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/ConstantRange.h
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
lib/IR/ConstantRange.cpp
unittests/IR/ConstantRangeTest.cpp

index 3ac853f3161858832e514fe4535ce68e478cfb1c..9612890000d97ec72c934efd10d547948a11bf8b 100644 (file)
@@ -163,9 +163,12 @@ public:
   /// Return true if this set contains no members.
   bool isEmptySet() const;
 
-  /// Return true if this set wraps around the top of the range.
-  /// For example: [100, 8).
-  bool isWrappedSet() const;
+  /// Return true if the exclusive upper bound wraps around the unsigned
+  /// domain. Special cases:
+  ///  * Empty set: Not wrapped.
+  ///  * Full set: Not wrapped.
+  ///  * [X, 0): Wrapped.
+  bool isUpperWrapped() const;
 
   /// Return true if this set wraps around the signed domain. Special cases:
   ///  * Empty set: Not wrapped.
index 68994ae8e048208cb4e74756328965d2a3ac6468..acd087a50839004f88a92f0f88321fbf4df14b13 100644 (file)
@@ -8346,7 +8346,7 @@ SDValue SelectionDAGBuilder::lowerRangeToAssertZExt(SelectionDAG &DAG,
     return Op;
 
   ConstantRange CR = getConstantRangeFromMetadata(*Range);
-  if (CR.isFullSet() || CR.isEmptySet() || CR.isWrappedSet())
+  if (CR.isFullSet() || CR.isEmptySet() || CR.isUpperWrapped())
     return Op;
 
   APInt Lo = CR.getUnsignedMin();
index 0c2a3a86597903f14a0e28392b68fa01bafa3b09..896a870bf9074af515ef03a22ba7ed7b9a041522 100644 (file)
@@ -344,7 +344,7 @@ bool ConstantRange::isEmptySet() const {
   return Lower == Upper && Lower.isMinValue();
 }
 
-bool ConstantRange::isWrappedSet() const {
+bool ConstantRange::isUpperWrapped() const {
   return Lower.ugt(Upper);
 }
 
@@ -382,13 +382,13 @@ ConstantRange::isSizeLargerThan(uint64_t MaxSize) const {
 }
 
 APInt ConstantRange::getUnsignedMax() const {
-  if (isFullSet() || isWrappedSet())
+  if (isFullSet() || isUpperWrapped())
     return APInt::getMaxValue(getBitWidth());
   return getUpper() - 1;
 }
 
 APInt ConstantRange::getUnsignedMin() const {
-  if (isFullSet() || (isWrappedSet() && !getUpper().isNullValue()))
+  if (isFullSet() || (isUpperWrapped() && !getUpper().isNullValue()))
     return APInt::getMinValue(getBitWidth());
   return getLower();
 }
@@ -409,7 +409,7 @@ bool ConstantRange::contains(const APInt &V) const {
   if (Lower == Upper)
     return isFullSet();
 
-  if (!isWrappedSet())
+  if (!isUpperWrapped())
     return Lower.ule(V) && V.ult(Upper);
   return Lower.ule(V) || V.ult(Upper);
 }
@@ -418,14 +418,14 @@ bool ConstantRange::contains(const ConstantRange &Other) const {
   if (isFullSet() || Other.isEmptySet()) return true;
   if (isEmptySet() || Other.isFullSet()) return false;
 
-  if (!isWrappedSet()) {
-    if (Other.isWrappedSet())
+  if (!isUpperWrapped()) {
+    if (Other.isUpperWrapped())
       return false;
 
     return Lower.ule(Other.getLower()) && Other.getUpper().ule(Upper);
   }
 
-  if (!Other.isWrappedSet())
+  if (!Other.isUpperWrapped())
     return Other.getUpper().ule(Upper) ||
            Lower.ule(Other.getLower());
 
@@ -452,10 +452,10 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const {
   if (   isEmptySet() || CR.isFullSet()) return *this;
   if (CR.isEmptySet() ||    isFullSet()) return CR;
 
-  if (!isWrappedSet() && CR.isWrappedSet())
+  if (!isUpperWrapped() && CR.isUpperWrapped())
     return CR.intersectWith(*this);
 
-  if (!isWrappedSet() && !CR.isWrappedSet()) {
+  if (!isUpperWrapped() && !CR.isUpperWrapped()) {
     if (Lower.ult(CR.Lower)) {
       if (Upper.ule(CR.Lower))
         return getEmpty();
@@ -474,7 +474,7 @@ ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const {
     return getEmpty();
   }
 
-  if (isWrappedSet() && !CR.isWrappedSet()) {
+  if (isUpperWrapped() && !CR.isUpperWrapped()) {
     if (CR.Lower.ult(Upper)) {
       if (CR.Upper.ult(Upper))
         return CR;
@@ -525,9 +525,9 @@ ConstantRange ConstantRange::unionWith(const ConstantRange &CR) const {
   if (   isFullSet() || CR.isEmptySet()) return *this;
   if (CR.isFullSet() ||    isEmptySet()) return CR;
 
-  if (!isWrappedSet() && CR.isWrappedSet()) return CR.unionWith(*this);
+  if (!isUpperWrapped() && CR.isUpperWrapped()) return CR.unionWith(*this);
 
-  if (!isWrappedSet() && !CR.isWrappedSet()) {
+  if (!isUpperWrapped() && !CR.isUpperWrapped()) {
     if (CR.Upper.ult(Lower) || Upper.ult(CR.Lower)) {
       // If the two ranges are disjoint, find the smaller gap and bridge it.
       APInt d1 = CR.Lower - Upper, d2 = Lower - CR.Upper;
@@ -545,7 +545,7 @@ ConstantRange ConstantRange::unionWith(const ConstantRange &CR) const {
     return ConstantRange(std::move(L), std::move(U));
   }
 
-  if (!CR.isWrappedSet()) {
+  if (!CR.isUpperWrapped()) {
     // ------U   L-----  and  ------U   L----- : this
     //   L--U                            L--U  : CR
     if (CR.Upper.ule(Upper) || CR.Lower.uge(Lower))
@@ -637,7 +637,7 @@ ConstantRange ConstantRange::zeroExtend(uint32_t DstTySize) const {
 
   unsigned SrcTySize = getBitWidth();
   assert(SrcTySize < DstTySize && "Not a value extension");
-  if (isFullSet() || isWrappedSet()) {
+  if (isFullSet() || isUpperWrapped()) {
     // Change into [0, 1 << src bit width)
     APInt LowerExt(DstTySize, 0);
     if (!Upper) // special case: [X, 0) -- not really wrapping around
@@ -680,7 +680,7 @@ ConstantRange ConstantRange::truncate(uint32_t DstTySize) const {
   // Analyze wrapped sets in their two parts: [0, Upper) \/ [Lower, MaxValue]
   // We use the non-wrapped set code to analyze the [Lower, MaxValue) part, and
   // then we do the union with [MaxValue, Upper)
-  if (isWrappedSet()) {
+  if (isUpperWrapped()) {
     // If Upper is greater than or equal to MaxValue(DstTy), it covers the whole
     // truncated range.
     if (Upper.getActiveBits() > DstTySize ||
@@ -859,7 +859,7 @@ ConstantRange::multiply(const ConstantRange &Other) const {
   // from one positive number to another which is as good as we can generate.
   // In this case, skip the extra work of generating signed ranges which aren't
   // going to be better than this range.
-  if (!UR.isWrappedSet() &&
+  if (!UR.isUpperWrapped() &&
       (UR.getUpper().isNonNegative() || UR.getUpper().isMinSignedValue()))
     return UR;
 
index c63c6cef7e18873e2ba55d370e50d5a5eefea4b7..0455df5fa5e3cf8ae2e2c232b36a95c0b76c1f63 100644 (file)
@@ -35,7 +35,7 @@ TEST_F(ConstantRangeTest, Basics) {
   EXPECT_TRUE(Full.isFullSet());
   EXPECT_FALSE(Full.isEmptySet());
   EXPECT_TRUE(Full.inverse().isEmptySet());
-  EXPECT_FALSE(Full.isWrappedSet());
+  EXPECT_FALSE(Full.isUpperWrapped());
   EXPECT_TRUE(Full.contains(APInt(16, 0x0)));
   EXPECT_TRUE(Full.contains(APInt(16, 0x9)));
   EXPECT_TRUE(Full.contains(APInt(16, 0xa)));
@@ -45,7 +45,7 @@ TEST_F(ConstantRangeTest, Basics) {
   EXPECT_FALSE(Empty.isFullSet());
   EXPECT_TRUE(Empty.isEmptySet());
   EXPECT_TRUE(Empty.inverse().isFullSet());
-  EXPECT_FALSE(Empty.isWrappedSet());
+  EXPECT_FALSE(Empty.isUpperWrapped());
   EXPECT_FALSE(Empty.contains(APInt(16, 0x0)));
   EXPECT_FALSE(Empty.contains(APInt(16, 0x9)));
   EXPECT_FALSE(Empty.contains(APInt(16, 0xa)));
@@ -54,7 +54,7 @@ TEST_F(ConstantRangeTest, Basics) {
 
   EXPECT_FALSE(One.isFullSet());
   EXPECT_FALSE(One.isEmptySet());
-  EXPECT_FALSE(One.isWrappedSet());
+  EXPECT_FALSE(One.isUpperWrapped());
   EXPECT_FALSE(One.contains(APInt(16, 0x0)));
   EXPECT_FALSE(One.contains(APInt(16, 0x9)));
   EXPECT_TRUE(One.contains(APInt(16, 0xa)));
@@ -64,7 +64,7 @@ TEST_F(ConstantRangeTest, Basics) {
 
   EXPECT_FALSE(Some.isFullSet());
   EXPECT_FALSE(Some.isEmptySet());
-  EXPECT_FALSE(Some.isWrappedSet());
+  EXPECT_FALSE(Some.isUpperWrapped());
   EXPECT_FALSE(Some.contains(APInt(16, 0x0)));
   EXPECT_FALSE(Some.contains(APInt(16, 0x9)));
   EXPECT_TRUE(Some.contains(APInt(16, 0xa)));
@@ -73,7 +73,7 @@ TEST_F(ConstantRangeTest, Basics) {
 
   EXPECT_FALSE(Wrap.isFullSet());
   EXPECT_FALSE(Wrap.isEmptySet());
-  EXPECT_TRUE(Wrap.isWrappedSet());
+  EXPECT_TRUE(Wrap.isUpperWrapped());
   EXPECT_TRUE(Wrap.contains(APInt(16, 0x0)));
   EXPECT_TRUE(Wrap.contains(APInt(16, 0x9)));
   EXPECT_FALSE(Wrap.contains(APInt(16, 0xa)));