xref: /freebsd/contrib/llvm-project/llvm/lib/Target/SystemZ/SystemZOperators.td (revision b64c5a0ace59af62eff52bfe110a521dc73c937b)
1//===-- SystemZOperators.td - SystemZ-specific operators ------*- tblgen-*-===//
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//===----------------------------------------------------------------------===//
10// Type profiles
11//===----------------------------------------------------------------------===//
12def SDT_CallSeqStart        : SDCallSeqStart<[SDTCisVT<0, i64>,
13                                              SDTCisVT<1, i64>]>;
14def SDT_CallSeqEnd          : SDCallSeqEnd<[SDTCisVT<0, i64>,
15                                            SDTCisVT<1, i64>]>;
16def SDT_ZCall               : SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>;
17def SDT_ZCmp                : SDTypeProfile<1, 2,
18                                            [SDTCisVT<0, i32>,
19                                             SDTCisSameAs<1, 2>]>;
20def SDT_ZICmp               : SDTypeProfile<1, 3,
21                                            [SDTCisVT<0, i32>,
22                                             SDTCisSameAs<1, 2>,
23                                             SDTCisVT<3, i32>]>;
24def SDT_ZBRCCMask           : SDTypeProfile<0, 4,
25                                            [SDTCisVT<0, i32>,
26                                             SDTCisVT<1, i32>,
27                                             SDTCisVT<2, OtherVT>,
28                                             SDTCisVT<3, i32>]>;
29def SDT_ZSelectCCMask       : SDTypeProfile<1, 5,
30                                            [SDTCisSameAs<0, 1>,
31                                             SDTCisSameAs<1, 2>,
32                                             SDTCisVT<3, i32>,
33                                             SDTCisVT<4, i32>,
34                                             SDTCisVT<5, i32>]>;
35def SDT_ZWrapPtr            : SDTypeProfile<1, 1,
36                                            [SDTCisSameAs<0, 1>,
37                                             SDTCisPtrTy<0>]>;
38def SDT_ZWrapOffset         : SDTypeProfile<1, 2,
39                                            [SDTCisSameAs<0, 1>,
40                                             SDTCisSameAs<0, 2>,
41                                             SDTCisPtrTy<0>]>;
42def SDT_ZAdjDynAlloc        : SDTypeProfile<1, 0, [SDTCisVT<0, i64>]>;
43def SDT_ZProbedAlloca       : SDTypeProfile<1, 2,
44                                            [SDTCisSameAs<0, 1>,
45                                             SDTCisSameAs<0, 2>,
46                                             SDTCisPtrTy<0>]>;
47def SDT_ZGR128Binary        : SDTypeProfile<1, 2,
48                                            [SDTCisVT<0, untyped>,
49                                             SDTCisInt<1>,
50                                             SDTCisInt<2>]>;
51def SDT_ZBinaryWithFlags    : SDTypeProfile<2, 2,
52                                            [SDTCisInt<0>,
53                                             SDTCisVT<1, i32>,
54                                             SDTCisSameAs<0, 2>,
55                                             SDTCisSameAs<0, 3>]>;
56def SDT_ZBinaryWithCarry    : SDTypeProfile<2, 3,
57                                            [SDTCisInt<0>,
58                                             SDTCisVT<1, i32>,
59                                             SDTCisSameAs<0, 2>,
60                                             SDTCisSameAs<0, 3>,
61                                             SDTCisVT<1, i32>]>;
62def SDT_ZBinaryConv         : SDTypeProfile<1, 2,
63                                            [SDTCisInt<0>,
64                                             SDTCisInt<1>,
65                                             SDTCisSameAs<1, 2>]>;
66def SDT_ZTernary            : SDTypeProfile<1, 3,
67                                            [SDTCisInt<0>,
68                                             SDTCisSameAs<0, 1>,
69                                             SDTCisSameAs<0, 2>,
70                                             SDTCisSameAs<0, 3>]>;
71def SDT_ZAtomicLoadBinaryW  : SDTypeProfile<1, 5,
72                                            [SDTCisVT<0, i32>,
73                                             SDTCisPtrTy<1>,
74                                             SDTCisVT<2, i32>,
75                                             SDTCisVT<3, i32>,
76                                             SDTCisVT<4, i32>,
77                                             SDTCisVT<5, i32>]>;
78def SDT_ZAtomicCmpSwapW     : SDTypeProfile<2, 6,
79                                            [SDTCisVT<0, i32>,
80                                             SDTCisVT<1, i32>,
81                                             SDTCisPtrTy<2>,
82                                             SDTCisVT<3, i32>,
83                                             SDTCisVT<4, i32>,
84                                             SDTCisVT<5, i32>,
85                                             SDTCisVT<6, i32>,
86                                             SDTCisVT<7, i32>]>;
87def SDT_ZAtomicCmpSwap      : SDTypeProfile<2, 3,
88                                            [SDTCisInt<0>,
89                                             SDTCisVT<1, i32>,
90                                             SDTCisPtrTy<2>,
91                                             SDTCisSameAs<0, 3>,
92                                             SDTCisSameAs<0, 4>]>;
93def SDT_ZAtomicLoad128      : SDTypeProfile<1, 1,
94                                            [SDTCisVT<0, untyped>,
95                                             SDTCisPtrTy<1>]>;
96def SDT_ZAtomicStore128     : SDTypeProfile<0, 2,
97                                            [SDTCisVT<0, untyped>,
98                                             SDTCisPtrTy<1>]>;
99def SDT_ZAtomicCmpSwap128   : SDTypeProfile<2, 3,
100                                            [SDTCisVT<0, untyped>,
101                                             SDTCisVT<1, i32>,
102                                             SDTCisPtrTy<2>,
103                                             SDTCisVT<3, untyped>,
104                                             SDTCisVT<4, untyped>]>;
105def SDT_ZMemMemLength       : SDTypeProfile<0, 3,
106                                            [SDTCisPtrTy<0>,
107                                             SDTCisPtrTy<1>,
108                                             SDTCisVT<2, i64>]>;
109def SDT_ZMemMemLengthCC     : SDTypeProfile<1, 3,
110                                            [SDTCisVT<0, i32>,
111                                             SDTCisPtrTy<1>,
112                                             SDTCisPtrTy<2>,
113                                             SDTCisVT<3, i64>]>;
114def SDT_ZMemsetMVC          : SDTypeProfile<0, 3,
115                                            [SDTCisPtrTy<0>,
116                                             SDTCisVT<1, i64>,
117                                             SDTCisVT<2, i32>]>;
118def SDT_ZString             : SDTypeProfile<1, 3,
119                                            [SDTCisPtrTy<0>,
120                                             SDTCisPtrTy<1>,
121                                             SDTCisPtrTy<2>,
122                                             SDTCisVT<3, i32>]>;
123def SDT_ZStringCC           : SDTypeProfile<2, 3,
124                                            [SDTCisPtrTy<0>,
125                                             SDTCisVT<1, i32>,
126                                             SDTCisPtrTy<2>,
127                                             SDTCisPtrTy<3>,
128                                             SDTCisVT<4, i32>]>;
129def SDT_ZIPM                : SDTypeProfile<1, 1,
130                                            [SDTCisVT<0, i32>,
131                                             SDTCisVT<1, i32>]>;
132def SDT_ZPrefetch           : SDTypeProfile<0, 2,
133                                            [SDTCisVT<0, i32>,
134                                             SDTCisPtrTy<1>]>;
135def SDT_ZStoreInherent      : SDTypeProfile<0, 1,
136                                            [SDTCisPtrTy<0>]>;
137def SDT_ZTBegin             : SDTypeProfile<1, 2,
138                                            [SDTCisVT<0, i32>,
139                                             SDTCisPtrTy<1>,
140                                             SDTCisVT<2, i32>]>;
141def SDT_ZADAENTRY           : SDTypeProfile<1, 3,
142                                            [SDTCisPtrTy<0>,
143                                             SDTCisPtrTy<1>,
144                                             SDTCisPtrTy<2>,
145                                             SDTCisVT<3, i64>]>;
146def SDT_ZTEnd               : SDTypeProfile<1, 0,
147                                            [SDTCisVT<0, i32>]>;
148def SDT_ZInsertVectorElt    : SDTypeProfile<1, 3,
149                                            [SDTCisVec<0>,
150                                             SDTCisSameAs<0, 1>,
151                                             SDTCisVT<3, i32>]>;
152def SDT_ZExtractVectorElt   : SDTypeProfile<1, 2,
153                                            [SDTCisVec<1>,
154                                             SDTCisVT<2, i32>]>;
155def SDT_ZReplicate          : SDTypeProfile<1, 1,
156                                            [SDTCisVec<0>]>;
157def SDT_ZVecUnaryConv       : SDTypeProfile<1, 1,
158                                            [SDTCisVec<0>,
159                                             SDTCisVec<1>]>;
160def SDT_ZVecUnary           : SDTypeProfile<1, 1,
161                                            [SDTCisVec<0>,
162                                             SDTCisSameAs<0, 1>]>;
163def SDT_ZVecUnaryCC         : SDTypeProfile<2, 1,
164                                            [SDTCisVec<0>,
165                                             SDTCisVT<1, i32>,
166                                             SDTCisSameAs<0, 2>]>;
167def SDT_ZVecBinary          : SDTypeProfile<1, 2,
168                                            [SDTCisVec<0>,
169                                             SDTCisSameAs<0, 1>,
170                                             SDTCisSameAs<0, 2>]>;
171def SDT_ZVecBinaryCC        : SDTypeProfile<2, 2,
172                                            [SDTCisVec<0>,
173                                             SDTCisVT<1, i32>,
174                                             SDTCisSameAs<0, 2>,
175                                             SDTCisSameAs<0, 2>]>;
176def SDT_ZVecBinaryInt       : SDTypeProfile<1, 2,
177                                            [SDTCisVec<0>,
178                                             SDTCisSameAs<0, 1>,
179                                             SDTCisVT<2, i32>]>;
180def SDT_ZVecBinaryConv      : SDTypeProfile<1, 2,
181                                            [SDTCisVec<0>,
182                                             SDTCisVec<1>,
183                                             SDTCisSameAs<1, 2>]>;
184def SDT_ZVecBinaryConvCC    : SDTypeProfile<2, 2,
185                                            [SDTCisVec<0>,
186                                             SDTCisVT<1, i32>,
187                                             SDTCisVec<2>,
188                                             SDTCisSameAs<2, 3>]>;
189def SDT_ZVecBinaryConvIntCC : SDTypeProfile<2, 2,
190                                            [SDTCisVec<0>,
191                                             SDTCisVT<1, i32>,
192                                             SDTCisVec<2>,
193                                             SDTCisVT<3, i32>]>;
194def SDT_ZRotateMask         : SDTypeProfile<1, 2,
195                                            [SDTCisVec<0>,
196                                             SDTCisVT<1, i32>,
197                                             SDTCisVT<2, i32>]>;
198def SDT_ZJoinDwords         : SDTypeProfile<1, 2,
199                                            [SDTCisVT<0, v2i64>,
200                                             SDTCisVT<1, i64>,
201                                             SDTCisVT<2, i64>]>;
202def SDT_ZVecTernary         : SDTypeProfile<1, 3,
203                                            [SDTCisVec<0>,
204                                             SDTCisSameAs<0, 1>,
205                                             SDTCisSameAs<0, 2>,
206                                             SDTCisSameAs<0, 3>]>;
207def SDT_ZVecTernaryConvCC   : SDTypeProfile<2, 3,
208                                            [SDTCisVec<0>,
209                                             SDTCisVT<1, i32>,
210                                             SDTCisVec<2>,
211                                             SDTCisSameAs<2, 3>,
212                                             SDTCisSameAs<0, 4>]>;
213def SDT_ZVecTernaryInt      : SDTypeProfile<1, 3,
214                                            [SDTCisVec<0>,
215                                             SDTCisSameAs<0, 1>,
216                                             SDTCisSameAs<0, 2>,
217                                             SDTCisVT<3, i32>]>;
218def SDT_ZVecTernaryIntCC    : SDTypeProfile<2, 3,
219                                            [SDTCisVec<0>,
220                                             SDTCisVT<1, i32>,
221                                             SDTCisSameAs<0, 2>,
222                                             SDTCisSameAs<0, 3>,
223                                             SDTCisVT<4, i32>]>;
224def SDT_ZVecQuaternaryInt   : SDTypeProfile<1, 4,
225                                            [SDTCisVec<0>,
226                                             SDTCisSameAs<0, 1>,
227                                             SDTCisSameAs<0, 2>,
228                                             SDTCisSameAs<0, 3>,
229                                             SDTCisVT<4, i32>]>;
230def SDT_ZVecQuaternaryIntCC : SDTypeProfile<2, 4,
231                                            [SDTCisVec<0>,
232                                             SDTCisVT<1, i32>,
233                                             SDTCisSameAs<0, 2>,
234                                             SDTCisSameAs<0, 3>,
235                                             SDTCisSameAs<0, 4>,
236                                             SDTCisVT<5, i32>]>;
237def SDT_ZTest               : SDTypeProfile<1, 2,
238                                            [SDTCisVT<0, i32>,
239                                             SDTCisVT<2, i64>]>;
240
241//===----------------------------------------------------------------------===//
242// Node definitions
243//===----------------------------------------------------------------------===//
244
245// These are target-independent nodes, but have target-specific formats.
246def callseq_start       : SDNode<"ISD::CALLSEQ_START", SDT_CallSeqStart,
247                                 [SDNPHasChain, SDNPSideEffect, SDNPOutGlue]>;
248def callseq_end         : SDNode<"ISD::CALLSEQ_END",   SDT_CallSeqEnd,
249                                 [SDNPHasChain, SDNPSideEffect, SDNPOptInGlue,
250                                  SDNPOutGlue]>;
251def global_offset_table : SDNode<"ISD::GLOBAL_OFFSET_TABLE", SDTPtrLeaf>;
252
253// Nodes for SystemZISD::*.  See SystemZISelLowering.h for more details.
254def z_retglue           : SDNode<"SystemZISD::RET_GLUE", SDTNone,
255                                 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
256def z_call              : SDNode<"SystemZISD::CALL", SDT_ZCall,
257                                 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
258                                  SDNPVariadic]>;
259def z_sibcall           : SDNode<"SystemZISD::SIBCALL", SDT_ZCall,
260                                 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
261                                  SDNPVariadic]>;
262def z_tls_gdcall        : SDNode<"SystemZISD::TLS_GDCALL", SDT_ZCall,
263                                 [SDNPHasChain, SDNPInGlue, SDNPOutGlue,
264                                  SDNPVariadic]>;
265def z_tls_ldcall        : SDNode<"SystemZISD::TLS_LDCALL", SDT_ZCall,
266                                 [SDNPHasChain, SDNPInGlue, SDNPOutGlue,
267                                  SDNPVariadic]>;
268def z_pcrel_wrapper     : SDNode<"SystemZISD::PCREL_WRAPPER", SDT_ZWrapPtr, []>;
269def z_pcrel_offset      : SDNode<"SystemZISD::PCREL_OFFSET",
270                                 SDT_ZWrapOffset, []>;
271def z_icmp              : SDNode<"SystemZISD::ICMP", SDT_ZICmp>;
272def z_fcmp              : SDNode<"SystemZISD::FCMP", SDT_ZCmp>;
273def z_strict_fcmp       : SDNode<"SystemZISD::STRICT_FCMP", SDT_ZCmp,
274                                 [SDNPHasChain]>;
275def z_strict_fcmps      : SDNode<"SystemZISD::STRICT_FCMPS", SDT_ZCmp,
276                                 [SDNPHasChain]>;
277def z_tm                : SDNode<"SystemZISD::TM", SDT_ZICmp>;
278def z_br_ccmask_1       : SDNode<"SystemZISD::BR_CCMASK", SDT_ZBRCCMask,
279                                 [SDNPHasChain]>;
280def z_select_ccmask_1   : SDNode<"SystemZISD::SELECT_CCMASK",
281                                 SDT_ZSelectCCMask>;
282def z_ipm_1             : SDNode<"SystemZISD::IPM", SDT_ZIPM>;
283def z_adjdynalloc       : SDNode<"SystemZISD::ADJDYNALLOC", SDT_ZAdjDynAlloc>;
284def z_probed_alloca     : SDNode<"SystemZISD::PROBED_ALLOCA", SDT_ZProbedAlloca,
285                                 [SDNPHasChain]>;
286def z_popcnt            : SDNode<"SystemZISD::POPCNT", SDTIntUnaryOp>;
287def z_smul_lohi         : SDNode<"SystemZISD::SMUL_LOHI", SDT_ZGR128Binary>;
288def z_umul_lohi         : SDNode<"SystemZISD::UMUL_LOHI", SDT_ZGR128Binary>;
289def z_sdivrem           : SDNode<"SystemZISD::SDIVREM", SDT_ZGR128Binary>;
290def z_udivrem           : SDNode<"SystemZISD::UDIVREM", SDT_ZGR128Binary>;
291def z_saddo             : SDNode<"SystemZISD::SADDO", SDT_ZBinaryWithFlags>;
292def z_ssubo             : SDNode<"SystemZISD::SSUBO", SDT_ZBinaryWithFlags>;
293def z_uaddo             : SDNode<"SystemZISD::UADDO", SDT_ZBinaryWithFlags>;
294def z_usubo             : SDNode<"SystemZISD::USUBO", SDT_ZBinaryWithFlags>;
295def z_addcarry_1        : SDNode<"SystemZISD::ADDCARRY", SDT_ZBinaryWithCarry>;
296def z_subcarry_1        : SDNode<"SystemZISD::SUBCARRY", SDT_ZBinaryWithCarry>;
297def z_vacc              : SDNode<"SystemZISD::VACC", SDTIntBinOp>;
298def z_vac               : SDNode<"SystemZISD::VAC", SDT_ZTernary>;
299def z_vaccc             : SDNode<"SystemZISD::VACCC", SDT_ZTernary>;
300def z_vscbi             : SDNode<"SystemZISD::VSCBI", SDTIntBinOp>;
301def z_vsbi              : SDNode<"SystemZISD::VSBI", SDT_ZTernary>;
302def z_vsbcbi            : SDNode<"SystemZISD::VSBCBI", SDT_ZTernary>;
303
304def z_loadbswap        : SDNode<"SystemZISD::LRV", SDTLoad,
305                                 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
306def z_storebswap       : SDNode<"SystemZISD::STRV", SDTStore,
307                                 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
308def z_loadeswap        : SDNode<"SystemZISD::VLER", SDTLoad,
309                                 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
310def z_storeeswap       : SDNode<"SystemZISD::VSTER", SDTStore,
311                                 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
312def z_stckf            : SDNode<"SystemZISD::STCKF", SDT_ZStoreInherent,
313                                [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
314
315def z_tdc               : SDNode<"SystemZISD::TDC", SDT_ZTest>;
316
317// Defined because the index is an i32 rather than a pointer.
318def z_vector_insert     : SDNode<"ISD::INSERT_VECTOR_ELT",
319                                 SDT_ZInsertVectorElt>;
320def z_vector_extract    : SDNode<"ISD::EXTRACT_VECTOR_ELT",
321                                 SDT_ZExtractVectorElt>;
322def z_byte_mask         : SDNode<"SystemZISD::BYTE_MASK", SDT_ZReplicate>;
323def z_rotate_mask       : SDNode<"SystemZISD::ROTATE_MASK", SDT_ZRotateMask>;
324def z_replicate         : SDNode<"SystemZISD::REPLICATE", SDT_ZReplicate>;
325def z_join_dwords       : SDNode<"SystemZISD::JOIN_DWORDS", SDT_ZJoinDwords>;
326def z_splat             : SDNode<"SystemZISD::SPLAT", SDT_ZVecBinaryInt>;
327def z_merge_high        : SDNode<"SystemZISD::MERGE_HIGH", SDT_ZVecBinary>;
328def z_merge_low         : SDNode<"SystemZISD::MERGE_LOW", SDT_ZVecBinary>;
329def z_shl_double        : SDNode<"SystemZISD::SHL_DOUBLE", SDT_ZVecTernaryInt>;
330def z_permute_dwords    : SDNode<"SystemZISD::PERMUTE_DWORDS",
331                                 SDT_ZVecTernaryInt>;
332def z_permute           : SDNode<"SystemZISD::PERMUTE", SDT_ZVecTernary>;
333def z_pack              : SDNode<"SystemZISD::PACK", SDT_ZVecBinaryConv>;
334def z_packs_cc          : SDNode<"SystemZISD::PACKS_CC", SDT_ZVecBinaryConvCC>;
335def z_packls_cc         : SDNode<"SystemZISD::PACKLS_CC", SDT_ZVecBinaryConvCC>;
336def z_unpack_high       : SDNode<"SystemZISD::UNPACK_HIGH", SDT_ZVecUnaryConv>;
337def z_unpackl_high      : SDNode<"SystemZISD::UNPACKL_HIGH", SDT_ZVecUnaryConv>;
338def z_unpack_low        : SDNode<"SystemZISD::UNPACK_LOW", SDT_ZVecUnaryConv>;
339def z_unpackl_low       : SDNode<"SystemZISD::UNPACKL_LOW", SDT_ZVecUnaryConv>;
340def z_vshl_by_scalar    : SDNode<"SystemZISD::VSHL_BY_SCALAR",
341                                 SDT_ZVecBinaryInt>;
342def z_vsrl_by_scalar    : SDNode<"SystemZISD::VSRL_BY_SCALAR",
343                                 SDT_ZVecBinaryInt>;
344def z_vsra_by_scalar    : SDNode<"SystemZISD::VSRA_BY_SCALAR",
345                                 SDT_ZVecBinaryInt>;
346def z_vrotl_by_scalar   : SDNode<"SystemZISD::VROTL_BY_SCALAR",
347                                 SDT_ZVecBinaryInt>;
348def z_vsum              : SDNode<"SystemZISD::VSUM", SDT_ZBinaryConv>;
349def z_vicmpe            : SDNode<"SystemZISD::VICMPE", SDT_ZVecBinary>;
350def z_vicmph            : SDNode<"SystemZISD::VICMPH", SDT_ZVecBinary>;
351def z_vicmphl           : SDNode<"SystemZISD::VICMPHL", SDT_ZVecBinary>;
352def z_vicmpes           : SDNode<"SystemZISD::VICMPES", SDT_ZVecBinaryCC>;
353def z_vicmphs           : SDNode<"SystemZISD::VICMPHS", SDT_ZVecBinaryCC>;
354def z_vicmphls          : SDNode<"SystemZISD::VICMPHLS", SDT_ZVecBinaryCC>;
355def z_vfcmpe            : SDNode<"SystemZISD::VFCMPE", SDT_ZVecBinaryConv>;
356def z_strict_vfcmpe     : SDNode<"SystemZISD::STRICT_VFCMPE",
357                                 SDT_ZVecBinaryConv, [SDNPHasChain]>;
358def z_strict_vfcmpes    : SDNode<"SystemZISD::STRICT_VFCMPES",
359                                 SDT_ZVecBinaryConv, [SDNPHasChain]>;
360def z_vfcmph            : SDNode<"SystemZISD::VFCMPH", SDT_ZVecBinaryConv>;
361def z_strict_vfcmph     : SDNode<"SystemZISD::STRICT_VFCMPH",
362                                 SDT_ZVecBinaryConv, [SDNPHasChain]>;
363def z_strict_vfcmphs    : SDNode<"SystemZISD::STRICT_VFCMPHS",
364                                 SDT_ZVecBinaryConv, [SDNPHasChain]>;
365def z_vfcmphe           : SDNode<"SystemZISD::VFCMPHE", SDT_ZVecBinaryConv>;
366def z_strict_vfcmphe    : SDNode<"SystemZISD::STRICT_VFCMPHE",
367                                 SDT_ZVecBinaryConv, [SDNPHasChain]>;
368def z_strict_vfcmphes   : SDNode<"SystemZISD::STRICT_VFCMPHES",
369                                 SDT_ZVecBinaryConv, [SDNPHasChain]>;
370def z_vfcmpes           : SDNode<"SystemZISD::VFCMPES", SDT_ZVecBinaryConvCC>;
371def z_vfcmphs           : SDNode<"SystemZISD::VFCMPHS", SDT_ZVecBinaryConvCC>;
372def z_vfcmphes          : SDNode<"SystemZISD::VFCMPHES", SDT_ZVecBinaryConvCC>;
373def z_vextend           : SDNode<"SystemZISD::VEXTEND", SDT_ZVecUnaryConv>;
374def z_strict_vextend    : SDNode<"SystemZISD::STRICT_VEXTEND",
375                                 SDT_ZVecUnaryConv, [SDNPHasChain]>;
376def z_vround            : SDNode<"SystemZISD::VROUND", SDT_ZVecUnaryConv>;
377def z_strict_vround     : SDNode<"SystemZISD::STRICT_VROUND",
378                                 SDT_ZVecUnaryConv, [SDNPHasChain]>;
379def z_vtm               : SDNode<"SystemZISD::VTM", SDT_ZCmp>;
380def z_scmp128hi         : SDNode<"SystemZISD::SCMP128HI", SDT_ZCmp>;
381def z_ucmp128hi         : SDNode<"SystemZISD::UCMP128HI", SDT_ZCmp>;
382def z_vfae_cc           : SDNode<"SystemZISD::VFAE_CC", SDT_ZVecTernaryIntCC>;
383def z_vfaez_cc          : SDNode<"SystemZISD::VFAEZ_CC", SDT_ZVecTernaryIntCC>;
384def z_vfee_cc           : SDNode<"SystemZISD::VFEE_CC", SDT_ZVecBinaryCC>;
385def z_vfeez_cc          : SDNode<"SystemZISD::VFEEZ_CC", SDT_ZVecBinaryCC>;
386def z_vfene_cc          : SDNode<"SystemZISD::VFENE_CC", SDT_ZVecBinaryCC>;
387def z_vfenez_cc         : SDNode<"SystemZISD::VFENEZ_CC", SDT_ZVecBinaryCC>;
388def z_vistr_cc          : SDNode<"SystemZISD::VISTR_CC", SDT_ZVecUnaryCC>;
389def z_vstrc_cc          : SDNode<"SystemZISD::VSTRC_CC",
390                                 SDT_ZVecQuaternaryIntCC>;
391def z_vstrcz_cc         : SDNode<"SystemZISD::VSTRCZ_CC",
392                                 SDT_ZVecQuaternaryIntCC>;
393def z_vstrs_cc          : SDNode<"SystemZISD::VSTRS_CC",
394                                 SDT_ZVecTernaryConvCC>;
395def z_vstrsz_cc         : SDNode<"SystemZISD::VSTRSZ_CC",
396                                 SDT_ZVecTernaryConvCC>;
397def z_vftci             : SDNode<"SystemZISD::VFTCI", SDT_ZVecBinaryConvIntCC>;
398
399class AtomicWOp<string name, SDTypeProfile profile = SDT_ZAtomicLoadBinaryW>
400  : SDNode<"SystemZISD::"#name, profile,
401           [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
402
403def z_atomic_swapw      : AtomicWOp<"ATOMIC_SWAPW">;
404def z_atomic_loadw_add  : AtomicWOp<"ATOMIC_LOADW_ADD">;
405def z_atomic_loadw_sub  : AtomicWOp<"ATOMIC_LOADW_SUB">;
406def z_atomic_loadw_and  : AtomicWOp<"ATOMIC_LOADW_AND">;
407def z_atomic_loadw_or   : AtomicWOp<"ATOMIC_LOADW_OR">;
408def z_atomic_loadw_xor  : AtomicWOp<"ATOMIC_LOADW_XOR">;
409def z_atomic_loadw_nand : AtomicWOp<"ATOMIC_LOADW_NAND">;
410def z_atomic_loadw_min  : AtomicWOp<"ATOMIC_LOADW_MIN">;
411def z_atomic_loadw_max  : AtomicWOp<"ATOMIC_LOADW_MAX">;
412def z_atomic_loadw_umin : AtomicWOp<"ATOMIC_LOADW_UMIN">;
413def z_atomic_loadw_umax : AtomicWOp<"ATOMIC_LOADW_UMAX">;
414
415def z_atomic_cmp_swap   : SDNode<"SystemZISD::ATOMIC_CMP_SWAP",
416                                 SDT_ZAtomicCmpSwap,
417                                 [SDNPHasChain, SDNPMayStore, SDNPMayLoad,
418                                  SDNPMemOperand]>;
419def z_atomic_cmp_swapw  : SDNode<"SystemZISD::ATOMIC_CMP_SWAPW",
420                                 SDT_ZAtomicCmpSwapW,
421                                 [SDNPHasChain, SDNPMayStore, SDNPMayLoad,
422                                  SDNPMemOperand]>;
423
424def z_atomic_load_128   : SDNode<"SystemZISD::ATOMIC_LOAD_128",
425                                 SDT_ZAtomicLoad128,
426                                 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
427def z_atomic_store_128  : SDNode<"SystemZISD::ATOMIC_STORE_128",
428                                 SDT_ZAtomicStore128,
429                                 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
430def z_atomic_cmp_swap_128 : SDNode<"SystemZISD::ATOMIC_CMP_SWAP_128",
431                                   SDT_ZAtomicCmpSwap128,
432                                   [SDNPHasChain, SDNPMayStore, SDNPMayLoad,
433                                    SDNPMemOperand]>;
434
435def z_mvc               : SDNode<"SystemZISD::MVC", SDT_ZMemMemLength,
436                                 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
437def z_nc                : SDNode<"SystemZISD::NC", SDT_ZMemMemLength,
438                                  [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
439def z_oc                : SDNode<"SystemZISD::OC", SDT_ZMemMemLength,
440                                  [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
441def z_xc                : SDNode<"SystemZISD::XC", SDT_ZMemMemLength,
442                                  [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
443def z_clc               : SDNode<"SystemZISD::CLC", SDT_ZMemMemLengthCC,
444                                 [SDNPHasChain, SDNPMayLoad]>;
445def z_memset_mvc        : SDNode<"SystemZISD::MEMSET_MVC", SDT_ZMemsetMVC,
446                                 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
447def z_strcmp            : SDNode<"SystemZISD::STRCMP", SDT_ZStringCC,
448                                 [SDNPHasChain, SDNPMayLoad]>;
449def z_stpcpy            : SDNode<"SystemZISD::STPCPY", SDT_ZString,
450                                 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
451def z_search_string     : SDNode<"SystemZISD::SEARCH_STRING", SDT_ZStringCC,
452                                 [SDNPHasChain, SDNPMayLoad]>;
453def z_prefetch          : SDNode<"SystemZISD::PREFETCH", SDT_ZPrefetch,
454                                 [SDNPHasChain, SDNPMayLoad, SDNPMayStore,
455                                  SDNPMemOperand]>;
456
457def z_tbegin            : SDNode<"SystemZISD::TBEGIN", SDT_ZTBegin,
458                                 [SDNPHasChain, SDNPMayStore, SDNPSideEffect]>;
459def z_tbegin_nofloat    : SDNode<"SystemZISD::TBEGIN_NOFLOAT", SDT_ZTBegin,
460                                 [SDNPHasChain, SDNPMayStore, SDNPSideEffect]>;
461def z_tend              : SDNode<"SystemZISD::TEND", SDT_ZTEnd,
462                                 [SDNPHasChain, SDNPSideEffect]>;
463
464def z_ada_entry         : SDNode<"SystemZISD::ADA_ENTRY",
465                                  SDT_ZADAENTRY>;
466
467def z_vshl              : SDNode<"ISD::SHL", SDT_ZVecBinary>;
468def z_vsra              : SDNode<"ISD::SRA", SDT_ZVecBinary>;
469def z_vsrl              : SDNode<"ISD::SRL", SDT_ZVecBinary>;
470
471//===----------------------------------------------------------------------===//
472// Pattern fragments
473//===----------------------------------------------------------------------===//
474
475def z_loadbswap16 : PatFrag<(ops node:$addr), (z_loadbswap node:$addr), [{
476  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i16;
477}]>;
478def z_loadbswap32 : PatFrag<(ops node:$addr), (z_loadbswap node:$addr), [{
479  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
480}]>;
481def z_loadbswap64 : PatFrag<(ops node:$addr), (z_loadbswap node:$addr), [{
482  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
483}]>;
484
485def z_storebswap16 : PatFrag<(ops node:$src, node:$addr),
486                             (z_storebswap node:$src, node:$addr), [{
487  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i16;
488}]>;
489def z_storebswap32 : PatFrag<(ops node:$src, node:$addr),
490                             (z_storebswap node:$src, node:$addr), [{
491  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i32;
492}]>;
493def z_storebswap64 : PatFrag<(ops node:$src, node:$addr),
494                             (z_storebswap node:$src, node:$addr), [{
495  return cast<MemIntrinsicSDNode>(N)->getMemoryVT() == MVT::i64;
496}]>;
497
498// Fragments including CC as an implicit source.
499def z_br_ccmask
500  : PatFrag<(ops node:$valid, node:$mask, node:$bb),
501            (z_br_ccmask_1 node:$valid, node:$mask, node:$bb, CC)>;
502def z_select_ccmask
503  : PatFrag<(ops node:$true, node:$false, node:$valid, node:$mask),
504            (z_select_ccmask_1 node:$true, node:$false,
505                               node:$valid, node:$mask, CC)>;
506def z_ipm : PatFrag<(ops), (z_ipm_1 CC)>;
507def z_addcarry : PatFrag<(ops node:$lhs, node:$rhs),
508                              (z_addcarry_1 node:$lhs, node:$rhs, CC)>;
509def z_subcarry : PatFrag<(ops node:$lhs, node:$rhs),
510                              (z_subcarry_1 node:$lhs, node:$rhs, CC)>;
511
512// Signed and unsigned comparisons.
513def z_scmp : PatFrag<(ops node:$a, node:$b), (z_icmp node:$a, node:$b, timm), [{
514  unsigned Type = N->getConstantOperandVal(2);
515  return Type != SystemZICMP::UnsignedOnly;
516}]>;
517def z_ucmp : PatFrag<(ops node:$a, node:$b), (z_icmp node:$a, node:$b, timm), [{
518  unsigned Type = N->getConstantOperandVal(2);
519  return Type != SystemZICMP::SignedOnly;
520}]>;
521
522// Register- and memory-based TEST UNDER MASK.
523def z_tm_reg : PatFrag<(ops node:$a, node:$b), (z_tm node:$a, node:$b, timm)>;
524def z_tm_mem : PatFrag<(ops node:$a, node:$b), (z_tm node:$a, node:$b, 0)>;
525
526// Register sign-extend operations.  Sub-32-bit values are represented as i32s.
527def sext8  : PatFrag<(ops node:$src), (sext_inreg node:$src, i8)>;
528def sext16 : PatFrag<(ops node:$src), (sext_inreg node:$src, i16)>;
529def sext32 : PatFrag<(ops node:$src), (sext (i32 node:$src))>;
530
531// Match extensions of an i32 to an i64, followed by an in-register sign
532// extension from a sub-i32 value.
533def sext8dbl : PatFrag<(ops node:$src), (sext8 (anyext node:$src))>;
534def sext16dbl : PatFrag<(ops node:$src), (sext16 (anyext node:$src))>;
535
536// Register zero-extend operations.  Sub-32-bit values are represented as i32s.
537def zext8  : PatFrag<(ops node:$src), (and node:$src, 0xff)>;
538def zext16 : PatFrag<(ops node:$src), (and node:$src, 0xffff)>;
539def zext32 : PatFrag<(ops node:$src), (zext (i32 node:$src))>;
540
541// Match a load or a non-extending atomic load.
542def z_load : PatFrags<(ops node:$ptr),
543                      [(load node:$ptr),
544                       (atomic_load node:$ptr)], [{
545  if (auto *AL = dyn_cast<AtomicSDNode>(N))
546    if (AL->getExtensionType() != ISD::NON_EXTLOAD)
547      return false;
548  return true;
549}]>;
550
551// Sign extending (atomic) loads.
552def z_sextload : PatFrags<(ops node:$ptr),
553                          [(unindexedload node:$ptr),
554                           (atomic_load node:$ptr)], [{
555  return getLoadExtType(N) == ISD::SEXTLOAD;
556}]>;
557def z_sextloadi8 : PatFrag<(ops node:$ptr), (z_sextload node:$ptr), [{
558  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i8;
559}]>;
560def z_sextloadi16 : PatFrag<(ops node:$ptr), (z_sextload node:$ptr), [{
561  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i16;
562}]>;
563def z_sextloadi32 : PatFrag<(ops node:$ptr), (z_sextload node:$ptr), [{
564  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i32;
565}]>;
566def z_sextloadi64 : PatFrag<(ops node:$ptr), (z_sextload node:$ptr), [{
567  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i64;
568}]>;
569
570// Zero extending (atomic) loads.
571def z_zextload : PatFrags<(ops node:$ptr),
572                          [(unindexedload node:$ptr),
573                           (atomic_load node:$ptr)], [{
574  return getLoadExtType(N) == ISD::ZEXTLOAD;
575}]>;
576def z_zextloadi8 : PatFrag<(ops node:$ptr), (z_zextload node:$ptr), [{
577  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i8;
578}]>;
579def z_zextloadi16 : PatFrag<(ops node:$ptr), (z_zextload node:$ptr), [{
580  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i16;
581}]>;
582def z_zextloadi32 : PatFrag<(ops node:$ptr), (z_zextload node:$ptr), [{
583  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i32;
584}]>;
585def z_zextloadi64 : PatFrag<(ops node:$ptr), (z_zextload node:$ptr), [{
586  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i64;
587}]>;
588
589// Extending (atomic) loads in which the extension type can be signed.
590def z_asextload : PatFrags<(ops node:$ptr),
591                           [(unindexedload node:$ptr),
592                            (atomic_load node:$ptr)], [{
593  ISD::LoadExtType ETy = getLoadExtType(N);
594  return ETy == ISD::EXTLOAD || ETy == ISD::SEXTLOAD;
595}]>;
596def z_asextloadi8 : PatFrag<(ops node:$ptr), (z_asextload node:$ptr), [{
597  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i8;
598}]>;
599def z_asextloadi16 : PatFrag<(ops node:$ptr), (z_asextload node:$ptr), [{
600  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i16;
601}]>;
602def z_asextloadi32 : PatFrag<(ops node:$ptr), (z_asextload node:$ptr), [{
603  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i32;
604}]>;
605
606// Extending (atomic) loads in which the extension type can be unsigned.
607def z_azextload : PatFrags<(ops node:$ptr),
608                           [(unindexedload node:$ptr),
609                           (atomic_load node:$ptr)], [{
610  ISD::LoadExtType ETy = getLoadExtType(N);
611  return ETy == ISD::EXTLOAD || ETy == ISD::ZEXTLOAD;
612}]>;
613def z_azextloadi8 : PatFrag<(ops node:$ptr), (z_azextload node:$ptr), [{
614  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i8;
615}]>;
616def z_azextloadi16 : PatFrag<(ops node:$ptr), (z_azextload node:$ptr), [{
617  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i16;
618}]>;
619def z_azextloadi32 : PatFrag<(ops node:$ptr), (z_azextload node:$ptr), [{
620  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i32;
621}]>;
622
623// Extending (atomic) loads in which the extension type doesn't matter.
624def z_anyextload : PatFrags<(ops node:$ptr),
625                            [(unindexedload node:$ptr),
626                             (atomic_load node:$ptr)], [{
627  return getLoadExtType(N) != ISD::NON_EXTLOAD;
628}]>;
629def z_anyextloadi8 : PatFrag<(ops node:$ptr), (z_anyextload node:$ptr), [{
630  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i8;
631}]>;
632def z_anyextloadi16 : PatFrag<(ops node:$ptr), (z_anyextload node:$ptr), [{
633  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i16;
634}]>;
635def z_anyextloadi32 : PatFrag<(ops node:$ptr), (z_anyextload node:$ptr), [{
636  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i32;
637}]>;
638def z_anyextloadi64 : PatFrag<(ops node:$ptr), (z_anyextload node:$ptr), [{
639  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i64;
640}]>;
641
642// Extending non-atomic loads in which the extension type doesn't matter.
643def anyextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
644  return cast<LoadSDNode>(N)->getExtensionType() != ISD::NON_EXTLOAD;
645}]>;
646def anyextloadi8 : PatFrag<(ops node:$ptr), (anyextload node:$ptr), [{
647  return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
648}]>;
649def anyextloadi16 : PatFrag<(ops node:$ptr), (anyextload node:$ptr), [{
650  return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
651}]>;
652def anyextloadi32 : PatFrag<(ops node:$ptr), (anyextload node:$ptr), [{
653  return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
654}]>;
655
656// Extending (atomic) loads that are not sign/zero extending.
657def z_extload : PatFrags<(ops node:$ptr),
658                         [(extload node:$ptr),
659                          (atomic_load node:$ptr)], [{
660  return getLoadExtType(N) == ISD::EXTLOAD;
661}]>;
662def z_extloadi8 : PatFrag<(ops node:$ptr), (z_extload node:$ptr), [{
663  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i8;
664}]>;
665def z_extloadi16 : PatFrag<(ops node:$ptr), (z_extload node:$ptr), [{
666  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i16;
667}]>;
668def z_extloadi32 : PatFrag<(ops node:$ptr), (z_extload node:$ptr), [{
669  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i32;
670}]>;
671def z_extloadi64 : PatFrag<(ops node:$ptr), (z_extload node:$ptr), [{
672  return cast<MemSDNode>(N)->getMemoryVT() == MVT::i64;
673}]>;
674
675// Extending atomic FP loads.
676def z_any_extloadf32 : PatFrags<(ops node:$ptr),
677                                [(any_extloadf32 node:$ptr),
678                                 (any_fpextend (f32 (atomic_load node:$ptr)))]>;
679def z_any_extloadf64 : PatFrags<(ops node:$ptr),
680                                [(any_extloadf64 node:$ptr),
681                                 (any_fpextend (f64 (atomic_load node:$ptr)))]>;
682
683// Aligned loads.
684class AlignedLoad<SDPatternOperator load>
685  : PatFrag<(ops node:$addr), (load node:$addr),
686  [{ return storeLoadIsAligned(N); }]>;
687def aligned_z_load         : AlignedLoad<z_load>;
688def aligned_z_asextloadi16 : AlignedLoad<z_asextloadi16>;
689def aligned_z_asextloadi32 : AlignedLoad<z_asextloadi32>;
690def aligned_z_azextloadi16 : AlignedLoad<z_azextloadi16>;
691def aligned_z_azextloadi32 : AlignedLoad<z_azextloadi32>;
692
693// Aligned stores.
694class AlignedStore<SDPatternOperator store>
695  : PatFrag<(ops node:$src, node:$addr), (store node:$src, node:$addr),
696  [{ return storeLoadIsAligned(N); }]>;
697def aligned_store         : AlignedStore<store>;
698def aligned_truncstorei16 : AlignedStore<truncstorei16>;
699def aligned_truncstorei32 : AlignedStore<truncstorei32>;
700
701// Non-volatile loads.  Used for instructions that might access the storage
702// location multiple times.
703class NonvolatileLoad<SDPatternOperator load>
704  : PatFrag<(ops node:$addr), (load node:$addr), [{
705  auto *Load = cast<LoadSDNode>(N);
706  return !Load->isVolatile();
707}]>;
708def nonvolatile_anyextloadi8  : NonvolatileLoad<anyextloadi8>;
709def nonvolatile_anyextloadi16 : NonvolatileLoad<anyextloadi16>;
710def nonvolatile_anyextloadi32 : NonvolatileLoad<anyextloadi32>;
711
712// Non-volatile stores.
713class NonvolatileStore<SDPatternOperator store>
714  : PatFrag<(ops node:$src, node:$addr), (store node:$src, node:$addr), [{
715  auto *Store = cast<StoreSDNode>(N);
716  return !Store->isVolatile();
717}]>;
718def nonvolatile_truncstorei8  : NonvolatileStore<truncstorei8>;
719def nonvolatile_truncstorei16 : NonvolatileStore<truncstorei16>;
720def nonvolatile_truncstorei32 : NonvolatileStore<truncstorei32>;
721
722// A store of a load that can be implemented using MVC.
723def mvc_store : PatFrag<(ops node:$value, node:$addr),
724                        (unindexedstore node:$value, node:$addr),
725                        [{ return storeLoadCanUseMVC(N); }]>;
726
727// Binary read-modify-write operations on memory in which the other
728// operand is also memory and for which block operations like NC can
729// be used.  There are two patterns for each operator, depending on
730// which operand contains the "other" load.
731multiclass block_op<SDPatternOperator operator> {
732  def "1" : PatFrag<(ops node:$value, node:$addr),
733                    (unindexedstore (operator node:$value,
734                                              (unindexedload node:$addr)),
735                                    node:$addr),
736                    [{ return storeLoadCanUseBlockBinary(N, 0); }]>;
737  def "2" : PatFrag<(ops node:$value, node:$addr),
738                    (unindexedstore (operator (unindexedload node:$addr),
739                                              node:$value),
740                                    node:$addr),
741                    [{ return storeLoadCanUseBlockBinary(N, 1); }]>;
742}
743defm block_and : block_op<and>;
744defm block_or  : block_op<or>;
745defm block_xor : block_op<xor>;
746
747// Insertions.
748def inserti8 : PatFrag<(ops node:$src1, node:$src2),
749                       (or (and node:$src1, -256), node:$src2)>;
750def insertll : PatFrag<(ops node:$src1, node:$src2),
751                       (or (and node:$src1, 0xffffffffffff0000), node:$src2)>;
752def insertlh : PatFrag<(ops node:$src1, node:$src2),
753                       (or (and node:$src1, 0xffffffff0000ffff), node:$src2)>;
754def inserthl : PatFrag<(ops node:$src1, node:$src2),
755                       (or (and node:$src1, 0xffff0000ffffffff), node:$src2)>;
756def inserthh : PatFrag<(ops node:$src1, node:$src2),
757                       (or (and node:$src1, 0x0000ffffffffffff), node:$src2)>;
758def insertlf : PatFrag<(ops node:$src1, node:$src2),
759                       (or (and node:$src1, 0xffffffff00000000), node:$src2)>;
760def inserthf : PatFrag<(ops node:$src1, node:$src2),
761                       (or (and node:$src1, 0x00000000ffffffff), node:$src2)>;
762
763// ORs that can be treated as insertions.
764def or_as_inserti8 : PatFrag<(ops node:$src1, node:$src2),
765                             (or node:$src1, node:$src2), [{
766  unsigned BitWidth = N->getValueType(0).getScalarSizeInBits();
767  return CurDAG->MaskedValueIsZero(N->getOperand(0),
768                                   APInt::getLowBitsSet(BitWidth, 8));
769}]>;
770
771// ORs that can be treated as reversed insertions.
772def or_as_revinserti8 : PatFrag<(ops node:$src1, node:$src2),
773                                (or node:$src1, node:$src2), [{
774  unsigned BitWidth = N->getValueType(0).getScalarSizeInBits();
775  return CurDAG->MaskedValueIsZero(N->getOperand(1),
776                                   APInt::getLowBitsSet(BitWidth, 8));
777}]>;
778
779// Negative integer absolute.
780def z_inegabs : PatFrag<(ops node:$src), (ineg (abs node:$src))>;
781
782// Integer multiply-and-add
783def z_muladd : PatFrag<(ops node:$src1, node:$src2, node:$src3),
784                       (add (mul node:$src1, node:$src2), node:$src3)>;
785
786// Alternatives to match operations with or without an overflow CC result.
787def z_sadd : PatFrags<(ops node:$src1, node:$src2),
788                      [(z_saddo node:$src1, node:$src2),
789                       (add node:$src1, node:$src2)]>;
790def z_uadd : PatFrags<(ops node:$src1, node:$src2),
791                      [(z_uaddo node:$src1, node:$src2),
792                       (add node:$src1, node:$src2)]>;
793def z_ssub : PatFrags<(ops node:$src1, node:$src2),
794                      [(z_ssubo node:$src1, node:$src2),
795                       (sub node:$src1, node:$src2)]>;
796def z_usub : PatFrags<(ops node:$src1, node:$src2),
797                      [(z_usubo node:$src1, node:$src2),
798                       (sub node:$src1, node:$src2)]>;
799
800// Combined logical operations.
801def andc : PatFrag<(ops node:$src1, node:$src2),
802                   (and node:$src1, (not node:$src2))>;
803def orc  : PatFrag<(ops node:$src1, node:$src2),
804                   (or node:$src1, (not node:$src2))>;
805def nand : PatFrag<(ops node:$src1, node:$src2),
806                   (not (and node:$src1, node:$src2))>;
807def nor  : PatFrag<(ops node:$src1, node:$src2),
808                   (not (or node:$src1, node:$src2))>;
809def nxor : PatFrag<(ops node:$src1, node:$src2),
810                   (not (xor node:$src1, node:$src2))>;
811
812// Fused multiply-subtract, using the natural operand order.
813def any_fms : PatFrag<(ops node:$src1, node:$src2, node:$src3),
814                      (any_fma node:$src1, node:$src2, (fneg node:$src3))>;
815
816// Fused multiply-add and multiply-subtract, but with the order of the
817// operands matching SystemZ's MA and MS instructions.
818def z_any_fma : PatFrag<(ops node:$src1, node:$src2, node:$src3),
819                        (any_fma node:$src2, node:$src3, node:$src1)>;
820def z_any_fms : PatFrag<(ops node:$src1, node:$src2, node:$src3),
821                        (any_fma node:$src2, node:$src3, (fneg node:$src1))>;
822
823// Negative fused multiply-add and multiply-subtract.
824def any_fnma : PatFrag<(ops node:$src1, node:$src2, node:$src3),
825                       (fneg (any_fma node:$src1, node:$src2, node:$src3))>;
826def any_fnms : PatFrag<(ops node:$src1, node:$src2, node:$src3),
827                       (fneg (any_fms node:$src1, node:$src2, node:$src3))>;
828
829// Floating-point negative absolute.
830def fnabs : PatFrag<(ops node:$ptr), (fneg (fabs node:$ptr))>;
831
832// Floating-point operations which will not participate in reassociation, and
833// therefore are candidates for reg/mem folding during isel.
834def z_any_fadd_noreassoc : PatFrag<(ops node:$src1, node:$src2),
835                                   (any_fadd node:$src1, node:$src2),
836                                   [{ return !shouldSelectForReassoc(N); }]>;
837def z_any_fsub_noreassoc : PatFrag<(ops node:$src1, node:$src2),
838                                   (any_fsub node:$src1, node:$src2),
839                                   [{ return !shouldSelectForReassoc(N); }]>;
840def z_any_fmul_noreassoc : PatFrag<(ops node:$src1, node:$src2),
841                                   (any_fmul node:$src1, node:$src2),
842                                   [{ return !shouldSelectForReassoc(N); }]>;
843
844// Strict floating-point fragments.
845def z_any_fcmp    : PatFrags<(ops node:$lhs, node:$rhs),
846                             [(z_strict_fcmp node:$lhs, node:$rhs),
847                              (z_fcmp node:$lhs, node:$rhs)]>;
848def z_any_vfcmpe  : PatFrags<(ops node:$lhs, node:$rhs),
849                             [(z_strict_vfcmpe node:$lhs, node:$rhs),
850                              (z_vfcmpe node:$lhs, node:$rhs)]>;
851def z_any_vfcmph  : PatFrags<(ops node:$lhs, node:$rhs),
852                             [(z_strict_vfcmph node:$lhs, node:$rhs),
853                              (z_vfcmph node:$lhs, node:$rhs)]>;
854def z_any_vfcmphe : PatFrags<(ops node:$lhs, node:$rhs),
855                             [(z_strict_vfcmphe node:$lhs, node:$rhs),
856                              (z_vfcmphe node:$lhs, node:$rhs)]>;
857def z_any_vextend : PatFrags<(ops node:$src),
858                             [(z_strict_vextend node:$src),
859                              (z_vextend node:$src)]>;
860def z_any_vround  : PatFrags<(ops node:$src),
861                             [(z_strict_vround node:$src),
862                              (z_vround node:$src)]>;
863
864// Create a unary operator that loads from memory and then performs
865// the given operation on it.
866class loadu<SDPatternOperator operator, SDPatternOperator load = z_load>
867  : PatFrag<(ops node:$addr), (operator (load node:$addr))>;
868
869// Create a store operator that performs the given unary operation
870// on the value before storing it.
871class storeu<SDPatternOperator operator, SDPatternOperator store = store>
872  : PatFrag<(ops node:$value, node:$addr),
873            (store (operator node:$value), node:$addr)>;
874
875// Create a store operator that performs the given inherent operation
876// and stores the resulting value.
877class storei<SDPatternOperator operator, SDPatternOperator store = store>
878  : PatFrag<(ops node:$addr),
879            (store (operator), node:$addr)>;
880
881// Create a shift operator that optionally ignores an AND of the
882// shift count with an immediate if the bottom 6 bits are all set.
883def imm32bottom6set : PatLeaf<(i32 imm), [{
884  return (N->getZExtValue() & 0x3f) == 0x3f;
885}]>;
886class shiftop<SDPatternOperator operator>
887  : PatFrags<(ops node:$val, node:$count),
888             [(operator node:$val, node:$count),
889              (operator node:$val, (and node:$count, imm32bottom6set))]>;
890
891// Create a shift operator that optionally ignores an AND of the
892// shift count with an immediate if the bottom 7 bits are all set.
893def imm32bottom7set : PatLeaf<(i32 imm), [{
894  return (N->getZExtValue() & 0x7f) == 0x7f;
895}]>;
896class vshiftop<SDPatternOperator operator>
897  : PatFrags<(ops node:$val, node:$count),
898             [(operator node:$val, node:$count),
899              (operator node:$val, (and node:$count, imm32bottom7set))]>;
900
901def imm32mod64  : PatLeaf<(i32 imm), [{
902  return (N->getZExtValue() % 64 == 0);
903}]>;
904
905def imm32nobits : PatLeaf<(i32 imm), [{
906  return (N->getZExtValue() & 0x07) == 0;
907}]>;
908def imm32nobytes : PatLeaf<(i32 imm), [{
909  return (N->getZExtValue() & 0x78) == 0;
910}]>;
911
912// Load a scalar and replicate it in all elements of a vector.
913class z_replicate_load<ValueType scalartype, SDPatternOperator load>
914  : PatFrag<(ops node:$addr),
915            (z_replicate (scalartype (load node:$addr)))>;
916def z_replicate_loadi8  : z_replicate_load<i32, z_anyextloadi8>;
917def z_replicate_loadi16 : z_replicate_load<i32, z_anyextloadi16>;
918def z_replicate_loadi32 : z_replicate_load<i32, z_load>;
919def z_replicate_loadi64 : z_replicate_load<i64, z_load>;
920def z_replicate_loadf32 : z_replicate_load<f32, z_load>;
921def z_replicate_loadf64 : z_replicate_load<f64, z_load>;
922// Byte-swapped replicated vector element loads.
923def z_replicate_loadbswapi16 : z_replicate_load<i32, z_loadbswap16>;
924def z_replicate_loadbswapi32 : z_replicate_load<i32, z_loadbswap32>;
925def z_replicate_loadbswapi64 : z_replicate_load<i64, z_loadbswap64>;
926
927// Load a scalar and insert it into a single element of a vector.
928class z_vle<ValueType scalartype, SDPatternOperator load>
929  : PatFrag<(ops node:$vec, node:$addr, node:$index),
930            (z_vector_insert node:$vec, (scalartype (load node:$addr)),
931                             node:$index)>;
932def z_vlei8  : z_vle<i32, z_anyextloadi8>;
933def z_vlei16 : z_vle<i32, z_anyextloadi16>;
934def z_vlei32 : z_vle<i32, z_load>;
935def z_vlei64 : z_vle<i64, z_load>;
936def z_vlef32 : z_vle<f32, z_load>;
937def z_vlef64 : z_vle<f64, z_load>;
938// Byte-swapped vector element loads.
939def z_vlebri16 : z_vle<i32, z_loadbswap16>;
940def z_vlebri32 : z_vle<i32, z_loadbswap32>;
941def z_vlebri64 : z_vle<i64, z_loadbswap64>;
942
943// Load a scalar and insert it into the low element of the high i64 of a
944// zeroed vector.
945class z_vllez<ValueType scalartype, SDPatternOperator load, int index>
946  : PatFrag<(ops node:$addr),
947            (z_vector_insert immAllZerosV,
948                             (scalartype (load node:$addr)), (i32 index))>;
949def z_vllezi8  : z_vllez<i32, z_anyextloadi8, 7>;
950def z_vllezi16 : z_vllez<i32, z_anyextloadi16, 3>;
951def z_vllezi32 : z_vllez<i32, z_load, 1>;
952def z_vllezi64 : PatFrags<(ops node:$addr),
953                          [(z_vector_insert immAllZerosV,
954                                            (i64 (z_load node:$addr)), (i32 0)),
955                           (z_join_dwords (i64 (z_load node:$addr)), (i64 0))]>;
956// We use high merges to form a v4f32 from four f32s.  Propagating zero
957// into all elements but index 1 gives this expression.
958def z_vllezf32 : PatFrag<(ops node:$addr),
959                         (z_merge_high
960                          (v2i64
961                           (z_unpackl_high
962                            (v4i32
963                             (bitconvert
964                              (v4f32 (scalar_to_vector
965                                      (f32 (z_load node:$addr)))))))),
966                          (v2i64
967                           (bitconvert (v4f32 immAllZerosV))))>;
968def z_vllezf64 : PatFrag<(ops node:$addr),
969                         (z_merge_high
970                          (v2f64 (scalar_to_vector (f64 (z_load node:$addr)))),
971                          immAllZerosV)>;
972
973// Similarly for the high element of a zeroed vector.
974def z_vllezli32 : z_vllez<i32, z_load, 0>;
975def z_vllezlf32 : PatFrag<(ops node:$addr),
976                          (z_merge_high
977                           (v2i64
978                            (bitconvert
979                             (z_merge_high
980                              (v4f32 (scalar_to_vector
981                                      (f32 (z_load node:$addr)))),
982                              (v4f32 immAllZerosV)))),
983                           (v2i64
984                            (bitconvert (v4f32 immAllZerosV))))>;
985
986// Byte-swapped variants.
987def z_vllebrzi16  : z_vllez<i32, z_loadbswap16, 3>;
988def z_vllebrzi32  : z_vllez<i32, z_loadbswap32, 1>;
989def z_vllebrzli32 : z_vllez<i32, z_loadbswap32, 0>;
990def z_vllebrzi64  : PatFrags<(ops node:$addr),
991                             [(z_vector_insert immAllZerosV,
992                                               (i64 (z_loadbswap64 node:$addr)),
993                                               (i32 0)),
994                              (z_join_dwords (i64 (z_loadbswap64 node:$addr)),
995                                             (i64 0))]>;
996
997
998// Store one element of a vector.
999class z_vste<ValueType scalartype, SDPatternOperator store>
1000  : PatFrag<(ops node:$vec, node:$addr, node:$index),
1001            (store (scalartype (z_vector_extract node:$vec, node:$index)),
1002                   node:$addr)>;
1003def z_vstei8  : z_vste<i32, truncstorei8>;
1004def z_vstei16 : z_vste<i32, truncstorei16>;
1005def z_vstei32 : z_vste<i32, store>;
1006def z_vstei64 : z_vste<i64, store>;
1007def z_vstef32 : z_vste<f32, store>;
1008def z_vstef64 : z_vste<f64, store>;
1009// Byte-swapped vector element stores.
1010def z_vstebri16 : z_vste<i32, z_storebswap16>;
1011def z_vstebri32 : z_vste<i32, z_storebswap32>;
1012def z_vstebri64 : z_vste<i64, z_storebswap64>;
1013
1014// Arithmetic negation on vectors.
1015def z_vneg : PatFrag<(ops node:$x), (sub immAllZerosV, node:$x)>;
1016
1017// Bitwise negation on vectors.
1018def z_vnot : PatFrag<(ops node:$x), (xor node:$x, immAllOnesV)>;
1019
1020// Signed "integer greater than zero" on vectors.
1021def z_vicmph_zero : PatFrag<(ops node:$x), (z_vicmph node:$x, immAllZerosV)>;
1022
1023// Signed "integer less than zero" on vectors.
1024def z_vicmpl_zero : PatFrag<(ops node:$x), (z_vicmph immAllZerosV, node:$x)>;
1025
1026// Sign-extend the i64 elements of a vector.
1027class z_vse<int shift>
1028  : PatFrag<(ops node:$src),
1029            (z_vsra_by_scalar (z_vshl_by_scalar node:$src, shift), shift)>;
1030def z_vsei8  : z_vse<56>;
1031def z_vsei16 : z_vse<48>;
1032def z_vsei32 : z_vse<32>;
1033
1034// ...and again with the extensions being done on individual i64 scalars.
1035class z_vse_by_parts<SDPatternOperator operator, int index1, int index2>
1036  : PatFrag<(ops node:$src),
1037            (z_join_dwords
1038             (operator (z_vector_extract node:$src, index1)),
1039             (operator (z_vector_extract node:$src, index2)))>;
1040def z_vsei8_by_parts  : z_vse_by_parts<sext8dbl, 7, 15>;
1041def z_vsei16_by_parts : z_vse_by_parts<sext16dbl, 3, 7>;
1042def z_vsei32_by_parts : z_vse_by_parts<sext32, 1, 3>;
1043