1 ; RUN: opt -ipsccp -S %s | FileCheck %s
4 ; Both arguments and return value of @callee can be tracked. The inferred range
5 ; can be added to call sites.
6 define internal noundef i32 @callee(i32 %x) {
7 ; CHECK-LABEL: @callee(
8 ; CHECK-NEXT: ret i32 [[X:%.*]]
13 define i32 @caller1() {
14 ; CHECK-LABEL: @caller1(
15 ; CHECK-NEXT: [[C1:%.*]] = call i32 @callee(i32 10), !range [[RANGE_10_21:![0-9]+]]
16 ; CHECK-NEXT: [[C2:%.*]] = call i32 @callee(i32 20), !range [[RANGE_10_21]]
17 ; CHECK-NEXT: [[A:%.*]] = add i32 [[C1]], [[C2]]
18 ; CHECK-NEXT: ret i32 [[A]]
20 %c1 = call i32 @callee(i32 10)
21 %c2 = call i32 @callee(i32 20)
26 define i32 @caller2(i32 %x) {
27 ; CHECK-LABEL: @caller2(
28 ; CHECK-NEXT: [[X_15:%.*]] = and i32 [[X:%.*]], 15
29 ; CHECK-NEXT: [[C:%.*]] = call i32 @callee(i32 [[X_15]]), !range [[RANGE_10_21]]
30 ; CHECK-NEXT: ret i32 [[C]]
32 %x.15 = and i32 %x, 15
33 %c = call i32 @callee(i32 %x.15)
38 ; The return value of @callee2 can be tracked, but arguments cannot, because
39 ; it is passed to @use_cb1. We cannot infer a range for the return value, no
40 ; metadata should be added.
42 declare void @use_cb1(i32 (i32)*)
44 define internal noundef i32 @callee2(i32 %x) {
45 ; CHECK-LABEL: @callee2(
46 ; CHECK-NEXT: ret i32 [[X:%.*]]
51 define void @caller_cb1() {
52 ; CHECK-LABEL: @caller_cb1(
53 ; CHECK-NEXT: [[C1:%.*]] = call i32 @callee2(i32 9)
55 ; CHECK-NEXT: [[C2:%.*]] = call i32 @callee2(i32 10)
57 ; CHECK-NEXT: call void @use_cb1(i32 (i32)* @callee2)
58 ; CHECK-NEXT: ret void
60 %c1 = call i32 @callee2(i32 9)
61 %c2 = call i32 @callee2(i32 10)
62 call void @use_cb1(i32 (i32)* @callee2)
67 ; The return value can be tracked and it the result range ([500, 601) does not
68 ; depend on the arguments, which cannot be tracked because @callee3 is passed
69 ; to @use_cb2. The result range can be added to the call sites of @callee.
71 declare void @use_cb2(i32 (i32)*)
73 define internal noundef i32 @callee3(i32 %x) {
74 ; CHECK-LABEL: @callee3(
75 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], 10
76 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i32 500, i32 600
77 ; CHECK-NEXT: ret i32 [[S]]
79 %c = icmp eq i32 %x, 10
80 %s = select i1 %c, i32 500, i32 600
84 define void @caller_cb2() {
85 ; CHECK-LABEL: @caller_cb2(
86 ; CHECK-NEXT: [[C1:%.*]] = call i32 @callee3(i32 9), !range [[RANGE_500_601:![0-9]+]]
87 ; CHECK-NEXT: [[C2:%.*]] = call i32 @callee3(i32 10), !range [[RANGE_500_601]]
88 ; CHECK-NEXT: call void @use_cb2(i32 (i32)* @callee3)
89 ; CHECK-NEXT: ret void
91 %c1 = call i32 @callee3(i32 9)
92 %c2 = call i32 @callee3(i32 10)
93 call void @use_cb2(i32 (i32)* @callee3)
98 ; The return value of @callee4 can be tracked, but depends on an argument which
99 ; cannot be tracked. No result range can be inferred.
101 declare void @use_cb3(i32 (i32, i32)*)
103 define internal noundef i32 @callee4(i32 %x, i32 %y) {
104 ; CHECK-LABEL: @callee4(
105 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], 10
106 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i32 500, i32 [[Y:%.*]]
107 ; CHECK-NEXT: ret i32 [[S]]
109 %c = icmp eq i32 %x, 10
110 %s = select i1 %c, i32 500, i32 %y
114 define void @caller_cb3() {
115 ; CHECK-LABEL: @caller_cb3(
116 ; CHECK-NEXT: [[C1:%.*]] = call i32 @callee4(i32 11, i32 30)
118 ; CHECK-NEXT: [[C2:%.*]] = call i32 @callee4(i32 12, i32 40)
120 ; CHECK-NEXT: call void @use_cb3(i32 (i32, i32)* @callee4)
121 ; CHECK-NEXT: ret void
123 %c1 = call i32 @callee4(i32 11, i32 30)
124 %c2 = call i32 @callee4(i32 12, i32 40)
125 call void @use_cb3(i32 (i32, i32)* @callee4)
130 ; Range for the return value of callee5 includes undef. No range metadata
131 ; should be added at call sites.
132 define internal noundef i32 @callee5(i32 %x, i32 %y) {
133 ; CHECK-LABEL: @callee5(
134 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[X:%.*]], 15
135 ; CHECK-NEXT: br i1 [[C]], label [[BB1:%.*]], label [[BB2:%.*]]
137 ; CHECK-NEXT: br label [[EXIT:%.*]]
139 ; CHECK-NEXT: br label [[EXIT]]
141 ; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[Y:%.*]], [[BB1]] ], [ undef, [[BB2]] ]
142 ; CHECK-NEXT: ret i32 [[RES]]
144 %c = icmp slt i32 %x, 15
145 br i1 %c, label %bb1, label %bb2
154 %res = phi i32 [ %y, %bb1 ], [ undef, %bb2]
158 define i32 @caller5() {
159 ; CHECK-LABEL: @caller5(
160 ; CHECK-NEXT: [[C1:%.*]] = call i32 @callee5(i32 10, i32 100)
162 ; CHECK-NEXT: [[C2:%.*]] = call i32 @callee5(i32 20, i32 200)
164 ; CHECK-NEXT: [[A:%.*]] = add i32 [[C1]], [[C2]]
165 ; CHECK-NEXT: ret i32 [[A]]
167 %c1 = call i32 @callee5(i32 10, i32 100)
168 %c2 = call i32 @callee5(i32 20, i32 200)
169 %a = add i32 %c1, %c2
173 ; CHECK: [[RANGE_10_21]] = !{i32 0, i32 21}
174 ; CHECK: [[RANGE_500_601]] = !{i32 500, i32 601}