1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=amdgcn -global-isel=0 -mcpu=gfx1010 < %s | FileCheck %s --check-prefixes=CHECK,DAGISEL
3 ; RUN: llc -mtriple=amdgcn -global-isel=0 -mcpu=gfx1100 -amdgpu-enable-delay-alu=0 < %s | FileCheck %s --check-prefixes=CHECK,DAGISEL
4 ; RUN: llc -mtriple=amdgcn -global-isel -mcpu=gfx1010 < %s | FileCheck %s --check-prefixes=CHECK,GISEL
5 ; RUN: llc -mtriple=amdgcn -global-isel -mcpu=gfx1100 -amdgpu-enable-delay-alu=0 < %s | FileCheck %s --check-prefixes=CHECK,GISEL
7 declare i64 @llvm.amdgcn.ballot.i64(i1)
8 declare i64 @llvm.ctpop.i64(i64)
12 define amdgpu_cs i64 @constant_false() {
13 ; CHECK-LABEL: constant_false:
15 ; CHECK-NEXT: s_mov_b32 s0, 0
16 ; CHECK-NEXT: s_mov_b32 s1, 0
17 ; CHECK-NEXT: ; return to shader part epilog
18 %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 0)
24 define amdgpu_cs i64 @constant_true() {
25 ; DAGISEL-LABEL: constant_true:
27 ; DAGISEL-NEXT: s_mov_b32 s0, exec_lo
28 ; DAGISEL-NEXT: s_mov_b32 s1, exec_hi
29 ; DAGISEL-NEXT: ; return to shader part epilog
31 ; GISEL-LABEL: constant_true:
33 ; GISEL-NEXT: s_mov_b32 s0, exec_lo
34 ; GISEL-NEXT: s_mov_b32 s1, 0
35 ; GISEL-NEXT: ; return to shader part epilog
36 %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 1)
40 ; Test ballot of a non-comparison operation
42 define amdgpu_cs i64 @non_compare(i32 %x) {
43 ; DAGISEL-LABEL: non_compare:
45 ; DAGISEL-NEXT: v_and_b32_e32 v0, 1, v0
46 ; DAGISEL-NEXT: s_mov_b32 s1, 0
47 ; DAGISEL-NEXT: v_cmp_ne_u32_e64 s0, 0, v0
48 ; DAGISEL-NEXT: ; return to shader part epilog
50 ; GISEL-LABEL: non_compare:
52 ; GISEL-NEXT: v_and_b32_e32 v0, 1, v0
53 ; GISEL-NEXT: s_mov_b32 s1, 0
54 ; GISEL-NEXT: v_cmp_ne_u32_e32 vcc_lo, 0, v0
55 ; GISEL-NEXT: s_and_b32 s0, vcc_lo, exec_lo
56 ; GISEL-NEXT: ; return to shader part epilog
57 %trunc = trunc i32 %x to i1
58 %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 %trunc)
62 ; Test ballot of comparisons
64 define amdgpu_cs i64 @compare_ints(i32 %x, i32 %y) {
65 ; CHECK-LABEL: compare_ints:
67 ; CHECK-NEXT: v_cmp_eq_u32_e64 s0, v0, v1
68 ; CHECK-NEXT: s_mov_b32 s1, 0
69 ; CHECK-NEXT: ; return to shader part epilog
70 %cmp = icmp eq i32 %x, %y
71 %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 %cmp)
75 define amdgpu_cs i64 @compare_int_with_constant(i32 %x) {
76 ; DAGISEL-LABEL: compare_int_with_constant:
78 ; DAGISEL-NEXT: v_cmp_lt_i32_e64 s0, 0x62, v0
79 ; DAGISEL-NEXT: s_mov_b32 s1, 0
80 ; DAGISEL-NEXT: ; return to shader part epilog
82 ; GISEL-LABEL: compare_int_with_constant:
84 ; GISEL-NEXT: v_cmp_le_i32_e64 s0, 0x63, v0
85 ; GISEL-NEXT: s_mov_b32 s1, 0
86 ; GISEL-NEXT: ; return to shader part epilog
87 %cmp = icmp sge i32 %x, 99
88 %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 %cmp)
92 define amdgpu_cs i64 @compare_floats(float %x, float %y) {
93 ; CHECK-LABEL: compare_floats:
95 ; CHECK-NEXT: v_cmp_gt_f32_e64 s0, v0, v1
96 ; CHECK-NEXT: s_mov_b32 s1, 0
97 ; CHECK-NEXT: ; return to shader part epilog
98 %cmp = fcmp ogt float %x, %y
99 %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 %cmp)
103 define amdgpu_cs i64 @ctpop_of_ballot(float %x, float %y) {
104 ; CHECK-LABEL: ctpop_of_ballot:
106 ; CHECK-NEXT: v_cmp_gt_f32_e64 s0, v0, v1
107 ; CHECK-NEXT: s_mov_b32 s1, 0
108 ; CHECK-NEXT: s_bcnt1_i32_b64 s0, s[0:1]
109 ; CHECK-NEXT: ; return to shader part epilog
110 %cmp = fcmp ogt float %x, %y
111 %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 %cmp)
112 %bcnt = call i64 @llvm.ctpop.i64(i64 %ballot)
116 define amdgpu_cs i32 @branch_divergent_ballot64_ne_zero_compare(i32 %v) {
117 ; CHECK-LABEL: branch_divergent_ballot64_ne_zero_compare:
119 ; CHECK-NEXT: v_cmp_gt_u32_e64 s0, 12, v0
120 ; CHECK-NEXT: s_mov_b32 s1, 0
121 ; CHECK-NEXT: s_cmp_eq_u64 s[0:1], 0
122 ; CHECK-NEXT: s_cbranch_scc1 .LBB7_2
123 ; CHECK-NEXT: ; %bb.1: ; %true
124 ; CHECK-NEXT: s_mov_b32 s0, 42
125 ; CHECK-NEXT: s_branch .LBB7_3
126 ; CHECK-NEXT: .LBB7_2: ; %false
127 ; CHECK-NEXT: s_mov_b32 s0, 33
128 ; CHECK-NEXT: s_branch .LBB7_3
129 ; CHECK-NEXT: .LBB7_3:
130 %c = icmp ult i32 %v, 12
131 %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 %c)
132 %ballot_ne_zero = icmp ne i64 %ballot, 0
133 br i1 %ballot_ne_zero, label %true, label %false
140 define amdgpu_cs i32 @branch_divergent_ballot64_ne_zero_and(i32 %v1, i32 %v2) {
141 ; DAGISEL-LABEL: branch_divergent_ballot64_ne_zero_and:
143 ; DAGISEL-NEXT: v_cmp_gt_u32_e32 vcc_lo, 12, v0
144 ; DAGISEL-NEXT: v_cmp_lt_u32_e64 s0, 34, v1
145 ; DAGISEL-NEXT: s_mov_b32 s1, 0
146 ; DAGISEL-NEXT: s_and_b32 s0, vcc_lo, s0
147 ; DAGISEL-NEXT: v_cndmask_b32_e64 v0, 0, 1, s0
148 ; DAGISEL-NEXT: v_cmp_ne_u32_e64 s0, 0, v0
149 ; DAGISEL-NEXT: s_cmp_eq_u64 s[0:1], 0
150 ; DAGISEL-NEXT: s_cbranch_scc1 .LBB8_2
151 ; DAGISEL-NEXT: ; %bb.1: ; %true
152 ; DAGISEL-NEXT: s_mov_b32 s0, 42
153 ; DAGISEL-NEXT: s_branch .LBB8_3
154 ; DAGISEL-NEXT: .LBB8_2: ; %false
155 ; DAGISEL-NEXT: s_mov_b32 s0, 33
156 ; DAGISEL-NEXT: s_branch .LBB8_3
157 ; DAGISEL-NEXT: .LBB8_3:
159 ; GISEL-LABEL: branch_divergent_ballot64_ne_zero_and:
161 ; GISEL-NEXT: v_cmp_gt_u32_e32 vcc_lo, 12, v0
162 ; GISEL-NEXT: v_cmp_lt_u32_e64 s0, 34, v1
163 ; GISEL-NEXT: s_mov_b32 s1, 0
164 ; GISEL-NEXT: s_and_b32 s0, vcc_lo, s0
165 ; GISEL-NEXT: s_cmp_eq_u64 s[0:1], 0
166 ; GISEL-NEXT: s_cbranch_scc1 .LBB8_2
167 ; GISEL-NEXT: ; %bb.1: ; %true
168 ; GISEL-NEXT: s_mov_b32 s0, 42
169 ; GISEL-NEXT: s_branch .LBB8_3
170 ; GISEL-NEXT: .LBB8_2: ; %false
171 ; GISEL-NEXT: s_mov_b32 s0, 33
172 ; GISEL-NEXT: s_branch .LBB8_3
173 ; GISEL-NEXT: .LBB8_3:
174 %v1c = icmp ult i32 %v1, 12
175 %v2c = icmp ugt i32 %v2, 34
176 %c = and i1 %v1c, %v2c
177 %ballot = call i64 @llvm.amdgcn.ballot.i64(i1 %c)
178 %ballot_ne_zero = icmp ne i64 %ballot, 0
179 br i1 %ballot_ne_zero, label %true, label %false