Skip to content

opt: invalid SPIR-V produced: ID 41[%41] defined in block 54[%54] does not dominate its use in block 56[%56] #2745

@paulthomson

Description

@paulthomson

bug_report.zip

Issue found using GraphicsFuzz.

Tool versions:

  • glslangValidator commit hash: e383c5f
  • spirv-opt commit hash: 230c9e4

To reproduce:

glslangValidator -V shader.frag -o shader.frag.spv

spirv-opt shader.frag.spv -o temp.spv --validate-after-all --redundancy-elimination --reduce-load-size --eliminate-dead-branches --merge-blocks --vector-dce --eliminate-dead-branches --merge-return --scalar-replacement=100 --scalar-replacement=100 --eliminate-dead-code-aggressive --eliminate-dead-code-aggressive --if-conversion --copy-propagate-arrays --redundancy-elimination --scalar-replacement=100

The following shader files are included in the attached archive, some of which are also shown inline below:

  • 0_glsl/shader.frag
  • 1_spirv/shader.frag.spv
  • 1_spirv_asm/shader.frag.asm
  • 2_spirv_opt/shader.frag.spv <-- ignore this one

0_glsl/shader.frag:

#version 310 es
precision highp float;

layout(set = 0, binding = 0) uniform buf0 {
 vec2 injectionSwitch;
};
void main()
{
 do
  {
   for(
       int j = int(injectionSwitch.x);
       j < 2;
       ++j
   )
    {
     return;
    }
  }
 while(0.0 > injectionSwitch.y);
 int(injectionSwitch.y);
}

1_spirv_asm/shader.frag.asm:

; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 7
; Bound: 46
; Schema: 0
               OpCapability Shader
          %1 = OpExtInstImport "GLSL.std.450"
               OpMemoryModel Logical GLSL450
               OpEntryPoint Fragment %4 "main"
               OpExecutionMode %4 OriginUpperLeft
               OpSource ESSL 310
               OpName %4 "main"
               OpName %12 "j"
               OpName %15 "buf0"
               OpMemberName %15 0 "injectionSwitch"
               OpName %17 ""
               OpDecorate %12 RelaxedPrecision
               OpMemberDecorate %15 0 Offset 0
               OpDecorate %15 Block
               OpDecorate %17 DescriptorSet 0
               OpDecorate %17 Binding 0
               OpDecorate %24 RelaxedPrecision
               OpDecorate %30 RelaxedPrecision
               OpDecorate %35 RelaxedPrecision
               OpDecorate %37 RelaxedPrecision
          %2 = OpTypeVoid
          %3 = OpTypeFunction %2
         %10 = OpTypeInt 32 1
         %11 = OpTypePointer Function %10
         %13 = OpTypeFloat 32
         %14 = OpTypeVector %13 2
         %15 = OpTypeStruct %14
         %16 = OpTypePointer Uniform %15
         %17 = OpVariable %16 Uniform
         %18 = OpConstant %10 0
         %19 = OpTypeInt 32 0
         %20 = OpConstant %19 0
         %21 = OpTypePointer Uniform %13
         %31 = OpConstant %10 2
         %32 = OpTypeBool
         %36 = OpConstant %10 1
         %38 = OpConstant %13 0
         %39 = OpConstant %19 1
          %4 = OpFunction %2 None %3
          %5 = OpLabel
         %12 = OpVariable %11 Function
               OpBranch %6
          %6 = OpLabel
               OpLoopMerge %8 %9 None
               OpBranch %7
          %7 = OpLabel
         %22 = OpAccessChain %21 %17 %18 %20
         %23 = OpLoad %13 %22
         %24 = OpConvertFToS %10 %23
               OpStore %12 %24
               OpBranch %25
         %25 = OpLabel
               OpLoopMerge %27 %28 None
               OpBranch %29
         %29 = OpLabel
         %30 = OpLoad %10 %12
         %33 = OpSLessThan %32 %30 %31
               OpBranchConditional %33 %26 %27
         %26 = OpLabel
               OpReturn
         %28 = OpLabel
         %35 = OpLoad %10 %12
         %37 = OpIAdd %10 %35 %36
               OpStore %12 %37
               OpBranch %25
         %27 = OpLabel
               OpBranch %9
          %9 = OpLabel
         %40 = OpAccessChain %21 %17 %18 %39
         %41 = OpLoad %13 %40
         %42 = OpFOrdGreaterThan %32 %38 %41
               OpBranchConditional %42 %6 %8
          %8 = OpLabel
         %43 = OpAccessChain %21 %17 %18 %39
         %44 = OpLoad %13 %43
         %45 = OpConvertFToS %10 %44
               OpReturn
               OpFunctionEnd

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions