[llvm] a2ce822 - Verifier: Fix assertion on range metadata with equal bounds

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 30 09:31:38 PDT 2023


Author: Matt Arsenault
Date: 2023-06-30T12:31:32-04:00
New Revision: a2ce822a096517e36fbc6ac9404b0b5ef5e6a2bc

URL: https://github.com/llvm/llvm-project/commit/a2ce822a096517e36fbc6ac9404b0b5ef5e6a2bc
DIFF: https://github.com/llvm/llvm-project/commit/a2ce822a096517e36fbc6ac9404b0b5ef5e6a2bc.diff

LOG: Verifier: Fix assertion on range metadata with equal bounds

This only worked if the same values were the min or max. We also seem
to be missing proper assembler tests for this.

Added: 
    llvm/test/Assembler/range.ll

Modified: 
    llvm/lib/IR/Verifier.cpp
    llvm/test/Verifier/range-1.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index a85a1f6522b223..251865abab32f9 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3927,6 +3927,12 @@ void Verifier::visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty) {
 
     APInt HighV = High->getValue();
     APInt LowV = Low->getValue();
+
+    // ConstantRange asserts if the ranges are the same except for the min/max
+    // value. Leave the cases it tolerates for the empty range error below.
+    Check(LowV != HighV || LowV.isMaxValue() || LowV.isMinValue(),
+          "The upper and lower limits cannot be the same value", &I);
+
     ConstantRange CurRange(LowV, HighV);
     Check(!CurRange.isEmptySet() && !CurRange.isFullSet(),
           "Range must not be empty!", Range);

diff  --git a/llvm/test/Assembler/range.ll b/llvm/test/Assembler/range.ll
new file mode 100644
index 00000000000000..9a455d98027a54
--- /dev/null
+++ b/llvm/test/Assembler/range.ll
@@ -0,0 +1,31 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+define i8 @neg1_zero(ptr %x) {
+; CHECK-LABEL: define i8 @neg1_zero
+; CHECK-SAME: (ptr [[X:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[Y:%.*]] = load i8, ptr [[X]], align 1, !range [[RNG0:![0-9]+]]
+; CHECK-NEXT:    ret i8 [[Y]]
+;
+entry:
+  %y = load i8, ptr %x, align 1, !range !0
+  ret i8 %y
+}
+
+define <2 x i8> @neg1_zero_vector(ptr %x) {
+; CHECK-LABEL: define <2 x i8> @neg1_zero_vector
+; CHECK-SAME: (ptr [[X:%.*]]) {
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[Y:%.*]] = load <2 x i8>, ptr [[X]], align 1, !range [[RNG0]]
+; CHECK-NEXT:    ret <2 x i8> [[Y]]
+;
+entry:
+  %y = load <2 x i8>, ptr %x, align 1, !range !0
+  ret <2 x i8> %y
+}
+
+!0 = !{i8 -1, i8 0}
+
+;.
+; CHECK: [[RNG0]] = !{i8 -1, i8 0}
+;.

diff  --git a/llvm/test/Verifier/range-1.ll b/llvm/test/Verifier/range-1.ll
index 011eb3cc98b24b..ed1b6dc60fa678 100644
--- a/llvm/test/Verifier/range-1.ll
+++ b/llvm/test/Verifier/range-1.ll
@@ -154,3 +154,10 @@ define <2 x i8> @vector_range_wrong_type(ptr %x) {
 }
 !19 = !{i16 0, i16 10}
 ; CHECK: Range types must match instruction type!
+
+define i32 @range_assert(ptr %x) {
+  %y = load i32, ptr %x, !range !20
+  ret i32 %y
+}
+; CHECK: The upper and lower limits cannot be the same value{{$}}
+!20 = !{i32 123, i32 123}


        


More information about the llvm-commits mailing list