https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/244046

>From aff38d95748915d39068712f53fc0c4b8d8d633b Mon Sep 17 00:00:00 2001
From: Joshua Batista <[email protected]>
Date: Wed, 18 Nov 2026 15:20:16 -0800
Subject: [PATCH 1/2] first attempt

---
 .../clang/Basic/DiagnosticSemaKinds.td        |   2 +
 clang/lib/Sema/SemaHLSL.cpp                   |  23 ++++
 .../BuiltIns/QuadAll-availability.hlsl        |   5 +-
 .../BuiltIns/QuadAll-stage-errors.hlsl        | 124 ++++++++++++++++++
 .../llvm/Frontend/HLSL/IntrinsicStageInfo.h   |  37 ++++++
 llvm/lib/Frontend/HLSL/CMakeLists.txt         |   7 +
 llvm/lib/Frontend/HLSL/IntrinsicStageInfo.cpp |  44 +++++++
 llvm/lib/Target/DirectX/DXIL.td               |  15 ++-
 .../Target/DirectX/DXILIntrinsicExpansion.cpp |  47 +++++++
 .../CodeGen/DirectX/QuadAll-stage-errors.ll   | 111 ++++++++++++++++
 llvm/utils/TableGen/DXILEmitter.cpp           |  25 ++++
 11 files changed, 436 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl
 create mode 100644 llvm/include/llvm/Frontend/HLSL/IntrinsicStageInfo.h
 create mode 100644 llvm/lib/Frontend/HLSL/IntrinsicStageInfo.cpp
 create mode 100644 llvm/test/CodeGen/DirectX/QuadAll-stage-errors.ll

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 56929fb4f89cee..f930dafaafab86 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -13861,6 +13861,8 @@ def err_hlsl_mult_inheritance : Error<"HLSL does not 
support multiple inheritanc
 def err_hlsl_cstor_dstor : Error<"HLSL does not support constructors or 
destructors">;
 def err_hlsl_langstd_unimplemented : Error<"support for HLSL language version 
%0 is incomplete">;
 def err_hlsl_attr_unsupported_in_stage : Error<"attribute %0 is unsupported in 
'%1' shaders, requires %select{|one of the following: }2%3">;
+def err_hlsl_intrinsic_unsupported_in_stage : Error<
+  "'%0' is not supported in '%1' shaders for DirectX; supported stages: %2">;
 def err_hlsl_attr_invalid_type : Error<
    "attribute %0 only applies to a field or parameter of type '%1'">;
 def err_hlsl_attr_invalid_ast_node : Error<
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 7627bb10ccf6f1..36e038099e1dc3 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -42,6 +42,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Frontend/HLSL/HLSLBinding.h"
+#include "llvm/Frontend/HLSL/IntrinsicStageInfo.h"
 #include "llvm/Frontend/HLSL/RootSignatureValidations.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/DXILABI.h"
@@ -3307,6 +3308,7 @@ class DiagnoseHLSLAvailability : public 
DynamicRecursiveASTVisitor {
                              SourceRange Range);
   const AvailabilityAttr *FindAvailabilityAttr(const Decl *D);
   bool HasMatchingEnvironmentOrNone(const AvailabilityAttr *AA);
+  void DiagnoseIntrinsicStage(CallExpr *CE);
   void DiagnoseBarrierCall(CallExpr *CE);
   uint64_t DiagnoseBarrierGroupMemory(Expr *MemoryArg, uint64_t MemoryFlags,
                                       bool HasVisibleGroup, bool IsAllMemory);
@@ -3342,11 +3344,32 @@ class DiagnoseHLSLAvailability : public 
DynamicRecursiveASTVisitor {
   }
 
   bool VisitCallExpr(CallExpr *CE) override {
+    DiagnoseIntrinsicStage(CE);
     DiagnoseBarrierCall(CE);
     return true;
   }
 };
 
