1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -basic-aa -dse -S | FileCheck %s
3 ; RUN: opt < %s -aa-pipeline=basic-aa -passes='dse,verify<memoryssa>' -S | FileCheck %s
4 target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
6 declare void @memset_pattern16(i8*, i8*, i64)
8 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
9 declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* nocapture, i8, i64, i32) nounwind
10 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
11 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32) nounwind
12 declare void @llvm.init.trampoline(i8*, i8*, i8*)
14 ; **** Noop load->store tests **************************************************
16 ; We CAN optimize volatile loads.
17 define void @test_load_volatile(i32* %Q) {
18 ; CHECK-LABEL: @test_load_volatile(
19 ; CHECK-NEXT: [[A:%.*]] = load volatile i32, i32* [[Q:%.*]], align 4
20 ; CHECK-NEXT: ret void
22 %a = load volatile i32, i32* %Q
27 ; We can NOT optimize volatile stores.
28 define void @test_store_volatile(i32* %Q) {
29 ; CHECK-LABEL: @test_store_volatile(
30 ; CHECK-NEXT: [[A:%.*]] = load i32, i32* [[Q:%.*]], align 4
31 ; CHECK-NEXT: store volatile i32 [[A]], i32* [[Q]], align 4
32 ; CHECK-NEXT: ret void
34 %a = load i32, i32* %Q
35 store volatile i32 %a, i32* %Q
39 ; PR2599 - load -> store to same address.
40 define void @test12({ i32, i32 }* %x) nounwind {
41 ; CHECK-LABEL: @test12(
42 ; CHECK-NEXT: [[TEMP7:%.*]] = getelementptr { i32, i32 }, { i32, i32 }* [[X:%.*]], i32 0, i32 1
43 ; CHECK-NEXT: [[TEMP8:%.*]] = load i32, i32* [[TEMP7]], align 4
44 ; CHECK-NEXT: [[TEMP17:%.*]] = sub i32 0, [[TEMP8]]
45 ; CHECK-NEXT: store i32 [[TEMP17]], i32* [[TEMP7]], align 4
46 ; CHECK-NEXT: ret void
48 %temp4 = getelementptr { i32, i32 }, { i32, i32 }* %x, i32 0, i32 0
49 %temp5 = load i32, i32* %temp4, align 4
50 %temp7 = getelementptr { i32, i32 }, { i32, i32 }* %x, i32 0, i32 1
51 %temp8 = load i32, i32* %temp7, align 4
52 %temp17 = sub i32 0, %temp8
53 store i32 %temp5, i32* %temp4, align 4
54 store i32 %temp17, i32* %temp7, align 4
58 ; Remove redundant store if loaded value is in another block.
59 define i32 @test26(i1 %c, i32* %p) {
60 ; CHECK-LABEL: @test26(
62 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
64 ; CHECK-NEXT: br label [[BB3:%.*]]
66 ; CHECK-NEXT: br label [[BB3]]
68 ; CHECK-NEXT: ret i32 0
71 %v = load i32, i32* %p, align 4
72 br i1 %c, label %bb1, label %bb2
76 store i32 %v, i32* %p, align 4
82 ; Remove redundant store if loaded value is in another block.
83 define i32 @test27(i1 %c, i32* %p) {
84 ; CHECK-LABEL: @test27(
86 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
88 ; CHECK-NEXT: br label [[BB3:%.*]]
90 ; CHECK-NEXT: br label [[BB3]]
92 ; CHECK-NEXT: ret i32 0
95 %v = load i32, i32* %p, align 4
96 br i1 %c, label %bb1, label %bb2
102 store i32 %v, i32* %p, align 4
106 ; Remove redundant store if loaded value is in another block inside a loop.
107 define i32 @test31(i1 %c, i32* %p, i32 %i) {
108 ; CHECK-LABEL: @test31(
110 ; CHECK-NEXT: br label [[BB1:%.*]]
112 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1]], label [[BB2:%.*]]
114 ; CHECK-NEXT: ret i32 0
117 %v = load i32, i32* %p, align 4
120 store i32 %v, i32* %p, align 4
121 br i1 %c, label %bb1, label %bb2
126 ; Don't remove "redundant" store if %p is possibly stored to.
127 define i32 @test46(i1 %c, i32* %p, i32* %p2, i32 %i) {
128 ; CHECK-LABEL: @test46(
130 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
131 ; CHECK-NEXT: br label [[BB1:%.*]]
133 ; CHECK-NEXT: store i32 [[V]], i32* [[P]], align 4
134 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1]], label [[BB2:%.*]]
136 ; CHECK-NEXT: store i32 0, i32* [[P2:%.*]], align 4
137 ; CHECK-NEXT: br i1 [[C]], label [[BB3:%.*]], label [[BB1]]
139 ; CHECK-NEXT: ret i32 0
142 %v = load i32, i32* %p, align 4
145 store i32 %v, i32* %p, align 4
146 br i1 %c, label %bb1, label %bb2
148 store i32 0, i32* %p2, align 4
149 br i1 %c, label %bb3, label %bb1
154 declare void @unknown_func()
156 ; Remove redundant store, which is in the lame loop as the load.
157 define i32 @test33(i1 %c, i32* %p, i32 %i) {
158 ; CHECK-LABEL: @test33(
160 ; CHECK-NEXT: br label [[BB1:%.*]]
162 ; CHECK-NEXT: br label [[BB2:%.*]]
164 ; CHECK-NEXT: call void @unknown_func()
165 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1]], label [[BB3:%.*]]
167 ; CHECK-NEXT: ret i32 0
172 %v = load i32, i32* %p, align 4
175 store i32 %v, i32* %p, align 4
176 ; Might read and overwrite value at %p, but doesn't matter.
177 call void @unknown_func()
178 br i1 %c, label %bb1, label %bb3
183 declare void @unkown_write(i32*)
185 ; We can't remove the "noop" store around an unkown write.
186 define void @test43(i32* %Q) {
187 ; CHECK-LABEL: @test43(
188 ; CHECK-NEXT: [[A:%.*]] = load i32, i32* [[Q:%.*]], align 4
189 ; CHECK-NEXT: call void @unkown_write(i32* [[Q]])
190 ; CHECK-NEXT: store i32 [[A]], i32* [[Q]], align 4
191 ; CHECK-NEXT: ret void
193 %a = load i32, i32* %Q
194 call void @unkown_write(i32* %Q)
195 store i32 %a, i32* %Q
199 ; We CAN remove it when the unkown write comes AFTER.
200 define void @test44(i32* %Q) {
201 ; CHECK-LABEL: @test44(
202 ; CHECK-NEXT: call void @unkown_write(i32* [[Q:%.*]])
203 ; CHECK-NEXT: ret void
205 %a = load i32, i32* %Q
206 store i32 %a, i32* %Q
207 call void @unkown_write(i32* %Q)
211 define void @test45(i32* %Q) {
212 ; CHECK-LABEL: @test45(
213 ; CHECK-NEXT: ret void
215 %a = load i32, i32* %Q
216 store i32 10, i32* %Q
217 store i32 %a, i32* %Q
221 define i32 @test48(i1 %c, i32* %p) {
222 ; CHECK-LABEL: @test48(
224 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
225 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB0:%.*]], label [[BB0_0:%.*]]
227 ; CHECK-NEXT: store i32 0, i32* [[P]], align 4
228 ; CHECK-NEXT: br i1 [[C]], label [[BB1:%.*]], label [[BB2:%.*]]
230 ; CHECK-NEXT: br label [[BB1]]
232 ; CHECK-NEXT: store i32 [[V]], i32* [[P]], align 4
233 ; CHECK-NEXT: br i1 [[C]], label [[BB2]], label [[BB0]]
235 ; CHECK-NEXT: ret i32 0
238 %v = load i32, i32* %p, align 4
239 br i1 %c, label %bb0, label %bb0.0
243 br i1 %c, label %bb1, label %bb2
249 store i32 %v, i32* %p, align 4
250 br i1 %c, label %bb2, label %bb0
255 define i32 @test47(i1 %c, i32* %p, i32 %i) {
256 ; CHECK-LABEL: @test47(
258 ; CHECK-NEXT: br label [[BB1:%.*]]
260 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1]], label [[BB2:%.*]]
262 ; CHECK-NEXT: br i1 [[C]], label [[BB3:%.*]], label [[BB1]]
264 ; CHECK-NEXT: ret i32 0
267 %v = load i32, i32* %p, align 4
270 store i32 %v, i32* %p, align 4
271 br i1 %c, label %bb1, label %bb2
273 store i32 %v, i32* %p, align 4
274 br i1 %c, label %bb3, label %bb1
279 ; Test case from PR47887.
280 define void @test_noalias_store_between_load_and_store(i32* noalias %x, i32* noalias %y) {
281 ; CHECK-LABEL: @test_noalias_store_between_load_and_store(
283 ; CHECK-NEXT: store i32 0, i32* [[Y:%.*]], align 4
284 ; CHECK-NEXT: ret void
287 %lv = load i32, i32* %x, align 4
288 store i32 0, i32* %y, align 4
289 store i32 %lv, i32* %x, align 4
293 ; Test case from PR47887. Currently we eliminate the dead `store i32 %inc, i32* %x`,
294 ; but not the no-op `store i32 %lv, i32* %x`. That is because no-op stores are
295 ; eliminated before dead stores for the same def.
296 define void @test_noalias_store_between_load_and_store_elimin_order(i32* noalias %x, i32* noalias %y) {
297 ; CHECK-LABEL: @test_noalias_store_between_load_and_store_elimin_order(
299 ; CHECK-NEXT: store i32 0, i32* [[Y:%.*]], align 4
300 ; CHECK-NEXT: ret void
303 %lv = load i32, i32* %x, align 4
304 %inc = add nsw i32 %lv, 1
305 store i32 %inc, i32* %x, align 4
306 store i32 0, i32* %y, align 4
307 store i32 %lv, i32* %x, align 4
311 declare noalias i8* @malloc(i64)
312 declare noalias i8* @_Znwm(i64)
313 declare void @clobber_memory(float*)
315 ; based on pr25892_lite
316 define i8* @zero_memset_after_malloc(i64 %size) {
317 ; CHECK-LABEL: @zero_memset_after_malloc(
318 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @calloc(i64 1, i64 [[SIZE:%.*]])
319 ; CHECK-NEXT: ret i8* [[CALL]]
321 %call = call i8* @malloc(i64 %size) inaccessiblememonly
322 call void @llvm.memset.p0i8.i64(i8* %call, i8 0, i64 %size, i1 false)
326 ; based on pr25892_lite
327 define i8* @zero_memset_after_malloc_with_intermediate_clobbering(i64 %size) {
328 ; CHECK-LABEL: @zero_memset_after_malloc_with_intermediate_clobbering(
329 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @malloc(i64 [[SIZE:%.*]])
330 ; CHECK-NEXT: [[BC:%.*]] = bitcast i8* [[CALL]] to float*
331 ; CHECK-NEXT: call void @clobber_memory(float* [[BC]])
332 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[CALL]], i8 0, i64 [[SIZE]], i1 false)
333 ; CHECK-NEXT: ret i8* [[CALL]]
335 %call = call i8* @malloc(i64 %size) inaccessiblememonly
336 %bc = bitcast i8* %call to float*
337 call void @clobber_memory(float* %bc)
338 call void @llvm.memset.p0i8.i64(i8* %call, i8 0, i64 %size, i1 false)
342 ; based on pr25892_lite
343 define i8* @zero_memset_after_malloc_with_different_sizes(i64 %size) {
344 ; CHECK-LABEL: @zero_memset_after_malloc_with_different_sizes(
345 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @malloc(i64 [[SIZE:%.*]])
346 ; CHECK-NEXT: [[SIZE2:%.*]] = add nsw i64 [[SIZE]], -1
347 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[CALL]], i8 0, i64 [[SIZE2]], i1 false)
348 ; CHECK-NEXT: ret i8* [[CALL]]
350 %call = call i8* @malloc(i64 %size) inaccessiblememonly
351 %size2 = add nsw i64 %size, -1
352 call void @llvm.memset.p0i8.i64(i8* %call, i8 0, i64 %size2, i1 false)
356 ; based on pr25892_lite
357 define i8* @zero_memset_after_new(i64 %size) {
358 ; CHECK-LABEL: @zero_memset_after_new(
359 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @_Znwm(i64 [[SIZE:%.*]])
360 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[CALL]], i8 0, i64 [[SIZE]], i1 false)
361 ; CHECK-NEXT: ret i8* [[CALL]]
363 %call = call i8* @_Znwm(i64 %size)
364 call void @llvm.memset.p0i8.i64(i8* %call, i8 0, i64 %size, i1 false)
368 ; This should not create a calloc and should not crash the compiler.
369 define i8* @notmalloc_memset(i64 %size, i8*(i64)* %notmalloc) {
370 ; CHECK-LABEL: @notmalloc_memset(
371 ; CHECK-NEXT: [[CALL1:%.*]] = call i8* [[NOTMALLOC:%.*]](i64 [[SIZE:%.*]])
372 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[CALL1]], i8 0, i64 [[SIZE]], i1 false)
373 ; CHECK-NEXT: ret i8* [[CALL1]]
375 %call1 = call i8* %notmalloc(i64 %size)
376 call void @llvm.memset.p0i8.i64(i8* %call1, i8 0, i64 %size, i1 false)
380 ; This should not create recursive call to calloc.
381 define i8* @calloc(i64 %nmemb, i64 %size) {
382 ; CHECK-LABEL: @calloc(
384 ; CHECK-NEXT: [[MUL:%.*]] = mul i64 [[SIZE:%.*]], [[NMEMB:%.*]]
385 ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias align 16 i8* @malloc(i64 [[MUL]])
386 ; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i8* [[CALL]], null
387 ; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
389 ; CHECK-NEXT: tail call void @llvm.memset.p0i8.i64(i8* nonnull align 16 [[CALL]], i8 0, i64 [[MUL]], i1 false)
390 ; CHECK-NEXT: br label [[IF_END]]
392 ; CHECK-NEXT: ret i8* [[CALL]]
395 %mul = mul i64 %size, %nmemb
396 %call = tail call noalias align 16 i8* @malloc(i64 %mul)
397 %tobool.not = icmp eq i8* %call, null
398 br i1 %tobool.not, label %if.end, label %if.then
400 if.then: ; preds = %entry
401 tail call void @llvm.memset.p0i8.i64(i8* nonnull align 16 %call, i8 0, i64 %mul, i1 false)
404 if.end: ; preds = %if.then, %entry
408 define float* @pr25892(i64 %size) {
409 ; CHECK-LABEL: @pr25892(
411 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @calloc(i64 1, i64 [[SIZE:%.*]])
412 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[CALL]], null
413 ; CHECK-NEXT: br i1 [[CMP]], label [[CLEANUP:%.*]], label [[IF_END:%.*]]
415 ; CHECK-NEXT: [[BC:%.*]] = bitcast i8* [[CALL]] to float*
416 ; CHECK-NEXT: br label [[CLEANUP]]
418 ; CHECK-NEXT: [[RETVAL_0:%.*]] = phi float* [ [[BC]], [[IF_END]] ], [ null, [[ENTRY:%.*]] ]
419 ; CHECK-NEXT: ret float* [[RETVAL_0]]
422 %call = call i8* @malloc(i64 %size) inaccessiblememonly
423 %cmp = icmp eq i8* %call, null
424 br i1 %cmp, label %cleanup, label %if.end
426 %bc = bitcast i8* %call to float*
427 call void @llvm.memset.p0i8.i64(i8* %call, i8 0, i64 %size, i1 false)
430 %retval.0 = phi float* [ %bc, %if.end ], [ null, %entry ]
434 define float* @pr25892_with_extra_store(i64 %size) {
435 ; CHECK-LABEL: @pr25892_with_extra_store(
437 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @calloc(i64 1, i64 [[SIZE:%.*]])
438 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[CALL]], null
439 ; CHECK-NEXT: br i1 [[CMP]], label [[CLEANUP:%.*]], label [[IF_END:%.*]]
441 ; CHECK-NEXT: [[BC:%.*]] = bitcast i8* [[CALL]] to float*
442 ; CHECK-NEXT: br label [[CLEANUP]]
444 ; CHECK-NEXT: [[RETVAL_0:%.*]] = phi float* [ [[BC]], [[IF_END]] ], [ null, [[ENTRY:%.*]] ]
445 ; CHECK-NEXT: ret float* [[RETVAL_0]]
448 %call = call i8* @malloc(i64 %size) inaccessiblememonly
449 %cmp = icmp eq i8* %call, null
450 br i1 %cmp, label %cleanup, label %if.end
452 %bc = bitcast i8* %call to float*
453 call void @llvm.memset.p0i8.i64(i8* %call, i8 0, i64 %size, i1 false)
454 store i8 0, i8* %call, align 1
457 %retval.0 = phi float* [ %bc, %if.end ], [ null, %entry ]
462 define i8* @store_zero_after_calloc_inaccessiblememonly() {
463 ; CHECK-LABEL: @store_zero_after_calloc_inaccessiblememonly(
464 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 1, i64 10) #[[ATTR6:[0-9]+]]
465 ; CHECK-NEXT: store i8 0, i8* [[CALL]], align 1
466 ; CHECK-NEXT: ret i8* [[CALL]]
468 %call = tail call i8* @calloc(i64 1, i64 10) inaccessiblememonly
469 store i8 0, i8* %call
473 define i8* @zero_memset_after_calloc() {
474 ; CHECK-LABEL: @zero_memset_after_calloc(
475 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 10000, i64 4)
476 ; CHECK-NEXT: ret i8* [[CALL]]
478 %call = tail call i8* @calloc(i64 10000, i64 4)
479 call void @llvm.memset.p0i8.i64(i8* %call, i8 0, i64 40000, i1 false)
483 define i8* @volatile_zero_memset_after_calloc() {
484 ; CHECK-LABEL: @volatile_zero_memset_after_calloc(
485 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 10000, i64 4)
486 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[CALL]], i8 0, i64 40000, i1 true)
487 ; CHECK-NEXT: ret i8* [[CALL]]
489 %call = tail call i8* @calloc(i64 10000, i64 4)
490 call void @llvm.memset.p0i8.i64(i8* %call, i8 0, i64 40000, i1 true)
494 define i8* @zero_memset_and_store_after_calloc(i8 %v) {
495 ; CHECK-LABEL: @zero_memset_and_store_after_calloc(
496 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 10000, i64 4)
497 ; CHECK-NEXT: ret i8* [[CALL]]
499 %call = tail call i8* @calloc(i64 10000, i64 4)
500 store i8 %v, i8* %call
501 call void @llvm.memset.p0i8.i64(i8* %call, i8 0, i64 40000, i1 false)
505 define i8* @partial_zero_memset_after_calloc() {
506 ; CHECK-LABEL: @partial_zero_memset_after_calloc(
507 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 10000, i64 4)
508 ; CHECK-NEXT: ret i8* [[CALL]]
510 %call = tail call i8* @calloc(i64 10000, i64 4)
511 call void @llvm.memset.p0i8.i64(i8* %call, i8 0, i64 20, i1 false)
515 define i8* @partial_zero_memset_and_store_after_calloc(i8 %v) {
516 ; CHECK-LABEL: @partial_zero_memset_and_store_after_calloc(
517 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 10000, i64 4)
518 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, i8* [[CALL]], i64 30
519 ; CHECK-NEXT: store i8 [[V:%.*]], i8* [[GEP]], align 1
520 ; CHECK-NEXT: ret i8* [[CALL]]
522 %call = tail call i8* @calloc(i64 10000, i64 4)
523 %gep = getelementptr inbounds i8, i8* %call, i64 30
524 store i8 %v, i8* %gep
525 call void @llvm.memset.p0i8.i64(i8* %call, i8 0, i64 20, i1 false)
529 define i8* @zero_memset_and_store_with_dyn_index_after_calloc(i8 %v, i64 %idx) {
530 ; CHECK-LABEL: @zero_memset_and_store_with_dyn_index_after_calloc(
531 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 10000, i64 4)
532 ; CHECK-NEXT: ret i8* [[CALL]]
534 %call = tail call i8* @calloc(i64 10000, i64 4)
535 %gep = getelementptr inbounds i8, i8* %call, i64 %idx
536 store i8 %v, i8* %gep
537 call void @llvm.memset.p0i8.i64(i8* %call, i8 0, i64 40000, i1 false)
541 define i8* @partial_zero_memset_and_store_with_dyn_index_after_calloc(i8 %v, i64 %idx) {
542 ; CHECK-LABEL: @partial_zero_memset_and_store_with_dyn_index_after_calloc(
543 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 10000, i64 4)
544 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, i8* [[CALL]], i64 [[IDX:%.*]]
545 ; CHECK-NEXT: store i8 [[V:%.*]], i8* [[GEP]], align 1
546 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[CALL]], i8 0, i64 20, i1 false)
547 ; CHECK-NEXT: ret i8* [[CALL]]
549 %call = tail call i8* @calloc(i64 10000, i64 4)
550 %gep = getelementptr inbounds i8, i8* %call, i64 %idx
551 store i8 %v, i8* %gep
552 call void @llvm.memset.p0i8.i64(i8* %call, i8 0, i64 20, i1 false)
556 define i8* @zero_memset_after_calloc_inaccessiblememonly() {
557 ; CHECK-LABEL: @zero_memset_after_calloc_inaccessiblememonly(
558 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 10000, i64 4) #[[ATTR6]]
559 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[CALL]], i8 0, i64 40000, i1 false)
560 ; CHECK-NEXT: ret i8* [[CALL]]
562 %call = tail call i8* @calloc(i64 10000, i64 4) inaccessiblememonly
563 call void @llvm.memset.p0i8.i64(i8* %call, i8 0, i64 40000, i1 false)
567 define i8* @cst_nonzero_memset_after_calloc() {
568 ; CHECK-LABEL: @cst_nonzero_memset_after_calloc(
569 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 10000, i64 4)
570 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[CALL]], i8 1, i64 40000, i1 false)
571 ; CHECK-NEXT: ret i8* [[CALL]]
573 %call = tail call i8* @calloc(i64 10000, i64 4)
574 call void @llvm.memset.p0i8.i64(i8* %call, i8 1, i64 40000, i1 false)
578 define i8* @nonzero_memset_after_calloc(i8 %v) {
579 ; CHECK-LABEL: @nonzero_memset_after_calloc(
580 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 10000, i64 4)
581 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[CALL]], i8 [[V:%.*]], i64 40000, i1 false)
582 ; CHECK-NEXT: ret i8* [[CALL]]
584 %call = tail call i8* @calloc(i64 10000, i64 4)
585 call void @llvm.memset.p0i8.i64(i8* %call, i8 %v, i64 40000, i1 false)
590 ; The first memset is dead, because calloc provides zero-filled memory.
591 ; TODO: This could be replaced with a call to malloc + memset_pattern16.
592 define i8* @memset_pattern16_after_calloc(i8* %pat) {
593 ; CHECK-LABEL: @memset_pattern16_after_calloc(
594 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @calloc(i64 10000, i64 4)
595 ; CHECK-NEXT: call void @memset_pattern16(i8* [[CALL]], i8* [[PAT:%.*]], i64 40000)
596 ; CHECK-NEXT: ret i8* [[CALL]]
598 %call = tail call i8* @calloc(i64 10000, i64 4) #1
599 call void @llvm.memset.p0i8.i64(i8* align 4 %call, i8 0, i64 40000, i1 false)
600 call void @memset_pattern16(i8* %call, i8* %pat, i64 40000) #1