Fix typos noticed by Benjamin Kramer.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 31 May 2012 16:04:26 +0000 (16:04 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 31 May 2012 16:04:26 +0000 (16:04 +0000)
Also make the checks stronger and test that we reject ranges that overlap
a previous wrapped range.

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

docs/LangRef.html
lib/VMCore/Verifier.cpp
test/Verifier/range-1.ll

index 45ee424aedb887ab63d682514854edddbd3efe89..1f43ab67f24f29b1eef25726d2bd43026ee40ed4 100644 (file)
@@ -3054,8 +3054,8 @@ call void @llvm.dbg.value(metadata !24, i64 0, metadata !25)
    <li>The range should not represent the full or empty set. That is,
        <tt>a!=b</tt>. </li>
 </ul>
-<p> In addiion, the pairs must be in signed order of the lower bound and
-  they must be non contigous.</p>
+<p> In addition, the pairs must be in signed order of the lower bound and
+  they must be non-contiguous.</p>
 
 <p>Examples:</p>
 <div class="doc_code">
index fdffd11f0901ca22fe2e653706bb6b1de3d5c3c9..e093c52f99f306b1099eeed88d4ea42dd7ae1f62 100644 (file)
@@ -68,6 +68,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/ConstantRange.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
@@ -1362,6 +1363,10 @@ void Verifier::visitGetElementPtrInst(GetElementPtrInst &GEP) {
   visitInstruction(GEP);
 }
 
+static bool isContiguous(const ConstantRange &A, const ConstantRange &B) {
+  return A.getUpper() == B.getLower() || A.getLower() == B.getUpper();
+}
+
 void Verifier::visitLoadInst(LoadInst &LI) {
   PointerType *PTy = dyn_cast<PointerType>(LI.getOperand(0)->getType());
   Assert1(PTy, "Load operand must be a pointer.", &LI);
@@ -1384,7 +1389,7 @@ void Verifier::visitLoadInst(LoadInst &LI) {
     unsigned NumRanges = NumOperands / 2;
     Assert1(NumRanges >= 1, "It should have at least one range!", Range);
 
-    APInt LastHigh;
+    ConstantRange LastRange(1); // Dummy initial value
     for (unsigned i = 0; i < NumRanges; ++i) {
       ConstantInt *Low = dyn_cast<ConstantInt>(Range->getOperand(2*i));
       Assert1(Low, "The lower limit must be an integer!", Low);
@@ -1396,18 +1401,32 @@ void Verifier::visitLoadInst(LoadInst &LI) {
 
       APInt HighV = High->getValue();
       APInt LowV = Low->getValue();
-      Assert1(HighV != LowV, "Range must not be empty!", Range);
+      ConstantRange CurRange(LowV, HighV);
+      Assert1(!CurRange.isEmptySet() && !CurRange.isFullSet(),
+              "Range must not be empty!", Range);
       if (i != 0) {
-        Assert1(Low->getValue().sgt(LastHigh),
-                "Intervals are overlapping, contiguous or not in order", Range);
-        if (i == NumRanges - 1 && HighV.slt(LowV)) {
-          APInt First = dyn_cast<ConstantInt>(Range->getOperand(0))->getValue();
-          Assert1(First.sgt(HighV),
-                  "First and last intervals are contiguous or overlap", Range);
-        }
+        Assert1(CurRange.intersectWith(LastRange).isEmptySet(),
+                "Intervals are overlapping", Range);
+        Assert1(LowV.sgt(LastRange.getLower()), "Intervals are not in order",
+                Range);
+        Assert1(!isContiguous(CurRange, LastRange), "Intervals are contiguous",
+                Range);
       }
-      LastHigh = High->getValue();
+      LastRange = ConstantRange(LowV, HighV);
     }
+    if (NumRanges > 2) {
+      APInt FirstLow =
+        dyn_cast<ConstantInt>(Range->getOperand(0))->getValue();
+      APInt FirstHigh =
+        dyn_cast<ConstantInt>(Range->getOperand(1))->getValue();
+      ConstantRange FirstRange(FirstLow, FirstHigh);
+      Assert1(FirstRange.intersectWith(LastRange).isEmptySet(),
+              "Intervals are overlapping", Range);
+      Assert1(!isContiguous(FirstRange, LastRange), "Intervals are contiguous",
+              Range);
+    }
+
+
   }
 
   visitInstruction(LI);
index af4382e0fa7562ab117e54edb05d1ee1b143d984..7a317fca8f2cf04daba78b28abb4f15aa0f1345b 100644 (file)
@@ -83,7 +83,7 @@ entry:
   ret i8 %y
 }
 !9 = metadata !{i8 0, i8 2, i8 1, i8 3}
-; CHECK: Intervals are overlapping, contiguous or not in order
+; CHECK: Intervals are overlapping
 
 define i8 @f11(i8* %x) {
 entry:
@@ -91,7 +91,7 @@ entry:
   ret i8 %y
 }
 !10 = metadata !{i8 0, i8 2, i8 2, i8 3}
-; CHECK: Intervals are overlapping, contiguous or not in order
+; CHECK: Intervals are contiguous
 
 define i8 @f12(i8* %x) {
 entry:
@@ -99,7 +99,7 @@ entry:
   ret i8 %y
 }
 !11 = metadata !{i8 1, i8 2, i8 -1, i8 0}
-; CHECK: Intervals are overlapping, contiguous or not in order
+; CHECK: Intervals are not in order
 
 define i8 @f13(i8* %x) {
 entry:
@@ -107,7 +107,7 @@ entry:
   ret i8 %y
 }
 !12 = metadata !{i8 1, i8 3, i8 5, i8 1}
-; CHECK: First and last intervals are contiguous or overlap
+; CHECK: Intervals are contiguous
 
 define i8 @f14(i8* %x) {
 entry:
@@ -115,4 +115,28 @@ entry:
   ret i8 %y
 }
 !13 = metadata !{i8 1, i8 3, i8 5, i8 2}
-; CHECK: First and last intervals are contiguous or overlap
+; CHECK: Intervals are overlapping
+
+define i8 @f15(i8* %x) {
+entry:
+  %y = load i8* %x, align 1, !range !14
+  ret i8 %y
+}
+!14 = metadata !{i8 10, i8 1, i8 12, i8 13}
+; CHECK: Intervals are overlapping
+
+define i8 @f16(i8* %x) {
+entry:
+  %y = load i8* %x, align 1, !range !16
+  ret i8 %y
+}
+!16 = metadata !{i8 1, i8 3, i8 4, i8 5, i8 6, i8 2}
+; CHECK: Intervals are overlapping
+
+define i8 @f17(i8* %x) {
+entry:
+  %y = load i8* %x, align 1, !range !17
+  ret i8 %y
+}
+!17 = metadata !{i8 1, i8 3, i8 4, i8 5, i8 6, i8 1}
+; CHECK: Intervals are contiguous