#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>
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);
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);
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);
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:
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:
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:
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:
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