1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=dse -dse-optimize-memoryssa=false -S %s | FileCheck --check-prefixes=CHECK,UNOPT %s
3 ; RUN: opt -passes=dse -dse-optimize-memoryssa -S %s | FileCheck --check-prefixes=CHECK,OPT %s
4 ; RUN: opt -passes=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.p0.p0.i64(ptr noalias nocapture writeonly, ptr 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, ptr nocapture %r) {
15 ; CHECK-LABEL: @test1_pr16520(
17 ; CHECK-NEXT: store i8 1, ptr [[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, ptr %r, align 1
30 br i1 %b, label %if.then, label %if.else
32 if.then: ; preds = %entry
33 store i8 1, ptr %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, ptr nocapture %r) {
49 ; CHECK-LABEL: @test2(
51 ; CHECK-NEXT: store i8 1, ptr [[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, ptr %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, ptr %r, align 1
79 ; Make sure volatile stores are not removed.
80 define void @test2_volatile(i1 %b, ptr nocapture %r) {
81 ; CHECK-LABEL: @test2_volatile(
83 ; CHECK-NEXT: store volatile i8 1, ptr [[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, ptr [[R]], align 1
93 ; CHECK-NEXT: ret void
96 store volatile i8 1, ptr %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, ptr %r, align 1
112 define void @test3(i1 %b, ptr nocapture %r) {
113 ; CHECK-LABEL: @test3(
115 ; CHECK-NEXT: store i8 1, ptr [[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, ptr [[R]], align 1
125 ; CHECK-NEXT: ret void
128 store i8 1, ptr %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, ptr %r, align 1
144 define void @test4(i1 %b, ptr nocapture %r) {
145 ; CHECK-LABEL: @test4(
147 ; CHECK-NEXT: store i8 1, ptr [[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, ptr [[R]], align 1
157 ; CHECK-NEXT: ret void
160 store i8 1, ptr %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, ptr %r, align 1
176 define void @test5(i1 %b, ptr nocapture %r) {
177 ; CHECK-LABEL: @test5(
179 ; CHECK-NEXT: store i8 1, ptr [[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, ptr [[R]], align 1
189 ; CHECK-NEXT: ret void
192 store i8 1, ptr %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, ptr %r, align 1
208 declare i1 @cond() readnone
210 define void @test6(ptr noalias %P) {
211 ; CHECK-LABEL: @test6(
213 ; CHECK-NEXT: br label [[FOR_HEADER:%.*]]
215 ; CHECK-NEXT: store i32 1, ptr [[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, ptr [[P]], align 4
220 ; CHECK-NEXT: br label [[FOR_HEADER]]
222 ; CHECK-NEXT: store i32 3, ptr [[P]], align 4
223 ; CHECK-NEXT: ret void
229 store i32 1, ptr %P, align 4
230 %c1 = call i1 @cond()
231 br i1 %c1, label %for.body, label %end
234 store i32 1, ptr %P, align 4
235 %lv = load i32, ptr %P
239 store i32 3, ptr %P, align 4
243 ; Make sure the store in %bb3 can be eliminated in the presences of early returns.
244 define void @test7(ptr noalias %P) {
245 ; CHECK-LABEL: @test7(
246 ; CHECK-NEXT: store i32 0, ptr [[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(ptr %P) {
268 ; CHECK-LABEL: @test8(
269 ; CHECK-NEXT: store i32 0, ptr [[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, ptr [[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(ptr noalias %P) {
295 ; CHECK-LABEL: @test9(
296 ; CHECK-NEXT: store i32 0, ptr [[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(ptr noalias %P, ptr %Q, i1 %c) {
320 ; UNOPT-LABEL: @test10(
321 ; UNOPT-NEXT: store i32 0, ptr [[P:%.*]], align 4
322 ; UNOPT-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
324 ; UNOPT-NEXT: store i32 10, ptr [[Q:%.*]], align 4
325 ; UNOPT-NEXT: br label [[BB3:%.*]]
327 ; UNOPT-NEXT: ret void
329 ; UNOPT-NEXT: store i32 0, ptr [[P]], align 4
330 ; UNOPT-NEXT: ret void
332 ; OPT-LABEL: @test10(
333 ; OPT-NEXT: store i32 0, ptr [[P:%.*]], align 4
334 ; OPT-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
336 ; OPT-NEXT: store i32 10, ptr [[Q:%.*]], align 4
337 ; OPT-NEXT: br label [[BB3:%.*]]
344 br i1 %c, label %bb1, label %bb2
358 define void @test11_smaller_later_store(ptr noalias %P, ptr %Q, i1 %c) {
359 ; CHECK-LABEL: @test11_smaller_later_store(
360 ; CHECK-NEXT: store i32 0, ptr [[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: store i8 0, ptr [[P]], align 1
368 ; CHECK-NEXT: ret void
371 br i1 %c, label %bb1, label %bb2
384 define void @test11_smaller_earlier_store(ptr noalias %P, ptr %Q, i1 %c) {
385 ; CHECK-LABEL: @test11_smaller_earlier_store(
386 ; CHECK-NEXT: store i8 0, ptr [[P:%.*]], align 1
387 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
389 ; CHECK-NEXT: br label [[BB3:%.*]]
391 ; CHECK-NEXT: ret void
393 ; CHECK-NEXT: store i32 0, ptr [[P]], align 4
394 ; CHECK-NEXT: ret void
397 br i1 %c, label %bb1, label %bb2
410 declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1
412 define void @test12_memset_simple(ptr %ptr) {
413 ; CHECK-LABEL: @test12_memset_simple(
414 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr [[PTR:%.*]], i8 0, i64 10, i1 false)
415 ; CHECK-NEXT: ret void
417 call void @llvm.memset.p0.i64(ptr %ptr, i8 0, i64 10, i1 false)
418 %ptr.5 = getelementptr i8, ptr %ptr, i64 4
419 store i8 0, ptr %ptr.5
423 define void @test12_memset_other_store_in_between(ptr %ptr) {
424 ; UNOPT-LABEL: @test12_memset_other_store_in_between(
425 ; UNOPT-NEXT: call void @llvm.memset.p0.i64(ptr [[PTR:%.*]], i8 0, i64 10, i1 false)
426 ; UNOPT-NEXT: [[PTR_4:%.*]] = getelementptr i8, ptr [[PTR]], i64 4
427 ; UNOPT-NEXT: store i8 8, ptr [[PTR_4]], align 1
428 ; UNOPT-NEXT: [[PTR_5:%.*]] = getelementptr i8, ptr [[PTR]], i64 5
429 ; UNOPT-NEXT: store i8 0, ptr [[PTR_5]], align 1
430 ; UNOPT-NEXT: ret void
432 ; OPT-LABEL: @test12_memset_other_store_in_between(
433 ; OPT-NEXT: call void @llvm.memset.p0.i64(ptr [[PTR:%.*]], i8 0, i64 10, i1 false)
434 ; OPT-NEXT: [[PTR_4:%.*]] = getelementptr i8, ptr [[PTR]], i64 4
435 ; OPT-NEXT: store i8 8, ptr [[PTR_4]], align 1
438 call void @llvm.memset.p0.i64(ptr %ptr, i8 0, i64 10, i1 false)
439 %ptr.4 = getelementptr i8, ptr %ptr, i64 4
440 store i8 8, ptr %ptr.4
441 %ptr.5 = getelementptr i8, ptr %ptr, i64 5
442 store i8 0, ptr %ptr.5
446 declare ptr @__memset_chk(ptr writeonly, i32, i64, i64) argmemonly writeonly nofree nounwind
448 define void @test12_memset_chk_other_store_in_between(ptr %ptr) {
449 ; CHECK-LABEL: @test12_memset_chk_other_store_in_between(
450 ; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__memset_chk(ptr [[PTR:%.*]], i32 0, i64 10, i64 -1)
451 ; CHECK-NEXT: [[PTR_4:%.*]] = getelementptr i8, ptr [[PTR]], i64 4
452 ; CHECK-NEXT: store i8 8, ptr [[PTR_4]], align 1
453 ; CHECK-NEXT: [[PTR_5:%.*]] = getelementptr i8, ptr [[PTR]], i64 5
454 ; CHECK-NEXT: store i8 0, ptr [[PTR_5]], align 1
455 ; CHECK-NEXT: ret void
457 %call = tail call ptr @__memset_chk(ptr %ptr, i32 0, i64 10, i64 -1)
458 %ptr.4 = getelementptr i8, ptr %ptr, i64 4
459 store i8 8, ptr %ptr.4
460 %ptr.5 = getelementptr i8, ptr %ptr, i64 5
461 store i8 0, ptr %ptr.5
465 declare void @use(ptr)
467 define void @test12_memset_chk_other_store_in_between_stack_obj_escape_after(i64 %n) {
468 ; CHECK-LABEL: @test12_memset_chk_other_store_in_between_stack_obj_escape_after(
469 ; CHECK-NEXT: [[OBJ:%.*]] = alloca [200 x i8], align 1
470 ; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__memset_chk(ptr [[OBJ]], i32 0, i64 10, i64 [[N:%.*]])
471 ; CHECK-NEXT: [[PTR_4:%.*]] = getelementptr i8, ptr [[OBJ]], i64 4
472 ; CHECK-NEXT: store i8 8, ptr [[PTR_4]], align 1
473 ; CHECK-NEXT: [[PTR_5:%.*]] = getelementptr i8, ptr [[OBJ]], i64 5
474 ; CHECK-NEXT: store i8 0, ptr [[PTR_5]], align 1
475 ; CHECK-NEXT: call void @use(ptr [[OBJ]])
476 ; CHECK-NEXT: ret void
478 %obj = alloca [200 x i8]
479 %call = tail call ptr @__memset_chk(ptr %obj, i32 0, i64 10, i64 %n)
480 %ptr.4 = getelementptr i8, ptr %obj, i64 4
481 store i8 8, ptr %ptr.4
482 %ptr.5 = getelementptr i8, ptr %obj, i64 5
483 store i8 0, ptr %ptr.5
484 call void @use(ptr %obj)
488 define void @test12_memset_chk_other_store_in_between_stack_obj_escape_before(i64 %n) {
489 ; CHECK-LABEL: @test12_memset_chk_other_store_in_between_stack_obj_escape_before(
490 ; CHECK-NEXT: [[OBJ:%.*]] = alloca [200 x i8], align 1
491 ; CHECK-NEXT: call void @use(ptr [[OBJ]])
492 ; CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__memset_chk(ptr [[OBJ]], i32 0, i64 10, i64 [[N:%.*]])
493 ; CHECK-NEXT: [[PTR_4:%.*]] = getelementptr i8, ptr [[OBJ]], i64 4
494 ; CHECK-NEXT: store i8 8, ptr [[PTR_4]], align 1
495 ; CHECK-NEXT: [[PTR_5:%.*]] = getelementptr i8, ptr [[OBJ]], i64 5
496 ; CHECK-NEXT: store i8 0, ptr [[PTR_5]], align 1
497 ; CHECK-NEXT: [[PTR_10:%.*]] = getelementptr i8, ptr [[OBJ]], i64 10
498 ; CHECK-NEXT: store i8 0, ptr [[PTR_10]], align 1
499 ; CHECK-NEXT: call void @use(ptr [[OBJ]])
500 ; CHECK-NEXT: ret void
502 %obj = alloca [200 x i8]
503 call void @use(ptr %obj)
504 %call = tail call ptr @__memset_chk(ptr %obj, i32 0, i64 10, i64 %n)
505 %ptr.4 = getelementptr i8, ptr %obj, i64 4
506 store i8 8, ptr %ptr.4
507 %ptr.5 = getelementptr i8, ptr %obj, i64 5
508 store i8 0, ptr %ptr.5
509 %ptr.10 = getelementptr i8, ptr %obj, i64 10
510 store i8 0, ptr %ptr.10
511 call void @use(ptr %obj)
515 define void @test12_memset_other_store_in_between_partial_overlap(ptr %ptr) {
516 ; CHECK-LABEL: @test12_memset_other_store_in_between_partial_overlap(
517 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr [[PTR:%.*]], i8 0, i64 10, i1 false)
518 ; CHECK-NEXT: [[PTR_4:%.*]] = getelementptr i8, ptr [[PTR]], i64 4
519 ; CHECK-NEXT: store i16 8, ptr [[PTR_4]], align 2
520 ; CHECK-NEXT: [[PTR_5:%.*]] = getelementptr i8, ptr [[PTR]], i64 5
521 ; CHECK-NEXT: store i16 0, ptr [[PTR_5]], align 2
522 ; CHECK-NEXT: ret void
524 call void @llvm.memset.p0.i64(ptr %ptr, i8 0, i64 10, i1 false)
525 %ptr.4 = getelementptr i8, ptr %ptr, i64 4
526 store i16 8, ptr %ptr.4
527 %ptr.5 = getelementptr i8, ptr %ptr, i64 5
528 store i16 0, ptr %ptr.5
532 define void @test12_memset_later_store_exceeds_memset(ptr %ptr) {
533 ; CHECK-LABEL: @test12_memset_later_store_exceeds_memset(
534 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[PTR:%.*]], i8 0, i64 8, i1 false)
535 ; CHECK-NEXT: [[PTR_4:%.*]] = getelementptr i8, ptr [[PTR]], i64 4
536 ; CHECK-NEXT: store i8 8, ptr [[PTR_4]], align 1
537 ; CHECK-NEXT: [[PTR_5:%.*]] = getelementptr i8, ptr [[PTR]], i64 8
538 ; CHECK-NEXT: store i64 0, ptr [[PTR_5]], align 8
539 ; CHECK-NEXT: ret void
541 call void @llvm.memset.p0.i64(ptr %ptr, i8 0, i64 10, i1 false)
542 %ptr.4 = getelementptr i8, ptr %ptr, i64 4
543 store i8 8, ptr %ptr.4
544 %ptr.5 = getelementptr i8, ptr %ptr, i64 8
545 store i64 0, ptr %ptr.5
549 define void @test12_memset_later_store_before_memset(ptr %ptr) {
550 ; CHECK-LABEL: @test12_memset_later_store_before_memset(
551 ; CHECK-NEXT: [[PTR_1:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 1
552 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[PTR_1]], i64 7
553 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP1]], i8 0, i64 3, i1 false)
554 ; CHECK-NEXT: store i64 0, ptr [[PTR]], align 8
555 ; CHECK-NEXT: ret void
557 %ptr.1 = getelementptr i8, ptr %ptr, i64 1
558 call void @llvm.memset.p0.i64(ptr %ptr.1, i8 0, i64 10, i1 false)
559 %ptr.4 = getelementptr i8, ptr %ptr, i64 4
560 store i8 8, ptr %ptr.4
561 store i64 0, ptr %ptr
565 ; The memset will be shortened and the store will not be redundant afterwards.
566 ; It cannot be eliminated.
567 define void @test13_memset_shortened(ptr %ptr) {
568 ; CHECK-LABEL: @test13_memset_shortened(
569 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[PTR:%.*]], i64 8
570 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP1]], i8 0, i64 16, i1 false)
571 ; CHECK-NEXT: store i64 0, ptr [[PTR]], align 8
572 ; CHECK-NEXT: ret void
574 call void @llvm.memset.p0.i64(ptr %ptr, i8 0, i64 24, i1 false)
575 store i64 0, ptr %ptr
579 declare ptr @strcat(ptr, ptr) nounwind argmemonly
581 define void @test14_strcat(ptr noalias %P, ptr noalias %Q) {
582 ; CHECK-LABEL: @test14_strcat(
583 ; CHECK-NEXT: [[CALL1:%.*]] = call ptr @strcat(ptr [[P:%.*]], ptr [[Q:%.*]])
584 ; CHECK-NEXT: [[CALL2:%.*]] = call ptr @strcat(ptr [[P]], ptr [[Q]])
585 ; CHECK-NEXT: ret void
587 %call1 = call ptr @strcat(ptr %P, ptr %Q)
588 ; 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).
589 %call2 = call ptr @strcat(ptr %P, ptr %Q)
593 define void @pr49927(ptr %q, ptr %p) {
594 ; CHECK-LABEL: @pr49927(
595 ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[P:%.*]], align 4
596 ; CHECK-NEXT: store i32 [[V]], ptr [[Q:%.*]], align 4
597 ; CHECK-NEXT: store i32 [[V]], ptr [[P]], align 4
598 ; CHECK-NEXT: ret void
600 %v = load i32, ptr %p, align 4
601 store i32 %v, ptr %q, align 4
602 store i32 %v, ptr %p, align 4
606 define void @pr50339(ptr nocapture readonly %0) {
607 ; CHECK-LABEL: @pr50339(
608 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) @a, ptr noundef nonnull align 1 dereferenceable(16) [[TMP0:%.*]], i64 16, i1 false)
609 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) @a, ptr noundef nonnull align 1 dereferenceable(16) [[TMP0]], i64 16, i1 false)
610 ; CHECK-NEXT: ret void
612 tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) @a, ptr noundef nonnull align 1 dereferenceable(16) %0, i64 16, i1 false)
613 ; 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).
614 tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) @a, ptr noundef nonnull align 1 dereferenceable(16) %0, i64 16, i1 false)
618 ; Cannot remove the second memcpy as redundant store, because %src is modified
620 define i8 @memset_optimized_access(ptr noalias %dst, ptr noalias %src) {
621 ; CHECK-LABEL: @memset_optimized_access(
622 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr [[DST:%.*]], ptr [[SRC:%.*]], i64 16, i1 false)
623 ; CHECK-NEXT: store i8 99, ptr [[SRC]], align 1
624 ; CHECK-NEXT: [[L:%.*]] = load i8, ptr [[DST]], align 1
625 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr [[DST]], ptr [[SRC]], i64 16, i1 false)
626 ; CHECK-NEXT: ret i8 [[L]]
628 tail call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 16, i1 false)
629 store i8 99, ptr %src
630 %l = load i8, ptr %dst
631 tail call void @llvm.memcpy.p0.p0.i64(ptr %dst, ptr %src, i64 16, i1 false)
635 ; The @use() call is a later non-removable store, but should not affect the
636 ; removal of the store in the if block.
637 define void @later_non_removable_store(i1 %c, ptr %p) {
638 ; CHECK-LABEL: @later_non_removable_store(
639 ; CHECK-NEXT: store i8 1, ptr [[P:%.*]], align 1
640 ; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[EXIT:%.*]]
642 ; CHECK-NEXT: br label [[EXIT]]
644 ; CHECK-NEXT: call void @use(ptr [[P]]) #[[ATTR6:[0-9]+]]
645 ; CHECK-NEXT: ret void
648 br i1 %c, label %if, label %exit
655 call void @use(ptr %p) argmemonly