-
Notifications
You must be signed in to change notification settings - Fork 193
[spv-in] Convert conditional backedges to break if
.
#2290
Conversation
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more @@ Coverage Diff @@
## master #2290 +/- ##
==========================================
- Coverage 82.19% 82.17% -0.02%
==========================================
Files 82 82
Lines 44267 44342 +75
==========================================
+ Hits 36384 36437 +53
- Misses 7883 7905 +22
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than handling this in BlockContext::lower
, it seems like it would be cleaner to detect conditional backedges in Frontend::next_block
's match arm for Op::BranchConditional
.
Rather than pushing a BodyFragment::If
onto the end of ctx.bodies[body_idx]
which BlockContext::lower
then has to analyze, next_block
could notice that the block it's finishing is a continue target (by checking ctx.mergers
), verify that the conditional branch's true_id
and false_id
each refer to the loop header or loop merge block, synthesize a negation expression as necessary, and then stash the proper condition expression handle somewhere. (Perhaps BodyFragment::Loop
should have a break_if: Option<Handle<Expression>>
field?)
I think this should be less circuitous - we'll be taking advantage of what SPIR-V promises us, rather than building weird Naga IR and then taking it apart again.
break if
.break if
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good - thank you for the fix!
I worry that that Op::BranchConditional
match arm is getting pretty long and difficult to follow. I wonder if it's not possible to organize it a bit. But, that doesn't have to be part of this PR.
…eak if`). (#2387) * [spv-in] Convert conditional backedges to `break if`. * Work around pre-Rust2021 semantics (array `.into_iter()` and closure captures). * Update `do-while` expected output for naga v0.10 backend behavior.
Statement::Loop
withbreak_if
expression #1977The only test I added was the reduced
do
-while
example (which only passes with my changes), but also note that the more complex Rust-GPU+SPIR-T motivating example, involving a Rustfor
loop, works as well now: