1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -aa-pipeline=basic-aa -passes=dse -S | FileCheck %s
3 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"
5 declare void @llvm.memset.p0.i64(ptr nocapture, i8, i64, i1) nounwind
6 declare void @llvm.memset.element.unordered.atomic.p0.i64(ptr nocapture, i8, i64, i32) nounwind
7 declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounwind
8 declare void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i32) nounwind
9 declare void @llvm.init.trampoline(ptr, ptr, ptr)
12 ;; Overwrite of memset by memcpy.
13 define void @test17(ptr %P, ptr noalias %Q) nounwind ssp {
14 ; CHECK-LABEL: @test17(
15 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr [[P:%.*]], ptr [[Q:%.*]], i64 12, i1 false)
16 ; CHECK-NEXT: ret void
18 tail call void @llvm.memset.p0.i64(ptr %P, i8 42, i64 8, i1 false)
19 tail call void @llvm.memcpy.p0.p0.i64(ptr %P, ptr %Q, i64 12, i1 false)
23 ;; Overwrite of memset by memcpy.
24 define void @test17_atomic(ptr %P, ptr noalias %Q) nounwind ssp {
25 ; CHECK-LABEL: @test17_atomic(
26 ; 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)
27 ; CHECK-NEXT: ret void
29 tail call void @llvm.memset.element.unordered.atomic.p0.i64(ptr align 1 %P, i8 42, i64 8, i32 1)
30 tail call void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr align 1 %P, ptr align 1 %Q, i64 12, i32 1)
34 ;; Overwrite of memset by memcpy. Overwrite is stronger atomicity. We can
36 define void @test17_atomic_weaker(ptr %P, ptr noalias %Q) nounwind ssp {
37 ; CHECK-LABEL: @test17_atomic_weaker(
38 ; 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)
39 ; CHECK-NEXT: ret void
41 tail call void @llvm.memset.p0.i64(ptr align 1 %P, i8 42, i64 8, i1 false)
42 tail call void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr align 1 %P, ptr align 1 %Q, i64 12, i32 1)
46 ;; Overwrite of memset by memcpy. Overwrite is weaker atomicity. We can remove
48 define void @test17_atomic_weaker_2(ptr %P, ptr noalias %Q) nounwind ssp {
49 ; CHECK-LABEL: @test17_atomic_weaker_2(
50 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 [[P:%.*]], ptr align 1 [[Q:%.*]], i64 12, i1 false)
51 ; CHECK-NEXT: ret void
53 tail call void @llvm.memset.element.unordered.atomic.p0.i64(ptr align 1 %P, i8 42, i64 8, i32 1)
54 tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %P, ptr align 1 %Q, i64 12, i1 false)
58 ; Should not delete the volatile memset.
59 define void @test17v(ptr %P, ptr %Q) nounwind ssp {
60 ; CHECK-LABEL: @test17v(
61 ; CHECK-NEXT: tail call void @llvm.memset.p0.i64(ptr [[P:%.*]], i8 42, i64 8, i1 true)
62 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr [[P]], ptr [[Q:%.*]], i64 12, i1 false)
63 ; CHECK-NEXT: ret void
65 tail call void @llvm.memset.p0.i64(ptr %P, i8 42, i64 8, i1 true)
66 tail call void @llvm.memcpy.p0.p0.i64(ptr %P, ptr %Q, i64 12, i1 false)
70 ; See PR11763 - LLVM allows memcpy's source and destination to be equal (but not
71 ; inequal and overlapping).
72 define void @test18(ptr %P, ptr %Q, ptr %R) nounwind ssp {
73 ; CHECK-LABEL: @test18(
74 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr [[P:%.*]], ptr [[Q:%.*]], i64 12, i1 false)
75 ; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr [[P]], ptr [[R:%.*]], i64 12, i1 false)
76 ; CHECK-NEXT: ret void
78 tail call void @llvm.memcpy.p0.p0.i64(ptr %P, ptr %Q, i64 12, i1 false)
79 tail call void @llvm.memcpy.p0.p0.i64(ptr %P, ptr %R, i64 12, i1 false)
83 define void @test18_atomic(ptr %P, ptr %Q, ptr %R) nounwind ssp {
84 ; CHECK-LABEL: @test18_atomic(
85 ; 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)
86 ; 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)
87 ; CHECK-NEXT: ret void
89 tail call void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr align 1 %P, ptr align 1 %Q, i64 12, i32 1)
90 tail call void @llvm.memcpy.element.unordered.atomic.p0.p0.i64(ptr align 1 %P, ptr align 1 %R, i64 12, i32 1)
94 define void @test_memset_memcpy_inline(ptr noalias %P, ptr noalias %Q) {
95 ; CHECK-LABEL: @test_memset_memcpy_inline(
96 ; CHECK-NEXT: tail call void @llvm.memcpy.inline.p0.p0.i64(ptr align 1 [[P:%.*]], ptr align 1 [[Q:%.*]], i64 12, i1 false)
97 ; CHECK-NEXT: ret void
99 tail call void @llvm.memset.p0.i64(ptr %P, i8 42, i64 8, i1 false)
100 tail call void @llvm.memcpy.inline.p0.p0.i64(ptr align 1 %P, ptr align 1 %Q, i64 12, i1 false)
104 define void @test_store_memcpy_inline(ptr noalias %P, ptr noalias %Q) {
105 ; CHECK-LABEL: @test_store_memcpy_inline(
106 ; CHECK-NEXT: [[P_4:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 4
107 ; CHECK-NEXT: store i8 4, ptr [[P_4]], align 1
108 ; CHECK-NEXT: tail call void @llvm.memcpy.inline.p0.p0.i64(ptr align 1 [[P]], ptr align 1 [[Q:%.*]], i64 4, i1 false)
109 ; CHECK-NEXT: ret void
112 %P.1 = getelementptr i8, ptr %P, i64 1
114 %P.4 = getelementptr i8, ptr %P, i64 4
116 tail call void @llvm.memcpy.inline.p0.p0.i64(ptr align 1 %P, ptr align 1 %Q, i64 4, i1 false)
120 declare void @llvm.memcpy.inline.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64 immarg, i1 immarg)