R600/SI: Add a stub GCNTargetMachine
[oota-llvm.git] / test / CodeGen / R600 / 32-bit-local-address-space.ll
1 ; RUN: llc -march=amdgcn -mcpu=verde -verify-machineinstrs < %s | FileCheck -check-prefix=SI -check-prefix=FUNC %s
2
3 ; On Southern Islands GPUs the local address space(3) uses 32-bit pointers and
4 ; the global address space(1) uses 64-bit pointers.  These tests check to make sure
5 ; the correct pointer size is used for the local address space.
6
7 ; The e{{32|64}} suffix on the instructions refers to the encoding size and not
8 ; the size of the operands.  The operand size is denoted in the instruction name.
9 ; Instructions with B32, U32, and I32 in their name take 32-bit operands, while
10 ; instructions with B64, U64, and I64 take 64-bit operands.
11
12 ; FUNC-LABEL: {{^}}local_address_load:
13 ; SI: v_mov_b32_e{{32|64}} [[PTR:v[0-9]]]
14 ; SI: ds_read_b32 v{{[0-9]+}}, [[PTR]]
15 define void @local_address_load(i32 addrspace(1)* %out, i32 addrspace(3)* %in) {
16 entry:
17   %0 = load i32 addrspace(3)* %in
18   store i32 %0, i32 addrspace(1)* %out
19   ret void
20 }
21
22 ; FUNC-LABEL: {{^}}local_address_gep:
23 ; SI: s_add_i32 [[SPTR:s[0-9]]]
24 ; SI: v_mov_b32_e32 [[VPTR:v[0-9]+]], [[SPTR]]
25 ; SI: ds_read_b32 [[VPTR]]
26 define void @local_address_gep(i32 addrspace(1)* %out, i32 addrspace(3)* %in, i32 %offset) {
27 entry:
28   %0 = getelementptr i32 addrspace(3)* %in, i32 %offset
29   %1 = load i32 addrspace(3)* %0
30   store i32 %1, i32 addrspace(1)* %out
31   ret void
32 }
33
34 ; FUNC-LABEL: {{^}}local_address_gep_const_offset:
35 ; SI: v_mov_b32_e32 [[VPTR:v[0-9]+]], s{{[0-9]+}}
36 ; SI: ds_read_b32 v{{[0-9]+}}, [[VPTR]] offset:4
37 define void @local_address_gep_const_offset(i32 addrspace(1)* %out, i32 addrspace(3)* %in) {
38 entry:
39   %0 = getelementptr i32 addrspace(3)* %in, i32 1
40   %1 = load i32 addrspace(3)* %0
41   store i32 %1, i32 addrspace(1)* %out
42   ret void
43 }
44
45 ; Offset too large, can't fold into 16-bit immediate offset.
46 ; FUNC-LABEL: {{^}}local_address_gep_large_const_offset:
47 ; SI: s_add_i32 [[SPTR:s[0-9]]], s{{[0-9]+}}, 0x10004
48 ; SI: v_mov_b32_e32 [[VPTR:v[0-9]+]], [[SPTR]]
49 ; SI: ds_read_b32 [[VPTR]]
50 define void @local_address_gep_large_const_offset(i32 addrspace(1)* %out, i32 addrspace(3)* %in) {
51 entry:
52   %0 = getelementptr i32 addrspace(3)* %in, i32 16385
53   %1 = load i32 addrspace(3)* %0
54   store i32 %1, i32 addrspace(1)* %out
55   ret void
56 }
57
58 ; FUNC-LABEL: {{^}}null_32bit_lds_ptr:
59 ; SI: v_cmp_ne_i32
60 ; SI-NOT: v_cmp_ne_i32
61 ; SI: v_cndmask_b32
62 define void @null_32bit_lds_ptr(i32 addrspace(1)* %out, i32 addrspace(3)* %lds) nounwind {
63   %cmp = icmp ne i32 addrspace(3)* %lds, null
64   %x = select i1 %cmp, i32 123, i32 456
65   store i32 %x, i32 addrspace(1)* %out
66   ret void
67 }
68
69 ; FUNC-LABEL: {{^}}mul_32bit_ptr:
70 ; SI: s_mul_i32
71 ; SI-NEXT: s_add_i32
72 ; SI: ds_read_b32
73 define void @mul_32bit_ptr(float addrspace(1)* %out, [3 x float] addrspace(3)* %lds, i32 %tid) {
74   %ptr = getelementptr [3 x float] addrspace(3)* %lds, i32 %tid, i32 0
75   %val = load float addrspace(3)* %ptr
76   store float %val, float addrspace(1)* %out
77   ret void
78 }
79
80 @g_lds = addrspace(3) global float undef, align 4
81
82 ; FUNC-LABEL: {{^}}infer_ptr_alignment_global_offset:
83 ; SI: v_mov_b32_e32 [[REG:v[0-9]+]], 0
84 ; SI: ds_read_b32 v{{[0-9]+}}, [[REG]]
85 define void @infer_ptr_alignment_global_offset(float addrspace(1)* %out, i32 %tid) {
86   %val = load float addrspace(3)* @g_lds
87   store float %val, float addrspace(1)* %out
88   ret void
89 }
90
91
92 @ptr = addrspace(3) global i32 addrspace(3)* undef
93 @dst = addrspace(3) global [16384 x i32] undef
94
95 ; FUNC-LABEL: {{^}}global_ptr:
96 ; SI: ds_write_b32
97 define void @global_ptr() nounwind {
98   store i32 addrspace(3)* getelementptr ([16384 x i32] addrspace(3)* @dst, i32 0, i32 16), i32 addrspace(3)* addrspace(3)* @ptr
99   ret void
100 }
101
102 ; FUNC-LABEL: {{^}}local_address_store:
103 ; SI: ds_write_b32
104 define void @local_address_store(i32 addrspace(3)* %out, i32 %val) {
105   store i32 %val, i32 addrspace(3)* %out
106   ret void
107 }
108
109 ; FUNC-LABEL: {{^}}local_address_gep_store:
110 ; SI: s_add_i32 [[SADDR:s[0-9]+]],
111 ; SI: v_mov_b32_e32 [[ADDR:v[0-9]+]], [[SADDR]]
112 ; SI: ds_write_b32 [[ADDR]], v{{[0-9]+}}
113 define void @local_address_gep_store(i32 addrspace(3)* %out, i32, i32 %val, i32 %offset) {
114   %gep = getelementptr i32 addrspace(3)* %out, i32 %offset
115   store i32 %val, i32 addrspace(3)* %gep, align 4
116   ret void
117 }
118
119 ; FUNC-LABEL: {{^}}local_address_gep_const_offset_store:
120 ; SI: v_mov_b32_e32 [[VPTR:v[0-9]+]], s{{[0-9]+}}
121 ; SI: v_mov_b32_e32 [[VAL:v[0-9]+]], s{{[0-9]+}}
122 ; SI: ds_write_b32 [[VPTR]], [[VAL]] offset:4
123 define void @local_address_gep_const_offset_store(i32 addrspace(3)* %out, i32 %val) {
124   %gep = getelementptr i32 addrspace(3)* %out, i32 1
125   store i32 %val, i32 addrspace(3)* %gep, align 4
126   ret void
127 }
128
129 ; Offset too large, can't fold into 16-bit immediate offset.
130 ; FUNC-LABEL: {{^}}local_address_gep_large_const_offset_store:
131 ; SI: s_add_i32 [[SPTR:s[0-9]]], s{{[0-9]+}}, 0x10004
132 ; SI: v_mov_b32_e32 [[VPTR:v[0-9]+]], [[SPTR]]
133 ; SI: ds_write_b32 [[VPTR]], v{{[0-9]+}} [M0]{{$}}
134 define void @local_address_gep_large_const_offset_store(i32 addrspace(3)* %out, i32 %val) {
135   %gep = getelementptr i32 addrspace(3)* %out, i32 16385
136   store i32 %val, i32 addrspace(3)* %gep, align 4
137   ret void
138 }