Skip to content

spirv-opt ssa-rewrite produces code that fails the validator #3873

@khyperia

Description

@khyperia

Minimized repro case:

; SPIR-V
; Version: 1.0
; Generator: Khronos SPIR-V Tools Assembler; 0
; Bound: 14
; Schema: 0
               OpCapability Shader
               OpCapability VariablePointers
               OpExtension "SPV_KHR_variable_pointers"
               OpMemoryModel Logical Simple
               OpEntryPoint Fragment %1 "main" %2 %3
               OpExecutionMode %1 OriginUpperLeft
      %float = OpTypeFloat 32
       %void = OpTypeVoid
          %6 = OpTypeFunction %void
%_ptr_Input_float = OpTypePointer Input %float
%_ptr_Output_float = OpTypePointer Output %float
%_ptr_Function__ptr_Input_float = OpTypePointer Function %_ptr_Input_float
          %2 = OpVariable %_ptr_Input_float Input
          %3 = OpVariable %_ptr_Output_float Output
          %1 = OpFunction %void None %6
         %10 = OpLabel
         %11 = OpVariable %_ptr_Function__ptr_Input_float Function
               OpStore %11 %2
         %12 = OpLoad %_ptr_Input_float %11
         %13 = OpLoad %float %12
               OpStore %3 %13
               OpReturn
               OpFunctionEnd

which succeeds spirv-val.

command: spirv-as --target-env spv1.0 thing.txt -o thing.spv && spirv-val thing.spv && spirv-opt --ssa-rewrite thing.spv -o thing_opt.spv && spirv-val thing_opt.spv

the resulting module:

; SPIR-V
; Version: 1.0
; Generator: Khronos SPIR-V Tools Assembler; 0
; Bound: 12
; Schema: 0
               OpCapability Shader
               OpCapability VariablePointers
               OpExtension "SPV_KHR_variable_pointers"
               OpMemoryModel Logical Simple
               OpEntryPoint Fragment %1 "main" %2 %3
               OpExecutionMode %1 OriginUpperLeft
      %float = OpTypeFloat 32
       %void = OpTypeVoid
          %6 = OpTypeFunction %void
%_ptr_Input_float = OpTypePointer Input %float
%_ptr_Output_float = OpTypePointer Output %float
%_ptr_Function__ptr_Input_float = OpTypePointer Function %_ptr_Input_float
          %2 = OpVariable %_ptr_Input_float Input
          %3 = OpVariable %_ptr_Output_float Output
          %1 = OpFunction %void None %6
         %10 = OpLabel
         %11 = OpVariable %_ptr_Function__ptr_Input_float Function
               OpStore %11 %2
               OpStore %3 %2
               OpReturn
               OpFunctionEnd

which fails spirv-val with

error: line 19: OpStore Pointer <id> '3[%3]'s type does not match Object <id> '2[%2]'s type.
  OpStore %3 %2

From a high-level glance, it seems like handling of pointers-to-pointers is the culprit? Or the sequence of load-load. No idea though.

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