Skip to content

Commit 4446a98

Browse files
adam-yanginbelic
andauthored
[HLSL][SPIRV][DXIL] Implement WaveActiveSum intrinsic (#118580)
``` - add clang builtin to Builtins.td - link builtin in hlsl_intrinsics - add codegen for spirv intrinsic and two directx intrinsics to retain signedness information of the operands in CGBuiltin.cpp - add semantic analysis in SemaHLSL.cpp - add lowering of spirv intrinsic to spirv backend in SPIRVInstructionSelector.cpp - add lowering of directx intrinsics to WaveActiveOp dxil op in DXIL.td - add test cases to illustrate passespendent pr merges. ``` Resolves #70106 --------- Co-authored-by: Finn Plummer <[email protected]>
1 parent a32e36f commit 4446a98

File tree

15 files changed

+491
-5
lines changed

15 files changed

+491
-5
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4795,6 +4795,12 @@ def HLSLWaveActiveCountBits : LangBuiltin<"HLSL_LANG"> {
47954795
let Prototype = "unsigned int(bool)";
47964796
}
47974797

4798+
def HLSLWaveActiveSum : LangBuiltin<"HLSL_LANG"> {
4799+
let Spellings = ["__builtin_hlsl_wave_active_sum"];
4800+
let Attributes = [NoThrow, Const];
4801+
let Prototype = "void (...)";
4802+
}
4803+
47984804
def HLSLWaveGetLaneIndex : LangBuiltin<"HLSL_LANG"> {
47994805
let Spellings = ["__builtin_hlsl_wave_get_lane_index"];
48004806
let Attributes = [NoThrow, Const];

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9303,7 +9303,7 @@ def err_typecheck_expect_scalar_or_vector : Error<
93039303
"invalid operand of type %0 where %1 or "
93049304
"a vector of such type is required">;
93059305
def err_typecheck_expect_any_scalar_or_vector : Error<
9306-
"invalid operand of type %0 where a scalar or vector is required">;
9306+
"invalid operand of type %0%select{| where a scalar or vector is required}1">;
93079307
def err_typecheck_expect_flt_or_vector : Error<
93089308
"invalid operand of type %0 where floating, complex or "
93099309
"a vector of such types is required">;

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19186,6 +19186,23 @@ static Intrinsic::ID getFirstBitHighIntrinsic(CGHLSLRuntime &RT, QualType QT) {
1918619186
return RT.getFirstBitUHighIntrinsic();
1918719187
}
1918819188

19189+
// Return wave active sum that corresponds to the QT scalar type
19190+
static Intrinsic::ID getWaveActiveSumIntrinsic(llvm::Triple::ArchType Arch,
19191+
CGHLSLRuntime &RT, QualType QT) {
19192+
switch (Arch) {
19193+
case llvm::Triple::spirv:
19194+
return llvm::Intrinsic::spv_wave_reduce_sum;
19195+
case llvm::Triple::dxil: {
19196+
if (QT->isUnsignedIntegerType())
19197+
return llvm::Intrinsic::dx_wave_reduce_usum;
19198+
return llvm::Intrinsic::dx_wave_reduce_sum;
19199+
}
19200+
default:
19201+
llvm_unreachable("Intrinsic WaveActiveSum"
19202+
" not supported by target architecture");
19203+
}
19204+
}
19205+
1918919206
Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
1919019207
const CallExpr *E,
1919119208
ReturnValueSlot ReturnValue) {
@@ -19498,6 +19515,23 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1949819515
Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID),
1949919516
ArrayRef{OpExpr});
1950019517
}
19518+
case Builtin::BI__builtin_hlsl_wave_active_sum: {
19519+
// Due to the use of variadic arguments, explicitly retreive argument
19520+
Value *OpExpr = EmitScalarExpr(E->getArg(0));
19521+
llvm::FunctionType *FT = llvm::FunctionType::get(
19522+
OpExpr->getType(), ArrayRef{OpExpr->getType()}, false);
19523+
Intrinsic::ID IID = getWaveActiveSumIntrinsic(
19524+
getTarget().getTriple().getArch(), CGM.getHLSLRuntime(),
19525+
E->getArg(0)->getType());
19526+
19527+
// Get overloaded name
19528+
std::string Name =
19529+
Intrinsic::getName(IID, ArrayRef{OpExpr->getType()}, &CGM.getModule());
19530+
return EmitRuntimeCall(CGM.CreateRuntimeFunction(FT, Name, {},
19531+
/*Local=*/false,
19532+
/*AssumeConvergent=*/true),
19533+
ArrayRef{OpExpr}, "hlsl.wave.active.sum");
19534+
}
1950119535
case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
1950219536
// We don't define a SPIR-V intrinsic, instead it is a SPIR-V built-in
1950319537
// defined in SPIRVBuiltins.td. So instead we manually get the matching name

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,6 +2468,105 @@ __attribute__((convergent)) double3 WaveReadLaneAt(double3, int32_t);
24682468
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_read_lane_at)
24692469
__attribute__((convergent)) double4 WaveReadLaneAt(double4, int32_t);
24702470

