From e3a20d67b2dd6b26662ad4743412b6af6e14c948 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 23 Oct 2019 15:40:46 -0700 Subject: [PATCH] Add x86 SIMD legalization of `icmp ne` --- .../codegen/meta/src/isa/x86/legalize.rs | 10 +++++ .../isa/x86/simd-comparison-legalize.clif | 12 +++++ .../isa/x86/simd-comparison-run.clif | 45 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 cranelift/filetests/filetests/isa/x86/simd-comparison-legalize.clif create mode 100644 cranelift/filetests/filetests/isa/x86/simd-comparison-run.clif diff --git a/cranelift/codegen/meta/src/isa/x86/legalize.rs b/cranelift/codegen/meta/src/isa/x86/legalize.rs index e43e3c3e37..1aa76798ea 100644 --- a/cranelift/codegen/meta/src/isa/x86/legalize.rs +++ b/cranelift/codegen/meta/src/isa/x86/legalize.rs @@ -496,6 +496,16 @@ pub(crate) fn define(shared: &mut SharedDefinitions, x86_instructions: &Instruct } } + // SIMD icmp ne + let ne = Literal::enumerator_for(&imm.intcc, "ne"); + for ty in ValueType::all_lane_types().filter(|ty| allowed_simd_type(ty) && ty.is_int()) { + let icmp_ = icmp.bind(vector(ty, sse_vector_size)); + narrow.legalize( + def!(c = icmp_(ne, a, b)), + vec![def!(x = icmp(eq, a, b)), def!(c = bnot(x))], + ); + } + narrow.custom_legalize(shuffle, "convert_shuffle"); narrow.custom_legalize(extractlane, "convert_extractlane"); narrow.custom_legalize(insertlane, "convert_insertlane"); diff --git a/cranelift/filetests/filetests/isa/x86/simd-comparison-legalize.clif b/cranelift/filetests/filetests/isa/x86/simd-comparison-legalize.clif new file mode 100644 index 0000000000..4555a25b42 --- /dev/null +++ b/cranelift/filetests/filetests/isa/x86/simd-comparison-legalize.clif @@ -0,0 +1,12 @@ +test legalizer +set enable_simd +target x86_64 skylake + +function %icmp_ne_32x4(i32x4, i32x4) -> b32x4 { +ebb0(v0: i32x4, v1: i32x4): + v2 = icmp ne v0, v1 + ; check: v3 = icmp eq v0, v1 + ; nextln: v4 = vconst.b32x4 0xffffffffffffffffffffffffffffffff + ; nextln: v2 = bxor v4, v3 + return v2 +} diff --git a/cranelift/filetests/filetests/isa/x86/simd-comparison-run.clif b/cranelift/filetests/filetests/isa/x86/simd-comparison-run.clif new file mode 100644 index 0000000000..6afbf418d6 --- /dev/null +++ b/cranelift/filetests/filetests/isa/x86/simd-comparison-run.clif @@ -0,0 +1,45 @@ +test run +set enable_simd +target x86_64 skylake + +function %icmp_eq_i8x16() -> b8 { +ebb0: + v0 = vconst.i8x16 0x00 + v1 = vconst.i8x16 0x00 + v2 = icmp eq v0, v1 + v3 = extractlane v2, 0 + return v3 +} +; run + +function %icmp_eq_i64x2() -> b64 { +ebb0: + v0 = vconst.i64x2 0xffffffffffffffffffffffffffffffff + v1 = vconst.i64x2 0xffffffffffffffffffffffffffffffff + v2 = icmp eq v0, v1 + v3 = extractlane v2, 1 + return v3 +} +; run + +function %icmp_ne_i32x4() -> b1 { +ebb0: + v0 = vconst.i32x4 [0 1 2 3] + v1 = vconst.i32x4 [7 7 7 7] + v2 = icmp ne v0, v1 + v3 = vall_true v2 + return v3 +} +; run + +function %icmp_ne_i16x8() -> b1 { +ebb0: + v0 = vconst.i16x8 [0 1 2 3 4 5 6 7] + v1 = vconst.i16x8 [0 1 2 3 4 5 6 7] + v2 = icmp ne v0, v1 + v3 = vall_true v2 + v4 = bint.i32 v3 + v5 = icmp_imm eq v4, 0 + return v5 +} +; run