1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S -data-layout="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" | FileCheck %s -check-prefixes=ALL,CHECK
3 ; RUN: opt < %s -passes=instcombine -S -data-layout="E-p:32:32:32-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" | FileCheck %s -check-prefixes=ALL,P32
4 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s -check-prefixes=ALL,NODL
8 @int = global i32 zeroinitializer
10 ; Zero byte allocas should be merged if they can't be deleted.
13 ; CHECK-NEXT: [[X:%.*]] = alloca [0 x i32], align 4
14 ; CHECK-NEXT: call void (...) @use(ptr nonnull [[X]])
15 ; CHECK-NEXT: call void (...) @use(ptr nonnull [[X]])
16 ; CHECK-NEXT: call void (...) @use(ptr nonnull [[X]])
17 ; CHECK-NEXT: call void (...) @use(ptr nonnull [[X]])
18 ; CHECK-NEXT: ret void
21 ; P32-NEXT: [[X:%.*]] = alloca [0 x i32], align 4
22 ; P32-NEXT: call void (...) @use(ptr nonnull [[X]])
23 ; P32-NEXT: call void (...) @use(ptr nonnull [[X]])
24 ; P32-NEXT: call void (...) @use(ptr nonnull [[X]])
25 ; P32-NEXT: call void (...) @use(ptr nonnull [[X]])
29 ; NODL-NEXT: [[X:%.*]] = alloca [0 x i32], align 8
30 ; NODL-NEXT: call void (...) @use(ptr nonnull [[X]])
31 ; NODL-NEXT: call void (...) @use(ptr nonnull [[X]])
32 ; NODL-NEXT: call void (...) @use(ptr nonnull [[X]])
33 ; NODL-NEXT: call void (...) @use(ptr nonnull [[X]])
36 %X = alloca [0 x i32] ; <ptr> [#uses=1]
37 call void (...) @use( ptr %X )
38 %Y = alloca i32, i32 0 ; <ptr> [#uses=1]
39 call void (...) @use( ptr %Y )
40 %Z = alloca { } ; <ptr> [#uses=1]
41 call void (...) @use( ptr %Z )
42 %size = load i32, ptr @int
43 %A = alloca {{}}, i32 %size
44 call void (...) @use( {{}}* %A )
48 ; Zero byte allocas should be deleted.
49 define void @test2() {
53 %A = alloca i32 ; <ptr> [#uses=1]
58 ; Zero byte allocas should be deleted.
59 define void @test3() {
63 %A = alloca { i32 } ; <ptr> [#uses=1]
64 %B = getelementptr { i32 }, ptr %A, i32 0, i32 0 ; <ptr> [#uses=1]
69 define ptr @test4(i32 %n) {
70 ; CHECK-LABEL: @test4(
71 ; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[N:%.*]] to i64
72 ; CHECK-NEXT: [[A:%.*]] = alloca i32, i64 [[TMP1]], align 4
73 ; CHECK-NEXT: ret ptr [[A]]
76 ; P32-NEXT: [[A:%.*]] = alloca i32, i32 [[N:%.*]], align 4
77 ; P32-NEXT: ret ptr [[A]]
80 ; NODL-NEXT: [[TMP1:%.*]] = zext i32 [[N:%.*]] to i64
81 ; NODL-NEXT: [[A:%.*]] = alloca i32, i64 [[TMP1]], align 4
82 ; NODL-NEXT: ret ptr [[A]]
84 %A = alloca i32, i32 %n
88 ; Allocas which are only used by GEPs, bitcasts, addrspacecasts, and stores
89 ; (transitively) should be deleted.
90 define void @test5() {
100 store i32 123, ptr %a
102 store i32 123, ptr %b
103 store atomic i32 2, ptr %a unordered, align 4
104 store atomic i32 3, ptr %a release, align 4
105 store atomic i32 4, ptr %a seq_cst, align 4
106 %c.1 = addrspacecast ptr %c to ptr addrspace(1)
107 store i32 123, ptr addrspace(1) %c.1
111 declare void @f(ptr %p)
113 ; Check that we don't delete allocas in some erroneous cases.
114 define void @test6() {
115 ; CHECK-LABEL: @test6(
117 ; CHECK-NEXT: [[A:%.*]] = alloca { i32 }, align 4
118 ; CHECK-NEXT: [[B:%.*]] = alloca i32, align 4
119 ; CHECK-NEXT: store volatile i32 123, ptr [[A]], align 4
120 ; CHECK-NEXT: tail call void @f(ptr nonnull [[B]])
121 ; CHECK-NEXT: ret void
125 ; P32-NEXT: [[A:%.*]] = alloca { i32 }, align 4
126 ; P32-NEXT: [[B:%.*]] = alloca i32, align 4
127 ; P32-NEXT: store volatile i32 123, ptr [[A]], align 4
128 ; P32-NEXT: tail call void @f(ptr nonnull [[B]])
131 ; NODL-LABEL: @test6(
133 ; NODL-NEXT: [[A:%.*]] = alloca { i32 }, align 8
134 ; NODL-NEXT: [[B:%.*]] = alloca i32, align 4
135 ; NODL-NEXT: store volatile i32 123, ptr [[A]], align 4
136 ; NODL-NEXT: tail call void @f(ptr nonnull [[B]])
137 ; NODL-NEXT: ret void
143 store volatile i32 123, ptr %a
144 tail call void @f(ptr %b)
149 %opaque_type = type opaque
150 %real_type = type { { i32, ptr } }
152 @opaque_global = external constant %opaque_type, align 4
154 define void @test7() {
160 %0 = alloca %real_type, align 4
161 call void @llvm.memcpy.p0.p0.i32(ptr %0, ptr @opaque_global, i32 8, i1 false)
165 declare void @llvm.memcpy.p0.p0.i32(ptr nocapture, ptr nocapture, i32, i1) nounwind
168 ; Check that the GEP indices use the pointer size, or 64 if unknown
169 define void @test8() {
171 ; ALL-NEXT: [[X1:%.*]] = alloca [100 x i32], align 4
172 ; ALL-NEXT: call void (...) @use(ptr nonnull [[X1]])
177 %x = alloca i32, i32 100
178 call void (...) @use(ptr %x)
183 %struct_type = type { i32, i32 }
184 declare void @test9_aux(ptr inalloca(<{ %struct_type }>))
185 declare ptr @llvm.stacksave()
186 declare void @llvm.stackrestore(ptr)
188 define void @test9(ptr %a) {
189 ; CHECK-LABEL: @test9(
191 ; CHECK-NEXT: [[ARGMEM:%.*]] = alloca inalloca <{ [[STRUCT_TYPE:%.*]] }>, align 1
192 ; CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[A:%.*]], align 4
193 ; CHECK-NEXT: store i64 [[TMP0]], ptr [[ARGMEM]], align 4
194 ; CHECK-NEXT: call void @test9_aux(ptr nonnull inalloca(<{ [[STRUCT_TYPE]] }>) [[ARGMEM]])
195 ; CHECK-NEXT: ret void
199 ; P32-NEXT: [[ARGMEM:%.*]] = alloca inalloca <{ [[STRUCT_TYPE:%.*]] }>, align 1
200 ; P32-NEXT: [[TMP0:%.*]] = load i64, ptr [[A:%.*]], align 4
201 ; P32-NEXT: store i64 [[TMP0]], ptr [[ARGMEM]], align 4
202 ; P32-NEXT: call void @test9_aux(ptr nonnull inalloca(<{ [[STRUCT_TYPE]] }>) [[ARGMEM]])
205 ; NODL-LABEL: @test9(
207 ; NODL-NEXT: [[ARGMEM:%.*]] = alloca inalloca <{ [[STRUCT_TYPE:%.*]] }>, align 8
208 ; NODL-NEXT: [[TMP0:%.*]] = load i64, ptr [[A:%.*]], align 4
209 ; NODL-NEXT: store i64 [[TMP0]], ptr [[ARGMEM]], align 8
210 ; NODL-NEXT: call void @test9_aux(ptr nonnull inalloca(<{ [[STRUCT_TYPE]] }>) [[ARGMEM]])
211 ; NODL-NEXT: ret void
214 %inalloca.save = call ptr @llvm.stacksave()
215 %argmem = alloca inalloca <{ %struct_type }>
216 call void @llvm.memcpy.p0.p0.i32(ptr align 4 %argmem, ptr align 4 %a, i32 8, i1 false)
217 call void @test9_aux(ptr inalloca(<{ %struct_type }>) %argmem)
218 call void @llvm.stackrestore(ptr %inalloca.save)
222 define void @test10() {
223 ; ALL-LABEL: @test10(
225 ; ALL-NEXT: [[V32:%.*]] = alloca i1, align 8
226 ; ALL-NEXT: [[V64:%.*]] = alloca i1, align 8
227 ; ALL-NEXT: [[V33:%.*]] = alloca i1, align 8
228 ; ALL-NEXT: call void (...) @use(ptr nonnull [[V32]], ptr nonnull [[V64]], ptr nonnull [[V33]])
232 %v32 = alloca i1, align 8
233 %v64 = alloca i1, i64 1, align 8
234 %v33 = alloca i1, i33 1, align 8
235 call void (...) @use(ptr %v32, ptr %v64, ptr %v33)
239 define void @test11() {
240 ; ALL-LABEL: @test11(
242 ; ALL-NEXT: [[Y:%.*]] = alloca i32, align 4
243 ; ALL-NEXT: call void (...) @use(ptr nonnull @int) [ "blah"(ptr [[Y]]) ]
248 call void (...) @use(ptr nonnull @int) [ "blah"(ptr %y) ]
252 define void @test_inalloca_with_element_count(ptr %a) {
253 ; ALL-LABEL: @test_inalloca_with_element_count(
254 ; ALL-NEXT: [[ALLOCA1:%.*]] = alloca inalloca [10 x %struct_type], align 4
255 ; ALL-NEXT: call void @test9_aux(ptr nonnull inalloca([[STRUCT_TYPE:%.*]]) [[ALLOCA1]])
258 %alloca = alloca inalloca %struct_type, i32 10, align 4
259 call void @test9_aux(ptr inalloca(%struct_type) %alloca)