From 727f3921e7af7a4b0f1e59635ebb99a52bd173c3 Mon Sep 17 00:00:00 2001 From: "Deric C." Date: Thu, 10 Apr 2025 16:06:48 -0700 Subject: [PATCH] [DirectX] Implement Shader Flags Analysis for ResMayNotAlias (#131070) Fixes #112270 Completed ACs: - `-res-may-alias` clang-dxc command-line option added - It inserts and sets a module metadata flag `dx.resmayalias` to 1 - Shader flag set appropriately: - The flag IS NOT set if DXIL Version <= 1.6 OR the command-line option `-res-may-alias` is specified - Otherwise the flag IS set when: - DXIL Version > 1.7 AND function uses UAVs, OR - DXIL Version <= 1.7 AND UAVs present globally - Add tests - Tests for Shader Models 6.6, 6.7, and 6.8 corresponding to DXIL Versions 1.6, 1.7, and 1.8 - Tests (`res-may-alias-0.ll`/`res-may-alias-1.ll`) for when the module metadata flag `dx.resmayalias` is set to 0 or 1 respectively - A frontend test (`res-may-alias.hlsl`) for testing that that the command-line option `-res-may-alias` inserts `dx.resmayalias` module metadata correctly --- clang/include/clang/Basic/CodeGenOptions.def | 3 ++ clang/include/clang/Driver/Options.td | 5 +++ clang/lib/CodeGen/CGHLSLRuntime.cpp | 3 ++ clang/lib/Driver/ToolChains/Clang.cpp | 1 + clang/test/CodeGenHLSL/res-may-alias.hlsl | 7 +++ llvm/lib/Target/DirectX/DXILShaderFlags.cpp | 40 ++++++++++++++--- llvm/lib/Target/DirectX/DXILShaderFlags.h | 6 ++- .../DirectX/ShaderFlags/res-may-alias-0.ll | 43 +++++++++++++++++++ .../DirectX/ShaderFlags/res-may-alias-1.ll | 41 ++++++++++++++++++ .../res-may-not-alias-shadermodel6.6.ll | 37 ++++++++++++++++ .../res-may-not-alias-shadermodel6.7.ll | 38 ++++++++++++++++ .../res-may-not-alias-shadermodel6.8.ll | 38 ++++++++++++++++ .../typed-uav-load-additional-formats.ll | 4 ++ 13 files changed, 258 insertions(+), 8 deletions(-) create mode 100644 clang/test/CodeGenHLSL/res-may-alias.hlsl create mode 100644 llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll create mode 100644 llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-1.ll create mode 100644 llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.6.ll create mode 100644 llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.7.ll create mode 100644 llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.8.ll diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index a7f5f1abbb82..a436c0ec98d5 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -476,6 +476,9 @@ CODEGENOPT(ImportCallOptimization, 1, 0) /// (BlocksRuntime) on Windows. CODEGENOPT(StaticClosure, 1, 0) +/// Assume that UAVs/SRVs may alias +CODEGENOPT(ResMayAlias, 1, 0) + /// FIXME: Make DebugOptions its own top-level .def file. #include "DebugOptions.def" diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 2ca5f99e4ca6..c42887deebde 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -9131,6 +9131,11 @@ def dxil_validator_version : Option<["/", "-"], "validator-version", KIND_SEPARA HelpText<"Override validator version for module. Format: ;" "Default: DXIL.dll version or current internal version">, MarshallingInfoString, "\"1.8\"">; +def res_may_alias : Option<["/", "-"], "res-may-alias", KIND_FLAG>, + Group, Flags<[HelpHidden]>, + Visibility<[DXCOption, ClangOption, CC1Option]>, + HelpText<"Assume that UAVs/SRVs may alias">, + MarshallingInfoFlag>; def target_profile : DXCJoinedOrSeparate<"T">, MetaVarName<"">, HelpText<"Set target profile">, Values<"ps_6_0, ps_6_1, ps_6_2, ps_6_3, ps_6_4, ps_6_5, ps_6_6, ps_6_7," diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 77700ea3a676..a756c3f1e032 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -282,11 +282,14 @@ void CGHLSLRuntime::addHLSLBufferLayoutType(const RecordType *StructType, void CGHLSLRuntime::finishCodeGen() { auto &TargetOpts = CGM.getTarget().getTargetOpts(); + auto &CodeGenOpts = CGM.getCodeGenOpts(); auto &LangOpts = CGM.getLangOpts(); llvm::Module &M = CGM.getModule(); Triple T(M.getTargetTriple()); if (T.getArch() == Triple::ArchType::dxil) addDxilValVersion(TargetOpts.DxilValidatorVersion, M); + if (CodeGenOpts.ResMayAlias) + M.setModuleFlag(llvm::Module::ModFlagBehavior::Error, "dx.resmayalias", 1); // NativeHalfType corresponds to the -fnative-half-type clang option which is // aliased by clang-dxc's -enable-16bit-types option. This option is used to diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 13b7b9442499..1de83baacff9 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3974,6 +3974,7 @@ static void RenderOpenCLOptions(const ArgList &Args, ArgStringList &CmdArgs, static void RenderHLSLOptions(const ArgList &Args, ArgStringList &CmdArgs, types::ID InputType) { const unsigned ForwardedArguments[] = {options::OPT_dxil_validator_version, + options::OPT_res_may_alias, options::OPT_D, options::OPT_I, options::OPT_O, diff --git a/clang/test/CodeGenHLSL/res-may-alias.hlsl b/clang/test/CodeGenHLSL/res-may-alias.hlsl new file mode 100644 index 000000000000..8cb30249a649 --- /dev/null +++ b/clang/test/CodeGenHLSL/res-may-alias.hlsl @@ -0,0 +1,7 @@ +// RUN: %clang_dxc -res-may-alias -T lib_6_3 -HV 202x -Vd -Xclang -emit-llvm %s | FileCheck %s --check-prefix=FLAG +// RUN: %clang_dxc -T lib_6_3 -HV 202x -Vd -Xclang -emit-llvm %s | FileCheck %s --check-prefix=NOFLAG + +// FLAG-DAG: ![[RMA:.*]] = !{i32 1, !"dx.resmayalias", i32 1} +// FLAG-DAG: !llvm.module.flags = !{{{.*}}![[RMA]]{{.*}}} + +// NOFLAG-NOT: dx.resmayalias diff --git a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp index 2ca428672e1c..1331b0d1d852 100644 --- a/llvm/lib/Target/DirectX/DXILShaderFlags.cpp +++ b/llvm/lib/Target/DirectX/DXILShaderFlags.cpp @@ -74,7 +74,8 @@ static bool checkWaveOps(Intrinsic::ID IID) { /// \param I Instruction to check. void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF, const Instruction &I, - DXILResourceTypeMap &DRTM) { + DXILResourceTypeMap &DRTM, + const ModuleMetadataInfo &MMDI) { if (!CSF.Doubles) CSF.Doubles = I.getType()->isDoubleTy(); @@ -128,8 +129,15 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF, switch (II->getIntrinsicID()) { default: break; - case Intrinsic::dx_resource_handlefrombinding: - switch (DRTM[cast(II->getType())].getResourceKind()) { + case Intrinsic::dx_resource_handlefrombinding: { + dxil::ResourceTypeInfo &RTI = DRTM[cast(II->getType())]; + + // Set ResMayNotAlias if DXIL version >= 1.8 and function uses UAVs + if (!CSF.ResMayNotAlias && CanSetResMayNotAlias && + MMDI.DXILVersion >= VersionTuple(1, 8) && RTI.isUAV()) + CSF.ResMayNotAlias = true; + + switch (RTI.getResourceKind()) { case dxil::ResourceKind::StructuredBuffer: case dxil::ResourceKind::RawBuffer: CSF.EnableRawAndStructuredBuffers = true; @@ -138,6 +146,7 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF, break; } break; + } case Intrinsic::dx_resource_load_typedbuffer: { dxil::ResourceTypeInfo &RTI = DRTM[cast(II->getArgOperand(0)->getType())]; @@ -163,7 +172,18 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF, /// Construct ModuleShaderFlags for module Module M void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM, + DXILResourceMap &DRM, const ModuleMetadataInfo &MMDI) { + + CanSetResMayNotAlias = MMDI.DXILVersion >= VersionTuple(1, 7); + + // Check if -res-may-alias was provided on the command line. + // The command line option will set the dx.resmayalias module flag to 1. + if (auto *RMA = mdconst::extract_or_null( + M.getModuleFlag("dx.resmayalias"))) + if (RMA->getValue() != 0) + CanSetResMayNotAlias = false; + CallGraph CG(M); // Compute Shader Flags Mask for all functions using post-order visit of SCC @@ -188,6 +208,11 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM, continue; } + // Set ResMayNotAlias to true if DXIL version < 1.8 and there are UAVs + // present globally. + if (CanSetResMayNotAlias && MMDI.DXILVersion < VersionTuple(1, 8)) + SCCSF.ResMayNotAlias = !DRM.uavs().empty(); + // Set UseNativeLowPrecision using dx.nativelowprec module metadata if (auto *NativeLowPrec = mdconst::extract_or_null( M.getModuleFlag("dx.nativelowprec"))) @@ -198,7 +223,7 @@ void ModuleShaderFlags::initialize(Module &M, DXILResourceTypeMap &DRTM, ComputedShaderFlags CSF; for (const auto &BB : *F) for (const auto &I : BB) - updateFunctionFlags(CSF, I, DRTM); + updateFunctionFlags(CSF, I, DRTM, MMDI); // Update combined shader flags mask for all functions in this SCC SCCSF.merge(CSF); @@ -268,10 +293,11 @@ AnalysisKey ShaderFlagsAnalysis::Key; ModuleShaderFlags ShaderFlagsAnalysis::run(Module &M, ModuleAnalysisManager &AM) { DXILResourceTypeMap &DRTM = AM.getResult(M); + DXILResourceMap &DRM = AM.getResult(M); const ModuleMetadataInfo MMDI = AM.getResult(M); ModuleShaderFlags MSFI; - MSFI.initialize(M, DRTM, MMDI); + MSFI.initialize(M, DRTM, DRM, MMDI); return MSFI; } @@ -301,16 +327,18 @@ PreservedAnalyses ShaderFlagsAnalysisPrinter::run(Module &M, bool ShaderFlagsAnalysisWrapper::runOnModule(Module &M) { DXILResourceTypeMap &DRTM = getAnalysis().getResourceTypeMap(); + DXILResourceMap &DRM = getAnalysis().getBindingMap(); const ModuleMetadataInfo MMDI = getAnalysis().getModuleMetadata(); - MSFI.initialize(M, DRTM, MMDI); + MSFI.initialize(M, DRTM, DRM, MMDI); return false; } void ShaderFlagsAnalysisWrapper::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); AU.addRequiredTransitive(); + AU.addRequiredTransitive(); AU.addRequired(); } diff --git a/llvm/lib/Target/DirectX/DXILShaderFlags.h b/llvm/lib/Target/DirectX/DXILShaderFlags.h index abf7cc86259e..0e0bd0036349 100644 --- a/llvm/lib/Target/DirectX/DXILShaderFlags.h +++ b/llvm/lib/Target/DirectX/DXILShaderFlags.h @@ -28,6 +28,7 @@ namespace llvm { class Module; class GlobalVariable; class DXILResourceTypeMap; +class DXILResourceMap; namespace dxil { @@ -84,12 +85,13 @@ struct ComputedShaderFlags { }; struct ModuleShaderFlags { - void initialize(Module &, DXILResourceTypeMap &DRTM, + void initialize(Module &, DXILResourceTypeMap &DRTM, DXILResourceMap &DRM, const ModuleMetadataInfo &MMDI); const ComputedShaderFlags &getFunctionFlags(const Function *) const; const ComputedShaderFlags &getCombinedFlags() const { return CombinedSFMask; } private: + bool CanSetResMayNotAlias; /// Map of Function-Shader Flag Mask pairs representing properties of each of /// the functions in the module. Shader Flags of each function represent both /// module-level and function-level flags @@ -97,7 +99,7 @@ private: /// Combined Shader Flag Mask of all functions of the module ComputedShaderFlags CombinedSFMask{}; void updateFunctionFlags(ComputedShaderFlags &, const Instruction &, - DXILResourceTypeMap &); + DXILResourceTypeMap &, const ModuleMetadataInfo &); }; class ShaderFlagsAnalysis : public AnalysisInfoMixin { diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll new file mode 100644 index 000000000000..d15b5c7b6198 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-0.ll @@ -0,0 +1,43 @@ +; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s + +; This test checks to ensure that setting the LLVM module flag "dx.resmayalias" +; to 0 has no effect on the DXIL shader flag analysis for the flag +; ResMayNotAlias. + +target triple = "dxil-pc-shadermodel6.8-library" + +; CHECK: Combined Shader Flags for Module +; CHECK-NEXT: Shader Flags Value: 0x200000010 + +; CHECK: Note: extra DXIL module flags: +; CHECK: Raw and Structured buffers +; CHECK: Any UAV may not alias any other UAV +; + +; CHECK: Function loadUAV : 0x20000000 +define float @loadUAV() #0 { + %res = call target("dx.TypedBuffer", float, 1, 0, 0) + @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) + %load = call {float, i1} @llvm.dx.resource.load.typedbuffer( + target("dx.TypedBuffer", float, 1, 0, 0) %res, i32 0) + %val = extractvalue {float, i1} %load, 0 + ret float %val +} + +; CHECK: Function loadSRV : 0x00000010 +define float @loadSRV() #0 { + %res = tail call target("dx.RawBuffer", float, 0, 0) + @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) + %load = call {float, i1} @llvm.dx.resource.load.rawbuffer( + target("dx.RawBuffer", float, 0, 0) %res, i32 0, i32 0) + %val = extractvalue { float, i1 } %load, 0 + ret float %val +} + +!llvm.module.flags = !{!0} + +; dx.resmayalias should never appear with a value of 0. +; But if it does, ensure that it has no effect. +!0 = !{i32 1, !"dx.resmayalias", i32 0} + +attributes #0 = { convergent norecurse nounwind "hlsl.export"} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-1.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-1.ll new file mode 100644 index 000000000000..edd3250a2db0 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-alias-1.ll @@ -0,0 +1,41 @@ +; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s + +; This test checks to ensure that setting the LLVM module flag "dx.resmayalias" +; to 1 prevents the DXIL shader flag analysis from setting the flag +; ResMayNotAlias. + +target triple = "dxil-pc-shadermodel6.8-library" + +; CHECK: Combined Shader Flags for Module +; CHECK-NEXT: Shader Flags Value: 0x00000010 + +; CHECK: Note: extra DXIL module flags: +; CHECK: Raw and Structured buffers +; CHECK-NOT: Any UAV may not alias any other UAV +; + +; CHECK: Function loadUAV : 0x00000000 +define float @loadUAV() #0 { + %res = call target("dx.TypedBuffer", float, 1, 0, 0) + @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) + %load = call {float, i1} @llvm.dx.resource.load.typedbuffer( + target("dx.TypedBuffer", float, 1, 0, 0) %res, i32 0) + %val = extractvalue {float, i1} %load, 0 + ret float %val +} + +; CHECK: Function loadSRV : 0x00000010 +define float @loadSRV() #0 { + %res = tail call target("dx.RawBuffer", float, 0, 0) + @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) + %load = call {float, i1} @llvm.dx.resource.load.rawbuffer( + target("dx.RawBuffer", float, 0, 0) %res, i32 0, i32 0) + %val = extractvalue { float, i1 } %load, 0 + ret float %val +} + +!llvm.module.flags = !{!0} + +!0 = !{i32 1, !"dx.resmayalias", i32 1} + +attributes #0 = { convergent norecurse nounwind "hlsl.export"} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.6.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.6.ll new file mode 100644 index 000000000000..da7c4c619790 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.6.ll @@ -0,0 +1,37 @@ +; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s + +; This test checks to ensure the behavior of the DXIL shader flag analysis +; for the flag ResMayNotAlias is correct when the DXIL Version is 1.6. The +; ResMayNotAlias flag (0x20000000) should not be set at all. + +target triple = "dxil-pc-shadermodel6.6-library" + +; CHECK: Combined Shader Flags for Module +; CHECK-NEXT: Shader Flags Value: 0x00000010 + +; CHECK: Note: extra DXIL module flags: +; CHECK: Raw and Structured buffers +; CHECK-NOT: Any UAV may not alias any other UAV +; + +; CHECK: Function loadUAV : 0x00000000 +define float @loadUAV() #0 { + %res = call target("dx.TypedBuffer", float, 1, 0, 0) + @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) + %load = call {float, i1} @llvm.dx.resource.load.typedbuffer( + target("dx.TypedBuffer", float, 1, 0, 0) %res, i32 0) + %val = extractvalue {float, i1} %load, 0 + ret float %val +} + +; CHECK: Function loadSRV : 0x00000010 +define float @loadSRV() #0 { + %res = tail call target("dx.RawBuffer", float, 0, 0) + @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) + %load = call {float, i1} @llvm.dx.resource.load.rawbuffer( + target("dx.RawBuffer", float, 0, 0) %res, i32 0, i32 0) + %val = extractvalue { float, i1 } %load, 0 + ret float %val +} + +attributes #0 = { convergent norecurse nounwind "hlsl.export"} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.7.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.7.ll new file mode 100644 index 000000000000..87a76162f734 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.7.ll @@ -0,0 +1,38 @@ +; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s + +; This test checks to ensure the behavior of the DXIL shader flag analysis +; for the flag ResMayNotAlias is correct when the DXIL Version is 1.7. The +; ResMayNotAlias flag (0x20000000) should be set on all functions if there are +; one or more UAVs present globally in the module. + +target triple = "dxil-pc-shadermodel6.7-library" + +; CHECK: Combined Shader Flags for Module +; CHECK-NEXT: Shader Flags Value: 0x200000010 + +; CHECK: Note: extra DXIL module flags: +; CHECK: Raw and Structured buffers +; CHECK: Any UAV may not alias any other UAV +; + +; CHECK: Function loadUAV : 0x200000000 +define float @loadUAV() #0 { + %res = call target("dx.TypedBuffer", float, 1, 0, 0) + @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) + %load = call {float, i1} @llvm.dx.resource.load.typedbuffer( + target("dx.TypedBuffer", float, 1, 0, 0) %res, i32 0) + %val = extractvalue {float, i1} %load, 0 + ret float %val +} + +; CHECK: Function loadSRV : 0x200000010 +define float @loadSRV() #0 { + %res = tail call target("dx.RawBuffer", float, 0, 0) + @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) + %load = call {float, i1} @llvm.dx.resource.load.rawbuffer( + target("dx.RawBuffer", float, 0, 0) %res, i32 0, i32 0) + %val = extractvalue { float, i1 } %load, 0 + ret float %val +} + +attributes #0 = { convergent norecurse nounwind "hlsl.export"} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.8.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.8.ll new file mode 100644 index 000000000000..a309d8ecea56 --- /dev/null +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/res-may-not-alias-shadermodel6.8.ll @@ -0,0 +1,38 @@ +; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s + +; This test checks to ensure the behavior of the DXIL shader flag analysis +; for the flag ResMayNotAlias is correct when the DXIL Version is 1.8. The +; ResMayNotAlias flag (0x20000000) should only be set when a function uses a +; UAV. + +target triple = "dxil-pc-shadermodel6.8-library" + +; CHECK: Combined Shader Flags for Module +; CHECK-NEXT: Shader Flags Value: 0x200000010 + +; CHECK: Note: extra DXIL module flags: +; CHECK: Raw and Structured buffers +; CHECK: Any UAV may not alias any other UAV +; + +; CHECK: Function loadUAV : 0x20000000 +define float @loadUAV() #0 { + %res = call target("dx.TypedBuffer", float, 1, 0, 0) + @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) + %load = call {float, i1} @llvm.dx.resource.load.typedbuffer( + target("dx.TypedBuffer", float, 1, 0, 0) %res, i32 0) + %val = extractvalue {float, i1} %load, 0 + ret float %val +} + +; CHECK: Function loadSRV : 0x00000010 +define float @loadSRV() #0 { + %res = tail call target("dx.RawBuffer", float, 0, 0) + @llvm.dx.resource.handlefrombinding(i32 0, i32 0, i32 1, i32 0, i1 false) + %load = call {float, i1} @llvm.dx.resource.load.rawbuffer( + target("dx.RawBuffer", float, 0, 0) %res, i32 0, i32 0) + %val = extractvalue { float, i1 } %load, 0 + ret float %val +} + +attributes #0 = { convergent norecurse nounwind "hlsl.export"} diff --git a/llvm/test/CodeGen/DirectX/ShaderFlags/typed-uav-load-additional-formats.ll b/llvm/test/CodeGen/DirectX/ShaderFlags/typed-uav-load-additional-formats.ll index 060d54f961c7..1bb8a4d78eb1 100644 --- a/llvm/test/CodeGen/DirectX/ShaderFlags/typed-uav-load-additional-formats.ll +++ b/llvm/test/CodeGen/DirectX/ShaderFlags/typed-uav-load-additional-formats.ll @@ -43,4 +43,8 @@ define void @noload(<4 x float> %val) #0 { ret void } +!llvm.module.flags = !{!0} +!0 = !{i32 1, !"dx.resmayalias", i32 1} + attributes #0 = { convergent norecurse nounwind "hlsl.export"} +