Skip to content

Commit 3ab6af0

Browse files
authored
Use Cranelift bitcast instead of store & load to bitcast between vectors and non-vectors (#1580)
1 parent 8e3d0b2 commit 3ab6af0

File tree

2 files changed

+2
-25
lines changed

2 files changed

+2
-25
lines changed

src/abi/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
154154

155155
let ret = self.lib_call_unadjusted(name, params, returns, &args)[0];
156156

157-
// FIXME(bytecodealliance/wasmtime#6104) use bitcast instead of store to get from i64x2 to i128
158-
let ret_ptr = self.create_stack_slot(16, 16);
159-
ret_ptr.store(self, ret, MemFlags::trusted());
160-
Cow::Owned(vec![ret_ptr.load(self, types::I128, MemFlags::trusted())])
157+
Cow::Owned(vec![codegen_bitcast(self, types::I128, ret)])
161158
} else if ret_single_i128 && self.tcx.sess.target.arch == "s390x" {
162159
// Return i128 using a return area pointer on s390x.
163160
let mut params = params;

src/value_and_place.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -564,27 +564,7 @@ impl<'tcx> CPlace<'tcx> {
564564
src_ty,
565565
dst_ty,
566566
);
567-
let data = match (src_ty, dst_ty) {
568-
(_, _) if src_ty == dst_ty => data,
569-
570-
// This is a `write_cvalue_transmute`.
571-
(types::I32, types::F32)
572-
| (types::F32, types::I32)
573-
| (types::I64, types::F64)
574-
| (types::F64, types::I64) => codegen_bitcast(fx, dst_ty, data),
575-
_ if src_ty.is_vector() && dst_ty.is_vector() => codegen_bitcast(fx, dst_ty, data),
576-
_ if src_ty.is_vector() || dst_ty.is_vector() => {
577-
// FIXME(bytecodealliance/wasmtime#6104) do something more efficient for transmutes between vectors and integers.
578-
let ptr = fx.create_stack_slot(src_ty.bytes(), src_ty.bytes());
579-
ptr.store(fx, data, MemFlags::trusted());
580-
ptr.load(fx, dst_ty, MemFlags::trusted())
581-
}
582-
583-
// `CValue`s should never contain SSA-only types, so if you ended
584-
// up here having seen an error like `B1 -> I8`, then before
585-
// calling `write_cvalue` you need to add a `bint` instruction.
586-
_ => unreachable!("write_cvalue_transmute: {:?} -> {:?}", src_ty, dst_ty),
587-
};
567+
let data = if src_ty == dst_ty { data } else { codegen_bitcast(fx, dst_ty, data) };
588568
//fx.bcx.set_val_label(data, cranelift_codegen::ir::ValueLabel::new(var.index()));
589569
fx.bcx.def_var(var, data);
590570
}

0 commit comments

Comments
 (0)