spv-in: Remove if when both branches are equal

This commit is contained in:
João Capucho 2021-12-15 22:07:10 +00:00 committed by Dzmitry Malyshau
parent 4334f0e6a9
commit 049b48b319

View File

@ -2769,9 +2769,16 @@ impl<I: Iterator<Item = u32>> Parser<I> {
get_expr_handle!(condition_id, lexp)
};
block.extend(emitter.finish(ctx.expressions));
ctx.blocks.insert(block_id, block);
let body = &mut ctx.bodies[body_idx];
body.data.push(BodyFragment::BlockId(block_id));
let true_id = self.next()?;
let false_id = self.next()?;
let same_target = true_id == false_id;
// Start a body block for the `accept` branch.
let accept = ctx.bodies.len();
let mut accept_block = Body::with_parent(body_idx);
@ -2780,13 +2787,29 @@ impl<I: Iterator<Item = u32>> Parser<I> {
// merge or continue block, then put a `Break` or `Continue`
// statement in this new body block.
if let Some(info) = ctx.mergers.get(&true_id) {
merger(&mut accept_block, info)
merger(
match same_target {
true => &mut ctx.bodies[body_idx],
false => &mut accept_block,
},
info,
)
} else {
// Note the body index for the block we're branching to.
let prev = ctx.body_for_label.insert(true_id, accept);
let prev = ctx.body_for_label.insert(
true_id,
match same_target {
true => body_idx,
false => accept,
},
);
debug_assert!(prev.is_none());
}
if same_target {
return Ok(());
}
ctx.bodies.push(accept_block);
// Handle the `reject` branch just like the `accept` block.
@ -2802,12 +2825,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
ctx.bodies.push(reject_block);
block.extend(emitter.finish(ctx.expressions));
ctx.blocks.insert(block_id, block);
let body = &mut ctx.bodies[body_idx];
// Make sure the vector has space for at least two more allocations
body.data.reserve(2);
body.data.push(BodyFragment::BlockId(block_id));
body.data.push(BodyFragment::If {
condition,
accept,