More i8 legalizations (#1253)
* Legalize stack_{load,store}.i8, fixes #433
* Legalize select.i8, cc: #466
* Legalize brz.i8 and brnz.i8, cc: #1117
This commit is contained in:
@@ -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");
|
||||
|
||||
34
cranelift/filetests/filetests/isa/x86/brz-i8-run.clif
Normal file
34
cranelift/filetests/filetests/isa/x86/brz-i8-run.clif
Normal file
@@ -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
|
||||
38
cranelift/filetests/filetests/isa/x86/brz-i8.clif
Normal file
38
cranelift/filetests/filetests/isa/x86/brz-i8.clif
Normal file
@@ -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
|
||||
}
|
||||
8
cranelift/filetests/filetests/isa/x86/select-i8.clif
Normal file
8
cranelift/filetests/filetests/isa/x86/select-i8.clif
Normal file
@@ -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
|
||||
}
|
||||
19
cranelift/filetests/filetests/isa/x86/stack-load-store8.clif
Normal file
19
cranelift/filetests/filetests/isa/x86/stack-load-store8.clif
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user