Skip to content

spirv-fuzz: TransformationInlineFunction doesn't handle OpPhis #3829

@Vasniktel

Description

@Vasniktel

This transformation doesn't handle OpPhi instructions if they are placed in the second block of the inlined function. The following test fails:

TEST(A, a) {
  std::string shader = R"(
               OpCapability Shader
          %1 = OpExtInstImport "GLSL.std.450"
               OpMemoryModel Logical GLSL450
               OpEntryPoint Fragment %4 "main"
               OpExecutionMode %4 OriginUpperLeft
          %2 = OpTypeVoid
          %3 = OpTypeFunction %2
         %10 = OpTypeInt 32 0
         %11 = OpUndef %10
          %4 = OpFunction %2 None %3
          %5 = OpLabel
          %6 = OpFunctionCall %2 %7
               OpBranch %14
         %14 = OpLabel
               OpReturn
               OpFunctionEnd
          %7 = OpFunction %2 None %3
          %8 = OpLabel
               OpBranch %13
         %13 = OpLabel
         %12 = OpPhi %10 %11 %8
               OpReturn
               OpFunctionEnd
  )";

  const auto env = SPV_ENV_UNIVERSAL_1_3;
  const auto consumer = nullptr;
  const auto context =
      BuildModule(env, consumer, shader, kFuzzAssembleOption);
  ASSERT_TRUE(IsValid(env, context.get()));

  FactManager fact_manager;
  spvtools::ValidatorOptions validator_options;
  TransformationContext transformation_context(&fact_manager,
                                               validator_options);

  TransformationInlineFunction transformation(6, {{{8, 20}, {13, 21}, {12, 22}}});
  ASSERT_TRUE(transformation.IsApplicable(context.get(), transformation_context));
  transformation.Apply(context.get(), &transformation_context);
  DumpShader(context.get(), "/home/vasniktel/shader.asm");
  ASSERT_TRUE(IsValid(env, context.get()));
}

producing the following invalid shader:

; SPIR-V
; Version: 1.3
; Generator: Khronos SPIR-V Tools Assembler; 0
; Bound: 23
; Schema: 0
               OpCapability Shader
          %1 = OpExtInstImport "GLSL.std.450"
               OpMemoryModel Logical GLSL450
               OpEntryPoint Fragment %4 "main"
               OpExecutionMode %4 OriginUpperLeft
          %2 = OpTypeVoid
          %3 = OpTypeFunction %2
         %10 = OpTypeInt 32 0
         %11 = OpUndef %10
          %4 = OpFunction %2 None %3
          %5 = OpLabel
               OpBranch %21
         %21 = OpLabel
         %22 = OpPhi %10 %11 %20
               OpBranch %14
         %14 = OpLabel
               OpReturn
               OpFunctionEnd
          %7 = OpFunction %2 None %3
          %8 = OpLabel
               OpBranch %13
         %13 = OpLabel
         %12 = OpPhi %10 %11 %8
               OpReturn
               OpFunctionEnd

Metadata

Metadata

Assignees

No one assigned

    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