1 ; RUN: opt < %s -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-prefix=CHECK -check-prefix=ALL
2 ; RUN: opt < %s -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-prefix=P32 -check-prefix=ALL
3 ; RUN: opt < %s -instcombine -S | FileCheck %s -check-prefix=NODL -check-prefix=ALL
8 @int = global i32 zeroinitializer
10 ; Zero byte allocas should be merged if they can't be deleted.
15 %X = alloca [0 x i32] ; <[0 x i32]*> [#uses=1]
16 call void (...) @use( [0 x i32]* %X )
17 %Y = alloca i32, i32 0 ; <i32*> [#uses=1]
18 call void (...) @use( i32* %Y )
19 %Z = alloca { } ; <{ }*> [#uses=1]
20 call void (...) @use( { }* %Z )
21 %size = load i32, i32* @int
22 %A = alloca {{}}, i32 %size
23 call void (...) @use( {{}}* %A )
27 ; Zero byte allocas should be deleted.
28 ; CHECK-LABEL: @test2(
30 define void @test2() {
31 %A = alloca i32 ; <i32*> [#uses=1]
32 store i32 123, i32* %A
36 ; Zero byte allocas should be deleted.
37 ; CHECK-LABEL: @test3(
39 define void @test3() {
40 %A = alloca { i32 } ; <{ i32 }*> [#uses=1]
41 %B = getelementptr { i32 }, { i32 }* %A, i32 0, i32 0 ; <i32*> [#uses=1]
42 store i32 123, i32* %B
46 ; CHECK-LABEL: @test4(
47 ; CHECK: = zext i32 %n to i64
48 ; CHECK: %A = alloca i32, i64 %
49 define i32* @test4(i32 %n) {
50 %A = alloca i32, i32 %n
54 ; Allocas which are only used by GEPs, bitcasts, addrspacecasts, and stores
55 ; (transitively) should be deleted.
56 define void @test5() {
57 ; CHECK-LABEL: @test5(
66 %a.1 = getelementptr { i32 }, { i32 }* %a, i32 0, i32 0
67 store i32 123, i32* %a.1
68 store i32* %a.1, i32** %b
69 %b.1 = bitcast i32** %b to i32*
70 store i32 123, i32* %b.1
71 %a.2 = getelementptr { i32 }, { i32 }* %a, i32 0, i32 0
72 store atomic i32 2, i32* %a.2 unordered, align 4
73 %a.3 = getelementptr { i32 }, { i32 }* %a, i32 0, i32 0
74 store atomic i32 3, i32* %a.3 release, align 4
75 %a.4 = getelementptr { i32 }, { i32 }* %a, i32 0, i32 0
76 store atomic i32 4, i32* %a.4 seq_cst, align 4
77 %c.1 = addrspacecast i32* %c to i32 addrspace(1)*
78 store i32 123, i32 addrspace(1)* %c.1
82 declare void @f(i32* %p)
84 ; Check that we don't delete allocas in some erroneous cases.
85 define void @test6() {
86 ; CHECK-LABEL: @test6(
95 %a.1 = getelementptr { i32 }, { i32 }* %a, i32 0, i32 0
96 store volatile i32 123, i32* %a.1
97 tail call void @f(i32* %b)
102 %opaque_type = type opaque
103 %real_type = type { { i32, i32* } }
105 @opaque_global = external constant %opaque_type, align 4
107 define void @test7() {
109 %0 = alloca %real_type, align 4
110 %1 = bitcast %real_type* %0 to i8*
111 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %1, i8* bitcast (%opaque_type* @opaque_global to i8*), i32 8, i1 false)
115 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i1) nounwind
118 ; Check that the GEP indices use the pointer size, or 64 if unknown
119 define void @test8() {
120 ; CHECK-LABEL: @test8(
121 ; CHECK: alloca [100 x i32]
122 ; CHECK: getelementptr inbounds [100 x i32], [100 x i32]* %x1, i64 0, i64 0
125 ; P32: alloca [100 x i32]
126 ; P32: getelementptr inbounds [100 x i32], [100 x i32]* %x1, i32 0, i32 0
128 ; NODL-LABEL: @test8(
129 ; NODL: alloca [100 x i32]
130 ; NODL: getelementptr inbounds [100 x i32], [100 x i32]* %x1, i64 0, i64 0
131 %x = alloca i32, i32 100
132 call void (...) @use(i32* %x)
137 %struct_type = type { i32, i32 }
138 declare void @test9_aux(<{ %struct_type }>* inalloca)
139 declare i8* @llvm.stacksave()
140 declare void @llvm.stackrestore(i8*)
142 define void @test9(%struct_type* %a) {
143 ; CHECK-LABEL: @test9(
145 %inalloca.save = call i8* @llvm.stacksave()
146 %argmem = alloca inalloca <{ %struct_type }>
147 ; CHECK: alloca inalloca i64, align 8
148 %0 = getelementptr inbounds <{ %struct_type }>, <{ %struct_type }>* %argmem, i32 0, i32 0
149 %1 = bitcast %struct_type* %0 to i8*
150 %2 = bitcast %struct_type* %a to i8*
151 call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %1, i8* align 4 %2, i32 8, i1 false)
152 call void @test9_aux(<{ %struct_type }>* inalloca %argmem)
153 call void @llvm.stackrestore(i8* %inalloca.save)
157 define void @test10() {
159 ; ALL-LABEL: @test10(
160 ; ALL: %v32 = alloca i1, align 8
161 ; ALL: %v64 = alloca i1, align 8
162 ; ALL: %v33 = alloca i1, align 8
163 %v32 = alloca i1, align 8
164 %v64 = alloca i1, i64 1, align 8
165 %v33 = alloca i1, i33 1, align 8
166 call void (...) @use(i1* %v32, i1* %v64, i1* %v33)
170 define void @test11() {
172 ; ALL-LABEL: @test11(
173 ; ALL: %y = alloca i32
174 ; ALL: call void (...) @use(i32* nonnull @int) [ "blah"(i32* %y) ]
177 call void (...) @use(i32* nonnull @int) [ "blah"(i32* %y) ]