Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt: keep all OpSource instructions #5901

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/opt/aggressive_dead_code_elim_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ void AggressiveDCEPass::InitializeModuleScopeLiveInstructions() {
auto op = dbg.GetShader100DebugOpcode();
if (op == NonSemanticShaderDebugInfo100DebugCompilationUnit ||
op == NonSemanticShaderDebugInfo100DebugEntryPoint ||
op == NonSemanticShaderDebugInfo100DebugSource ||
op == NonSemanticShaderDebugInfo100DebugSourceContinued) {
AddToWorklist(&dbg);
}
Expand Down
64 changes: 64 additions & 0 deletions test/opt/aggressive_dead_code_elim_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <string>
#include <vector>

#include "gmock/gmock.h"
#include "test/opt/assembly_builder.h"
#include "test/opt/pass_fixture.h"
#include "test/opt/pass_utils.h"
Expand All @@ -26,6 +27,8 @@ namespace {

using AggressiveDCETest = PassTest<::testing::Test>;

using ::testing::HasSubstr;

TEST_F(AggressiveDCETest, EliminateExtendedInst) {
// #version 140
//
Expand Down Expand Up @@ -8233,6 +8236,67 @@ OpFunctionEnd
SinglePassRunAndCheck<AggressiveDCEPass>(spirv, spirv, true, false);
}

TEST_F(AggressiveDCETest, NoEliminateOpSource) {
// Should not eliminate OpSource

const std::string text =
R"(OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %in_var_COLOR %out_var_SV_TARGET
OpExecutionMode %main OriginUpperLeft
%4 = OpString "D:\\directxshadercompiler\\tools\\clang\\test\\CodeGenSPIRV\\spirv.debug.opsource.include.hlsl"
%5 = OpString "D:\\directxshadercompiler\\tools\\clang\\test\\CodeGenSPIRV/spirv.debug.opsource.include-file.hlsli"
OpSource HLSL 600 %4 "// RUN: %dxc -T ps_6_0 -E main -Zi %s -spirv | FileCheck %s
#include \"spirv.debug.opsource.include-file.hlsli\"

struct ColorType
{
float4 position : SV_POSITION;
float4 color : COLOR;
};

float4 main(UBER_TYPE(Color) input) : SV_TARGET
{
return input.color;
}
"
OpSource HLSL 600 %5 "#define UBER_TYPE(x) x ## Type
"
OpName %in_var_COLOR "in.var.COLOR"
OpName %out_var_SV_TARGET "out.var.SV_TARGET"
OpName %main "main"
OpDecorate %in_var_COLOR Location 0
OpDecorate %out_var_SV_TARGET Location 0
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Input_v4float = OpTypePointer Input %v4float
%_ptr_Output_v4float = OpTypePointer Output %v4float
%void = OpTypeVoid
%11 = OpTypeFunction %void
%in_var_COLOR = OpVariable %_ptr_Input_v4float Input
%out_var_SV_TARGET = OpVariable %_ptr_Output_v4float Output
OpLine %4 22 1
%main = OpFunction %void None %11
OpNoLine
%12 = OpLabel
OpLine %4 22 1
%13 = OpLoad %v4float %in_var_COLOR
OpStore %out_var_SV_TARGET %13
OpLine %4 25 1
OpReturn
OpFunctionEnd
)";

auto result = SinglePassRunAndDisassemble<AggressiveDCEPass>(
text, /* skip_nop = */ true, /* skip_validation = */ false);

EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result));
const std::string& output = std::get<0>(result);
EXPECT_THAT(
output,
HasSubstr("OpSource HLSL 600 %5 \"#define UBER_TYPE(x) x ## Type"));
}

} // namespace
} // namespace opt
} // namespace spvtools
Loading