2471+
//===----------------------------------------------------------------------===//
2472+
// WaveActiveSum builtins
2473+
//===----------------------------------------------------------------------===//
2474+
2475+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2476+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2477+
__attribute__((convergent)) half WaveActiveSum(half);
2478+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2479+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2480+
__attribute__((convergent)) half2 WaveActiveSum(half2);
2481+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2482+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2483+
__attribute__((convergent)) half3 WaveActiveSum(half3);
2484+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2485+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2486+
__attribute__((convergent)) half4 WaveActiveSum(half4);
2487+
2488+
#ifdef __HLSL_ENABLE_16_BIT
2489+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2490+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2491+
__attribute__((convergent)) int16_t WaveActiveSum(int16_t);
2492+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2493+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2494+
__attribute__((convergent)) int16_t2 WaveActiveSum(int16_t2);
2495+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2496+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2497+
__attribute__((convergent)) int16_t3 WaveActiveSum(int16_t3);
2498+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2499+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2500+
__attribute__((convergent)) int16_t4 WaveActiveSum(int16_t4);
2501+
2502+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2503+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2504+
__attribute__((convergent)) uint16_t WaveActiveSum(uint16_t);
2505+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2506+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2507+
__attribute__((convergent)) uint16_t2 WaveActiveSum(uint16_t2);
2508+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2509+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2510+
__attribute__((convergent)) uint16_t3 WaveActiveSum(uint16_t3);
2511+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2512+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2513+
__attribute__((convergent)) uint16_t4 WaveActiveSum(uint16_t4);
2514+
#endif
2515+
2516+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2517+
__attribute__((convergent)) int WaveActiveSum(int);
2518+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2519+
__attribute__((convergent)) int2 WaveActiveSum(int2);
2520+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2521+
__attribute__((convergent)) int3 WaveActiveSum(int3);
2522+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2523+
__attribute__((convergent)) int4 WaveActiveSum(int4);
2524+
2525+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2526+
__attribute__((convergent)) uint WaveActiveSum(uint);
2527+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2528+
__attribute__((convergent)) uint2 WaveActiveSum(uint2);
2529+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2530+
__attribute__((convergent)) uint3 WaveActiveSum(uint3);
2531+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2532+
__attribute__((convergent)) uint4 WaveActiveSum(uint4);
2533+
2534+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2535+
__attribute__((convergent)) int64_t WaveActiveSum(int64_t);
2536+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2537+
__attribute__((convergent)) int64_t2 WaveActiveSum(int64_t2);
2538+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2539+
__attribute__((convergent)) int64_t3 WaveActiveSum(int64_t3);
2540+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2541+
__attribute__((convergent)) int64_t4 WaveActiveSum(int64_t4);
2542+
2543+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2544+
__attribute__((convergent)) uint64_t WaveActiveSum(uint64_t);
2545+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2546+
__attribute__((convergent)) uint64_t2 WaveActiveSum(uint64_t2);
2547+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2548+
__attribute__((convergent)) uint64_t3 WaveActiveSum(uint64_t3);
2549+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2550+
__attribute__((convergent)) uint64_t4 WaveActiveSum(uint64_t4);
2551+
2552+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2553+
__attribute__((convergent)) float WaveActiveSum(float);
2554+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2555+
__attribute__((convergent)) float2 WaveActiveSum(float2);
2556+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2557+
__attribute__((convergent)) float3 WaveActiveSum(float3);
2558+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2559+
__attribute__((convergent)) float4 WaveActiveSum(float4);
2560+
2561+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2562+
__attribute__((convergent)) double WaveActiveSum(double);
2563+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2564+
__attribute__((convergent)) double2 WaveActiveSum(double2);
2565+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2566+
__attribute__((convergent)) double3 WaveActiveSum(double3);
2567+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2568+
__attribute__((convergent)) double4 WaveActiveSum(double4);
2569+
24712570
//===----------------------------------------------------------------------===//
24722571
// sign builtins
24732572
//===----------------------------------------------------------------------===//

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,24 @@ static bool CheckAnyScalarOrVector(Sema *S, CallExpr *TheCall,
18591859
(VTy && VTy->getElementType()->isScalarType()))) {
18601860
S->Diag(TheCall->getArg(0)->getBeginLoc(),
18611861
diag::err_typecheck_expect_any_scalar_or_vector)
1862-
<< ArgType;
1862+
<< ArgType << 1;
1863+
return true;
1864+
}
1865+
return false;
1866+
}
1867+
1868+
static bool CheckWaveActive(Sema *S, CallExpr *TheCall) {
1869+
QualType BoolType = S->getASTContext().BoolTy;
1870+
assert(TheCall->getNumArgs() >= 1);
1871+
QualType ArgType = TheCall->getArg(0)->getType();
1872+
auto *VTy = ArgType->getAs<VectorType>();
1873+
// is the bool or vector<bool>
1874+
if (S->Context.hasSameUnqualifiedType(ArgType, BoolType) ||
1875+
(VTy &&
1876+
S->Context.hasSameUnqualifiedType(VTy->getElementType(), BoolType))) {
1877+
S->Diag(TheCall->getArg(0)->getBeginLoc(),
1878+
diag::err_typecheck_expect_any_scalar_or_vector)
1879+
<< ArgType << 0;
18631880
return true;
18641881
}
18651882
return false;
@@ -2156,6 +2173,20 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
21562173
TheCall->setType(ArgTyA);
21572174
break;
21582175
}
2176+
case Builtin::BI__builtin_hlsl_wave_active_sum: {
2177+
if (SemaRef.checkArgCount(TheCall, 1))
2178+
return true;
2179+
2180+
// Ensure input expr type is a scalar/vector and the same as the return type
2181+
if (CheckAnyScalarOrVector(&SemaRef, TheCall, 0))
2182+
return true;
2183+
if (CheckWaveActive(&SemaRef, TheCall))
2184+
return true;
2185+
ExprResult Expr = TheCall->getArg(0);
2186+
QualType ArgTyExpr = Expr.get()->getType();
2187+
TheCall->setType(ArgTyExpr);
2188+
break;
2189+
}
21592190
// Note these are llvm builtins that we want to catch invalid intrinsic
21602191
// generation. Normal handling of these builitns will occur elsewhere.
21612192
case Builtin::BI__builtin_elementwise_bitreverse: {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -triple \
2+
// RUN: dxil-pc-shadermodel6.3-compute %s -emit-llvm -disable-llvm-passes -o - | \
3+
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-DXIL
4+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -triple \
5+
// RUN: spirv-pc-vulkan-compute %s -emit-llvm -disable-llvm-passes -o - | \
6+
// RUN: FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV
7+
8+
// Test basic lowering to runtime function call.
9+
10+
// CHECK-LABEL: test_int
11+
int test_int(int expr) {
12+
// CHECK-SPIRV: %[[RET:.*]] = call spir_func [[TY:.*]] @llvm.spv.wave.reduce.sum.i32([[TY]] %[[#]])
13+
// CHECK-DXIL: %[[RET:.*]] = call [[TY:.*]] @llvm.dx.wave.reduce.sum.i32([[TY]] %[[#]])
14+
// CHECK: ret [[TY]] %[[RET]]
15+
return WaveActiveSum(expr);
16+
}
17+
18+
// CHECK-DXIL: declare [[TY]] @llvm.dx.wave.reduce.sum.i32([[TY]]) #[[#attr:]]
19+
// CHECK-SPIRV: declare spir_func [[TY]] @llvm.spv.wave.reduce.sum.i32([[TY]]) #[[#attr:]]
20+
21+
// CHECK-LABEL: test_uint64_t
22+
uint64_t test_uint64_t(uint64_t expr) {
23+
// CHECK-SPIRV: %[[RET:.*]] = call spir_func [[TY:.*]] @llvm.spv.wave.reduce.sum.i64([[TY]] %[[#]])
24+
// CHECK-DXIL: %[[RET:.*]] = call [[TY:.*]] @llvm.dx.wave.reduce.usum.i64([[TY]] %[[#]])
25+
// CHECK: ret [[TY]] %[[RET]]
26+
return WaveActiveSum(expr);
27+
}
28+
29+
// CHECK-DXIL: declare [[TY]] @llvm.dx.wave.reduce.usum.i64([[TY]]) #[[#attr:]]
30+
// CHECK-SPIRV: declare spir_func [[TY]] @llvm.spv.wave.reduce.sum.i64([[TY]]) #[[#attr:]]
31+
32+
// Test basic lowering to runtime function call with array and float value.
33+
34+
// CHECK-LABEL: test_floatv4
35+
float4 test_floatv4(float4 expr) {
36+
// CHECK-SPIRV: %[[RET1:.*]] = call reassoc nnan ninf nsz arcp afn spir_func [[TY1:.*]] @llvm.spv.wave.reduce.sum.v4f32([[TY1]] %[[#]]
37+
// CHECK-DXIL: %[[RET1:.*]] = call reassoc nnan ninf nsz arcp afn [[TY1:.*]] @llvm.dx.wave.reduce.sum.v4f32([[TY1]] %[[#]])
38+
// CHECK: ret [[TY1]] %[[RET1]]
39+
return WaveActiveSum(expr);
40+
}
41+
42+
// CHECK-DXIL: declare [[TY1]] @llvm.dx.wave.reduce.sum.v4f32([[TY1]]) #[[#attr]]
43+
// CHECK-SPIRV: declare spir_func [[TY1]] @llvm.spv.wave.reduce.sum.v4f32([[TY1]]) #[[#attr]]
44+
45+
// CHECK: attributes #[[#attr]] = {{{.*}} convergent {{.*}}}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify
2+
3+
int test_too_few_arg() {
4+
return __builtin_hlsl_wave_active_sum();
5+
// expected-error@-1 {{too few arguments to function call, expected 1, have 0}}
6+
}
7+
8+
float2 test_too_many_arg(float2 p0) {
9+
return __builtin_hlsl_wave_active_sum(p0, p0);
10+
// expected-error@-1 {{too many arguments to function call, expected 1, have 2}}
11+
}
12+
13+
bool test_expr_bool_type_check(bool p0) {
14+
return __builtin_hlsl_wave_active_sum(p0);
15+
// expected-error@-1 {{invalid operand of type 'bool'}}
16+
}
17+
18+
bool2 test_expr_bool_vec_type_check(bool2 p0) {
19+
return __builtin_hlsl_wave_active_sum(p0);
20+
// expected-error@-1 {{invalid operand of type 'bool2' (aka 'vector<bool, 2>')}}
21+
}
22+
23+
struct S { float f; };
24+
25+
S test_expr_struct_type_check(S p0) {
26+
return __builtin_hlsl_wave_active_sum(p0);
27+
// expected-error@-1 {{invalid operand of type 'S' where a scalar or vector is required}}
28+
}

llvm/include/llvm/IR/IntrinsicsDirectX.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ def int_dx_wave_active_countbits : DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i1
105105
def int_dx_wave_all : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_i1_ty], [IntrConvergent, IntrNoMem]>;
106106
def int_dx_wave_any : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_i1_ty], [IntrConvergent, IntrNoMem]>;
107107
def int_dx_wave_getlaneindex : DefaultAttrsIntrinsic<[llvm_i32_ty], [], [IntrConvergent, IntrNoMem]>;
108+
def int_dx_wave_reduce_sum : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
109+
def int_dx_wave_reduce_usum : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
108110
def int_dx_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], [IntrConvergent]>;
109111
def int_dx_wave_readlane : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>, llvm_i32_ty], [IntrConvergent, IntrNoMem]>;
110112
def int_dx_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_any_ty], [IntrNoMem]>;

