Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inliner generates invalid OpLabel if callee has single return in block that does not appear last #755

Closed
dneto0 opened this issue Aug 9, 2017 · 2 comments
Assignees
Labels
Projects

Comments

@dneto0
Copy link
Collaborator

dneto0 commented Aug 9, 2017

Example code:

               OpCapability Shader
          %1 = OpExtInstImport "GLSL.std.450"
               OpMemoryModel Logical GLSL450
               OpEntryPoint Vertex %main "main"
               OpSource GLSL 450
               OpName %main "main"
               OpName %foo_ "foo("
       %void = OpTypeVoid
          %3 = OpTypeFunction %void
       %bool = OpTypeBool
       %true = OpConstantTrue %bool
       %main = OpFunction %void None %3
          %5 = OpLabel
         %12 = OpFunctionCall %void %foo_
               OpReturn
               OpFunctionEnd
       %foo_ = OpFunction %void None %3
          %7 = OpLabel
               OpSelectionMerge %11 None
               OpBranchConditional %true %10 %11
         %11 = OpLabel
               OpReturn  ;  This causes returnLabelId to be non-zero, but earlyReturn is false.
         %10 = OpLabel
               OpBranch %11
               OpFunctionEnd

It's generated from this vertex shader, but where I reorder, in the SPIR-V assembly, the last two basic blocks of the "foo" function:

#version 450

void foo() {
 if (true) {
 }
}
void main() {
  foo();
}

When running spirv-opt with inline-entry-points-exhaustive:

  • returnLabelId is non-zero since we encountered an OpReturn well before the OpFunctionEnd
  • but earlyReturn is false
  • but at OpFunctionEnd we generate "continue target" with OpLabel for result id singleTripLoopContinueId. But that is still zero.
  • this causes a new instruction with OpLabel opcode, but zero result Id, and generates a 1-word OpLabel instruction, which is invalid.

Likely remedy is to guard the codegen of continue target block by earlyReturn. Still have to create the block with label Id returnLabelId.

@dneto0
Copy link
Collaborator Author

dneto0 commented Aug 9, 2017

I expect to have patch soon.
Cc @greg-lunarg

@dneto0
Copy link
Collaborator Author

dneto0 commented Aug 9, 2017

I have a code fix at https://github.com/dneto0/SPIRV-Tools/tree/inline-avoid-nil-label
Need to make a test for it.

@dneto0 dneto0 changed the title inliner generates invalid OpLabel if calle has single return in block that does not appear last inliner generates invalid OpLabel if callee has single return in block that does not appear last Aug 10, 2017
@dneto0 dneto0 added the bug label Aug 10, 2017
@dneto0 dneto0 self-assigned this Aug 10, 2017
dneto0 added a commit to dneto0/SPIRV-Tools that referenced this issue Aug 10, 2017
Avoid generating an invalid OpLabel.
Create the continue target for the single-trip loop only if
you actually created the header for the single-trip loop.

Fixes KhronosGroup#755
dneto0 added a commit to dneto0/SPIRV-Tools that referenced this issue Aug 10, 2017
Avoid generating an invalid OpLabel.
Create the continue target for the single-trip loop only if
you actually created the header for the single-trip loop.

Fixes KhronosGroup#755
@dneto0 dneto0 added this to Done in Optimizer Aug 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

1 participant