+void DiagnoseHLSLAvailability::DiagnoseIntrinsicStage(CallExpr *CE) {
+  if (!SemaRef.Context.getTargetInfo().getTriple().isDXIL() ||
+      InUnknownShaderStageContext())
+    return;
+
+  const FunctionDecl *FD = CE->getDirectCallee();
+  if (!FD || !FD->getBuiltinID())
+    return;
+
+  const auto *Info = llvm::hlsl::getDXILIntrinsicStageInfo(
+      SemaRef.Context.BuiltinInfo.getName(FD->getBuiltinID()));
+  StringRef Stage =
+      llvm::Triple::getEnvironmentTypeName(GetCurrentShaderEnvironment());
+  if (!Info || Info->isSupportedIn(Stage))
+    return;
+
+  SemaRef.Diag(CE->getExprLoc(), diag::err_hlsl_intrinsic_unsupported_in_stage)
+      << Info->Name << Stage << Info->getStageNames();
+}
+
 uint64_t DiagnoseHLSLAvailability::DiagnoseBarrierGroupMemory(
     Expr *MemoryArg, uint64_t MemoryFlags, bool HasVisibleGroup,
     bool IsAllMemory) {
diff --git a/clang/test/SemaHLSL/BuiltIns/QuadAll-availability.hlsl 
b/clang/test/SemaHLSL/BuiltIns/QuadAll-availability.hlsl
index b9104e47fc1323..fd29c6afd25389 100644
--- a/clang/test/SemaHLSL/BuiltIns/QuadAll-availability.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/QuadAll-availability.hlsl
@@ -7,12 +7,11 @@
 // RUN: %clang_cc1 -finclude-default-header -triple \
 // RUN:   dxil-pc-shadermodel6.7-library %s -fhlsl-strict-availability \
 // RUN:   -fsyntax-only -verify
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN:   spirv-pc-vulkan-library %s -fsyntax-only -verify
 
 // expected-no-diagnostics
 
-// TODO: Test vulkan targets after 
-// https://github.com/llvm/llvm-project/issues/243266 is resolved.
-
 bool test_availability(bool cond) {
   return QuadAll(cond);
 }
diff --git a/clang/test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl
new file mode 100644
index 00000000000000..7483d9584cb24e
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl
@@ -0,0 +1,124 @@
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN:   dxil-pc-shadermodel6.0-library %s -fsyntax-only -verify=dxil
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN:   dxil-pc-shadermodel6.6-library %s -fsyntax-only -verify=dxil
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN:   dxil-pc-shadermodel6.7-library %s -fsyntax-only -verify=dxil
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN:   dxil-pc-shadermodel6.7-library %s -fhlsl-strict-availability \
+// RUN:   -fsyntax-only -verify=dxil
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN:   spirv-pc-vulkan-library %s -fsyntax-only -verify=spirv
+// RUN: %clang_cc1 -finclude-default-header -triple \
+// RUN:   spirv-pc-vulkan-library %s -emit-llvm -disable-llvm-passes -o - \
+// RUN:   | FileCheck %s --check-prefix=SPIRV
+
+// SPIRV: call i1 @llvm.spv.quad.all
+
+// spirv-no-diagnostics
+
+bool shared(bool cond) {
+  return QuadAll(cond); // #shared
+  // dxil-error@#shared {{'QuadAll' is not supported in 'vertex' shaders}}
+  // dxil-error@#shared {{'QuadAll' is not supported in 'geometry' shaders}}
+}
+
+bool indirect(bool cond) {
+  return shared(cond);
+}
+
+[shader("vertex")]
+void vertex() {
+  indirect(true);
+  (void)__builtin_hlsl_quad_all(true);
+  // dxil-error@-1 {{'QuadAll' is not supported in 'vertex' shaders}}
+}
+
+[shader("vertex")]
+void another_vertex() {
+  indirect(false);
+}
+
+[shader("geometry")]
+void geometry() {
+  shared(true);
+}
+
+[shader("hull")]
+void hull() {
+  (void)QuadAll(true);
+  // dxil-error@-1 {{'QuadAll' is not supported in 'hull' shaders}}
+}
+
+[shader("domain")]
+void domain() {
+  (void)QuadAll(true);
+  // dxil-error@-1 {{'QuadAll' is not supported in 'domain' shaders}}
+}
+
+[shader("raygeneration")]
+void raygeneration() {
+  (void)QuadAll(true);
+  // dxil-error@-1 {{'QuadAll' is not supported in 'raygeneration' shaders}}
+}
+
+[shader("intersection")]
+void intersection() {
+  (void)QuadAll(true);
+  // dxil-error@-1 {{'QuadAll' is not supported in 'intersection' shaders}}
+}
+
+[shader("anyhit")]
+void anyhit() {
+  (void)QuadAll(true);
+  // dxil-error@-1 {{'QuadAll' is not supported in 'anyhit' shaders}}
+}
+
+[shader("closesthit")]
+void closesthit() {
+  (void)QuadAll(true);
+  // dxil-error@-1 {{'QuadAll' is not supported in 'closesthit' shaders}}
+}
+
+[shader("miss")]
+void miss() {
+  (void)QuadAll(true);
+  // dxil-error@-1 {{'QuadAll' is not supported in 'miss' shaders}}
+}
+
+[shader("callable")]
+void callable() {
+  (void)QuadAll(true);
+  // dxil-error@-1 {{'QuadAll' is not supported in 'callable' shaders}}
+}
+
+[shader("pixel")]
+void pixel() {
+  indirect(true);
+}
+
+[shader("compute")]
+[numthreads(4, 2, 1)]
+void compute() {
+  indirect(true);
+}
+
+[shader("mesh")]
+[numthreads(4, 2, 1)]
+void mesh() {
+  indirect(true);
+}
+
+[shader("amplification")]
+[numthreads(4, 2, 1)]
+void amplification() {
+  indirect(true);
+}
+
+export bool exported(bool cond) {
+  return shared(cond);
+}
+
+bool unused(bool cond) {
+  return QuadAll(cond);
+}
diff --git a/llvm/include/llvm/Frontend/HLSL/IntrinsicStageInfo.h 
b/llvm/include/llvm/Frontend/HLSL/IntrinsicStageInfo.h
new file mode 100644
index 00000000000000..e242a6a1e3c86e
--- /dev/null
+++ b/llvm/include/llvm/Frontend/HLSL/IntrinsicStageInfo.h
@@ -0,0 +1,37 @@
+//===- IntrinsicStageInfo.h - Intrinsic stage availability -------*- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_FRONTEND_HLSL_INTRINSICSTAGEINFO_H
+#define LLVM_FRONTEND_HLSL_INTRINSICSTAGEINFO_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/Support/Compiler.h"
+#include <string>
+
+namespace llvm::hlsl {
+
+struct IntrinsicStageInfo {
+  Intrinsic::ID ID;
+  StringRef BuiltinName;
+  StringRef Name;
+  ArrayRef<StringRef> Stages;
+
+  LLVM_ABI bool isSupportedIn(StringRef Stage) const;
+  LLVM_ABI std::string getStageNames() const;
+};
+
+LLVM_ABI ArrayRef<IntrinsicStageInfo> getDXILIntrinsicStageInfos();
+LLVM_ABI const IntrinsicStageInfo *
+getDXILIntrinsicStageInfo(StringRef BuiltinName);
+
+} // namespace llvm::hlsl
+
+#endif
diff --git a/llvm/lib/Frontend/HLSL/CMakeLists.txt 
b/llvm/lib/Frontend/HLSL/CMakeLists.txt
index 4703458c681681..948ec7dc4cad8e 100644
--- a/llvm/lib/Frontend/HLSL/CMakeLists.txt
+++ b/llvm/lib/Frontend/HLSL/CMakeLists.txt
@@ -1,8 +1,14 @@
+set(LLVM_TARGET_DEFINITIONS
+  ${LLVM_MAIN_SRC_DIR}/lib/Target/DirectX/DXIL.td)
+llvm_tablegen(DXILIntrinsicStages.inc -gen-dxil-intrinsic-stages)
+add_public_tablegen_target(HLSLIntrinsicStagesGen)
+
 add_llvm_component_library(LLVMFrontendHLSL
   CBuffer.cpp
   HLSLBinding.cpp
   HLSLResource.cpp
   HLSLRootSignature.cpp
+  IntrinsicStageInfo.cpp
   RootSignatureMetadata.cpp
   RootSignatureValidations.cpp
   SemanticSignaturePacking.cpp
@@ -13,6 +19,7 @@ add_llvm_component_library(LLVMFrontendHLSL
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend/HLSL
 
   DEPENDS
+  HLSLIntrinsicStagesGen
   intrinsics_gen
 
   LINK_COMPONENTS
diff --git a/llvm/lib/Frontend/HLSL/IntrinsicStageInfo.cpp 
b/llvm/lib/Frontend/HLSL/IntrinsicStageInfo.cpp
new file mode 100644
index 00000000000000..d26f443d81f63e
--- /dev/null
+++ b/llvm/lib/Frontend/HLSL/IntrinsicStageInfo.cpp
@@ -0,0 +1,44 @@
+//===- IntrinsicStageInfo.cpp - Intrinsic stage availability
+//---------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Frontend/HLSL/IntrinsicStageInfo.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/IR/IntrinsicsDirectX.h"
+
+using namespace llvm;
+using namespace llvm::hlsl;
+
+namespace {
+#include "DXILIntrinsicStages.inc"
+} // namespace
+
+bool IntrinsicStageInfo::isSupportedIn(StringRef Stage) const {
+  return Stage.empty() || Stage == "unknown" || Stage == "library" ||
+         llvm::is_contained(Stages, Stage);
+}
+
+std::string IntrinsicStageInfo::getStageNames() const {
+  return llvm::join(
+      llvm::map_range(
+          Stages, [](StringRef Stage) { return ("'" + Stage + "'").str(); }),
+      ", ");
+}
+
+ArrayRef<IntrinsicStageInfo> llvm::hlsl::getDXILIntrinsicStageInfos() {
+  return DXILIntrinsicStages;
+}
+
+const IntrinsicStageInfo *
+llvm::hlsl::getDXILIntrinsicStageInfo(StringRef BuiltinName) {
+  auto It = llvm::find_if(DXILIntrinsicStages, [=](const auto &Info) {
+    return Info.BuiltinName == BuiltinName;
+  });
+  return It == std::end(DXILIntrinsicStages) ? nullptr : It;
+}
diff --git a/llvm/lib/Target/DirectX/DXIL.td b/llvm/lib/Target/DirectX/DXIL.td
index 68f5d693804fe4..391f9a2003254d 100644
--- a/llvm/lib/Target/DirectX/DXIL.td
+++ b/llvm/lib/Target/DirectX/DXIL.td
@@ -280,6 +280,14 @@ def all_stages : DXILShaderStage;
 // Denote support for DXIL Op to have been removed
 def removed : DXILShaderStage;
 
+class DXILIntrinsicStages<Intrinsic intrinsic, string builtinName, string name,
+                          list<DXILShaderStage> stages> {
+  Intrinsic Intrin = intrinsic;
+  string BuiltinName = builtinName;
+  string Name = name;
+  list<DXILShaderStage> Stages = stages;
+}
+
 // DXIL Op attributes
 
 // A function attribute denotes that there is a corresponding LLVM function
@@ -1665,6 +1673,11 @@ def CreateHandleFromHeap : DXILOp<218, 
createHandleFromHeap> {
   let attributes = [Attributes<DXIL1_0, [DXILReadNone]>];
 }
 
+defvar QuadVoteStages = [compute, amplification, mesh, pixel, node];
+
+def QuadAllStages : DXILIntrinsicStages<
+    int_dx_quad_all, "__builtin_hlsl_quad_all", "QuadAll", QuadVoteStages>;
+
 def QuadVote : DXILOp<222, quadVote> {
   let Doc = "compares a boolean condition across a quad";
   let intrinsics = [
@@ -1675,7 +1688,7 @@ def QuadVote : DXILOp<222, quadVote> {
   let result = OverloadTy;
   let overloads = [Overloads<DXIL1_7, [Int1Ty]>];
   let stages = [
-    Stages<DXIL1_7, [library, compute, amplification, mesh, pixel, node]>
+    Stages<DXIL1_7, !listconcat([library], QuadVoteStages)>
   ];
 }
 
diff --git a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp 
b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
index 44892aead91616..8c89829b27dd54 100644
--- a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
+++ b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
@@ -13,8 +13,10 @@
 #include "DirectX.h"
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/CodeGen/Passes.h"
+#include "llvm/Frontend/HLSL/IntrinsicStageInfo.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/InstrTypes.h"
@@ -1401,7 +1403,52 @@ static bool expandIntrinsic(Function &F, CallInst *Orig) 
{
   return false;
 }
 
+static bool validateIntrinsicStages(Module &M) {
+  if (!M.getTargetTriple().isDXIL())
+    return true;
+
+  bool HasEntryPoints = llvm::any_of(
+      M, [](const Function &F) { return F.hasFnAttribute("hlsl.shader"); });
+  for (const auto &Info : hlsl::getDXILIntrinsicStageInfos()) {
+    Function *IntrinsicFn = Intrinsic::getDeclarationIfExists(&M, Info.ID);
+    if (!IntrinsicFn)
+      continue;
+
+    SmallVector<Function *, 8> Worklist{IntrinsicFn};
+    SmallPtrSet<Function *, 16> Visited;
+    while (!Worklist.empty()) {
+      Function *F = Worklist.pop_back_val();
+      if (!Visited.insert(F).second)
+        continue;
+
+      if (!F->isDeclaration() &&
+          (F->hasFnAttribute("hlsl.shader") || !HasEntryPoints)) {
+        StringRef Stage = Triple::getEnvironmentTypeName(
+            M.getTargetTriple().getEnvironment());
+        Attribute ShaderAttr = F->getFnAttribute("hlsl.shader");
+        if (ShaderAttr.isValid())
+          Stage = ShaderAttr.getValueAsString();
+        if (!Info.isSupportedIn(Stage)) {
+          M.getContext().emitError(
+              "'" + Info.Name + "' is not supported in '" + Stage +
+              "' shaders for DirectX; supported stages: " +
+              Info.getStageNames() + " (function '" + F->getName() + "')");
+          return false;
+        }
+      }
+
+      for (User *U : F->users())
+        if (auto *Call = dyn_cast<CallBase>(U))
+          Worklist.push_back(Call->getFunction());
+    }
+  }
+  return true;
+}
+
 static bool expansionIntrinsics(Module &M) {
+  if (!validateIntrinsicStages(M))
+    return false;
+
   for (auto &F : make_early_inc_range(M.functions())) {
     if (!isIntrinsicExpansion(F))
       continue;
diff --git a/llvm/test/CodeGen/DirectX/QuadAll-stage-errors.ll 
b/llvm/test/CodeGen/DirectX/QuadAll-stage-errors.ll
new file mode 100644
index 00000000000000..1d427c209ad941
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/QuadAll-stage-errors.ll
@@ -0,0 +1,111 @@
+; RUN: split-file %s %t
+; RUN: not opt -S -dxil-intrinsic-expansion \
+; RUN:   -mtriple=dxil-pc-shadermodel6.0-vertex %t/direct.ll 2>&1 \
+; RUN:   | FileCheck %s --check-prefix=VERTEX
+; RUN: not opt -S -dxil-intrinsic-expansion \
+; RUN:   -mtriple=dxil-pc-shadermodel6.7-vertex %t/direct.ll 2>&1 \
+; RUN:   | FileCheck %s --check-prefix=VERTEX
+; RUN: not opt -S -dxil-intrinsic-expansion \
+; RUN:   -mtriple=dxil-pc-shadermodel6.6-library %t/library.ll 2>&1 \
+; RUN:   | FileCheck %s --check-prefix=LIBRARY
+; RUN: not opt -S -dxil-intrinsic-expansion \
+; RUN:   -mtriple=dxil-pc-shadermodel6.7-library %t/library.ll 2>&1 \
+; RUN:   | FileCheck %s --check-prefix=LIBRARY
+; RUN: opt -S -dxil-intrinsic-expansion \
+; RUN:   -mtriple=dxil-pc-shadermodel6.6-library %t/allowed.ll \
+; 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 %t/allowed.ll \
+; RUN:   | FileCheck %s --check-prefix=NATIVE
+; RUN: opt -S -dxil-intrinsic-expansion \
+; RUN:   -mtriple=dxil-pc-shadermodel6.6-vertex %t/unused.ll \
+; RUN:   | FileCheck %s --check-prefix=UNUSED
+
+; VERTEX: error: 'QuadAll' is not supported in 'vertex' shaders for DirectX; 
supported stages: 'compute', 'amplification', 'mesh', 'pixel', 'node' (function 
'vote')
+; LIBRARY: error: 'QuadAll' is not supported in 'vertex' shaders for DirectX; 
supported stages: 'compute', 'amplification', 'mesh', 'pixel', 'node' (function 
'vertex')
+; EMULATED: call i32 @llvm.dx.quad.read.across.x.i32
+; NATIVE: call i1 @llvm.dx.quad.all
+; UNUSED: define void @vertex()
+
+;--- direct.ll
+define i1 @vote(i1 %cond) {
+  %ret = call i1 @llvm.dx.quad.all(i1 %cond)
+  ret i1 %ret
+}
+
+declare i1 @llvm.dx.quad.all(i1)
+
+;--- unused.ll
+define i1 @unused(i1 %cond) {
+  %ret = call i1 @llvm.dx.quad.all(i1 %cond)
+  ret i1 %ret
+}
+
+define void @vertex() #0 {
+  ret void
+}
+
+attributes #0 = { "hlsl.shader"="vertex" }
+
+declare i1 @llvm.dx.quad.all(i1)
+
+;--- library.ll
+define i1 @shared(i1 %cond) {
+  %ret = call i1 @llvm.dx.quad.all(i1 %cond)
+  ret i1 %ret
+}
+
+define i1 @compute(i1 %cond) #0 {
+  %ret = call i1 @shared(i1 %cond)
+  ret i1 %ret
+}
+
+define i1 @vertex(i1 %cond) #1 {
+  %ret = call i1 @shared(i1 %cond)
+  ret i1 %ret
+}
+
+attributes #0 = { "hlsl.shader"="compute" }
+attributes #1 = { "hlsl.shader"="vertex" }
+
+declare i1 @llvm.dx.quad.all(i1)
+
+;--- allowed.ll
+define i1 @exported(i1 %cond) {
+  %ret = call i1 @llvm.dx.quad.all(i1 %cond)
+  ret i1 %ret
+}
+
+define i1 @pixel(i1 %cond) #0 {
+  %ret = call i1 @exported(i1 %cond)
+  ret i1 %ret
+}
+
+define i1 @compute(i1 %cond) #1 {
+  %ret = call i1 @exported(i1 %cond)
+  ret i1 %ret
+}
+
+define i1 @amplification(i1 %cond) #2 {
+  %ret = call i1 @exported(i1 %cond)
+  ret i1 %ret
+}
+
+define i1 @mesh(i1 %cond) #3 {
+  %ret = call i1 @exported(i1 %cond)
+  ret i1 %ret
+}
+
+define i1 @node(i1 %cond) #4 {
+  %ret = call i1 @exported(i1 %cond)
+  ret i1 %ret
+}
+
+attributes #0 = { "hlsl.shader"="pixel" }
+attributes #1 = { "hlsl.shader"="compute" }
+attributes #2 = { "hlsl.shader"="amplification" }
+attributes #3 = { "hlsl.shader"="mesh" }
+attributes #4 = { "hlsl.shader"="node" }
+
+declare i1 @llvm.dx.quad.all(i1)
diff --git a/llvm/utils/TableGen/DXILEmitter.cpp 
b/llvm/utils/TableGen/DXILEmitter.cpp
index 5c422993bf5265..be3a3f9101b08b 100644
--- a/llvm/utils/TableGen/DXILEmitter.cpp
+++ b/llvm/utils/TableGen/DXILEmitter.cpp
@@ -626,3 +626,28 @@ static void emitDxilOperation(const RecordKeeper &Records, 
raw_ostream &OS) {
 
 static TableGen::Emitter::Opt X("gen-dxil-operation", emitDxilOperation,
                                 "Generate DXIL operation information");
+
+static void emitDXILIntrinsicStages(const RecordKeeper &Records,
+                                    raw_ostream &OS) {
+  OS << "// Generated code, do not edit.\n\n";
+  auto Rules = Records.getAllDerivedDefinitions("DXILIntrinsicStages");
+  for (const Record *R : Rules) {
+    auto Stages = R->getValueAsListOfDefs("Stages");
+    if (Stages.empty())
+      PrintFatalError(R, "expected at least one shader stage");
+    OS << "static constexpr StringRef " << R->getName() << "[] = {\n";
+    for (const Record *Stage : Stages)
+      OS << "  \"" << Stage->getName() << "\",\n";
+    OS << "};\n\n";
+  }
+  OS << "static const IntrinsicStageInfo DXILIntrinsicStages[] = {\n";
+  for (const Record *R : Rules)
+    OS << "  {Intrinsic::" << GetIntrinsicName(R->getValue("Intrin")) << ", \""
+       << R->getValueAsString("BuiltinName") << "\", \""
+       << R->getValueAsString("Name") << "\", " << R->getName() << "},\n";
+  OS << "};\n";
+}
+
+static TableGen::Emitter::Opt Y("gen-dxil-intrinsic-stages",
+                                emitDXILIntrinsicStages,
+                                "Generate DXIL intrinsic stage availability");

>From bcb977a90dce9d08cc4c5303127ec7502b8a6531 Mon Sep 17 00:00:00 2001
From: Joshua Batista <[email protected]>
Date: Wed, 18 Nov 2026 15:59:47 -0800
Subject: [PATCH 2/2] self review

---
 clang/test/CodeGenHLSL/builtins/QuadAll.hlsl         | 12 +++++++++++-
 .../test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl |  6 ------
 llvm/include/llvm/Frontend/HLSL/IntrinsicStageInfo.h |  3 +--
 llvm/lib/Frontend/HLSL/IntrinsicStageInfo.cpp        |  3 +--
 4 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/clang/test/CodeGenHLSL/builtins/QuadAll.hlsl 
b/clang/test/CodeGenHLSL/builtins/QuadAll.hlsl
index 864c2ededec3c4..f54a76d83b00cc 100644
--- a/clang/test/CodeGenHLSL/builtins/QuadAll.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/QuadAll.hlsl
@@ -5,7 +5,8 @@
 // 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:   spirv-pc-vulkan-library %s -DSPIRV_STAGE_TEST \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | \
 // RUN:   FileCheck %s --check-prefixes=CHECK,SPIRV
 
 // CHECK-LABEL: define {{.*}}test_quad_all{{.*}}(
@@ -25,3 +26,12 @@ bool test_quad_all(bool cond) {
 bool test_builtin(bool cond) {
   return __builtin_hlsl_quad_all(cond);
 }
+
+#ifdef SPIRV_STAGE_TEST
+// SPIRV-LABEL: define {{.*}}vertex{{.*}}(
+// SPIRV: call {{.*}}test_quad_all
+[shader("vertex")]
+void vertex() {
+  (void)test_quad_all(true);
+}
+#endif
diff --git a/clang/test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl
index 7483d9584cb24e..36c704672707b6 100644
--- a/clang/test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/QuadAll-stage-errors.hlsl
@@ -9,12 +9,6 @@
 // RUN:   -fsyntax-only -verify=dxil
 // RUN: %clang_cc1 -finclude-default-header -triple \
 // RUN:   spirv-pc-vulkan-library %s -fsyntax-only -verify=spirv
-// RUN: %clang_cc1 -finclude-default-header -triple \
-// RUN:   spirv-pc-vulkan-library %s -emit-llvm -disable-llvm-passes -o - \
-// RUN:   | FileCheck %s --check-prefix=SPIRV
-
-// SPIRV: call i1 @llvm.spv.quad.all
-
 // spirv-no-diagnostics
 
 bool shared(bool cond) {
diff --git a/llvm/include/llvm/Frontend/HLSL/IntrinsicStageInfo.h 
b/llvm/include/llvm/Frontend/HLSL/IntrinsicStageInfo.h
index e242a6a1e3c86e..a1d587996a6c04 100644
--- a/llvm/include/llvm/Frontend/HLSL/IntrinsicStageInfo.h
+++ b/llvm/include/llvm/Frontend/HLSL/IntrinsicStageInfo.h
@@ -1,5 +1,4 @@
-//===- IntrinsicStageInfo.h - Intrinsic stage availability -------*- C++
-//-*-===//
+//===- IntrinsicStageInfo.h - HLSL stage information -----------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/llvm/lib/Frontend/HLSL/IntrinsicStageInfo.cpp 
b/llvm/lib/Frontend/HLSL/IntrinsicStageInfo.cpp
index d26f443d81f63e..d12a73a8594f0c 100644
--- a/llvm/lib/Frontend/HLSL/IntrinsicStageInfo.cpp
+++ b/llvm/lib/Frontend/HLSL/IntrinsicStageInfo.cpp
@@ -1,5 +1,4 @@
-//===- IntrinsicStageInfo.cpp - Intrinsic stage availability
-//---------------===//
+//===- IntrinsicStageInfo.cpp - HLSL stage information ------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to