@@ -8883,6 +8883,148 @@ OpFunctionEnd
88838883
88848884 SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true );
88858885}
8886+
8887+ TEST_F (AggressiveDCETest, DebugDeclareConvertedToDebugValueKeepsDebugScope) {
8888+ const std::string spirv = R"(
8889+ ; CHECK: [[ext:%\w+]] = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
8890+ ; CHECK-DAG: [[inlined:%\w+]] = OpExtInst %void [[ext]] DebugInlinedAt
8891+ ; CHECK-DAG: [[UniformVar:%\w+]] = OpVariable %_ptr_Uniform_float Uniform
8892+ ; CHECK: [[scope:%\w+]] = OpExtInst %void [[ext]] DebugScope {{%\w+}} [[inlined]]
8893+ ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue {{%\w+}} {{%\w+}} {{%\w+}}
8894+ ; CHECK-NEXT: DebugScope
8895+ ; CHECK-NEXT: DebugLine
8896+ ; CHECK-NEXT: OpStore [[UniformVar]] %float_0
8897+ ; CHECK-NEXT: OpReturn
8898+ OpCapability Shader
8899+ OpExtension "SPV_KHR_non_semantic_info"
8900+ %1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
8901+ OpMemoryModel Logical GLSL450
8902+ OpEntryPoint GLCompute %2 "main"
8903+ OpExecutionMode %2 LocalSize 1 1 1
8904+ %3 = OpString ""
8905+ %void = OpTypeVoid
8906+ %uint = OpTypeInt 32 0
8907+ %6 = OpTypeFunction %void
8908+ %float = OpTypeFloat 32
8909+ %uint_3 = OpConstant %uint 3
8910+ %uint_0 = OpConstant %uint 0
8911+ %_ptr_Function_float = OpTypePointer Function %float
8912+ %_ptr_Uniform_float = OpTypePointer Uniform %float
8913+ %float_0 = OpConstant %float 0
8914+ %13 = OpVariable %_ptr_Uniform_float Uniform
8915+ %uint_57 = OpConstant %uint 57
8916+ %15 = OpExtInst %void %1 DebugExpression
8917+ %16 = OpExtInst %void %1 DebugSource %3 %3
8918+ %17 = OpExtInst %void %1 DebugCompilationUnit %uint_0 %uint_0 %16 %uint_0
8919+ %18 = OpExtInst %void %1 DebugTypeBasic %3 %uint_0 %uint_0 %uint_0
8920+ %19 = OpExtInst %void %1 DebugTypeVector %18 %uint_3
8921+ %20 = OpExtInst %void %1 DebugTypePointer %19 %uint_0 %uint_0
8922+ %21 = OpExtInst %void %1 DebugTypeFunction %uint_0 %void %20
8923+ %22 = OpExtInst %void %1 DebugFunction %3 %21 %16 %uint_0 %uint_0 %17 %3 %uint_0 %uint_0
8924+ %23 = OpExtInst %void %1 DebugTypeBasic %3 %uint_0 %uint_3 %uint_0
8925+ %24 = OpExtInst %void %1 DebugTypeMember %3 %23 %16 %uint_0 %uint_0 %uint_0 %uint_0 %uint_0
8926+ %25 = OpExtInst %void %1 DebugTypeComposite %3 %uint_0 %16 %uint_0 %uint_0 %17 %3 %uint_0 %uint_0 %24
8927+ %26 = OpExtInst %void %1 DebugTypeFunction %uint_0 %23 %25 %23
8928+ %27 = OpExtInst %void %1 DebugFunction %3 %26 %16 %uint_0 %uint_0 %17 %3 %uint_0 %uint_0
8929+ %28 = OpExtInst %void %1 DebugLocalVariable %3 %23 %16 %uint_0 %uint_0 %27 %uint_0 %uint_0
8930+ %29 = OpExtInst %void %1 DebugInlinedAt %uint_0 %22
8931+ %2 = OpFunction %void None %6
8932+ %30 = OpLabel
8933+ %31 = OpVariable %_ptr_Function_float Function
8934+ %32 = OpExtInst %void %1 DebugScope %27 %29
8935+ %33 = OpExtInst %void %1 DebugNoLine
8936+ %34 = OpExtInst %void %1 DebugDeclare %28 %31 %15
8937+ OpStore %31 %float_0
8938+ %35 = OpExtInst %void %1 DebugScope %22
8939+ %36 = OpExtInst %void %1 DebugLine %16 %uint_0 %uint_0 %uint_0 %uint_0
8940+ OpStore %13 %float_0
8941+ OpReturn
8942+ %37 = OpExtInst %void %1 DebugNoScope
8943+ OpFunctionEnd
8944+ )" ;
8945+
8946+ SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true );
8947+ }
8948+
8949+ TEST_F (AggressiveDCETest, DebugValueWithDeadOperandKeepsDebugScope) {
8950+ const std::string spirv = R"(
8951+ ; CHECK: [[ext:%\w+]] = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
8952+ ; CHECK-DAG: [[inlined:%\w+]] = OpExtInst %void [[ext]] DebugInlinedAt
8953+ ; CHECK-DAG: [[undef:%\w+]] = OpUndef %float
8954+ ; CHECK: [[scope:%\w+]] = OpExtInst %void [[ext]] DebugScope {{%\w+}} [[inlined]]
8955+ ; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue {{%\w+}} [[undef]] {{%\w+}}
8956+ OpCapability Shader
8957+ OpExtension "SPV_KHR_non_semantic_info"
8958+ %1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
8959+ OpMemoryModel Logical GLSL450
8960+ OpEntryPoint GLCompute %2 "main"
8961+ OpExecutionMode %2 LocalSize 1 1 1
8962+ %4 = OpString ""
8963+ %5 = OpString "file.slang"
8964+ %6 = OpString "uint"
8965+ %7 = OpString "computeMain"
8966+ %8 = OpString "float"
8967+ %9 = OpString "x"
8968+ %10 = OpString "A"
8969+ %11 = OpString "test"
8970+ %12 = OpString "v"
8971+ %void = OpTypeVoid
8972+ %uint = OpTypeInt 32 0
8973+ %uint_11 = OpConstant %uint 11
8974+ %uint_5 = OpConstant %uint 5
8975+ %uint_100 = OpConstant %uint 100
8976+ %21 = OpTypeFunction %void
8977+ %float = OpTypeFloat 32
8978+ %uint_32 = OpConstant %uint 32
8979+ %uint_6 = OpConstant %uint 6
8980+ %uint_131072 = OpConstant %uint 131072
8981+ %uint_3 = OpConstant %uint 3
8982+ %uint_7 = OpConstant %uint 7
8983+ %uint_0 = OpConstant %uint 0
8984+ %uint_46 = OpConstant %uint 46
8985+ %uint_1 = OpConstant %uint 1
8986+ %uint_8 = OpConstant %uint 8
8987+ %_ptr_Function_float = OpTypePointer Function %float
8988+ %int = OpTypeInt 32 1
8989+ %int_0 = OpConstant %int 0
8990+ %float_0 = OpConstant %float 0
8991+ %uint_50 = OpConstant %uint 50
8992+ %uint_34 = OpConstant %uint 34
8993+ %uint_2 = OpConstant %uint 2
8994+ %uint_56 = OpConstant %uint 56
8995+ %_runtimearr_float = OpTypeRuntimeArray %float
8996+ %uint_57 = OpConstant %uint 57
8997+ %42 = OpExtInst %void %1 DebugExpression
8998+ %43 = OpExtInst %void %1 DebugSource %5 %4
8999+ %44 = OpExtInst %void %1 DebugCompilationUnit %uint_100 %uint_5 %43 %uint_11
9000+ %45 = OpExtInst %void %1 DebugTypeBasic %6 %uint_32 %uint_6 %uint_131072
9001+ %46 = OpExtInst %void %1 DebugTypeVector %45 %uint_3
9002+ %47 = OpExtInst %void %1 DebugTypePointer %46 %uint_7 %uint_131072
9003+ %48 = OpExtInst %void %1 DebugTypeFunction %uint_0 %void %47
9004+ %49 = OpExtInst %void %1 DebugFunction %7 %48 %43 %uint_46 %uint_6 %44 %7 %uint_0 %uint_46
9005+ %50 = OpExtInst %void %1 DebugTypeBasic %8 %uint_32 %uint_3 %uint_131072
9006+ %51 = OpExtInst %void %1 DebugTypeMember %9 %50 %43 %uint_8 %uint_11 %uint_0 %uint_32 %uint_0
9007+ %52 = OpExtInst %void %1 DebugTypeComposite %10 %uint_1 %43 %uint_6 %uint_8 %44 %10 %uint_32 %uint_131072 %51
9008+ %53 = OpExtInst %void %1 DebugTypeFunction %uint_0 %50 %52 %50
9009+ %54 = OpExtInst %void %1 DebugFunction %11 %53 %43 %uint_34 %uint_7 %44 %11 %uint_0 %uint_34
9010+ %55 = OpExtInst %void %1 DebugLocalVariable %12 %50 %43 %uint_34 %uint_7 %54 %uint_0 %uint_2
9011+ %56 = OpExtInst %void %1 DebugInlinedAt %uint_50 %49
9012+ %2 = OpFunction %void None %21
9013+ %57 = OpLabel
9014+ %59 = OpExtInst %void %1 DebugScope %54 %56
9015+ %60 = OpExtInst %void %1 DebugNoLine
9016+ %val = OpFAdd %float %float_0 %float_0
9017+ %61 = OpExtInst %void %1 DebugValue %55 %val %42
9018+ %62 = OpExtInst %void %1 DebugScope %49
9019+ %63 = OpExtInst %void %1 DebugLine %43 %uint_56 %uint_56 %uint_5 %uint_6
9020+ OpReturn
9021+ %66 = OpExtInst %void %1 DebugNoScope
9022+ OpFunctionEnd
9023+ )" ;
9024+
9025+ SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true );
9026+ }
9027+
88869028} // namespace
88879029} // namespace opt
88889030} // namespace spvtools
0 commit comments