[llvm-branch-commits] [llvm-branch] r115217 - in /llvm/branches/Apple/whitney: lib/Support/ConstantRange.cpp unittests/Support/ConstantRangeTest.cpp

Daniel Dunbar daniel at zuster.org
Thu Sep 30 15:19:14 PDT 2010


Author: ddunbar
Date: Thu Sep 30 17:19:14 2010
New Revision: 115217

URL: http://llvm.org/viewvc/llvm-project?rev=115217&view=rev
Log:
Merge r114972:
--
Author: Nick Lewycky <nicholas at mxc.ca>
Date:   Tue Sep 28 18:18:36 2010 +0000

    Make ConstantRange::makeICmpRegion handle all the edge cases properly. This
    also fixes PR8250.

Modified:
    llvm/branches/Apple/whitney/lib/Support/ConstantRange.cpp
    llvm/branches/Apple/whitney/unittests/Support/ConstantRangeTest.cpp

Modified: llvm/branches/Apple/whitney/lib/Support/ConstantRange.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/lib/Support/ConstantRange.cpp?rev=115217&r1=115216&r2=115217&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/lib/Support/ConstantRange.cpp (original)
+++ llvm/branches/Apple/whitney/lib/Support/ConstantRange.cpp Thu Sep 30 17:19:14 2010
@@ -51,6 +51,9 @@
 
 ConstantRange ConstantRange::makeICmpRegion(unsigned Pred,
                                             const ConstantRange &CR) {
+  if (CR.isEmptySet())
+    return CR;
+
   uint32_t W = CR.getBitWidth();
   switch (Pred) {
     default: assert(!"Invalid ICmp predicate to makeICmpRegion()");
@@ -60,10 +63,18 @@
       if (CR.isSingleElement())
         return ConstantRange(CR.getUpper(), CR.getLower());
       return ConstantRange(W);
-    case ICmpInst::ICMP_ULT:
-      return ConstantRange(APInt::getMinValue(W), CR.getUnsignedMax());
-    case ICmpInst::ICMP_SLT:
-      return ConstantRange(APInt::getSignedMinValue(W), CR.getSignedMax());
+    case ICmpInst::ICMP_ULT: {
+      APInt UMax(CR.getUnsignedMax());
+      if (UMax.isMinValue())
+        return ConstantRange(W, /* empty */ false);
+      return ConstantRange(APInt::getMinValue(W), UMax);
+    }
+    case ICmpInst::ICMP_SLT: {
+      APInt SMax(CR.getSignedMax());
+      if (SMax.isMinSignedValue())
+        return ConstantRange(W, /* empty */ false);
+      return ConstantRange(APInt::getSignedMinValue(W), SMax);
+    }
     case ICmpInst::ICMP_ULE: {
       APInt UMax(CR.getUnsignedMax());
       if (UMax.isMaxValue())
@@ -72,15 +83,22 @@
     }
     case ICmpInst::ICMP_SLE: {
       APInt SMax(CR.getSignedMax());
-      if (SMax.isMaxSignedValue() || (SMax+1).isMaxSignedValue())
+      if (SMax.isMaxSignedValue())
         return ConstantRange(W);
       return ConstantRange(APInt::getSignedMinValue(W), SMax + 1);
     }
-    case ICmpInst::ICMP_UGT:
-      return ConstantRange(CR.getUnsignedMin() + 1, APInt::getNullValue(W));
-    case ICmpInst::ICMP_SGT:
-      return ConstantRange(CR.getSignedMin() + 1,
-                           APInt::getSignedMinValue(W));
+    case ICmpInst::ICMP_UGT: {
+      APInt UMin(CR.getUnsignedMin());
+      if (UMin.isMaxValue())
+        return ConstantRange(W, /* empty */ false);
+      return ConstantRange(UMin + 1, APInt::getNullValue(W));
+    }
+    case ICmpInst::ICMP_SGT: {
+      APInt SMin(CR.getSignedMin());
+      if (SMin.isMaxSignedValue())
+        return ConstantRange(W, /* empty */ false);
+      return ConstantRange(SMin + 1, APInt::getSignedMinValue(W));
+    }
     case ICmpInst::ICMP_UGE: {
       APInt UMin(CR.getUnsignedMin());
       if (UMin.isMinValue())

Modified: llvm/branches/Apple/whitney/unittests/Support/ConstantRangeTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/unittests/Support/ConstantRangeTest.cpp?rev=115217&r1=115216&r2=115217&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/unittests/Support/ConstantRangeTest.cpp (original)
+++ llvm/branches/Apple/whitney/unittests/Support/ConstantRangeTest.cpp Thu Sep 30 17:19:14 2010
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Support/ConstantRange.h"
+#include "llvm/Instructions.h"
 
 #include "gtest/gtest.h"
 
@@ -429,4 +430,11 @@
   EXPECT_EQ(Wrap.lshr(Wrap), Full);
 }
 
+TEST(ConstantRange, MakeICmpRegion) {
+  // PR8250
+  ConstantRange SMax = ConstantRange(APInt::getSignedMaxValue(32));
+  EXPECT_TRUE(ConstantRange::makeICmpRegion(ICmpInst::ICMP_SGT,
+                                            SMax).isEmptySet());
+}
+
 }  // anonymous namespace





More information about the llvm-branch-commits mailing list