Skip to content

Commit 594ed49

Browse files
KungFuDonkeyaokblast
authored andcommitted
[HLSL][DXIL][SPRIV] Added WaveActiveMin intrinsic (llvm#164385)
Adds the WaveActiveMin intrinsic from llvm#99169. I think I did all of the required things on the checklist: - [x] Implement `WaveActiveMin` clang builtin, - [x] Link `WaveActiveMin` clang builtin with `hlsl_intrinsics.h` - [x] Add sema checks for `WaveActiveMin` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp` - [x] Add codegen for `WaveActiveMin` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp` - [x] Add codegen tests to `clang/test/CodeGenHLSL/builtins/WaveActiveMin.hlsl` - [x] Add sema tests to `clang/test/SemaHLSL/BuiltIns/WaveActiveMin-errors.hlsl` - [x] Create the `int_dx_WaveActiveMin` intrinsic in `IntrinsicsDirectX.td` - [x] Create the `DXILOpMapping` of `int_dx_WaveActiveMin` to `119` in `DXIL.td` - [x] Create the `WaveActiveMin.ll` and `WaveActiveMin_errors.ll` tests in `llvm/test/CodeGen/DirectX/` - [x] Create the `int_spv_WaveActiveMin` intrinsic in `IntrinsicsSPIRV.td` - [x] In SPIRVInstructionSelector.cpp create the `WaveActiveMin` lowering and map it to `int_spv_WaveActiveMin` in `SPIRVInstructionSelector::selectIntrinsic`. - [x] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveMin.ll But as some of the code has changed and was moved around (E.G. `CGBuiltin.cpp` -> `CGHLSLBuiltins.cpp`) I mostly followed how `WaveActiveMax()` is implemented. I have not been able to run the tests myself as I am unsure which project runs the correct test. Any guidance on how I can test myself would be helpful. Also added some tests to the offload-test-suite llvm/offload-test-suite#478
1 parent 8bbcdae commit 594ed49

File tree

15 files changed

+505
-2
lines changed

15 files changed

+505
-2
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5030,6 +5030,12 @@ def HLSLWaveActiveMax : LangBuiltin<"HLSL_LANG"> {
50305030
let Prototype = "void (...)";
50315031
}
50325032

5033+
def HLSLWaveActiveMin : LangBuiltin<"HLSL_LANG"> {
5034+
let Spellings = ["__builtin_hlsl_wave_active_min"];
5035+
let Attributes = [NoThrow, Const];
5036+
let Prototype = "void (...)";
5037+
}
5038+
50335039
def HLSLWaveActiveSum : LangBuiltin<"HLSL_LANG"> {
50345040
let Spellings = ["__builtin_hlsl_wave_active_sum"];
50355041
let Attributes = [NoThrow, Const];

clang/lib/CodeGen/CGHLSLBuiltins.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static Intrinsic::ID getWaveActiveSumIntrinsic(llvm::Triple::ArchType Arch,
206206
}
207207
}
208208

209-
// Return wave active sum that corresponds to the QT scalar type
209+
// Return wave active max that corresponds to the QT scalar type
210210
static Intrinsic::ID getWaveActiveMaxIntrinsic(llvm::Triple::ArchType Arch,
211211
CGHLSLRuntime &RT, QualType QT) {
212212
switch (Arch) {
@@ -225,6 +225,25 @@ static Intrinsic::ID getWaveActiveMaxIntrinsic(llvm::Triple::ArchType Arch,
225225
}
226226
}
227227

228+
// Return wave active min that corresponds to the QT scalar type
229+
static Intrinsic::ID getWaveActiveMinIntrinsic(llvm::Triple::ArchType Arch,
230+
CGHLSLRuntime &RT, QualType QT) {
231+
switch (Arch) {
232+
case llvm::Triple::spirv:
233+
if (QT->isUnsignedIntegerType())
234+
return Intrinsic::spv_wave_reduce_umin;
235+
return Intrinsic::spv_wave_reduce_min;
236+
case llvm::Triple::dxil: {
237+
if (QT->isUnsignedIntegerType())
238+
return Intrinsic::dx_wave_reduce_umin;
239+
return Intrinsic::dx_wave_reduce_min;
240+
}
241+
default:
242+
llvm_unreachable("Intrinsic WaveActiveMin"
243+
" not supported by target architecture");
244+
}
245+
}
246+
228247
// Returns the mangled name for a builtin function that the SPIR-V backend
229248
// will expand into a spec Constant.
230249
static std::string getSpecConstantFunctionName(clang::QualType SpecConstantType,
@@ -742,6 +761,17 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
742761
&CGM.getModule(), IID, {OpExpr->getType()}),
743762
ArrayRef{OpExpr}, "hlsl.wave.active.max");
744763
}
764+
case Builtin::BI__builtin_hlsl_wave_active_min: {
765+
// Due to the use of variadic arguments, explicitly retreive argument
766+
Value *OpExpr = EmitScalarExpr(E->getArg(0));
767+
Intrinsic::ID IID = getWaveActiveMinIntrinsic(
768+
getTarget().getTriple().getArch(), CGM.getHLSLRuntime(),
769+
E->getArg(0)->getType());
770+
771+
return EmitRuntimeCall(Intrinsic::getOrInsertDeclaration(
772+
&CGM.getModule(), IID, {OpExpr->getType()}),
773+
ArrayRef{OpExpr}, "hlsl.wave.active.min");
774+
}
745775
case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
746776
// We don't define a SPIR-V intrinsic, instead it is a SPIR-V built-in
747777
// defined in SPIRVBuiltins.td. So instead we manually get the matching name

clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,6 +2597,129 @@ __attribute__((convergent)) double3 WaveActiveMax(double3);
25972597
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_max)
25982598
__attribute__((convergent)) double4 WaveActiveMax(double4);
25992599

2600+
//===----------------------------------------------------------------------===//
2601+
// WaveActiveMin builtins
2602+
//===----------------------------------------------------------------------===//
2603+
2604+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2605+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2606+
__attribute__((convergent)) half WaveActiveMin(half);
2607+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2608+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2609+
__attribute__((convergent)) half2 WaveActiveMin(half2);
2610+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2611+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2612+
__attribute__((convergent)) half3 WaveActiveMin(half3);
2613+
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.0)
2614+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2615+
__attribute__((convergent)) half4 WaveActiveMin(half4);
2616+
2617+
#ifdef __HLSL_ENABLE_16_BIT
2618+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2619+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2620+
__attribute__((convergent)) int16_t WaveActiveMin(int16_t);
2621+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2622+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2623+
__attribute__((convergent)) int16_t2 WaveActiveMin(int16_t2);
2624+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2625+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2626+
__attribute__((convergent)) int16_t3 WaveActiveMin(int16_t3);
2627+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2628+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2629+
__attribute__((convergent)) int16_t4 WaveActiveMin(int16_t4);
2630+
2631+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2632+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2633+
__attribute__((convergent)) uint16_t WaveActiveMin(uint16_t);
2634+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2635+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2636+
__attribute__((convergent)) uint16_t2 WaveActiveMin(uint16_t2);
2637+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2638+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2639+
__attribute__((convergent)) uint16_t3 WaveActiveMin(uint16_t3);
2640+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2641+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2642+
__attribute__((convergent)) uint16_t4 WaveActiveMin(uint16_t4);
2643+
#endif
2644+
2645+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2646+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2647+
__attribute__((convergent)) int WaveActiveMin(int);
2648+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2649+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2650+
__attribute__((convergent)) int2 WaveActiveMin(int2);
2651+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2652+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2653+
__attribute__((convergent)) int3 WaveActiveMin(int3);
2654+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2655+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2656+
__attribute__((convergent)) int4 WaveActiveMin(int4);
2657+
2658+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2659+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2660+
__attribute__((convergent)) uint WaveActiveMin(uint);
2661+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2662+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2663+
__attribute__((convergent)) uint2 WaveActiveMin(uint2);
2664+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2665+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2666+
__attribute__((convergent)) uint3 WaveActiveMin(uint3);
2667+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2668+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2669+
__attribute__((convergent)) uint4 WaveActiveMin(uint4);
2670+
2671+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2672+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2673+
__attribute__((convergent)) int64_t WaveActiveMin(int64_t);
2674+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2675+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2676+
__attribute__((convergent)) int64_t2 WaveActiveMin(int64_t2);
2677+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2678+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2679+
__attribute__((convergent)) int64_t3 WaveActiveMin(int64_t3);
2680+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2681+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2682+
__attribute__((convergent)) int64_t4 WaveActiveMin(int64_t4);
2683+
2684+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2685+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2686+
__attribute__((convergent)) uint64_t WaveActiveMin(uint64_t);
2687+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2688+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2689+
__attribute__((convergent)) uint64_t2 WaveActiveMin(uint64_t2);
2690+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2691+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2692+
__attribute__((convergent)) uint64_t3 WaveActiveMin(uint64_t3);
2693+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2694+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2695+
__attribute__((convergent)) uint64_t4 WaveActiveMin(uint64_t4);
2696+
2697+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2698+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2699+
__attribute__((convergent)) float WaveActiveMin(float);
2700+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2701+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2702+
__attribute__((convergent)) float2 WaveActiveMin(float2);
2703+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2704+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2705+
__attribute__((convergent)) float3 WaveActiveMin(float3);
2706+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2707+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2708+
__attribute__((convergent)) float4 WaveActiveMin(float4);
2709+
2710+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2711+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2712+
__attribute__((convergent)) double WaveActiveMin(double);
2713+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2714+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2715+
__attribute__((convergent)) double2 WaveActiveMin(double2);
2716+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2717+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2718+
__attribute__((convergent)) double3 WaveActiveMin(double3);
2719+
_HLSL_AVAILABILITY(shadermodel, 6.0)
2720+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_min)
2721+
__attribute__((convergent)) double4 WaveActiveMin(double4);
2722+
26002723
//===----------------------------------------------------------------------===//
26012724
// WaveActiveSum builtins
26022725
//===----------------------------------------------------------------------===//

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,6 +3279,7 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
32793279
break;
32803280
}
32813281
case Builtin::BI__builtin_hlsl_wave_active_max:
3282+
case Builtin::BI__builtin_hlsl_wave_active_min:
32823283
case Builtin::BI__builtin_hlsl_wave_active_sum: {
32833284
if (SemaRef.checkArgCount(TheCall, 1))
32843285
return true;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.min.i32([[TY]] %[[#]])
13+
// CHECK-DXIL: %[[RET:.*]] = call [[TY:.*]] @llvm.dx.wave.reduce.min.i32([[TY]] %[[#]])
14+
// CHECK: ret [[TY]] %[[RET]]
15+
return WaveActiveMin(expr);
16+
}
17+
18+
// CHECK-DXIL: declare [[TY]] @llvm.dx.wave.reduce.min.i32([[TY]]) #[[#attr:]]
19+
// CHECK-SPIRV: declare [[TY]] @llvm.spv.wave.reduce.min.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.umin.i64([[TY]] %[[#]])
24+
// CHECK-DXIL: %[[RET:.*]] = call [[TY:.*]] @llvm.dx.wave.reduce.umin.i64([[TY]] %[[#]])
25+
// CHECK: ret [[TY]] %[[RET]]
26+
return WaveActiveMin(expr);
27+
}
28+
29+
// CHECK-DXIL: declare [[TY]] @llvm.dx.wave.reduce.umin.i64([[TY]]) #[[#attr:]]
30+
// CHECK-SPIRV: declare [[TY]] @llvm.spv.wave.reduce.umin.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.min.v4f32([[TY1]] %[[#]]
37+
// CHECK-DXIL: %[[RET1:.*]] = call reassoc nnan ninf nsz arcp afn [[TY1:.*]] @llvm.dx.wave.reduce.min.v4f32([[TY1]] %[[#]])
38+
// CHECK: ret [[TY1]] %[[RET1]]
39+
return WaveActiveMin(expr);
40+
}
41+
42+
// CHECK-DXIL: declare [[TY1]] @llvm.dx.wave.reduce.min.v4f32([[TY1]]) #[[#attr]]
43+
// CHECK-SPIRV: declare [[TY1]] @llvm.spv.wave.reduce.min.v4f32([[TY1]]) #[[#attr]]
44+
45+
// CHECK: attributes #[[#attr]] = {{{.*}} convergent {{.*}}}
46+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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_min();
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_min(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_min(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_min(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_min(p0);
27+
// expected-error@-1 {{invalid operand of type 'S' where a scalar or vector is required}}
28+
}
29+

llvm/include/llvm/IR/IntrinsicsDirectX.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def int_dx_wave_any : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_i1_ty], [IntrCon
153153
def int_dx_wave_getlaneindex : DefaultAttrsIntrinsic<[llvm_i32_ty], [], [IntrConvergent, IntrNoMem]>;
154154
def int_dx_wave_reduce_max : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
155155
def int_dx_wave_reduce_umax : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
156+
def int_dx_wave_reduce_min : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
157+
def int_dx_wave_reduce_umin : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
156158
def int_dx_wave_reduce_sum : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
157159
def int_dx_wave_reduce_usum : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
158160
def int_dx_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], [IntrConvergent]>;

llvm/include/llvm/IR/IntrinsicsSPIRV.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ def int_spv_rsqrt : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty]
122122
def int_spv_wave_any : DefaultAttrsIntrinsic<[llvm_i1_ty], [llvm_i1_ty], [IntrConvergent, IntrNoMem]>;
123123
def int_spv_wave_reduce_umax : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
124124
def int_spv_wave_reduce_max : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
125+
def int_spv_wave_reduce_min : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
126+
def int_spv_wave_reduce_umin : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
125127
def int_spv_wave_reduce_sum : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
126128
def int_spv_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], [IntrConvergent]>;
127129
def int_spv_wave_readlane : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>, llvm_i32_ty], [IntrConvergent, IntrNoMem]>;
@@ -136,7 +138,7 @@ def int_spv_rsqrt : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty]
136138
def int_spv_sclamp : DefaultAttrsIntrinsic<[llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>], [IntrNoMem]>;
137139
def int_spv_nclamp : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>, LLVMMatchType<0>, LLVMMatchType<0>], [IntrNoMem]>;
138140

