Skip to content

Commit cb507cc

Browse files
committed
[HLSL][SPIRV][DXIL] Implement WaveActiveSum intrinsic
- 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 passes
1 parent 9a5b3a1 commit cb507cc

File tree

14 files changed

+495
-0
lines changed

14 files changed

+495
-0
lines changed

clang/include/clang/Basic/Builtins.td

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

4753+
def HLSLWaveActiveSum : LangBuiltin<"HLSL_LANG"> {
4754+
let Spellings = ["__builtin_hlsl_wave_active_sum"];
4755+
let Attributes = [NoThrow, Const];
4756+
let Prototype = "void (...)";
4757+
}
4758+
47534759
def HLSLWaveGetLaneIndex : LangBuiltin<"HLSL_LANG"> {
47544760
let Spellings = ["__builtin_hlsl_wave_get_lane_index"];
47554761
let Attributes = [NoThrow, Const];

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9236,6 +9236,9 @@ def err_typecheck_expect_scalar_or_vector : Error<
92369236
"a vector of such type is required">;
92379237
def err_typecheck_expect_any_scalar_or_vector : Error<
92389238
"invalid operand of type %0 where a scalar or vector is required">;
9239+
def err_typecheck_expect_scalar_or_vector_not_type : Error<
9240+
"invalid operand of type %0 where %1 or "
9241+
"a vector of such type is not allowed">;
92399242
def err_typecheck_expect_flt_or_vector : Error<
92409243
"invalid operand of type %0 where floating, complex or "
92419244
"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
@@ -18715,6 +18715,23 @@ static Intrinsic::ID getDotProductIntrinsic(CGHLSLRuntime &RT, QualType QT) {
1871518715
return RT.getUDotIntrinsic();
1871618716
}
1871718717

18718+
// Return wave active sum that corresponds to the QT scalar type
18719+
static Intrinsic::ID getWaveActiveSumIntrinsic(llvm::Triple::ArchType Arch,
18720+
CGHLSLRuntime &RT, QualType QT) {
18721+
switch (Arch) {
18722+
case llvm::Triple::spirv:
18723+
return llvm::Intrinsic::spv_wave_active_sum;
18724+
case llvm::Triple::dxil: {
18725+
if (QT->isUnsignedIntegerType())
18726+
return llvm::Intrinsic::dx_wave_active_usum;
18727+
return llvm::Intrinsic::dx_wave_active_sum;
18728+
}
18729+
default:
18730+
llvm_unreachable("Intrinsic WaveActiveSum"
18731+
" not supported by target architecture");
18732+
}
18733+
}
18734+
1871818735
Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
1871918736
const CallExpr *E,
1872018737
ReturnValueSlot ReturnValue) {
@@ -18960,6 +18977,23 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1896018977
/*ReturnType=*/Op0->getType(), CGM.getHLSLRuntime().getStepIntrinsic(),
1896118978
ArrayRef<Value *>{Op0, Op1}, nullptr, "hlsl.step");
1896218979
}
18980+
case Builtin::BI__builtin_hlsl_wave_active_sum: {
18981+
// Due to the use of variadic arguments, explicitly retreive argument
18982+
Value *OpExpr = EmitScalarExpr(E->getArg(0));
18983+
llvm::FunctionType *FT = llvm::FunctionType::get(
18984+
OpExpr->getType(), ArrayRef{OpExpr->getType()}, false);
18985+
Intrinsic::ID IID = getWaveActiveSumIntrinsic(
18986+
getTarget().getTriple().getArch(), CGM.getHLSLRuntime(),
18987+
E->getArg(0)->getType());
18988+
18989+
// Get overloaded name
18990+
std::string Name =
18991+
Intrinsic::getName(IID, ArrayRef{OpExpr->getType()}, &CGM.getModule());
18992+
return EmitRuntimeCall(CGM.CreateRuntimeFunction(FT, Name, {},
18993+
/*Local=*/false,
18994+
/*AssumeConvergent=*/true),
18995+
ArrayRef{OpExpr}, "hlsl.wave.active.sum");
18996+
}
1896318997
case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
1896418998
// We don't define a SPIR-V intrinsic, instead it is a SPIR-V built-in
1896518999
// 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
@@ -2217,6 +2217,105 @@ __attribute__((convergent)) double3 WaveReadLaneAt(double3, int32_t);
22172217
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_read_lane_at)
22182218
__attribute__((convergent)) double4 WaveReadLaneAt(double4, int32_t);
22192219

