1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
4 ; RUN: opt < %s -basic-aa -dse -S | FileCheck %s
5 ; RUN: opt < %s -aa-pipeline=basic-aa -passes=dse -S | FileCheck %s
6 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"
8 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
9 declare void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* nocapture, i8, i64, i32) nounwind
10 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
11 declare void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32) nounwind
15 ;; Fully dead overwrite of memcpy.
16 define void @test15(i8* %P, i8* %Q) nounwind ssp {
17 ; CHECK-LABEL: @test15(
18 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
19 ; CHECK-NEXT: ret void
21 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
22 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
26 ;; Fully dead overwrite of memcpy.
27 define void @test15_atomic(i8* %P, i8* %Q) nounwind ssp {
28 ; CHECK-LABEL: @test15_atomic(
29 ; 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)
30 ; CHECK-NEXT: ret void
32 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i32 1)
33 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i32 1)
37 ;; Fully dead overwrite of memcpy.
38 define void @test15_atomic_weaker(i8* %P, i8* %Q) nounwind ssp {
39 ; CHECK-LABEL: @test15_atomic_weaker(
40 ; 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)
41 ; CHECK-NEXT: ret void
43 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i1 false)
44 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i32 1)
48 ;; Fully dead overwrite of memcpy.
49 define void @test15_atomic_weaker_2(i8* %P, i8* %Q) nounwind ssp {
50 ; CHECK-LABEL: @test15_atomic_weaker_2(
51 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 [[P:%.*]], i8* align 1 [[Q:%.*]], i64 12, i1 false)
52 ; CHECK-NEXT: ret void
54 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i32 1)
55 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i1 false)
59 ;; Full overwrite of smaller memcpy.
60 define void @test16(i8* %P, i8* %Q) nounwind ssp {
61 ; CHECK-LABEL: @test16(
62 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
63 ; CHECK-NEXT: ret void
65 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 8, i1 false)
66 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
70 ;; Full overwrite of smaller memcpy.
71 define void @test16_atomic(i8* %P, i8* %Q) nounwind ssp {
72 ; CHECK-LABEL: @test16_atomic(
73 ; 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)
74 ; CHECK-NEXT: ret void
76 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 8, i32 1)
77 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i32 1)
81 ;; Full overwrite of smaller memory where overwrite has stronger atomicity
82 define void @test16_atomic_weaker(i8* %P, i8* %Q) nounwind ssp {
83 ; CHECK-LABEL: @test16_atomic_weaker(
84 ; 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)
85 ; CHECK-NEXT: ret void
87 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 8, i1 false)
88 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i32 1)
92 ;; Full overwrite of smaller memory where overwrite has weaker atomicity.
93 define void @test16_atomic_weaker_2(i8* %P, i8* %Q) nounwind ssp {
94 ; CHECK-LABEL: @test16_atomic_weaker_2(
95 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 [[P:%.*]], i8* align 1 [[Q:%.*]], i64 12, i1 false)
96 ; CHECK-NEXT: ret void
98 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 8, i32 1)
99 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i1 false)
103 ;; Overwrite of memset by memcpy.
104 define void @test17(i8* %P, i8* noalias %Q) nounwind ssp {
105 ; CHECK-LABEL: @test17(
106 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
107 ; CHECK-NEXT: ret void
109 tail call void @llvm.memset.p0i8.i64(i8* %P, i8 42, i64 8, i1 false)
110 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
114 ;; Overwrite of memset by memcpy.
115 define void @test17_atomic(i8* %P, i8* noalias %Q) nounwind ssp {
116 ; CHECK-LABEL: @test17_atomic(
117 ; 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)
118 ; CHECK-NEXT: ret void
120 tail call void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* align 1 %P, i8 42, i64 8, i32 1)
121 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i32 1)
125 ;; Overwrite of memset by memcpy. Overwrite is stronger atomicity. We can
126 ;; remove the memset.
127 define void @test17_atomic_weaker(i8* %P, i8* noalias %Q) nounwind ssp {
128 ; CHECK-LABEL: @test17_atomic_weaker(
129 ; 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)
130 ; CHECK-NEXT: ret void
132 tail call void @llvm.memset.p0i8.i64(i8* align 1 %P, i8 42, i64 8, i1 false)
133 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i32 1)
137 ;; Overwrite of memset by memcpy. Overwrite is weaker atomicity. We can remove
139 define void @test17_atomic_weaker_2(i8* %P, i8* noalias %Q) nounwind ssp {
140 ; CHECK-LABEL: @test17_atomic_weaker_2(
141 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 [[P:%.*]], i8* align 1 [[Q:%.*]], i64 12, i1 false)
142 ; CHECK-NEXT: ret void
144 tail call void @llvm.memset.element.unordered.atomic.p0i8.i64(i8* align 1 %P, i8 42, i64 8, i32 1)
145 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i1 false)
149 ; Should not delete the volatile memset.
150 define void @test17v(i8* %P, i8* %Q) nounwind ssp {
151 ; CHECK-LABEL: @test17v(
152 ; CHECK-NEXT: tail call void @llvm.memset.p0i8.i64(i8* [[P:%.*]], i8 42, i64 8, i1 true)
153 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P]], i8* [[Q:%.*]], i64 12, i1 false)
154 ; CHECK-NEXT: ret void
156 tail call void @llvm.memset.p0i8.i64(i8* %P, i8 42, i64 8, i1 true)
157 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
162 ; Do not delete instruction where possible situation is:
166 ; NB! See PR11763 - currently LLVM allows memcpy's source and destination to be
167 ; equal (but not inequal and overlapping).
168 define void @test18(i8* %P, i8* %Q, i8* %R) nounwind ssp {
169 ; CHECK-LABEL: @test18(
170 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
171 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P]], i8* [[R:%.*]], i64 12, i1 false)
172 ; CHECK-NEXT: ret void
174 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
175 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %R, i64 12, i1 false)
179 define void @test18_atomic(i8* %P, i8* %Q, i8* %R) nounwind ssp {
180 ; CHECK-LABEL: @test18_atomic(
181 ; 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)
182 ; 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)
183 ; CHECK-NEXT: ret void
185 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %Q, i64 12, i32 1)
186 tail call void @llvm.memcpy.element.unordered.atomic.p0i8.p0i8.i64(i8* align 1 %P, i8* align 1 %R, i64 12, i32 1)