Repository navigation
merge blocks optimization - #35
Conversation
5f7308c to
46c5d0d
Compare
cfallin
left a comment
There was a problem hiding this comment.
Thanks! One comment below but otherwise LGTM.
| assert_eq!(succ.params.len(), target.args.len()); | ||
| for (&(_, from), &to) in succ.params.iter().zip(target.args.iter()) { | ||
| body.values[from] = ValueDef::Alias(to); | ||
| body.value_blocks[from] = pred_id; |
There was a problem hiding this comment.
I don't think this is correct: the argument passed to the blockparam may not be actually computed in the predecessor (it could be defined in any dominating block), right? I think we can copy it from value_blocks[to].
... actually I think we can use Function::set_alias. I also see that that doesn't update value_blocks (which was a later addition); please go ahead and update that as well while you're at it!
There was a problem hiding this comment.
(This didn't trigger any failures locally within the crate because it is only a pub export to users, not used for any opt or codegen here; but we should keep it updated, and probably validate it too)
There was a problem hiding this comment.
Pushed a followup commit fixing the aliasing. Though I can't use body.set_alias(&mut self) there cause succ and target are borrowed from body, so I'll keep doing it manually to satisfy borrowck.
|
Thanks! |
I've found that even simple rust programs such as:
compiled to
wasm32-unknown-unknownand parsed by waffle contains multiple basic blocks:I'm building a new codegen backend based on waffle, and it's a lot easier if I could just focus on basic instructions and ignore control flow for now. So I've made an optimization that merges waffle's bbs even in situations where
empty_blocksbails out.With this PR, the function above turns into:
(Note that standard display does not show the
v0 = v5alias...)For more examples, see the tests added by the first commit, which are modified by the second commit adding the
merge_blocksopt. I've made use of rust-analyzer'sexpect-testcrate so updating the output is trivial withUPDATE_EXPECT=1env var. Also survives fuzzing for a few minutes with #34 (before dying on a parser unwrap).