2220+
//===----------------------------------------------------------------------===//
2221+
// WaveActiveSum builtins
2222+
//===----------------------------------------------------------------------===//
2223+
2224+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2225+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2226+
__attribute((convergent)) half WaveActiveSum(half);
2227+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2228+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2229+
__attribute((convergent)) half2 WaveActiveSum(half2);
2230+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2231+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2232+
__attribute((convergent)) half3 WaveActiveSum(half3);
2233+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2234+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2235+
__attribute((convergent)) half4 WaveActiveSum(half4);
2236+
2237+
#ifdef __HLSL_ENABLE_16_BIT
2238+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2239+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2240+
__attribute((convergent)) int16_t WaveActiveSum(int16_t);
2241+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2242+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2243+
__attribute((convergent)) int16_t2 WaveActiveSum(int16_t2);
2244+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2245+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2246+
__attribute((convergent)) int16_t3 WaveActiveSum(int16_t3);
2247+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2248+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2249+
__attribute((convergent)) int16_t4 WaveActiveSum(int16_t4);
2250+
2251+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2252+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2253+
__attribute((convergent)) uint16_t WaveActiveSum(uint16_t);
2254+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2255+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2256+
__attribute((convergent)) uint16_t2 WaveActiveSum(uint16_t2);
2257+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2258+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2259+
__attribute((convergent)) uint16_t3 WaveActiveSum(uint16_t3);
2260+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2261+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2262+
__attribute((convergent)) uint16_t4 WaveActiveSum(uint16_t4);
2263+
#endif
2264+
2265+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2266+
__attribute((convergent)) int WaveActiveSum(int);
2267+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2268+
__attribute((convergent)) int2 WaveActiveSum(int2);
2269+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2270+
__attribute((convergent)) int3 WaveActiveSum(int3);
2271+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2272+
__attribute((convergent)) int4 WaveActiveSum(int4);
2273+
2274+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2275+
__attribute((convergent)) uint WaveActiveSum(uint);
2276+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2277+
__attribute((convergent)) uint2 WaveActiveSum(uint2);
2278+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2279+
__attribute((convergent)) uint3 WaveActiveSum(uint3);
2280+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2281+
__attribute((convergent)) uint4 WaveActiveSum(uint4);
2282+
2283+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2284+
__attribute((convergent)) int64_t WaveActiveSum(int64_t);
2285+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2286+
__attribute((convergent)) int64_t2 WaveActiveSum(int64_t2);
2287+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2288+
__attribute((convergent)) int64_t3 WaveActiveSum(int64_t3);
2289+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2290+
__attribute((convergent)) int64_t4 WaveActiveSum(int64_t4);
2291+
2292+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2293+
__attribute((convergent)) uint64_t WaveActiveSum(uint64_t);
2294+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2295+
__attribute((convergent)) uint64_t2 WaveActiveSum(uint64_t2);
2296+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2297+
__attribute((convergent)) uint64_t3 WaveActiveSum(uint64_t3);
2298+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2299+
__attribute((convergent)) uint64_t4 WaveActiveSum(uint64_t4);
2300+
2301+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2302+
__attribute((convergent)) float WaveActiveSum(float);
2303+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2304+
__attribute((convergent)) float2 WaveActiveSum(float2);
2305+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2306+
__attribute((convergent)) float3 WaveActiveSum(float3);
2307+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2308+
__attribute((convergent)) float4 WaveActiveSum(float4);
2309+
2310+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2311+
__attribute((convergent)) double WaveActiveSum(double);
2312+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2313+
__attribute((convergent)) double2 WaveActiveSum(double2);
2314+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2315+
__attribute((convergent)) double3 WaveActiveSum(double3);
2316+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_sum)
2317+
__attribute((convergent)) double4 WaveActiveSum(double4);
2318+
22202319
//===----------------------------------------------------------------------===//
22212320
// sign builtins
22222321
//===----------------------------------------------------------------------===//

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,23 @@ static bool CheckAnyScalarOrVector(Sema *S, CallExpr *TheCall,
18241824
return false;
18251825
}
18261826

