diff --git a/llvm/docs/LangRef.html b/llvm/docs/LangRef.html
index 14589b425db2..45ee424aedb8 100644
--- a/llvm/docs/LangRef.html
+++ b/llvm/docs/LangRef.html
@@ -3054,6 +3054,8 @@ call void @llvm.dbg.value(metadata !24, i64 0, metadata !25)
The range should not represent the full or empty set. That is,
a!=b.
+ In addiion, the pairs must be in signed order of the lower bound and
+ they must be non contigous.
Examples:
@@ -3061,10 +3063,12 @@ call void @llvm.dbg.value(metadata !24, i64 0, metadata !25)
%a = load i8* %x, align 1, !range !0 ; Can only be 0 or 1
%b = load i8* %y, align 1, !range !1 ; Can only be 255 (-1), 0 or 1
%c = load i8* %z, align 1, !range !2 ; Can only be 0, 1, 3, 4 or 5
+ %d = load i8* %z, align 1, !range !3 ; Can only be -2, -1, 3, 4 or 5
...
!0 = metadata !{ i8 0, i8 2 }
!1 = metadata !{ i8 255, i8 2 }
!2 = metadata !{ i8 0, i8 2, i8 3, i8 6 }
+!3 = metadata !{ i8 -2, i8 0, i8 3, i8 6 }
diff --git a/llvm/lib/VMCore/Verifier.cpp b/llvm/lib/VMCore/Verifier.cpp
index cae3bc8855e2..fdffd11f0901 100644
--- a/llvm/lib/VMCore/Verifier.cpp
+++ b/llvm/lib/VMCore/Verifier.cpp
@@ -1383,6 +1383,8 @@ void Verifier::visitLoadInst(LoadInst &LI) {
Assert1(NumOperands % 2 == 0, "Unfinished range!", Range);
unsigned NumRanges = NumOperands / 2;
Assert1(NumRanges >= 1, "It should have at least one range!", Range);
+
+ APInt LastHigh;
for (unsigned i = 0; i < NumRanges; ++i) {
ConstantInt *Low = dyn_cast(Range->getOperand(2*i));
Assert1(Low, "The lower limit must be an integer!", Low);
@@ -1391,8 +1393,20 @@ void Verifier::visitLoadInst(LoadInst &LI) {
Assert1(High->getType() == Low->getType() &&
High->getType() == ElTy, "Range types must match load type!",
&LI);
- Assert1(High->getValue() != Low->getValue(), "Range must not be empty!",
- Range);
+
+ APInt HighV = High->getValue();
+ APInt LowV = Low->getValue();
+ Assert1(HighV != LowV, "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(Range->getOperand(0))->getValue();
+ Assert1(First.sgt(HighV),
+ "First and last intervals are contiguous or overlap", Range);
+ }
+ }
+ LastHigh = High->getValue();
}
}
diff --git a/llvm/test/Verifier/range-1.ll b/llvm/test/Verifier/range-1.ll
index 611933a1ec30..af4382e0fa75 100644
--- a/llvm/test/Verifier/range-1.ll
+++ b/llvm/test/Verifier/range-1.ll
@@ -76,3 +76,43 @@ entry:
}
!8 = metadata !{i8 0, i8 0}
; CHECK: Range must not be empty!
+
+define i8 @f10(i8* %x) {
+entry:
+ %y = load i8* %x, align 1, !range !9
+ ret i8 %y
+}
+!9 = metadata !{i8 0, i8 2, i8 1, i8 3}
+; CHECK: Intervals are overlapping, contiguous or not in order
+
+define i8 @f11(i8* %x) {
+entry:
+ %y = load i8* %x, align 1, !range !10
+ ret i8 %y
+}
+!10 = metadata !{i8 0, i8 2, i8 2, i8 3}
+; CHECK: Intervals are overlapping, contiguous or not in order
+
+define i8 @f12(i8* %x) {
+entry:
+ %y = load i8* %x, align 1, !range !11
+ ret i8 %y
+}
+!11 = metadata !{i8 1, i8 2, i8 -1, i8 0}
+; CHECK: Intervals are overlapping, contiguous or not in order
+
+define i8 @f13(i8* %x) {
+entry:
+ %y = load i8* %x, align 1, !range !12
+ ret i8 %y
+}
+!12 = metadata !{i8 1, i8 3, i8 5, i8 1}
+; CHECK: First and last intervals are contiguous or overlap
+
+define i8 @f14(i8* %x) {
+entry:
+ %y = load i8* %x, align 1, !range !13
+ ret i8 %y
+}
+!13 = metadata !{i8 1, i8 3, i8 5, i8 2}
+; CHECK: First and last intervals are contiguous or overlap
diff --git a/llvm/test/Verifier/range-2.ll b/llvm/test/Verifier/range-2.ll
index ef542c8c9380..8d85d1915195 100644
--- a/llvm/test/Verifier/range-2.ll
+++ b/llvm/test/Verifier/range-2.ll
@@ -20,3 +20,17 @@ entry:
ret i8 %y
}
!2 = metadata !{i8 1, i8 3, i8 5, i8 42}
+
+define i8 @f4(i8* %x) {
+entry:
+ %y = load i8* %x, align 1, !range !3
+ ret i8 %y
+}
+!3 = metadata !{i8 -1, i8 0, i8 1, i8 2}
+
+define i8 @f5(i8* %x) {
+entry:
+ %y = load i8* %x, align 1, !range !4
+ ret i8 %y
+}
+!4 = metadata !{i8 -1, i8 0, i8 1, i8 -2}