Skip to content

Commit 672757b

Browse files
authored
[WebAssembly] Add patterns for extadd pairwise (#167960)
Add a few patterns for extadd pairwise.
1 parent 2ea1a09 commit 672757b

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyInstrSIMD.td

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,32 @@ def : Pat<(v4i32 (int_wasm_extadd_pairwise_signed (v8i16 V128:$in))),
15411541
def : Pat<(v8i16 (int_wasm_extadd_pairwise_signed (v16i8 V128:$in))),
15421542
(extadd_pairwise_s_I16x8 V128:$in)>;
15431543

1544+
multiclass ExtAddPairwiseShuffle<ValueType from_ty, ValueType to_ty, string suffix,
1545+
int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7,
1546+
int b0, int b1, int b2, int b3, int b4, int b5, int b6, int b7> {
1547+
foreach sign = ["s", "u"] in {
1548+
def : Pat<(to_ty (add
1549+
(!cast<SDNode>("extend_low_"#sign) (from_ty (wasm_shuffle (from_ty V128:$vec), (from_ty srcvalue),
1550+
(i32 a0), (i32 a1), (i32 a2), (i32 a3),
1551+
(i32 a4), (i32 a5), (i32 a6), (i32 a7),
1552+
(i32 srcvalue), (i32 srcvalue), (i32 srcvalue), (i32 srcvalue),
1553+
(i32 srcvalue), (i32 srcvalue), (i32 srcvalue), (i32 srcvalue)))),
1554+
(!cast<SDNode>("extend_low_"#sign) (from_ty (wasm_shuffle (from_ty V128:$vec), (from_ty srcvalue),
1555+
(i32 b0), (i32 b1), (i32 b2), (i32 b3),
1556+
(i32 b4), (i32 b5), (i32 b6), (i32 b7),
1557+
(i32 srcvalue), (i32 srcvalue), (i32 srcvalue), (i32 srcvalue),
1558+
(i32 srcvalue), (i32 srcvalue), (i32 srcvalue), (i32 srcvalue)))))),
1559+
(!cast<Instruction>("extadd_pairwise_"#sign#"_"#suffix) V128:$vec)>;
1560+
}
1561+
}
1562+
1563+
defm : ExtAddPairwiseShuffle<v8i16, v4i32, "I32x4",
1564+
0, 1, 4, 5, 8, 9, 12, 13,
1565+
2, 3, 6, 7, 10, 11, 14, 15>;
1566+
defm : ExtAddPairwiseShuffle<v16i8, v8i16, "I16x8",
1567+
0, 2, 4, 6, 8, 10, 12, 14,
1568+
1, 3, 5, 7, 9, 11, 13, 15>;
1569+
15441570
// f64x2 <-> f32x4 conversions
15451571
def demote_t : SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVec<1>]>;
15461572
def demote_zero : SDNode<"WebAssemblyISD::DEMOTE_ZERO", demote_t>;
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
2+
; RUN: llc < %s -O2 -mtriple=wasm32 -mattr=+simd128 | FileCheck %s
3+
4+
target triple = "wasm32-unknown-unknown"
5+
6+
; Test that adding two extended shuffles from the same vector that ends w/ an add converts to extadd_pairwise
7+
8+
define <8 x i16> @test_extadd_pairwise_i8x16_s(<16 x i8> %v) {
9+
; CHECK-LABEL: test_extadd_pairwise_i8x16_s:
10+
; CHECK: .functype test_extadd_pairwise_i8x16_s (v128) -> (v128)
11+
; CHECK-NEXT: # %bb.0:
12+
; CHECK-NEXT: local.get 0
13+
; CHECK-NEXT: i16x8.extadd_pairwise_i8x16_s
14+
; CHECK-NEXT: # fallthrough-return
15+
%even = shufflevector <16 x i8> %v, <16 x i8> poison, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14>
16+
%odd = shufflevector <16 x i8> %v, <16 x i8> poison, <8 x i32> <i32 1, i32 3, i32 5, i32 7, i32 9, i32 11, i32 13, i32 15>
17+
%even_ext = sext <8 x i8> %even to <8 x i16>
18+
%odd_ext = sext <8 x i8> %odd to <8 x i16>
19+
%result = add <8 x i16> %even_ext, %odd_ext
20+
ret <8 x i16> %result
21+
}
22+
23+
define <8 x i16> @test_extadd_pairwise_i8x16_u(<16 x i8> %v) {
24+
; CHECK-LABEL: test_extadd_pairwise_i8x16_u:
25+
; CHECK: .functype test_extadd_pairwise_i8x16_u (v128) -> (v128)
26+
; CHECK-NEXT: # %bb.0:
27+
; CHECK-NEXT: local.get 0
28+
; CHECK-NEXT: i16x8.extadd_pairwise_i8x16_u
29+
; CHECK-NEXT: # fallthrough-return
30+
%even = shufflevector <16 x i8> %v, <16 x i8> poison, <8 x i32> <i32 0, i32 2, i32 4, i32 6, i32 8, i32 10, i32 12, i32 14>
31+
%odd = shufflevector <16 x i8> %v, <16 x i8> poison, <8 x i32> <i32 1, i32 3, i32 5, i32 7, i32 9, i32 11, i32 13, i32 15>
32+
%even_ext = zext <8 x i8> %even to <8 x i16>
33+
%odd_ext = zext <8 x i8> %odd to <8 x i16>
34+
%result = add <8 x i16> %even_ext, %odd_ext
35+
ret <8 x i16> %result
36+
}
37+
38+
define <4 x i32> @test_extadd_pairwise_i16x8_s(<8 x i16> %v) {
39+
; CHECK-LABEL: test_extadd_pairwise_i16x8_s:
40+
; CHECK: .functype test_extadd_pairwise_i16x8_s (v128) -> (v128)
41+
; CHECK-NEXT: # %bb.0:
42+
; CHECK-NEXT: local.get 0
43+
; CHECK-NEXT: i32x4.extadd_pairwise_i16x8_s
44+
; CHECK-NEXT: # fallthrough-return
45+
%even = shufflevector <8 x i16> %v, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
46+
%odd = shufflevector <8 x i16> %v, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
47+
%even_ext = sext <4 x i16> %even to <4 x i32>
48+
%odd_ext = sext <4 x i16> %odd to <4 x i32>
49+
%result = add <4 x i32> %even_ext, %odd_ext
50+
ret <4 x i32> %result
51+
}
52+
53+
define <4 x i32> @test_extadd_pairwise_i16x8_u(<8 x i16> %v) {
54+
; CHECK-LABEL: test_extadd_pairwise_i16x8_u:
55+
; CHECK: .functype test_extadd_pairwise_i16x8_u (v128) -> (v128)
56+
; CHECK-NEXT: # %bb.0:
57+
; CHECK-NEXT: local.get 0
58+
; CHECK-NEXT: i32x4.extadd_pairwise_i16x8_u
59+
; CHECK-NEXT: # fallthrough-return
60+
%even = shufflevector <8 x i16> %v, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
61+
%odd = shufflevector <8 x i16> %v, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
62+
%even_ext = zext <4 x i16> %even to <4 x i32>
63+
%odd_ext = zext <4 x i16> %odd to <4 x i32>
64+
%result = add <4 x i32> %even_ext, %odd_ext
65+
ret <4 x i32> %result
66+
}
67+
68+
; Negative test: shuffling mask doesn't fit pattern
69+
define <4 x i32> @negative_test_extadd_pairwise_i16x8_u(<8 x i16> %v) {
70+
; CHECK-LABEL: negative_test_extadd_pairwise_i16x8_u:
71+
; CHECK: .functype negative_test_extadd_pairwise_i16x8_u (v128) -> (v128)
72+
; CHECK-NEXT: # %bb.0:
73+
; CHECK-NEXT: local.get 0
74+
; CHECK-NEXT: local.get 0
75+
; CHECK-NEXT: i8x16.shuffle 0, 1, 6, 7, 8, 9, 12, 13, 0, 1, 0, 1, 0, 1, 0, 1
76+
; CHECK-NEXT: i32x4.extend_low_i16x8_u
77+
; CHECK-NEXT: local.get 0
78+
; CHECK-NEXT: local.get 0
79+
; CHECK-NEXT: i8x16.shuffle 2, 3, 6, 7, 10, 11, 14, 15, 0, 1, 0, 1, 0, 1, 0, 1
80+
; CHECK-NEXT: i32x4.extend_low_i16x8_u
81+
; CHECK-NEXT: i32x4.add
82+
; CHECK-NEXT: # fallthrough-return
83+
%even = shufflevector <8 x i16> %v, <8 x i16> poison, <4 x i32> <i32 0, i32 3, i32 4, i32 6>
84+
%odd = shufflevector <8 x i16> %v, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
85+
%even_ext = zext <4 x i16> %even to <4 x i32>
86+
%odd_ext = zext <4 x i16> %odd to <4 x i32>
87+
%result = add <4 x i32> %even_ext, %odd_ext
88+
ret <4 x i32> %result
89+
}

0 commit comments

Comments
 (0)