From 824f7b0f8db55aa725a6c65a293cd6d5ac318a3e Mon Sep 17 00:00:00 2001 From: Tex Riddell Date: Wed, 14 Feb 2018 14:05:13 -0800 Subject: [PATCH] TranslatePreciseAttribute for libraries. --- lib/HLSL/DxilGenerationPass.cpp | 23 ++++++++++++------- .../CodeGenHLSL/quick-test/incomp_array.hlsl | 8 +++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/HLSL/DxilGenerationPass.cpp b/lib/HLSL/DxilGenerationPass.cpp index 5c1a80281..e12116c45 100644 --- a/lib/HLSL/DxilGenerationPass.cpp +++ b/lib/HLSL/DxilGenerationPass.cpp @@ -778,15 +778,22 @@ void DxilGenerationPass::TranslatePreciseAttribute() { // argument and call site without precise argument, need to clone the function // to propagate the precise for the precise call site. // This should be done at CGMSHLSLRuntime::FinishCodeGen. - Function *EntryFn = m_pHLModule->GetEntryFunction(); - if (!m_pHLModule->GetShaderModel()->IsLib()) { + if (m_pHLModule->GetShaderModel()->IsLib()) { + // TODO: If all functions have been inlined, and unreferenced functions removed, + // it should make sense to run on all funciton bodies, + // even when not processing a library. + for (Function &F : M.functions()) { + if (!F.isDeclaration()) + TranslatePreciseAttributeOnFunction(F, M); + } + } else { + Function *EntryFn = m_pHLModule->GetEntryFunction(); TranslatePreciseAttributeOnFunction(*EntryFn, M); - } - - if (m_pHLModule->GetShaderModel()->IsHS()) { - DxilFunctionProps &EntryQual = m_pHLModule->GetDxilFunctionProps(EntryFn); - Function *patchConstantFunc = EntryQual.ShaderProps.HS.patchConstantFunc; - TranslatePreciseAttributeOnFunction(*patchConstantFunc, M); + if (m_pHLModule->GetShaderModel()->IsHS()) { + DxilFunctionProps &EntryQual = m_pHLModule->GetDxilFunctionProps(EntryFn); + Function *patchConstantFunc = EntryQual.ShaderProps.HS.patchConstantFunc; + TranslatePreciseAttributeOnFunction(*patchConstantFunc, M); + } } } diff --git a/tools/clang/test/CodeGenHLSL/quick-test/incomp_array.hlsl b/tools/clang/test/CodeGenHLSL/quick-test/incomp_array.hlsl index ca3430e3f..f7a4c8908 100644 --- a/tools/clang/test/CodeGenHLSL/quick-test/incomp_array.hlsl +++ b/tools/clang/test/CodeGenHLSL/quick-test/incomp_array.hlsl @@ -1,4 +1,4 @@ -// RUN: %dxc -T lib_6_1 %s | FileCheck %s +// RUN: %dxc -T lib_6_3 %s | FileCheck %s // Verify no hang on incomplete array @@ -32,7 +32,7 @@ float4 fn1(in Special in1: SEMANTIC_IN) : SEMANTIC_OUT { // CHECK: getelementptr // CHECK: load i32, i32* // CHECK: sitofp i32 - // CHECK: fadd float + // CHECK: fadd fast float return in1.member + (float)s_testa[i]; } @@ -55,7 +55,7 @@ float4 fn3(in Special in1: SEMANTIC_IN) : SEMANTIC_OUT { // CHECK: getelementptr // CHECK: load i32, i32* // CHECK: sitofp i32 - // CHECK: fadd float + // CHECK: fadd fast float return in1.member + (float)in1.a[i]; } @@ -72,6 +72,6 @@ float4 fn4(in Special in1: SEMANTIC_IN) : SEMANTIC_OUT { // CHECK: extractvalue // CHECK: , 0 // CHECK: sitofp i32 - // CHECK: fadd float + // CHECK: fadd fast float return in1.member + c_special.a[i]; }