Browse Source

[cranelift-frontend] Fix emit_zero for vectors (#1428)

* Fix emit_zero for vectors
* Add undef_vector_vars frontend test
* Remove unused import
pull/1437/head
bjorn3 5 years ago
committed by GitHub
parent
commit
bc462404b3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 47
      cranelift/frontend/src/frontend.rs
  2. 12
      cranelift/frontend/src/ssa.rs

47
cranelift/frontend/src/frontend.rs

@ -1229,6 +1229,53 @@ block0:
);
}
#[test]
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(F32X4));
let mut fn_ctx = FunctionBuilderContext::new();
let mut func = Function::with_name_signature(ExternalName::testcase("sample"), sig);
{
let mut builder = FunctionBuilder::new(&mut func, &mut fn_ctx);
let block0 = builder.create_block();
let a = Variable::new(0);
let b = Variable::new(1);
let c = Variable::new(2);
builder.declare_var(a, I8X16);
builder.declare_var(b, B8X16);
builder.declare_var(c, F32X4);
builder.switch_to_block(block0);
let a = builder.use_var(a);
let b = builder.use_var(b);
let c = builder.use_var(c);
builder.ins().return_(&[a, b, c]);
builder.seal_all_blocks();
builder.finalize();
}
assert_eq!(
func.display(None).to_string(),
"function %sample() -> i8x16, b8x16, f32x4 system_v {
block0:
v5 = f32const 0.0
v6 = splat.f32x4 v5
v2 -> v6
v4 = vconst.b8x16 0x00
v1 -> v4
v3 = vconst.i8x16 0x00
v0 -> v3
return v0, v1, v2
}
"
);
}
#[test]
fn test_greatest_divisible_power_of_two() {
assert_eq!(64, greatest_divisible_power_of_two(64));

12
cranelift/frontend/src/ssa.rs

@ -9,6 +9,7 @@
use crate::Variable;
use alloc::vec::Vec;
use core::convert::TryInto;
use core::mem;
use cranelift_codegen::cursor::{Cursor, FuncCursor};
use cranelift_codegen::entity::SecondaryMap;
@ -185,10 +186,13 @@ 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() {
cur.ins().iconst(ty, 0)
} else if scalar_ty.is_bool() {
cur.ins().bconst(ty, false)
if scalar_ty.is_int() || scalar_ty.is_bool() {
let zero = cur.func.dfg.constants.insert(
core::iter::repeat(0)
.take(ty.bytes().try_into().unwrap())
.collect(),
);
cur.ins().vconst(ty, zero)
} else if scalar_ty == F32 {
let scalar = cur.ins().f32const(Ieee32::with_bits(0));
cur.ins().splat(ty, scalar)

Loading…
Cancel
Save