• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -sroa -S | FileCheck %s
2; RUN: opt < %s -passes=sroa -S | FileCheck %s
3target datalayout = "e-p:64:64:64-p1:16:16:16-p2:32:32-p3:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n8:16:32:64-A2"
4
5declare void @llvm.memcpy.p2i8.p2i8.i32(i8 addrspace(2)* nocapture, i8 addrspace(2)* nocapture readonly, i32, i1)
6declare void @llvm.memcpy.p1i8.p2i8.i32(i8 addrspace(1)* nocapture, i8 addrspace(2)* nocapture readonly, i32, i1)
7declare void @llvm.memcpy.p2i8.p1i8.i32(i8 addrspace(2)* nocapture, i8 addrspace(1)* nocapture readonly, i32, i1)
8declare void @llvm.memcpy.p1i8.p1i8.i32(i8 addrspace(1)* nocapture, i8 addrspace(1)* nocapture readonly, i32, i1)
9
10
11
12; CHECK-LABEL: @test_address_space_1_1(
13; CHECK: load <2 x i64>, <2 x i64> addrspace(1)* %a, align 2
14; CHECK: store <2 x i64> {{.*}}, <2 x i64> addrspace(1)* {{.*}}, align 2
15; CHECK: ret void
16define void @test_address_space_1_1(<2 x i64> addrspace(1)* %a, i16 addrspace(1)* %b) {
17  %aa = alloca <2 x i64>, align 16, addrspace(2)
18  %aptr = bitcast <2 x i64> addrspace(1)* %a to i8 addrspace(1)*
19  %aaptr = bitcast <2 x i64> addrspace(2)* %aa to i8 addrspace(2)*
20  call void @llvm.memcpy.p2i8.p1i8.i32(i8 addrspace(2)* align 2 %aaptr, i8 addrspace(1)* align 2 %aptr, i32 16, i1 false)
21  %bptr = bitcast i16 addrspace(1)* %b to i8 addrspace(1)*
22  call void @llvm.memcpy.p1i8.p2i8.i32(i8 addrspace(1)* align 2 %bptr, i8 addrspace(2)* align 2 %aaptr, i32 16, i1 false)
23  ret void
24}
25
26; CHECK-LABEL: @test_address_space_1_0(
27; CHECK: load <2 x i64>, <2 x i64> addrspace(1)* %a, align 2
28; CHECK: store <2 x i64> {{.*}}, <2 x i64> addrspace(2)* {{.*}}, align 2
29; CHECK: ret void
30define void @test_address_space_1_0(<2 x i64> addrspace(1)* %a, i16 addrspace(2)* %b) {
31  %aa = alloca <2 x i64>, align 16, addrspace(2)
32  %aptr = bitcast <2 x i64> addrspace(1)* %a to i8 addrspace(1)*
33  %aaptr = bitcast <2 x i64> addrspace(2)* %aa to i8 addrspace(2)*
34  call void @llvm.memcpy.p2i8.p1i8.i32(i8 addrspace(2)* align 2 %aaptr, i8 addrspace(1)* align 2 %aptr, i32 16, i1 false)
35  %bptr = bitcast i16 addrspace(2)* %b to i8 addrspace(2)*
36  call void @llvm.memcpy.p2i8.p2i8.i32(i8 addrspace(2)* align 2 %bptr, i8 addrspace(2)* align 2 %aaptr, i32 16, i1 false)
37  ret void
38}
39
40; CHECK-LABEL: @test_address_space_0_1(
41; CHECK: load <2 x i64>, <2 x i64> addrspace(2)* %a, align 2
42; CHECK: store <2 x i64> {{.*}}, <2 x i64> addrspace(1)* {{.*}}, align 2
43; CHECK: ret void
44define void @test_address_space_0_1(<2 x i64> addrspace(2)* %a, i16 addrspace(1)* %b) {
45  %aa = alloca <2 x i64>, align 16, addrspace(2)
46  %aptr = bitcast <2 x i64> addrspace(2)* %a to i8 addrspace(2)*
47  %aaptr = bitcast <2 x i64> addrspace(2)* %aa to i8 addrspace(2)*
48  call void @llvm.memcpy.p2i8.p2i8.i32(i8 addrspace(2)* align 2 %aaptr, i8 addrspace(2)* align 2 %aptr, i32 16, i1 false)
49  %bptr = bitcast i16 addrspace(1)* %b to i8 addrspace(1)*
50  call void @llvm.memcpy.p1i8.p2i8.i32(i8 addrspace(1)* align 2 %bptr, i8 addrspace(2)* align 2 %aaptr, i32 16, i1 false)
51  ret void
52}
53
54%struct.struct_test_27.0.13 = type { i32, float, i64, i8, [4 x i32] }
55
56; CHECK-LABEL: @copy_struct(
57; CHECK-NOT: memcpy
58define void @copy_struct([5 x i64] %in.coerce) {
59for.end:
60  %in = alloca %struct.struct_test_27.0.13, align 8, addrspace(2)
61  %0 = bitcast %struct.struct_test_27.0.13 addrspace(2)* %in to [5 x i64] addrspace(2)*
62  store [5 x i64] %in.coerce, [5 x i64] addrspace(2)* %0, align 8
63  %scevgep9 = getelementptr %struct.struct_test_27.0.13, %struct.struct_test_27.0.13 addrspace(2)* %in, i32 0, i32 4, i32 0
64  %scevgep910 = bitcast i32 addrspace(2)* %scevgep9 to i8 addrspace(2)*
65  call void @llvm.memcpy.p1i8.p2i8.i32(i8 addrspace(1)* align 4 undef, i8 addrspace(2)* align 4 %scevgep910, i32 16, i1 false)
66  ret void
67}
68
69%union.anon = type { i32* }
70
71@g = common global i32 0, align 4
72@l = common addrspace(3) global i32 0, align 4
73
74; If pointers from different address spaces have different sizes, make sure an
75; illegal bitcast isn't introduced
76; CHECK-LABEL: @pr27557(
77; CHECK: %[[CAST:.*]] = bitcast i32* addrspace(2)* {{.*}} to i32 addrspace(3)* addrspace(2)*
78; CHECK: store i32 addrspace(3)* @l, i32 addrspace(3)* addrspace(2)* %[[CAST]]
79define void @pr27557() {
80  %1 = alloca %union.anon, align 8, addrspace(2)
81  %2 = bitcast %union.anon addrspace(2)* %1 to i32* addrspace(2)*
82  store i32* @g, i32* addrspace(2)* %2, align 8
83  %3 = bitcast %union.anon addrspace(2)* %1 to i32 addrspace(3)* addrspace(2)*
84  store i32 addrspace(3)* @l, i32 addrspace(3)* addrspace(2)* %3, align 8
85  ret void
86}
87
88@l4 = common addrspace(4) global i32 0, align 4
89
90; If pointers from different address spaces have the same size, that pointer
91; should be promoted through the pair of `ptrtoint`/`inttoptr`.
92define i32* @pr27557.alt() {
93; CHECK-LABEL: @pr27557.alt(
94; CHECK: ret i32* inttoptr (i64 ptrtoint (i32 addrspace(4)* @l4 to i64) to i32*)
95  %1 = alloca %union.anon, align 8, addrspace(2)
96  %2 = bitcast %union.anon addrspace(2)* %1 to i32 addrspace(4)* addrspace(2)*
97  store i32 addrspace(4)* @l4, i32 addrspace(4)* addrspace(2)* %2, align 8
98  %3 = bitcast %union.anon addrspace(2)* %1 to i32* addrspace(2)*
99  %4 = load i32*, i32* addrspace(2)* %3, align 8
100  ret i32* %4
101}
102
103; Test load from and store to non-zero address space.
104define void @test_load_store_diff_addr_space([2 x float] addrspace(1)* %complex1, [2 x float] addrspace(1)* %complex2) {
105; CHECK-LABEL: @test_load_store_diff_addr_space
106; CHECK-NOT: alloca
107; CHECK: load i32, i32 addrspace(1)*
108; CHECK: load i32, i32 addrspace(1)*
109; CHECK: store i32 %{{.*}}, i32 addrspace(1)*
110; CHECK: store i32 %{{.*}}, i32 addrspace(1)*
111  %a0 = alloca [2 x i64], align 8, addrspace(2)
112  %a = getelementptr [2 x i64], [2 x i64] addrspace(2)* %a0, i32 0, i32 0
113  %a.cast = bitcast i64 addrspace(2)* %a to [2 x float] addrspace(2)*
114  %a.gep1 = getelementptr [2 x float], [2 x float] addrspace(2)* %a.cast, i32 0, i32 0
115  %a.gep2 = getelementptr [2 x float], [2 x float] addrspace(2)* %a.cast, i32 0, i32 1
116  %complex1.gep = getelementptr [2 x float], [2 x float] addrspace(1)* %complex1, i32 0, i32 0
117  %p1 = bitcast float addrspace(1)* %complex1.gep to i64 addrspace(1)*
118  %v1 = load i64, i64 addrspace(1)* %p1
119  store i64 %v1, i64 addrspace(2)* %a
120  %f1 = load float, float addrspace(2)* %a.gep1
121  %f2 = load float, float addrspace(2)* %a.gep2
122  %sum = fadd float %f1, %f2
123  store float %sum, float addrspace(2)* %a.gep1
124  store float %sum, float addrspace(2)* %a.gep2
125  %v2 = load i64, i64 addrspace(2)* %a
126  %complex2.gep = getelementptr [2 x float], [2 x float] addrspace(1)* %complex2, i32 0, i32 0
127  %p2 = bitcast float addrspace(1)* %complex2.gep to i64 addrspace(1)*
128  store i64 %v2, i64 addrspace(1)* %p2
129  ret void
130}
131
132define void @addressspace_alloca_lifetime() {
133; CHECK-LABEL: @addressspace_alloca_lifetime(
134; CHECK-NEXT:    ret void
135;
136  %alloca = alloca i8, align 8, addrspace(2)
137  %cast = addrspacecast i8 addrspace(2)* %alloca to i8*
138  call void @llvm.lifetime.start.p0i8(i64 2, i8* %cast)
139  ret void
140}
141
142declare void @llvm.lifetime.start.p0i8(i64 %size, i8* nocapture %ptr)
143