From 994fe41daf6dade899ca41fa9c70c6a7c3d44fc2 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 19 Nov 2021 10:29:37 -0800 Subject: [PATCH] x64: allow vector types in `select` move As reported in #3173, the `select` instruction fails an assertion when it is given `v128` types as operands. This change relaxes the assertion to allow the same type of XMM move that occurs for the f32 and f64 types. This fixes #3173 in the old `lower.rs` code temporarily until the relatively complex `select` lowering can be ported to ISLE. --- cranelift/codegen/src/isa/x64/lower.rs | 6 +++++- tests/misc_testsuite/simd/issue_3173_select_v128.wast | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/misc_testsuite/simd/issue_3173_select_v128.wast diff --git a/cranelift/codegen/src/isa/x64/lower.rs b/cranelift/codegen/src/isa/x64/lower.rs index 41e986f401..e2d2376f34 100644 --- a/cranelift/codegen/src/isa/x64/lower.rs +++ b/cranelift/codegen/src/isa/x64/lower.rs @@ -5297,7 +5297,11 @@ fn lower_insn_to_regs>( if is_int_or_ref_ty(ty) || ty == types::I128 { emit_cmoves(ctx, size, cc, lhs, dst); } else { - debug_assert!(ty == types::F32 || ty == types::F64); + debug_assert!( + ty == types::F32 + || ty == types::F64 + || (ty.is_vector() && ty.bits() == 128) + ); ctx.emit(Inst::xmm_cmove( if ty == types::F64 { OperandSize::Size64 diff --git a/tests/misc_testsuite/simd/issue_3173_select_v128.wast b/tests/misc_testsuite/simd/issue_3173_select_v128.wast new file mode 100644 index 0000000000..612d39b283 --- /dev/null +++ b/tests/misc_testsuite/simd/issue_3173_select_v128.wast @@ -0,0 +1,10 @@ +(; See issue https://github.com/bytecodealliance/wasmtime/issues/3173. ;) + +(module + (func (export "select_v128") (result v128) + v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000 + v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000 + i32.const 0 + select)) + +(assert_return (invoke "select_v128") (v128.const i32x4 0 0 0 0))