File: actual-arguments.ll

package info (click to toggle)
llvm-toolchain-20 1%3A20.1.6-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,111,304 kB
  • sloc: cpp: 7,438,677; ansic: 1,393,822; asm: 1,012,926; python: 241,650; f90: 86,635; objc: 75,479; lisp: 42,144; pascal: 17,286; sh: 10,027; ml: 5,082; perl: 4,730; awk: 3,523; makefile: 3,349; javascript: 2,251; xml: 892; fortran: 672
file content (297 lines) | stat: -rw-r--r-- 10,570 bytes parent folder | download | duplicates (2)
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes
; RUN: opt -S -passes=argpromotion < %s | FileCheck %s

; In the following tests, the call to @callee may invalidate ptr %test_c and so
; prohibit removing loads of %test_c following the call, preventing Argument
; Promotion of %test_c in the general case.

; This is called by @caller_ptr_args, from which we cannot prove anything about
; whether %test_c may alias %p and so we cannot promote %test_c.
;
define internal i32 @test_cannot_promote_1(ptr %p, ptr nocapture readonly %test_c) {
; CHECK-LABEL: define {{[^@]+}}@test_cannot_promote_1
; CHECK-SAME: (ptr [[P:%.*]], ptr nocapture readonly [[TEST_C:%.*]]) {
; CHECK-NEXT:    [[TEST_C_VAL:%.*]] = load i32, ptr [[TEST_C]], align 4
; CHECK-NEXT:    [[RES:%.*]] = call i32 @callee(ptr [[P]], i32 [[TEST_C_VAL]])
; CHECK-NEXT:    [[LTEST_C:%.*]] = load i32, ptr [[TEST_C]], align 4
; CHECK-NEXT:    [[SUM:%.*]] = add i32 [[LTEST_C]], [[RES]]
; CHECK-NEXT:    ret i32 [[SUM]]
;
  %res = call i32 @callee(ptr %p, ptr %test_c)

  %ltest_c = load i32, ptr %test_c

  %sum = add i32 %ltest_c, %res

  ret i32 %sum
}

; This is called by multiple callers, from which we can see that %test_c may
; alias %p and so we cannot promote %test_c.
;
define internal i32 @test_cannot_promote_2(ptr %p, ptr nocapture readonly %test_c) {
; CHECK-LABEL: define {{[^@]+}}@test_cannot_promote_2
; CHECK-SAME: (ptr [[P:%.*]], ptr nocapture readonly [[TEST_C:%.*]]) {
; CHECK-NEXT:    [[TEST_C_VAL:%.*]] = load i32, ptr [[TEST_C]], align 4
; CHECK-NEXT:    [[RES:%.*]] = call i32 @callee(ptr [[P]], i32 [[TEST_C_VAL]])
; CHECK-NEXT:    [[LTEST_C:%.*]] = load i32, ptr [[TEST_C]], align 4
; CHECK-NEXT:    [[SUM:%.*]] = add i32 [[LTEST_C]], [[RES]]
; CHECK-NEXT:    ret i32 [[SUM]]
;
  %res = call i32 @callee(ptr %p, ptr %test_c)

  %ltest_c = load i32, ptr %test_c

  %sum = add i32 %ltest_c, %res

  ret i32 %sum
}

; This is called by @caller_safe_args_1, but also from @caller_aliased_args, so
; we cannot promote %test_c.
;
define internal i32 @test_cannot_promote_3(ptr %p, ptr nocapture readonly %test_c) {
; CHECK-LABEL: define {{[^@]+}}@test_cannot_promote_3
; CHECK-SAME: (ptr [[P:%.*]], ptr nocapture readonly [[TEST_C:%.*]]) {
; CHECK-NEXT:    [[TEST_C_VAL:%.*]] = load i32, ptr [[TEST_C]], align 4
; CHECK-NEXT:    [[RES:%.*]] = call i32 @callee(ptr [[P]], i32 [[TEST_C_VAL]])
; CHECK-NEXT:    [[LTEST_C:%.*]] = load i32, ptr [[TEST_C]], align 4
; CHECK-NEXT:    [[SUM:%.*]] = add i32 [[LTEST_C]], [[RES]]
; CHECK-NEXT:    ret i32 [[SUM]]
;
  %res = call i32 @callee(ptr %p, ptr %test_c)

  %ltest_c = load i32, ptr %test_c

  %sum = add i32 %ltest_c, %res

  ret i32 %sum
}

; This is called only by @caller_safe_args_1, from which we can prove that
; %test_c does not alias %p for any Call to the function, so we can promote it.
;
define internal i32 @test_can_promote_1(ptr %p, ptr nocapture readonly %test_c) {
; CHECK-LABEL: define {{[^@]+}}@test_can_promote_1
; CHECK-SAME: (ptr [[P:%.*]], i32 [[TEST_C_0_VAL:%.*]]) {
; CHECK-NEXT:    [[RES:%.*]] = call i32 @callee(ptr [[P]], i32 [[TEST_C_0_VAL]])
; CHECK-NEXT:    [[SUM:%.*]] = add i32 [[TEST_C_0_VAL]], [[RES]]
; CHECK-NEXT:    ret i32 [[SUM]]
;
  %res = call i32 @callee(ptr %p, ptr %test_c)

  %ltest_c = load i32, ptr %test_c

  %sum = add i32 %ltest_c, %res

  ret i32 %sum
}

; This is called by multiple callers, from which we can prove that %test_c does
; not alias %p for any Call to the function, so we can promote it.
;
define internal i32 @test_can_promote_2(ptr %p, ptr nocapture readonly %test_c) {
; CHECK-LABEL: define {{[^@]+}}@test_can_promote_2
; CHECK-SAME: (ptr [[P:%.*]], i32 [[TEST_C_0_VAL:%.*]]) {
; CHECK-NEXT:    [[RES:%.*]] = call i32 @callee(ptr [[P]], i32 [[TEST_C_0_VAL]])
; CHECK-NEXT:    [[SUM:%.*]] = add i32 [[TEST_C_0_VAL]], [[RES]]
; CHECK-NEXT:    ret i32 [[SUM]]
;
  %res = call i32 @callee(ptr %p, ptr %test_c)

  %ltest_c = load i32, ptr %test_c

  %sum = add i32 %ltest_c, %res

  ret i32 %sum
}

; Called by @test_XXX
define internal i32 @callee(ptr %p, ptr nocapture readonly %callee_c) {
; CHECK-LABEL: define {{[^@]+}}@callee
; CHECK-SAME: (ptr [[P:%.*]], i32 [[CALLEE_C_0_VAL:%.*]]) {
; CHECK-NEXT:    [[A:%.*]] = load i32, ptr [[P]], align 4
; CHECK-NEXT:    [[SUM:%.*]] = add i32 [[A]], [[CALLEE_C_0_VAL]]
; CHECK-NEXT:    store i32 [[SUM]], ptr [[P]], align 4
; CHECK-NEXT:    ret i32 [[SUM]]
;
  %a = load i32, ptr %p

  %lcallee_c = load i32, ptr %callee_c

  %sum = add i32 %a, %lcallee_c

  store i32 %sum, ptr %p

  ret i32 %sum
}

; Calls @test_cannot_promote_1
define i32 @caller_ptr_args(i64 %n, ptr %p1, ptr %p2) {
; CHECK-LABEL: define {{[^@]+}}@caller_ptr_args
; CHECK-SAME: (i64 [[N:%.*]], ptr [[P1:%.*]], ptr [[P2:%.*]]) {
; CHECK-NEXT:    call void @memset(ptr [[P1]], i64 0, i64 [[N]])
; CHECK-NEXT:    store i32 5, ptr [[P2]], align 4
; CHECK-NEXT:    [[RES:%.*]] = call i32 @test_cannot_promote_1(ptr [[P1]], ptr [[P2]])
; CHECK-NEXT:    ret i32 [[RES]]
;
  call void @memset(ptr %p1, i64 0, i64 %n)

  store i32 5, ptr %p2

  %res = call i32 @test_cannot_promote_1(ptr %p1, ptr %p2)

  ret i32 %res
}

; Calls @test_cannot_promote_2
; Calls @test_cannot_promote_3
define i32 @caller_aliased_args() {
; CHECK-LABEL: define {{[^@]+}}@caller_aliased_args() {
; CHECK-NEXT:    [[CALLER_C:%.*]] = alloca i32, align 4
; CHECK-NEXT:    store i32 5, ptr [[CALLER_C]], align 4
; CHECK-NEXT:    [[RES1:%.*]] = call i32 @test_cannot_promote_2(ptr [[CALLER_C]], ptr [[CALLER_C]])
; CHECK-NEXT:    [[RES2:%.*]] = call i32 @test_cannot_promote_3(ptr [[CALLER_C]], ptr [[CALLER_C]])
; CHECK-NEXT:    [[RES:%.*]] = add i32 [[RES1]], [[RES2]]
; CHECK-NEXT:    ret i32 [[RES]]
;
  %caller_c = alloca i32
  store i32 5, ptr %caller_c

  %res1 = call i32 @test_cannot_promote_2(ptr %caller_c, ptr %caller_c)
  %res2 = call i32 @test_cannot_promote_3(ptr %caller_c, ptr %caller_c)

  %res = add i32 %res1, %res2

  ret i32 %res
}

; Calls @test_cannot_promote_3
; Calls @test_can_promote_1
; Calls @test_can_promote_2
define i32 @caller_safe_args_1(i64 %n) {
; CHECK-LABEL: define {{[^@]+}}@caller_safe_args_1
; CHECK-SAME: (i64 [[N:%.*]]) {
; CHECK-NEXT:    [[P:%.*]] = alloca [5 x double], i64 [[N]], align 8
; CHECK-NEXT:    call void @memset(ptr [[P]], i64 0, i64 [[N]])
; CHECK-NEXT:    [[CALLER_C:%.*]] = alloca i32, align 4
; CHECK-NEXT:    store i32 5, ptr [[CALLER_C]], align 4
; CHECK-NEXT:    [[RES1:%.*]] = call i32 @test_cannot_promote_3(ptr [[P]], ptr [[CALLER_C]])
; CHECK-NEXT:    [[CALLER_C_VAL:%.*]] = load i32, ptr [[CALLER_C]], align 4
; CHECK-NEXT:    [[RES2:%.*]] = call i32 @test_can_promote_1(ptr [[P]], i32 [[CALLER_C_VAL]])
; CHECK-NEXT:    [[CALLER_C_VAL1:%.*]] = load i32, ptr [[CALLER_C]], align 4
; CHECK-NEXT:    [[RES3:%.*]] = call i32 @test_can_promote_2(ptr [[P]], i32 [[CALLER_C_VAL1]])
; CHECK-NEXT:    [[RES12:%.*]] = add i32 [[RES1]], [[RES2]]
; CHECK-NEXT:    [[RES:%.*]] = add i32 [[RES12]], [[RES3]]
; CHECK-NEXT:    ret i32 [[RES]]
;
  %p = alloca [5 x double], i64 %n
  call void @memset(ptr %p, i64 0, i64 %n)

  %caller_c = alloca i32
  store i32 5, ptr %caller_c

  %res1 = call i32 @test_cannot_promote_3(ptr %p, ptr %caller_c)
  %res2 = call i32 @test_can_promote_1(ptr %p, ptr %caller_c)
  %res3 = call i32 @test_can_promote_2(ptr %p, ptr %caller_c)

  %res12 = add i32 %res1, %res2
  %res = add i32 %res12, %res3

  ret i32 %res
}

; Calls @test_can_promote_2
define i32 @caller_safe_args_2(i64 %n, ptr %p) {
; CHECK-LABEL: define {{[^@]+}}@caller_safe_args_2
; CHECK-SAME: (i64 [[N:%.*]], ptr [[P:%.*]]) {
; CHECK-NEXT:    call void @memset(ptr [[P]], i64 0, i64 [[N]])
; CHECK-NEXT:    [[CALLER_C:%.*]] = alloca i32, align 4
; CHECK-NEXT:    store i32 5, ptr [[CALLER_C]], align 4
; CHECK-NEXT:    [[CALLER_C_VAL:%.*]] = load i32, ptr [[CALLER_C]], align 4
; CHECK-NEXT:    [[RES:%.*]] = call i32 @test_can_promote_2(ptr [[P]], i32 [[CALLER_C_VAL]])
; CHECK-NEXT:    ret i32 [[RES]]
;
  call void @memset(ptr %p, i64 0, i64 %n)

  %caller_c = alloca i32
  store i32 5, ptr %caller_c

  %res = call i32 @test_can_promote_2(ptr %p, ptr %caller_c)

  ret i32 %res
}

; Invokes @test_cannot_promote_2
define i32 @caller_invoke_aliased_args() personality ptr @__gxx_personality_v0 {
; CHECK-LABEL: define {{[^@]+}}@caller_invoke_aliased_args() personality ptr @__gxx_personality_v0 {
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[CALLER_C:%.*]] = alloca i32, align 4
; CHECK-NEXT:    store i32 5, ptr [[CALLER_C]], align 4
; CHECK-NEXT:    [[RES:%.*]] = invoke i32 @test_cannot_promote_2(ptr [[CALLER_C]], ptr [[CALLER_C]])
; CHECK-NEXT:            to label [[OUT:%.*]] unwind label [[CPAD:%.*]]
; CHECK:       out:
; CHECK-NEXT:    ret i32 [[RES]]
; CHECK:       cpad:
; CHECK-NEXT:    [[EXN:%.*]] = landingpad { ptr, i32 }
; CHECK-NEXT:            catch ptr @_ZTIi
; CHECK-NEXT:    ret i32 -1
;
entry:
  %caller_c = alloca i32
  store i32 5, ptr %caller_c

  %res = invoke i32 @test_cannot_promote_2(ptr %caller_c, ptr %caller_c)
  to label %out unwind label %cpad

out:
  ret i32 %res

cpad:
  %exn = landingpad { ptr, i32 }
  catch ptr @_ZTIi
  ret i32 -1
}

; Invokes @test_can_promote_2
define i32 @caller_invoke_safe_args(i64 %n) personality ptr @__gxx_personality_v0 {
; CHECK-LABEL: define {{[^@]+}}@caller_invoke_safe_args
; CHECK-SAME: (i64 [[N:%.*]]) personality ptr @__gxx_personality_v0 {
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[P:%.*]] = alloca [5 x double], i64 [[N]], align 8
; CHECK-NEXT:    call void @memset(ptr [[P]], i64 0, i64 [[N]])
; CHECK-NEXT:    [[CALLER_C:%.*]] = alloca i32, align 4
; CHECK-NEXT:    store i32 5, ptr [[CALLER_C]], align 4
; CHECK-NEXT:    [[CALLER_C_VAL:%.*]] = load i32, ptr [[CALLER_C]], align 4
; CHECK-NEXT:    [[RES:%.*]] = invoke i32 @test_can_promote_2(ptr [[P]], i32 [[CALLER_C_VAL]])
; CHECK-NEXT:            to label [[OUT:%.*]] unwind label [[CPAD:%.*]]
; CHECK:       out:
; CHECK-NEXT:    ret i32 [[RES]]
; CHECK:       cpad:
; CHECK-NEXT:    [[EXN:%.*]] = landingpad { ptr, i32 }
; CHECK-NEXT:            catch ptr @_ZTIi
; CHECK-NEXT:    ret i32 -1
;
entry:
  %p = alloca [5 x double], i64 %n
  call void @memset(ptr %p, i64 0, i64 %n)

  %caller_c = alloca i32
  store i32 5, ptr %caller_c

  %res = invoke i32 @test_can_promote_2(ptr %p, ptr %caller_c)
  to label %out unwind label %cpad

out:
  ret i32 %res

cpad:
  %exn = landingpad { ptr, i32 }
  catch ptr @_ZTIi
  ret i32 -1
}

declare void @memset(ptr, i64, i64)
declare i32 @__gxx_personality_v0(...)

@_ZTIi = external constant ptr