Address code review comments, simplifying some bits of branch_opt.

This commit is contained in:
Tyler McMullen
2019-04-10 13:41:49 -07:00
committed by Benjamin Bouvier
parent 402d0d9c83
commit 5596b5fadc
2 changed files with 79 additions and 80 deletions

View File

@@ -545,14 +545,8 @@ fn simplify(pos: &mut FuncCursor, inst: Inst) {
struct BranchOptInfo {
br_inst: Inst,
cmp_arg: Value,
destination: Ebb,
args: ValueList,
kind: BranchOptKind,
}
enum BranchOptKind {
EqualZero,
NotEqualZero,
new_opcode: Opcode,
}
/// Fold comparisons into branch operations when possible.
@@ -561,12 +555,10 @@ enum BranchOptKind {
/// result in a `brz` or `brnz` branch. It folds those two operations into a
/// single `brz` or `brnz`.
fn branch_opt(pos: &mut FuncCursor, inst: Inst) {
let info = match pos.func.dfg[inst] {
InstructionData::Branch {
opcode,
destination,
ref args,
} => {
let mut info = if let InstructionData::Branch {
opcode, ref args, ..
} = pos.func.dfg[inst]
{
let first_arg = {
let args = pos.func.dfg.inst_args(inst);
args[0]
@@ -599,26 +591,33 @@ fn branch_opt(pos: &mut FuncCursor, inst: Inst) {
_ => return,
};
let kind = match cond {
IntCC::Equal => BranchOptKind::EqualZero,
IntCC::NotEqual => BranchOptKind::NotEqualZero,
let new_opcode = match cond {
IntCC::Equal => Opcode::Brz,
IntCC::NotEqual => Opcode::Brnz,
_ => return,
};
BranchOptInfo {
br_inst: inst,
cmp_arg: cmp_arg,
destination: destination,
args: args.clone(),
kind: kind,
new_opcode: new_opcode,
}
} else {
return;
}
}
_ => return,
} else {
return;
};
info.args.as_mut_slice(&mut pos.func.dfg.value_lists)[0] = info.cmp_arg;
if let InstructionData::Branch { ref mut opcode, .. } = pos.func.dfg[info.br_inst] {
*opcode = info.new_opcode;
} else {
panic!();
}
/*
match info.kind {
BranchOptKind::EqualZero => {
let args = info.args.as_slice(&pos.func.dfg.value_lists)[1..].to_vec();
@@ -635,6 +634,7 @@ fn branch_opt(pos: &mut FuncCursor, inst: Inst) {
.brnz(info.cmp_arg, info.destination, &args);
}
}
*/
}
struct BranchOrderInfo {
@@ -696,7 +696,6 @@ fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, ebb: Ebb, inst
opcode,
args: ref prev_args,
destination: cond_dest,
..
} => {
let cond_arg = {
let args = pos.func.dfg.inst_args(prev_inst);
@@ -762,7 +761,7 @@ fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, ebb: Ebb, inst
pos.func
.dfg
.replace(info.term_inst)
.fallthrough(info.cond_dest, &cond_args[1..]);
.jump(info.cond_dest, &cond_args[1..]);
pos.func
.dfg
.replace(info.cond_inst)
@@ -772,7 +771,7 @@ fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, ebb: Ebb, inst
pos.func
.dfg
.replace(info.term_inst)
.fallthrough(info.cond_dest, &cond_args[1..]);
.jump(info.cond_dest, &cond_args[1..]);
pos.func
.dfg
.replace(info.cond_inst)
@@ -782,7 +781,7 @@ fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, ebb: Ebb, inst
pos.func
.dfg
.replace(info.term_inst)
.fallthrough(info.cond_dest, &cond_args[2..]);
.jump(info.cond_dest, &cond_args[2..]);
pos.func.dfg.replace(info.cond_inst).br_icmp(
cond.inverse(),
x_arg,

View File

@@ -17,7 +17,7 @@ ebb2:
; nextln: ebb0(v0: i32):
; nextln: v1 = icmp_imm eq v0, 0
; nextln: brnz v0, ebb2
; nextln: fallthrough ebb1
; nextln: jump ebb1
; nextln:
; nextln: ebb1:
; nextln: v3 = iconst.i32 1
@@ -44,7 +44,7 @@ ebb2:
; nextln: ebb0(v0: i32):
; nextln: v1 = icmp_imm ne v0, 0
; nextln: brnz v0, ebb2
; nextln: fallthrough ebb1
; nextln: jump ebb1
; nextln:
; nextln: ebb1:
; nextln: v3 = iconst.i32 1
@@ -69,7 +69,7 @@ ebb2:
; sameln: function %br_icmp_inversio
; nextln: ebb0(v0: i32, v1: i32):
; nextln: br_icmp ule v0, v1, ebb2
; nextln: fallthrough ebb1
; nextln: jump ebb1
; nextln:
; nextln: ebb1:
; nextln: v2 = iconst.i32 1