@@ -206,12 +206,12 @@ define void @test_matrix_store(i64 %stride) {
206
206
}
207
207
208
208
; %P doesn't escape, the DEAD instructions should be removed.
209
- declare void @test13f ()
210
- define i32* @test13 () {
211
- ; CHECK-LABEL: @test13 (
209
+ declare void @may_unwind ()
210
+ define i32* @test_malloc_no_escape_before_return () {
211
+ ; CHECK-LABEL: @test_malloc_no_escape_before_return (
212
212
; CHECK-NEXT: [[PTR:%.*]] = tail call i8* @malloc(i32 4)
213
213
; CHECK-NEXT: [[P:%.*]] = bitcast i8* [[PTR]] to i32*
214
- ; CHECK-NEXT: call void @test13f ()
214
+ ; CHECK-NEXT: call void @may_unwind ()
215
215
; CHECK-NEXT: store i32 0, i32* [[P]], align 4
216
216
; CHECK-NEXT: ret i32* [[P]]
217
217
;
@@ -220,7 +220,28 @@ define i32* @test13() {
220
220
%DEAD = load i32 , i32* %P
221
221
%DEAD2 = add i32 %DEAD , 1
222
222
store i32 %DEAD2 , i32* %P
223
- call void @test13f ( )
223
+ call void @may_unwind ()
224
+ store i32 0 , i32* %P
225
+ ret i32* %P
226
+ }
227
+
228
+ define i32* @test_custom_malloc_no_escape_before_return () {
229
+ ; CHECK-LABEL: @test_custom_malloc_no_escape_before_return(
230
+ ; CHECK-NEXT: [[PTR:%.*]] = tail call i8* @custom_malloc(i32 4)
231
+ ; CHECK-NEXT: [[P:%.*]] = bitcast i8* [[PTR]] to i32*
232
+ ; CHECK-NEXT: [[DEAD:%.*]] = load i32, i32* [[P]], align 4
233
+ ; CHECK-NEXT: [[DEAD2:%.*]] = add i32 [[DEAD]], 1
234
+ ; CHECK-NEXT: store i32 [[DEAD2]], i32* [[P]], align 4
235
+ ; CHECK-NEXT: call void @may_unwind()
236
+ ; CHECK-NEXT: store i32 0, i32* [[P]], align 4
237
+ ; CHECK-NEXT: ret i32* [[P]]
238
+ ;
239
+ %ptr = tail call i8* @custom_malloc (i32 4 )
240
+ %P = bitcast i8* %ptr to i32*
241
+ %DEAD = load i32 , i32* %P
242
+ %DEAD2 = add i32 %DEAD , 1
243
+ store i32 %DEAD2 , i32* %P
244
+ call void @may_unwind ()
224
245
store i32 0 , i32* %P
225
246
ret i32* %P
226
247
}
@@ -230,7 +251,7 @@ define i32 addrspace(1)* @test13_addrspacecast() {
230
251
; CHECK-NEXT: [[P:%.*]] = tail call i8* @malloc(i32 4)
231
252
; CHECK-NEXT: [[P_BC:%.*]] = bitcast i8* [[P]] to i32*
232
253
; CHECK-NEXT: [[P:%.*]] = addrspacecast i32* [[P_BC]] to i32 addrspace(1)*
233
- ; CHECK-NEXT: call void @test13f ()
254
+ ; CHECK-NEXT: call void @may_unwind ()
234
255
; CHECK-NEXT: store i32 0, i32 addrspace(1)* [[P]], align 4
235
256
; CHECK-NEXT: ret i32 addrspace(1)* [[P]]
236
257
;
@@ -240,13 +261,14 @@ define i32 addrspace(1)* @test13_addrspacecast() {
240
261
%DEAD = load i32 , i32 addrspace (1 )* %P
241
262
%DEAD2 = add i32 %DEAD , 1
242
263
store i32 %DEAD2 , i32 addrspace (1 )* %P
243
- call void @test13f ( )
264
+ call void @may_unwind ( )
244
265
store i32 0 , i32 addrspace (1 )* %P
245
266
ret i32 addrspace (1 )* %P
246
267
}
247
268
248
269
249
270
declare noalias i8* @malloc (i32 ) willreturn
271
+ declare noalias i8* @custom_malloc (i32 ) willreturn
250
272
declare noalias i8* @calloc (i32 , i32 ) willreturn
251
273
252
274
define void @test14 (i32* %Q ) {
@@ -279,15 +301,26 @@ bb:
279
301
280
302
}
281
303
282
- define void @test20 () {
283
- ; CHECK-LABEL: @test20 (
304
+ define void @malloc_no_escape () {
305
+ ; CHECK-LABEL: @malloc_no_escape (
284
306
; CHECK-NEXT: ret void
285
307
;
286
308
%m = call i8* @malloc (i32 24 )
287
309
store i8 0 , i8* %m
288
310
ret void
289
311
}
290
312
313
+ define void @custom_malloc_no_escape () {
314
+ ; CHECK-LABEL: @custom_malloc_no_escape(
315
+ ; CHECK-NEXT: [[M:%.*]] = call i8* @custom_malloc(i32 24)
316
+ ; CHECK-NEXT: store i8 0, i8* [[M]], align 1
317
+ ; CHECK-NEXT: ret void
318
+ ;
319
+ %m = call i8* @custom_malloc (i32 24 )
320
+ store i8 0 , i8* %m
321
+ ret void
322
+ }
323
+
291
324
define void @test21 () {
292
325
; CHECK-LABEL: @test21(
293
326
; CHECK-NEXT: ret void
0 commit comments