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 -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.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
7 declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* nocapture, i8, i64, i32) nounwind
8 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
9 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32) nounwind
10 declare void @llvm.init.trampoline(i8*, i8*, i8*)
11 declare void @llvm.matrix.column.major.store(<6 x float>, float*, i64, i1, i32, i32)
13 define void @test1(i32* %Q, i32* %P) {
14 ; CHECK-LABEL: @test1(
15 ; CHECK-NEXT: store i32 0, i32* [[P:%.*]], align 4
16 ; CHECK-NEXT: ret void
18 %DEAD = load i32, i32* %Q
19 store i32 %DEAD, i32* %P
27 define i32 @test3(i32* %g_addr) nounwind {
28 ; CHECK-LABEL: @test3(
29 ; CHECK-NEXT: [[G_VALUE:%.*]] = load i32, i32* [[G_ADDR:%.*]], align 4
30 ; CHECK-NEXT: store i32 -1, i32* @g, align 4
31 ; CHECK-NEXT: store i32 [[G_VALUE]], i32* [[G_ADDR]], align 4
32 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, i32* @g, align 4
33 ; CHECK-NEXT: ret i32 [[TMP3]]
35 %g_value = load i32, i32* %g_addr, align 4
36 store i32 -1, i32* @g, align 4
37 store i32 %g_value, i32* %g_addr, align 4
38 %tmp3 = load i32, i32* @g, align 4
43 define void @test4(i32* %Q) {
44 ; CHECK-LABEL: @test4(
45 ; CHECK-NEXT: [[A:%.*]] = load i32, i32* [[Q:%.*]], align 4
46 ; CHECK-NEXT: store volatile i32 [[A]], i32* [[Q]], align 4
47 ; CHECK-NEXT: ret void
49 %a = load i32, i32* %Q
50 store volatile i32 %a, i32* %Q
54 ; PR8576 - Should delete store of 10 even though p/q are may aliases.
55 define void @test2(i32 *%p, i32 *%q) {
56 ; CHECK-LABEL: @test2(
57 ; CHECK-NEXT: store i32 20, i32* [[Q:%.*]], align 4
58 ; CHECK-NEXT: store i32 30, i32* [[P:%.*]], align 4
59 ; CHECK-NEXT: ret void
61 store i32 10, i32* %p, align 4
62 store i32 20, i32* %q, align 4
63 store i32 30, i32* %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(i32 *%p, i8 *%q) {
70 ; CHECK-LABEL: @test6(
71 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[Q:%.*]], i8 42, i64 900, i1 false)
72 ; CHECK-NEXT: store i32 30, i32* [[P:%.*]], align 4
73 ; CHECK-NEXT: ret void
75 store i32 10, i32* %p, align 4 ;; dead.
76 call void @llvm.memset.p0i8.i64(i8* %q, i8 42, i64 900, i1 false)
77 store i32 30, i32* %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(i32* align 4 %p, i8* align 4 %q) {
84 ; CHECK-LABEL: @test6_atomic(
85 ; CHECK-NEXT: call void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* align 4 [[Q:%.*]], i8 42, i64 900, i32 4)
86 ; CHECK-NEXT: store atomic i32 30, i32* [[P:%.*]] unordered, align 4
87 ; CHECK-NEXT: ret void
89 store atomic i32 10, i32* %p unordered, align 4 ;; dead.
90 call void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* align 4 %q, i8 42, i64 900, i32 4)
91 store atomic i32 30, i32* %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(i32 *%p, i8 *%q, i8* noalias %r) {
98 ; CHECK-LABEL: @test7(
99 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[Q:%.*]], i8* [[R:%.*]], i64 900, i1 false)
100 ; CHECK-NEXT: store i32 30, i32* [[P:%.*]], align 4
101 ; CHECK-NEXT: ret void
103 store i32 10, i32* %p, align 4 ;; dead.
104 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %q, i8* %r, i64 900, i1 false)
105 store i32 30, i32* %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(i32* align 4 %p, i8* align 4 %q, i8* noalias align 4 %r) {
112 ; CHECK-LABEL: @test7_atomic(
113 ; CHECK-NEXT: call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 4 [[Q:%.*]], i8* align 4 [[R:%.*]], i64 900, i32 4)
114 ; CHECK-NEXT: store atomic i32 30, i32* [[P:%.*]] unordered, align 4
115 ; CHECK-NEXT: ret void
117 store atomic i32 10, i32* %p unordered, align 4 ;; dead.
118 call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 4 %q, i8* align 4 %r, i64 900, i32 4)
119 store atomic i32 30, i32* %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, i32* [[V]], align 4
128 ; CHECK-NEXT: [[X:%.*]] = load i32, i32* [[V]], align 4
129 ; CHECK-NEXT: ret i32 [[X]]
132 store i32 1234567, i32* %V
133 %V2 = bitcast i32* %V to i8*
135 %X = load i32, i32* %V
140 ; Test for byval handling.
141 %struct.x = type { i32, i32, i32, i32 }
142 define void @test9(%struct.x* byval(%struct.x) %a) nounwind {
143 ; CHECK-LABEL: @test9(
144 ; CHECK-NEXT: ret void
146 %tmp2 = getelementptr %struct.x, %struct.x* %a, i32 0, i32 0
147 store i32 1, i32* %tmp2, align 4
151 ; Test for inalloca handling.
152 define void @test9_2(%struct.x* inalloca(%struct.x) %a) nounwind {
153 ; CHECK-LABEL: @test9_2(
154 ; CHECK-NEXT: ret void
156 %tmp2 = getelementptr %struct.x, %struct.x* %a, i32 0, i32 0
157 store i32 1, i32* %tmp2, align 4
161 ; Test for preallocated handling.
162 define void @test9_3(%struct.x* preallocated(%struct.x) %a) nounwind {
163 ; CHECK-LABEL: @test9_3(
164 ; CHECK-NEXT: ret void
166 %tmp2 = getelementptr %struct.x, %struct.x* %a, i32 0, i32 0
167 store i32 1, i32* %tmp2, align 4
171 ; va_arg has fuzzy dependence, the store shouldn't be zapped.
172 define double @test10(i8* %X) {
173 ; CHECK-LABEL: @test10(
174 ; CHECK-NEXT: [[X_ADDR:%.*]] = alloca i8*, align 8
175 ; CHECK-NEXT: store i8* [[X:%.*]], i8** [[X_ADDR]], align 8
176 ; CHECK-NEXT: [[TMP_0:%.*]] = va_arg i8** [[X_ADDR]], double
177 ; CHECK-NEXT: ret double [[TMP_0]]
180 store i8* %X, i8** %X_addr
181 %tmp.0 = va_arg i8** %X_addr, double
185 ; DSE should delete the dead trampoline.
186 declare void @test11f()
187 define void @test11() {
188 ; CHECK-LABEL: @test11(
189 ; CHECK-NEXT: ret void
191 %storage = alloca [10 x i8], align 16 ; <[10 x i8]*> [#uses=1]
192 %cast = getelementptr [10 x i8], [10 x i8]* %storage, i32 0, i32 0 ; <i8*> [#uses=1]
193 call void @llvm.init.trampoline( i8* %cast, i8* bitcast (void ()* @test11f to i8*), i8* null ) ; <i8*> [#uses=1]
197 ; Specialized store intrinsics should be removed if dead.
198 define void @test_matrix_store(i64 %stride) {
199 ; CHECK-LABEL: @test_matrix_store(
200 ; CHECK-NEXT: ret void
202 %a = alloca [6 x float]
203 %cast = bitcast [6 x float]* %a to float*
204 call void @llvm.matrix.column.major.store(<6 x float> zeroinitializer, float* %cast, i64 %stride, i1 false, i32 3, i32 2)
208 ; %P doesn't escape, the DEAD instructions should be removed.
209 declare void @may_unwind()
210 define i32* @test_malloc_no_escape_before_return() {
211 ; CHECK-LABEL: @test_malloc_no_escape_before_return(
212 ; CHECK-NEXT: [[PTR:%.*]] = tail call i8* @malloc(i32 4)
213 ; CHECK-NEXT: [[P:%.*]] = bitcast i8* [[PTR]] to i32*
214 ; CHECK-NEXT: call void @may_unwind()
215 ; CHECK-NEXT: store i32 0, i32* [[P]], align 4
216 ; CHECK-NEXT: ret i32* [[P]]
218 %ptr = tail call i8* @malloc(i32 4)
219 %P = bitcast i8* %ptr to i32*
220 %DEAD = load i32, i32* %P
221 %DEAD2 = add i32 %DEAD, 1
222 store i32 %DEAD2, i32* %P
223 call void @may_unwind()
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: call void @may_unwind()
233 ; CHECK-NEXT: store i32 0, i32* [[P]], align 4
234 ; CHECK-NEXT: ret i32* [[P]]
236 %ptr = tail call i8* @custom_malloc(i32 4)
237 %P = bitcast i8* %ptr to i32*
238 %DEAD = load i32, i32* %P
239 %DEAD2 = add i32 %DEAD, 1
240 store i32 %DEAD2, i32* %P
241 call void @may_unwind()
246 define i32 addrspace(1)* @test13_addrspacecast() {
247 ; CHECK-LABEL: @test13_addrspacecast(
248 ; CHECK-NEXT: [[P:%.*]] = tail call i8* @malloc(i32 4)
249 ; CHECK-NEXT: [[P_BC:%.*]] = bitcast i8* [[P]] to i32*
250 ; CHECK-NEXT: [[P:%.*]] = addrspacecast i32* [[P_BC]] to i32 addrspace(1)*
251 ; CHECK-NEXT: call void @may_unwind()
252 ; CHECK-NEXT: store i32 0, i32 addrspace(1)* [[P]], align 4
253 ; CHECK-NEXT: ret i32 addrspace(1)* [[P]]
255 %p = tail call i8* @malloc(i32 4)
256 %p.bc = bitcast i8* %p to i32*
257 %P = addrspacecast i32* %p.bc to i32 addrspace(1)*
258 %DEAD = load i32, i32 addrspace(1)* %P
259 %DEAD2 = add i32 %DEAD, 1
260 store i32 %DEAD2, i32 addrspace(1)* %P
261 call void @may_unwind()
262 store i32 0, i32 addrspace(1)* %P
263 ret i32 addrspace(1)* %P
267 declare noalias i8* @malloc(i32) willreturn
268 declare noalias i8* @custom_malloc(i32) willreturn
269 declare noalias i8* @calloc(i32, i32) willreturn
271 define void @test14(i32* %Q) {
272 ; CHECK-LABEL: @test14(
273 ; CHECK-NEXT: ret void
276 %DEAD = load i32, i32* %Q
277 store i32 %DEAD, i32* %P
282 ; The store here is not dead because the byval call reads it.
283 declare void @test19f({i32}* byval({i32}) align 4 %P)
285 define void @test19({i32}* nocapture byval({i32}) align 4 %arg5) nounwind ssp {
286 ; CHECK-LABEL: @test19(
288 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds { i32 }, { i32 }* [[ARG5:%.*]], i32 0, i32 0
289 ; CHECK-NEXT: store i32 912, i32* [[TMP7]], align 4
290 ; CHECK-NEXT: call void @test19f({ i32 }* byval({ i32 }) align 4 [[ARG5]])
291 ; CHECK-NEXT: ret void
294 %tmp7 = getelementptr inbounds {i32}, {i32}* %arg5, i32 0, i32 0
295 store i32 912, i32* %tmp7
296 call void @test19f({i32}* byval({i32}) align 4 %arg5)
301 define void @malloc_no_escape() {
302 ; CHECK-LABEL: @malloc_no_escape(
303 ; CHECK-NEXT: ret void
305 %m = call i8* @malloc(i32 24)
310 define void @custom_malloc_no_escape() {
311 ; CHECK-LABEL: @custom_malloc_no_escape(
312 ; CHECK-NEXT: [[M:%.*]] = call i8* @custom_malloc(i32 24)
313 ; CHECK-NEXT: ret void
315 %m = call i8* @custom_malloc(i32 24)
320 define void @test21() {
321 ; CHECK-LABEL: @test21(
322 ; CHECK-NEXT: ret void
324 %m = call i8* @calloc(i32 9, i32 7)
329 ; Currently elimination of stores at the end of a function is limited to a
330 ; single underlying object, for compile-time. This case appears to not be
331 ; very important in practice.
332 define void @test22(i1 %i, i32 %k, i32 %m) nounwind {
333 ; CHECK-LABEL: @test22(
334 ; CHECK-NEXT: [[K_ADDR:%.*]] = alloca i32, align 4
335 ; CHECK-NEXT: [[M_ADDR:%.*]] = alloca i32, align 4
336 ; CHECK-NEXT: [[K_ADDR_M_ADDR:%.*]] = select i1 [[I:%.*]], i32* [[K_ADDR]], i32* [[M_ADDR]]
337 ; CHECK-NEXT: store i32 0, i32* [[K_ADDR_M_ADDR]], align 4
338 ; CHECK-NEXT: ret void
342 %k.addr.m.addr = select i1 %i, i32* %k.addr, i32* %m.addr
343 store i32 0, i32* %k.addr.m.addr, align 4
348 declare noalias i8* @strdup(i8* nocapture) nounwind
349 define noalias i8* @test23() nounwind uwtable ssp {
350 ; CHECK-LABEL: @test23(
351 ; CHECK-NEXT: [[X:%.*]] = alloca [2 x i8], align 1
352 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [2 x i8], [2 x i8]* [[X]], i64 0, i64 0
353 ; CHECK-NEXT: store i8 97, i8* [[ARRAYIDX]], align 1
354 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds [2 x i8], [2 x i8]* [[X]], i64 0, i64 1
355 ; CHECK-NEXT: store i8 0, i8* [[ARRAYIDX1]], align 1
356 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @strdup(i8* [[ARRAYIDX]]) #[[ATTR5:[0-9]+]]
357 ; CHECK-NEXT: ret i8* [[CALL]]
359 %x = alloca [2 x i8], align 1
360 %arrayidx = getelementptr inbounds [2 x i8], [2 x i8]* %x, i64 0, i64 0
361 store i8 97, i8* %arrayidx, align 1
362 %arrayidx1 = getelementptr inbounds [2 x i8], [2 x i8]* %x, i64 0, i64 1
363 store i8 0, i8* %arrayidx1, align 1
364 %call = call i8* @strdup(i8* %arrayidx) nounwind
368 ; Make sure same sized store to later element is deleted
369 define void @test24([2 x i32]* %a, i32 %b, i32 %c) nounwind {
370 ; CHECK-LABEL: @test24(
371 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [2 x i32], [2 x i32]* [[A:%.*]], i64 0, i64 0
372 ; CHECK-NEXT: store i32 [[B:%.*]], i32* [[TMP1]], align 4
373 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [2 x i32], [2 x i32]* [[A]], i64 0, i64 1
374 ; CHECK-NEXT: store i32 [[C:%.*]], i32* [[TMP2]], align 4
375 ; CHECK-NEXT: ret void
377 %1 = getelementptr inbounds [2 x i32], [2 x i32]* %a, i64 0, i64 0
378 store i32 0, i32* %1, align 4
379 %2 = getelementptr inbounds [2 x i32], [2 x i32]* %a, i64 0, i64 1
380 store i32 0, i32* %2, align 4
381 %3 = getelementptr inbounds [2 x i32], [2 x i32]* %a, i64 0, i64 0
382 store i32 %b, i32* %3, align 4
383 %4 = getelementptr inbounds [2 x i32], [2 x i32]* %a, i64 0, i64 1
384 store i32 %c, i32* %4, align 4
388 ; Check another case like PR13547 where strdup is not like malloc.
389 define i8* @test25(i8* %p) nounwind {
390 ; CHECK-LABEL: @test25(
391 ; CHECK-NEXT: [[P_4:%.*]] = getelementptr i8, i8* [[P:%.*]], i64 4
392 ; CHECK-NEXT: [[TMP:%.*]] = load i8, i8* [[P_4]], align 1
393 ; CHECK-NEXT: store i8 0, i8* [[P_4]], align 1
394 ; CHECK-NEXT: [[Q:%.*]] = call i8* @strdup(i8* [[P]]) #[[ATTR10:[0-9]+]]
395 ; CHECK-NEXT: store i8 [[TMP]], i8* [[P_4]], align 1
396 ; CHECK-NEXT: ret i8* [[Q]]
398 %p.4 = getelementptr i8, i8* %p, i64 4
399 %tmp = load i8, i8* %p.4, align 1
400 store i8 0, i8* %p.4, align 1
401 %q = call i8* @strdup(i8* %p) nounwind optsize
402 store i8 %tmp, i8* %p.4, align 1
406 ; Don't remove redundant store because of may-aliased store.
407 define i32 @test28(i1 %c, i32* %p, i32* %p2, i32 %i) {
408 ; CHECK-LABEL: @test28(
410 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
411 ; CHECK-NEXT: store i32 [[I:%.*]], i32* [[P2:%.*]], align 4
412 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
414 ; CHECK-NEXT: br label [[BB3:%.*]]
416 ; CHECK-NEXT: br label [[BB3]]
418 ; CHECK-NEXT: store i32 [[V]], i32* [[P]], align 4
419 ; CHECK-NEXT: ret i32 0
422 %v = load i32, i32* %p, align 4
424 ; Might overwrite value at %p
425 store i32 %i, i32* %p2, align 4
426 br i1 %c, label %bb1, label %bb2
432 store i32 %v, i32* %p, align 4
436 ; Don't remove redundant store because of may-aliased store.
437 define i32 @test29(i1 %c, i32* %p, i32* %p2, i32 %i) {
438 ; CHECK-LABEL: @test29(
440 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
441 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
443 ; CHECK-NEXT: br label [[BB3:%.*]]
445 ; CHECK-NEXT: store i32 [[I:%.*]], i32* [[P2:%.*]], align 4
446 ; CHECK-NEXT: br label [[BB3]]
448 ; CHECK-NEXT: store i32 [[V]], i32* [[P]], align 4
449 ; CHECK-NEXT: ret i32 0
452 %v = load i32, i32* %p, align 4
453 br i1 %c, label %bb1, label %bb2
457 ; Might overwrite value at %p
458 store i32 %i, i32* %p2, align 4
461 store i32 %v, i32* %p, align 4
465 declare void @unknown_func()
467 ; Don't remove redundant store because of unknown call.
468 define i32 @test30(i1 %c, i32* %p, i32 %i) {
469 ; CHECK-LABEL: @test30(
471 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
472 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
474 ; CHECK-NEXT: br label [[BB3:%.*]]
476 ; CHECK-NEXT: call void @unknown_func()
477 ; CHECK-NEXT: br label [[BB3]]
479 ; CHECK-NEXT: store i32 [[V]], i32* [[P]], align 4
480 ; CHECK-NEXT: ret i32 0
483 %v = load i32, i32* %p, align 4
484 br i1 %c, label %bb1, label %bb2
488 ; Might overwrite value at %p
489 call void @unknown_func()
492 store i32 %v, i32* %p, align 4
496 ; Don't remove redundant store in a loop with a may-alias store.
497 define i32 @test32(i1 %c, i32* %p, i32 %i) {
498 ; CHECK-LABEL: @test32(
500 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
501 ; CHECK-NEXT: br label [[BB1:%.*]]
503 ; CHECK-NEXT: store i32 [[V]], i32* [[P]], align 4
504 ; CHECK-NEXT: call void @unknown_func()
505 ; CHECK-NEXT: br i1 undef, label [[BB1]], label [[BB2:%.*]]
507 ; CHECK-NEXT: ret i32 0
510 %v = load i32, i32* %p, align 4
513 store i32 %v, i32* %p, align 4
514 ; Might read and overwrite value at %p
515 call void @unknown_func()
516 br i1 undef, label %bb1, label %bb2
521 ; We cannot remove any stores, because @unknown_func may unwind and the caller
522 ; may read %p while unwinding.
523 define void @test34(i32* noalias %p) {
524 ; CHECK-LABEL: @test34(
525 ; CHECK-NEXT: store i32 1, i32* [[P:%.*]], align 4
526 ; CHECK-NEXT: call void @unknown_func()
527 ; CHECK-NEXT: store i32 0, i32* [[P]], align 4
528 ; CHECK-NEXT: ret void
531 call void @unknown_func()
536 ; Remove redundant store even with an unwinding function in the same block
537 define void @test35(i32* noalias %p) {
538 ; CHECK-LABEL: @test35(
539 ; CHECK-NEXT: call void @unknown_func()
540 ; CHECK-NEXT: store i32 0, i32* [[P:%.*]], align 4
541 ; CHECK-NEXT: ret void
543 call void @unknown_func()
549 ; We cannot optimize away the first memmove since %P could overlap with %Q.
550 define void @test36(i8* %P, i8* %Q) {
551 ; CHECK-LABEL: @test36(
552 ; CHECK-NEXT: tail call void @llvm.memmove.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
553 ; CHECK-NEXT: tail call void @llvm.memmove.p0i8.p0i8.i64(i8* [[P]], i8* [[Q]], i64 12, i1 false)
554 ; CHECK-NEXT: ret void
557 tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
558 tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
562 define void @test36_atomic(i8* %P, i8* %Q) {
563 ; CHECK-LABEL: @test36_atomic(
564 ; CHECK-NEXT: tail call void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 [[P:%.*]], i8* align 1 [[Q:%.*]], i64 12, i32 1)
565 ; CHECK-NEXT: tail call void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 [[P]], i8* align 1 [[Q]], i64 12, i32 1)
566 ; CHECK-NEXT: ret void
569 tail call void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i32 1)
570 tail call void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i32 1)
574 define void @test37(i8* %P, i8* %Q, i8* %R) {
575 ; CHECK-LABEL: @test37(
576 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
577 ; CHECK-NEXT: tail call void @llvm.memmove.p0i8.p0i8.i64(i8* [[P]], i8* [[R:%.*]], i64 12, i1 false)
578 ; CHECK-NEXT: ret void
581 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
582 tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %P, i8* %R, i64 12, i1 false)
586 define void @test37_atomic(i8* %P, i8* %Q, i8* %R) {
587 ; CHECK-LABEL: @test37_atomic(
588 ; CHECK-NEXT: tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 [[P:%.*]], i8* align 1 [[Q:%.*]], i64 12, i32 1)
589 ; CHECK-NEXT: tail call void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 [[P]], i8* align 1 [[R:%.*]], i64 12, i32 1)
590 ; CHECK-NEXT: ret void
593 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i32 1)
594 tail call void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %R, i64 12, i32 1)
598 ; See PR11763 - LLVM allows memcpy's source and destination to be equal (but not
599 ; inequal and overlapping).
600 define void @test38(i8* %P, i8* %Q, i8* %R) {
601 ; CHECK-LABEL: @test38(
602 ; CHECK-NEXT: tail call void @llvm.memmove.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
603 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P]], i8* [[R:%.*]], i64 12, i1 false)
604 ; CHECK-NEXT: ret void
607 tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
608 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %R, i64 12, i1 false)
612 ; See PR11763 - LLVM allows memcpy's source and destination to be equal (but not
613 ; inequal and overlapping).
614 define void @test38_atomic(i8* %P, i8* %Q, i8* %R) {
615 ; CHECK-LABEL: @test38_atomic(
616 ; CHECK-NEXT: tail call void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 [[P:%.*]], i8* align 1 [[Q:%.*]], i64 12, i32 1)
617 ; CHECK-NEXT: tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 [[P]], i8* align 1 [[R:%.*]], i64 12, i32 1)
618 ; CHECK-NEXT: ret void
621 tail call void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i32 1)
622 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %R, i64 12, i32 1)
626 define void @test39(i8* %P, i8* %Q, i8* %R) {
627 ; CHECK-LABEL: @test39(
628 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
629 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P]], i8* [[R:%.*]], i64 8, i1 false)
630 ; CHECK-NEXT: ret void
633 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
634 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %R, i64 8, i1 false)
638 define void @test39_atomic(i8* %P, i8* %Q, i8* %R) {
639 ; CHECK-LABEL: @test39_atomic(
640 ; CHECK-NEXT: tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 [[P:%.*]], i8* align 1 [[Q:%.*]], i64 12, i32 1)
641 ; CHECK-NEXT: tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 [[P]], i8* align 1 [[R:%.*]], i64 8, i32 1)
642 ; CHECK-NEXT: ret void
645 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i32 1)
646 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %R, i64 8, i32 1)
650 declare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i1)
651 declare void @llvm.memmove.element.unordered.atomic.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32)
653 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) nounwind
654 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) nounwind
655 define void @test40(i32** noalias %Pp, i32* noalias %Q) {
656 ; CHECK-LABEL: @test40(
658 ; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
659 ; CHECK-NEXT: [[AC:%.*]] = bitcast i32* [[A]] to i8*
660 ; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull [[AC]])
661 ; CHECK-NEXT: [[TMP0:%.*]] = bitcast i32** [[PP:%.*]] to i8**
662 ; CHECK-NEXT: [[PC:%.*]] = load i8*, i8** [[TMP0]], align 8
663 ; CHECK-NEXT: [[QC:%.*]] = bitcast i32* [[Q:%.*]] to i8*
664 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 4 [[AC]], i8* align 4 [[QC]], i64 4, i1 false)
665 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[PC]], i8* nonnull align 4 [[AC]], i64 4, i1 true)
666 ; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull [[AC]])
667 ; CHECK-NEXT: ret void
670 %A = alloca i32, align 4
671 %Ac = bitcast i32* %A to i8*
672 call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %Ac)
673 %0 = bitcast i32** %Pp to i8**
674 %Pc = load i8*, i8** %0, align 8
675 %Qc = bitcast i32* %Q to i8*
676 call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 4 %Ac, i8* align 4 %Qc, i64 4, i1 false)
677 call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %Pc, i8* nonnull align 4 %Ac, i64 4, i1 true)
678 call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %Ac)
682 declare void @free(i8* nocapture)
684 ; We cannot remove `store i32 1, i32* %p`, because @unknown_func may unwind
685 ; and the caller may read %p while unwinding.
686 define void @test41(i32* noalias %P) {
687 ; CHECK-LABEL: @test41(
688 ; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P:%.*]] to i8*
689 ; CHECK-NEXT: store i32 1, i32* [[P]], align 4
690 ; CHECK-NEXT: call void @unknown_func()
691 ; CHECK-NEXT: call void @free(i8* [[P2]])
692 ; CHECK-NEXT: ret void
694 %P2 = bitcast i32* %P to i8*
696 call void @unknown_func()
698 call void @free(i8* %P2)
702 define void @test42(i32* %P, i32* %Q) {
703 ; CHECK-LABEL: @test42(
704 ; CHECK-NEXT: store i32 1, i32* [[P:%.*]], align 4
705 ; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P]] to i8*
706 ; CHECK-NEXT: store i32 2, i32* [[Q:%.*]], align 4
707 ; CHECK-NEXT: store i8 3, i8* [[P2]], align 1
708 ; CHECK-NEXT: ret void
711 %P2 = bitcast i32* %P to i8*
717 define void @test42a(i32* %P, i32* %Q) {
718 ; CHECK-LABEL: @test42a(
719 ; CHECK-NEXT: store atomic i32 1, i32* [[P:%.*]] unordered, align 4
720 ; CHECK-NEXT: [[P2:%.*]] = bitcast i32* [[P]] to i8*
721 ; CHECK-NEXT: store atomic i32 2, i32* [[Q:%.*]] unordered, align 4
722 ; CHECK-NEXT: store atomic i8 3, i8* [[P2]] unordered, align 4
723 ; CHECK-NEXT: ret void
725 store atomic i32 1, i32* %P unordered, align 4
726 %P2 = bitcast i32* %P to i8*
727 store atomic i32 2, i32* %Q unordered, align 4
728 store atomic i8 3, i8* %P2 unordered, align 4
732 define void @test43a(i32* %P, i32* noalias %Q) {
733 ; CHECK-LABEL: @test43a(
735 ; CHECK-NEXT: store atomic i32 50331649, i32* [[P:%.*]] unordered, align 4
736 ; CHECK-NEXT: store atomic i32 2, i32* [[Q:%.*]] unordered, align 4
737 ; CHECK-NEXT: ret void
740 store atomic i32 1, i32* %P unordered, align 4
741 %P2 = bitcast i32* %P to i8*
742 store atomic i32 2, i32* %Q unordered, align 4
743 store atomic i8 3, i8* %P2 unordered, align 4
747 ; Some tests where volatile may block removing a store.
749 ; Here we can remove the first non-volatile store. We cannot remove the
751 define void @test44_volatile(i32* %P) {
752 ; CHECK-LABEL: @test44_volatile(
753 ; CHECK-NEXT: store volatile i32 2, i32* [[P:%.*]], align 4
754 ; CHECK-NEXT: store i32 3, i32* [[P]], align 4
755 ; CHECK-NEXT: ret void
757 store i32 1, i32* %P, align 4
758 store volatile i32 2, i32* %P, align 4
759 store i32 3, i32* %P, align 4
763 define void @test45_volatile(i32* %P) {
764 ; CHECK-LABEL: @test45_volatile(
765 ; CHECK-NEXT: store volatile i32 2, i32* [[P:%.*]], align 4
766 ; CHECK-NEXT: store volatile i32 3, i32* [[P]], align 4
767 ; CHECK-NEXT: ret void
769 store i32 1, i32* %P, align 4
770 store volatile i32 2, i32* %P, align 4
771 store volatile i32 3, i32* %P, align 4
775 define void @test46_volatile(i32* %P) {
776 ; CHECK-LABEL: @test46_volatile(
777 ; CHECK-NEXT: store volatile i32 2, i32* [[P:%.*]], align 4
778 ; CHECK-NEXT: store volatile i32 3, i32* [[P]], align 4
779 ; CHECK-NEXT: ret void
781 store volatile i32 2, i32* %P, align 4
782 store i32 1, i32* %P, align 4
783 store volatile i32 3, i32* %P, align 4
787 define void @test47_volatile(i32* %P) {
788 ; CHECK-LABEL: @test47_volatile(
789 ; CHECK-NEXT: store volatile i32 2, i32* [[P:%.*]], align 4
790 ; CHECK-NEXT: store volatile i32 3, i32* [[P]], align 4
791 ; CHECK-NEXT: ret void
793 store volatile i32 2, i32* %P, align 4
794 store volatile i32 3, i32* %P, align 4
798 define i32 @test48(i32* %P, i32* noalias %Q, i32* %R) {
799 ; CHECK-LABEL: @test48(
800 ; CHECK-NEXT: store i32 2, i32* [[P:%.*]], align 4
801 ; CHECK-NEXT: store i32 3, i32* [[Q:%.*]], align 4
802 ; CHECK-NEXT: [[L:%.*]] = load i32, i32* [[R:%.*]], align 4
803 ; CHECK-NEXT: ret i32 [[L]]
808 %l = load i32, i32* %R