Legalize brz.i128 and brnz.i128

This commit is contained in:
bjorn3
2019-06-29 16:38:53 +02:00
committed by Dan Gohman
parent 83ac6dd4d4
commit 762b5e494b
3 changed files with 54 additions and 1 deletions

View File

@@ -415,6 +415,11 @@ fn gen_transform<'a>(
fmt.line("let removed = pos.remove_inst();"); fmt.line("let removed = pos.remove_inst();");
fmt.line("debug_assert_eq!(removed, inst);"); fmt.line("debug_assert_eq!(removed, inst);");
} }
if transform.def_pool.get(transform.src).apply.inst.is_branch {
fmt.line("cfg.recompute_ebb(pos.func, pos.current_ebb().unwrap());");
}
fmt.line("return true;"); fmt.line("return true;");
}); });
fmt.line("}"); fmt.line("}");

View File

@@ -4,7 +4,7 @@ use crate::cdsl::xform::{TransformGroupBuilder, TransformGroups};
use crate::shared::immediates::Immediates; use crate::shared::immediates::Immediates;
use crate::shared::types::Float::{F32, F64}; use crate::shared::types::Float::{F32, F64};
use crate::shared::types::Int::{I16, I32, I64, I8}; use crate::shared::types::Int::{I16, I128, I32, I64, I8};
pub(crate) fn define(insts: &InstructionGroup, imm: &Immediates) -> TransformGroups { pub(crate) fn define(insts: &InstructionGroup, imm: &Immediates) -> TransformGroups {
let mut narrow = TransformGroupBuilder::new( let mut narrow = TransformGroupBuilder::new(
@@ -49,6 +49,8 @@ pub(crate) fn define(insts: &InstructionGroup, imm: &Immediates) -> TransformGro
let bor = insts.by_name("bor"); let bor = insts.by_name("bor");
let bor_imm = insts.by_name("bor_imm"); let bor_imm = insts.by_name("bor_imm");
let bor_not = insts.by_name("bor_not"); let bor_not = insts.by_name("bor_not");
let brnz = insts.by_name("brnz");
let brz = insts.by_name("brz");
let br_icmp = insts.by_name("br_icmp"); let br_icmp = insts.by_name("br_icmp");
let br_table = insts.by_name("br_table"); let br_table = insts.by_name("br_table");
let bxor = insts.by_name("bxor"); let bxor = insts.by_name("bxor");
@@ -177,9 +179,11 @@ pub(crate) fn define(insts: &InstructionGroup, imm: &Immediates) -> TransformGro
let al = var("al"); let al = var("al");
let ah = var("ah"); let ah = var("ah");
let cc = var("cc"); let cc = var("cc");
let ebb = var("ebb");
let ptr = var("ptr"); let ptr = var("ptr");
let flags = var("flags"); let flags = var("flags");
let offset = var("off"); let offset = var("off");
let vararg = var("vararg");
narrow.legalize( narrow.legalize(
def!(a = iadd(x, y)), def!(a = iadd(x, y)),
@@ -227,6 +231,26 @@ pub(crate) fn define(insts: &InstructionGroup, imm: &Immediates) -> TransformGro
], ],
); );
narrow.legalize(
def!(brz.I128(x, ebb, vararg)),
vec![
def!((xl, xh) = isplit(x)),
def!(a = icmp_imm(Literal::enumerator_for(intcc, "eq"), xl, Literal::constant(imm64, 0))),
def!(b = icmp_imm(Literal::enumerator_for(intcc, "eq"), xh, Literal::constant(imm64, 0))),
def!(c = band(a, b)),
def!(brz(c, ebb, vararg)),
],
);
narrow.legalize(
def!(brnz.I128(x, ebb, vararg)),
vec![
def!((xl, xh) = isplit(x)),
def!(brnz(xl, ebb, vararg)),
def!(brnz(xh, ebb, vararg)),
],
);
// Widen instructions with one input operand. // Widen instructions with one input operand.
for &op in &[bnot, popcnt] { for &op in &[bnot, popcnt] {
for &int_ty in &[I8, I16] { for &int_ty in &[I8, I16] {

View File

@@ -0,0 +1,24 @@
test compile
target x86_64
function u0:0(i128) -> i8 fast {
ebb0(v0: i128):
brz v0, ebb1
v1 = iconst.i8 0
return v1
ebb1:
v2 = iconst.i8 1
return v2
}
function u0:1(i128) -> i8 fast {
ebb0(v0: i128):
brnz v0, ebb1
v1 = iconst.i8 0
return v1
ebb1:
v2 = iconst.i8 1
return v2
}