eb7e4ed8f9f6bcf00f81e437f4998842330b69d9
[oota-llvm.git] / test / CodeGen / R600 / trunc.ll
1 ; RUN: llc -march=amdgcn -mcpu=SI -verify-machineinstrs< %s | FileCheck -check-prefix=SI %s
2 ; RUN: llc -march=r600 -mcpu=cypress < %s | FileCheck -check-prefix=EG %s
3
4 define void @trunc_i64_to_i32_store(i32 addrspace(1)* %out, i64 %in) {
5 ; SI-LABEL: {{^}}trunc_i64_to_i32_store:
6 ; SI: s_load_dword [[SLOAD:s[0-9]+]], s[0:1], 0xb
7 ; SI: v_mov_b32_e32 [[VLOAD:v[0-9]+]], [[SLOAD]]
8 ; SI: buffer_store_dword [[VLOAD]]
9
10 ; EG-LABEL: {{^}}trunc_i64_to_i32_store:
11 ; EG: MEM_RAT_CACHELESS STORE_RAW T0.X, T1.X, 1
12 ; EG: LSHR
13 ; EG-NEXT: 2(
14
15   %result = trunc i64 %in to i32 store i32 %result, i32 addrspace(1)* %out, align 4
16   ret void
17 }
18
19 ; SI-LABEL: {{^}}trunc_load_shl_i64:
20 ; SI-DAG: s_load_dwordx2
21 ; SI-DAG: s_load_dword [[SREG:s[0-9]+]],
22 ; SI: s_lshl_b32 [[SHL:s[0-9]+]], [[SREG]], 2
23 ; SI: v_mov_b32_e32 [[VSHL:v[0-9]+]], [[SHL]]
24 ; SI: buffer_store_dword [[VSHL]],
25 define void @trunc_load_shl_i64(i32 addrspace(1)* %out, i64 %a) {
26   %b = shl i64 %a, 2
27   %result = trunc i64 %b to i32
28   store i32 %result, i32 addrspace(1)* %out, align 4
29   ret void
30 }
31
32 ; SI-LABEL: {{^}}trunc_shl_i64:
33 ; SI: s_load_dwordx2 s{{\[}}[[LO_SREG:[0-9]+]]:{{[0-9]+\]}}, s{{\[[0-9]+:[0-9]+\]}}, 0xd
34 ; SI: s_lshl_b64 s{{\[}}[[LO_SHL:[0-9]+]]:{{[0-9]+\]}}, s{{\[}}[[LO_SREG]]:{{[0-9]+\]}}, 2
35 ; SI: s_add_u32 s[[LO_SREG2:[0-9]+]], s[[LO_SHL]],
36 ; SI: s_addc_u32
37 ; SI: v_mov_b32_e32
38 ; SI: v_mov_b32_e32
39 ; SI: v_mov_b32_e32 v[[LO_VREG:[0-9]+]], s[[LO_SREG2]]
40 ; SI: buffer_store_dword v[[LO_VREG]],
41 define void @trunc_shl_i64(i64 addrspace(1)* %out2, i32 addrspace(1)* %out, i64 %a) {
42   %aa = add i64 %a, 234 ; Prevent shrinking store.
43   %b = shl i64 %aa, 2
44   %result = trunc i64 %b to i32
45   store i32 %result, i32 addrspace(1)* %out, align 4
46   store i64 %b, i64 addrspace(1)* %out2, align 8 ; Prevent reducing ops to 32-bits
47   ret void
48 }
49
50 ; SI-LABEL: {{^}}trunc_i32_to_i1:
51 ; SI: v_and_b32_e32 v{{[0-9]+}}, 1, v{{[0-9]+}}
52 ; SI: v_cmp_eq_i32
53 define void @trunc_i32_to_i1(i32 addrspace(1)* %out, i32 addrspace(1)* %ptr) {
54   %a = load i32 addrspace(1)* %ptr, align 4
55   %trunc = trunc i32 %a to i1
56   %result = select i1 %trunc, i32 1, i32 0
57   store i32 %result, i32 addrspace(1)* %out, align 4
58   ret void
59 }
60
61 ; SI-LABEL: {{^}}sgpr_trunc_i32_to_i1:
62 ; SI: v_and_b32_e64 v{{[0-9]+}}, 1, s{{[0-9]+}}
63 ; SI: v_cmp_eq_i32
64 define void @sgpr_trunc_i32_to_i1(i32 addrspace(1)* %out, i32 %a) {
65   %trunc = trunc i32 %a to i1
66   %result = select i1 %trunc, i32 1, i32 0
67   store i32 %result, i32 addrspace(1)* %out, align 4
68   ret void
69 }