1827+
static bool CheckNotScalarType(Sema *S, CallExpr *TheCall, QualType Scalar,
1828+
unsigned ArgIndex) {
1829+
assert(TheCall->getNumArgs() >= ArgIndex);
1830+
QualType ArgType = TheCall->getArg(ArgIndex)->getType();
1831+
auto *VTy = ArgType->getAs<VectorType>();
1832+
// is the scalar or vector<scalar>
1833+
if (S->Context.hasSameUnqualifiedType(ArgType, Scalar) ||
1834+
(VTy &&
1835+
S->Context.hasSameUnqualifiedType(VTy->getElementType(), Scalar))) {
1836+
S->Diag(TheCall->getArg(0)->getBeginLoc(),
1837+
diag::err_typecheck_expect_scalar_or_vector_not_type)
1838+
<< ArgType << Scalar;
1839+
return true;
1840+
}
1841+
return false;
1842+
}
1843+
18271844
static bool CheckBoolSelect(Sema *S, CallExpr *TheCall) {
18281845
assert(TheCall->getNumArgs() == 3);
18291846
Expr *Arg1 = TheCall->getArg(1);
@@ -2059,6 +2076,20 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
20592076
TheCall->setType(ArgTyA);
20602077
break;
20612078
}
2079+
case Builtin::BI__builtin_hlsl_wave_active_sum: {
2080+
if (SemaRef.checkArgCount(TheCall, 1))
2081+
return true;
2082+
2083+
// Ensure input expr type is a scalar/vector and the same as the return type
2084+
if (CheckAnyScalarOrVector(&SemaRef, TheCall, 0))
2085+
return true;
2086+
if (CheckNotScalarType(&SemaRef, TheCall, getASTContext().BoolTy, 0))
2087+
return true;
2088+
ExprResult Expr = TheCall->getArg(0);
2089+
QualType ArgTyExpr = Expr.get()->getType();
2090+
TheCall->setType(ArgTyExpr);
2091+
break;
2092+
}
20622093
// Note these are llvm builtins that we want to catch invalid intrinsic
20632094
// generation. Normal handling of these builitns will occur elsewhere.
20642095
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.active.sum.i32([[TY]] %[[#]])
13+
// CHECK-DXIL: %[[RET:.*]] = call [[TY:.*]] @llvm.dx.wave.active.sum.i32([[TY]] %[[#]])
14+
// CHECK: ret [[TY]] %[[RET]]
15+
return WaveActiveSum(expr);
16+
}
17+
18+
// CHECK-DXIL: declare [[TY]] @llvm.dx.wave.active.sum.i32([[TY]]) #[[#attr:]]
19+
// CHECK-SPIRV: declare spir_func [[TY]] @llvm.spv.wave.active.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.active.sum.i64([[TY]] %[[#]])
24+
// CHECK-DXIL: %[[RET:.*]] = call [[TY:.*]] @llvm.dx.wave.active.usum.i64([[TY]] %[[#]])
25+
// CHECK: ret [[TY]] %[[RET]]
26+
return WaveActiveSum(expr);
27+
}
28+
29+
// CHECK-DXIL: declare [[TY]] @llvm.dx.wave.active.usum.i64([[TY]]) #[[#attr:]]
30+
// CHECK-SPIRV: declare spir_func [[TY]] @llvm.spv.wave.active.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 spir_func [[TY1:.*]] @llvm.spv.wave.active.sum.v4f32([[TY1]] %[[#]]
37+
// CHECK-DXIL: %[[RET1:.*]] = call [[TY1:.*]] @llvm.dx.wave.active.sum.v4f32([[TY1]] %[[#]])
38+
// CHECK: ret [[TY1]] %[[RET1]]
39+
return WaveActiveSum(expr);
40+
}
41+
42+
// CHECK-DXIL: declare [[TY1]] @llvm.dx.wave.active.sum.v4f32([[TY1]]) #[[#attr]]
43+
// CHECK-SPIRV: declare spir_func [[TY1]] @llvm.spv.wave.active.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' where 'bool' or a vector of such type is not allowed}}
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>') where 'bool' or a vector of such type is not allowed}}
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
@@ -85,6 +85,8 @@ def int_dx_umad : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>, LLV
8585
def int_dx_normalize : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty], [IntrNoMem]>;
8686
def int_dx_rsqrt : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem]>;
8787
def int_dx_wave_getlaneindex : DefaultAttrsIntrinsic<[llvm_i32_ty], [], [IntrConvergent, IntrNoMem]>;
88+
def int_dx_wave_active_sum : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
89+
def int_dx_wave_active_usum : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
8890
def int_dx_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], [IntrConvergent]>;
8991
def int_dx_wave_readlane : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>, llvm_i32_ty], [IntrConvergent, IntrNoMem]>;
9092
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
@@ -83,6 +83,7 @@ let TargetPrefix = "spv" in {
8383
DefaultAttrsIntrinsic<[LLVMVectorElementType<0>],
8484
[llvm_anyint_ty, LLVMScalarOrSameVectorWidth<0, LLVMVectorElementType<0>>],
8585
[IntrNoMem, Commutative] >;
86+
def int_spv_wave_active_sum : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
8687
def int_spv_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], [IntrConvergent]>;
8788
def int_spv_wave_readlane : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>, llvm_i32_ty], [IntrConvergent, IntrNoMem]>;
8889
def int_spv_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_any_ty], [IntrNoMem]>;

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,18 @@ defset list<DXILConstant> BarrierModes = {
307307
def BarrierMode_AllMemoryBarrierWithGroupSync : DXILConstant<11>;
308308
}
309309

