diff --git a/cranelift/codegen/meta/src/shared/legalize.rs b/cranelift/codegen/meta/src/shared/legalize.rs index 041937b8f8..482f5c69c6 100644 --- a/cranelift/codegen/meta/src/shared/legalize.rs +++ b/cranelift/codegen/meta/src/shared/legalize.rs @@ -139,6 +139,7 @@ pub(crate) fn define(insts: &InstructionGroup, imm: &Immediates) -> TransformGro expand.custom_legalize(trapnz, "expand_cond_trap"); expand.custom_legalize(br_table, "expand_br_table"); expand.custom_legalize(select, "expand_select"); + widen.custom_legalize(select, "expand_select"); // small ints // Custom expansions for floating point constants. // These expansions require bit-casting or creating constant pool entries. @@ -149,6 +150,10 @@ pub(crate) fn define(insts: &InstructionGroup, imm: &Immediates) -> TransformGro expand.custom_legalize(insts.by_name("stack_load"), "expand_stack_load"); expand.custom_legalize(insts.by_name("stack_store"), "expand_stack_store"); + // Custom expansions for small stack memory acccess. + widen.custom_legalize(insts.by_name("stack_load"), "expand_stack_load"); + widen.custom_legalize(insts.by_name("stack_store"), "expand_stack_store"); + // List of variables to reuse in patterns. let x = var("x"); let y = var("y"); @@ -612,6 +617,18 @@ pub(crate) fn define(insts: &InstructionGroup, imm: &Immediates) -> TransformGro } } + for &ty in &[I8, I16] { + widen.legalize( + def!(brz.ty(x, ebb, vararg)), + vec![def!(a = uextend.I32(x)), def!(brz(a, ebb, vararg))], + ); + + widen.legalize( + def!(brnz.ty(x, ebb, vararg)), + vec![def!(a = uextend.I32(x)), def!(brnz(a, ebb, vararg))], + ); + } + // Expand integer operations with carry for RISC architectures that don't have // the flags. let intcc_ult = Literal::enumerator_for(&imm.intcc, "ult"); diff --git a/cranelift/filetests/filetests/isa/x86/brz-i8-run.clif b/cranelift/filetests/filetests/isa/x86/brz-i8-run.clif new file mode 100644 index 0000000000..c050a91425 --- /dev/null +++ b/cranelift/filetests/filetests/isa/x86/brz-i8-run.clif @@ -0,0 +1,34 @@ +test run +target x86_64 + +function u0:0() -> b1 { +ebb0: + v0 = iconst.i8 0 + brz v0, ebb1 + jump ebb2 + +ebb1: + v1 = bconst.b1 true + return v1 + +ebb2: + v2 = bconst.b1 false + return v2 +} +; run + +function u0:1() -> b1 { +ebb0: + v0 = iconst.i8 0 + brnz v0, ebb1 + jump ebb2 + +ebb1: + v1 = bconst.b1 false + return v1 + +ebb2: + v2 = bconst.b1 true + return v2 +} +; run diff --git a/cranelift/filetests/filetests/isa/x86/brz-i8.clif b/cranelift/filetests/filetests/isa/x86/brz-i8.clif new file mode 100644 index 0000000000..a5cc03c985 --- /dev/null +++ b/cranelift/filetests/filetests/isa/x86/brz-i8.clif @@ -0,0 +1,38 @@ +test compile +target x86_64 + +function u0:0() -> b1 { +ebb0: + v0 = iconst.i8 0 + ; check: v0 = iconst.i8 0 + brz v0, ebb1 + ; nextln: v3 = uextend.i32 v0 + ; nextln: brz v3, ebb1 + jump ebb2 + +ebb1: + v1 = bconst.b1 true + return v1 + +ebb2: + v2 = bconst.b1 false + return v2 +} + +function u0:1() -> b1 { +ebb0: + v0 = iconst.i8 0 + ; check: v0 = iconst.i8 0 + brnz v0, ebb1 + ; nextln: v3 = uextend.i32 v0 + ; nextln: brnz v3, ebb1 + jump ebb2 + +ebb1: + v1 = bconst.b1 false + return v1 + +ebb2: + v2 = bconst.b1 true + return v2 +} diff --git a/cranelift/filetests/filetests/isa/x86/select-i8.clif b/cranelift/filetests/filetests/isa/x86/select-i8.clif new file mode 100644 index 0000000000..aac59c1e9c --- /dev/null +++ b/cranelift/filetests/filetests/isa/x86/select-i8.clif @@ -0,0 +1,8 @@ +test compile +target x86_64 + +function u0:0(b1, i8, i8) -> i8 { +ebb0(v0: b1, v1: i8, v2: i8): + v3 = select v0, v1, v2 + return v3 +} diff --git a/cranelift/filetests/filetests/isa/x86/stack-load-store8.clif b/cranelift/filetests/filetests/isa/x86/stack-load-store8.clif new file mode 100644 index 0000000000..2c368f6dfc --- /dev/null +++ b/cranelift/filetests/filetests/isa/x86/stack-load-store8.clif @@ -0,0 +1,19 @@ +test compile +target x86_64 + +function u0:0(i8) -> i8 { + ss0 = explicit_slot 1 + +ebb0(v0: i8): + stack_store v0, ss0 + ; check: v2 = stack_addr.i64 ss0 + ; nextln: v3 = uextend.i32 v0 + ; nextln: istore8 notrap aligned v3, v2 + + v1 = stack_load.i8 ss0 + ; check: v4 = stack_addr.i64 ss0 + ; nextln: v5 = uload8.i32 notrap aligned v4 + ; nextln: v1 = ireduce.i8 v5 + + return v1 +}