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