| 1 |
// RUN: %clang_cc1 -triple spir-unknown-unknown -O1 -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header -emit-llvm-bc %s -o %t.bc |
| 2 |
// RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV |
| 3 |
// RUN: llvm-spirv %t.bc -o %t.spv |
| 4 |
// RUN: spirv-val %t.spv |
| 5 |
// RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.rev.bc |
| 6 |
// RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM |
| 7 |
|
| 8 |
// CHECK-SPIRV-DAG: TypeInt [[int:[0-9]+]] 32 0 |
| 9 |
// CHECK-SPIRV-DAG: TypeFloat [[float:[0-9]+]] 32 |
| 10 |
// CHECK-SPIRV-DAG: Constant [[int]] [[ScopeWorkgroup:[0-9]+]] 2 |
| 11 |
// CHECK-SPIRV-DAG: Constant [[int]] [[ScopeSubgroup:[0-9]+]] 3 |
| 12 |
|
| 13 |
// CHECK-SPIRV-LABEL: 5 Function |
| 14 |
// CHECK-SPIRV: GroupFMax [[float]] {{[0-9]+}} [[ScopeWorkgroup]] 0 |
| 15 |
// CHECK-SPIRV: FunctionEnd |
| 16 |
|
| 17 |
// CHECK-LLVM-LABEL: @testWorkGroupFMax |
| 18 |
// CHECK-LLVM: call spir_func float @_Z21work_group_reduce_maxf(float %a) |
| 19 |
|
| 20 |
kernel void testWorkGroupFMax(float a, global float *res) { |
| 21 |
res[0] = work_group_reduce_max(a); |
| 22 |
} |
| 23 |
|
| 24 |
// CHECK-SPIRV-LABEL: 5 Function |
| 25 |
// CHECK-SPIRV: GroupFMin [[float]] {{[0-9]+}} [[ScopeWorkgroup]] 0 |
| 26 |
// CHECK-SPIRV: FunctionEnd |
| 27 |
|
| 28 |
// CHECK-LLVM-LABEL: @testWorkGroupFMin |
| 29 |
// CHECK-LLVM: call spir_func float @_Z21work_group_reduce_minf(float %a) |
| 30 |
|
| 31 |
kernel void testWorkGroupFMin(float a, global float *res) { |
| 32 |
res[0] = work_group_reduce_min(a); |
| 33 |
} |
| 34 |
|
| 35 |
// CHECK-SPIRV-LABEL: 5 Function |
| 36 |
// CHECK-SPIRV: GroupFAdd [[float]] {{[0-9]+}} [[ScopeWorkgroup]] 0 |
| 37 |
// CHECK-SPIRV: FunctionEnd |
| 38 |
|
| 39 |
// CHECK-LLVM-LABEL: @testWorkGroupFAdd |
| 40 |
// CHECK-LLVM: call spir_func float @_Z21work_group_reduce_addf(float %a) |
| 41 |
|
| 42 |
kernel void testWorkGroupFAdd(float a, global float *res) { |
| 43 |
res[0] = work_group_reduce_add(a); |
| 44 |
} |
| 45 |
|
| 46 |
// CHECK-SPIRV-LABEL: 5 Function |
| 47 |
// CHECK-SPIRV: GroupFMax [[float]] {{[0-9]+}} [[ScopeWorkgroup]] 1 |
| 48 |
// CHECK-SPIRV: FunctionEnd |
| 49 |
|
| 50 |
// CHECK-LLVM-LABEL: @testWorkGroupScanInclusiveFMax |
| 51 |
// CHECK-LLVM: call spir_func float @_Z29work_group_scan_inclusive_maxf(float %a) |
| 52 |
|
| 53 |
kernel void testWorkGroupScanInclusiveFMax(float a, global float *res) { |
| 54 |
res[0] = work_group_scan_inclusive_max(a); |
| 55 |
} |
| 56 |
|
| 57 |
// CHECK-SPIRV-LABEL: 5 Function |
| 58 |
// CHECK-SPIRV: GroupFMax [[float]] {{[0-9]+}} [[ScopeWorkgroup]] 2 |
| 59 |
// CHECK-SPIRV: FunctionEnd |
| 60 |
|
| 61 |
// CHECK-LLVM-LABEL: @testWorkGroupScanExclusiveFMax |
| 62 |
// CHECK-LLVM: call spir_func float @_Z29work_group_scan_exclusive_maxf(float %a) |
| 63 |
|
| 64 |
kernel void testWorkGroupScanExclusiveFMax(float a, global float *res) { |
| 65 |
res[0] = work_group_scan_exclusive_max(a); |
| 66 |
} |
| 67 |
|
| 68 |
// CHECK-SPIRV-LABEL: 5 Function |
| 69 |
// CHECK-SPIRV: GroupSMax [[int]] {{[0-9]+}} [[ScopeWorkgroup]] 0 |
| 70 |
// CHECK-SPIRV: FunctionEnd |
| 71 |
|
| 72 |
// CHECK-LLVM-LABEL: @testWorkGroupSMax |
| 73 |
// CHECK-LLVM: call spir_func i32 @_Z21work_group_reduce_maxi(i32 %a) |
| 74 |
|
| 75 |
kernel void testWorkGroupSMax(int a, global int *res) { |
| 76 |
res[0] = work_group_reduce_max(a); |
| 77 |
} |
| 78 |
|
| 79 |
// CHECK-SPIRV-LABEL: 5 Function |
| 80 |
// CHECK-SPIRV: GroupSMin [[int]] {{[0-9]+}} [[ScopeWorkgroup]] 0 |
| 81 |
// CHECK-SPIRV: FunctionEnd |
| 82 |
|
| 83 |
// CHECK-LLVM-LABEL: @testWorkGroupSMin |
| 84 |
// CHECK-LLVM: call spir_func i32 @_Z21work_group_reduce_mini(i32 %a) |
| 85 |
|
| 86 |
kernel void testWorkGroupSMin(int a, global int *res) { |
| 87 |
res[0] = work_group_reduce_min(a); |
| 88 |
} |
| 89 |
|
| 90 |
// CHECK-SPIRV-LABEL: 5 Function |
| 91 |
// CHECK-SPIRV: GroupIAdd [[int]] {{[0-9]+}} [[ScopeWorkgroup]] 0 |
| 92 |
// CHECK-SPIRV: FunctionEnd |
| 93 |
|
| 94 |
// CHECK-LLVM-LABEL: @testWorkGroupIAddSigned |
| 95 |
// TODO: This should map to _Z21work_group_reduce_addj, instead. |
| 96 |
// Update this test and remove OpGroupIAdd.spt when fixing this. |
| 97 |
// CHECK-LLVM: call spir_func i32 @_Z21work_group_reduce_addi(i32 %a) |
| 98 |
|
| 99 |
kernel void testWorkGroupIAddSigned(int a, global int *res) { |
| 100 |
res[0] = work_group_reduce_add(a); |
| 101 |
} |
| 102 |
|
| 103 |
// CHECK-SPIRV-LABEL: 5 Function |
| 104 |
// CHECK-SPIRV: GroupIAdd [[int]] {{[0-9]+}} [[ScopeWorkgroup]] 0 |
| 105 |
// CHECK-SPIRV: FunctionEnd |
| 106 |
|
| 107 |
// CHECK-LLVM-LABEL: @testWorkGroupIAddUnsigned |
| 108 |
// TODO: This should map to _Z21work_group_reduce_addj, instead. |
| 109 |
// Update this test and remove OpGroupIAdd.spt when fixing this. |
| 110 |
// CHECK-LLVM: call spir_func i32 @_Z21work_group_reduce_addi(i32 %a) |
| 111 |
|
| 112 |
kernel void testWorkGroupIAddUnsigned(uint a, global uint *res) { |
| 113 |
res[0] = work_group_reduce_add(a); |
| 114 |
} |
| 115 |
|
| 116 |
// CHECK-SPIRV-LABEL: 5 Function |
| 117 |
// CHECK-SPIRV: GroupUMax [[int]] {{[0-9]+}} [[ScopeWorkgroup]] 0 |
| 118 |
// CHECK-SPIRV: FunctionEnd |
| 119 |
|
| 120 |
// CHECK-LLVM-LABEL: @testWorkGroupUMax |
| 121 |
// CHECK-LLVM: call spir_func i32 @_Z21work_group_reduce_maxj(i32 %a) |
| 122 |
|
| 123 |
kernel void testWorkGroupUMax(uint a, global uint *res) { |
| 124 |
res[0] = work_group_reduce_max(a); |
| 125 |
} |
| 126 |
|
| 127 |
// CHECK-SPIRV-LABEL: 5 Function |
| 128 |
// CHECK-SPIRV: GroupUMax [[int]] {{[0-9]+}} [[ScopeSubgroup]] 0 |
| 129 |
// CHECK-SPIRV: FunctionEnd |
| 130 |
|
| 131 |
// CHECK-LLVM-LABEL: @testSubGroupUMax |
| 132 |
// CHECK-LLVM: call spir_func i32 @_Z20sub_group_reduce_maxj(i32 %a) |
| 133 |
|
| 134 |
#pragma OPENCL EXTENSION cl_khr_subgroups: enable |
| 135 |
kernel void testSubGroupUMax(uint a, global uint *res) { |
| 136 |
res[0] = sub_group_reduce_max(a); |
| 137 |
} |
| 138 |
#pragma OPENCL EXTENSION cl_khr_subgroups: disable |
| 139 |
|
| 140 |
// CHECK-SPIRV-LABEL: 5 Function |
| 141 |
// CHECK-SPIRV: GroupUMax [[int]] {{[0-9]+}} [[ScopeWorkgroup]] 1 |
| 142 |
// CHECK-SPIRV: FunctionEnd |
| 143 |
|
| 144 |
// CHECK-LLVM-LABEL: @testWorkGroupScanInclusiveUMax |
| 145 |
// CHECK-LLVM: call spir_func i32 @_Z29work_group_scan_inclusive_maxj(i32 %a) |
| 146 |
|
| 147 |
kernel void testWorkGroupScanInclusiveUMax(uint a, global uint *res) { |
| 148 |
res[0] = work_group_scan_inclusive_max(a); |
| 149 |
} |
| 150 |
|
| 151 |
// CHECK-SPIRV-LABEL: 5 Function |
| 152 |
// CHECK-SPIRV: GroupUMax [[int]] {{[0-9]+}} [[ScopeWorkgroup]] 2 |
| 153 |
// CHECK-SPIRV: FunctionEnd |
| 154 |
|
| 155 |
// CHECK-LLVM-LABEL: @testWorkGroupScanExclusiveUMax |
| 156 |
// CHECK-LLVM: call spir_func i32 @_Z29work_group_scan_exclusive_maxj(i32 %a) |
| 157 |
|
| 158 |
kernel void testWorkGroupScanExclusiveUMax(uint a, global uint *res) { |
| 159 |
res[0] = work_group_scan_exclusive_max(a); |
| 160 |
} |
| 161 |
|
| 162 |
// CHECK-SPIRV-LABEL: 5 Function |
| 163 |
// CHECK-SPIRV: GroupUMin [[int]] {{[0-9]+}} [[ScopeWorkgroup]] 0 |
| 164 |
// CHECK-SPIRV: FunctionEnd |
| 165 |
|
| 166 |
// CHECK-LLVM-LABEL: @testWorkGroupUMin |
| 167 |
// CHECK-LLVM: call spir_func i32 @_Z21work_group_reduce_minj(i32 %a) |
| 168 |
|
| 169 |
kernel void testWorkGroupUMin(uint a, global uint *res) { |
| 170 |
res[0] = work_group_reduce_min(a); |
| 171 |
} |
| 172 |
|
| 173 |
// CHECK-SPIRV-LABEL: 5 Function |
| 174 |
// CHECK-SPIRV: GroupBroadcast [[int]] {{[0-9]+}} [[ScopeWorkgroup]] |
| 175 |
// CHECK-SPIRV: FunctionEnd |
| 176 |
|
| 177 |
// CHECK-LLVM-LABEL: @testWorkGroupBroadcast |
| 178 |
// CHECK-LLVM: call spir_func i32 @_Z20work_group_broadcast{{[ji]}}{{[jm]}}(i32 %a, i32 %0) |
| 179 |
|
| 180 |
kernel void testWorkGroupBroadcast(uint a, global size_t *id, global int *res) { |
| 181 |
res[0] = work_group_broadcast(a, *id); |
| 182 |
} |