1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -basic-aa -dse -dse-optimize-memoryssa=false -S %s | FileCheck --check-prefixes=CHECK,UNOPT %s
3 ; RUN: opt -basic-aa -dse -dse-optimize-memoryssa -S %s | FileCheck --check-prefixes=CHECK,OPT %s
4 ; RUN: opt -basic-aa -dse -S %s | FileCheck --check-prefixes=CHECK,OPT %s
6 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
8 @a = external global [32 x i8], align 16
10 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg)
12 ; Test case for PR16520. The store in %if.then is redundant, because the same value
13 ; has been stored earlier to the same location.
14 define void @test1_pr16520(i1 %b, i8* nocapture %r) {
15 ; CHECK-LABEL: @test1_pr16520(
17 ; CHECK-NEXT: store i8 1, i8* [[R:%.*]], align 1
18 ; CHECK-NEXT: br i1 [[B:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
20 ; CHECK-NEXT: tail call void @fn_mayread_or_clobber()
21 ; CHECK-NEXT: br label [[IF_END:%.*]]
23 ; CHECK-NEXT: tail call void @fn_mayread_or_clobber()
24 ; CHECK-NEXT: br label [[IF_END]]
26 ; CHECK-NEXT: ret void
29 store i8 1, i8* %r, align 1
30 br i1 %b, label %if.then, label %if.else
32 if.then: ; preds = %entry
33 store i8 1, i8* %r, align 1
34 tail call void @fn_mayread_or_clobber()
37 if.else: ; preds = %entry
38 tail call void @fn_mayread_or_clobber()
41 if.end: ; preds = %if.else, %if.then
45 declare void @fn_mayread_or_clobber()
46 declare void @fn_readonly() readonly
48 define void @test2(i1 %b, i8* nocapture %r) {
49 ; CHECK-LABEL: @test2(
51 ; CHECK-NEXT: store i8 1, i8* [[R:%.*]], align 1
52 ; CHECK-NEXT: br i1 [[B:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
54 ; CHECK-NEXT: tail call void @fn_readonly()
55 ; CHECK-NEXT: br label [[IF_END:%.*]]
57 ; CHECK-NEXT: tail call void @fn_readonly()
58 ; CHECK-NEXT: br label [[IF_END]]
60 ; CHECK-NEXT: ret void
63 store i8 1, i8* %r, align 1
64 br i1 %b, label %if.then, label %if.else
66 if.then: ; preds = %entry
67 tail call void @fn_readonly()
70 if.else: ; preds = %entry
71 tail call void @fn_readonly()
74 if.end: ; preds = %if.else, %if.then
75 store i8 1, i8* %r, align 1
79 ; Make sure volatile stores are not removed.
80 define void @test2_volatile(i1 %b, i8* nocapture %r) {
81 ; CHECK-LABEL: @test2_volatile(
83 ; CHECK-NEXT: store volatile i8 1, i8* [[R:%.*]], align 1
84 ; CHECK-NEXT: br i1 [[B:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
86 ; CHECK-NEXT: tail call void @fn_readonly()
87 ; CHECK-NEXT: br label [[IF_END:%.*]]
89 ; CHECK-NEXT: tail call void @fn_readonly()
90 ; CHECK-NEXT: br label [[IF_END]]
92 ; CHECK-NEXT: store volatile i8 1, i8* [[R]], align 1
93 ; CHECK-NEXT: ret void
96 store volatile i8 1, i8* %r, align 1
97 br i1 %b, label %if.then, label %if.else
99 if.then: ; preds = %entry
100 tail call void @fn_readonly()
103 if.else: ; preds = %entry
104 tail call void @fn_readonly()
107 if.end: ; preds = %if.else, %if.then
108 store volatile i8 1, i8* %r, align 1
112 define void @test3(i1 %b, i8* nocapture %r) {
113 ; CHECK-LABEL: @test3(
115 ; CHECK-NEXT: store i8 1, i8* [[R:%.*]], align 1
116 ; CHECK-NEXT: br i1 [[B:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
118 ; CHECK-NEXT: tail call void @fn_mayread_or_clobber()
119 ; CHECK-NEXT: br label [[IF_END:%.*]]
121 ; CHECK-NEXT: tail call void @fn_readonly()
122 ; CHECK-NEXT: br label [[IF_END]]
124 ; CHECK-NEXT: store i8 1, i8* [[R]], align 1
125 ; CHECK-NEXT: ret void
128 store i8 1, i8* %r, align 1
129 br i1 %b, label %if.then, label %if.else
131 if.then: ; preds = %entry
132 tail call void @fn_mayread_or_clobber()
135 if.else: ; preds = %entry
136 tail call void @fn_readonly()
139 if.end: ; preds = %if.else, %if.then
140 store i8 1, i8* %r, align 1
144 define void @test4(i1 %b, i8* nocapture %r) {
145 ; CHECK-LABEL: @test4(
147 ; CHECK-NEXT: store i8 1, i8* [[R:%.*]], align 1
148 ; CHECK-NEXT: br i1 [[B:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
150 ; CHECK-NEXT: tail call void @fn_readonly()
151 ; CHECK-NEXT: br label [[IF_END:%.*]]
153 ; CHECK-NEXT: tail call void @fn_mayread_or_clobber()
154 ; CHECK-NEXT: br label [[IF_END]]
156 ; CHECK-NEXT: store i8 1, i8* [[R]], align 1
157 ; CHECK-NEXT: ret void
160 store i8 1, i8* %r, align 1
161 br i1 %b, label %if.then, label %if.else
163 if.then: ; preds = %entry
164 tail call void @fn_readonly()
167 if.else: ; preds = %entry
168 tail call void @fn_mayread_or_clobber()
171 if.end: ; preds = %if.else, %if.then
172 store i8 1, i8* %r, align 1
176 define void @test5(i1 %b, i8* nocapture %r) {
177 ; CHECK-LABEL: @test5(
179 ; CHECK-NEXT: store i8 1, i8* [[R:%.*]], align 1
180 ; CHECK-NEXT: br i1 [[B:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
182 ; CHECK-NEXT: tail call void @fn_readonly()
183 ; CHECK-NEXT: br label [[IF_END:%.*]]
185 ; CHECK-NEXT: tail call void @fn_mayread_or_clobber()
186 ; CHECK-NEXT: br label [[IF_END]]
188 ; CHECK-NEXT: store i8 1, i8* [[R]], align 1
189 ; CHECK-NEXT: ret void
192 store i8 1, i8* %r, align 1
193 br i1 %b, label %if.then, label %if.else
195 if.then: ; preds = %entry
196 tail call void @fn_readonly()
199 if.else: ; preds = %entry
200 tail call void @fn_mayread_or_clobber()
203 if.end: ; preds = %if.else, %if.then
204 store i8 1, i8* %r, align 1
208 declare i1 @cond() readnone
210 define void @test6(i32* noalias %P) {
211 ; CHECK-LABEL: @test6(
213 ; CHECK-NEXT: br label [[FOR_HEADER:%.*]]
215 ; CHECK-NEXT: store i32 1, i32* [[P:%.*]], align 4
216 ; CHECK-NEXT: [[C1:%.*]] = call i1 @cond()
217 ; CHECK-NEXT: br i1 [[C1]], label [[FOR_BODY:%.*]], label [[END:%.*]]
219 ; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[P]], align 4
220 ; CHECK-NEXT: br label [[FOR_HEADER]]
222 ; CHECK-NEXT: store i32 3, i32* [[P]], align 4
223 ; CHECK-NEXT: ret void
229 store i32 1, i32* %P, align 4
230 %c1 = call i1 @cond()
231 br i1 %c1, label %for.body, label %end
234 store i32 1, i32* %P, align 4
235 %lv = load i32, i32* %P
239 store i32 3, i32* %P, align 4
243 ; Make sure the store in %bb3 can be eliminated in the presences of early returns.
244 define void @test7(i32* noalias %P) {
245 ; CHECK-LABEL: @test7(
246 ; CHECK-NEXT: store i32 0, i32* [[P:%.*]], align 4
247 ; CHECK-NEXT: br i1 true, label [[BB1:%.*]], label [[BB2:%.*]]
249 ; CHECK-NEXT: br label [[BB3:%.*]]
251 ; CHECK-NEXT: ret void
253 ; CHECK-NEXT: ret void
256 br i1 true, label %bb1, label %bb2
266 ; Make sure the store in %bb3 won't be eliminated because it may be clobbered before.
267 define void @test8(i32* %P) {
268 ; CHECK-LABEL: @test8(
269 ; CHECK-NEXT: store i32 0, i32* [[P:%.*]], align 4
270 ; CHECK-NEXT: br i1 true, label [[BB1:%.*]], label [[BB2:%.*]]
272 ; CHECK-NEXT: call void @fn_mayread_or_clobber()
273 ; CHECK-NEXT: br label [[BB3:%.*]]
275 ; CHECK-NEXT: ret void
277 ; CHECK-NEXT: store i32 0, i32* [[P]], align 4
278 ; CHECK-NEXT: ret void
281 br i1 true, label %bb1, label %bb2
283 call void @fn_mayread_or_clobber()
292 ; Make sure the store in %bb3 will be eliminated because only the early exit path
294 define void @test9(i32* noalias %P) {
295 ; CHECK-LABEL: @test9(
296 ; CHECK-NEXT: store i32 0, i32* [[P:%.*]], align 4
297 ; CHECK-NEXT: br i1 true, label [[BB1:%.*]], label [[BB2:%.*]]
299 ; CHECK-NEXT: br label [[BB3:%.*]]
301 ; CHECK-NEXT: call void @fn_mayread_or_clobber()
302 ; CHECK-NEXT: ret void
304 ; CHECK-NEXT: ret void
307 br i1 true, label %bb1, label %bb2
311 call void @fn_mayread_or_clobber()
318 ; The store in bb3 can be eliminated, because the store in bb1 cannot alias it.
319 define void @test10(i32* noalias %P, i32* %Q, i1 %c) {
320 ; UNOPT-LABEL: @test10(
321 ; UNOPT-NEXT: store i32 0, i32* [[P:%.*]], align 4
322 ; UNOPT-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
324 ; UNOPT-NEXT: store i32 10, i32* [[Q:%.*]], align 4
325 ; UNOPT-NEXT: br label [[BB3:%.*]]
327 ; UNOPT-NEXT: ret void
329 ; UNOPT-NEXT: store i32 0, i32* [[P]], align 4
330 ; UNOPT-NEXT: ret void
332 ; OPT-LABEL: @test10(
333 ; OPT-NEXT: store i32 0, i32* [[P:%.*]], align 4
334 ; OPT-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
336 ; OPT-NEXT: store i32 10, i32* [[Q:%.*]], align 4
337 ; OPT-NEXT: br label [[BB3:%.*]]
344 br i1 %c, label %bb1, label %bb2
347 store i32 10, i32* %Q
358 define void @test11_smaller_later_store(i32* noalias %P, i32* %Q, i1 %c) {
359 ; CHECK-LABEL: @test11_smaller_later_store(
360 ; CHECK-NEXT: store i32 0, i32* [[P:%.*]], align 4
361 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
363 ; CHECK-NEXT: br label [[BB3:%.*]]
365 ; CHECK-NEXT: ret void
367 ; CHECK-NEXT: [[BC:%.*]] = bitcast i32* [[P]] to i8*
368 ; CHECK-NEXT: store i8 0, i8* [[BC]], align 1
369 ; CHECK-NEXT: ret void
372 br i1 %c, label %bb1, label %bb2
381 %bc = bitcast i32* %P to i8*
386 define void @test11_smaller_earlier_store(i32* noalias %P, i32* %Q, i1 %c) {
387 ; CHECK-LABEL: @test11_smaller_earlier_store(
388 ; CHECK-NEXT: [[BC:%.*]] = bitcast i32* [[P:%.*]] to i8*
389 ; CHECK-NEXT: store i8 0, i8* [[BC]], align 1
390 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
392 ; CHECK-NEXT: br label [[BB3:%.*]]
394 ; CHECK-NEXT: ret void
396 ; CHECK-NEXT: store i32 0, i32* [[P]], align 4
397 ; CHECK-NEXT: ret void
399 %bc = bitcast i32* %P to i8*
401 br i1 %c, label %bb1, label %bb2
414 declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg) #1
416 define void @test12_memset_simple(i8* %ptr) {
417 ; CHECK-LABEL: @test12_memset_simple(
418 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[PTR:%.*]], i8 0, i64 10, i1 false)
419 ; CHECK-NEXT: ret void
421 call void @llvm.memset.p0i8.i64(i8* %ptr, i8 0, i64 10, i1 false)
422 %ptr.5 = getelementptr i8, i8* %ptr, i64 4
423 store i8 0, i8* %ptr.5
427 define void @test12_memset_other_store_in_between(i8* %ptr) {
428 ; UNOPT-LABEL: @test12_memset_other_store_in_between(
429 ; UNOPT-NEXT: call void @llvm.memset.p0i8.i64(i8* [[PTR:%.*]], i8 0, i64 10, i1 false)
430 ; UNOPT-NEXT: [[PTR_4:%.*]] = getelementptr i8, i8* [[PTR]], i64 4
431 ; UNOPT-NEXT: store i8 8, i8* [[PTR_4]], align 1
432 ; UNOPT-NEXT: [[PTR_5:%.*]] = getelementptr i8, i8* [[PTR]], i64 5
433 ; UNOPT-NEXT: store i8 0, i8* [[PTR_5]], align 1
434 ; UNOPT-NEXT: ret void
436 ; OPT-LABEL: @test12_memset_other_store_in_between(
437 ; OPT-NEXT: call void @llvm.memset.p0i8.i64(i8* [[PTR:%.*]], i8 0, i64 10, i1 false)
438 ; OPT-NEXT: [[PTR_4:%.*]] = getelementptr i8, i8* [[PTR]], i64 4
439 ; OPT-NEXT: store i8 8, i8* [[PTR_4]], align 1
442 call void @llvm.memset.p0i8.i64(i8* %ptr, i8 0, i64 10, i1 false)
443 %ptr.4 = getelementptr i8, i8* %ptr, i64 4
444 store i8 8, i8* %ptr.4
445 %ptr.5 = getelementptr i8, i8* %ptr, i64 5
446 store i8 0, i8* %ptr.5
450 declare i8* @__memset_chk(i8* writeonly, i32, i64, i64) argmemonly writeonly nofree nounwind
452 define void @test12_memset_chk_other_store_in_between(i8* %ptr) {
453 ; CHECK-LABEL: @test12_memset_chk_other_store_in_between(
454 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__memset_chk(i8* [[PTR:%.*]], i32 0, i64 10, i64 -1)
455 ; CHECK-NEXT: [[PTR_4:%.*]] = getelementptr i8, i8* [[PTR]], i64 4
456 ; CHECK-NEXT: store i8 8, i8* [[PTR_4]], align 1
457 ; CHECK-NEXT: [[PTR_5:%.*]] = getelementptr i8, i8* [[PTR]], i64 5
458 ; CHECK-NEXT: store i8 0, i8* [[PTR_5]], align 1
459 ; CHECK-NEXT: ret void
461 %call = tail call i8* @__memset_chk(i8* %ptr, i32 0, i64 10, i64 -1)
462 %ptr.4 = getelementptr i8, i8* %ptr, i64 4
463 store i8 8, i8* %ptr.4
464 %ptr.5 = getelementptr i8, i8* %ptr, i64 5
465 store i8 0, i8* %ptr.5
469 declare void @use(i8*)
471 define void @test12_memset_chk_other_store_in_between_stack_obj_escape_after(i64 %n) {
472 ; CHECK-LABEL: @test12_memset_chk_other_store_in_between_stack_obj_escape_after(
473 ; CHECK-NEXT: [[OBJ:%.*]] = alloca [200 x i8], align 1
474 ; CHECK-NEXT: [[PTR:%.*]] = bitcast [200 x i8]* [[OBJ]] to i8*
475 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__memset_chk(i8* [[PTR]], i32 0, i64 10, i64 [[N:%.*]])
476 ; CHECK-NEXT: [[PTR_4:%.*]] = getelementptr i8, i8* [[PTR]], i64 4
477 ; CHECK-NEXT: store i8 8, i8* [[PTR_4]], align 1
478 ; CHECK-NEXT: [[PTR_5:%.*]] = getelementptr i8, i8* [[PTR]], i64 5
479 ; CHECK-NEXT: store i8 0, i8* [[PTR_5]], align 1
480 ; CHECK-NEXT: call void @use(i8* [[PTR]])
481 ; CHECK-NEXT: ret void
483 %obj = alloca [200 x i8]
484 %ptr = bitcast [200 x i8]* %obj to i8*
485 %call = tail call i8* @__memset_chk(i8* %ptr, i32 0, i64 10, i64 %n)
486 %ptr.4 = getelementptr i8, i8* %ptr, i64 4
487 store i8 8, i8* %ptr.4
488 %ptr.5 = getelementptr i8, i8* %ptr, i64 5
489 store i8 0, i8* %ptr.5
490 call void @use(i8* %ptr)
494 define void @test12_memset_chk_other_store_in_between_stack_obj_escape_before(i64 %n) {
495 ; CHECK-LABEL: @test12_memset_chk_other_store_in_between_stack_obj_escape_before(
496 ; CHECK-NEXT: [[OBJ:%.*]] = alloca [200 x i8], align 1
497 ; CHECK-NEXT: [[PTR:%.*]] = bitcast [200 x i8]* [[OBJ]] to i8*
498 ; CHECK-NEXT: call void @use(i8* [[PTR]])
499 ; CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__memset_chk(i8* [[PTR]], i32 0, i64 10, i64 [[N:%.*]])
500 ; CHECK-NEXT: [[PTR_4:%.*]] = getelementptr i8, i8* [[PTR]], i64 4
501 ; CHECK-NEXT: store i8 8, i8* [[PTR_4]], align 1
502 ; CHECK-NEXT: [[PTR_5:%.*]] = getelementptr i8, i8* [[PTR]], i64 5
503 ; CHECK-NEXT: store i8 0, i8* [[PTR_5]], align 1
504 ; CHECK-NEXT: [[PTR_10:%.*]] = getelementptr i8, i8* [[PTR]], i64 10
505 ; CHECK-NEXT: store i8 0, i8* [[PTR_10]], align 1
506 ; CHECK-NEXT: call void @use(i8* [[PTR]])
507 ; CHECK-NEXT: ret void
509 %obj = alloca [200 x i8]
510 %ptr = bitcast [200 x i8]* %obj to i8*
511 call void @use(i8* %ptr)
512 %call = tail call i8* @__memset_chk(i8* %ptr, i32 0, i64 10, i64 %n)
513 %ptr.4 = getelementptr i8, i8* %ptr, i64 4
514 store i8 8, i8* %ptr.4
515 %ptr.5 = getelementptr i8, i8* %ptr, i64 5
516 store i8 0, i8* %ptr.5
517 %ptr.10 = getelementptr i8, i8* %ptr, i64 10
518 store i8 0, i8* %ptr.10
519 call void @use(i8* %ptr)
523 define void @test12_memset_other_store_in_between_partial_overlap(i8* %ptr) {
524 ; CHECK-LABEL: @test12_memset_other_store_in_between_partial_overlap(
525 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[PTR:%.*]], i8 0, i64 10, i1 false)
526 ; CHECK-NEXT: [[PTR_4:%.*]] = getelementptr i8, i8* [[PTR]], i64 4
527 ; CHECK-NEXT: [[BC_4:%.*]] = bitcast i8* [[PTR_4]] to i16*
528 ; CHECK-NEXT: store i16 8, i16* [[BC_4]], align 2
529 ; CHECK-NEXT: [[PTR_5:%.*]] = getelementptr i8, i8* [[PTR]], i64 5
530 ; CHECK-NEXT: [[BC_5:%.*]] = bitcast i8* [[PTR_5]] to i16*
531 ; CHECK-NEXT: store i16 0, i16* [[BC_5]], align 2
532 ; CHECK-NEXT: ret void
534 call void @llvm.memset.p0i8.i64(i8* %ptr, i8 0, i64 10, i1 false)
535 %ptr.4 = getelementptr i8, i8* %ptr, i64 4
536 %bc.4 = bitcast i8* %ptr.4 to i16*
537 store i16 8, i16* %bc.4
538 %ptr.5 = getelementptr i8, i8* %ptr, i64 5
539 %bc.5 = bitcast i8* %ptr.5 to i16*
540 store i16 0, i16* %bc.5
544 define void @test12_memset_later_store_exceeds_memset(i8* %ptr) {
545 ; CHECK-LABEL: @test12_memset_later_store_exceeds_memset(
546 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 1 [[PTR:%.*]], i8 0, i64 8, i1 false)
547 ; CHECK-NEXT: [[PTR_4:%.*]] = getelementptr i8, i8* [[PTR]], i64 4
548 ; CHECK-NEXT: store i8 8, i8* [[PTR_4]], align 1
549 ; CHECK-NEXT: [[PTR_5:%.*]] = getelementptr i8, i8* [[PTR]], i64 8
550 ; CHECK-NEXT: [[BC:%.*]] = bitcast i8* [[PTR_5]] to i64*
551 ; CHECK-NEXT: store i64 0, i64* [[BC]], align 8
552 ; CHECK-NEXT: ret void
554 call void @llvm.memset.p0i8.i64(i8* %ptr, i8 0, i64 10, i1 false)
555 %ptr.4 = getelementptr i8, i8* %ptr, i64 4
556 store i8 8, i8* %ptr.4
557 %ptr.5 = getelementptr i8, i8* %ptr, i64 8
558 %bc = bitcast i8* %ptr.5 to i64*
559 store i64 0, i64* %bc
563 define void @test12_memset_later_store_before_memset(i8* %ptr) {
564 ; CHECK-LABEL: @test12_memset_later_store_before_memset(
565 ; CHECK-NEXT: [[PTR_1:%.*]] = getelementptr i8, i8* [[PTR:%.*]], i64 1
566 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i8, i8* [[PTR_1]], i64 7
567 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 1 [[TMP1]], i8 0, i64 3, i1 false)
568 ; CHECK-NEXT: [[BC:%.*]] = bitcast i8* [[PTR]] to i64*
569 ; CHECK-NEXT: store i64 0, i64* [[BC]], align 8
570 ; CHECK-NEXT: ret void
572 %ptr.1 = getelementptr i8, i8* %ptr, i64 1
573 call void @llvm.memset.p0i8.i64(i8* %ptr.1, i8 0, i64 10, i1 false)
574 %ptr.4 = getelementptr i8, i8* %ptr, i64 4
575 store i8 8, i8* %ptr.4
576 %bc = bitcast i8* %ptr to i64*
577 store i64 0, i64* %bc
581 ; The memset will be shortened and the store will not be redundant afterwards.
582 ; It cannot be eliminated.
583 define void @test13_memset_shortened(i64* %ptr) {
584 ; CHECK-LABEL: @test13_memset_shortened(
585 ; CHECK-NEXT: [[PTR_I8:%.*]] = bitcast i64* [[PTR:%.*]] to i8*
586 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i8, i8* [[PTR_I8]], i64 8
587 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 1 [[TMP1]], i8 0, i64 16, i1 false)
588 ; CHECK-NEXT: store i64 0, i64* [[PTR]], align 8
589 ; CHECK-NEXT: ret void
591 %ptr.i8 = bitcast i64* %ptr to i8*
592 call void @llvm.memset.p0i8.i64(i8* %ptr.i8, i8 0, i64 24, i1 false)
593 store i64 0, i64* %ptr
597 declare i8* @strcat(i8*, i8*) nounwind argmemonly
599 define void @test14_strcat(i8* noalias %P, i8* noalias %Q) {
600 ; CHECK-LABEL: @test14_strcat(
601 ; CHECK-NEXT: [[CALL1:%.*]] = call i8* @strcat(i8* [[P:%.*]], i8* [[Q:%.*]])
602 ; CHECK-NEXT: [[CALL2:%.*]] = call i8* @strcat(i8* [[P]], i8* [[Q]])
603 ; CHECK-NEXT: ret void
605 %call1 = call i8* @strcat(i8* %P, i8* %Q)
606 ; FIXME: Eliminate the second strcat as a "store of existing value" for this particular case, where both strcat's are identical (same source, not just same dest).
607 %call2 = call i8* @strcat(i8* %P, i8* %Q)
611 define void @pr49927(i32* %q, i32* %p) {
612 ; CHECK-LABEL: @pr49927(
613 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
614 ; CHECK-NEXT: store i32 [[V]], i32* [[Q:%.*]], align 4
615 ; CHECK-NEXT: store i32 [[V]], i32* [[P]], align 4
616 ; CHECK-NEXT: ret void
618 %v = load i32, i32* %p, align 4
619 store i32 %v, i32* %q, align 4
620 ; FIXME: this store can be eliminated
621 store i32 %v, i32* %p, align 4
625 define void @pr50339(i8* nocapture readonly %0) {
626 ; CHECK-LABEL: @pr50339(
627 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* noundef nonnull align 16 dereferenceable(16) getelementptr inbounds ([32 x i8], [32 x i8]* @a, i64 0, i64 0), i8* noundef nonnull align 1 dereferenceable(16) [[TMP0:%.*]], i64 16, i1 false)
628 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* noundef nonnull align 16 dereferenceable(16) getelementptr inbounds ([32 x i8], [32 x i8]* @a, i64 0, i64 0), i8* noundef nonnull align 1 dereferenceable(16) [[TMP0]], i64 16, i1 false)
629 ; CHECK-NEXT: ret void
631 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* noundef nonnull align 16 dereferenceable(16) getelementptr inbounds ([32 x i8], [32 x i8]* @a, i64 0, i64 0), i8* noundef nonnull align 1 dereferenceable(16) %0, i64 16, i1 false)
632 ; FIXME: Eliminate the second memcpy as a "store of existing value" for this particular case, where both memcpy's are identical (same source, not just same dest).
633 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* noundef nonnull align 16 dereferenceable(16) getelementptr inbounds ([32 x i8], [32 x i8]* @a, i64 0, i64 0), i8* noundef nonnull align 1 dereferenceable(16) %0, i64 16, i1 false)
637 ; Cannot remove the second memcpy as redundant store, because %src is modified
639 define i8 @memset_optimized_access(i8* noalias %dst, i8* noalias %src) {
640 ; CHECK-LABEL: @memset_optimized_access(
641 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[DST:%.*]], i8* [[SRC:%.*]], i64 16, i1 false)
642 ; CHECK-NEXT: store i8 99, i8* [[SRC]], align 1
643 ; CHECK-NEXT: [[L:%.*]] = load i8, i8* [[DST]], align 1
644 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[DST]], i8* [[SRC]], i64 16, i1 false)
645 ; CHECK-NEXT: ret i8 [[L]]
647 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 16, i1 false)
648 store i8 99, i8* %src
649 %l = load i8, i8* %dst
650 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 16, i1 false)
654 ; The @use() call is a later non-removable store, but should not affect the
655 ; removal of the store in the if block.
656 define void @later_non_removable_store(i1 %c, i8* %p) {
657 ; CHECK-LABEL: @later_non_removable_store(
658 ; CHECK-NEXT: store i8 1, i8* [[P:%.*]], align 1
659 ; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[EXIT:%.*]]
661 ; CHECK-NEXT: br label [[EXIT]]
663 ; CHECK-NEXT: call void @use(i8* [[P]]) #[[ATTR6:[0-9]+]]
664 ; CHECK-NEXT: ret void
667 br i1 %c, label %if, label %exit
674 call void @use(i8* %p) argmemonly