ip-add-range-to-call.ll
4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
; RUN: opt -ipsccp -S %s | FileCheck %s
; Test 1.
; Both arguments and return value of @callee can be tracked. The inferred range
; can be added to call sites.
define internal noundef i32 @callee(i32 %x) {
; CHECK-LABEL: @callee(
; CHECK-NEXT: ret i32 [[X:%.*]]
;
ret i32 %x
}
define i32 @caller1() {
; CHECK-LABEL: @caller1(
; CHECK-NEXT: [[C1:%.*]] = call i32 @callee(i32 10), !range [[RANGE_10_21:![0-9]+]]
; CHECK-NEXT: [[C2:%.*]] = call i32 @callee(i32 20), !range [[RANGE_10_21]]
; CHECK-NEXT: [[A:%.*]] = add i32 [[C1]], [[C2]]
; CHECK-NEXT: ret i32 [[A]]
;
%c1 = call i32 @callee(i32 10)
%c2 = call i32 @callee(i32 20)
%a = add i32 %c1, %c2
ret i32 %a
}
define i32 @caller2(i32 %x) {
; CHECK-LABEL: @caller2(
; CHECK-NEXT: [[X_15:%.*]] = and i32 [[X:%.*]], 15
; CHECK-NEXT: [[C:%.*]] = call i32 @callee(i32 [[X_15]]), !range [[RANGE_10_21]]
; CHECK-NEXT: ret i32 [[C]]
;
%x.15 = and i32 %x, 15
%c = call i32 @callee(i32 %x.15)
ret i32 %c
}
; Test 2.
; The return value of @callee2 can be tracked, but arguments cannot, because
; it is passed to @use_cb1. We cannot infer a range for the return value, no
; metadata should be added.
declare void @use_cb1(i32 (i32)*)
define internal noundef i32 @callee2(i32 %x) {
; CHECK-LABEL: @callee2(
; CHECK-NEXT: ret i32 [[X:%.*]]
;
ret i32 %x
}
define void @caller_cb1() {
; CHECK-LABEL: @caller_cb1(
; CHECK-NEXT: [[C1:%.*]] = call i32 @callee2(i32 9)
; CHECK-NOT: !range
; CHECK-NEXT: [[C2:%.*]] = call i32 @callee2(i32 10)
; CHECK-NOT: !range
; CHECK-NEXT: call void @use_cb1(i32 (i32)* @callee2)
; CHECK-NEXT: ret void
;
%c1 = call i32 @callee2(i32 9)
%c2 = call i32 @callee2(i32 10)
call void @use_cb1(i32 (i32)* @callee2)
ret void
}
; Test 3.
; The return value can be tracked and it the result range ([500, 601) does not
; depend on the arguments, which cannot be tracked because @callee3 is passed
; to @use_cb2. The result range can be added to the call sites of @callee.
declare void @use_cb2(i32 (i32)*)
define internal noundef i32 @callee3(i32 %x) {
; CHECK-LABEL: @callee3(
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], 10
; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i32 500, i32 600
; CHECK-NEXT: ret i32 [[S]]
;
%c = icmp eq i32 %x, 10
%s = select i1 %c, i32 500, i32 600
ret i32 %s
}
define void @caller_cb2() {
; CHECK-LABEL: @caller_cb2(
; CHECK-NEXT: [[C1:%.*]] = call i32 @callee3(i32 9), !range [[RANGE_500_601:![0-9]+]]
; CHECK-NEXT: [[C2:%.*]] = call i32 @callee3(i32 10), !range [[RANGE_500_601]]
; CHECK-NEXT: call void @use_cb2(i32 (i32)* @callee3)
; CHECK-NEXT: ret void
;
%c1 = call i32 @callee3(i32 9)
%c2 = call i32 @callee3(i32 10)
call void @use_cb2(i32 (i32)* @callee3)
ret void
}
; Test 4.
; The return value of @callee4 can be tracked, but depends on an argument which
; cannot be tracked. No result range can be inferred.
declare void @use_cb3(i32 (i32, i32)*)
define internal noundef i32 @callee4(i32 %x, i32 %y) {
; CHECK-LABEL: @callee4(
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], 10
; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i32 500, i32 [[Y:%.*]]
; CHECK-NEXT: ret i32 [[S]]
;
%c = icmp eq i32 %x, 10
%s = select i1 %c, i32 500, i32 %y
ret i32 %s
}
define void @caller_cb3() {
; CHECK-LABEL: @caller_cb3(
; CHECK-NEXT: [[C1:%.*]] = call i32 @callee4(i32 11, i32 30)
; CHECK-NOT: !range
; CHECK-NEXT: [[C2:%.*]] = call i32 @callee4(i32 12, i32 40)
; CHECK-NOT: !range
; CHECK-NEXT: call void @use_cb3(i32 (i32, i32)* @callee4)
; CHECK-NEXT: ret void
;
%c1 = call i32 @callee4(i32 11, i32 30)
%c2 = call i32 @callee4(i32 12, i32 40)
call void @use_cb3(i32 (i32, i32)* @callee4)
ret void
}
; Test 5.
; Range for the return value of callee5 includes undef. No range metadata
; should be added at call sites.
define internal noundef i32 @callee5(i32 %x, i32 %y) {
; CHECK-LABEL: @callee5(
; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[X:%.*]], 15
; CHECK-NEXT: br i1 [[C]], label [[BB1:%.*]], label [[BB2:%.*]]
; CHECK: bb1:
; CHECK-NEXT: br label [[EXIT:%.*]]
; CHECK: bb2:
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[Y:%.*]], [[BB1]] ], [ undef, [[BB2]] ]
; CHECK-NEXT: ret i32 [[RES]]
;
%c = icmp slt i32 %x, 15
br i1 %c, label %bb1, label %bb2
bb1:
br label %exit
bb2:
br label %exit
exit:
%res = phi i32 [ %y, %bb1 ], [ undef, %bb2]
ret i32 %res
}
define i32 @caller5() {
; CHECK-LABEL: @caller5(
; CHECK-NEXT: [[C1:%.*]] = call i32 @callee5(i32 10, i32 100)
; CHECK-NOT: !range
; CHECK-NEXT: [[C2:%.*]] = call i32 @callee5(i32 20, i32 200)
; CHECK-NOT: !range
; CHECK-NEXT: [[A:%.*]] = add i32 [[C1]], [[C2]]
; CHECK-NEXT: ret i32 [[A]]
;
%c1 = call i32 @callee5(i32 10, i32 100)
%c2 = call i32 @callee5(i32 20, i32 200)
%a = add i32 %c1, %c2
ret i32 %a
}
; CHECK: [[RANGE_10_21]] = !{i32 0, i32 21}
; CHECK: [[RANGE_500_601]] = !{i32 500, i32 601}