1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=ipsccp -S %s | FileCheck %s
5 ; Both arguments and return value of @callee can be tracked. The inferred range
6 ; can be added to call sites.
7 define internal i32 @callee(i32 %x) {
8 ; CHECK-LABEL: @callee(
9 ; CHECK-NEXT: ret i32 [[X:%.*]]
14 define i32 @caller1() {
15 ; CHECK-LABEL: @caller1(
16 ; CHECK-NEXT: [[C1:%.*]] = call i32 @callee(i32 10), !range [[RNG0:![0-9]+]]
17 ; CHECK-NEXT: [[C2:%.*]] = call i32 @callee(i32 20), !range [[RNG0]]
18 ; CHECK-NEXT: [[A:%.*]] = add nuw nsw i32 [[C1]], [[C2]]
19 ; CHECK-NEXT: ret i32 [[A]]
21 %c1 = call i32 @callee(i32 10)
22 %c2 = call i32 @callee(i32 20)
27 define i32 @caller2(i32 %x) {
28 ; CHECK-LABEL: @caller2(
29 ; CHECK-NEXT: [[X_15:%.*]] = and i32 [[X:%.*]], 15
30 ; CHECK-NEXT: [[C:%.*]] = call i32 @callee(i32 [[X_15]]), !range [[RNG0]]
31 ; CHECK-NEXT: ret i32 [[C]]
33 %x.15 = and i32 %x, 15
34 %c = call i32 @callee(i32 %x.15)
39 ; The return value of @callee2 can be tracked, but arguments cannot, because
40 ; it is passed to @use_cb1. We cannot infer a range for the return value, no
41 ; metadata should be added.
43 declare void @use_cb1(ptr)
45 define internal i32 @callee2(i32 %x) {
46 ; CHECK-LABEL: @callee2(
47 ; CHECK-NEXT: ret i32 [[X:%.*]]
52 define void @caller_cb1() {
53 ; CHECK-LABEL: @caller_cb1(
54 ; CHECK-NEXT: [[C1:%.*]] = call i32 @callee2(i32 9)
55 ; CHECK-NEXT: [[C2:%.*]] = call i32 @callee2(i32 10)
56 ; CHECK-NEXT: call void @use_cb1(ptr @callee2)
57 ; CHECK-NEXT: ret void
59 %c1 = call i32 @callee2(i32 9)
60 %c2 = call i32 @callee2(i32 10)
61 call void @use_cb1(ptr @callee2)
66 ; The return value can be tracked and it the result range ([500, 601) does not
67 ; depend on the arguments, which cannot be tracked because @callee3 is passed
68 ; to @use_cb2. The result range can be added to the call sites of @callee.
70 declare void @use_cb2(ptr)
72 define internal i32 @callee3(i32 %x) {
73 ; CHECK-LABEL: @callee3(
74 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], 10
75 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i32 500, i32 600
76 ; CHECK-NEXT: ret i32 [[S]]
78 %c = icmp eq i32 %x, 10
79 %s = select i1 %c, i32 500, i32 600
83 define void @caller_cb2() {
84 ; CHECK-LABEL: @caller_cb2(
85 ; CHECK-NEXT: [[C1:%.*]] = call i32 @callee3(i32 9), !range [[RNG1:![0-9]+]]
86 ; CHECK-NEXT: [[C2:%.*]] = call i32 @callee3(i32 10), !range [[RNG1]]
87 ; CHECK-NEXT: call void @use_cb2(ptr @callee3)
88 ; CHECK-NEXT: ret void
90 %c1 = call i32 @callee3(i32 9)
91 %c2 = call i32 @callee3(i32 10)
92 call void @use_cb2(ptr @callee3)
97 ; The return value of @callee4 can be tracked, but depends on an argument which
98 ; cannot be tracked. No result range can be inferred.
100 declare void @use_cb3(ptr)
102 define internal i32 @callee4(i32 %x, i32 %y) {
103 ; CHECK-LABEL: @callee4(
104 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], 10
105 ; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i32 500, i32 [[Y:%.*]]
106 ; CHECK-NEXT: ret i32 [[S]]
108 %c = icmp eq i32 %x, 10
109 %s = select i1 %c, i32 500, i32 %y
113 define void @caller_cb3() {
114 ; CHECK-LABEL: @caller_cb3(
115 ; CHECK-NEXT: [[C1:%.*]] = call i32 @callee4(i32 11, i32 30)
117 ; CHECK-NEXT: [[C2:%.*]] = call i32 @callee4(i32 12, i32 40)
119 ; CHECK-NEXT: call void @use_cb3(ptr @callee4)
120 ; CHECK-NEXT: ret void
122 %c1 = call i32 @callee4(i32 11, i32 30)
123 %c2 = call i32 @callee4(i32 12, i32 40)
124 call void @use_cb3(ptr @callee4)
129 ; Range for the return value of callee5 includes undef. No range metadata
130 ; should be added at call sites.
131 define internal i32 @callee5(i32 %x, i32 %y) {
132 ; CHECK-LABEL: @callee5(
133 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[X:%.*]], 15
134 ; CHECK-NEXT: br i1 [[C]], label [[BB1:%.*]], label [[BB2:%.*]]
136 ; CHECK-NEXT: br label [[EXIT:%.*]]
138 ; CHECK-NEXT: br label [[EXIT]]
140 ; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[Y:%.*]], [[BB1]] ], [ undef, [[BB2]] ]
141 ; CHECK-NEXT: ret i32 [[RES]]
143 %c = icmp slt i32 %x, 15
144 br i1 %c, label %bb1, label %bb2
153 %res = phi i32 [ %y, %bb1 ], [ undef, %bb2]
157 define i32 @caller5() {
158 ; CHECK-LABEL: @caller5(
159 ; CHECK-NEXT: [[C1:%.*]] = call i32 @callee5(i32 10, i32 100)
161 ; CHECK-NEXT: [[C2:%.*]] = call i32 @callee5(i32 20, i32 200)
163 ; CHECK-NEXT: [[A:%.*]] = add i32 [[C1]], [[C2]]
164 ; CHECK-NEXT: ret i32 [[A]]
166 %c1 = call i32 @callee5(i32 10, i32 100)
167 %c2 = call i32 @callee5(i32 20, i32 200)
168 %a = add i32 %c1, %c2
172 define internal <2 x i64> @ctlz(<2 x i64> %arg) {
173 ; CHECK-LABEL: @ctlz(
174 ; CHECK-NEXT: [[RES:%.*]] = call <2 x i64> @llvm.ctlz.v2i64(<2 x i64> [[ARG:%.*]], i1 false)
175 ; CHECK-NEXT: ret <2 x i64> [[RES]]
177 %res = call <2 x i64> @llvm.ctlz.v2i64(<2 x i64> %arg, i1 false)
181 define <2 x i64> @ctlz_caller(<2 x i64> %arg) {
182 ; CHECK-LABEL: @ctlz_caller(
183 ; CHECK-NEXT: [[RES:%.*]] = call <2 x i64> @ctlz(<2 x i64> [[ARG:%.*]]), !range [[RNG2:![0-9]+]]
184 ; CHECK-NEXT: ret <2 x i64> [[RES]]
186 %res = call <2 x i64> @ctlz(<2 x i64> %arg)
190 declare <2 x i64> @llvm.ctlz.v2i64(<2 x i64>, i1)
192 ; CHECK: [[RNG0]] = !{i32 0, i32 21}
193 ; CHECK: [[RNG1]] = !{i32 500, i32 601}
194 ; CHECK: [[RNG2]] = !{i64 0, i64 65}