139-
// Create resource handle given the binding information. Returns a
141+
// Create resource handle given the binding information. Returns a
140142
// type appropriate for the kind of resource given the set id, binding id,
141143
// array size of the binding, as well as an index and an indicator
142144
// whether that index may be non-uniform.

llvm/lib/Target/DirectX/DXIL.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,16 @@ def WaveActiveOp : DXILOp<119, waveActiveOp> {
10581058
IntrinArgIndex<0>, IntrinArgI8<WaveOpKind_Max>,
10591059
IntrinArgI8<SignedOpKind_Unsigned>
10601060
]>,
1061+
IntrinSelect<int_dx_wave_reduce_min,
1062+
[
1063+
IntrinArgIndex<0>, IntrinArgI8<WaveOpKind_Min>,
1064+
IntrinArgI8<SignedOpKind_Signed>
1065+
]>,
1066+
IntrinSelect<int_dx_wave_reduce_umin,
1067+
[
1068+
IntrinArgIndex<0>, IntrinArgI8<WaveOpKind_Min>,
1069+
IntrinArgI8<SignedOpKind_Unsigned>
1070+
]>,
10611071
];
10621072

10631073
let arguments = [OverloadTy, Int8Ty, Int8Ty];

llvm/lib/Target/DirectX/DXILShaderFlags.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ static bool checkWaveOps(Intrinsic::ID IID) {
9494
case Intrinsic::dx_wave_reduce_usum:
9595
case Intrinsic::dx_wave_reduce_max:
9696
case Intrinsic::dx_wave_reduce_umax:
97+
case Intrinsic::dx_wave_reduce_min:
98+
case Intrinsic::dx_wave_reduce_umin:
9799
return true;
98100
}
99101
}

0 commit comments

Comments
 (0)