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

spv/lift: use loop body entry (instead of exit), as the "continue" target. #10

Merged
merged 1 commit into from
Dec 9, 2022

Conversation

eddyb
Copy link
Contributor

@eddyb eddyb commented Nov 18, 2022

As we have no break edges out of SPIR-T loop bodies, any point in the loop body (not nested in another selection/loop) is a valid "continue" target, and we can spare a block by making the whole body that.

In WGSL loops, this corresponds to moving the rest of the loop body (not using break/continue) into the continuing {...} block. (but examples are hard because break if isn't implemented yet in Naga, and our do-while-style loops use SPIR-V "conditional back-edges" which in WGSL require break if - see gfx-rs/naga#1977 (comment) for more details/context)

For tests/data/for-loop.wgsl.spvasm (after spirv-as -> spv-lower-link-lift -> spirv-dis), the change is:

@@ -25,5 +25,5 @@
          %22 = OpLabel
-         %13 = OpPhi %int %int_1 %21 %16 %27
-         %14 = OpPhi %int %int_1 %21 %17 %27
-               OpLoopMerge %28 %27 None
+         %13 = OpPhi %int %int_1 %21 %16 %26
+         %14 = OpPhi %int %int_1 %21 %17 %26
+               OpLoopMerge %28 %23 None
                OpBranch %23
@@ -44,4 +44,2 @@
          %17 = OpPhi %int %20 %24 %11 %25
-               OpBranch %27
-         %27 = OpLabel
                OpBranchConditional %15 %22 %28

(on the "after" side I had to use sed 's/%27/%28/g' on to make the diff more readable wrt renumbering)

@eddyb eddyb merged commit cda161b into main Dec 9, 2022
@eddyb eddyb deleted the abc-always-be-continuing branch December 9, 2022 12:36
@eddyb
Copy link
Contributor Author

eddyb commented Dec 16, 2022

Will sadly have to revert this, because it fails to account for divergence in the loop body.

eddyb added a commit that referenced this pull request Dec 16, 2022
…inue" target. (#10)"

This reverts commit cda161b, reversing
changes made to b050a10.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant