Issue: https://github.com/llvm/llvm-project/issues/99172 - [x] Implement `WavePrefixSum` clang builtin - [x] Link `WavePrefixSum` clang builtin with `hlsl_intrinsics.h` - [x] Add sema checks for `WavePrefixSum` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp` - [x] Add codegen for `WavePrefixSum` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp` - [x] Add codegen tests to `clang/test/CodeGenHLSL/builtins/WavePrefixSum.hlsl` - [x] Add sema tests to `clang/test/SemaHLSL/BuiltIns/WavePrefixSum-errors.hlsl` - [x] Create the `int_dx_WavePrefixSum` intrinsic in `IntrinsicsDirectX.td` - [x] Create the `DXILOpMapping` of `int_dx_WavePrefixSum` to `121` in `DXIL.td` - [x] Create the `WavePrefixSum.ll` and `WavePrefixSum_errors.ll` tests in `llvm/test/CodeGen/DirectX/` - [x] Create the `int_spv_WavePrefixSum` intrinsic in `IntrinsicsSPIRV.td` - [x] In SPIRVInstructionSelector.cpp create the `WavePrefixSum` lowering and map it to `int_spv_WavePrefixSum` in `SPIRVInstructionSelector::selectIntrinsic`. - [x] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WavePrefixSum.ll` I also added a new macro `GENERATE_HLSL_INTRINSIC_FUNCTION_SELECT_UNSIGNED` in conjunction with the new function `getUnsignedIntrinsicVariant` to make selecting unsigned variants of the intrinsic easier. As a result, I was able to replace `getWaveActiveSumIntrinsic`, `getWaveActiveMaxIntrinsic`, and `getWaveActiveMinIntrinsic` using the new macro.
47 lines
2.1 KiB
HLSL
47 lines
2.1 KiB
HLSL
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -triple \
|
|
// RUN: dxil-pc-shadermodel6.3-compute %s -emit-llvm -disable-llvm-passes -o - | \
|
|
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DXIL
|
|
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -triple \
|
|
// RUN: spirv-pc-vulkan-compute %s -emit-llvm -disable-llvm-passes -o - | \
|
|
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV
|
|
|
|
// Test basic lowering to runtime function call.
|
|
|
|
// CHECK-LABEL: test_int
|
|
int test_int(int expr) {
|
|
// CHECK-SPIRV: %[[RET:.*]] = call spir_func [[TY:.*]] @llvm.spv.wave.prefix.sum.i32([[TY]] %[[#]])
|
|
// CHECK-DXIL: %[[RET:.*]] = call [[TY:.*]] @llvm.dx.wave.prefix.sum.i32([[TY]] %[[#]])
|
|
// CHECK: ret [[TY]] %[[RET]]
|
|
return WavePrefixSum(expr);
|
|
}
|
|
|
|
// CHECK-DXIL: declare [[TY]] @llvm.dx.wave.prefix.sum.i32([[TY]]) #[[#attr:]]
|
|
// CHECK-SPIRV: declare [[TY]] @llvm.spv.wave.prefix.sum.i32([[TY]]) #[[#attr:]]
|
|
|
|
// CHECK-LABEL: test_uint64_t
|
|
uint64_t test_uint64_t(uint64_t expr) {
|
|
// CHECK-SPIRV: %[[RET:.*]] = call spir_func [[TY:.*]] @llvm.spv.wave.prefix.sum.i64([[TY]] %[[#]])
|
|
// CHECK-DXIL: %[[RET:.*]] = call [[TY:.*]] @llvm.dx.wave.prefix.usum.i64([[TY]] %[[#]])
|
|
// CHECK: ret [[TY]] %[[RET]]
|
|
return WavePrefixSum(expr);
|
|
}
|
|
|
|
// CHECK-DXIL: declare [[TY]] @llvm.dx.wave.prefix.usum.i64([[TY]]) #[[#attr:]]
|
|
// CHECK-SPIRV: declare [[TY]] @llvm.spv.wave.prefix.sum.i64([[TY]]) #[[#attr:]]
|
|
|
|
// Test basic lowering to runtime function call with array and float value.
|
|
|
|
// CHECK-LABEL: test_floatv4
|
|
float4 test_floatv4(float4 expr) {
|
|
// CHECK-SPIRV: %[[RET1:.*]] = call reassoc nnan ninf nsz arcp afn spir_func [[TY1:.*]] @llvm.spv.wave.prefix.sum.v4f32([[TY1]] %[[#]]
|
|
// CHECK-DXIL: %[[RET1:.*]] = call reassoc nnan ninf nsz arcp afn [[TY1:.*]] @llvm.dx.wave.prefix.sum.v4f32([[TY1]] %[[#]])
|
|
// CHECK: ret [[TY1]] %[[RET1]]
|
|
return WavePrefixSum(expr);
|
|
}
|
|
|
|
// CHECK-DXIL: declare [[TY1]] @llvm.dx.wave.prefix.sum.v4f32([[TY1]]) #[[#attr]]
|
|
// CHECK-SPIRV: declare [[TY1]] @llvm.spv.wave.prefix.sum.v4f32([[TY1]]) #[[#attr]]
|
|
|
|
// CHECK: attributes #[[#attr]] = {{{.*}} convergent {{.*}}}
|
|
|