Fix assert on unaligned access to global with different address space size.
[oota-llvm.git] / test / CodeGen / R600 / 32-bit-local-address-space.ll
1 ; RUN: llc < %s -march=r600 -mcpu=verde -verify-machineinstrs | FileCheck %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 ; CHECK-LABEL: @local_address_load
13 ; CHECK: V_MOV_B32_e{{32|64}} [[PTR:v[0-9]]]
14 ; CHECK: DS_READ_B32 [[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 ; CHECK-LABEL: @local_address_gep
23 ; CHECK: V_ADD_I32_e{{32|64}} [[PTR:v[0-9]]]
24 ; CHECK: DS_READ_B32 [[PTR]]
25 define void @local_address_gep(i32 addrspace(1)* %out, i32 addrspace(3)* %in, i32 %offset) {
26 entry:
27   %0 = getelementptr i32 addrspace(3)* %in, i32 %offset
28   %1 = load i32 addrspace(3)* %0
29   store i32 %1, i32 addrspace(1)* %out
30   ret void
31 }
32
33 ; CHECK-LABEL: @local_address_gep_const_offset
34 ; CHECK: V_ADD_I32_e{{32|64}} [[PTR:v[0-9]]]
35 ; CHECK: DS_READ_B32 [[PTR]]
36 define void @local_address_gep_const_offset(i32 addrspace(1)* %out, i32 addrspace(3)* %in) {
37 entry:
38   %0 = getelementptr i32 addrspace(3)* %in, i32 1
39   %1 = load i32 addrspace(3)* %0
40   store i32 %1, i32 addrspace(1)* %out
41   ret void
42 }
43
44 ; CHECK-LABEL: @null_32bit_lds_ptr:
45 ; CHECK: V_CMP_NE_I32
46 ; CHECK-NOT: V_CMP_NE_I32
47 ; CHECK: V_CNDMASK_B32
48 define void @null_32bit_lds_ptr(i32 addrspace(1)* %out, i32 addrspace(3)* %lds) nounwind {
49   %cmp = icmp ne i32 addrspace(3)* %lds, null
50   %x = select i1 %cmp, i32 123, i32 456
51   store i32 %x, i32 addrspace(1)* %out
52   ret void
53 }
54
55 ; CHECK-LABEL: @mul_32bit_ptr:
56 ; CHECK: V_MUL_LO_I32
57 ; CHECK-NEXT: V_ADD_I32_e32
58 ; CHECK-NEXT: DS_READ_B32
59 define void @mul_32bit_ptr(float addrspace(1)* %out, [3 x float] addrspace(3)* %lds, i32 %tid) {
60   %ptr = getelementptr [3 x float] addrspace(3)* %lds, i32 %tid, i32 0
61   %val = load float addrspace(3)* %ptr
62   store float %val, float addrspace(1)* %out
63   ret void
64 }
65
66 @g_lds = addrspace(3) global float zeroinitializer, align 4
67
68 ; CHECK-LABEL: @infer_ptr_alignment_global_offset:
69 ; CHECK: V_MOV_B32_e32 [[REG:v[0-9]+]], 0
70 ; CHECK: DS_READ_B32 v{{[0-9]+}}, 0, [[REG]]
71 define void @infer_ptr_alignment_global_offset(float addrspace(1)* %out, i32 %tid) {
72   %val = load float addrspace(3)* @g_lds
73   store float %val, float addrspace(1)* %out
74   ret void
75 }