[PATCH] D153979: Verifier: Fix assertion on range metadata with equal bounds

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 28 07:32:58 PDT 2023


arsenm created this revision.
arsenm added reviewers: nikic, reames, tahonermann, dexonsmith, nlopes, fhahn, efriedma.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

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


https://reviews.llvm.org/D153979

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


Index: llvm/test/Verifier/range-1.ll
===================================================================
--- llvm/test/Verifier/range-1.ll
+++ llvm/test/Verifier/range-1.ll
@@ -154,3 +154,10 @@
 }
 !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}
Index: llvm/test/Assembler/range.ll
===================================================================
--- /dev/null
+++ 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}
+;.
Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -3927,6 +3927,12 @@
 
     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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153979.535403.patch
Type: text/x-patch
Size: 2112 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230628/7f58ca15/attachment.bin>


More information about the llvm-commits mailing list