1 ; RUN: opt < %s -basicaa -dse -S | FileCheck %s
2 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"
4 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
5 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
6 declare void @llvm.memset.i64(i8*, i8, i64, i32)
7 declare void @llvm.memcpy.i64(i8*, i8*, i64, i32)
8 declare i8* @llvm.init.trampoline(i8*, i8*, i8*)
10 define void @test1(i32* %Q, i32* %P) {
12 store i32 %DEAD, i32* %P
16 ; CHECK-NEXT: store i32 0, i32* %P
17 ; CHECK-NEXT: ret void
20 ; PR8576 - Should delete store of 10 even though p/q are may aliases.
21 define void @test2(i32 *%p, i32 *%q) {
22 store i32 10, i32* %p, align 4
23 store i32 20, i32* %q, align 4
24 store i32 30, i32* %p, align 4
27 ; CHECK-NEXT: store i32 20
34 define i32 @test3(i32* %g_addr) nounwind {
36 ; CHECK: load i32* %g_addr
37 %g_value = load i32* %g_addr, align 4
38 store i32 -1, i32* @g, align 4
39 store i32 %g_value, i32* %g_addr, align 4
40 %tmp3 = load i32* @g, align 4
45 define void @test4(i32* %Q) {
47 volatile store i32 %a, i32* %Q
50 ; CHECK-NEXT: load i32
51 ; CHECK-NEXT: volatile store
52 ; CHECK-NEXT: ret void
55 define void @test5(i32* %Q) {
56 %a = volatile load i32* %Q
60 ; CHECK-NEXT: volatile load
61 ; CHECK-NEXT: ret void
64 ; Should delete store of 10 even though memset is a may-store to P (P and Q may
66 define void @test6(i32 *%p, i8 *%q) {
67 store i32 10, i32* %p, align 4 ;; dead.
68 call void @llvm.memset.i64(i8* %q, i8 42, i64 900, i32 1)
69 store i32 30, i32* %p, align 4
72 ; CHECK-NEXT: call void @llvm.memset
75 ; Should delete store of 10 even though memcpy is a may-store to P (P and Q may
77 define void @test7(i32 *%p, i8 *%q, i8* noalias %r) {
78 store i32 10, i32* %p, align 4 ;; dead.
79 call void @llvm.memcpy.i64(i8* %q, i8* %r, i64 900, i32 1)
80 store i32 30, i32* %p, align 4
83 ; CHECK-NEXT: call void @llvm.memcpy
86 ; Do not delete stores that are only partially killed.
89 store i32 1234567, i32* %V
90 %V2 = bitcast i32* %V to i8*
96 ; CHECK: store i32 1234567
100 ; Test for byval handling.
101 %struct.x = type { i32, i32, i32, i32 }
102 define void @test9(%struct.x* byval %a) nounwind {
103 %tmp2 = getelementptr %struct.x* %a, i32 0, i32 0
104 store i32 1, i32* %tmp2, align 4
107 ; CHECK-NEXT: ret void
110 ; va_arg has fuzzy dependence, the store shouldn't be zapped.
111 define double @test10(i8* %X) {
113 store i8* %X, i8** %X_addr
114 %tmp.0 = va_arg i8** %X_addr, double
121 ; DSE should delete the dead trampoline.
122 declare void @test11f()
123 define void @test11() {
125 %storage = alloca [10 x i8], align 16 ; <[10 x i8]*> [#uses=1]
127 %cast = getelementptr [10 x i8]* %storage, i32 0, i32 0 ; <i8*> [#uses=1]
128 %tramp = call i8* @llvm.init.trampoline( i8* %cast, i8* bitcast (void ()* @test11f to i8*), i8* null ) ; <i8*> [#uses=1]
129 ; CHECK-NOT: trampoline
135 ; PR2599 - load -> store to same address.
136 define void @test12({ i32, i32 }* %x) nounwind {
137 %tmp4 = getelementptr { i32, i32 }* %x, i32 0, i32 0
138 %tmp5 = load i32* %tmp4, align 4
139 %tmp7 = getelementptr { i32, i32 }* %x, i32 0, i32 1
140 %tmp8 = load i32* %tmp7, align 4
141 %tmp17 = sub i32 0, %tmp8
142 store i32 %tmp5, i32* %tmp4, align 4
143 store i32 %tmp17, i32* %tmp7, align 4
151 ; %P doesn't escape, the DEAD instructions should be removed.
152 declare void @test13f()
153 define i32* @test13() {
154 %p = tail call i8* @malloc(i32 4)
155 %P = bitcast i8* %p to i32*
157 %DEAD2 = add i32 %DEAD, 1
158 store i32 %DEAD2, i32* %P
159 call void @test13f( )
164 ; CHECK-NEXT: bitcast
165 ; CHECK-NEXT: call void
168 declare noalias i8* @malloc(i32)
172 define void @test14(i32* %Q) {
175 store i32 %DEAD, i32* %P
179 ; CHECK-NEXT: ret void
185 ;; Fully dead overwrite of memcpy.
186 define void @test15(i8* %P, i8* %Q) nounwind ssp {
187 tail call void @llvm.memcpy.i64(i8* %P, i8* %Q, i64 12, i32 1)
188 tail call void @llvm.memcpy.i64(i8* %P, i8* %Q, i64 12, i32 1)
191 ; CHECK-NEXT: call void @llvm.memcpy
195 ;; Full overwrite of smaller memcpy.
196 define void @test16(i8* %P, i8* %Q) nounwind ssp {
197 tail call void @llvm.memcpy.i64(i8* %P, i8* %Q, i64 8, i32 1)
198 tail call void @llvm.memcpy.i64(i8* %P, i8* %Q, i64 12, i32 1)
201 ; CHECK-NEXT: call void @llvm.memcpy
205 ;; Overwrite of memset by memcpy.
206 define void @test17(i8* %P, i8* noalias %Q) nounwind ssp {
207 tail call void @llvm.memset.i64(i8* %P, i8 42, i64 8, i32 1)
208 tail call void @llvm.memcpy.i64(i8* %P, i8* %Q, i64 12, i32 1)
211 ; CHECK-NEXT: call void @llvm.memcpy
215 ; Should not delete the volatile memset.
216 define void @test17v(i8* %P, i8* %Q) nounwind ssp {
217 tail call void @llvm.memset.p0i8.i64(i8* %P, i8 42, i64 8, i32 1, i1 true)
218 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %P, i8* %Q, i64 12, i32 1, i1 false)
221 ; CHECK-NEXT: call void @llvm.memset
222 ; CHECK-NEXT: call void @llvm.memcpy
227 ; Do not delete instruction where possible situation is:
230 define void @test18(i8* %P, i8* %Q, i8* %R) nounwind ssp {
231 tail call void @llvm.memcpy.i64(i8* %P, i8* %Q, i64 12, i32 1)
232 tail call void @llvm.memcpy.i64(i8* %P, i8* %R, i64 12, i32 1)
235 ; CHECK-NEXT: call void @llvm.memcpy
236 ; CHECK-NEXT: call void @llvm.memcpy