[llvm] [IPSCCP] Add range attribute handling. (PR #86747)
Andreas Jonson via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 10 13:49:18 PDT 2024
================
@@ -0,0 +1,82 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=ipsccp -S | FileCheck %s
+
+declare void @use(i1)
+declare i32 @get_i32()
+
+define void @range_attribute(i32 range(i32 0, 10) %v) {
+; CHECK-LABEL: @range_attribute(
+; CHECK-NEXT: call void @use(i1 true)
+; CHECK-NEXT: [[C2:%.*]] = icmp ult i32 [[V:%.*]], 9
+; CHECK-NEXT: call void @use(i1 [[C2]])
+; CHECK-NEXT: call void @use(i1 false)
+; CHECK-NEXT: [[C4:%.*]] = icmp ugt i32 [[V]], 8
+; CHECK-NEXT: call void @use(i1 [[C4]])
+; CHECK-NEXT: ret void
+;
+ %c1 = icmp ult i32 %v, 10
+ call void @use(i1 %c1)
+ %c2 = icmp ult i32 %v, 9
+ call void @use(i1 %c2)
+ %c3 = icmp ugt i32 %v, 9
+ call void @use(i1 %c3)
+ %c4 = icmp ugt i32 %v, 8
+ call void @use(i1 %c4)
+ ret void
+}
+
+define i32 @range_attribute_single(i32 range(i32 0, 1) %v) {
+; CHECK-LABEL: @range_attribute_single(
+; CHECK-NEXT: ret i32 0
+;
+ ret i32 %v
+}
+
+define void @call_range_attribute(ptr %p) {
+; CHECK-LABEL: @call_range_attribute(
+; CHECK-NEXT: [[V:%.*]] = call range(i32 0, 10) i32 @get_i32()
+; CHECK-NEXT: call void @use(i1 true)
+; CHECK-NEXT: [[C2:%.*]] = icmp ult i32 [[V]], 9
+; CHECK-NEXT: call void @use(i1 [[C2]])
+; CHECK-NEXT: call void @use(i1 false)
+; CHECK-NEXT: [[C4:%.*]] = icmp ugt i32 [[V]], 8
+; CHECK-NEXT: call void @use(i1 [[C4]])
+; CHECK-NEXT: ret void
+;
+ %v = call range(i32 0, 10) i32 @get_i32()
+ %c1 = icmp ult i32 %v, 10
+ call void @use(i1 %c1)
+ %c2 = icmp ult i32 %v, 9
+ call void @use(i1 %c2)
+ %c3 = icmp ugt i32 %v, 9
+ call void @use(i1 %c3)
+ %c4 = icmp ugt i32 %v, 8
+ call void @use(i1 %c4)
+ ret void
+}
+
+
+declare range(i32 0, 10) i32 @get_i32_in_range()
+
+define void @call_range_result(ptr %p) {
+; CHECK-LABEL: @call_range_result(
+; CHECK-NEXT: [[V:%.*]] = call i32 @get_i32_in_range()
+; CHECK-NEXT: call void @use(i1 true)
+; CHECK-NEXT: [[C2:%.*]] = icmp ult i32 [[V]], 9
+; CHECK-NEXT: call void @use(i1 [[C2]])
+; CHECK-NEXT: call void @use(i1 false)
+; CHECK-NEXT: [[C4:%.*]] = icmp ugt i32 [[V]], 8
+; CHECK-NEXT: call void @use(i1 [[C4]])
+; CHECK-NEXT: ret void
+;
+ %v = call i32 @get_i32_in_range()
+ %c1 = icmp ult i32 %v, 10
+ call void @use(i1 %c1)
+ %c2 = icmp ult i32 %v, 9
+ call void @use(i1 %c2)
+ %c3 = icmp ugt i32 %v, 9
+ call void @use(i1 %c3)
+ %c4 = icmp ugt i32 %v, 8
+ call void @use(i1 %c4)
+ ret void
+}
----------------
andjo403 wrote:
think that my test fails as ConstantVector is not handled in https://github.com/andjo403/llvm-project/blob/fa71860e1937b916758693e268d5a16021c8b5c3/llvm/include/llvm/Analysis/ValueLattice.h#L301-L339
https://github.com/llvm/llvm-project/pull/86747
More information about the llvm-commits
mailing list