cranelift: Remove booleans (#5031)
Remove the boolean types from cranelift, and the associated instructions breduce, bextend, bconst, and bint. Standardize on using 1/0 for the return value from instructions that produce scalar boolean results, and -1/0 for boolean vector elements. Fixes #3205 Co-authored-by: Afonso Bordado <afonso360@users.noreply.github.com> Co-authored-by: Ulrich Weigand <ulrich.weigand@de.ibm.com> Co-authored-by: Chris Fallin <chris@cfallin.org>
This commit is contained in:
@@ -1012,13 +1012,13 @@ impl<'a> FunctionBuilder<'a> {
|
||||
use IntCC::*;
|
||||
let (zero_cc, empty_imm) = match int_cc {
|
||||
//
|
||||
Equal => (Equal, true),
|
||||
NotEqual => (NotEqual, false),
|
||||
Equal => (Equal, 1),
|
||||
NotEqual => (NotEqual, 0),
|
||||
|
||||
UnsignedLessThan => (SignedLessThan, false),
|
||||
UnsignedGreaterThanOrEqual => (SignedGreaterThanOrEqual, true),
|
||||
UnsignedGreaterThan => (SignedGreaterThan, false),
|
||||
UnsignedLessThanOrEqual => (SignedLessThanOrEqual, true),
|
||||
UnsignedLessThan => (SignedLessThan, 0),
|
||||
UnsignedGreaterThanOrEqual => (SignedGreaterThanOrEqual, 1),
|
||||
UnsignedGreaterThan => (SignedGreaterThan, 0),
|
||||
UnsignedLessThanOrEqual => (SignedLessThanOrEqual, 1),
|
||||
|
||||
SignedLessThan
|
||||
| SignedGreaterThanOrEqual
|
||||
@@ -1029,7 +1029,7 @@ impl<'a> FunctionBuilder<'a> {
|
||||
};
|
||||
|
||||
if size == 0 {
|
||||
return self.ins().bconst(types::B1, empty_imm);
|
||||
return self.ins().iconst(types::I8, empty_imm);
|
||||
}
|
||||
|
||||
// Future work could consider expanding this to handle more-complex scenarios.
|
||||
@@ -1562,8 +1562,8 @@ block0:
|
||||
v1 -> v4
|
||||
v3 = iconst.i64 0
|
||||
v0 -> v3
|
||||
v2 = bconst.b1 true
|
||||
return v2 ; v2 = true",
|
||||
v2 = iconst.i8 1
|
||||
return v2 ; v2 = 1",
|
||||
|builder, target, x, y| {
|
||||
builder.emit_small_memory_compare(
|
||||
target.frontend_config(),
|
||||
@@ -1718,7 +1718,7 @@ block0:
|
||||
.expect("Should be able to create backend with default flags");
|
||||
|
||||
let mut sig = Signature::new(target.default_call_conv());
|
||||
sig.returns.push(AbiParam::new(B1));
|
||||
sig.returns.push(AbiParam::new(I8));
|
||||
|
||||
let mut fn_ctx = FunctionBuilderContext::new();
|
||||
let mut func = Function::with_name_signature(UserFuncName::testcase("sample"), sig);
|
||||
@@ -1744,7 +1744,7 @@ block0:
|
||||
|
||||
check(
|
||||
&func,
|
||||
&format!("function %sample() -> b1 system_v {{{}\n}}\n", expected),
|
||||
&format!("function %sample() -> i8 system_v {{{}\n}}\n", expected),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1752,7 +1752,7 @@ block0:
|
||||
fn undef_vector_vars() {
|
||||
let mut sig = Signature::new(CallConv::SystemV);
|
||||
sig.returns.push(AbiParam::new(I8X16));
|
||||
sig.returns.push(AbiParam::new(B8X16));
|
||||
sig.returns.push(AbiParam::new(I8X16));
|
||||
sig.returns.push(AbiParam::new(F32X4));
|
||||
|
||||
let mut fn_ctx = FunctionBuilderContext::new();
|
||||
@@ -1765,7 +1765,7 @@ block0:
|
||||
let b = Variable::new(1);
|
||||
let c = Variable::new(2);
|
||||
builder.declare_var(a, I8X16);
|
||||
builder.declare_var(b, B8X16);
|
||||
builder.declare_var(b, I8X16);
|
||||
builder.declare_var(c, F32X4);
|
||||
builder.switch_to_block(block0);
|
||||
|
||||
@@ -1780,14 +1780,14 @@ block0:
|
||||
|
||||
check(
|
||||
&func,
|
||||
"function %sample() -> i8x16, b8x16, f32x4 system_v {
|
||||
"function %sample() -> i8x16, i8x16, f32x4 system_v {
|
||||
const0 = 0x00000000000000000000000000000000
|
||||
|
||||
block0:
|
||||
v5 = f32const 0.0
|
||||
v6 = splat.f32x4 v5 ; v5 = 0.0
|
||||
v2 -> v6
|
||||
v4 = vconst.b8x16 const0
|
||||
v4 = vconst.i8x16 const0
|
||||
v1 -> v4
|
||||
v3 = vconst.i8x16 const0
|
||||
v0 -> v3
|
||||
|
||||
@@ -142,8 +142,6 @@ enum Call {
|
||||
fn emit_zero(ty: Type, mut cur: FuncCursor) -> Value {
|
||||
if ty.is_int() {
|
||||
cur.ins().iconst(ty, 0)
|
||||
} else if ty.is_bool() {
|
||||
cur.ins().bconst(ty, false)
|
||||
} else if ty == F32 {
|
||||
cur.ins().f32const(Ieee32::with_bits(0))
|
||||
} else if ty == F64 {
|
||||
@@ -152,7 +150,7 @@ fn emit_zero(ty: Type, mut cur: FuncCursor) -> Value {
|
||||
cur.ins().null(ty)
|
||||
} else if ty.is_vector() {
|
||||
let scalar_ty = ty.lane_type();
|
||||
if scalar_ty.is_int() || scalar_ty.is_bool() {
|
||||
if scalar_ty.is_int() {
|
||||
let zero = cur.func.dfg.constants.insert(
|
||||
core::iter::repeat(0)
|
||||
.take(ty.bytes().try_into().unwrap())
|
||||
@@ -1167,12 +1165,12 @@ mod tests {
|
||||
let i32_var = Variable::new(0);
|
||||
let f32_var = Variable::new(1);
|
||||
let f64_var = Variable::new(2);
|
||||
let b1_var = Variable::new(3);
|
||||
let i8_var = Variable::new(3);
|
||||
let f32x4_var = Variable::new(4);
|
||||
ssa.use_var(&mut func, i32_var, I32, block0);
|
||||
ssa.use_var(&mut func, f32_var, F32, block0);
|
||||
ssa.use_var(&mut func, f64_var, F64, block0);
|
||||
ssa.use_var(&mut func, b1_var, B1, block0);
|
||||
ssa.use_var(&mut func, i8_var, I8, block0);
|
||||
ssa.use_var(&mut func, f32x4_var, F32X4, block0);
|
||||
assert_eq!(func.dfg.num_block_params(block0), 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user