diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp index fedad25c775e2..2877e909933fe 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp @@ -228,6 +228,9 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering( MVT::v2f64}) setOperationAction(ISD::VECTOR_SHUFFLE, T, Custom); + if (Subtarget->hasFP16()) + setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v8f16, Custom); + // Support splatting for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v4f32, MVT::v2i64, MVT::v2f64}) diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td index 14acc623ce24d..c591e5ef181a4 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td +++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td @@ -558,7 +558,7 @@ defm SHUFFLE : // Shuffles after custom lowering def wasm_shuffle_t : SDTypeProfile<1, 18, []>; def wasm_shuffle : SDNode<"WebAssemblyISD::SHUFFLE", wasm_shuffle_t>; -foreach vec = StdVecs in { +foreach vec = AllVecs in { // The @llvm.wasm.shuffle intrinsic has immediate arguments that become TargetConstants. def : Pat<(vec.vt (wasm_shuffle (vec.vt V128:$x), (vec.vt V128:$y), (i32 timm:$m0), (i32 timm:$m1), diff --git a/llvm/test/CodeGen/WebAssembly/half-precision.ll b/llvm/test/CodeGen/WebAssembly/half-precision.ll index 5f0ba4aa9c3c4..9a20ef8433157 100644 --- a/llvm/test/CodeGen/WebAssembly/half-precision.ll +++ b/llvm/test/CodeGen/WebAssembly/half-precision.ll @@ -335,3 +335,27 @@ define void @store_v8f16(<8 x half> %v, ptr %p) { store <8 x half> %v , ptr %p ret void } + +; ============================================================================== +; Shuffle +; ============================================================================== +define <8 x half> @shuffle_v8f16(<8 x half> %x, <8 x half> %y) { +; CHECK-LABEL: shuffle_v8f16: +; CHECK: .functype shuffle_v8f16 (v128, v128) -> (v128) +; CHECK-NEXT: i8x16.shuffle $push0=, $0, $1, 0, 1, 18, 19, 4, 5, 22, 23, 8, 9, 26, 27, 12, 13, 30, 31 +; CHECK-NEXT: return $pop0 + %res = shufflevector <8 x half> %x, <8 x half> %y, + <8 x i32> + ret <8 x half> %res +} + +define <8 x half> @shuffle_poison_v8f16(<8 x half> %x, <8 x half> %y) { +; CHECK-LABEL: shuffle_poison_v8f16: +; CHECK: .functype shuffle_poison_v8f16 (v128, v128) -> (v128) +; CHECK-NEXT: i8x16.shuffle $push0=, $0, $0, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 +; CHECK-NEXT: return $pop0 + %res = shufflevector <8 x half> %x, <8 x half> %y, + <8 x i32> + ret <8 x half> %res +}