1; RUN: llc < %s -march=amdgcn -mcpu=SI -verify-machineinstrs | FileCheck %s
2; RUN: llc < %s -march=amdgcn -mcpu=tonga -verify-machineinstrs | FileCheck %s
3
4; CHECK-LABEL: {{^}}select0:
5; i64 select should be split into two i32 selects, and we shouldn't need
6; to use a shfit to extract the hi dword of the input.
7; CHECK-NOT: s_lshr_b64
8; CHECK: v_cndmask
9; CHECK: v_cndmask
10define void @select0(i64 addrspace(1)* %out, i32 %cond, i64 %in) {
11entry:
12  %0 = icmp ugt i32 %cond, 5
13  %1 = select i1 %0, i64 0, i64 %in
14  store i64 %1, i64 addrspace(1)* %out
15  ret void
16}
17
18; CHECK-LABEL: {{^}}select_trunc_i64:
19; CHECK: v_cndmask_b32
20; CHECK-NOT: v_cndmask_b32
21define void @select_trunc_i64(i32 addrspace(1)* %out, i32 %cond, i64 %in) nounwind {
22  %cmp = icmp ugt i32 %cond, 5
23  %sel = select i1 %cmp, i64 0, i64 %in
24  %trunc = trunc i64 %sel to i32
25  store i32 %trunc, i32 addrspace(1)* %out, align 4
26  ret void
27}
28
29; CHECK-LABEL: {{^}}select_trunc_i64_2:
30; CHECK: v_cndmask_b32
31; CHECK-NOT: v_cndmask_b32
32define void @select_trunc_i64_2(i32 addrspace(1)* %out, i32 %cond, i64 %a, i64 %b) nounwind {
33  %cmp = icmp ugt i32 %cond, 5
34  %sel = select i1 %cmp, i64 %a, i64 %b
35  %trunc = trunc i64 %sel to i32
36  store i32 %trunc, i32 addrspace(1)* %out, align 4
37  ret void
38}
39
40; CHECK-LABEL: {{^}}v_select_trunc_i64_2:
41; CHECK: v_cndmask_b32
42; CHECK-NOT: v_cndmask_b32
43define void @v_select_trunc_i64_2(i32 addrspace(1)* %out, i32 %cond, i64 addrspace(1)* %aptr, i64 addrspace(1)* %bptr) nounwind {
44  %cmp = icmp ugt i32 %cond, 5
45  %a = load i64, i64 addrspace(1)* %aptr, align 8
46  %b = load i64, i64 addrspace(1)* %bptr, align 8
47  %sel = select i1 %cmp, i64 %a, i64 %b
48  %trunc = trunc i64 %sel to i32
49  store i32 %trunc, i32 addrspace(1)* %out, align 4
50  ret void
51}
52
53; CHECK-LABEL: {{^}}v_select_i64_split_imm:
54; CHECK-DAG: v_cndmask_b32_e32 {{v[0-9]+}}, 0, {{v[0-9]+}}
55; CHECK-DAG: v_cndmask_b32_e32 {{v[0-9]+}}, 63, {{v[0-9]+}}
56; CHECK: s_endpgm
57define void @v_select_i64_split_imm(i64 addrspace(1)* %out, i32 %cond, i64 addrspace(1)* %aptr, i64 addrspace(1)* %bptr) nounwind {
58  %cmp = icmp ugt i32 %cond, 5
59  %a = load i64, i64 addrspace(1)* %aptr, align 8
60  %b = load i64, i64 addrspace(1)* %bptr, align 8
61  %sel = select i1 %cmp, i64 %a, i64 270582939648 ; 63 << 32
62  store i64 %sel, i64 addrspace(1)* %out, align 8
63  ret void
64}
65