Switch branch order opt from brif/brff to br_icmp, as that's what frontends should produce.
This commit is contained in:
committed by
Benjamin Bouvier
parent
571b87414f
commit
fd6940baaf
@@ -9,12 +9,13 @@
|
|||||||
use crate::cursor::{Cursor, FuncCursor};
|
use crate::cursor::{Cursor, FuncCursor};
|
||||||
use crate::divconst_magic_numbers::{magic_s32, magic_s64, magic_u32, magic_u64};
|
use crate::divconst_magic_numbers::{magic_s32, magic_s64, magic_u32, magic_u64};
|
||||||
use crate::divconst_magic_numbers::{MS32, MS64, MU32, MU64};
|
use crate::divconst_magic_numbers::{MS32, MS64, MU32, MU64};
|
||||||
use crate::ir::condcodes::{CondCode, FloatCC, IntCC};
|
use crate::flowgraph::ControlFlowGraph;
|
||||||
|
use crate::ir::condcodes::{CondCode, IntCC};
|
||||||
use crate::ir::dfg::ValueDef;
|
use crate::ir::dfg::ValueDef;
|
||||||
use crate::ir::instructions::{Opcode, ValueList};
|
use crate::ir::instructions::{Opcode, ValueList};
|
||||||
use crate::ir::types::{I32, I64};
|
use crate::ir::types::{I32, I64};
|
||||||
use crate::ir::Inst;
|
use crate::ir::Inst;
|
||||||
use crate::ir::{DataFlowGraph, Function, InstBuilder, InstructionData, Type, Value};
|
use crate::ir::{DataFlowGraph, Ebb, Function, InstBuilder, InstructionData, Type, Value};
|
||||||
use crate::timing;
|
use crate::timing;
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
@@ -636,17 +637,15 @@ struct BranchOrderInfo {
|
|||||||
term_inst_args: ValueList,
|
term_inst_args: ValueList,
|
||||||
term_dest: Ebb,
|
term_dest: Ebb,
|
||||||
cond_inst: Inst,
|
cond_inst: Inst,
|
||||||
cond_arg: Value,
|
|
||||||
cond_inst_args: ValueList,
|
cond_inst_args: ValueList,
|
||||||
cond_dest: Ebb,
|
cond_dest: Ebb,
|
||||||
kind: BranchOrderKind,
|
kind: BranchOrderKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum BranchOrderKind {
|
enum BranchOrderKind {
|
||||||
BrzToBrnz,
|
BrzToBrnz(Value),
|
||||||
BrnzToBrz,
|
BrnzToBrz(Value),
|
||||||
InvertIntCond(IntCC),
|
InvertIcmpCond(IntCC, Value, Value),
|
||||||
InvertFloatCond(FloatCC),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, ebb: Ebb, inst: Inst) {
|
fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, ebb: Ebb, inst: Inst) {
|
||||||
@@ -695,8 +694,8 @@ fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, ebb: Ebb, inst
|
|||||||
};
|
};
|
||||||
|
|
||||||
let kind = match opcode {
|
let kind = match opcode {
|
||||||
Opcode::Brz => BranchOrderKind::BrzToBrnz,
|
Opcode::Brz => BranchOrderKind::BrzToBrnz(cond_arg),
|
||||||
Opcode::Brnz => BranchOrderKind::BrnzToBrz,
|
Opcode::Brnz => BranchOrderKind::BrnzToBrz(cond_arg),
|
||||||
_ => panic!("unexpected opcode"),
|
_ => panic!("unexpected opcode"),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -705,54 +704,29 @@ fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, ebb: Ebb, inst
|
|||||||
term_inst_args: args.clone(),
|
term_inst_args: args.clone(),
|
||||||
term_dest: destination,
|
term_dest: destination,
|
||||||
cond_inst: prev_inst,
|
cond_inst: prev_inst,
|
||||||
cond_arg: cond_arg,
|
|
||||||
cond_inst_args: prev_args.clone(),
|
cond_inst_args: prev_args.clone(),
|
||||||
cond_dest: *cond_dest,
|
cond_dest: *cond_dest,
|
||||||
kind: kind,
|
kind: kind,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InstructionData::BranchInt {
|
InstructionData::BranchIcmp {
|
||||||
opcode: Opcode::Brif,
|
opcode: Opcode::BrIcmp,
|
||||||
args: ref prev_args,
|
|
||||||
cond,
|
cond,
|
||||||
destination: cond_dest,
|
destination: cond_dest,
|
||||||
..
|
args: ref prev_args,
|
||||||
} => {
|
} => {
|
||||||
let cond_arg = {
|
let (x_arg, y_arg) = {
|
||||||
let args = pos.func.dfg.inst_args(prev_inst);
|
let args = pos.func.dfg.inst_args(prev_inst);
|
||||||
args[0]
|
(args[0], args[1])
|
||||||
};
|
};
|
||||||
BranchOrderInfo {
|
BranchOrderInfo {
|
||||||
term_inst: inst,
|
term_inst: inst,
|
||||||
term_inst_args: args.clone(),
|
term_inst_args: args.clone(),
|
||||||
term_dest: destination,
|
term_dest: destination,
|
||||||
cond_inst: prev_inst,
|
cond_inst: prev_inst,
|
||||||
cond_arg: cond_arg,
|
|
||||||
cond_inst_args: prev_args.clone(),
|
cond_inst_args: prev_args.clone(),
|
||||||
cond_dest: *cond_dest,
|
cond_dest: *cond_dest,
|
||||||
kind: BranchOrderKind::InvertIntCond(*cond),
|
kind: BranchOrderKind::InvertIcmpCond(*cond, x_arg, y_arg),
|
||||||
}
|
|
||||||
}
|
|
||||||
InstructionData::BranchFloat {
|
|
||||||
opcode: Opcode::Brff,
|
|
||||||
args: ref prev_args,
|
|
||||||
cond,
|
|
||||||
destination: cond_dest,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
let cond_arg = {
|
|
||||||
let args = pos.func.dfg.inst_args(prev_inst);
|
|
||||||
args[0]
|
|
||||||
};
|
|
||||||
BranchOrderInfo {
|
|
||||||
term_inst: inst,
|
|
||||||
term_inst_args: args.clone(),
|
|
||||||
term_dest: destination,
|
|
||||||
cond_inst: prev_inst,
|
|
||||||
cond_arg: cond_arg,
|
|
||||||
cond_inst_args: prev_args.clone(),
|
|
||||||
cond_dest: *cond_dest,
|
|
||||||
kind: BranchOrderKind::InvertFloatCond(*cond),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => return,
|
_ => return,
|
||||||
@@ -773,36 +747,36 @@ fn branch_order(pos: &mut FuncCursor, cfg: &mut ControlFlowGraph, ebb: Ebb, inst
|
|||||||
.to_vec()
|
.to_vec()
|
||||||
};
|
};
|
||||||
|
|
||||||
pos.func
|
|
||||||
.dfg
|
|
||||||
.replace(info.term_inst)
|
|
||||||
.fallthrough(info.cond_dest, &cond_args[1..]);
|
|
||||||
|
|
||||||
match info.kind {
|
match info.kind {
|
||||||
BranchOrderKind::BrnzToBrz => {
|
BranchOrderKind::BrnzToBrz(cond_arg) => {
|
||||||
|
pos.func
|
||||||
|
.dfg
|
||||||
|
.replace(info.term_inst)
|
||||||
|
.fallthrough(info.cond_dest, &cond_args[1..]);
|
||||||
pos.func
|
pos.func
|
||||||
.dfg
|
.dfg
|
||||||
.replace(info.cond_inst)
|
.replace(info.cond_inst)
|
||||||
.brz(info.cond_arg, info.term_dest, &term_args);
|
.brz(cond_arg, info.term_dest, &term_args);
|
||||||
}
|
}
|
||||||
BranchOrderKind::BrzToBrnz => {
|
BranchOrderKind::BrzToBrnz(cond_arg) => {
|
||||||
|
pos.func
|
||||||
|
.dfg
|
||||||
|
.replace(info.term_inst)
|
||||||
|
.fallthrough(info.cond_dest, &cond_args[1..]);
|
||||||
pos.func
|
pos.func
|
||||||
.dfg
|
.dfg
|
||||||
.replace(info.cond_inst)
|
.replace(info.cond_inst)
|
||||||
.brnz(info.cond_arg, info.term_dest, &term_args);
|
.brnz(cond_arg, info.term_dest, &term_args);
|
||||||
}
|
}
|
||||||
BranchOrderKind::InvertIntCond(cond) => {
|
BranchOrderKind::InvertIcmpCond(cond, x_arg, y_arg) => {
|
||||||
pos.func.dfg.replace(info.cond_inst).brif(
|
pos.func
|
||||||
|
.dfg
|
||||||
|
.replace(info.term_inst)
|
||||||
|
.fallthrough(info.cond_dest, &cond_args[2..]);
|
||||||
|
pos.func.dfg.replace(info.cond_inst).br_icmp(
|
||||||
cond.inverse(),
|
cond.inverse(),
|
||||||
info.cond_arg,
|
x_arg,
|
||||||
info.term_dest,
|
y_arg,
|
||||||
&term_args,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
BranchOrderKind::InvertFloatCond(cond) => {
|
|
||||||
pos.func.dfg.replace(info.cond_inst).brff(
|
|
||||||
cond.inverse(),
|
|
||||||
info.cond_arg,
|
|
||||||
info.term_dest,
|
info.term_dest,
|
||||||
&term_args,
|
&term_args,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -55,10 +55,9 @@ ebb2:
|
|||||||
; nextln: return v4
|
; nextln: return v4
|
||||||
; nextln: }
|
; nextln: }
|
||||||
|
|
||||||
function %brif_inversion(i32) -> i32 {
|
function %br_icmp_inversion(i32, i32) -> i32 {
|
||||||
ebb0(v0: i32):
|
ebb0(v0: i32, v1: i32):
|
||||||
v1 = ifcmp_imm v0, 42
|
br_icmp ugt v0, v1, ebb1
|
||||||
brif ugt v1, ebb1
|
|
||||||
jump ebb2
|
jump ebb2
|
||||||
ebb1:
|
ebb1:
|
||||||
v2 = iconst.i32 1
|
v2 = iconst.i32 1
|
||||||
@@ -67,10 +66,9 @@ ebb2:
|
|||||||
v3 = iconst.i32 2
|
v3 = iconst.i32 2
|
||||||
return v3
|
return v3
|
||||||
}
|
}
|
||||||
; sameln: function %brif_inversion
|
; sameln: function %br_icmp_inversio
|
||||||
; nextln: ebb0(v0: i32):
|
; nextln: ebb0(v0: i32, v1: i32):
|
||||||
; nextln: v1 = ifcmp_imm v0, 42
|
; nextln: br_icmp ule v0, v1, ebb2
|
||||||
; nextln: brif ule v1, ebb2
|
|
||||||
; nextln: fallthrough ebb1
|
; nextln: fallthrough ebb1
|
||||||
; nextln:
|
; nextln:
|
||||||
; nextln: ebb1:
|
; nextln: ebb1:
|
||||||
@@ -81,30 +79,3 @@ ebb2:
|
|||||||
; nextln: v3 = iconst.i32 2
|
; nextln: v3 = iconst.i32 2
|
||||||
; nextln: return v3
|
; nextln: return v3
|
||||||
; nextln: }
|
; nextln: }
|
||||||
|
|
||||||
function %brff_inversion(f32, f32) -> i32 {
|
|
||||||
ebb0(v0: f32, v1: f32):
|
|
||||||
v2 = ffcmp v0, v1
|
|
||||||
brff gt v2, ebb1
|
|
||||||
jump ebb2
|
|
||||||
ebb1:
|
|
||||||
v3 = iconst.i32 1
|
|
||||||
return v3
|
|
||||||
ebb2:
|
|
||||||
v4 = iconst.i32 2
|
|
||||||
return v4
|
|
||||||
}
|
|
||||||
; sameln: function %brff_inversion
|
|
||||||
; nextln: ebb0(v0: f32, v1: f32):
|
|
||||||
; nextln: v2 = ffcmp v0, v1
|
|
||||||
; nextln: brff ule v2, ebb2
|
|
||||||
; nextln: fallthrough ebb1
|
|
||||||
; nextln:
|
|
||||||
; nextln: ebb1:
|
|
||||||
; nextln: v3 = iconst.i32 1
|
|
||||||
; nextln: return v3
|
|
||||||
; nextln:
|
|
||||||
; nextln: ebb2:
|
|
||||||
; nextln: v4 = iconst.i32 2
|
|
||||||
; nextln: return v4
|
|
||||||
; nextln: }
|
|
||||||
|
|||||||
Reference in New Issue
Block a user