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