-
Notifications
You must be signed in to change notification settings - Fork 247
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
Need to refine definition of a back edge used by structured control flow rules #16
Comments
I think we could use a new concept of "latch edge" and most current uses of "back edge" are replaced by "latch edge". A "latch edge" is either:
Then we get these:
Remove the concept of a back-edge blocks, since it would no longer be used. I think we also want to say that unreachable continue constructs can't be shared: a latch-edge block ends with an unconditional branch. (E.g. it can't branch to two distinct loop headers.) (Aside: An unreachable continue construct can be replaced by a trivial block that just has an OpLabel followed by its unconditional branch. Modulo dead decorations.) Update: fixed the first sentence to say uses of back edge are replaced by latch edge. |
Hm. Given how a do-while loop would be generated (with a conditional branch at the end), I think it's too strong to say that an unreachable continue construct must end with an unconditional branch. |
Another weird case: What if the loop header itself is unreachable? Does that affect the conditions on the continue construct? I suspect it does not, except that in this case the continue construct is probably forced to be unreachable (?). |
I'm prototyping validator support to permit the extra case. It would be simplify book-keeping if we forced the (unreachable) latch block to appear after the loop header. For a reachable latch block, dominance already forces this condition. |
(Sorry if I'm hijacking this thread/issue, I can create a new issue if you want me to, but this seems trivial enough.) Considering that a loop header can contain a conditional branch (-> OpLoopMerge description), the loop header block would also need to contain an OpSelectionMerge in addition to the OpLoopMerge, but this isn't currently allowed by the spec, because both state that (OpLoopMerge|OpSelectionMerge) "must be the second-to-last instruction in its block". => either remove OpBranchConditional from the OpLoopMerge description or refine the "second-to-last" text so that both merge operations can occur in a block. If doing the latter: shouldn't OpLoopMerge allow OpSwitch as well then? |
I'm not so sure that complicating the loop construct like that is a good idea. Conceptually a loop header should only branch to the entry point of the loop and optionally to the merge block of the loop. Allowing more targets from the header would only complicate matters. |
@a2flo: That's a distinct issue so please file it separately. |
This is fixed in the just published Rev. 2 of SPIR-V 1.5 in the Khronos SPIR-V Registry. |
The current definition of a back edge in SPIR-V is not quite correct:
This was a late addition that doesn't quite work with the intent of the structured control flow rules.
Suggestions from @dneto0, in issue KhronosGroup/SPIRV-Tools#270 :
The text was updated successfully, but these errors were encountered: