https://github.com/bob80905 updated https://github.com/llvm/llvm-project/pull/240645
>From 76027fba1b5e048f1f64bca3ec9c890e37d21948 Mon Sep 17 00:00:00 2001 From: Joshua Batista <[email protected]> Date: Mon, 9 Nov 2026 16:45:24 -0800 Subject: [PATCH 1/9] first attempt Co-authored-by: Copilot <[email protected]> Copilot-Session: 365638e8-2291-4925-8f1e-1b5c23220818 --- clang/include/clang/Basic/HLSLIntrinsics.td | 2 +- clang/test/CodeGenHLSL/builtins/QuadAll.hlsl | 3 ++ .../BuiltIns/QuadAll-availability.hlsl | 10 +++--- llvm/docs/SPIRVUsage.md | 2 ++ .../Target/DirectX/DXILIntrinsicExpansion.cpp | 24 +++++++++++++ .../Target/SPIRV/SPIRVInstructionSelector.cpp | 32 +++++++++++++---- .../test/CodeGen/DirectX/QuadAll-expansion.ll | 36 +++++++++++++++++++ llvm/test/CodeGen/DirectX/QuadAll.ll | 21 +++++++++++ .../quad-all.ll | 22 +++++++++--- .../CodeGen/SPIRV/hlsl-intrinsics/QuadAll.ll | 35 ++++++++++++++++-- 10 files changed, 168 insertions(+), 19 deletions(-) create mode 100644 llvm/test/CodeGen/DirectX/QuadAll-expansion.ll diff --git a/clang/include/clang/Basic/HLSLIntrinsics.td b/clang/include/clang/Basic/HLSLIntrinsics.td index d0500838a81f7..dcabb5a6c05d0 100644 --- a/clang/include/clang/Basic/HLSLIntrinsics.td +++ b/clang/include/clang/Basic/HLSLIntrinsics.td @@ -1405,7 +1405,7 @@ def hlsl_quad_all : HLSLBuiltin<"QuadAll", "__builtin_hlsl_quad_all"> { let Args = [BoolTy]; let ReturnType = BoolTy; let IsConvergent = 1; - let Availability = SM6_7; + let Availability = SM6_0; } // Reads the value from the lane across the X axis of the quad. diff --git a/clang/test/CodeGenHLSL/builtins/QuadAll.hlsl b/clang/test/CodeGenHLSL/builtins/QuadAll.hlsl index 986178e8d9ab1..864c2ededec3c 100644 --- a/clang/test/CodeGenHLSL/builtins/QuadAll.hlsl +++ b/clang/test/CodeGenHLSL/builtins/QuadAll.hlsl @@ -2,6 +2,9 @@ // RUN: dxil-pc-shadermodel6.7-library %s -emit-llvm \ // RUN: -disable-llvm-passes -o - | FileCheck %s --check-prefixes=CHECK,DXIL // RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: dxil-pc-shadermodel6.0-library %s -emit-llvm \ +// RUN: -disable-llvm-passes -o - | FileCheck %s --check-prefixes=CHECK,DXIL +// RUN: %clang_cc1 -finclude-default-header -triple \ // RUN: spirv-pc-vulkan-library %s -emit-llvm -disable-llvm-passes -o - | \ // RUN: FileCheck %s --check-prefixes=CHECK,SPIRV diff --git a/clang/test/SemaHLSL/BuiltIns/QuadAll-availability.hlsl b/clang/test/SemaHLSL/BuiltIns/QuadAll-availability.hlsl index c6b3bea64e760..6617fecf40280 100644 --- a/clang/test/SemaHLSL/BuiltIns/QuadAll-availability.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/QuadAll-availability.hlsl @@ -1,13 +1,15 @@ // RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: dxil-pc-shadermodel6.0-library %s -fhlsl-strict-availability \ +// RUN: -fsyntax-only -verify +// RUN: %clang_cc1 -finclude-default-header -triple \ // RUN: dxil-pc-shadermodel6.6-library %s -fhlsl-strict-availability \ -// RUN: -fsyntax-only -verify -verify-ignore-unexpected=note +// RUN: -fsyntax-only -verify // RUN: %clang_cc1 -finclude-default-header -triple \ // RUN: dxil-pc-shadermodel6.7-library %s -fhlsl-strict-availability \ -// RUN: -fsyntax-only -verify=sm67 +// RUN: -fsyntax-only -verify -// sm67-no-diagnostics +// expected-no-diagnostics bool test_availability(bool cond) { - // expected-error@+1 {{'QuadAll' is only available on Shader Model 6.7}} return QuadAll(cond); } diff --git a/llvm/docs/SPIRVUsage.md b/llvm/docs/SPIRVUsage.md index 2cfe73bf398d9..16e4cb48865f7 100644 --- a/llvm/docs/SPIRVUsage.md +++ b/llvm/docs/SPIRVUsage.md @@ -242,6 +242,8 @@ Below is a list of supported SPIR-V extensions, sorted alphabetically by their e - Adds the quad vote instruction for HLSL `QuadAll` and the `QuadDerivativesKHR` and `RequireFullQuadsKHR` execution modes. These features also require `SPV_KHR_maximal_reconvergence`. + Without `SPV_KHR_quad_control`, `QuadAll` uses quad-read emulation. + This path requires SPIR-V 1.3 but not maximal reconvergence. * - ``SPV_ALTERA_blocking_pipes`` - Adds new pipe read and write functions that have blocking semantics instead of the non-blocking semantics of the existing pipe read/write functions. * - ``SPV_ALTERA_arbitrary_precision_fixed_point`` diff --git a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp index 25bdd17b7f7bc..44892aead9161 100644 --- a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp +++ b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp @@ -242,6 +242,9 @@ static bool isIntrinsicExpansion(Function &F) { case Intrinsic::vector_reduce_or: return F.getParent()->getTargetTriple().getDXILVersion() < VersionTuple(1, 9); + case Intrinsic::dx_quad_all: + return F.getParent()->getTargetTriple().getDXILVersion() < + VersionTuple(1, 7); case Intrinsic::dx_fdot: return shouldExpandFloatDotIntrinsic(F); case Intrinsic::dx_resource_load_rawbuffer: @@ -1261,6 +1264,24 @@ static Value *expandLoadInput(CallInst *Orig) { return Vec; } +static Value *expandQuadAll(CallInst *Orig) { + IRBuilder<> Builder(Orig); + SmallVector<OperandBundleDef, 1> Bundles; + Orig->getOperandBundlesAsDefs(Bundles); + + Value *Cond = + Builder.CreateSExt(Orig->getArgOperand(0), Builder.getInt32Ty()); + Value *Result = Cond; + for (Intrinsic::ID ID : + {Intrinsic::dx_quad_read_across_x, Intrinsic::dx_quad_read_across_y, + Intrinsic::dx_quad_read_across_diagonal}) { + Value *QuadValue = Builder.CreateIntrinsic(ID, {Builder.getInt32Ty()}, Cond, + nullptr, "", Bundles); + Result = Builder.CreateAnd(Result, QuadValue); + } + return Builder.CreateTrunc(Result, Builder.getInt1Ty()); +} + static bool expandIntrinsic(Function &F, CallInst *Orig) { Value *Result = nullptr; Intrinsic::ID IntrinsicId = F.getIntrinsicID(); @@ -1327,6 +1348,9 @@ static bool expandIntrinsic(Function &F, CallInst *Orig) { case Intrinsic::dx_sign: Result = expandSignIntrinsic(Orig); break; + case Intrinsic::dx_quad_all: + Result = expandQuadAll(Orig); + break; case Intrinsic::dx_load_input: Result = expandLoadInput(Orig); break; diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp index 301bd5a486eb3..d109733892e7c 100644 --- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp @@ -329,6 +329,9 @@ class SPIRVInstructionSelector : public InstructionSelector { bool selectQuadSwap(Register ResVReg, SPIRVTypeInst ResType, MachineInstr &I, unsigned Direction) const; + bool selectQuadAll(Register ResVReg, SPIRVTypeInst ResType, + MachineInstr &I) const; + bool selectConst(Register ResVReg, SPIRVTypeInst ResType, MachineInstr &I) const; @@ -4110,6 +4113,28 @@ bool SPIRVInstructionSelector::selectQuadSwap(Register ResVReg, return true; } +bool SPIRVInstructionSelector::selectQuadAll(Register ResVReg, + SPIRVTypeInst ResType, + MachineInstr &I) const { + if (STI.canUseExtension(SPIRV::Extension::SPV_KHR_quad_control)) + return selectOpWithSrcs(ResVReg, ResType, I, {I.getOperand(2).getReg()}, + SPIRV::OpGroupNonUniformQuadAllKHR); + + Register Result = I.getOperand(2).getReg(); + for (unsigned Direction = 0; Direction != 3; ++Direction) { + Register QuadValue = createVirtualRegister(ResType, &GR, MRI, MRI->getMF()); + Register Next = + Direction == 2 ? ResVReg + : createVirtualRegister(ResType, &GR, MRI, MRI->getMF()); + if (!selectQuadSwap(QuadValue, ResType, I, Direction) || + !selectOpWithSrcs(Next, ResType, I, {Result, QuadValue}, + SPIRV::OpLogicalAnd)) + return false; + Result = Next; + } + return true; +} + bool SPIRVInstructionSelector::selectBitreverseViaI32(Register ResVReg, SPIRVTypeInst ResType, MachineInstr &I, @@ -5895,12 +5920,7 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg, case Intrinsic::spv_wave_prefix_product: return selectWaveExclusiveScanProduct(ResVReg, ResType, I); case Intrinsic::spv_quad_all: - BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpGroupNonUniformQuadAllKHR)) - .addDef(ResVReg) - .addUse(GR.getSPIRVTypeID(ResType)) - .addUse(I.getOperand(2).getReg()) - .constrainAllUses(TII, TRI, RBI); - return true; + return selectQuadAll(ResVReg, ResType, I); case Intrinsic::spv_quad_read_across_x: { return selectQuadSwap(ResVReg, ResType, I, /*Direction*/ 0); } diff --git a/llvm/test/CodeGen/DirectX/QuadAll-expansion.ll b/llvm/test/CodeGen/DirectX/QuadAll-expansion.ll new file mode 100644 index 0000000000000..75a9fe825de83 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/QuadAll-expansion.ll @@ -0,0 +1,36 @@ +; RUN: opt -S -dxil-intrinsic-expansion \ +; RUN: -mtriple=dxil-pc-shadermodel6.0-library %s \ +; RUN: | FileCheck %s --check-prefix=EMULATED \ +; RUN: --implicit-check-not=llvm.dx.quad.all +; RUN: opt -S -dxil-intrinsic-expansion \ +; RUN: -mtriple=dxil-pc-shadermodel6.6-library %s \ +; RUN: | FileCheck %s --check-prefix=EMULATED \ +; RUN: --implicit-check-not=llvm.dx.quad.all +; RUN: opt -S -dxil-intrinsic-expansion \ +; RUN: -mtriple=dxil-pc-shadermodel6.7-library %s \ +; RUN: | FileCheck %s --check-prefix=NATIVE \ +; RUN: --implicit-check-not=llvm.dx.quad.read + +; EMULATED-LABEL: define i1 @quad_all( +; EMULATED-NEXT: %[[TOKEN:.*]] = call token @llvm.experimental.convergence.entry() +; EMULATED-NEXT: %[[COND:.*]] = sext i1 %cond to i32 +; EMULATED-NEXT: %[[X:.*]] = call i32 @llvm.dx.quad.read.across.x.i32(i32 %[[COND]]) [ "convergencectrl"(token %[[TOKEN]]) ] +; EMULATED-NEXT: %[[ANDX:.*]] = and i32 %[[COND]], %[[X]] +; EMULATED-NEXT: %[[Y:.*]] = call i32 @llvm.dx.quad.read.across.y.i32(i32 %[[COND]]) [ "convergencectrl"(token %[[TOKEN]]) ] +; EMULATED-NEXT: %[[ANDY:.*]] = and i32 %[[ANDX]], %[[Y]] +; EMULATED-NEXT: %[[D:.*]] = call i32 @llvm.dx.quad.read.across.diagonal.i32(i32 %[[COND]]) [ "convergencectrl"(token %[[TOKEN]]) ] +; EMULATED-NEXT: %[[ANDD:.*]] = and i32 %[[ANDY]], %[[D]] +; EMULATED-NEXT: %[[RET:.*]] = trunc i32 %[[ANDD]] to i1 +; EMULATED-NEXT: ret i1 %[[RET]] + +; NATIVE-LABEL: define i1 @quad_all( +; NATIVE-NEXT: %[[TOKEN:.*]] = call token @llvm.experimental.convergence.entry() +; NATIVE-NEXT: %ret = call i1 @llvm.dx.quad.all(i1 %cond) [ "convergencectrl"(token %[[TOKEN]]) ] +; NATIVE-NEXT: ret i1 %ret +define i1 @quad_all(i1 %cond) convergent { + %tok = call token @llvm.experimental.convergence.entry() + %ret = call i1 @llvm.dx.quad.all(i1 %cond) [ "convergencectrl"(token %tok) ] + ret i1 %ret +} + +declare i1 @llvm.dx.quad.all(i1) convergent diff --git a/llvm/test/CodeGen/DirectX/QuadAll.ll b/llvm/test/CodeGen/DirectX/QuadAll.ll index 383de1135adab..a3da4f6919dae 100644 --- a/llvm/test/CodeGen/DirectX/QuadAll.ll +++ b/llvm/test/CodeGen/DirectX/QuadAll.ll @@ -8,10 +8,31 @@ ; RUN: | FileCheck %s ; RUN: opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.7-mesh %s \ ; RUN: | FileCheck %s +; RUN: opt -S -dxil-intrinsic-expansion -dxil-op-lower \ +; RUN: -mtriple=dxil-pc-shadermodel6.0-library %s \ +; RUN: | FileCheck %s --check-prefix=EMULATED --implicit-check-not=quadVote +; RUN: opt -S -dxil-intrinsic-expansion -dxil-op-lower \ +; RUN: -mtriple=dxil-pc-shadermodel6.6-compute %s \ +; RUN: | FileCheck %s --check-prefix=EMULATED --implicit-check-not=quadVote +; RUN: opt -S -dxil-intrinsic-expansion -dxil-op-lower \ +; RUN: -mtriple=dxil-pc-shadermodel6.6-pixel %s \ +; RUN: | FileCheck %s --check-prefix=EMULATED --implicit-check-not=quadVote +; RUN: opt -S -dxil-intrinsic-expansion -dxil-op-lower \ +; RUN: -mtriple=dxil-pc-shadermodel6.7-library %s | FileCheck %s ; CHECK-LABEL: define i1 @quad_all( ; CHECK: %[[RET:.*]] = call i1 @dx.op.quadVote.i1(i32 222, i1 %cond, i8 1) ; CHECK-NEXT: ret i1 %[[RET]] +; EMULATED-LABEL: define i1 @quad_all( +; EMULATED-NEXT: %[[COND:.*]] = sext i1 %cond to i32 +; EMULATED-NEXT: %[[X:.*]] = call i32 @dx.op.quadOp.i32(i32 123, i32 %[[COND]], i8 0) +; EMULATED-NEXT: %[[ANDX:.*]] = and i32 %[[COND]], %[[X]] +; EMULATED-NEXT: %[[Y:.*]] = call i32 @dx.op.quadOp.i32(i32 123, i32 %[[COND]], i8 1) +; EMULATED-NEXT: %[[ANDY:.*]] = and i32 %[[ANDX]], %[[Y]] +; EMULATED-NEXT: %[[D:.*]] = call i32 @dx.op.quadOp.i32(i32 123, i32 %[[COND]], i8 2) +; EMULATED-NEXT: %[[ANDD:.*]] = and i32 %[[ANDY]], %[[D]] +; EMULATED-NEXT: %[[RET:.*]] = trunc i32 %[[ANDD]] to i1 +; EMULATED-NEXT: ret i1 %[[RET]] define i1 @quad_all(i1 %cond) { %ret = call i1 @llvm.dx.quad.all(i1 %cond) ret i1 %ret diff --git a/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_compute_shader_derivatives/quad-all.ll b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_compute_shader_derivatives/quad-all.ll index e62c3d2af0755..549c4ea0ac126 100644 --- a/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_compute_shader_derivatives/quad-all.ll +++ b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_compute_shader_derivatives/quad-all.ll @@ -4,17 +4,27 @@ ; RUN: llc -O0 -verify-machineinstrs \ ; RUN: -mtriple=spirv1.5-unknown-vulkan-compute \ ; RUN: --spirv-ext=%{deriv-ext},%{quad-exts} \ -; RUN: %s -o - | FileCheck %s +; RUN: %s -o - | FileCheck %s --check-prefixes=CHECK,NATIVE +; RUN: llc -O0 -verify-machineinstrs \ +; RUN: -mtriple=spirv1.5-unknown-vulkan-compute \ +; RUN: --spirv-ext=%{deriv-ext},-SPV_KHR_quad_control \ +; RUN: %s -o - | FileCheck %s --check-prefixes=CHECK,EMULATED \ +; RUN: --implicit-check-not=SPV_KHR_quad_control \ +; RUN: --implicit-check-not=SPV_KHR_maximal_reconvergence ; RUN: %if spirv-tools %{ llc -O0 \ ; RUN: -mtriple=spirv1.5-unknown-vulkan-compute \ ; RUN: --spirv-ext=%{deriv-ext},%{quad-exts} \ ; RUN: %s -o - -filetype=obj | spirv-val --target-env vulkan1.2 %} +; RUN: %if spirv-tools %{ llc -O0 \ +; RUN: -mtriple=spirv1.5-unknown-vulkan-compute \ +; RUN: --spirv-ext=%{deriv-ext},-SPV_KHR_quad_control \ +; RUN: %s -o - -filetype=obj | spirv-val --target-env vulkan1.2 %} ; CHECK-DAG: OpCapability ComputeDerivativeGroupQuadsKHR -; CHECK-DAG: OpCapability QuadControlKHR +; NATIVE-DAG: OpCapability QuadControlKHR ; CHECK-DAG: OpExtension "SPV_KHR_compute_shader_derivatives" -; CHECK-DAG: OpExtension "SPV_KHR_quad_control" -; CHECK-DAG: OpExtension "SPV_KHR_maximal_reconvergence" +; NATIVE-DAG: OpExtension "SPV_KHR_quad_control" +; NATIVE-DAG: OpExtension "SPV_KHR_maximal_reconvergence" ; CHECK: OpEntryPoint GLCompute %[[#MAIN:]] "main" ; CHECK-DAG: OpExecutionMode %[[#MAIN]] DerivativeGroupQuadsKHR ; CHECK-DAG: OpExecutionMode %[[#MAIN]] LocalSize 2 2 1 @@ -22,7 +32,9 @@ ; CHECK-DAG: %[[#TRUE:]] = OpConstantTrue %[[#BOOL]] ; CHECK: %[[#MAIN]] = OpFunction -; CHECK: %[[#ALL:]] = OpGroupNonUniformQuadAllKHR %[[#BOOL]] %[[#TRUE]] +; NATIVE: %[[#ALL:]] = OpGroupNonUniformQuadAllKHR %[[#BOOL]] %[[#TRUE]] +; EMULATED-COUNT-3: OpGroupNonUniformQuadSwap %[[#BOOL]] %{{[0-9]+}} %[[#TRUE]] +; EMULATED-NEXT: %[[#ALL:]] = OpLogicalAnd %[[#BOOL]] ; CHECK: %[[#VALUE:]] = OpSelect %{{[0-9]+}} %[[#ALL]] ; CHECK: OpStore %{{[0-9]+}} %[[#VALUE]] Volatile define void @main() #0 { diff --git a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/QuadAll.ll b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/QuadAll.ll index 10e8faad8cb0f..58f2a33c8bf94 100644 --- a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/QuadAll.ll +++ b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/QuadAll.ll @@ -1,8 +1,17 @@ ; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv1.5-unknown-vulkan-library \ ; RUN: --spirv-ext=+SPV_KHR_quad_control,+SPV_KHR_maximal_reconvergence \ ; RUN: %s -o - | FileCheck %s -; RUN: not llc -O0 -mtriple=spirv1.5-unknown-vulkan-library \ -; RUN: %s -o - 2>&1 | FileCheck %s --check-prefix=NO-EXT +; RUN: llc -O0 -verify-machineinstrs \ +; RUN: -mtriple=spirv32v1.3-unknown-vulkan-library %s -o - \ +; RUN: | FileCheck %s --check-prefix=EMULATED \ +; RUN: --implicit-check-not=OpGroupNonUniformQuadAllKHR \ +; RUN: --implicit-check-not=OpExtension +; RUN: llc -O0 -verify-machineinstrs \ +; RUN: -mtriple=spirv1.5-unknown-vulkan-library \ +; RUN: --spirv-ext=-SPV_KHR_quad_control,-SPV_KHR_maximal_reconvergence \ +; RUN: %s -o - | FileCheck %s --check-prefix=EMULATED \ +; RUN: --implicit-check-not=OpGroupNonUniformQuadAllKHR \ +; RUN: --implicit-check-not=OpExtension ; RUN: not llc -O0 -mtriple=spirv1.5-unknown-vulkan-library \ ; RUN: --spirv-ext=+SPV_KHR_quad_control,-SPV_KHR_maximal_reconvergence \ ; RUN: %s -o - 2>&1 | FileCheck %s --check-prefix=NO-RECONVERGENCE @@ -13,8 +22,10 @@ ; RUN: -mtriple=spirv1.5-unknown-vulkan-library \ ; RUN: --spirv-ext=+SPV_KHR_quad_control,+SPV_KHR_maximal_reconvergence \ ; RUN: %s -o - -filetype=obj | spirv-val %} +; RUN: %if spirv-tools %{ llc -O0 \ +; RUN: -mtriple=spirv32v1.3-unknown-vulkan-library \ +; RUN: %s -o - -filetype=obj | spirv-val %} -; NO-EXT: OpGroupNonUniformQuadAllKHR requires the following SPIR-V extension: SPV_KHR_quad_control ; NO-RECONVERGENCE: SPV_KHR_quad_control requires the following SPIR-V extension: SPV_KHR_maximal_reconvergence ; VERSION: OpGroupNonUniformQuadAllKHR requires SPIR-V 1.3 @@ -28,6 +39,24 @@ ; CHECK: %[[#COND:]] = OpFunctionParameter %[[#BOOL]] ; CHECK: %[[#RET:]] = OpGroupNonUniformQuadAllKHR %[[#BOOL]] %[[#COND]] ; CHECK-NEXT: OpReturnValue %[[#RET]] + +; EMULATED-DAG: OpCapability GroupNonUniformQuad +; EMULATED-NOT: OpExecutionMode +; EMULATED-DAG: %[[#BOOL:]] = OpTypeBool +; EMULATED-DAG: %[[#INT:]] = OpTypeInt 32 0 +; EMULATED-DAG: %[[#SCOPE:]] = OpConstant %[[#INT]] 3 +; EMULATED-DAG: %[[#XDIR:]] = OpConstant %[[#INT]] 0 +; EMULATED-DAG: %[[#YDIR:]] = OpConstant %[[#INT]] 1 +; EMULATED-DAG: %[[#DDIR:]] = OpConstant %[[#INT]] 2 +; EMULATED-LABEL: Begin function quad_all +; EMULATED: %[[#COND:]] = OpFunctionParameter %[[#BOOL]] +; EMULATED: %[[#X:]] = OpGroupNonUniformQuadSwap %[[#BOOL]] %[[#SCOPE]] %[[#COND]] %[[#XDIR]] +; EMULATED-NEXT: %[[#ANDX:]] = OpLogicalAnd %[[#BOOL]] %[[#COND]] %[[#X]] +; EMULATED-NEXT: %[[#Y:]] = OpGroupNonUniformQuadSwap %[[#BOOL]] %[[#SCOPE]] %[[#COND]] %[[#YDIR]] +; EMULATED-NEXT: %[[#ANDY:]] = OpLogicalAnd %[[#BOOL]] %[[#ANDX]] %[[#Y]] +; EMULATED-NEXT: %[[#D:]] = OpGroupNonUniformQuadSwap %[[#BOOL]] %[[#SCOPE]] %[[#COND]] %[[#DDIR]] +; EMULATED-NEXT: %[[#RET:]] = OpLogicalAnd %[[#BOOL]] %[[#ANDY]] %[[#D]] +; EMULATED-NEXT: OpReturnValue %[[#RET]] define i1 @quad_all(i1 %cond) convergent { %tok = call token @llvm.experimental.convergence.entry() %ret = call i1 @llvm.spv.quad.all(i1 %cond) [ "convergencectrl"(token %tok) ] >From 8af9df36b31e630e4df82d4dd66a8bdf40fb47f0 Mon Sep 17 00:00:00 2001 From: Joshua Batista <[email protected]> Date: Tue, 10 Nov 2026 16:41:37 -0800 Subject: [PATCH 2/9] address Deric, disallow quadall except for mesh / amp / compute / pixel --- .../clang/Basic/DiagnosticSemaKinds.td | 3 + clang/lib/Sema/SemaHLSL.cpp | 21 +++++ .../BuiltIns/QuadAll-stages.errors.hlsl | 86 +++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 clang/test/SemaHLSL/BuiltIns/QuadAll-stages.errors.hlsl diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 3e56980e22902..1bd9316499262 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -13986,6 +13986,9 @@ def err_hlsl_atomic_arg_addr_space : Error< def err_hlsl_builtin_requires_sm : Error< "%0 requires shader model %1 or newer">; +def err_hlsl_builtin_unsupported_in_stage : Error< + "%0 is not supported in '%1' shaders">; + def err_hlsl_export_not_on_function : Error< "export declaration can only be used on functions">; diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 506ac8e13fe30..53f57970c2599 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -3191,6 +3191,7 @@ class DiagnoseHLSLAvailability : public DynamicRecursiveASTVisitor { SourceRange Range); const AvailabilityAttr *FindAvailabilityAttr(const Decl *D); bool HasMatchingEnvironmentOrNone(const AvailabilityAttr *AA); + void DiagnoseQuadAllCall(CallExpr *CE); void DiagnoseBarrierCall(CallExpr *CE); uint64_t DiagnoseBarrierGroupMemory(Expr *MemoryArg, uint64_t MemoryFlags, bool HasVisibleGroup, bool IsAllMemory); @@ -3226,11 +3227,31 @@ class DiagnoseHLSLAvailability : public DynamicRecursiveASTVisitor { } bool VisitCallExpr(CallExpr *CE) override { + DiagnoseQuadAllCall(CE); DiagnoseBarrierCall(CE); return true; } }; +void DiagnoseHLSLAvailability::DiagnoseQuadAllCall(CallExpr *CE) { + const FunctionDecl *FD = CE->getDirectCallee(); + if (!FD || FD->getBuiltinID() != Builtin::BI__builtin_hlsl_quad_all) + return; + + switch (GetCurrentShaderEnvironment()) { + case llvm::Triple::UnknownEnvironment: + case llvm::Triple::Pixel: + case llvm::Triple::Compute: + case llvm::Triple::Mesh: + case llvm::Triple::Amplification: + return; + default: + SemaRef.Diag(CE->getExprLoc(), diag::err_hlsl_builtin_unsupported_in_stage) + << FD + << llvm::Triple::getEnvironmentTypeName(GetCurrentShaderEnvironment()); + } +} + uint64_t DiagnoseHLSLAvailability::DiagnoseBarrierGroupMemory( Expr *MemoryArg, uint64_t MemoryFlags, bool HasVisibleGroup, bool IsAllMemory) { diff --git a/clang/test/SemaHLSL/BuiltIns/QuadAll-stages.errors.hlsl b/clang/test/SemaHLSL/BuiltIns/QuadAll-stages.errors.hlsl new file mode 100644 index 0000000000000..1832f01eaaf09 --- /dev/null +++ b/clang/test/SemaHLSL/BuiltIns/QuadAll-stages.errors.hlsl @@ -0,0 +1,86 @@ +// RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: dxil-pc-shadermodel6.0-library %s -fsyntax-only -verify +// RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: dxil-pc-shadermodel6.6-library %s -fsyntax-only -verify \ +// RUN: -fhlsl-strict-availability +// RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: dxil-pc-shadermodel6.7-library %s -fsyntax-only -verify +// RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: spirv-pc-vulkan-library %s -fsyntax-only -verify + +bool test_quad_all(bool cond) { + return QuadAll(cond); // #quad +} + +export bool exported_quad_all(bool cond) { + return test_quad_all(cond); +} + +[shader("pixel")] +void pixel_main() { + test_quad_all(true); + (void)__builtin_hlsl_quad_all(true); +} + +[shader("compute")] +[numthreads(2, 2, 1)] +void compute_main() { + test_quad_all(true); + (void)__builtin_hlsl_quad_all(true); +} + +[shader("mesh")] +[numthreads(2, 2, 1)] +void mesh_main() { + test_quad_all(true); +} + +[shader("amplification")] +[numthreads(2, 2, 1)] +void amplification_main() { + test_quad_all(true); +} + +// expected-error@#quad {{'QuadAll' is not supported in 'vertex' shaders}} +[shader("vertex")] +void vertex_main() { + test_quad_all(true); + // expected-error@+1 {{'__builtin_hlsl_quad_all' is not supported}} + (void)__builtin_hlsl_quad_all(true); +} + +// expected-error@#quad {{'QuadAll' is not supported in 'geometry' shaders}} +[shader("geometry")] +void geometry_main() { test_quad_all(true); } + +// expected-error@#quad {{'QuadAll' is not supported in 'hull' shaders}} +[shader("hull")] +void hull_main() { test_quad_all(true); } + +// expected-error@#quad {{'QuadAll' is not supported in 'domain' shaders}} +[shader("domain")] +void domain_main() { test_quad_all(true); } + +// expected-error@#quad {{'QuadAll' is not supported in 'raygeneration'}} +[shader("raygeneration")] +void raygeneration_main() { test_quad_all(true); } + +// expected-error@#quad {{'QuadAll' is not supported in 'intersection' shaders}} +[shader("intersection")] +void intersection_main() { test_quad_all(true); } + +// expected-error@#quad {{'QuadAll' is not supported in 'anyhit' shaders}} +[shader("anyhit")] +void anyhit_main() { test_quad_all(true); } + +// expected-error@#quad {{'QuadAll' is not supported in 'closesthit' shaders}} +[shader("closesthit")] +void closesthit_main() { test_quad_all(true); } + +// expected-error@#quad {{'QuadAll' is not supported in 'miss' shaders}} +[shader("miss")] +void miss_main() { test_quad_all(true); } + +// expected-error@#quad {{'QuadAll' is not supported in 'callable' shaders}} +[shader("callable")] +void callable_main() { test_quad_all(true); } >From 047c68196d7e49144a8197ca17f05477719caa7b Mon Sep 17 00:00:00 2001 From: Joshua Batista <[email protected]> Date: Wed, 11 Nov 2026 14:38:43 -0800 Subject: [PATCH 3/9] add derivative mode if applicable Co-authored-by: Copilot <[email protected]> Copilot-Session: 365638e8-2291-4925-8f1e-1b5c23220818 --- clang/lib/CodeGen/CGHLSLRuntime.cpp | 34 +++++++++ .../builtins/QuadAll-derivative-group.hlsl | 71 +++++++++++++++++++ llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp | 11 +-- .../lib/Target/SPIRV/SPIRVSymbolicOperands.td | 10 ++- 4 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group.hlsl diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index e65ada1ee8100..8eccf28f20656 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -35,6 +35,7 @@ #include "llvm/ADT/Enum.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/ScopeExit.h" +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Frontend/HLSL/HLSLResource.h" @@ -1000,6 +1001,37 @@ void CGHLSLRuntime::addHLSLBufferLayoutType(const RecordType *StructType, LayoutTypes[StructType] = LayoutTy; } +static void addSPIRVQuadAllExecutionModes(llvm::Module &M) { + Function *QuadAll = + Intrinsic::getDeclarationIfExists(&M, Intrinsic::spv_quad_all); + if (!QuadAll) + return; + + SmallVector<Function *, 8> Worklist{QuadAll}; + SmallPtrSet<Function *, 16> Visited; + IRBuilder<> B(M); + while (!Worklist.empty()) { + Function *F = Worklist.pop_back_val(); + if (!Visited.insert(F).second) + continue; + + if (F->hasFnAttribute("hlsl.numthreads")) { + StringRef NumThreads = + F->getFnAttribute("hlsl.numthreads").getValueAsString(); + // DerivativeGroupLinearKHR is 5290; DerivativeGroupQuadsKHR is 5289. + unsigned Mode = NumThreads.ends_with(",1,1") ? 5290 : 5289; + MDNode *MD = MDNode::get( + M.getContext(), + {ValueAsMetadata::get(F), ConstantAsMetadata::get(B.getInt32(Mode))}); + M.getOrInsertNamedMetadata("spirv.ExecutionMode")->addOperand(MD); + } + + for (User *U : F->users()) + if (auto *Call = dyn_cast<CallBase>(U)) + Worklist.push_back(Call->getFunction()); + } +} + void CGHLSLRuntime::finishCodeGen() { auto &TargetOpts = CGM.getTarget().getTargetOpts(); auto &CodeGenOpts = CGM.getCodeGenOpts(); @@ -1044,6 +1076,8 @@ void CGHLSLRuntime::finishCodeGen() { } generateGlobalCtorDtorCalls(); + if (T.isSPIRV()) + addSPIRVQuadAllExecutionModes(M); } void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes( diff --git a/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group.hlsl b/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group.hlsl new file mode 100644 index 0000000000000..5fa6afefac66c --- /dev/null +++ b/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group.hlsl @@ -0,0 +1,71 @@ +// DEFINE: %{deriv-ext} = +SPV_KHR_compute_shader_derivatives +// DEFINE: %{quad-exts} = +SPV_KHR_quad_control,+SPV_KHR_maximal_reconvergence +// RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: spirv-pc-vulkan-library %s -emit-llvm -disable-llvm-passes -o - \ +// RUN: | FileCheck %s --check-prefix=IR +// RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: dxil-pc-shadermodel6.7-library %s -emit-llvm \ +// RUN: -disable-llvm-passes -o - | FileCheck %s --check-prefix=DXIL +// RUN: %if spirv-registered-target %{ \ +// RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: spirv1.6-unknown-vulkan1.3-library -O3 -S %s -o - \ +// RUN: -mllvm -spirv-ext=%{deriv-ext},%{quad-exts} \ +// RUN: | FileCheck %s --check-prefixes=SPIRV,NATIVE %} +// RUN: %if spirv-registered-target %{ \ +// RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: spirv1.6-unknown-vulkan1.3-library -O3 -S %s -o - \ +// RUN: -mllvm -spirv-ext=%{deriv-ext},-SPV_KHR_quad_control \ +// RUN: | FileCheck %s --check-prefixes=SPIRV,EMULATED \ +// RUN: --implicit-check-not=OpGroupNonUniformQuadAllKHR %} + +RWStructuredBuffer<uint> Out; + +bool vote(bool cond) { + return QuadAll(cond); +} + +bool helper(bool cond) { + return vote(cond); +} + +export bool exported_vote(bool cond) { + return helper(cond); +} + +[shader("compute")] +[numthreads(4, 2, 1)] +void compute_2d(uint index : SV_GroupIndex) { + Out[index] = helper(index != 0) && helper(index < 8); +} + +[shader("compute")] +[numthreads(8, 1, 1)] +void compute_1d(uint index : SV_GroupIndex) { + Out[index] = __builtin_hlsl_quad_all(index != 0); +} + +[shader("pixel")] +void pixel_main() { + Out[0] = helper(Out[0] != 0); +} + +[shader("compute")] +[numthreads(4, 2, 1)] +void no_vote(uint index : SV_GroupIndex) { + Out[index] = index; +} + +// IR: !spirv.ExecutionMode = !{!{{[0-9]+}}, !{{[0-9]+}}} +// IR-DAG: !{{[0-9]+}} = !{ptr @compute_2d, i32 5289} +// IR-DAG: !{{[0-9]+}} = !{ptr @compute_1d, i32 5290} +// DXIL-NOT: !spirv.ExecutionMode + +// SPIRV-DAG: OpCapability ComputeDerivativeGroupQuadsKHR +// SPIRV-DAG: OpCapability ComputeDerivativeGroupLinearKHR +// SPIRV-DAG: OpExtension "SPV_KHR_compute_shader_derivatives" +// SPIRV-DAG: OpEntryPoint GLCompute %[[#QUADS:]] "compute_2d" +// SPIRV-DAG: OpEntryPoint GLCompute %[[#LINEAR:]] "compute_1d" +// SPIRV-DAG: OpExecutionMode %[[#QUADS]] DerivativeGroupQuadsKHR +// SPIRV-DAG: OpExecutionMode %[[#LINEAR]] DerivativeGroupLinearKHR +// NATIVE: OpGroupNonUniformQuadAllKHR +// EMULATED: OpGroupNonUniformQuadSwap diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp index c3766765bc4bc..59df96461dd5f 100644 --- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp @@ -872,12 +872,13 @@ void SPIRV::RequirementHandler::getAndAddRequirements( addQuadControlRequirements(*this, ST, getSymbolicOperandMnemonic(Category, i)); if (Category == SPIRV::OperandCategory::ExecutionModeOperand && - i == SPIRV::ExecutionMode::DerivativeGroupQuadsKHR && + (i == SPIRV::ExecutionMode::DerivativeGroupQuadsKHR || + i == SPIRV::ExecutionMode::DerivativeGroupLinearKHR) && !ST.canUseExtension(SPIRV::Extension::SPV_KHR_compute_shader_derivatives)) - report_fatal_error( - "DerivativeGroupQuadsKHR requires the following SPIR-V extension: " - "SPV_KHR_compute_shader_derivatives", - false); + report_fatal_error(Twine(getSymbolicOperandMnemonic(Category, i)) + + " requires the following SPIR-V extension: " + "SPV_KHR_compute_shader_derivatives", + false); addRequirements(getSymbolicOperandRequirements(Category, i, ST, *this)); } diff --git a/llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td b/llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td index 9c8c6d1051f86..e8a9edad64db2 100644 --- a/llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td +++ b/llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td @@ -577,7 +577,11 @@ defm ComputeDerivativeGroupQuadsKHR def ComputeDerivativeGroupQuadsNV : Capability<"ComputeDerivativeGroupQuadsNV", 5288>; defm DemoteToHelperInvocation : CapabilityOperand<5379, 0x10600, 0, [SPV_EXT_demote_to_helper_invocation], []>; -defm ComputeDerivativeGroupLinearNV : CapabilityOperand<5350, 0, 0, [], []>; +defm ComputeDerivativeGroupLinearKHR + : CapabilityOperand<5350, 0, 0, [SPV_KHR_compute_shader_derivatives], + [Shader]>; +def ComputeDerivativeGroupLinearNV + : Capability<"ComputeDerivativeGroupLinearNV", 5350>; defm FragmentDensityEXT : CapabilityOperand<5291, 0, 0, [], [Shader]>; defm PhysicalStorageBufferAddressesEXT : CapabilityOperand<5347, 0, 0, [], [Shader]>; defm CooperativeMatrixNV : CapabilityOperand<5357, 0, 0, [], [Shader]>; @@ -864,7 +868,9 @@ defm OutputLinesNV : ExecutionModeOperand<5269, [MeshShadingNV]>; defm DerivativeGroupQuadsKHR : ExecutionModeOperand<5289, [ComputeDerivativeGroupQuadsKHR]>; def DerivativeGroupQuadsNV : ExecutionMode<"DerivativeGroupQuadsNV", 5289>; -defm DerivativeGroupLinearNV : ExecutionModeOperand<5290, [ComputeDerivativeGroupLinearNV]>; +defm DerivativeGroupLinearKHR + : ExecutionModeOperand<5290, [ComputeDerivativeGroupLinearKHR]>; +def DerivativeGroupLinearNV : ExecutionMode<"DerivativeGroupLinearNV", 5290>; defm OutputTrianglesNV : ExecutionModeOperand<5298, [MeshShadingNV]>; defm RoundingModeRTPINTEL : ExecutionModeOperand<5620, [RoundToInfinityINTEL]>; defm RoundingModeRTNINTEL : ExecutionModeOperand<5621, [RoundToInfinityINTEL]>; >From cd33fd3ffc87385d5fc3537799a2cd6a7b6d7e6e Mon Sep 17 00:00:00 2001 From: Joshua Batista <[email protected]> Date: Thu, 12 Nov 2026 11:34:03 -0800 Subject: [PATCH 4/9] address Deric, fix diag msg --- .../clang/Basic/DiagnosticSemaKinds.td | 3 +- clang/lib/Sema/SemaHLSL.cpp | 27 +++++++++------ ....errors.hlsl => QuadAll-stage-errors.hlsl} | 34 +++++++++++++------ 3 files changed, 41 insertions(+), 23 deletions(-) rename clang/test/SemaHLSL/BuiltIns/{QuadAll-stages.errors.hlsl => QuadAll-stage-errors.hlsl} (71%) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 1bd9316499262..b0356b82f0260 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -13987,7 +13987,8 @@ def err_hlsl_builtin_requires_sm : Error< "%0 requires shader model %1 or newer">; def err_hlsl_builtin_unsupported_in_stage : Error< - "%0 is not supported in '%1' shaders">; + "%0 is not supported in '%1' shaders, requires " + "%select{|one of the following: }2%3">; def err_hlsl_export_not_on_function : Error< "export declaration can only be used on functions">; diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 53f57970c2599..d3b88bbdfb614 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -3238,18 +3238,23 @@ void DiagnoseHLSLAvailability::DiagnoseQuadAllCall(CallExpr *CE) { if (!FD || FD->getBuiltinID() != Builtin::BI__builtin_hlsl_quad_all) return; - switch (GetCurrentShaderEnvironment()) { - case llvm::Triple::UnknownEnvironment: - case llvm::Triple::Pixel: - case llvm::Triple::Compute: - case llvm::Triple::Mesh: - case llvm::Triple::Amplification: + const llvm::Triple::EnvironmentType AllowedStages[] = { + llvm::Triple::Pixel, llvm::Triple::Compute, llvm::Triple::Mesh, + llvm::Triple::Amplification}; + llvm::Triple::EnvironmentType Stage = GetCurrentShaderEnvironment(); + if (Stage == llvm::Triple::UnknownEnvironment || + llvm::is_contained(AllowedStages, Stage)) return; - default: - SemaRef.Diag(CE->getExprLoc(), diag::err_hlsl_builtin_unsupported_in_stage) - << FD - << llvm::Triple::getEnvironmentTypeName(GetCurrentShaderEnvironment()); - } + + SmallVector<StringRef, 4> StageStrings; + llvm::transform(AllowedStages, std::back_inserter(StageStrings), + [](llvm::Triple::EnvironmentType ST) { + return StringRef( + HLSLShaderAttr::ConvertEnvironmentTypeToStr(ST)); + }); + SemaRef.Diag(CE->getExprLoc(), diag::err_hlsl_builtin_unsupported_in_stage) + << FD << llvm::Triple::getEnvironmentTypeName(Stage) + << (std::size(AllowedStages) != 1) << join(StageStrings, ", "); } uint64_t DiagnoseHLSLAvailability::DiagnoseBarrierGroupMemory( diff --git a/clang/test/SemaHLSL/BuiltIns/QuadAll-stages.errors.hlsl b/clang/test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl similarity index 71% rename from clang/test/SemaHLSL/BuiltIns/QuadAll-stages.errors.hlsl rename to clang/test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl index 1832f01eaaf09..1c375034d5554 100644 --- a/clang/test/SemaHLSL/BuiltIns/QuadAll-stages.errors.hlsl +++ b/clang/test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl @@ -41,46 +41,58 @@ void amplification_main() { test_quad_all(true); } -// expected-error@#quad {{'QuadAll' is not supported in 'vertex' shaders}} +// expected-error@#quad {{'QuadAll' is not supported in 'vertex' shaders, \ +requires one of the following: pixel, compute, mesh, amplification}} [shader("vertex")] void vertex_main() { test_quad_all(true); - // expected-error@+1 {{'__builtin_hlsl_quad_all' is not supported}} + // expected-error@+3 {{'__builtin_hlsl_quad_all' is not supported in \ +'vertex' shaders, requires one of the following: \ +pixel, compute, mesh, amplification}} (void)__builtin_hlsl_quad_all(true); } -// expected-error@#quad {{'QuadAll' is not supported in 'geometry' shaders}} +// expected-error@#quad {{'QuadAll' is not supported in 'geometry' shaders, \ +requires one of the following: pixel, compute, mesh, amplification}} [shader("geometry")] void geometry_main() { test_quad_all(true); } -// expected-error@#quad {{'QuadAll' is not supported in 'hull' shaders}} +// expected-error@#quad {{'QuadAll' is not supported in 'hull' shaders, \ +requires one of the following: pixel, compute, mesh, amplification}} [shader("hull")] void hull_main() { test_quad_all(true); } -// expected-error@#quad {{'QuadAll' is not supported in 'domain' shaders}} +// expected-error@#quad {{'QuadAll' is not supported in 'domain' shaders, \ +requires one of the following: pixel, compute, mesh, amplification}} [shader("domain")] void domain_main() { test_quad_all(true); } -// expected-error@#quad {{'QuadAll' is not supported in 'raygeneration'}} +// expected-error@#quad {{'QuadAll' is not supported in 'raygeneration' \ +shaders, requires one of the following: pixel, compute, mesh, amplification}} [shader("raygeneration")] void raygeneration_main() { test_quad_all(true); } -// expected-error@#quad {{'QuadAll' is not supported in 'intersection' shaders}} +// expected-error@#quad {{'QuadAll' is not supported in 'intersection' \ +shaders, requires one of the following: pixel, compute, mesh, amplification}} [shader("intersection")] void intersection_main() { test_quad_all(true); } -// expected-error@#quad {{'QuadAll' is not supported in 'anyhit' shaders}} +// expected-error@#quad {{'QuadAll' is not supported in 'anyhit' shaders, \ +requires one of the following: pixel, compute, mesh, amplification}} [shader("anyhit")] void anyhit_main() { test_quad_all(true); } -// expected-error@#quad {{'QuadAll' is not supported in 'closesthit' shaders}} +// expected-error@#quad {{'QuadAll' is not supported in 'closesthit' shaders, \ +requires one of the following: pixel, compute, mesh, amplification}} [shader("closesthit")] void closesthit_main() { test_quad_all(true); } -// expected-error@#quad {{'QuadAll' is not supported in 'miss' shaders}} +// expected-error@#quad {{'QuadAll' is not supported in 'miss' shaders, \ +requires one of the following: pixel, compute, mesh, amplification}} [shader("miss")] void miss_main() { test_quad_all(true); } -// expected-error@#quad {{'QuadAll' is not supported in 'callable' shaders}} +// expected-error@#quad {{'QuadAll' is not supported in 'callable' shaders, \ +requires one of the following: pixel, compute, mesh, amplification}} [shader("callable")] void callable_main() { test_quad_all(true); } >From beef838c078c5433170e6f2282ce39e465cd545c Mon Sep 17 00:00:00 2001 From: Joshua Batista <[email protected]> Date: Fri, 13 Nov 2026 14:18:32 -0800 Subject: [PATCH 5/9] address Helena --- .../clang/Basic/DiagnosticFrontendKinds.td | 4 + .../clang/Basic/DiagnosticSemaKinds.td | 4 - clang/lib/CodeGen/CGHLSLRuntime.cpp | 33 ++++++- clang/lib/Sema/SemaHLSL.cpp | 26 ----- .../QuadAll-derivative-group-errors.hlsl | 57 +++++++++++ .../builtins/QuadAll-derivative-group.hlsl | 23 ----- .../BuiltIns/QuadAll-stage-errors.hlsl | 98 ------------------- .../derivative-group-linear.ll | 30 ++++++ 8 files changed, 119 insertions(+), 156 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group-errors.hlsl delete mode 100644 clang/test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl create mode 100644 llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_compute_shader_derivatives/derivative-group-linear.ll diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index b51aa3ff0a0cb..be82686552733 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -504,6 +504,10 @@ def warn_hlsl_langstd_minimal : InGroup<HLSLDXCCompat>; def err_hlsl_signature_packing : Error< "failed to pack %select{input|output}0 signature: %1">; +def err_hlsl_spirv_quad_all_numthreads : Error< + "entry point '%0' uses QuadAll with invalid numthreads: " + "%select{DerivativeGroupQuadsKHR requires X and Y to be multiples of 2|" + "DerivativeGroupLinearKHR requires X * Y * Z to be a multiple of 4}1">; def warn_hlsl_signature_packing_ignored : Warning< "semantic signature packing mode '%0' is ignored as " "%select{vertex shader inputs|pixel shader outputs}1 always use " diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index b0356b82f0260..3e56980e22902 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -13986,10 +13986,6 @@ def err_hlsl_atomic_arg_addr_space : Error< def err_hlsl_builtin_requires_sm : Error< "%0 requires shader model %1 or newer">; -def err_hlsl_builtin_unsupported_in_stage : Error< - "%0 is not supported in '%1' shaders, requires " - "%select{|one of the following: }2%3">; - def err_hlsl_export_not_on_function : Error< "export declaration can only be used on functions">; diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 8eccf28f20656..3f9e01716ffb6 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -68,6 +68,11 @@ using llvm::hlsl::CBufferRowSizeInBytes; namespace { +enum class SPIRVExecutionMode : uint32_t { + DerivativeGroupQuadsKHR = 5289, + DerivativeGroupLinearKHR = 5290 +}; + void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) { // The validation of ValVersionStr is done at HLSLToolChain::TranslateArgs. // Assume ValVersionStr is legal here. @@ -1001,7 +1006,8 @@ void CGHLSLRuntime::addHLSLBufferLayoutType(const RecordType *StructType, LayoutTypes[StructType] = LayoutTy; } -static void addSPIRVQuadAllExecutionModes(llvm::Module &M) { +static void addSPIRVQuadAllExecutionModes(CodeGenModule &CGM) { + llvm::Module &M = CGM.getModule(); Function *QuadAll = Intrinsic::getDeclarationIfExists(&M, Intrinsic::spv_quad_all); if (!QuadAll) @@ -1018,11 +1024,28 @@ static void addSPIRVQuadAllExecutionModes(llvm::Module &M) { if (F->hasFnAttribute("hlsl.numthreads")) { StringRef NumThreads = F->getFnAttribute("hlsl.numthreads").getValueAsString(); - // DerivativeGroupLinearKHR is 5290; DerivativeGroupQuadsKHR is 5289. - unsigned Mode = NumThreads.ends_with(",1,1") ? 5290 : 5289; + SmallVector<StringRef, 3> Dimensions; + NumThreads.split(Dimensions, ','); + assert(Dimensions.size() == 3 && "expected three numthreads dimensions"); + std::array<uint32_t, 3> Threads; + for (auto [Dimension, Thread] : llvm::zip(Dimensions, Threads)) { + [[maybe_unused]] bool Invalid = Dimension.getAsInteger(10, Thread); + assert(!Invalid && "expected an integer numthreads dimension"); + } + bool IsLinear = Threads[1] == 1 && Threads[2] == 1; + if (IsLinear ? (uint64_t(Threads[0]) * Threads[1] * Threads[2]) % 4 != 0 + : Threads[0] % 2 != 0 || Threads[1] % 2 != 0) { + CGM.getDiags().Report(diag::err_hlsl_spirv_quad_all_numthreads) + << F->getName() << IsLinear; + continue; + } + SPIRVExecutionMode Mode = + IsLinear ? SPIRVExecutionMode::DerivativeGroupLinearKHR + : SPIRVExecutionMode::DerivativeGroupQuadsKHR; MDNode *MD = MDNode::get( M.getContext(), - {ValueAsMetadata::get(F), ConstantAsMetadata::get(B.getInt32(Mode))}); + {ValueAsMetadata::get(F), + ConstantAsMetadata::get(B.getInt32(llvm::to_underlying(Mode)))}); M.getOrInsertNamedMetadata("spirv.ExecutionMode")->addOperand(MD); } @@ -1077,7 +1100,7 @@ void CGHLSLRuntime::finishCodeGen() { generateGlobalCtorDtorCalls(); if (T.isSPIRV()) - addSPIRVQuadAllExecutionModes(M); + addSPIRVQuadAllExecutionModes(CGM); } void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes( diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index d3b88bbdfb614..506ac8e13fe30 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -3191,7 +3191,6 @@ class DiagnoseHLSLAvailability : public DynamicRecursiveASTVisitor { SourceRange Range); const AvailabilityAttr *FindAvailabilityAttr(const Decl *D); bool HasMatchingEnvironmentOrNone(const AvailabilityAttr *AA); - void DiagnoseQuadAllCall(CallExpr *CE); void DiagnoseBarrierCall(CallExpr *CE); uint64_t DiagnoseBarrierGroupMemory(Expr *MemoryArg, uint64_t MemoryFlags, bool HasVisibleGroup, bool IsAllMemory); @@ -3227,36 +3226,11 @@ class DiagnoseHLSLAvailability : public DynamicRecursiveASTVisitor { } bool VisitCallExpr(CallExpr *CE) override { - DiagnoseQuadAllCall(CE); DiagnoseBarrierCall(CE); return true; } }; -void DiagnoseHLSLAvailability::DiagnoseQuadAllCall(CallExpr *CE) { - const FunctionDecl *FD = CE->getDirectCallee(); - if (!FD || FD->getBuiltinID() != Builtin::BI__builtin_hlsl_quad_all) - return; - - const llvm::Triple::EnvironmentType AllowedStages[] = { - llvm::Triple::Pixel, llvm::Triple::Compute, llvm::Triple::Mesh, - llvm::Triple::Amplification}; - llvm::Triple::EnvironmentType Stage = GetCurrentShaderEnvironment(); - if (Stage == llvm::Triple::UnknownEnvironment || - llvm::is_contained(AllowedStages, Stage)) - return; - - SmallVector<StringRef, 4> StageStrings; - llvm::transform(AllowedStages, std::back_inserter(StageStrings), - [](llvm::Triple::EnvironmentType ST) { - return StringRef( - HLSLShaderAttr::ConvertEnvironmentTypeToStr(ST)); - }); - SemaRef.Diag(CE->getExprLoc(), diag::err_hlsl_builtin_unsupported_in_stage) - << FD << llvm::Triple::getEnvironmentTypeName(Stage) - << (std::size(AllowedStages) != 1) << join(StageStrings, ", "); -} - uint64_t DiagnoseHLSLAvailability::DiagnoseBarrierGroupMemory( Expr *MemoryArg, uint64_t MemoryFlags, bool HasVisibleGroup, bool IsAllMemory) { diff --git a/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group-errors.hlsl b/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group-errors.hlsl new file mode 100644 index 0000000000000..29574af763267 --- /dev/null +++ b/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group-errors.hlsl @@ -0,0 +1,57 @@ +// RUN: not %clang_cc1 -finclude-default-header -triple \ +// RUN: spirv-pc-vulkan-library %s -emit-llvm -disable-llvm-passes \ +// RUN: -o %t 2>&1 | FileCheck %s \ +// RUN: --implicit-check-not="entry point 'valid" \ +// RUN: --implicit-check-not="entry point 'no_vote'" +// RUN: %clang_cc1 -finclude-default-header -triple \ +// RUN: dxil-pc-shadermodel6.7-library %s -emit-llvm \ +// RUN: -disable-llvm-passes -o %t + +bool helper(bool cond) { + return QuadAll(cond); +} + +[shader("compute")] +[numthreads(4, 1, 1)] +void valid_linear() { + helper(true); +} + +[shader("compute")] +[numthreads(2, 2, 3)] +void valid_quads() { + helper(true); +} + +[shader("compute")] +[numthreads(6, 1, 1)] +void invalid_linear() { + (void)__builtin_hlsl_quad_all(true); +} + +[shader("compute")] +[numthreads(3, 4, 1)] +void invalid_quad_x() { + helper(true); +} + +[shader("compute")] +[numthreads(4, 3, 1)] +void invalid_quad_y() { + helper(true); +} + +[shader("compute")] +[numthreads(2, 1, 2)] +void invalid_quad_3d() { + helper(true); +} + +[shader("compute")] +[numthreads(3, 1, 1)] +void no_vote() {} + +// CHECK-DAG: error: entry point 'invalid_linear' uses QuadAll with invalid numthreads: DerivativeGroupLinearKHR requires X * Y * Z to be a multiple of 4 +// CHECK-DAG: error: entry point 'invalid_quad_x' uses QuadAll with invalid numthreads: DerivativeGroupQuadsKHR requires X and Y to be multiples of 2 +// CHECK-DAG: error: entry point 'invalid_quad_y' uses QuadAll with invalid numthreads: DerivativeGroupQuadsKHR requires X and Y to be multiples of 2 +// CHECK-DAG: error: entry point 'invalid_quad_3d' uses QuadAll with invalid numthreads: DerivativeGroupQuadsKHR requires X and Y to be multiples of 2 diff --git a/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group.hlsl b/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group.hlsl index 5fa6afefac66c..52f33e20ca09d 100644 --- a/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group.hlsl +++ b/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group.hlsl @@ -1,22 +1,9 @@ -// DEFINE: %{deriv-ext} = +SPV_KHR_compute_shader_derivatives -// DEFINE: %{quad-exts} = +SPV_KHR_quad_control,+SPV_KHR_maximal_reconvergence // RUN: %clang_cc1 -finclude-default-header -triple \ // RUN: spirv-pc-vulkan-library %s -emit-llvm -disable-llvm-passes -o - \ // RUN: | FileCheck %s --check-prefix=IR // RUN: %clang_cc1 -finclude-default-header -triple \ // RUN: dxil-pc-shadermodel6.7-library %s -emit-llvm \ // RUN: -disable-llvm-passes -o - | FileCheck %s --check-prefix=DXIL -// RUN: %if spirv-registered-target %{ \ -// RUN: %clang_cc1 -finclude-default-header -triple \ -// RUN: spirv1.6-unknown-vulkan1.3-library -O3 -S %s -o - \ -// RUN: -mllvm -spirv-ext=%{deriv-ext},%{quad-exts} \ -// RUN: | FileCheck %s --check-prefixes=SPIRV,NATIVE %} -// RUN: %if spirv-registered-target %{ \ -// RUN: %clang_cc1 -finclude-default-header -triple \ -// RUN: spirv1.6-unknown-vulkan1.3-library -O3 -S %s -o - \ -// RUN: -mllvm -spirv-ext=%{deriv-ext},-SPV_KHR_quad_control \ -// RUN: | FileCheck %s --check-prefixes=SPIRV,EMULATED \ -// RUN: --implicit-check-not=OpGroupNonUniformQuadAllKHR %} RWStructuredBuffer<uint> Out; @@ -59,13 +46,3 @@ void no_vote(uint index : SV_GroupIndex) { // IR-DAG: !{{[0-9]+}} = !{ptr @compute_2d, i32 5289} // IR-DAG: !{{[0-9]+}} = !{ptr @compute_1d, i32 5290} // DXIL-NOT: !spirv.ExecutionMode - -// SPIRV-DAG: OpCapability ComputeDerivativeGroupQuadsKHR -// SPIRV-DAG: OpCapability ComputeDerivativeGroupLinearKHR -// SPIRV-DAG: OpExtension "SPV_KHR_compute_shader_derivatives" -// SPIRV-DAG: OpEntryPoint GLCompute %[[#QUADS:]] "compute_2d" -// SPIRV-DAG: OpEntryPoint GLCompute %[[#LINEAR:]] "compute_1d" -// SPIRV-DAG: OpExecutionMode %[[#QUADS]] DerivativeGroupQuadsKHR -// SPIRV-DAG: OpExecutionMode %[[#LINEAR]] DerivativeGroupLinearKHR -// NATIVE: OpGroupNonUniformQuadAllKHR -// EMULATED: OpGroupNonUniformQuadSwap diff --git a/clang/test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl deleted file mode 100644 index 1c375034d5554..0000000000000 --- a/clang/test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl +++ /dev/null @@ -1,98 +0,0 @@ -// RUN: %clang_cc1 -finclude-default-header -triple \ -// RUN: dxil-pc-shadermodel6.0-library %s -fsyntax-only -verify -// RUN: %clang_cc1 -finclude-default-header -triple \ -// RUN: dxil-pc-shadermodel6.6-library %s -fsyntax-only -verify \ -// RUN: -fhlsl-strict-availability -// RUN: %clang_cc1 -finclude-default-header -triple \ -// RUN: dxil-pc-shadermodel6.7-library %s -fsyntax-only -verify -// RUN: %clang_cc1 -finclude-default-header -triple \ -// RUN: spirv-pc-vulkan-library %s -fsyntax-only -verify - -bool test_quad_all(bool cond) { - return QuadAll(cond); // #quad -} - -export bool exported_quad_all(bool cond) { - return test_quad_all(cond); -} - -[shader("pixel")] -void pixel_main() { - test_quad_all(true); - (void)__builtin_hlsl_quad_all(true); -} - -[shader("compute")] -[numthreads(2, 2, 1)] -void compute_main() { - test_quad_all(true); - (void)__builtin_hlsl_quad_all(true); -} - -[shader("mesh")] -[numthreads(2, 2, 1)] -void mesh_main() { - test_quad_all(true); -} - -[shader("amplification")] -[numthreads(2, 2, 1)] -void amplification_main() { - test_quad_all(true); -} - -// expected-error@#quad {{'QuadAll' is not supported in 'vertex' shaders, \ -requires one of the following: pixel, compute, mesh, amplification}} -[shader("vertex")] -void vertex_main() { - test_quad_all(true); - // expected-error@+3 {{'__builtin_hlsl_quad_all' is not supported in \ -'vertex' shaders, requires one of the following: \ -pixel, compute, mesh, amplification}} - (void)__builtin_hlsl_quad_all(true); -} - -// expected-error@#quad {{'QuadAll' is not supported in 'geometry' shaders, \ -requires one of the following: pixel, compute, mesh, amplification}} -[shader("geometry")] -void geometry_main() { test_quad_all(true); } - -// expected-error@#quad {{'QuadAll' is not supported in 'hull' shaders, \ -requires one of the following: pixel, compute, mesh, amplification}} -[shader("hull")] -void hull_main() { test_quad_all(true); } - -// expected-error@#quad {{'QuadAll' is not supported in 'domain' shaders, \ -requires one of the following: pixel, compute, mesh, amplification}} -[shader("domain")] -void domain_main() { test_quad_all(true); } - -// expected-error@#quad {{'QuadAll' is not supported in 'raygeneration' \ -shaders, requires one of the following: pixel, compute, mesh, amplification}} -[shader("raygeneration")] -void raygeneration_main() { test_quad_all(true); } - -// expected-error@#quad {{'QuadAll' is not supported in 'intersection' \ -shaders, requires one of the following: pixel, compute, mesh, amplification}} -[shader("intersection")] -void intersection_main() { test_quad_all(true); } - -// expected-error@#quad {{'QuadAll' is not supported in 'anyhit' shaders, \ -requires one of the following: pixel, compute, mesh, amplification}} -[shader("anyhit")] -void anyhit_main() { test_quad_all(true); } - -// expected-error@#quad {{'QuadAll' is not supported in 'closesthit' shaders, \ -requires one of the following: pixel, compute, mesh, amplification}} -[shader("closesthit")] -void closesthit_main() { test_quad_all(true); } - -// expected-error@#quad {{'QuadAll' is not supported in 'miss' shaders, \ -requires one of the following: pixel, compute, mesh, amplification}} -[shader("miss")] -void miss_main() { test_quad_all(true); } - -// expected-error@#quad {{'QuadAll' is not supported in 'callable' shaders, \ -requires one of the following: pixel, compute, mesh, amplification}} -[shader("callable")] -void callable_main() { test_quad_all(true); } diff --git a/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_compute_shader_derivatives/derivative-group-linear.ll b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_compute_shader_derivatives/derivative-group-linear.ll new file mode 100644 index 0000000000000..b4e53e32c82aa --- /dev/null +++ b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_compute_shader_derivatives/derivative-group-linear.ll @@ -0,0 +1,30 @@ +; RUN: llc -O0 -verify-machineinstrs \ +; RUN: -mtriple=spirv1.5-unknown-vulkan-compute \ +; RUN: --spirv-ext=+SPV_KHR_compute_shader_derivatives \ +; RUN: %s -o - | FileCheck %s +; RUN: not llc -O0 -mtriple=spirv1.5-unknown-vulkan-compute \ +; RUN: --spirv-ext=-SPV_KHR_compute_shader_derivatives \ +; RUN: %s -o - 2>&1 | FileCheck %s --check-prefix=NO-EXT +; RUN: %if spirv-tools %{ llc -O0 \ +; RUN: -mtriple=spirv1.5-unknown-vulkan-compute \ +; RUN: --spirv-ext=+SPV_KHR_compute_shader_derivatives \ +; RUN: %s -o - -filetype=obj | spirv-val --target-env vulkan1.2 %} + +; NO-EXT: DerivativeGroupLinearKHR requires the following SPIR-V extension: SPV_KHR_compute_shader_derivatives + +; CHECK-DAG: OpCapability Shader +; CHECK-DAG: OpCapability ComputeDerivativeGroupLinearKHR +; CHECK: OpExtension "SPV_KHR_compute_shader_derivatives" +; CHECK-NOT: OpExtension +; CHECK: OpEntryPoint GLCompute %[[#MAIN:]] "main" +; CHECK: OpExecutionMode %[[#MAIN]] DerivativeGroupLinearKHR +; CHECK: OpExecutionMode %[[#MAIN]] LocalSize 8 1 1 + +define void @main() #0 { + ret void +} + +attributes #0 = { "hlsl.numthreads"="8,1,1" "hlsl.shader"="compute" } + +!spirv.ExecutionMode = !{!0} +!0 = !{ptr @main, i32 5290} >From dc26ed1ba8a2e07acaa6b4432553b9210fe3a89a Mon Sep 17 00:00:00 2001 From: Joshua Batista <[email protected]> Date: Fri, 13 Nov 2026 15:02:22 -0800 Subject: [PATCH 6/9] address deric, extract helper function for identifying derivative mode --- clang/lib/CodeGen/CGHLSLRuntime.cpp | 46 ++++++++++++++++------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 3f9e01716ffb6..1958761ffec1b 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -1006,6 +1006,28 @@ void CGHLSLRuntime::addHLSLBufferLayoutType(const RecordType *StructType, LayoutTypes[StructType] = LayoutTy; } +static std::optional<SPIRVExecutionMode> +getSPIRVDerivativeGroupMode(CodeGenModule &CGM, const Function &F) { + StringRef NumThreads = F.getFnAttribute("hlsl.numthreads").getValueAsString(); + SmallVector<StringRef, 3> Dimensions; + NumThreads.split(Dimensions, ','); + assert(Dimensions.size() == 3 && "expected three numthreads dimensions"); + std::array<uint32_t, 3> Threads; + for (auto [Dimension, Thread] : llvm::zip(Dimensions, Threads)) { + [[maybe_unused]] bool Invalid = Dimension.getAsInteger(10, Thread); + assert(!Invalid && "expected an integer numthreads dimension"); + } + bool IsLinear = Threads[1] == 1 && Threads[2] == 1; + if (IsLinear ? (uint64_t(Threads[0]) * Threads[1] * Threads[2]) % 4 != 0 + : Threads[0] % 2 != 0 || Threads[1] % 2 != 0) { + CGM.getDiags().Report(diag::err_hlsl_spirv_quad_all_numthreads) + << F.getName() << IsLinear; + return std::nullopt; + } + return IsLinear ? SPIRVExecutionMode::DerivativeGroupLinearKHR + : SPIRVExecutionMode::DerivativeGroupQuadsKHR; +} + static void addSPIRVQuadAllExecutionModes(CodeGenModule &CGM) { llvm::Module &M = CGM.getModule(); Function *QuadAll = @@ -1022,30 +1044,14 @@ static void addSPIRVQuadAllExecutionModes(CodeGenModule &CGM) { continue; if (F->hasFnAttribute("hlsl.numthreads")) { - StringRef NumThreads = - F->getFnAttribute("hlsl.numthreads").getValueAsString(); - SmallVector<StringRef, 3> Dimensions; - NumThreads.split(Dimensions, ','); - assert(Dimensions.size() == 3 && "expected three numthreads dimensions"); - std::array<uint32_t, 3> Threads; - for (auto [Dimension, Thread] : llvm::zip(Dimensions, Threads)) { - [[maybe_unused]] bool Invalid = Dimension.getAsInteger(10, Thread); - assert(!Invalid && "expected an integer numthreads dimension"); - } - bool IsLinear = Threads[1] == 1 && Threads[2] == 1; - if (IsLinear ? (uint64_t(Threads[0]) * Threads[1] * Threads[2]) % 4 != 0 - : Threads[0] % 2 != 0 || Threads[1] % 2 != 0) { - CGM.getDiags().Report(diag::err_hlsl_spirv_quad_all_numthreads) - << F->getName() << IsLinear; + std::optional<SPIRVExecutionMode> Mode = + getSPIRVDerivativeGroupMode(CGM, *F); + if (!Mode) continue; - } - SPIRVExecutionMode Mode = - IsLinear ? SPIRVExecutionMode::DerivativeGroupLinearKHR - : SPIRVExecutionMode::DerivativeGroupQuadsKHR; MDNode *MD = MDNode::get( M.getContext(), {ValueAsMetadata::get(F), - ConstantAsMetadata::get(B.getInt32(llvm::to_underlying(Mode)))}); + ConstantAsMetadata::get(B.getInt32(llvm::to_underlying(*Mode)))}); M.getOrInsertNamedMetadata("spirv.ExecutionMode")->addOperand(MD); } >From 3bad2efe250ddfd6be925294ae618fd690c2e5ef Mon Sep 17 00:00:00 2001 From: Joshua Batista <[email protected]> Date: Fri, 13 Nov 2026 15:12:05 -0800 Subject: [PATCH 7/9] generalize diagnostic message and name --- clang/include/clang/Basic/DiagnosticFrontendKinds.td | 4 ++-- clang/lib/CodeGen/CGHLSLRuntime.cpp | 2 +- .../builtins/QuadAll-derivative-group-errors.hlsl | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index be82686552733..cff8808f7d7b1 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -504,8 +504,8 @@ def warn_hlsl_langstd_minimal : InGroup<HLSLDXCCompat>; def err_hlsl_signature_packing : Error< "failed to pack %select{input|output}0 signature: %1">; -def err_hlsl_spirv_quad_all_numthreads : Error< - "entry point '%0' uses QuadAll with invalid numthreads: " +def err_hlsl_spirv_derivative_group_numthreads : Error< + "entry point '%0' has invalid numthreads: " "%select{DerivativeGroupQuadsKHR requires X and Y to be multiples of 2|" "DerivativeGroupLinearKHR requires X * Y * Z to be a multiple of 4}1">; def warn_hlsl_signature_packing_ignored : Warning< diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 1958761ffec1b..b4c3a5278d601 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -1020,7 +1020,7 @@ getSPIRVDerivativeGroupMode(CodeGenModule &CGM, const Function &F) { bool IsLinear = Threads[1] == 1 && Threads[2] == 1; if (IsLinear ? (uint64_t(Threads[0]) * Threads[1] * Threads[2]) % 4 != 0 : Threads[0] % 2 != 0 || Threads[1] % 2 != 0) { - CGM.getDiags().Report(diag::err_hlsl_spirv_quad_all_numthreads) + CGM.getDiags().Report(diag::err_hlsl_spirv_derivative_group_numthreads) << F.getName() << IsLinear; return std::nullopt; } diff --git a/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group-errors.hlsl b/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group-errors.hlsl index 29574af763267..cbc18c4e06e97 100644 --- a/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group-errors.hlsl +++ b/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group-errors.hlsl @@ -51,7 +51,7 @@ void invalid_quad_3d() { [numthreads(3, 1, 1)] void no_vote() {} -// CHECK-DAG: error: entry point 'invalid_linear' uses QuadAll with invalid numthreads: DerivativeGroupLinearKHR requires X * Y * Z to be a multiple of 4 -// CHECK-DAG: error: entry point 'invalid_quad_x' uses QuadAll with invalid numthreads: DerivativeGroupQuadsKHR requires X and Y to be multiples of 2 -// CHECK-DAG: error: entry point 'invalid_quad_y' uses QuadAll with invalid numthreads: DerivativeGroupQuadsKHR requires X and Y to be multiples of 2 -// CHECK-DAG: error: entry point 'invalid_quad_3d' uses QuadAll with invalid numthreads: DerivativeGroupQuadsKHR requires X and Y to be multiples of 2 +// CHECK-DAG: error: entry point 'invalid_linear' has invalid numthreads: DerivativeGroupLinearKHR requires X * Y * Z to be a multiple of 4 +// CHECK-DAG: error: entry point 'invalid_quad_x' has invalid numthreads: DerivativeGroupQuadsKHR requires X and Y to be multiples of 2 +// CHECK-DAG: error: entry point 'invalid_quad_y' has invalid numthreads: DerivativeGroupQuadsKHR requires X and Y to be multiples of 2 +// CHECK-DAG: error: entry point 'invalid_quad_3d' has invalid numthreads: DerivativeGroupQuadsKHR requires X and Y to be multiples of 2 >From a5e659b74819d3549df7f60a074021b04c21a519 Mon Sep 17 00:00:00 2001 From: Joshua Batista <[email protected]> Date: Fri, 13 Nov 2026 16:25:33 -0800 Subject: [PATCH 8/9] add context that quadall is causing the error --- clang/include/clang/Basic/DiagnosticFrontendKinds.td | 3 +++ clang/lib/CodeGen/CGHLSLRuntime.cpp | 6 +++++- .../builtins/QuadAll-derivative-group-errors.hlsl | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td b/clang/include/clang/Basic/DiagnosticFrontendKinds.td index cff8808f7d7b1..5ec3d1bb1114e 100644 --- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td +++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td @@ -508,6 +508,9 @@ def err_hlsl_spirv_derivative_group_numthreads : Error< "entry point '%0' has invalid numthreads: " "%select{DerivativeGroupQuadsKHR requires X and Y to be multiples of 2|" "DerivativeGroupLinearKHR requires X * Y * Z to be a multiple of 4}1">; +def note_hlsl_spirv_derivative_group_requirement : Note< + "'%0' implicitly requires a derivative group execution mode " + "for SPIR-V entry point '%1'">; def warn_hlsl_signature_packing_ignored : Warning< "semantic signature packing mode '%0' is ignored as " "%select{vertex shader inputs|pixel shader outputs}1 always use " diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index b4c3a5278d601..3be39712b5cab 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -1046,8 +1046,12 @@ static void addSPIRVQuadAllExecutionModes(CodeGenModule &CGM) { if (F->hasFnAttribute("hlsl.numthreads")) { std::optional<SPIRVExecutionMode> Mode = getSPIRVDerivativeGroupMode(CGM, *F); - if (!Mode) + if (!Mode) { + CGM.getDiags().Report( + diag::note_hlsl_spirv_derivative_group_requirement) + << "QuadAll" << F->getName(); continue; + } MDNode *MD = MDNode::get( M.getContext(), {ValueAsMetadata::get(F), diff --git a/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group-errors.hlsl b/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group-errors.hlsl index cbc18c4e06e97..03e7962faf061 100644 --- a/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group-errors.hlsl +++ b/clang/test/CodeGenHLSL/builtins/QuadAll-derivative-group-errors.hlsl @@ -52,6 +52,10 @@ void invalid_quad_3d() { void no_vote() {} // CHECK-DAG: error: entry point 'invalid_linear' has invalid numthreads: DerivativeGroupLinearKHR requires X * Y * Z to be a multiple of 4 +// CHECK-DAG: note: 'QuadAll' implicitly requires a derivative group execution mode for SPIR-V entry point 'invalid_linear' // CHECK-DAG: error: entry point 'invalid_quad_x' has invalid numthreads: DerivativeGroupQuadsKHR requires X and Y to be multiples of 2 +// CHECK-DAG: note: 'QuadAll' implicitly requires a derivative group execution mode for SPIR-V entry point 'invalid_quad_x' // CHECK-DAG: error: entry point 'invalid_quad_y' has invalid numthreads: DerivativeGroupQuadsKHR requires X and Y to be multiples of 2 +// CHECK-DAG: note: 'QuadAll' implicitly requires a derivative group execution mode for SPIR-V entry point 'invalid_quad_y' // CHECK-DAG: error: entry point 'invalid_quad_3d' has invalid numthreads: DerivativeGroupQuadsKHR requires X and Y to be multiples of 2 +// CHECK-DAG: note: 'QuadAll' implicitly requires a derivative group execution mode for SPIR-V entry point 'invalid_quad_3d' >From 7ea001b2e59883846da41c5132688536e21f413b Mon Sep 17 00:00:00 2001 From: Joshua Batista <[email protected]> Date: Fri, 13 Nov 2026 17:05:48 -0800 Subject: [PATCH 9/9] address recent validator updates Co-authored-by: Copilot <[email protected]> Copilot-Session: 365638e8-2291-4925-8f1e-1b5c23220818 --- .../cooperative_matrix.ll | 34 +++++++++---------- .../untyped-ptr-coopmatrix.ll | 10 +++--- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_cooperative_matrix/cooperative_matrix.ll b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_cooperative_matrix/cooperative_matrix.ll index ad9425afe6394..2502883ec35ba 100644 --- a/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_cooperative_matrix/cooperative_matrix.ll +++ b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_cooperative_matrix/cooperative_matrix.ll @@ -37,17 +37,17 @@ ; CHECK: OpCooperativeMatrixMulAddKHR %[[#MatTy6]] %[[#MatA]] %[[#MatB]] %[[#MatC]] MatrixASignedComponentsKHR|MatrixBSignedComponentsKHR ; CHECK: OpCooperativeMatrixStoreKHR -define spir_kernel void @matr_mult(ptr addrspace(1) align 1 %_arg_accA, ptr addrspace(1) align 1 %_arg_accB, ptr addrspace(1) align 4 %_arg_accC, i64 %_arg_N, i64 %_arg_K) { +define spir_kernel void @matr_mult(ptr addrspace(1) align 1 %_arg_accA, ptr addrspace(1) align 1 %_arg_accB, ptr addrspace(1) align 4 %_arg_accC, i32 %_arg_N, i32 %_arg_K) { entry: %addr1 = alloca target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2), align 8 %res = alloca target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2), align 8 %m1 = tail call spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2) @_Z26__spirv_CompositeConstruct(i32 0) store target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2) %m1, ptr %addr1, align 8 %accA3 = addrspacecast ptr addrspace(1) %_arg_accA to ptr addrspace(3) - %m2 = tail call spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 12, 48, 0) @_Z32__spirv_CooperativeMatrixLoadKHR_1(ptr addrspace(3) %accA3, i32 0, i64 %_arg_K, i32 1) + %m2 = tail call spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 12, 48, 0) @_Z32__spirv_CooperativeMatrixLoadKHR_1(ptr addrspace(3) %accA3, i32 0, i32 %_arg_K, i32 1) %len = tail call spir_func i32 @_Z34__spirv_CooperativeMatrixLengthKHR(target("spirv.CooperativeMatrixKHR", i32, 3, 12, 48, 0) %m2) %accB3 = addrspacecast ptr addrspace(1) %_arg_accB to ptr addrspace(3) - %m3 = tail call spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 48, 12, 1) @_Z32__spirv_CooperativeMatrixLoadKHR_2(ptr addrspace(3) %accB3, i32 0, i64 0) + %m3 = tail call spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 48, 12, 1) @_Z32__spirv_CooperativeMatrixLoadKHR_2(ptr addrspace(3) %accB3, i32 0, i32 0) %m4 = load target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2), ptr %addr1, align 8 %m5 = tail call spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2) @_Z34__spirv_CooperativeMatrixMulAddKHR(target("spirv.CooperativeMatrixKHR", i32, 3, 12, 48, 0) %m2, target("spirv.CooperativeMatrixKHR", i32, 3, 48, 12, 1) %m3, target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2) %m4, i32 12) store target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2) %m5, ptr %res, align 8 @@ -55,34 +55,34 @@ entry: store i64 %r, ptr %addr1, align 8 %accC3 = addrspacecast ptr addrspace(1) %_arg_accC to ptr addrspace(3) %m6 = load target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2), ptr %addr1, align 8 - tail call spir_func void @_Z33__spirv_CooperativeMatrixStoreKHR(ptr addrspace(3) %accC3, target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2) %m6, i32 0, i64 %_arg_N, i32 1) + tail call spir_func void @_Z33__spirv_CooperativeMatrixStoreKHR(ptr addrspace(3) %accC3, target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2) %m6, i32 0, i32 %_arg_N, i32 1) ret void } -define spir_kernel void @matr_mult_with_complex_mangling(ptr addrspace(1) %_arg_A, ptr addrspace(1) %_arg_B, i64 %_arg_M, i64 %_arg_N) { +define spir_kernel void @matr_mult_with_complex_mangling(ptr addrspace(1) %_arg_A, ptr addrspace(1) %_arg_B, i32 %_arg_M, i32 %_arg_N) { entry: - ; __spv::__spirv_CooperativeMatrixKHR<short, (__spv::Scope::Flag)3, 8ul, 16ul, (__spv::MatrixUse)0>* __spirv_CooperativeMatrixLoadKHR<short AS1, short, 8ul, 16ul, (__spv::MatrixUse)0, (__spv::MatrixLayout)1, (__spv::Scope::Flag)3>(short AS1*, __spv::MatrixLayout, unsigned long, int) - %call = call spir_func target("spirv.CooperativeMatrixKHR", i16, 3, 8, 16, 0) @_Z32__spirv_CooperativeMatrixLoadKHRIU3AS1ssLm8ELm16ELN5__spv9MatrixUseE0ELNS1_12MatrixLayoutE1ELNS1_5Scope4FlagE3EEPNS1_28__spirv_CooperativeMatrixKHRIT0_XT5_EXT1_EXT2_EXT3_EEEPT_S3_mi(ptr addrspace(1) %_arg_A, i32 1, i64 %_arg_M, i32 0) - ; __spv::__spirv_CooperativeMatrixKHR<short, (__spv::Scope::Flag)3, 16ul, 16ul, (__spv::MatrixUse)1>* __spirv_CooperativeMatrixLoadKHR<short AS1, short, 16ul, 16ul, (__spv::MatrixUse)1, (__spv::MatrixLayout)0, (__spv::Scope::Flag)3>(short AS1*, __spv::MatrixLayout, unsigned long, int) - %call1 = call spir_func target("spirv.CooperativeMatrixKHR", i16, 3, 16, 16, 1) @_Z32__spirv_CooperativeMatrixLoadKHRIU3AS1ssLm16ELm16ELN5__spv9MatrixUseE1ELNS1_12MatrixLayoutE0ELNS1_5Scope4FlagE3EEPNS1_28__spirv_CooperativeMatrixKHRIT0_XT5_EXT1_EXT2_EXT3_EEEPT_S3_mi(ptr addrspace(1) %_arg_B, i32 0, i64 %_arg_N, i32 0) + ; __spv::__spirv_CooperativeMatrixKHR<short, (__spv::Scope::Flag)3, 8ul, 16ul, (__spv::MatrixUse)0>* __spirv_CooperativeMatrixLoadKHR<short AS1, short, 8ul, 16ul, (__spv::MatrixUse)0, (__spv::MatrixLayout)1, (__spv::Scope::Flag)3>(short AS1*, __spv::MatrixLayout, unsigned int, int) + %call = call spir_func target("spirv.CooperativeMatrixKHR", i16, 3, 8, 16, 0) @_Z32__spirv_CooperativeMatrixLoadKHRIU3AS1ssLm8ELm16ELN5__spv9MatrixUseE0ELNS1_12MatrixLayoutE1ELNS1_5Scope4FlagE3EEPNS1_28__spirv_CooperativeMatrixKHRIT0_XT5_EXT1_EXT2_EXT3_EEEPT_S3_ji(ptr addrspace(1) %_arg_A, i32 1, i32 %_arg_M, i32 0) + ; __spv::__spirv_CooperativeMatrixKHR<short, (__spv::Scope::Flag)3, 16ul, 16ul, (__spv::MatrixUse)1>* __spirv_CooperativeMatrixLoadKHR<short AS1, short, 16ul, 16ul, (__spv::MatrixUse)1, (__spv::MatrixLayout)0, (__spv::Scope::Flag)3>(short AS1*, __spv::MatrixLayout, unsigned int, int) + %call1 = call spir_func target("spirv.CooperativeMatrixKHR", i16, 3, 16, 16, 1) @_Z32__spirv_CooperativeMatrixLoadKHRIU3AS1ssLm16ELm16ELN5__spv9MatrixUseE1ELNS1_12MatrixLayoutE0ELNS1_5Scope4FlagE3EEPNS1_28__spirv_CooperativeMatrixKHRIT0_XT5_EXT1_EXT2_EXT3_EEEPT_S3_ji(ptr addrspace(1) %_arg_B, i32 0, i32 %_arg_N, i32 0) ; __spv::__spirv_CooperativeMatrixKHR<int, (__spv::Scope::Flag)3, 8ul, 16ul, (__spv::MatrixUse)2>* __spirv_CompositeConstruct<int, int, 8ul, 16ul, (__spv::MatrixUse)2, (__spv::MatrixLayout)3, (__spv::Scope::Flag)3>(int) %call2 = tail call spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 8, 16, 2) @_Z26__spirv_CompositeConstructIiiLm8ELm16ELN5__spv9MatrixUseE2ELNS0_12MatrixLayoutE3ELNS0_5Scope4FlagE3EEPNS0_28__spirv_CooperativeMatrixKHRIT0_XT5_EXT1_EXT2_EXT3_EEET_(i32 1) ; __spv::__spirv_CooperativeMatrixKHR<int, (__spv::Scope::Flag)3, 8ul, 16ul, (__spv::MatrixUse)2>* __spirv_CooperativeMatrixMulAddKHR<short, short, int, int, 8ul, 16ul, 16ul, (__spv::MatrixUse)0, (__spv::MatrixUse)1, (__spv::MatrixUse)2, (__spv::MatrixLayout)0, (__spv::MatrixLayout)0, (__spv::MatrixLayout)0, (__spv::Scope::Flag)3>(__spv::__spirv_CooperativeMatrixKHR<short, (__spv::Scope::Flag)3, 8ul, 16ul, (__spv::MatrixUse)0>*, __spv::__spirv_CooperativeMatrixKHR<short, (__spv::Scope::Flag)3, 16ul, 16ul, (__spv::MatrixUse)1>*, __spv::__spirv_CooperativeMatrixKHR<int, (__spv::Scope::Flag)3, 8ul, 16ul, (__spv::MatrixUse)2>*, unsigned long) %call3 = tail call spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 8, 16, 2) @_Z34__spirv_CooperativeMatrixMulAddKHRIssiiLm8ELm16ELm16ELN5__spv9MatrixUseE0ELS1_1ELS1_2ELNS0_12MatrixLayoutE0ELS2_0ELS2_0ELNS0_5Scope4FlagE3EEPNS0_28__spirv_CooperativeMatrixKHRIT2_XT12_EXT3_EXT5_EXT8_EEEPNS5_IT_XT12_EXT3_EXT4_EXT6_EEEPNS5_IT0_XT12_EXT4_EXT5_EXT7_EEEPNS5_IT1_XT12_EXT3_EXT5_EXT8_EEEm(target("spirv.CooperativeMatrixKHR", i16, 3, 8, 16, 0) %call, target("spirv.CooperativeMatrixKHR", i16, 3, 16, 16, 1) %call1, target("spirv.CooperativeMatrixKHR", i32, 3, 8, 16, 2) %call2, i64 3) - ; void __spirv_CooperativeMatrixStoreKHR<int AS1, int, 8ul, 16ul, (__spv::MatrixUse)2, (__spv::MatrixLayout)3, (__spv::Scope::Flag)3>(int AS1*, __spv::__spirv_CooperativeMatrixKHR<int, (__spv::Scope::Flag)3, 8ul, 16ul, (__spv::MatrixUse)2>*, __spv::MatrixLayout, unsigned long, int) - call spir_func void @_Z33__spirv_CooperativeMatrixStoreKHRIU3AS1iiLm8ELm16ELN5__spv9MatrixUseE2ELNS1_12MatrixLayoutE3ELNS1_5Scope4FlagE3EEvPT_PNS1_28__spirv_CooperativeMatrixKHRIT0_XT5_EXT1_EXT2_EXT3_EEES3_mi(ptr addrspace(1) %_arg_A, target("spirv.CooperativeMatrixKHR", i32, 3, 8, 16, 2) %call2, i32 1, i64 %_arg_M, i32 0) + ; void __spirv_CooperativeMatrixStoreKHR<int AS1, int, 8ul, 16ul, (__spv::MatrixUse)2, (__spv::MatrixLayout)3, (__spv::Scope::Flag)3>(int AS1*, __spv::__spirv_CooperativeMatrixKHR<int, (__spv::Scope::Flag)3, 8ul, 16ul, (__spv::MatrixUse)2>*, __spv::MatrixLayout, unsigned int, int) + call spir_func void @_Z33__spirv_CooperativeMatrixStoreKHRIU3AS1iiLm8ELm16ELN5__spv9MatrixUseE2ELNS1_12MatrixLayoutE3ELNS1_5Scope4FlagE3EEvPT_PNS1_28__spirv_CooperativeMatrixKHRIT0_XT5_EXT1_EXT2_EXT3_EEES3_ji(ptr addrspace(1) %_arg_A, target("spirv.CooperativeMatrixKHR", i32, 3, 8, 16, 2) %call2, i32 1, i32 %_arg_M, i32 0) ret void } declare dso_local spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2) @_Z26__spirv_CompositeConstruct(i32) declare dso_local spir_func i32 @_Z34__spirv_CooperativeMatrixLengthKHR(target("spirv.CooperativeMatrixKHR", i32, 3, 12, 48, 0)) -declare dso_local spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 12, 48, 0) @_Z32__spirv_CooperativeMatrixLoadKHR_1(ptr addrspace(3), i32, i64, i32) -declare dso_local spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 48, 12, 1) @_Z32__spirv_CooperativeMatrixLoadKHR_2(ptr addrspace(3), i32, i64) +declare dso_local spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 12, 48, 0) @_Z32__spirv_CooperativeMatrixLoadKHR_1(ptr addrspace(3), i32, i32, i32) +declare dso_local spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 48, 12, 1) @_Z32__spirv_CooperativeMatrixLoadKHR_2(ptr addrspace(3), i32, i32) declare dso_local spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2) @_Z34__spirv_CooperativeMatrixMulAddKHR(target("spirv.CooperativeMatrixKHR", i32, 3, 12, 48, 0), target("spirv.CooperativeMatrixKHR", i32, 3, 48, 12, 1), target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2), i32) -declare dso_local spir_func void @_Z33__spirv_CooperativeMatrixStoreKHR(ptr addrspace(3), target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2), i32, i64, i32) +declare dso_local spir_func void @_Z33__spirv_CooperativeMatrixStoreKHR(ptr addrspace(3), target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2), i32, i32, i32) declare dso_local spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 8, 16, 2) @_Z26__spirv_CompositeConstructIiiLm8ELm16ELN5__spv9MatrixUseE2ELNS0_12MatrixLayoutE3ELNS0_5Scope4FlagE3EEPNS0_28__spirv_CooperativeMatrixKHRIT0_XT5_EXT1_EXT2_EXT3_EEET_(i32) -declare dso_local spir_func target("spirv.CooperativeMatrixKHR", i16, 3, 8, 16, 0) @_Z32__spirv_CooperativeMatrixLoadKHRIU3AS1ssLm8ELm16ELN5__spv9MatrixUseE0ELNS1_12MatrixLayoutE1ELNS1_5Scope4FlagE3EEPNS1_28__spirv_CooperativeMatrixKHRIT0_XT5_EXT1_EXT2_EXT3_EEEPT_S3_mi(ptr addrspace(1), i32, i64, i32) -declare dso_local spir_func target("spirv.CooperativeMatrixKHR", i16, 3, 16, 16, 1) @_Z32__spirv_CooperativeMatrixLoadKHRIU3AS1ssLm16ELm16ELN5__spv9MatrixUseE1ELNS1_12MatrixLayoutE0ELNS1_5Scope4FlagE3EEPNS1_28__spirv_CooperativeMatrixKHRIT0_XT5_EXT1_EXT2_EXT3_EEEPT_S3_mi(ptr addrspace(1), i32, i64, i32) +declare dso_local spir_func target("spirv.CooperativeMatrixKHR", i16, 3, 8, 16, 0) @_Z32__spirv_CooperativeMatrixLoadKHRIU3AS1ssLm8ELm16ELN5__spv9MatrixUseE0ELNS1_12MatrixLayoutE1ELNS1_5Scope4FlagE3EEPNS1_28__spirv_CooperativeMatrixKHRIT0_XT5_EXT1_EXT2_EXT3_EEEPT_S3_ji(ptr addrspace(1), i32, i32, i32) +declare dso_local spir_func target("spirv.CooperativeMatrixKHR", i16, 3, 16, 16, 1) @_Z32__spirv_CooperativeMatrixLoadKHRIU3AS1ssLm16ELm16ELN5__spv9MatrixUseE1ELNS1_12MatrixLayoutE0ELNS1_5Scope4FlagE3EEPNS1_28__spirv_CooperativeMatrixKHRIT0_XT5_EXT1_EXT2_EXT3_EEEPT_S3_ji(ptr addrspace(1), i32, i32, i32) declare dso_local spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 8, 16, 2) @_Z34__spirv_CooperativeMatrixMulAddKHRIssiiLm8ELm16ELm16ELN5__spv9MatrixUseE0ELS1_1ELS1_2ELNS0_12MatrixLayoutE0ELS2_0ELS2_0ELNS0_5Scope4FlagE3EEPNS0_28__spirv_CooperativeMatrixKHRIT2_XT12_EXT3_EXT5_EXT8_EEEPNS5_IT_XT12_EXT3_EXT4_EXT6_EEEPNS5_IT0_XT12_EXT4_EXT5_EXT7_EEEPNS5_IT1_XT12_EXT3_EXT5_EXT8_EEEm(target("spirv.CooperativeMatrixKHR", i16, 3, 8, 16, 0), target("spirv.CooperativeMatrixKHR", i16, 3, 16, 16, 1), target("spirv.CooperativeMatrixKHR", i32, 3, 8, 16, 2), i64) -declare dso_local spir_func void @_Z33__spirv_CooperativeMatrixStoreKHRIU3AS1iiLm8ELm16ELN5__spv9MatrixUseE2ELNS1_12MatrixLayoutE3ELNS1_5Scope4FlagE3EEvPT_PNS1_28__spirv_CooperativeMatrixKHRIT0_XT5_EXT1_EXT2_EXT3_EEES3_mi(ptr addrspace(1), target("spirv.CooperativeMatrixKHR", i32, 3, 8, 16, 2), i32, i64, i32) +declare dso_local spir_func void @_Z33__spirv_CooperativeMatrixStoreKHRIU3AS1iiLm8ELm16ELN5__spv9MatrixUseE2ELNS1_12MatrixLayoutE3ELNS1_5Scope4FlagE3EEvPT_PNS1_28__spirv_CooperativeMatrixKHRIT0_XT5_EXT1_EXT2_EXT3_EEES3_ji(ptr addrspace(1), target("spirv.CooperativeMatrixKHR", i32, 3, 8, 16, 2), i32, i32, i32) diff --git a/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_untyped_pointers/untyped-ptr-coopmatrix.ll b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_untyped_pointers/untyped-ptr-coopmatrix.ll index 2b77049a95aaa..bca423233be98 100644 --- a/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_untyped_pointers/untyped-ptr-coopmatrix.ll +++ b/llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_untyped_pointers/untyped-ptr-coopmatrix.ll @@ -6,10 +6,10 @@ ; CHECK-DAG: %[[#CROSS:]] = OpTypeUntypedPointerKHR CrossWorkgroup ; CHECK: OpCooperativeMatrixLoadKHR ; CHECK: OpCooperativeMatrixStoreKHR -define spir_kernel void @t(ptr addrspace(1) %src, ptr addrspace(1) %dst, i64 %stride) { - %m = tail call spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2) @_Z32__spirv_CooperativeMatrixLoadKHR(ptr addrspace(1) %src, i32 0, i64 %stride, i32 1) - tail call spir_func void @_Z33__spirv_CooperativeMatrixStoreKHR(ptr addrspace(1) %dst, target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2) %m, i32 0, i64 %stride, i32 1) +define spir_kernel void @t(ptr addrspace(1) %src, ptr addrspace(1) %dst, i32 %stride) { + %m = tail call spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2) @_Z32__spirv_CooperativeMatrixLoadKHR(ptr addrspace(1) %src, i32 0, i32 %stride, i32 1) + tail call spir_func void @_Z33__spirv_CooperativeMatrixStoreKHR(ptr addrspace(1) %dst, target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2) %m, i32 0, i32 %stride, i32 1) ret void } -declare spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2) @_Z32__spirv_CooperativeMatrixLoadKHR(ptr addrspace(1), i32, i64, i32) -declare spir_func void @_Z33__spirv_CooperativeMatrixStoreKHR(ptr addrspace(1), target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2), i32, i64, i32) +declare spir_func target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2) @_Z32__spirv_CooperativeMatrixLoadKHR(ptr addrspace(1), i32, i32, i32) +declare spir_func void @_Z33__spirv_CooperativeMatrixStoreKHR(ptr addrspace(1), target("spirv.CooperativeMatrixKHR", i32, 3, 12, 12, 2), i32, i32, i32) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
