1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc -march=amdgcn -mcpu=gfx900 -global-isel -verify-machineinstrs < %s | FileCheck %s
3
4declare i64 @llvm.amdgcn.ballot.i64(i1)
5
6; Test ballot(0)
7
8define amdgpu_cs i64 @constant_false() {
9; CHECK-LABEL: constant_false:
10; CHECK:       ; %bb.0:
11; CHECK-NEXT:    s_mov_b32 s0, 0
12; CHECK-NEXT:    s_mov_b32 s1, 0
13; CHECK-NEXT:    ; return to shader part epilog
14  %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 0)
15  ret i64 %ballot
16}
17
18; Test ballot(1)
19
20define amdgpu_cs i64 @constant_true() {
21; CHECK-LABEL: constant_true:
22; CHECK:       ; %bb.0:
23; CHECK-NEXT:    s_mov_b32 s0, exec_lo
24; CHECK-NEXT:    s_mov_b32 s1, exec_hi
25; CHECK-NEXT:    ; return to shader part epilog
26  %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 1)
27  ret i64 %ballot
28}
29
30; Test ballot of a non-comparison operation
31
32define amdgpu_cs i64 @non_compare(i32 %x) {
33; CHECK-LABEL: non_compare:
34; CHECK:       ; %bb.0:
35; CHECK-NEXT:    v_and_b32_e32 v0, 1, v0
36; CHECK-NEXT:    v_cmp_ne_u32_e64 s[0:1], 0, v0
37; CHECK-NEXT:    ; return to shader part epilog
38  %trunc = trunc i32 %x to i1
39  %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 %trunc)
40  ret i64 %ballot
41}
42
43; Test ballot of comparisons
44
45define amdgpu_cs i64 @compare_ints(i32 %x, i32 %y) {
46; CHECK-LABEL: compare_ints:
47; CHECK:       ; %bb.0:
48; CHECK-NEXT:    v_cmp_eq_u32_e64 s[0:1], v0, v1
49; CHECK-NEXT:    ; return to shader part epilog
50  %cmp = icmp eq i32 %x, %y
51  %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 %cmp)
52  ret i64 %ballot
53}
54
55define amdgpu_cs i64 @compare_int_with_constant(i32 %x) {
56; CHECK-LABEL: compare_int_with_constant:
57; CHECK:       ; %bb.0:
58; CHECK-NEXT:    v_mov_b32_e32 v1, 0x63
59; CHECK-NEXT:    v_cmp_ge_i32_e64 s[0:1], v0, v1
60; CHECK-NEXT:    ; return to shader part epilog
61  %cmp = icmp sge i32 %x, 99
62  %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 %cmp)
63  ret i64 %ballot
64}
65
66define amdgpu_cs i64 @compare_floats(float %x, float %y) {
67; CHECK-LABEL: compare_floats:
68; CHECK:       ; %bb.0:
69; CHECK-NEXT:    v_cmp_gt_f32_e64 s[0:1], v0, v1
70; CHECK-NEXT:    ; return to shader part epilog
71  %cmp = fcmp ogt float %x, %y
72  %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 %cmp)
73  ret i64 %ballot
74}
75