llvm.org GIT mirror llvm / ebae4b6
[DSE] Regenerate tests with update_test_checks.py (NFC) Summary: In preparation for a future commit, this regenerates the test checks for test/Transforms/DeadStoreElimination/simple.ll test/Transforms/DeadStoreElimination/memintrinsics.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329824 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Neilson 1 year, 5 months ago
2 changed file(s) with 312 addition(s) and 179 deletion(s). Raw diff Collapse all Expand all
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt -S -dse < %s | FileCheck %s
12
23 declare void @llvm.memcpy.p0i8.p0i8.i8(i8* nocapture, i8* nocapture, i8, i1) nounwind
56
67 define void @test1() {
78 ; CHECK-LABEL: @test1(
9 ; CHECK-NEXT: ret void
10 ;
811 %A = alloca i8
912 %B = alloca i8
1013
1114 store i8 0, i8* %A ;; Written to by memcpy
12 ; CHECK-NOT: store
1315
1416 call void @llvm.memcpy.p0i8.p0i8.i8(i8* %A, i8* %B, i8 -1, i1 false)
1517
1618 ret void
17 ; CHECK: ret void
1819 }
1920
2021 define void @test2() {
2122 ; CHECK-LABEL: @test2(
23 ; CHECK-NEXT: ret void
24 ;
2225 %A = alloca i8
2326 %B = alloca i8
2427
2528 store i8 0, i8* %A ;; Written to by memmove
26 ; CHECK-NOT: store
2729
2830 call void @llvm.memmove.p0i8.p0i8.i8(i8* %A, i8* %B, i8 -1, i1 false)
2931
3032 ret void
31 ; CHECK: ret void
3233 }
3334
3435 define void @test3() {
3536 ; CHECK-LABEL: @test3(
37 ; CHECK-NEXT: ret void
38 ;
3639 %A = alloca i8
3740 %B = alloca i8
3841
3942 store i8 0, i8* %A ;; Written to by memset
40 ; CHECK-NOT: store
4143
4244 call void @llvm.memset.p0i8.i8(i8* %A, i8 0, i8 -1, i1 false)
4345
4446 ret void
45 ; CHECK: ret void
4647 }
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -basicaa -dse -S | FileCheck %s
12 ; RUN: opt < %s -aa-pipeline=basic-aa -passes=dse -S | FileCheck %s
23 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"
67 declare void @llvm.init.trampoline(i8*, i8*, i8*)
78
89 define void @test1(i32* %Q, i32* %P) {
9 %DEAD = load i32, i32* %Q
10 store i32 %DEAD, i32* %P
11 store i32 0, i32* %P
12 ret void
1310 ; CHECK-LABEL: @test1(
14 ; CHECK-NEXT: store i32 0, i32* %P
15 ; CHECK-NEXT: ret void
11 ; CHECK-NEXT: store i32 0, i32* [[P:%.*]]
12 ; CHECK-NEXT: ret void
13 ;
14 %DEAD = load i32, i32* %Q
15 store i32 %DEAD, i32* %P
16 store i32 0, i32* %P
17 ret void
1618 }
1719
1820 ; PR8576 - Should delete store of 10 even though p/q are may aliases.
1921 define void @test2(i32 *%p, i32 *%q) {
22 ; CHECK-LABEL: @test2(
23 ; CHECK-NEXT: store i32 20, i32* [[Q:%.*]], align 4
24 ; CHECK-NEXT: store i32 30, i32* [[P:%.*]], align 4
25 ; CHECK-NEXT: ret void
26 ;
2027 store i32 10, i32* %p, align 4
2128 store i32 20, i32* %q, align 4
2229 store i32 30, i32* %p, align 4
2330 ret void
24 ; CHECK-LABEL: @test2(
25 ; CHECK-NEXT: store i32 20
2631 }
2732
2833
3136
3237 define i32 @test3(i32* %g_addr) nounwind {
3338 ; CHECK-LABEL: @test3(
34 ; CHECK: load i32, i32* %g_addr
39 ; CHECK-NEXT: [[G_VALUE:%.*]] = load i32, i32* [[G_ADDR:%.*]], align 4
40 ; CHECK-NEXT: store i32 -1, i32* @g, align 4
41 ; CHECK-NEXT: store i32 [[G_VALUE]], i32* [[G_ADDR]], align 4
42 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, i32* @g, align 4
43 ; CHECK-NEXT: ret i32 [[TMP3]]
44 ;
3545 %g_value = load i32, i32* %g_addr, align 4
3646 store i32 -1, i32* @g, align 4
3747 store i32 %g_value, i32* %g_addr, align 4
4151
4252
4353 define void @test4(i32* %Q) {
44 %a = load i32, i32* %Q
45 store volatile i32 %a, i32* %Q
46 ret void
4754 ; CHECK-LABEL: @test4(
48 ; CHECK-NEXT: load i32
49 ; CHECK-NEXT: store volatile
50 ; CHECK-NEXT: ret void
55 ; CHECK-NEXT: [[A:%.*]] = load i32, i32* [[Q:%.*]]
56 ; CHECK-NEXT: store volatile i32 [[A]], i32* [[Q]]
57 ; CHECK-NEXT: ret void
58 ;
59 %a = load i32, i32* %Q
60 store volatile i32 %a, i32* %Q
61 ret void
5162 }
5263
5364 define void @test5(i32* %Q) {
54 %a = load volatile i32, i32* %Q
55 store i32 %a, i32* %Q
56 ret void
5765 ; CHECK-LABEL: @test5(
58 ; CHECK-NEXT: load volatile
59 ; CHECK-NEXT: ret void
66 ; CHECK-NEXT: [[A:%.*]] = load volatile i32, i32* [[Q:%.*]]
67 ; CHECK-NEXT: ret void
68 ;
69 %a = load volatile i32, i32* %Q
70 store i32 %a, i32* %Q
71 ret void
6072 }
6173
6274 ; Should delete store of 10 even though memset is a may-store to P (P and Q may
6375 ; alias).
6476 define void @test6(i32 *%p, i8 *%q) {
77 ; CHECK-LABEL: @test6(
78 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[Q:%.*]], i8 42, i64 900, i1 false)
79 ; CHECK-NEXT: store i32 30, i32* [[P:%.*]], align 4
80 ; CHECK-NEXT: ret void
81 ;
6582 store i32 10, i32* %p, align 4 ;; dead.
6683 call void @llvm.memset.p0i8.i64(i8* %q, i8 42, i64 900, i1 false)
6784 store i32 30, i32* %p, align 4
6885 ret void
69 ; CHECK-LABEL: @test6(
70 ; CHECK-NEXT: call void @llvm.memset
7186 }
7287
7388 ; Should delete store of 10 even though memcpy is a may-store to P (P and Q may
7489 ; alias).
7590 define void @test7(i32 *%p, i8 *%q, i8* noalias %r) {
91 ; CHECK-LABEL: @test7(
92 ; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[Q:%.*]], i8* [[R:%.*]], i64 900, i1 false)
93 ; CHECK-NEXT: store i32 30, i32* [[P:%.*]], align 4
94 ; CHECK-NEXT: ret void
95 ;
7696 store i32 10, i32* %p, align 4 ;; dead.
7797 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %q, i8* %r, i64 900, i1 false)
7898 store i32 30, i32* %p, align 4
7999 ret void
80 ; CHECK-LABEL: @test7(
81 ; CHECK-NEXT: call void @llvm.memcpy
82100 }
83101
84102 ; Do not delete stores that are only partially killed.
85103 define i32 @test8() {
86 %V = alloca i32
87 store i32 1234567, i32* %V
88 %V2 = bitcast i32* %V to i8*
89 store i8 0, i8* %V2
90 %X = load i32, i32* %V
91 ret i32 %X
92
93104 ; CHECK-LABEL: @test8(
94 ; CHECK: store i32 1234567
105 ; CHECK-NEXT: [[V:%.*]] = alloca i32
106 ; CHECK-NEXT: store i32 1234567, i32* [[V]]
107 ; CHECK-NEXT: [[X:%.*]] = load i32, i32* [[V]]
108 ; CHECK-NEXT: ret i32 [[X]]
109 ;
110 %V = alloca i32
111 store i32 1234567, i32* %V
112 %V2 = bitcast i32* %V to i8*
113 store i8 0, i8* %V2
114 %X = load i32, i32* %V
115 ret i32 %X
116
95117 }
96118
97119
98120 ; Test for byval handling.
99121 %struct.x = type { i32, i32, i32, i32 }
100122 define void @test9(%struct.x* byval %a) nounwind {
101 %tmp2 = getelementptr %struct.x, %struct.x* %a, i32 0, i32 0
102 store i32 1, i32* %tmp2, align 4
103 ret void
104123 ; CHECK-LABEL: @test9(
105 ; CHECK-NEXT: ret void
124 ; CHECK-NEXT: ret void
125 ;
126 %tmp2 = getelementptr %struct.x, %struct.x* %a, i32 0, i32 0
127 store i32 1, i32* %tmp2, align 4
128 ret void
106129 }
107130
108131 ; Test for inalloca handling.
109132 define void @test9_2(%struct.x* inalloca %a) nounwind {
110 %tmp2 = getelementptr %struct.x, %struct.x* %a, i32 0, i32 0
111 store i32 1, i32* %tmp2, align 4
112 ret void
113133 ; CHECK-LABEL: @test9_2(
114 ; CHECK-NEXT: ret void
134 ; CHECK-NEXT: ret void
135 ;
136 %tmp2 = getelementptr %struct.x, %struct.x* %a, i32 0, i32 0
137 store i32 1, i32* %tmp2, align 4
138 ret void
115139 }
116140
117141 ; va_arg has fuzzy dependence, the store shouldn't be zapped.
118142 define double @test10(i8* %X) {
119 %X_addr = alloca i8*
120 store i8* %X, i8** %X_addr
121 %tmp.0 = va_arg i8** %X_addr, double
122 ret double %tmp.0
123143 ; CHECK-LABEL: @test10(
124 ; CHECK: store
144 ; CHECK-NEXT: [[X_ADDR:%.*]] = alloca i8*
145 ; CHECK-NEXT: store i8* [[X:%.*]], i8** [[X_ADDR]]
146 ; CHECK-NEXT: [[TMP_0:%.*]] = va_arg i8** [[X_ADDR]], double
147 ; CHECK-NEXT: ret double [[TMP_0]]
148 ;
149 %X_addr = alloca i8*
150 store i8* %X, i8** %X_addr
151 %tmp.0 = va_arg i8** %X_addr, double
152 ret double %tmp.0
125153 }
126154
127155
129157 declare void @test11f()
130158 define void @test11() {
131159 ; CHECK-LABEL: @test11(
132 %storage = alloca [10 x i8], align 16 ; <[10 x i8]*> [#uses=1]
133 ; CHECK-NOT: alloca
134 %cast = getelementptr [10 x i8], [10 x i8]* %storage, i32 0, i32 0 ; [#uses=1]
135 call void @llvm.init.trampoline( i8* %cast, i8* bitcast (void ()* @test11f to i8*), i8* null ) ; [#uses=1]
136 ; CHECK-NOT: trampoline
137 ret void
138 ; CHECK: ret void
160 ; CHECK-NEXT: ret void
161 ;
162 %storage = alloca [10 x i8], align 16 ; <[10 x i8]*> [#uses=1]
163 %cast = getelementptr [10 x i8], [10 x i8]* %storage, i32 0, i32 0 ; [#uses=1]
164 call void @llvm.init.trampoline( i8* %cast, i8* bitcast (void ()* @test11f to i8*), i8* null ) ; [#uses=1]
165 ret void
139166 }
140167
141168
142169 ; PR2599 - load -> store to same address.
143170 define void @test12({ i32, i32 }* %x) nounwind {
144 %tmp4 = getelementptr { i32, i32 }, { i32, i32 }* %x, i32 0, i32 0
145 %tmp5 = load i32, i32* %tmp4, align 4
146 %tmp7 = getelementptr { i32, i32 }, { i32, i32 }* %x, i32 0, i32 1
147 %tmp8 = load i32, i32* %tmp7, align 4
148 %tmp17 = sub i32 0, %tmp8
149 store i32 %tmp5, i32* %tmp4, align 4
150 store i32 %tmp17, i32* %tmp7, align 4
151 ret void
152171 ; CHECK-LABEL: @test12(
153 ; CHECK-NOT: tmp5
154 ; CHECK: ret void
172 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr { i32, i32 }, { i32, i32 }* [[X:%.*]], i32 0, i32 1
173 ; CHECK-NEXT: [[TMP8:%.*]] = load i32, i32* [[TMP7]], align 4
174 ; CHECK-NEXT: [[TMP17:%.*]] = sub i32 0, [[TMP8]]
175 ; CHECK-NEXT: store i32 [[TMP17]], i32* [[TMP7]], align 4
176 ; CHECK-NEXT: ret void
177 ;
178 %tmp4 = getelementptr { i32, i32 }, { i32, i32 }* %x, i32 0, i32 0
179 %tmp5 = load i32, i32* %tmp4, align 4
180 %tmp7 = getelementptr { i32, i32 }, { i32, i32 }* %x, i32 0, i32 1
181 %tmp8 = load i32, i32* %tmp7, align 4
182 %tmp17 = sub i32 0, %tmp8
183 store i32 %tmp5, i32* %tmp4, align 4
184 store i32 %tmp17, i32* %tmp7, align 4
185 ret void
155186 }
156187
157188
158189 ; %P doesn't escape, the DEAD instructions should be removed.
159190 declare void @test13f()
160191 define i32* @test13() {
161 %p = tail call i8* @malloc(i32 4)
162 %P = bitcast i8* %p to i32*
163 %DEAD = load i32, i32* %P
164 %DEAD2 = add i32 %DEAD, 1
165 store i32 %DEAD2, i32* %P
166 call void @test13f( )
167 store i32 0, i32* %P
168 ret i32* %P
169 ; CHECK: @test13()
170 ; CHECK-NEXT: malloc
171 ; CHECK-NEXT: bitcast
172 ; CHECK-NEXT: call void
192 ; CHECK-LABEL: @test13(
193 ; CHECK-NEXT: [[PTR:%.*]] = tail call i8* @malloc(i32 4)
194 ; CHECK-NEXT: [[P:%.*]] = bitcast i8* [[PTR]] to i32*
195 ; CHECK-NEXT: call void @test13f()
196 ; CHECK-NEXT: store i32 0, i32* [[P]]
197 ; CHECK-NEXT: ret i32* [[P]]
198 ;
199 %ptr = tail call i8* @malloc(i32 4)
200 %P = bitcast i8* %ptr to i32*
201 %DEAD = load i32, i32* %P
202 %DEAD2 = add i32 %DEAD, 1
203 store i32 %DEAD2, i32* %P
204 call void @test13f( )
205 store i32 0, i32* %P
206 ret i32* %P
173207 }
174208
175209 define i32 addrspace(1)* @test13_addrspacecast() {
210 ; CHECK-LABEL: @test13_addrspacecast(
211 ; CHECK-NEXT: [[P:%.*]] = tail call i8* @malloc(i32 4)
212 ; CHECK-NEXT: [[P_BC:%.*]] = bitcast i8* [[P]] to i32*
213 ; CHECK-NEXT: [[P:%.*]] = addrspacecast i32* [[P_BC]] to i32 addrspace(1)*
214 ; CHECK-NEXT: call void @test13f()
215 ; CHECK-NEXT: store i32 0, i32 addrspace(1)* [[P]]
216 ; CHECK-NEXT: ret i32 addrspace(1)* [[P]]
217 ;
176218 %p = tail call i8* @malloc(i32 4)
177219 %p.bc = bitcast i8* %p to i32*
178220 %P = addrspacecast i32* %p.bc to i32 addrspace(1)*
182224 call void @test13f( )
183225 store i32 0, i32 addrspace(1)* %P
184226 ret i32 addrspace(1)* %P
185 ; CHECK: @test13_addrspacecast()
186 ; CHECK-NEXT: malloc
187 ; CHECK-NEXT: bitcast
188 ; CHECK-NEXT: addrspacecast
189 ; CHECK-NEXT: call void
190227 }
191228
192229 declare noalias i8* @malloc(i32)
194231
195232
196233 define void @test14(i32* %Q) {
197 %P = alloca i32
198 %DEAD = load i32, i32* %Q
199 store i32 %DEAD, i32* %P
200 ret void
201
202234 ; CHECK-LABEL: @test14(
203 ; CHECK-NEXT: ret void
235 ; CHECK-NEXT: ret void
236 ;
237 %P = alloca i32
238 %DEAD = load i32, i32* %Q
239 store i32 %DEAD, i32* %P
240 ret void
241
204242 }
205243
206244
208246
209247 ;; Fully dead overwrite of memcpy.
210248 define void @test15(i8* %P, i8* %Q) nounwind ssp {
249 ; CHECK-LABEL: @test15(
250 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
251 ; CHECK-NEXT: ret void
252 ;
211253 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
212254 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
213255 ret void
214 ; CHECK-LABEL: @test15(
215 ; CHECK-NEXT: call void @llvm.memcpy
216 ; CHECK-NEXT: ret
217256 }
218257
219258 ;; Full overwrite of smaller memcpy.
220259 define void @test16(i8* %P, i8* %Q) nounwind ssp {
260 ; CHECK-LABEL: @test16(
261 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
262 ; CHECK-NEXT: ret void
263 ;
221264 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 8, i1 false)
222265 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
223266 ret void
224 ; CHECK-LABEL: @test16(
225 ; CHECK-NEXT: call void @llvm.memcpy
226 ; CHECK-NEXT: ret
227267 }
228268
229269 ;; Overwrite of memset by memcpy.
230270 define void @test17(i8* %P, i8* noalias %Q) nounwind ssp {
271 ; CHECK-LABEL: @test17(
272 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
273 ; CHECK-NEXT: ret void
274 ;
231275 tail call void @llvm.memset.p0i8.i64(i8* %P, i8 42, i64 8, i1 false)
232276 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
233277 ret void
234 ; CHECK-LABEL: @test17(
235 ; CHECK-NEXT: call void @llvm.memcpy
236 ; CHECK-NEXT: ret
237278 }
238279
239280 ; Should not delete the volatile memset.
240281 define void @test17v(i8* %P, i8* %Q) nounwind ssp {
282 ; CHECK-LABEL: @test17v(
283 ; CHECK-NEXT: tail call void @llvm.memset.p0i8.i64(i8* [[P:%.*]], i8 42, i64 8, i1 true)
284 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P]], i8* [[Q:%.*]], i64 12, i1 false)
285 ; CHECK-NEXT: ret void
286 ;
241287 tail call void @llvm.memset.p0i8.i64(i8* %P, i8 42, i64 8, i1 true)
242288 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
243289 ret void
244 ; CHECK-LABEL: @test17v(
245 ; CHECK-NEXT: call void @llvm.memset
246 ; CHECK-NEXT: call void @llvm.memcpy
247 ; CHECK-NEXT: ret
248290 }
249291
250292 ; PR8728
255297 ; NB! See PR11763 - currently LLVM allows memcpy's source and destination to be
256298 ; equal (but not inequal and overlapping).
257299 define void @test18(i8* %P, i8* %Q, i8* %R) nounwind ssp {
300 ; CHECK-LABEL: @test18(
301 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
302 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P]], i8* [[R:%.*]], i64 12, i1 false)
303 ; CHECK-NEXT: ret void
304 ;
258305 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
259306 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %R, i64 12, i1 false)
260307 ret void
261 ; CHECK-LABEL: @test18(
262 ; CHECK-NEXT: call void @llvm.memcpy
263 ; CHECK-NEXT: call void @llvm.memcpy
264 ; CHECK-NEXT: ret
265308 }
266309
267310
269312 declare void @test19f({i32}* byval align 4 %P)
270313
271314 define void @test19({i32} * nocapture byval align 4 %arg5) nounwind ssp {
315 ; CHECK-LABEL: @test19(
316 ; CHECK-NEXT: bb:
317 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds { i32 }, { i32 }* [[ARG5:%.*]], i32 0, i32 0
318 ; CHECK-NEXT: store i32 912, i32* [[TMP7]]
319 ; CHECK-NEXT: call void @test19f({ i32 }* byval align 4 [[ARG5]])
320 ; CHECK-NEXT: ret void
321 ;
272322 bb:
273323 %tmp7 = getelementptr inbounds {i32}, {i32}* %arg5, i32 0, i32 0
274324 store i32 912, i32* %tmp7
275325 call void @test19f({i32}* byval align 4 %arg5)
276326 ret void
277327
278 ; CHECK-LABEL: @test19(
279 ; CHECK: store i32 912
280 ; CHECK: call void @test19f
281328 }
282329
283330 define void @test20() {
331 ; CHECK-LABEL: @test20(
332 ; CHECK-NEXT: ret void
333 ;
284334 %m = call i8* @malloc(i32 24)
285335 store i8 0, i8* %m
286336 ret void
287337 }
288 ; CHECK-LABEL: @test20(
289 ; CHECK-NEXT: ret void
290
338
339 define void @test21() {
291340 ; CHECK-LABEL: @test21(
292 define void @test21() {
341 ; CHECK-NEXT: ret void
342 ;
293343 %m = call i8* @calloc(i32 9, i32 7)
294344 store i8 0, i8* %m
295 ; CHECK-NEXT: ret void
296 ret void
297 }
298
345 ret void
346 }
347
348 define void @test22(i1 %i, i32 %k, i32 %m) nounwind {
299349 ; CHECK-LABEL: @test22(
300 define void @test22(i1 %i, i32 %k, i32 %m) nounwind {
350 ; CHECK-NEXT: ret void
351 ;
301352 %k.addr = alloca i32
302353 %m.addr = alloca i32
303354 %k.addr.m.addr = select i1 %i, i32* %k.addr, i32* %m.addr
304355 store i32 0, i32* %k.addr.m.addr, align 4
305 ; CHECK-NEXT: ret void
306356 ret void
307357 }
308358
309359 ; PR13547
310 ; CHECK-LABEL: @test23(
311 ; CHECK: store i8 97
312 ; CHECK: store i8 0
313360 declare noalias i8* @strdup(i8* nocapture) nounwind
314361 define noalias i8* @test23() nounwind uwtable ssp {
362 ; CHECK-LABEL: @test23(
363 ; CHECK-NEXT: [[X:%.*]] = alloca [2 x i8], align 1
364 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [2 x i8], [2 x i8]* [[X]], i64 0, i64 0
365 ; CHECK-NEXT: store i8 97, i8* [[ARRAYIDX]], align 1
366 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds [2 x i8], [2 x i8]* [[X]], i64 0, i64 1
367 ; CHECK-NEXT: store i8 0, i8* [[ARRAYIDX1]], align 1
368 ; CHECK-NEXT: [[CALL:%.*]] = call i8* @strdup(i8* [[ARRAYIDX]]) #1
369 ; CHECK-NEXT: ret i8* [[CALL]]
370 ;
315371 %x = alloca [2 x i8], align 1
316372 %arrayidx = getelementptr inbounds [2 x i8], [2 x i8]* %x, i64 0, i64 0
317373 store i8 97, i8* %arrayidx, align 1
322378 }
323379
324380 ; Make sure same sized store to later element is deleted
381 define void @test24([2 x i32]* %a, i32 %b, i32 %c) nounwind {
325382 ; CHECK-LABEL: @test24(
326 ; CHECK-NOT: store i32 0
327 ; CHECK-NOT: store i32 0
328 ; CHECK: store i32 %b
329 ; CHECK: store i32 %c
330 ; CHECK: ret void
331 define void @test24([2 x i32]* %a, i32 %b, i32 %c) nounwind {
383 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [2 x i32], [2 x i32]* [[A:%.*]], i64 0, i64 0
384 ; CHECK-NEXT: store i32 [[B:%.*]], i32* [[TMP1]], align 4
385 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [2 x i32], [2 x i32]* [[A]], i64 0, i64 1
386 ; CHECK-NEXT: store i32 [[C:%.*]], i32* [[TMP2]], align 4
387 ; CHECK-NEXT: ret void
388 ;
332389 %1 = getelementptr inbounds [2 x i32], [2 x i32]* %a, i64 0, i64 0
333390 store i32 0, i32* %1, align 4
334391 %2 = getelementptr inbounds [2 x i32], [2 x i32]* %a, i64 0, i64 1
341398 }
342399
343400 ; Check another case like PR13547 where strdup is not like malloc.
401 define i8* @test25(i8* %p) nounwind {
344402 ; CHECK-LABEL: @test25(
345 ; CHECK: load i8
346 ; CHECK: store i8 0
347 ; CHECK: store i8 %tmp
348 define i8* @test25(i8* %p) nounwind {
403 ; CHECK-NEXT: [[P_4:%.*]] = getelementptr i8, i8* [[P:%.*]], i64 4
404 ; CHECK-NEXT: [[TMP:%.*]] = load i8, i8* [[P_4]], align 1
405 ; CHECK-NEXT: store i8 0, i8* [[P_4]], align 1
406 ; CHECK-NEXT: [[Q:%.*]] = call i8* @strdup(i8* [[P]]) #4
407 ; CHECK-NEXT: store i8 [[TMP]], i8* [[P_4]], align 1
408 ; CHECK-NEXT: ret i8* [[Q]]
409 ;
349410 %p.4 = getelementptr i8, i8* %p, i64 4
350411 %tmp = load i8, i8* %p.4, align 1
351412 store i8 0, i8* %p.4, align 1
355416 }
356417
357418 ; Remove redundant store if loaded value is in another block.
419 define i32 @test26(i1 %c, i32* %p) {
358420 ; CHECK-LABEL: @test26(
359 ; CHECK-NOT: store
360 ; CHECK: ret
361 define i32 @test26(i1 %c, i32* %p) {
421 ; CHECK-NEXT: entry:
422 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
423 ; CHECK: bb1:
424 ; CHECK-NEXT: br label [[BB3:%.*]]
425 ; CHECK: bb2:
426 ; CHECK-NEXT: br label [[BB3]]
427 ; CHECK: bb3:
428 ; CHECK-NEXT: ret i32 0
429 ;
362430 entry:
363431 %v = load i32, i32* %p, align 4
364432 br i1 %c, label %bb1, label %bb2
372440 }
373441
374442 ; Remove redundant store if loaded value is in another block.
443 define i32 @test27(i1 %c, i32* %p) {
375444 ; CHECK-LABEL: @test27(
376 ; CHECK-NOT: store
377 ; CHECK: ret
378 define i32 @test27(i1 %c, i32* %p) {
445 ; CHECK-NEXT: entry:
446 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
447 ; CHECK: bb1:
448 ; CHECK-NEXT: br label [[BB3:%.*]]
449 ; CHECK: bb2:
450 ; CHECK-NEXT: br label [[BB3]]
451 ; CHECK: bb3:
452 ; CHECK-NEXT: ret i32 0
453 ;
379454 entry:
380455 %v = load i32, i32* %p, align 4
381456 br i1 %c, label %bb1, label %bb2
389464 }
390465
391466 ; Don't remove redundant store because of may-aliased store.
467 define i32 @test28(i1 %c, i32* %p, i32* %p2, i32 %i) {
392468 ; CHECK-LABEL: @test28(
393 ; CHECK: bb3:
394 ; CHECK-NEXT: store i32 %v
395 define i32 @test28(i1 %c, i32* %p, i32* %p2, i32 %i) {
469 ; CHECK-NEXT: entry:
470 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
471 ; CHECK-NEXT: store i32 [[I:%.*]], i32* [[P2:%.*]], align 4
472 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
473 ; CHECK: bb1:
474 ; CHECK-NEXT: br label [[BB3:%.*]]
475 ; CHECK: bb2:
476 ; CHECK-NEXT: br label [[BB3]]
477 ; CHECK: bb3:
478 ; CHECK-NEXT: store i32 [[V]], i32* [[P]], align 4
479 ; CHECK-NEXT: ret i32 0
480 ;
396481 entry:
397482 %v = load i32, i32* %p, align 4
398483
409494 }
410495
411496 ; Don't remove redundant store because of may-aliased store.
497 define i32 @test29(i1 %c, i32* %p, i32* %p2, i32 %i) {
412498 ; CHECK-LABEL: @test29(
413 ; CHECK: bb3:
414 ; CHECK-NEXT: store i32 %v
415 define i32 @test29(i1 %c, i32* %p, i32* %p2, i32 %i) {
499 ; CHECK-NEXT: entry:
500 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
501 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
502 ; CHECK: bb1:
503 ; CHECK-NEXT: br label [[BB3:%.*]]
504 ; CHECK: bb2:
505 ; CHECK-NEXT: store i32 [[I:%.*]], i32* [[P2:%.*]], align 4
506 ; CHECK-NEXT: br label [[BB3]]
507 ; CHECK: bb3:
508 ; CHECK-NEXT: store i32 [[V]], i32* [[P]], align 4
509 ; CHECK-NEXT: ret i32 0
510 ;
416511 entry:
417512 %v = load i32, i32* %p, align 4
418513 br i1 %c, label %bb1, label %bb2
430525 declare void @unknown_func()
431526
432527 ; Don't remove redundant store because of unknown call.
528 define i32 @test30(i1 %c, i32* %p, i32 %i) {
433529 ; CHECK-LABEL: @test30(
434 ; CHECK: bb3:
435 ; CHECK-NEXT: store i32 %v
436 define i32 @test30(i1 %c, i32* %p, i32 %i) {
530 ; CHECK-NEXT: entry:
531 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
532 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
533 ; CHECK: bb1:
534 ; CHECK-NEXT: br label [[BB3:%.*]]
535 ; CHECK: bb2:
536 ; CHECK-NEXT: call void @unknown_func()
537 ; CHECK-NEXT: br label [[BB3]]
538 ; CHECK: bb3:
539 ; CHECK-NEXT: store i32 [[V]], i32* [[P]], align 4
540 ; CHECK-NEXT: ret i32 0
541 ;
437542 entry:
438543 %v = load i32, i32* %p, align 4
439544 br i1 %c, label %bb1, label %bb2
449554 }
450555
451556 ; Remove redundant store if loaded value is in another block inside a loop.
557 define i32 @test31(i1 %c, i32* %p, i32 %i) {
452558 ; CHECK-LABEL: @test31(
453 ; CHECK-NOT: store
454 ; CHECK: ret
455 define i32 @test31(i1 %c, i32* %p, i32 %i) {
559 ; CHECK-NEXT: entry:
560 ; CHECK-NEXT: br label [[BB1:%.*]]
561 ; CHECK: bb1:
562 ; CHECK-NEXT: br i1 undef, label [[BB1]], label [[BB2:%.*]]
563 ; CHECK: bb2:
564 ; CHECK-NEXT: ret i32 0
565 ;
456566 entry:
457567 %v = load i32, i32* %p, align 4
458568 br label %bb1
464574 }
465575
466576 ; Don't remove redundant store in a loop with a may-alias store.
577 define i32 @test32(i1 %c, i32* %p, i32 %i) {
467578 ; CHECK-LABEL: @test32(
468 ; CHECK: bb1:
469 ; CHECK-NEXT: store i32 %v
470 ; CHECK-NEXT: call void @unknown_func
471 define i32 @test32(i1 %c, i32* %p, i32 %i) {
579 ; CHECK-NEXT: entry:
580 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
581 ; CHECK-NEXT: br label [[BB1:%.*]]
582 ; CHECK: bb1:
583 ; CHECK-NEXT: store i32 [[V]], i32* [[P]], align 4
584 ; CHECK-NEXT: call void @unknown_func()
585 ; CHECK-NEXT: br i1 undef, label [[BB1]], label [[BB2:%.*]]
586 ; CHECK: bb2:
587 ; CHECK-NEXT: ret i32 0
588 ;
472589 entry:
473590 %v = load i32, i32* %p, align 4
474591 br label %bb1
482599 }
483600
484601 ; Remove redundant store, which is in the lame loop as the load.
602 define i32 @test33(i1 %c, i32* %p, i32 %i) {
485603 ; CHECK-LABEL: @test33(
486 ; CHECK-NOT: store
487 ; CHECK: ret
488 define i32 @test33(i1 %c, i32* %p, i32 %i) {
604 ; CHECK-NEXT: entry:
605 ; CHECK-NEXT: br label [[BB1:%.*]]
606 ; CHECK: bb1:
607 ; CHECK-NEXT: br label [[BB2:%.*]]
608 ; CHECK: bb2:
609 ; CHECK-NEXT: call void @unknown_func()
610 ; CHECK-NEXT: br i1 undef, label [[BB1]], label [[BB3:%.*]]
611 ; CHECK: bb3:
612 ; CHECK-NEXT: ret i32 0
613 ;
489614 entry:
490615 br label %bb1
491616 bb1:
501626 }
502627
503628 ; Don't remove redundant store: unknown_func could unwind
629 define void @test34(i32* noalias %p) {
504630 ; CHECK-LABEL: @test34(
505 ; CHECK: store i32 1
506 ; CHECK: store i32 0
507 ; CHECK: ret
508 define void @test34(i32* noalias %p) {
631 ; CHECK-NEXT: store i32 1, i32* [[P:%.*]]
632 ; CHECK-NEXT: call void @unknown_func()
633 ; CHECK-NEXT: store i32 0, i32* [[P]]
634 ; CHECK-NEXT: ret void
635 ;
509636 store i32 1, i32* %p
510637 call void @unknown_func()
511638 store i32 0, i32* %p
513640 }
514641
515642 ; Remove redundant store even with an unwinding function in the same block
643 define void @test35(i32* noalias %p) {
516644 ; CHECK-LABEL: @test35(
517 ; CHECK: call void @unknown_func
518 ; CHECK-NEXT: store i32 0
519 ; CHECK-NEXT: ret void
520 define void @test35(i32* noalias %p) {
645 ; CHECK-NEXT: call void @unknown_func()
646 ; CHECK-NEXT: store i32 0, i32* [[P:%.*]]
647 ; CHECK-NEXT: ret void
648 ;
521649 call void @unknown_func()
522650 store i32 1, i32* %p
523651 store i32 0, i32* %p
527655 ; We cannot optimize away the first memmove since %P could overlap with %Q.
528656 define void @test36(i8* %P, i8* %Q) {
529657 ; CHECK-LABEL: @test36(
530 ; CHECK-NEXT: tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
531 ; CHECK-NEXT: tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
532 ; CHECK-NEXT: ret
658 ; CHECK-NEXT: tail call void @llvm.memmove.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
659 ; CHECK-NEXT: tail call void @llvm.memmove.p0i8.p0i8.i64(i8* [[P]], i8* [[Q]], i64 12, i1 false)
660 ; CHECK-NEXT: ret void
661 ;
533662
534663 tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
535664 tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
538667
539668 define void @test37(i8* %P, i8* %Q, i8* %R) {
540669 ; CHECK-LABEL: @test37(
541 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
542 ; CHECK-NEXT: tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %P, i8* %R, i64 12, i1 false)
543 ; CHECK-NEXT: ret
670 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
671 ; CHECK-NEXT: tail call void @llvm.memmove.p0i8.p0i8.i64(i8* [[P]], i8* [[R:%.*]], i64 12, i1 false)
672 ; CHECK-NEXT: ret void
673 ;
544674
545675 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
546676 tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %P, i8* %R, i64 12, i1 false)
550680 ; Same caveat about memcpy as in @test18 applies here.
551681 define void @test38(i8* %P, i8* %Q, i8* %R) {
552682 ; CHECK-LABEL: @test38(
553 ; CHECK-NEXT: tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
554 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %R, i64 12, i1 false)
555 ; CHECK-NEXT: ret
683 ; CHECK-NEXT: tail call void @llvm.memmove.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
684 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P]], i8* [[R:%.*]], i64 12, i1 false)
685 ; CHECK-NEXT: ret void
686 ;
556687
557688 tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
558689 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %R, i64 12, i1 false)
561692
562693 define void @test39(i8* %P, i8* %Q, i8* %R) {
563694 ; CHECK-LABEL: @test39(
564 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
565 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %R, i64 8, i1 false)
566 ; CHECK-NEXT: ret
695 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P:%.*]], i8* [[Q:%.*]], i64 12, i1 false)
696 ; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[P]], i8* [[R:%.*]], i64 8, i1 false)
697 ; CHECK-NEXT: ret void
698 ;
567699
568700 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i1 false)
569701 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %R, i64 8, i1 false)