mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-04-21 20:40:36 +02:00
nak: Optimize jumps to fall-through if possible
This saves 15 instructions on the compute shader in Sascha Willems' computecloth example. Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26473>
This commit is contained in:
parent
b2420fae4b
commit
586c34b19c
1 changed files with 20 additions and 1 deletions
|
|
@ -118,9 +118,28 @@ fn rewrite_cfg(func: &mut Function) {
|
|||
let _ = std::mem::replace(&mut func.blocks, builder.as_cfg());
|
||||
}
|
||||
|
||||
/// Replace jumps to the following block with fall-through
|
||||
fn opt_fall_through(func: &mut Function) {
|
||||
for i in 0..func.blocks.len() - 1 {
|
||||
let remove_last_instr = match func.blocks[i].branch() {
|
||||
Some(b) => match b.op {
|
||||
Op::Bra(OpBra { target }) => target == func.blocks[i + 1].label,
|
||||
_ => false,
|
||||
},
|
||||
None => false,
|
||||
};
|
||||
|
||||
if remove_last_instr {
|
||||
func.blocks[i].instrs.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Function {
|
||||
pub fn opt_jump_thread(&mut self) {
|
||||
jump_thread(self);
|
||||
if jump_thread(self) {
|
||||
opt_fall_through(self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue