1 ; RUN: opt < %s -sroa -S | FileCheck %s
2 target datalayout = "e-p:64:64:64-p1:16:16:16-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"
4 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly, i32, i1)
5 declare void @llvm.memcpy.p1i8.p0i8.i32(i8 addrspace(1)* nocapture, i8* nocapture readonly, i32, i1)
6 declare void @llvm.memcpy.p0i8.p1i8.i32(i8* nocapture, i8 addrspace(1)* nocapture readonly, i32, i1)
7 declare void @llvm.memcpy.p1i8.p1i8.i32(i8 addrspace(1)* nocapture, i8 addrspace(1)* nocapture readonly, i32, i1)
10 ; Make sure an illegal bitcast isn't introduced
11 define void @test_address_space_1_1(<2 x i64> addrspace(1)* %a, i16 addrspace(1)* %b) {
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
16 %aa = alloca <2 x i64>, align 16
17 %aptr = bitcast <2 x i64> addrspace(1)* %a to i8 addrspace(1)*
18 %aaptr = bitcast <2 x i64>* %aa to i8*
19 call void @llvm.memcpy.p0i8.p1i8.i32(i8* align 2 %aaptr, i8 addrspace(1)* align 2 %aptr, i32 16, i1 false)
20 %bptr = bitcast i16 addrspace(1)* %b to i8 addrspace(1)*
21 call void @llvm.memcpy.p1i8.p0i8.i32(i8 addrspace(1)* align 2 %bptr, i8* align 2 %aaptr, i32 16, i1 false)
25 define void @test_address_space_1_0(<2 x i64> addrspace(1)* %a, i16* %b) {
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>* {{.*}}, align 2
30 %aa = alloca <2 x i64>, align 16
31 %aptr = bitcast <2 x i64> addrspace(1)* %a to i8 addrspace(1)*
32 %aaptr = bitcast <2 x i64>* %aa to i8*
33 call void @llvm.memcpy.p0i8.p1i8.i32(i8* align 2 %aaptr, i8 addrspace(1)* align 2 %aptr, i32 16, i1 false)
34 %bptr = bitcast i16* %b to i8*
35 call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 2 %bptr, i8* align 2 %aaptr, i32 16, i1 false)
39 define void @test_address_space_0_1(<2 x i64>* %a, i16 addrspace(1)* %b) {
40 ; CHECK-LABEL: @test_address_space_0_1(
41 ; CHECK: load <2 x i64>, <2 x i64>* %a, align 2
42 ; CHECK: store <2 x i64> {{.*}}, <2 x i64> addrspace(1)* {{.*}}, align 2
44 %aa = alloca <2 x i64>, align 16
45 %aptr = bitcast <2 x i64>* %a to i8*
46 %aaptr = bitcast <2 x i64>* %aa to i8*
47 call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 2 %aaptr, i8* align 2 %aptr, i32 16, i1 false)
48 %bptr = bitcast i16 addrspace(1)* %b to i8 addrspace(1)*
49 call void @llvm.memcpy.p1i8.p0i8.i32(i8 addrspace(1)* align 2 %bptr, i8* align 2 %aaptr, i32 16, i1 false)
53 %struct.struct_test_27.0.13 = type { i32, float, i64, i8, [4 x i32] }
55 ; Function Attrs: nounwind
56 define void @copy_struct([5 x i64] %in.coerce) {
57 ; CHECK-LABEL: @copy_struct(
60 %in = alloca %struct.struct_test_27.0.13, align 8
61 %0 = bitcast %struct.struct_test_27.0.13* %in to [5 x i64]*
62 store [5 x i64] %in.coerce, [5 x i64]* %0, align 8
63 %scevgep9 = getelementptr %struct.struct_test_27.0.13, %struct.struct_test_27.0.13* %in, i32 0, i32 4, i32 0
64 %scevgep910 = bitcast i32* %scevgep9 to i8*
65 call void @llvm.memcpy.p1i8.p0i8.i32(i8 addrspace(1)* align 4 undef, i8* align 4 %scevgep910, i32 16, i1 false)
69 %union.anon = type { i32* }
71 @g = common global i32 0, align 4
72 @l = common addrspace(3) global i32 0, align 4
74 ; If pointers from different address spaces have different sizes, make sure an
75 ; illegal bitcast isn't introduced
76 define void @pr27557() {
77 ; CHECK-LABEL: @pr27557(
78 ; CHECK: %[[CAST:.*]] = bitcast i32** {{.*}} to i32 addrspace(3)**
79 ; CHECK: store i32 addrspace(3)* @l, i32 addrspace(3)** %[[CAST]]
80 %1 = alloca %union.anon, align 8
81 %2 = bitcast %union.anon* %1 to i32**
82 store i32* @g, i32** %2, align 8
83 %3 = bitcast %union.anon* %1 to i32 addrspace(3)**
84 store i32 addrspace(3)* @l, i32 addrspace(3)** %3, align 8
88 @l2 = common addrspace(2) global i32 0, align 4
90 ; If pointers from different address spaces have the same size, that pointer
91 ; should be promoted through the pair of `ptrtoint`/`inttoptr`.
92 define i32* @pr27557.alt() {
93 ; CHECK-LABEL: @pr27557.alt(
94 ; CHECK: ret i32* inttoptr (i64 ptrtoint (i32 addrspace(2)* @l2 to i64) to i32*)
95 %1 = alloca %union.anon, align 8
96 %2 = bitcast %union.anon* %1 to i32 addrspace(2)**
97 store i32 addrspace(2)* @l2, i32 addrspace(2)** %2, align 8
98 %3 = bitcast %union.anon* %1 to i32**
99 %4 = load i32*, i32** %3, align 8
103 ; Make sure pre-splitting doesn't try to introduce an illegal bitcast
104 define float @presplit(i64 addrspace(1)* %p) {
106 ; CHECK-LABEL: @presplit(
107 ; CHECK: %[[CAST:.*]] = bitcast i64 addrspace(1)* {{.*}} to i32 addrspace(1)*
108 ; CHECK: load i32, i32 addrspace(1)* %[[CAST]]
110 %b.cast = bitcast i64* %b to [2 x float]*
111 %b.gep1 = getelementptr [2 x float], [2 x float]* %b.cast, i32 0, i32 0
112 %b.gep2 = getelementptr [2 x float], [2 x float]* %b.cast, i32 0, i32 1
113 %l = load i64, i64 addrspace(1)* %p
114 store i64 %l, i64* %b
115 %f1 = load float, float* %b.gep1
116 %f2 = load float, float* %b.gep2
117 %ret = fadd float %f1, %f2
121 ; Test load from and store to non-zero address space.
122 define void @test_load_store_diff_addr_space([2 x float] addrspace(1)* %complex1, [2 x float] addrspace(1)* %complex2) {
123 ; CHECK-LABEL: @test_load_store_diff_addr_space
125 ; CHECK: load i32, i32 addrspace(1)*
126 ; CHECK: load i32, i32 addrspace(1)*
127 ; CHECK: store i32 %{{.*}}, i32 addrspace(1)*
128 ; CHECK: store i32 %{{.*}}, i32 addrspace(1)*
130 %a.cast = bitcast i64* %a to [2 x float]*
131 %a.gep1 = getelementptr [2 x float], [2 x float]* %a.cast, i32 0, i32 0
132 %a.gep2 = getelementptr [2 x float], [2 x float]* %a.cast, i32 0, i32 1
133 %complex1.gep = getelementptr [2 x float], [2 x float] addrspace(1)* %complex1, i32 0, i32 0
134 %p1 = bitcast float addrspace(1)* %complex1.gep to i64 addrspace(1)*
135 %v1 = load i64, i64 addrspace(1)* %p1
136 store i64 %v1, i64* %a
137 %f1 = load float, float* %a.gep1
138 %f2 = load float, float* %a.gep2
139 %sum = fadd float %f1, %f2
140 store float %sum, float* %a.gep1
141 store float %sum, float* %a.gep2
142 %v2 = load i64, i64* %a
143 %complex2.gep = getelementptr [2 x float], [2 x float] addrspace(1)* %complex2, i32 0, i32 0
144 %p2 = bitcast float addrspace(1)* %complex2.gep to i64 addrspace(1)*
145 store i64 %v2, i64 addrspace(1)* %p2