310+
defset list<DXILConstant> WaveOpKind = {
311+
def WaveOpKind_Sum : DXILConstant<0>;
312+
def WaveOpKind_Product : DXILConstant<1>;
313+
def WaveOpKind_Min : DXILConstant<2>;
314+
def WaveOpKind_Max : DXILConstant<3>;
315+
}
316+
317+
defset list<DXILConstant> SignedOpKind = {
318+
def SignedOpKind_Signed : DXILConstant<0>;
319+
def SignedOpKind_Unsigned : DXILConstant<1>;
320+
}
321+
310322
// Intrinsic arg selection
311323
class Arg {
312324
int index = -1;
@@ -842,6 +854,24 @@ def CreateHandleFromBinding : DXILOp<218, createHandleFromBinding> {
842854
let stages = [Stages<DXIL1_6, [all_stages]>];
843855
}
844856

857+
def WaveActiveOp : DXILOp<119, waveActiveOp> {
858+
let Doc = "returns the result of the operation across waves";
859+
let intrinsic_selects = [
860+
IntrinsicSelect<
861+
int_dx_wave_active_sum,
862+
[ ArgSelect<0>, ArgI8<WaveOpKind_Sum>, ArgI8<SignedOpKind_Signed> ]>,
863+
IntrinsicSelect<
864+
int_dx_wave_active_usum,
865+
[ ArgSelect<0>, ArgI8<WaveOpKind_Sum>, ArgI8<SignedOpKind_Unsigned> ]>,
866+
];
867+
868+
let arguments = [OverloadTy, Int8Ty, Int8Ty];
869+
let result = OverloadTy;
870+
let overloads = [Overloads<DXIL1_0, [HalfTy, FloatTy, DoubleTy, Int16Ty, Int32Ty, Int64Ty]>];
871+
let stages = [Stages<DXIL1_0, [all_stages]>];
872+
let attributes = [Attributes<DXIL1_0, [ReadNone]>];
873+
}
874+
845875
def WaveIsFirstLane : DXILOp<110, waveIsFirstLane> {
846876
let Doc = "returns 1 for the first lane in the wave";
847877
let LLVMIntrinsic = int_dx_wave_is_first_lane;

llvm/lib/Target/DirectX/DirectXTargetTransformInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ bool DirectXTTIImpl::isTargetIntrinsicTriviallyScalarizable(
3030
switch (ID) {
3131
case Intrinsic::dx_frac:
3232
case Intrinsic::dx_rsqrt:
33+
case Intrinsic::dx_wave_active_sum:
34+
case Intrinsic::dx_wave_active_usum:
3335
case Intrinsic::dx_wave_readlane:
3436
case Intrinsic::dx_splitdouble:
3537
return true;

0 commit comments

Comments
 (0)