llvm/include/llvm/IR/IntrinsicsSPIRV.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ let TargetPrefix = "spv" in {
9191
def int_spv_wave_active_countbits : DefaultAttrsIntrinsic<[llvm_i32_ty], [llvm_i1_ty], [IntrConvergent, IntrNoMem]>;
9292
def int_spv_wave_all : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_i1_ty], [IntrConvergent, IntrNoMem]>;
9393
def int_spv_wave_any : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_i1_ty], [IntrConvergent, IntrNoMem]>;
94+
def int_spv_wave_reduce_sum : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
9495
def int_spv_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], [IntrConvergent]>;
9596
def int_spv_wave_readlane : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>, llvm_i32_ty], [IntrConvergent, IntrNoMem]>;
9697
def int_spv_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_any_ty], [IntrNoMem]>;

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,14 @@ defvar BarrierMode_GroupMemoryBarrierWithGroupSync = 9;
303303
defvar BarrierMode_AllMemoryBarrier = 10;
304304
defvar BarrierMode_AllMemoryBarrierWithGroupSync = 11;
305305

306+
defvar WaveOpKind_Sum = 0;
307+
defvar WaveOpKind_Product = 1;
308+
defvar WaveOpKind_Min = 2;
309+
defvar WaveOpKind_Max = 3;
310+
311+
defvar SignedOpKind_Signed = 0;
312+
defvar SignedOpKind_Unsigned = 1;
313+
306314
// Intrinsic arg selection
307315
class IntrinArgSelectType;
308316
def IntrinArgSelect_Index : IntrinArgSelectType;
@@ -340,7 +348,7 @@ class IntrinArgI32 <int value> : IntrinArgSelect<IntrinArgSelect_I32, value>;
340348
// IntrinSelect<int_dx_wave_active_usum,
341349
// [ IntrinArgIndex<0>, IntrinArgI8<0>, IntrinArgI8<1> ]
342350
// >,
343-
// IntrinSelect<int_dx_wave_active_sum,
351+
// IntrinSelect<int_dx_wave_reduce_sum,
344352
// [ IntrinArgIndex<0>, IntrinArgI8<0>, IntrinArgI8<0> ]
345353
// >,
346354
// ]
@@ -991,6 +999,24 @@ def WaveActiveAnyTrue : DXILOp<113, waveAnyTrue> {
991999
let stages = [Stages<DXIL1_0, [all_stages]>];
9921000
}
9931001

