1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=dse -S | FileCheck %s
3 ; RUN: opt < %s -aa-pipeline=basic-aa -passes=dse -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 @llvm.memset.p0.i64(ptr nocapture, i8, i64, i1) nounwind
7 declare void @llvm.memset.element.unordered.atomic.p0.i64(ptr nocapture, i8, i64, i32) nounwind
8 declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounwind
9 declare void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i32) nounwind
10 declare void @llvm.init.trampoline(ptr, ptr, ptr)
11 declare void @llvm.matrix.column.major.store(<6 x float>, ptr, i64, i1, i32, i32)
13 define void @test1(ptr %Q, ptr %P) {
14 ; CHECK-LABEL: @test1(
15 ; CHECK-NEXT: store i32 0, ptr [[P:%.*]], align 4
16 ; CHECK-NEXT: ret void
18 %DEAD = load i32, ptr %Q
19 store i32 %DEAD, ptr %P
27 define i32 @test3(ptr %g_addr) nounwind {
28 ; CHECK-LABEL: @test3(
29 ; CHECK-NEXT: [[G_VALUE:%.*]] = load i32, ptr [[G_ADDR:%.*]], align 4
30 ; CHECK-NEXT: store i32 -1, ptr @g, align 4
31 ; CHECK-NEXT: store i32 [[G_VALUE]], ptr [[G_ADDR]], align 4
32 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr @g, align 4
33 ; CHECK-NEXT: ret i32 [[TMP3]]
35 %g_value = load i32, ptr %g_addr, align 4
36 store i32 -1, ptr @g, align 4
37 store i32 %g_value, ptr %g_addr, align 4
38 %tmp3 = load i32, ptr @g, align 4
43 define void @test4(ptr %Q) {
44 ; CHECK-LABEL: @test4(
45 ; CHECK-NEXT: [[A:%.*]] = load i32, ptr [[Q:%.*]], align 4
46 ; CHECK-NEXT: store volatile i32 [[A]], ptr [[Q]], align 4
47 ; CHECK-NEXT: ret void
50 store volatile i32 %a, ptr %Q
54 ; PR8576 - Should delete store of 10 even though p/q are may aliases.
55 define void @test2(ptr %p, ptr %q) {
56 ; CHECK-LABEL: @test2(
57 ; CHECK-NEXT: store i32 20, ptr [[Q:%.*]], align 4
58 ; CHECK-NEXT: store i32 30, ptr [[P:%.*]], align 4
59 ; CHECK-NEXT: ret void
61 store i32 10, ptr %p, align 4
62 store i32 20, ptr %q, align 4
63 store i32 30, ptr %p, align 4
67 ; Should delete store of 10 even though memset is a may-store to P (P and Q may
69 define void @test6(ptr %p, ptr %q) {
70 ; CHECK-LABEL: @test6(
71 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr [[Q:%.*]], i8 42, i64 900, i1 false)
72 ; CHECK-NEXT: store i32 30, ptr [[P:%.*]], align 4
73 ; CHECK-NEXT: ret void
75 store i32 10, ptr %p, align 4 ;; dead.
76 call void @llvm.memset.p0.i64(ptr %q, i8 42, i64 900, i1 false)
77 store i32 30, ptr %p, align 4
81 ; Should delete store of 10 even though memset is a may-store to P (P and Q may
83 define void @test6_atomic(ptr align 4 %p, ptr align 4 %q) {
84 ; CHECK-LABEL: @test6_atomic(
85 ; CHECK-NEXT: call void @llvm.memset.element.unordered.atomic.p0.i64(ptr align 4 [[Q:%.*]], i8 42, i64 900, i32 4)
86 ; CHECK-NEXT: store atomic i32 30, ptr [[P:%.*]] unordered, align 4
87 ; CHECK-NEXT: ret void
89 store atomic i32 10, ptr %p unordered, align 4 ;; dead.
90 call void @llvm.memset.element.unordered.atomic.p0.i64(ptr align 4 %q, i8 42, i64 900, i32 4)
91 store atomic i32 30, ptr %p unordered, align 4
95 ; Should delete store of 10 even though memcpy is a may-store to P (P and Q may
97 define void @test7(ptr %p, ptr %q, ptr noalias %r) {
98 ; CHECK-LABEL: @test7(
99 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[Q:%.*]], ptr [[R:%.*]], i64 900, i1 false)
100 ; CHECK-NEXT: store i32 30, ptr [[P:%.*]], align 4
101 ; CHECK-NEXT: ret void
103 store i32 10, ptr %p, align 4 ;; dead.
104 call void @llvm.memcpy.p0.p0.i64(ptr %q, ptr %r, i64 900, i1 false)
105 store i32 30, ptr %p, align 4
109 ; Should delete store of 10 even though memcpy is a may-store to P (P and Q may
111 define void @test7_atomic(ptr align 4 %p, ptr align 4 %q, ptr noalias align 4 %r) {
112 ; CHECK-LABEL: @test7_atomic(
113 ; CHECK-NEXT: call void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr align 4 [[Q:%.*]], ptr align 4 [[R:%.*]], i64 900, i32 4)
114 ; CHECK-NEXT: store atomic i32 30, ptr [[P:%.*]] unordered, align 4
115 ; CHECK-NEXT: ret void
117 store atomic i32 10, ptr %p unordered, align 4 ;; dead.
118 call void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr align 4 %q, ptr align 4 %r, i64 900, i32 4)
119 store atomic i32 30, ptr %p unordered, align 4
123 ; Do not delete stores that are only partially killed.
124 define i32 @test8() {
125 ; CHECK-LABEL: @test8(
126 ; CHECK-NEXT: [[V:%.*]] = alloca i32, align 4
127 ; CHECK-NEXT: store i32 1234567, ptr [[V]], align 4
128 ; CHECK-NEXT: [[X:%.*]] = load i32, ptr [[V]], align 4
129 ; CHECK-NEXT: ret i32 [[X]]
132 store i32 1234567, ptr %V
134 %X = load i32, ptr %V
139 ; Test for byval handling.
140 %struct.x = type { i32, i32, i32, i32 }
141 define void @test9(ptr byval(%struct.x) %a) nounwind {
142 ; CHECK-LABEL: @test9(
143 ; CHECK-NEXT: ret void
145 store i32 1, ptr %a, align 4
149 ; Test for inalloca handling.
150 define void @test9_2(ptr inalloca(%struct.x) %a) nounwind {
151 ; CHECK-LABEL: @test9_2(
152 ; CHECK-NEXT: ret void
154 store i32 1, ptr %a, align 4
158 ; Test for preallocated handling.
159 define void @test9_3(ptr preallocated(%struct.x) %a) nounwind {
160 ; CHECK-LABEL: @test9_3(
161 ; CHECK-NEXT: ret void
163 store i32 1, ptr %a, align 4
167 ; va_arg has fuzzy dependence, the store shouldn't be zapped.
168 define double @test10(ptr %X) {
169 ; CHECK-LABEL: @test10(
170 ; CHECK-NEXT: [[X_ADDR:%.*]] = alloca ptr, align 8
171 ; CHECK-NEXT: store ptr [[X:%.*]], ptr [[X_ADDR]], align 8
172 ; CHECK-NEXT: [[TMP_0:%.*]] = va_arg ptr [[X_ADDR]], double
173 ; CHECK-NEXT: ret double [[TMP_0]]
176 store ptr %X, ptr %X_addr
177 %tmp.0 = va_arg ptr %X_addr, double
181 ; DSE should delete the dead trampoline.
182 declare void @test11f()
183 define void @test11() {
184 ; CHECK-LABEL: @test11(
185 ; CHECK-NEXT: ret void
187 %storage = alloca [10 x i8], align 16 ; <ptr> [#uses=1]
188 %cast = getelementptr [10 x i8], ptr %storage, i32 0, i32 0 ; <ptr> [#uses=1]
189 call void @llvm.init.trampoline( ptr %cast, ptr @test11f, ptr null ) ; <ptr> [#uses=1]
193 ; Specialized store intrinsics should be removed if dead.
194 define void @test_matrix_store(i64 %stride) {
195 ; CHECK-LABEL: @test_matrix_store(
196 ; CHECK-NEXT: ret void
198 %a = alloca [6 x float]
199 call void @llvm.matrix.column.major.store(<6 x float> zeroinitializer, ptr %a, i64 %stride, i1 false, i32 3, i32 2)
203 ; %P doesn't escape, the DEAD instructions should be removed.
204 declare void @may_unwind()
205 define ptr @test_malloc_no_escape_before_return() {
206 ; CHECK-LABEL: @test_malloc_no_escape_before_return(
207 ; CHECK-NEXT: [[PTR:%.*]] = tail call ptr @malloc(i64 4)
208 ; CHECK-NEXT: call void @may_unwind()
209 ; CHECK-NEXT: store i32 0, ptr [[PTR]], align 4
210 ; CHECK-NEXT: ret ptr [[PTR]]
212 %ptr = tail call ptr @malloc(i64 4)
213 %DEAD = load i32, ptr %ptr
214 %DEAD2 = add i32 %DEAD, 1
215 store i32 %DEAD2, ptr %ptr
216 call void @may_unwind()
217 store i32 0, ptr %ptr
221 define ptr @test_custom_malloc_no_escape_before_return() {
222 ; CHECK-LABEL: @test_custom_malloc_no_escape_before_return(
223 ; CHECK-NEXT: [[PTR:%.*]] = tail call ptr @custom_malloc(i32 4)
224 ; CHECK-NEXT: call void @may_unwind()
225 ; CHECK-NEXT: store i32 0, ptr [[PTR]], align 4
226 ; CHECK-NEXT: ret ptr [[PTR]]
228 %ptr = tail call ptr @custom_malloc(i32 4)
229 %DEAD = load i32, ptr %ptr
230 %DEAD2 = add i32 %DEAD, 1
231 store i32 %DEAD2, ptr %ptr
232 call void @may_unwind()
233 store i32 0, ptr %ptr
237 define ptr addrspace(1) @test13_addrspacecast() {
238 ; CHECK-LABEL: @test13_addrspacecast(
239 ; CHECK-NEXT: [[P:%.*]] = tail call ptr @malloc(i64 4)
240 ; CHECK-NEXT: [[P_AC:%.*]] = addrspacecast ptr [[P]] to ptr addrspace(1)
241 ; CHECK-NEXT: call void @may_unwind()
242 ; CHECK-NEXT: store i32 0, ptr addrspace(1) [[P_AC]], align 4
243 ; CHECK-NEXT: ret ptr addrspace(1) [[P_AC]]
245 %p = tail call ptr @malloc(i64 4)
246 %p.ac = addrspacecast ptr %p to ptr addrspace(1)
247 %DEAD = load i32, ptr addrspace(1) %p.ac
248 %DEAD2 = add i32 %DEAD, 1
249 store i32 %DEAD2, ptr addrspace(1) %p.ac
250 call void @may_unwind()
251 store i32 0, ptr addrspace(1) %p.ac
252 ret ptr addrspace(1) %p.ac
256 declare noalias ptr @malloc(i64) willreturn allockind("alloc,uninitialized")
257 declare noalias ptr @custom_malloc(i32) willreturn
258 declare noalias ptr @calloc(i64, i64) willreturn allockind("alloc,zeroed")
260 define void @test14(ptr %Q) {
261 ; CHECK-LABEL: @test14(
262 ; CHECK-NEXT: ret void
265 %DEAD = load i32, ptr %Q
266 store i32 %DEAD, ptr %P
271 ; The store here is not dead because the byval call reads it.
272 declare void @test19f(ptr byval({i32}) align 4 %P)
274 define void @test19(ptr nocapture byval({i32}) align 4 %arg5) nounwind ssp {
275 ; CHECK-LABEL: @test19(
277 ; CHECK-NEXT: store i32 912, ptr [[ARG5:%.*]], align 4
278 ; CHECK-NEXT: call void @test19f(ptr byval({ i32 }) align 4 [[ARG5]])
279 ; CHECK-NEXT: ret void
282 store i32 912, ptr %arg5
283 call void @test19f(ptr byval({i32}) align 4 %arg5)
288 define void @malloc_no_escape() {
289 ; CHECK-LABEL: @malloc_no_escape(
290 ; CHECK-NEXT: ret void
292 %m = call ptr @malloc(i64 24)
297 define void @custom_malloc_no_escape() {
298 ; CHECK-LABEL: @custom_malloc_no_escape(
299 ; CHECK-NEXT: [[M:%.*]] = call ptr @custom_malloc(i32 24)
300 ; CHECK-NEXT: ret void
302 %m = call ptr @custom_malloc(i32 24)
307 define void @test21() {
308 ; CHECK-LABEL: @test21(
309 ; CHECK-NEXT: ret void
311 %m = call ptr @calloc(i64 9, i64 7)
316 ; Currently elimination of stores at the end of a function is limited to a
317 ; single underlying object, for compile-time. This case appears to not be
318 ; very important in practice.
319 define void @test22(i1 %i, i32 %k, i32 %m) nounwind {
320 ; CHECK-LABEL: @test22(
321 ; CHECK-NEXT: [[K_ADDR:%.*]] = alloca i32, align 4
322 ; CHECK-NEXT: [[M_ADDR:%.*]] = alloca i32, align 4
323 ; CHECK-NEXT: [[K_ADDR_M_ADDR:%.*]] = select i1 [[I:%.*]], ptr [[K_ADDR]], ptr [[M_ADDR]]
324 ; CHECK-NEXT: store i32 0, ptr [[K_ADDR_M_ADDR]], align 4
325 ; CHECK-NEXT: ret void
329 %k.addr.m.addr = select i1 %i, ptr %k.addr, ptr %m.addr
330 store i32 0, ptr %k.addr.m.addr, align 4
335 declare noalias ptr @strdup(ptr nocapture) nounwind
336 define noalias ptr @test23() nounwind uwtable ssp {
337 ; CHECK-LABEL: @test23(
338 ; CHECK-NEXT: [[X:%.*]] = alloca [2 x i8], align 1
339 ; CHECK-NEXT: store i8 97, ptr [[X]], align 1
340 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds [2 x i8], ptr [[X]], i64 0, i64 1
341 ; CHECK-NEXT: store i8 0, ptr [[ARRAYIDX1]], align 1
342 ; CHECK-NEXT: [[CALL:%.*]] = call ptr @strdup(ptr [[X]]) #[[ATTR5:[0-9]+]]
343 ; CHECK-NEXT: ret ptr [[CALL]]
345 %x = alloca [2 x i8], align 1
346 store i8 97, ptr %x, align 1
347 %arrayidx1 = getelementptr inbounds [2 x i8], ptr %x, i64 0, i64 1
348 store i8 0, ptr %arrayidx1, align 1
349 %call = call ptr @strdup(ptr %x) nounwind
353 ; Make sure same sized store to later element is deleted
354 define void @test24(ptr %a, i32 %b, i32 %c) nounwind {
355 ; CHECK-LABEL: @test24(
356 ; CHECK-NEXT: store i32 [[B:%.*]], ptr [[A:%.*]], align 4
357 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [2 x i32], ptr [[A]], i64 0, i64 1
358 ; CHECK-NEXT: store i32 [[C:%.*]], ptr [[TMP1]], align 4
359 ; CHECK-NEXT: ret void
361 store i32 0, ptr %a, align 4
362 %1 = getelementptr inbounds [2 x i32], ptr %a, i64 0, i64 1
363 store i32 0, ptr %1, align 4
364 store i32 %b, ptr %a, align 4
365 %2 = getelementptr inbounds [2 x i32], ptr %a, i64 0, i64 1
366 store i32 %c, ptr %2, align 4
370 ; Check another case like PR13547 where strdup is not like malloc.
371 define ptr @test25(ptr %p) nounwind {
372 ; CHECK-LABEL: @test25(
373 ; CHECK-NEXT: [[P_4:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 4
374 ; CHECK-NEXT: [[TMP:%.*]] = load i8, ptr [[P_4]], align 1
375 ; CHECK-NEXT: store i8 0, ptr [[P_4]], align 1
376 ; CHECK-NEXT: [[Q:%.*]] = call ptr @strdup(ptr [[P]]) #[[ATTR13:[0-9]+]]
377 ; CHECK-NEXT: store i8 [[TMP]], ptr [[P_4]], align 1
378 ; CHECK-NEXT: ret ptr [[Q]]
380 %p.4 = getelementptr i8, ptr %p, i64 4
381 %tmp = load i8, ptr %p.4, align 1
382 store i8 0, ptr %p.4, align 1
383 %q = call ptr @strdup(ptr %p) nounwind optsize
384 store i8 %tmp, ptr %p.4, align 1
388 ; Don't remove redundant store because of may-aliased store.
389 define i32 @test28(i1 %c, ptr %p, ptr %p2, i32 %i) {
390 ; CHECK-LABEL: @test28(
392 ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[P:%.*]], align 4
393 ; CHECK-NEXT: store i32 [[I:%.*]], ptr [[P2:%.*]], align 4
394 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
396 ; CHECK-NEXT: br label [[BB3:%.*]]
398 ; CHECK-NEXT: br label [[BB3]]
400 ; CHECK-NEXT: store i32 [[V]], ptr [[P]], align 4
401 ; CHECK-NEXT: ret i32 0
404 %v = load i32, ptr %p, align 4
406 ; Might overwrite value at %p
407 store i32 %i, ptr %p2, align 4
408 br i1 %c, label %bb1, label %bb2
414 store i32 %v, ptr %p, align 4
418 ; Don't remove redundant store because of may-aliased store.
419 define i32 @test29(i1 %c, ptr %p, ptr %p2, i32 %i) {
420 ; CHECK-LABEL: @test29(
422 ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[P:%.*]], align 4
423 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
425 ; CHECK-NEXT: br label [[BB3:%.*]]
427 ; CHECK-NEXT: store i32 [[I:%.*]], ptr [[P2:%.*]], align 4
428 ; CHECK-NEXT: br label [[BB3]]
430 ; CHECK-NEXT: store i32 [[V]], ptr [[P]], align 4
431 ; CHECK-NEXT: ret i32 0
434 %v = load i32, ptr %p, align 4
435 br i1 %c, label %bb1, label %bb2
439 ; Might overwrite value at %p
440 store i32 %i, ptr %p2, align 4
443 store i32 %v, ptr %p, align 4
447 declare void @unknown_func()
449 ; Don't remove redundant store because of unknown call.
450 define i32 @test30(i1 %c, ptr %p, i32 %i) {
451 ; CHECK-LABEL: @test30(
453 ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[P:%.*]], align 4
454 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
456 ; CHECK-NEXT: br label [[BB3:%.*]]
458 ; CHECK-NEXT: call void @unknown_func()
459 ; CHECK-NEXT: br label [[BB3]]
461 ; CHECK-NEXT: store i32 [[V]], ptr [[P]], align 4
462 ; CHECK-NEXT: ret i32 0
465 %v = load i32, ptr %p, align 4
466 br i1 %c, label %bb1, label %bb2
470 ; Might overwrite value at %p
471 call void @unknown_func()
474 store i32 %v, ptr %p, align 4
478 ; Don't remove redundant store in a loop with a may-alias store.
479 define i32 @test32(i1 %c, ptr %p, i32 %i) {
480 ; CHECK-LABEL: @test32(
482 ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[P:%.*]], align 4
483 ; CHECK-NEXT: br label [[BB1:%.*]]
485 ; CHECK-NEXT: store i32 [[V]], ptr [[P]], align 4
486 ; CHECK-NEXT: call void @unknown_func()
487 ; CHECK-NEXT: br i1 undef, label [[BB1]], label [[BB2:%.*]]
489 ; CHECK-NEXT: ret i32 0
492 %v = load i32, ptr %p, align 4
495 store i32 %v, ptr %p, align 4
496 ; Might read and overwrite value at %p
497 call void @unknown_func()
498 br i1 undef, label %bb1, label %bb2
503 ; We cannot remove any stores, because @unknown_func may unwind and the caller
504 ; may read %p while unwinding.
505 define void @test34(ptr noalias %p) {
506 ; CHECK-LABEL: @test34(
507 ; CHECK-NEXT: store i32 1, ptr [[P:%.*]], align 4
508 ; CHECK-NEXT: call void @unknown_func()
509 ; CHECK-NEXT: store i32 0, ptr [[P]], align 4
510 ; CHECK-NEXT: ret void
513 call void @unknown_func()
517 ; Same as previous case, but with an sret argument.
518 ; TODO: The first store could be eliminated if sret is not visible on unwind.
519 define void @test34_sret(ptr noalias sret(i32) %p) {
520 ; CHECK-LABEL: @test34_sret(
521 ; CHECK-NEXT: store i32 1, ptr [[P:%.*]], align 4
522 ; CHECK-NEXT: call void @unknown_func()
523 ; CHECK-NEXT: store i32 0, ptr [[P]], align 4
524 ; CHECK-NEXT: ret void
527 call void @unknown_func()
532 ; Remove redundant store even with an unwinding function in the same block
533 define void @test35(ptr noalias %p) {
534 ; CHECK-LABEL: @test35(
535 ; CHECK-NEXT: call void @unknown_func()
536 ; CHECK-NEXT: store i32 0, ptr [[P:%.*]], align 4
537 ; CHECK-NEXT: ret void
539 call void @unknown_func()
545 ; We cannot optimize away the first memmove since %P could overlap with %Q.
546 define void @test36(ptr %P, ptr %Q) {
547 ; CHECK-LABEL: @test36(
548 ; CHECK-NEXT: tail call void @llvm.memmove.p0.p0.i64(ptr [[P:%.*]], ptr [[Q:%.*]], i64 12, i1 false)
549 ; CHECK-NEXT: tail call void @llvm.memmove.p0.p0.i64(ptr [[P]], ptr [[Q]], i64 12, i1 false)
550 ; CHECK-NEXT: ret void
553 tail call void @llvm.memmove.p0.p0.i64(ptr %P, ptr %Q, i64 12, i1 false)
554 tail call void @llvm.memmove.p0.p0.i64(ptr %P, ptr %Q, i64 12, i1 false)
558 define void @test36_atomic(ptr %P, ptr %Q) {
559 ; CHECK-LABEL: @test36_atomic(
560 ; CHECK-NEXT: tail call void @llvm.memmove.element.unordered.atomic.p0.p0.i64(ptr align 1 [[P:%.*]], ptr align 1 [[Q:%.*]], i64 12, i32 1)
561 ; CHECK-NEXT: tail call void @llvm.memmove.element.unordered.atomic.p0.p0.i64(ptr align 1 [[P]], ptr align 1 [[Q]], i64 12, i32 1)
562 ; CHECK-NEXT: ret void
565 tail call void @llvm.memmove.element.unordered.atomic.p0.p0.i64(ptr align 1 %P, ptr align 1 %Q, i64 12, i32 1)
566 tail call void @llvm.memmove.element.unordered.atomic.p0.p0.i64(ptr align 1 %P, ptr align 1 %Q, i64 12, i32 1)
570 define void @test37(ptr %P, ptr %Q, ptr %R) {
571 ; CHECK-LABEL: @test37(
572 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr [[P:%.*]], ptr [[Q:%.*]], i64 12, i1 false)
573 ; CHECK-NEXT: tail call void @llvm.memmove.p0.p0.i64(ptr [[P]], ptr [[R:%.*]], i64 12, i1 false)
574 ; CHECK-NEXT: ret void
577 tail call void @llvm.memcpy.p0.p0.i64(ptr %P, ptr %Q, i64 12, i1 false)
578 tail call void @llvm.memmove.p0.p0.i64(ptr %P, ptr %R, i64 12, i1 false)
582 define void @test37_atomic(ptr %P, ptr %Q, ptr %R) {
583 ; CHECK-LABEL: @test37_atomic(
584 ; CHECK-NEXT: tail call void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr align 1 [[P:%.*]], ptr align 1 [[Q:%.*]], i64 12, i32 1)
585 ; CHECK-NEXT: tail call void @llvm.memmove.element.unordered.atomic.p0.p0.i64(ptr align 1 [[P]], ptr align 1 [[R:%.*]], i64 12, i32 1)
586 ; CHECK-NEXT: ret void
589 tail call void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr align 1 %P, ptr align 1 %Q, i64 12, i32 1)
590 tail call void @llvm.memmove.element.unordered.atomic.p0.p0.i64(ptr align 1 %P, ptr align 1 %R, i64 12, i32 1)
594 ; See PR11763 - LLVM allows memcpy's source and destination to be equal (but not
595 ; inequal and overlapping).
596 define void @test38(ptr %P, ptr %Q, ptr %R) {
597 ; CHECK-LABEL: @test38(
598 ; CHECK-NEXT: tail call void @llvm.memmove.p0.p0.i64(ptr [[P:%.*]], ptr [[Q:%.*]], i64 12, i1 false)
599 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr [[P]], ptr [[R:%.*]], i64 12, i1 false)
600 ; CHECK-NEXT: ret void
603 tail call void @llvm.memmove.p0.p0.i64(ptr %P, ptr %Q, i64 12, i1 false)
604 tail call void @llvm.memcpy.p0.p0.i64(ptr %P, ptr %R, i64 12, i1 false)
608 ; See PR11763 - LLVM allows memcpy's source and destination to be equal (but not
609 ; inequal and overlapping).
610 define void @test38_atomic(ptr %P, ptr %Q, ptr %R) {
611 ; CHECK-LABEL: @test38_atomic(
612 ; CHECK-NEXT: tail call void @llvm.memmove.element.unordered.atomic.p0.p0.i64(ptr align 1 [[P:%.*]], ptr align 1 [[Q:%.*]], i64 12, i32 1)
613 ; CHECK-NEXT: tail call void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr align 1 [[P]], ptr align 1 [[R:%.*]], i64 12, i32 1)
614 ; CHECK-NEXT: ret void
617 tail call void @llvm.memmove.element.unordered.atomic.p0.p0.i64(ptr align 1 %P, ptr align 1 %Q, i64 12, i32 1)
618 tail call void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr align 1 %P, ptr align 1 %R, i64 12, i32 1)
622 define void @test39(ptr %P, ptr %Q, ptr %R) {
623 ; CHECK-LABEL: @test39(
624 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr [[P:%.*]], ptr [[Q:%.*]], i64 12, i1 false)
625 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr [[P]], ptr [[R:%.*]], i64 8, i1 false)
626 ; CHECK-NEXT: ret void
629 tail call void @llvm.memcpy.p0.p0.i64(ptr %P, ptr %Q, i64 12, i1 false)
630 tail call void @llvm.memcpy.p0.p0.i64(ptr %P, ptr %R, i64 8, i1 false)
634 define void @test39_atomic(ptr %P, ptr %Q, ptr %R) {
635 ; CHECK-LABEL: @test39_atomic(
636 ; CHECK-NEXT: tail call void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr align 1 [[P:%.*]], ptr align 1 [[Q:%.*]], i64 12, i32 1)
637 ; CHECK-NEXT: tail call void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr align 1 [[P]], ptr align 1 [[R:%.*]], i64 8, i32 1)
638 ; CHECK-NEXT: ret void
641 tail call void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr align 1 %P, ptr align 1 %Q, i64 12, i32 1)
642 tail call void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr align 1 %P, ptr align 1 %R, i64 8, i32 1)
646 declare void @llvm.memmove.p0.p0.i64(ptr nocapture, ptr nocapture readonly, i64, i1)
647 declare void @llvm.memmove.element.unordered.atomic.p0.p0.i64(ptr nocapture, ptr nocapture readonly, i64, i32)
649 declare void @llvm.lifetime.start.p0(i64, ptr nocapture) nounwind
650 declare void @llvm.lifetime.end.p0(i64, ptr nocapture) nounwind
651 define void @test40(ptr noalias %Pp, ptr noalias %Q) {
652 ; CHECK-LABEL: @test40(
654 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
655 ; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr nonnull [[A]])
656 ; CHECK-NEXT: [[PC:%.*]] = load ptr, ptr [[PP:%.*]], align 8
657 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 [[A]], ptr align 4 [[Q:%.*]], i64 4, i1 false)
658 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[PC]], ptr nonnull align 4 [[A]], i64 4, i1 true)
659 ; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr nonnull [[A]])
660 ; CHECK-NEXT: ret void
663 %A = alloca i32, align 4
664 call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %A)
665 %Pc = load ptr, ptr %Pp, align 8
666 call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 %A, ptr align 4 %Q, i64 4, i1 false)
667 call void @llvm.memcpy.p0.p0.i64(ptr align 4 %Pc, ptr nonnull align 4 %A, i64 4, i1 true)
668 call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %A)
672 declare void @free(ptr nocapture) allockind("free")
674 ; We cannot remove `store i32 1, ptr %p`, because @unknown_func may unwind
675 ; and the caller may read %p while unwinding.
676 define void @test41(ptr noalias %P) {
677 ; CHECK-LABEL: @test41(
678 ; CHECK-NEXT: store i32 1, ptr [[P:%.*]], align 4
679 ; CHECK-NEXT: call void @unknown_func()
680 ; CHECK-NEXT: call void @free(ptr [[P]])
681 ; CHECK-NEXT: ret void
684 call void @unknown_func()
686 call void @free(ptr %P)
690 define void @test42(ptr %P, ptr %Q) {
691 ; CHECK-LABEL: @test42(
692 ; CHECK-NEXT: store i32 1, ptr [[P:%.*]], align 4
693 ; CHECK-NEXT: store i32 2, ptr [[Q:%.*]], align 4
694 ; CHECK-NEXT: store i8 3, ptr [[P]], align 1
695 ; CHECK-NEXT: ret void
703 define void @test42a(ptr %P, ptr %Q) {
704 ; CHECK-LABEL: @test42a(
705 ; CHECK-NEXT: store atomic i32 1, ptr [[P:%.*]] unordered, align 4
706 ; CHECK-NEXT: store atomic i32 2, ptr [[Q:%.*]] unordered, align 4
707 ; CHECK-NEXT: store atomic i8 3, ptr [[P]] unordered, align 4
708 ; CHECK-NEXT: ret void
710 store atomic i32 1, ptr %P unordered, align 4
711 store atomic i32 2, ptr %Q unordered, align 4
712 store atomic i8 3, ptr %P unordered, align 4
716 define void @test43a(ptr %P, ptr noalias %Q) {
717 ; CHECK-LABEL: @test43a(
719 ; CHECK-NEXT: store atomic i32 50331649, ptr [[P:%.*]] unordered, align 4
720 ; CHECK-NEXT: store atomic i32 2, ptr [[Q:%.*]] unordered, align 4
721 ; CHECK-NEXT: ret void
724 store atomic i32 1, ptr %P unordered, align 4
725 store atomic i32 2, ptr %Q unordered, align 4
726 store atomic i8 3, ptr %P unordered, align 4
730 ; Some tests where volatile may block removing a store.
732 ; Here we can remove the first non-volatile store. We cannot remove the
734 define void @test44_volatile(ptr %P) {
735 ; CHECK-LABEL: @test44_volatile(
736 ; CHECK-NEXT: store volatile i32 2, ptr [[P:%.*]], align 4
737 ; CHECK-NEXT: store i32 3, ptr [[P]], align 4
738 ; CHECK-NEXT: ret void
740 store i32 1, ptr %P, align 4
741 store volatile i32 2, ptr %P, align 4
742 store i32 3, ptr %P, align 4
746 define void @test45_volatile(ptr %P) {
747 ; CHECK-LABEL: @test45_volatile(
748 ; CHECK-NEXT: store volatile i32 2, ptr [[P:%.*]], align 4
749 ; CHECK-NEXT: store volatile i32 3, ptr [[P]], align 4
750 ; CHECK-NEXT: ret void
752 store i32 1, ptr %P, align 4
753 store volatile i32 2, ptr %P, align 4
754 store volatile i32 3, ptr %P, align 4
758 define void @test46_volatile(ptr %P) {
759 ; CHECK-LABEL: @test46_volatile(
760 ; CHECK-NEXT: store volatile i32 2, ptr [[P:%.*]], align 4
761 ; CHECK-NEXT: store volatile i32 3, ptr [[P]], align 4
762 ; CHECK-NEXT: ret void
764 store volatile i32 2, ptr %P, align 4
765 store i32 1, ptr %P, align 4
766 store volatile i32 3, ptr %P, align 4
770 define void @test47_volatile(ptr %P) {
771 ; CHECK-LABEL: @test47_volatile(
772 ; CHECK-NEXT: store volatile i32 2, ptr [[P:%.*]], align 4
773 ; CHECK-NEXT: store volatile i32 3, ptr [[P]], align 4
774 ; CHECK-NEXT: ret void
776 store volatile i32 2, ptr %P, align 4
777 store volatile i32 3, ptr %P, align 4
781 define i32 @test48(ptr %P, ptr noalias %Q, ptr %R) {
782 ; CHECK-LABEL: @test48(
783 ; CHECK-NEXT: store i32 2, ptr [[P:%.*]], align 4
784 ; CHECK-NEXT: store i32 3, ptr [[Q:%.*]], align 4
785 ; CHECK-NEXT: [[L:%.*]] = load i32, ptr [[R:%.*]], align 4
786 ; CHECK-NEXT: ret i32 [[L]]
791 %l = load i32, ptr %R