Skip to content

Commit 67056c2

Browse files
authored
[WebAssembly] Support shuffle for F16x8 vectors. (llvm#127857)
1 parent 43999de commit 67056c2

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ WebAssemblyTargetLowering::WebAssemblyTargetLowering(
228228
MVT::v2f64})
229229
setOperationAction(ISD::VECTOR_SHUFFLE, T, Custom);
230230

231+
if (Subtarget->hasFP16())
232+
setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v8f16, Custom);
233+
231234
// Support splatting
232235
for (auto T : {MVT::v16i8, MVT::v8i16, MVT::v4i32, MVT::v4f32, MVT::v2i64,
233236
MVT::v2f64})

llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ defm SHUFFLE :
558558
// Shuffles after custom lowering
559559
def wasm_shuffle_t : SDTypeProfile<1, 18, []>;
560560
def wasm_shuffle : SDNode<"WebAssemblyISD::SHUFFLE", wasm_shuffle_t>;
561-
foreach vec = StdVecs in {
561+
foreach vec = AllVecs in {
562562
// The @llvm.wasm.shuffle intrinsic has immediate arguments that become TargetConstants.
563563
def : Pat<(vec.vt (wasm_shuffle (vec.vt V128:$x), (vec.vt V128:$y),
564564
(i32 timm:$m0), (i32 timm:$m1),

llvm/test/CodeGen/WebAssembly/half-precision.ll

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,27 @@ define void @store_v8f16(<8 x half> %v, ptr %p) {
335335
store <8 x half> %v , ptr %p
336336
ret void
337337
}
338+
339+
; ==============================================================================
340+
; Shuffle
341+
; ==============================================================================
342+
define <8 x half> @shuffle_v8f16(<8 x half> %x, <8 x half> %y) {
343+
; CHECK-LABEL: shuffle_v8f16:
344+
; CHECK: .functype shuffle_v8f16 (v128, v128) -> (v128)
345+
; CHECK-NEXT: i8x16.shuffle $push0=, $0, $1, 0, 1, 18, 19, 4, 5, 22, 23, 8, 9, 26, 27, 12, 13, 30, 31
346+
; CHECK-NEXT: return $pop0
347+
%res = shufflevector <8 x half> %x, <8 x half> %y,
348+
<8 x i32> <i32 0, i32 9, i32 2, i32 11, i32 4, i32 13, i32 6, i32 15>
349+
ret <8 x half> %res
350+
}
351+
352+
define <8 x half> @shuffle_poison_v8f16(<8 x half> %x, <8 x half> %y) {
353+
; CHECK-LABEL: shuffle_poison_v8f16:
354+
; CHECK: .functype shuffle_poison_v8f16 (v128, v128) -> (v128)
355+
; CHECK-NEXT: i8x16.shuffle $push0=, $0, $0, 2, 3, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1
356+
; CHECK-NEXT: return $pop0
357+
%res = shufflevector <8 x half> %x, <8 x half> %y,
358+
<8 x i32> <i32 1, i32 poison, i32 poison, i32 poison,
359+
i32 poison, i32 poison, i32 poison, i32 poison>
360+
ret <8 x half> %res
361+
}

0 commit comments

Comments
 (0)