1002+
def WaveActiveOp : DXILOp<119, waveActiveOp> {
1003+
let Doc = "returns the result of the operation across waves";
1004+
let intrinsics = [
1005+
IntrinSelect<
1006+
int_dx_wave_reduce_sum,
1007+
[ IntrinArgIndex<0>, IntrinArgI8<WaveOpKind_Sum>, IntrinArgI8<SignedOpKind_Signed> ]>,
1008+
IntrinSelect<
1009+
int_dx_wave_reduce_usum,
1010+
[ IntrinArgIndex<0>, IntrinArgI8<WaveOpKind_Sum>, IntrinArgI8<SignedOpKind_Unsigned> ]>,
1011+
];
1012+
1013+
let arguments = [OverloadTy, Int8Ty, Int8Ty];
1014+
let result = OverloadTy;
1015+
let overloads = [Overloads<DXIL1_0, [HalfTy, FloatTy, DoubleTy, Int16Ty, Int32Ty, Int64Ty]>];
1016+
let stages = [Stages<DXIL1_0, [all_stages]>];
1017+
let attributes = [Attributes<DXIL1_0, [ReadNone]>];
1018+
}
1019+
9941020
def WaveIsFirstLane : DXILOp<110, waveIsFirstLane> {
9951021
let Doc = "returns 1 for the first lane in the wave";
9961022
let intrinsics = [ IntrinSelect<int_dx_wave_is_first_lane> ];

0 commit comments

Comments
 (0)