xref: /freebsd/contrib/llvm-project/llvm/lib/Target/VE/VVPInstrPatternsVec.td (revision 9729f076e4d93c5a37e78d427bfe0f1ab99bbcc6)
1//===----------- VVPInstrPatternsVec.td - VVP_* SDNode patterns -----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file describes how VVP_* SDNodes are lowered to machine instructions.
10//
11//===----------------------------------------------------------------------===//
12
13//===----------------------------------------------------------------------===//
14//
15// VVP SDNode definitions.
16//
17//===----------------------------------------------------------------------===//
18include "VVPInstrInfo.td"
19
20multiclass Binary_rv<SDPatternOperator OpNode,
21    ValueType ScalarVT, ValueType DataVT,
22    ValueType MaskVT, string OpBaseName> {
23  // Masked with passthru, broadcast.
24  def : Pat<(vvp_select
25                (OpNode
26                    (any_broadcast ScalarVT:$sx),
27                    DataVT:$vy,
28                    (MaskVT srcvalue),
29                    (i32 srcvalue)),
30                DataVT:$vfalse,
31                MaskVT:$mask,
32                i32:$pivot),
33            (!cast<Instruction>(OpBaseName#"rvml_v")
34                ScalarVT:$sx,
35                $vy,
36                $mask,
37                $pivot,
38                $vfalse)>;
39
40  // Unmasked, broadcast.
41  def : Pat<(OpNode
42                (any_broadcast ScalarVT:$sx), DataVT:$vy,
43                (MaskVT true_mask),
44                i32:$avl),
45            (!cast<Instruction>(OpBaseName#"rvl")
46                ScalarVT:$sx, $vy, $avl)>;
47  // Masked, broadcast.
48  def : Pat<(OpNode
49                (any_broadcast ScalarVT:$sx), DataVT:$vy,
50                MaskVT:$mask,
51                i32:$avl),
52            (!cast<Instruction>(OpBaseName#"rvml")
53                ScalarVT:$sx, $vy, $mask, $avl)>;
54}
55
56multiclass Binary_vr<SDPatternOperator OpNode,
57    ValueType ScalarVT, ValueType DataVT,
58    ValueType MaskVT, string OpBaseName> {
59  // Masked with passthru, broadcast.
60  def : Pat<(vvp_select
61                (OpNode
62                    DataVT:$vx,
63                    (any_broadcast ScalarVT:$sy),
64                    (MaskVT srcvalue),
65                    (i32 srcvalue)),
66                DataVT:$vfalse,
67                MaskVT:$mask,
68                i32:$pivot),
69            (!cast<Instruction>(OpBaseName#"vrml_v")
70                $vx,
71                ScalarVT:$sy,
72                $mask,
73                $pivot,
74                $vfalse)>;
75
76  // Unmasked, broadcast.
77  def : Pat<(OpNode
78                DataVT:$vx, (any_broadcast ScalarVT:$sy),
79                (MaskVT true_mask),
80                i32:$avl),
81            (!cast<Instruction>(OpBaseName#"vrl")
82                $vx, ScalarVT:$sy, $avl)>;
83  // Masked, broadcast.
84  def : Pat<(OpNode
85                DataVT:$vx, (any_broadcast ScalarVT:$sy),
86                MaskVT:$mask,
87                i32:$avl),
88            (!cast<Instruction>(OpBaseName#"vrml")
89                $vx, ScalarVT:$sy, $mask, $avl)>;
90}
91
92multiclass Binary_vv<SDPatternOperator OpNode,
93    ValueType DataVT,
94    ValueType MaskVT, string OpBaseName> {
95  // Masked with passthru, broadcast.
96  def : Pat<(vvp_select
97                (OpNode
98                    DataVT:$vx,
99                    DataVT:$vy,
100                    (MaskVT srcvalue),
101                    (i32 srcvalue)),
102                DataVT:$vfalse,
103                MaskVT:$mask,
104                i32:$pivot),
105            (!cast<Instruction>(OpBaseName#"vvml_v")
106                $vx,
107                $vy,
108                $mask,
109                $pivot,
110                $vfalse)>;
111
112  // Masked with select.
113  // TODO
114
115  // Unmasked.
116  def : Pat<(OpNode
117                DataVT:$vx, DataVT:$vy,
118                (MaskVT true_mask),
119                i32:$avl),
120            (!cast<Instruction>(OpBaseName#"vvl")
121                $vx, $vy, $avl)>;
122
123  // Masked.
124  def : Pat<(OpNode
125                DataVT:$vx, DataVT:$vy,
126                MaskVT:$mask,
127                i32:$avl),
128            (!cast<Instruction>(OpBaseName#"vvml")
129                $vx, $vy, $mask, $avl)>;
130}
131
132multiclass Binary_rv_vv<
133    SDPatternOperator OpNode,
134    ValueType ScalarVT, ValueType DataVT, ValueType MaskVT,
135    string OpBaseName> {
136  defm : Binary_rv<OpNode, ScalarVT, DataVT, MaskVT, OpBaseName>;
137  defm : Binary_vv<OpNode, DataVT, MaskVT, OpBaseName>;
138}
139
140multiclass Binary_vr_vv<
141    SDPatternOperator OpNode,
142    ValueType ScalarVT, ValueType DataVT, ValueType MaskVT,
143    string OpBaseName> {
144  defm : Binary_vr<OpNode, ScalarVT, DataVT, MaskVT, OpBaseName>;
145  defm : Binary_vv<OpNode, DataVT, MaskVT, OpBaseName>;
146}
147
148multiclass Binary_rv_vr_vv<
149    SDPatternOperator OpNode,
150    ValueType ScalarVT, ValueType DataVT, ValueType MaskVT,
151    string OpBaseName> {
152  defm : Binary_rv<OpNode, ScalarVT, DataVT, MaskVT, OpBaseName>;
153  defm : Binary_vr_vv<OpNode, ScalarVT, DataVT, MaskVT, OpBaseName>;
154}
155
156// Expand both 64bit and 32 bit variant (256 elements)
157multiclass Binary_rv_vv_ShortLong<
158    SDPatternOperator OpNode,
159    ValueType LongScalarVT, ValueType LongDataVT, string LongOpBaseName,
160    ValueType ShortScalarVT, ValueType ShortDataVT, string ShortOpBaseName> {
161  defm : Binary_rv_vv<OpNode,
162                      LongScalarVT, LongDataVT, v256i1,
163                      LongOpBaseName>;
164  defm : Binary_rv_vv<OpNode,
165                      ShortScalarVT, ShortDataVT, v256i1,
166                      ShortOpBaseName>;
167}
168
169multiclass Binary_vr_vv_ShortLong<
170    SDPatternOperator OpNode,
171    ValueType LongScalarVT, ValueType LongDataVT, string LongOpBaseName,
172    ValueType ShortScalarVT, ValueType ShortDataVT, string ShortOpBaseName> {
173  defm : Binary_vr_vv<OpNode,
174                      LongScalarVT, LongDataVT, v256i1,
175                      LongOpBaseName>;
176  defm : Binary_vr_vv<OpNode,
177                      ShortScalarVT, ShortDataVT, v256i1,
178                      ShortOpBaseName>;
179}
180
181multiclass Binary_rv_vr_vv_ShortLong<
182    SDPatternOperator OpNode,
183    ValueType LongScalarVT, ValueType LongDataVT, string LongOpBaseName,
184    ValueType ShortScalarVT, ValueType ShortDataVT, string ShortOpBaseName> {
185  defm : Binary_rv_vr_vv<OpNode,
186                      LongScalarVT, LongDataVT, v256i1,
187                      LongOpBaseName>;
188  defm : Binary_rv_vr_vv<OpNode,
189                      ShortScalarVT, ShortDataVT, v256i1,
190                      ShortOpBaseName>;
191}
192
193defm : Binary_rv_vv_ShortLong<c_vvp_add,
194                              i64, v256i64, "VADDSL",
195                              i32, v256i32, "VADDSWSX">;
196defm : Binary_rv_vv_ShortLong<vvp_sub,
197                              i64, v256i64, "VSUBSL",
198                              i32, v256i32, "VSUBSWSX">;
199defm : Binary_rv_vv_ShortLong<c_vvp_mul,
200                              i64, v256i64, "VMULSL",
201                              i32, v256i32, "VMULSWSX">;
202defm : Binary_rv_vr_vv_ShortLong<vvp_sdiv,
203                              i64, v256i64, "VDIVSL",
204                              i32, v256i32, "VDIVSWSX">;
205defm : Binary_rv_vr_vv_ShortLong<vvp_udiv,
206                              i64, v256i64, "VDIVUL",
207                              i32, v256i32, "VDIVUW">;
208defm : Binary_rv_vv_ShortLong<c_vvp_and,
209                              i64, v256i64, "VAND",
210                              i32, v256i32, "PVANDLO">;
211defm : Binary_rv_vv_ShortLong<c_vvp_or,
212                              i64, v256i64, "VOR",
213                              i32, v256i32, "PVORLO">;
214defm : Binary_rv_vv_ShortLong<c_vvp_xor,
215                              i64, v256i64, "VXOR",
216                              i32, v256i32, "PVXORLO">;
217defm : Binary_vr_vv_ShortLong<vvp_shl,
218                              i64, v256i64, "VSLL",
219                              i32, v256i32, "PVSLLLO">;
220defm : Binary_vr_vv_ShortLong<vvp_sra,
221                              i64, v256i64, "VSRAL",
222                              i32, v256i32, "PVSRALO">;
223defm : Binary_vr_vv_ShortLong<vvp_srl,
224                              i64, v256i64, "VSRL",
225                              i32, v256i32, "PVSRLLO">;
226
227defm : Binary_rv_vv_ShortLong<c_vvp_fadd,
228                              f64, v256f64, "VFADDD",
229                              f32, v256f32, "PVFADDUP">;
230defm : Binary_rv_vv_ShortLong<c_vvp_fmul,
231                              f64, v256f64, "VFMULD",
232                              f32, v256f32, "PVFMULUP">;
233defm : Binary_rv_vv_ShortLong<vvp_fsub,
234                              f64, v256f64, "VFSUBD",
235                              f32, v256f32, "PVFSUBUP">;
236defm : Binary_rv_vr_vv_ShortLong<vvp_fdiv,
237                              f64, v256f64, "VFDIVD",
238                              f32, v256f32, "VFDIVS">;
239
240multiclass Merge_mvv<
241    SDPatternOperator OpNode,
242    ValueType DataVT, ValueType MaskVT,
243    string OpBaseName> {
244  // Masked.
245  def : Pat<(OpNode
246                DataVT:$vtrue, DataVT:$vfalse,
247                MaskVT:$vm,
248                i32:$avl),
249            (!cast<Instruction>(OpBaseName#"vvml_v")
250                $vfalse, $vtrue, $vm, $avl, $vfalse)>;
251}
252
253multiclass Merge_mvv_ShortLong<
254    SDPatternOperator OpNode,
255    ValueType LongDataVT, ValueType ShortDataVT,
256    string OpBaseName> {
257  defm : Merge_mvv<OpNode,
258                   LongDataVT, v256i1,
259                   OpBaseName>;
260  defm : Merge_mvv<OpNode,
261                   ShortDataVT, v256i1,
262                   OpBaseName>;
263}
264
265defm : Merge_mvv_ShortLong<vvp_select,
266                           v256f64,
267                           v256f32, "VMRG">;
268defm : Merge_mvv_ShortLong<vvp_select,
269                           v256i64,
270                           v256i32, "VMRG">;
271