1//===- TargetSelectionDAG.td - Common code for DAG isels ---*- tablegen -*-===//
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 defines the target-independent interfaces used by SelectionDAG
10// instruction selection generators.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
15// Selection DAG Type Constraint definitions.
16//
17// Note that the semantics of these constraints are hard coded into tblgen.  To
18// modify or add constraints, you have to hack tblgen.
19//
20
21class SDTypeConstraint<int opnum> {
22  int OperandNum = opnum;
23}
24
25// SDTCisVT - The specified operand has exactly this VT.
26class SDTCisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
27  ValueType VT = vt;
28}
29
30class SDTCisPtrTy<int OpNum> : SDTypeConstraint<OpNum>;
31
32// SDTCisInt - The specified operand has integer type.
33class SDTCisInt<int OpNum> : SDTypeConstraint<OpNum>;
34
35// SDTCisFP - The specified operand has floating-point type.
36class SDTCisFP<int OpNum> : SDTypeConstraint<OpNum>;
37
38// SDTCisVec - The specified operand has a vector type.
39class SDTCisVec<int OpNum> : SDTypeConstraint<OpNum>;
40
41// SDTCisSameAs - The two specified operands have identical types.
42class SDTCisSameAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
43  int OtherOperandNum = OtherOp;
44}
45
46// SDTCisVTSmallerThanOp - The specified operand is a VT SDNode, and its type is
47// smaller than the 'Other' operand.
48class SDTCisVTSmallerThanOp<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
49  int OtherOperandNum = OtherOp;
50}
51
52class SDTCisOpSmallerThanOp<int SmallOp, int BigOp> : SDTypeConstraint<SmallOp>{
53  int BigOperandNum = BigOp;
54}
55
56/// SDTCisEltOfVec - This indicates that ThisOp is a scalar type of the same
57/// type as the element type of OtherOp, which is a vector type.
58class SDTCisEltOfVec<int ThisOp, int OtherOp>
59  : SDTypeConstraint<ThisOp> {
60  int OtherOpNum = OtherOp;
61}
62
63/// SDTCisSubVecOfVec - This indicates that ThisOp is a vector type
64/// with length less that of OtherOp, which is a vector type.
65class SDTCisSubVecOfVec<int ThisOp, int OtherOp>
66  : SDTypeConstraint<ThisOp> {
67  int OtherOpNum = OtherOp;
68}
69
70// SDTCVecEltisVT - The specified operand is vector type with element type
71// of VT.
72class SDTCVecEltisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
73  ValueType VT = vt;
74}
75
76// SDTCisSameNumEltsAs - The two specified operands have identical number
77// of elements.
78class SDTCisSameNumEltsAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
79  int OtherOperandNum = OtherOp;
80}
81
82// SDTCisSameSizeAs - The two specified operands have identical size.
83class SDTCisSameSizeAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
84  int OtherOperandNum = OtherOp;
85}
86
87//===----------------------------------------------------------------------===//
88// Selection DAG Type Profile definitions.
89//
90// These use the constraints defined above to describe the type requirements of
91// the various nodes.  These are not hard coded into tblgen, allowing targets to
92// add their own if needed.
93//
94
95// SDTypeProfile - This profile describes the type requirements of a Selection
96// DAG node.
97class SDTypeProfile<int numresults, int numoperands,
98                    list<SDTypeConstraint> constraints> {
99  int NumResults = numresults;
100  int NumOperands = numoperands;
101  list<SDTypeConstraint> Constraints = constraints;
102}
103
104// Builtin profiles.
105def SDTIntLeaf: SDTypeProfile<1, 0, [SDTCisInt<0>]>;         // for 'imm'.
106def SDTFPLeaf : SDTypeProfile<1, 0, [SDTCisFP<0>]>;          // for 'fpimm'.
107def SDTPtrLeaf: SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;       // for '&g'.
108def SDTOther  : SDTypeProfile<1, 0, [SDTCisVT<0, OtherVT>]>; // for 'vt'.
109def SDTUNDEF  : SDTypeProfile<1, 0, []>;                     // for 'undef'.
110def SDTUnaryOp  : SDTypeProfile<1, 1, []>;                   // for bitconvert.
111
112def SDTPtrAddOp : SDTypeProfile<1, 2, [     // ptradd
113  SDTCisSameAs<0, 1>, SDTCisInt<2>, SDTCisPtrTy<1>
114]>;
115def SDTIntBinOp : SDTypeProfile<1, 2, [     // add, and, or, xor, udiv, etc.
116  SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>
117]>;
118def SDTIntShiftOp : SDTypeProfile<1, 2, [   // shl, sra, srl
119  SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<2>
120]>;
121def SDTIntShiftDOp: SDTypeProfile<1, 3, [   // fshl, fshr
122  SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>, SDTCisInt<3>
123]>;
124def SDTIntSatNoShOp : SDTypeProfile<1, 2, [   // ssat with no shift
125  SDTCisSameAs<0, 1>, SDTCisInt<2>
126]>;
127def SDTIntBinHiLoOp : SDTypeProfile<2, 2, [ // mulhi, mullo, sdivrem, udivrem
128  SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>,SDTCisInt<0>
129]>;
130def SDTIntScaledBinOp : SDTypeProfile<1, 3, [  // smulfix, sdivfix, etc
131  SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>, SDTCisInt<3>
132]>;
133
134def SDTFPBinOp : SDTypeProfile<1, 2, [      // fadd, fmul, etc.
135  SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisFP<0>
136]>;
137def SDTFPSignOp : SDTypeProfile<1, 2, [     // fcopysign.
138  SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisFP<2>
139]>;
140def SDTFPTernaryOp : SDTypeProfile<1, 3, [  // fmadd, fnmsub, etc.
141  SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisFP<0>
142]>;
143def SDTIntUnaryOp : SDTypeProfile<1, 1, [ // bitreverse
144  SDTCisSameAs<0, 1>, SDTCisInt<0>
145]>;
146def SDTIntBitCountUnaryOp : SDTypeProfile<1, 1, [   // ctlz, cttz
147  SDTCisInt<0>, SDTCisInt<1>
148]>;
149def SDTIntExtendOp : SDTypeProfile<1, 1, [  // sext, zext, anyext
150  SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<1, 0>, SDTCisSameNumEltsAs<0, 1>
151]>;
152def SDTIntTruncOp  : SDTypeProfile<1, 1, [  // trunc
153  SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<0, 1>, SDTCisSameNumEltsAs<0, 1>
154]>;
155def SDTFPUnaryOp  : SDTypeProfile<1, 1, [   // fneg, fsqrt, etc
156  SDTCisSameAs<0, 1>, SDTCisFP<0>
157]>;
158def SDTFPRoundOp  : SDTypeProfile<1, 1, [   // fpround
159  SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<0, 1>, SDTCisSameNumEltsAs<0, 1>
160]>;
161def SDTFPExtendOp  : SDTypeProfile<1, 1, [  // fpextend
162  SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<1, 0>, SDTCisSameNumEltsAs<0, 1>
163]>;
164def SDIsFPClassOp : SDTypeProfile<1, 2, [   // is_fpclass
165  SDTCisInt<0>, SDTCisFP<1>, SDTCisInt<2>, SDTCisSameNumEltsAs<0, 1>
166]>;
167def SDTIntToFPOp : SDTypeProfile<1, 1, [    // [su]int_to_fp
168  SDTCisFP<0>, SDTCisInt<1>, SDTCisSameNumEltsAs<0, 1>
169]>;
170def SDTFPToIntOp : SDTypeProfile<1, 1, [    // fp_to_[su]int
171  SDTCisInt<0>, SDTCisFP<1>, SDTCisSameNumEltsAs<0, 1>
172]>;
173def SDTFPToIntSatOp : SDTypeProfile<1, 2, [    // fp_to_[su]int_sat
174  SDTCisInt<0>, SDTCisFP<1>, SDTCisSameNumEltsAs<0, 1>, SDTCisVT<2, OtherVT>
175]>;
176def SDTFPExpOp : SDTypeProfile<1, 2, [      // ldexp
177  SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisInt<2>
178]>;
179def SDTGetFPStateOp : SDTypeProfile<1, 0, [ // get_fpenv, get_fpmode
180  SDTCisInt<0>
181]>;
182def SDTSetFPStateOp : SDTypeProfile<0, 1, [ // set_fpenv, set_fpmode
183  SDTCisInt<0>
184]>;
185def SDTExtInreg : SDTypeProfile<1, 2, [     // sext_inreg
186  SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisVT<2, OtherVT>,
187  SDTCisVTSmallerThanOp<2, 1>
188]>;
189def SDTExtInvec : SDTypeProfile<1, 1, [     // sext_invec
190  SDTCisInt<0>, SDTCisVec<0>, SDTCisInt<1>, SDTCisVec<1>,
191  SDTCisOpSmallerThanOp<1, 0>
192]>;
193def SDTFreeze : SDTypeProfile<1, 1, [
194  SDTCisSameAs<0, 1>
195]>;
196
197def SDTSetCC : SDTypeProfile<1, 3, [        // setcc
198  SDTCisInt<0>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
199]>;
200
201def SDTSelect : SDTypeProfile<1, 3, [       // select
202  SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
203]>;
204
205def SDTVSelect : SDTypeProfile<1, 3, [       // vselect
206  SDTCisVec<0>, SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>, SDTCisSameNumEltsAs<0, 1>
207]>;
208
209def SDTSelectCC : SDTypeProfile<1, 5, [     // select_cc
210  SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>, SDTCisSameAs<0, 3>,
211  SDTCisVT<5, OtherVT>
212]>;
213
214def SDTBr : SDTypeProfile<0, 1, [           // br
215  SDTCisVT<0, OtherVT>
216]>;
217
218def SDTBrCC : SDTypeProfile<0, 4, [       // brcc
219  SDTCisVT<0, OtherVT>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
220]>;
221
222def SDTBrcond : SDTypeProfile<0, 2, [       // brcond
223  SDTCisInt<0>, SDTCisVT<1, OtherVT>
224]>;
225
226def SDTBrind : SDTypeProfile<0, 1, [        // brind
227  SDTCisPtrTy<0>
228]>;
229
230def SDTCatchret : SDTypeProfile<0, 2, [     // catchret
231  SDTCisVT<0, OtherVT>, SDTCisVT<1, OtherVT>
232]>;
233
234def SDTNone : SDTypeProfile<0, 0, []>;      // ret, trap
235
236def SDTUBSANTrap : SDTypeProfile<0, 1, []>;      // ubsantrap
237
238def SDTLoad : SDTypeProfile<1, 1, [         // load
239  SDTCisPtrTy<1>
240]>;
241
242def SDTStore : SDTypeProfile<0, 2, [        // store
243  SDTCisPtrTy<1>
244]>;
245
246def SDTIStore : SDTypeProfile<1, 3, [       // indexed store
247  SDTCisSameAs<0, 2>, SDTCisPtrTy<0>, SDTCisPtrTy<3>
248]>;
249
250def SDTMaskedStore: SDTypeProfile<0, 4, [       // masked store
251  SDTCisVec<0>, SDTCisPtrTy<1>, SDTCisPtrTy<2>, SDTCisVec<3>, SDTCisSameNumEltsAs<0, 3>
252]>;
253
254def SDTMaskedLoad: SDTypeProfile<1, 4, [       // masked load
255  SDTCisVec<0>, SDTCisPtrTy<1>, SDTCisPtrTy<2>, SDTCisVec<3>, SDTCisSameAs<0, 4>,
256  SDTCisSameNumEltsAs<0, 3>
257]>;
258
259def SDTMaskedGather : SDTypeProfile<1, 4, [
260  SDTCisVec<0>, SDTCisSameAs<0, 1>, SDTCisVec<2>, SDTCisPtrTy<3>, SDTCisVec<4>,
261  SDTCisSameNumEltsAs<0, 2>, SDTCisSameNumEltsAs<0, 4>
262]>;
263
264def SDTMaskedScatter : SDTypeProfile<0, 4, [
265  SDTCisVec<0>, SDTCisVec<1>, SDTCisPtrTy<2>, SDTCisVec<3>,
266  SDTCisSameNumEltsAs<0, 1>, SDTCisSameNumEltsAs<0, 3>
267]>;
268
269def SDTVecShuffle : SDTypeProfile<1, 2, [
270  SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>
271]>;
272def SDTVecSlice : SDTypeProfile<1, 3, [     // vector splice
273  SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisInt<3>
274]>;
275def SDTVecExtract : SDTypeProfile<1, 2, [   // vector extract
276  SDTCisEltOfVec<0, 1>, SDTCisPtrTy<2>
277]>;
278def SDTVecInsert : SDTypeProfile<1, 3, [    // vector insert
279  SDTCisEltOfVec<2, 1>, SDTCisSameAs<0, 1>, SDTCisPtrTy<3>
280]>;
281def SDTVecReduce : SDTypeProfile<1, 1, [    // vector reduction
282  SDTCisInt<0>, SDTCisVec<1>
283]>;
284def SDTFPVecReduce : SDTypeProfile<1, 1, [  // FP vector reduction
285  SDTCisFP<0>, SDTCisVec<1>
286]>;
287
288def SDTVecReverse : SDTypeProfile<1, 1, [  // vector reverse
289  SDTCisVec<0>, SDTCisSameAs<0,1>
290]>;
291
292def SDTSubVecExtract : SDTypeProfile<1, 2, [// subvector extract
293  SDTCisSubVecOfVec<0,1>, SDTCisInt<2>
294]>;
295def SDTSubVecInsert : SDTypeProfile<1, 3, [ // subvector insert
296  SDTCisSubVecOfVec<2, 1>, SDTCisSameAs<0,1>, SDTCisInt<3>
297]>;
298
299def SDTPrefetch : SDTypeProfile<0, 4, [     // prefetch
300  SDTCisPtrTy<0>, SDTCisSameAs<1, 2>, SDTCisSameAs<1, 3>, SDTCisInt<1>
301]>;
302
303def SDTAtomicFence : SDTypeProfile<0, 2, [
304  SDTCisSameAs<0,1>, SDTCisPtrTy<0>
305]>;
306def SDTAtomic3 : SDTypeProfile<1, 3, [
307  SDTCisSameAs<0,2>,  SDTCisSameAs<0,3>, SDTCisInt<0>, SDTCisPtrTy<1>
308]>;
309def SDTAtomic2 : SDTypeProfile<1, 2, [
310  SDTCisSameAs<0,2>, SDTCisInt<0>, SDTCisPtrTy<1>
311]>;
312
313def SDTFPAtomic2 : SDTypeProfile<1, 2, [
314  SDTCisSameAs<0,2>, SDTCisFP<0>, SDTCisPtrTy<1>
315]>;
316
317def SDTAtomicStore : SDTypeProfile<0, 2, [
318  SDTCisInt<0>, SDTCisPtrTy<1>
319]>;
320def SDTAtomicLoad : SDTypeProfile<1, 1, [
321  SDTCisInt<0>, SDTCisPtrTy<1>
322]>;
323
324class SDCallSeqStart<list<SDTypeConstraint> constraints> :
325        SDTypeProfile<0, 2, constraints>;
326class SDCallSeqEnd<list<SDTypeConstraint> constraints> :
327        SDTypeProfile<0, 2, constraints>;
328
329//===----------------------------------------------------------------------===//
330// Selection DAG Node definitions.
331//
332class SDNode<string opcode, SDTypeProfile typeprof,
333             list<SDNodeProperty> props = [], string sdclass = "SDNode">
334             : SDPatternOperator {
335  string Opcode  = opcode;
336  string SDClass = sdclass;
337  let Properties = props;
338  SDTypeProfile TypeProfile = typeprof;
339}
340
341// Special TableGen-recognized dag nodes
342def set;
343def implicit;
344def node;
345def srcvalue;
346
347def imm        : SDNode<"ISD::Constant"  , SDTIntLeaf , [], "ConstantSDNode">;
348def timm       : SDNode<"ISD::TargetConstant",SDTIntLeaf, [], "ConstantSDNode">;
349def fpimm      : SDNode<"ISD::ConstantFP", SDTFPLeaf  , [], "ConstantFPSDNode">;
350def vt         : SDNode<"ISD::VALUETYPE" , SDTOther   , [], "VTSDNode">;
351def bb         : SDNode<"ISD::BasicBlock", SDTOther   , [], "BasicBlockSDNode">;
352def cond       : SDNode<"ISD::CONDCODE"  , SDTOther   , [], "CondCodeSDNode">;
353def undef      : SDNode<"ISD::UNDEF"     , SDTUNDEF   , []>;
354def vscale     : SDNode<"ISD::VSCALE"    , SDTIntUnaryOp, []>;
355def globaladdr : SDNode<"ISD::GlobalAddress",         SDTPtrLeaf, [],
356                        "GlobalAddressSDNode">;
357def tglobaladdr : SDNode<"ISD::TargetGlobalAddress",  SDTPtrLeaf, [],
358                         "GlobalAddressSDNode">;
359def globaltlsaddr : SDNode<"ISD::GlobalTLSAddress",         SDTPtrLeaf, [],
360                          "GlobalAddressSDNode">;
361def tglobaltlsaddr : SDNode<"ISD::TargetGlobalTLSAddress",  SDTPtrLeaf, [],
362                           "GlobalAddressSDNode">;
363def constpool   : SDNode<"ISD::ConstantPool",         SDTPtrLeaf, [],
364                         "ConstantPoolSDNode">;
365def tconstpool  : SDNode<"ISD::TargetConstantPool",   SDTPtrLeaf, [],
366                         "ConstantPoolSDNode">;
367def jumptable   : SDNode<"ISD::JumpTable",            SDTPtrLeaf, [],
368                         "JumpTableSDNode">;
369def tjumptable  : SDNode<"ISD::TargetJumpTable",      SDTPtrLeaf, [],
370                         "JumpTableSDNode">;
371def frameindex  : SDNode<"ISD::FrameIndex",           SDTPtrLeaf, [],
372                         "FrameIndexSDNode">;
373def tframeindex : SDNode<"ISD::TargetFrameIndex",     SDTPtrLeaf, [],
374                         "FrameIndexSDNode">;
375def externalsym : SDNode<"ISD::ExternalSymbol",       SDTPtrLeaf, [],
376                         "ExternalSymbolSDNode">;
377def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
378                         "ExternalSymbolSDNode">;
379def mcsym: SDNode<"ISD::MCSymbol", SDTPtrLeaf, [], "MCSymbolSDNode">;
380def blockaddress : SDNode<"ISD::BlockAddress",        SDTPtrLeaf, [],
381                         "BlockAddressSDNode">;
382def tblockaddress: SDNode<"ISD::TargetBlockAddress",  SDTPtrLeaf, [],
383                         "BlockAddressSDNode">;
384
385def add        : SDNode<"ISD::ADD"       , SDTIntBinOp   ,
386                        [SDNPCommutative, SDNPAssociative]>;
387def ptradd     : SDNode<"ISD::ADD"       , SDTPtrAddOp, []>;
388def sub        : SDNode<"ISD::SUB"       , SDTIntBinOp>;
389def mul        : SDNode<"ISD::MUL"       , SDTIntBinOp,
390                        [SDNPCommutative, SDNPAssociative]>;
391def mulhs      : SDNode<"ISD::MULHS"     , SDTIntBinOp, [SDNPCommutative]>;
392def mulhu      : SDNode<"ISD::MULHU"     , SDTIntBinOp, [SDNPCommutative]>;
393def avgfloors  : SDNode<"ISD::AVGFLOORS" , SDTIntBinOp, [SDNPCommutative]>;
394def avgflooru  : SDNode<"ISD::AVGFLOORU" , SDTIntBinOp, [SDNPCommutative]>;
395def avgceils   : SDNode<"ISD::AVGCEILS"  , SDTIntBinOp, [SDNPCommutative]>;
396def avgceilu   : SDNode<"ISD::AVGCEILU"  , SDTIntBinOp, [SDNPCommutative]>;
397def abds       : SDNode<"ISD::ABDS"      , SDTIntBinOp, [SDNPCommutative]>;
398def abdu       : SDNode<"ISD::ABDU"      , SDTIntBinOp, [SDNPCommutative]>;
399def smullohi   : SDNode<"ISD::SMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
400def umullohi   : SDNode<"ISD::UMUL_LOHI" , SDTIntBinHiLoOp, [SDNPCommutative]>;
401def sdiv       : SDNode<"ISD::SDIV"      , SDTIntBinOp>;
402def udiv       : SDNode<"ISD::UDIV"      , SDTIntBinOp>;
403def srem       : SDNode<"ISD::SREM"      , SDTIntBinOp>;
404def urem       : SDNode<"ISD::UREM"      , SDTIntBinOp>;
405def sdivrem    : SDNode<"ISD::SDIVREM"   , SDTIntBinHiLoOp>;
406def udivrem    : SDNode<"ISD::UDIVREM"   , SDTIntBinHiLoOp>;
407def srl        : SDNode<"ISD::SRL"       , SDTIntShiftOp>;
408def sra        : SDNode<"ISD::SRA"       , SDTIntShiftOp>;
409def shl        : SDNode<"ISD::SHL"       , SDTIntShiftOp>;
410def rotl       : SDNode<"ISD::ROTL"      , SDTIntShiftOp>;
411def rotr       : SDNode<"ISD::ROTR"      , SDTIntShiftOp>;
412def fshl       : SDNode<"ISD::FSHL"      , SDTIntShiftDOp>;
413def fshr       : SDNode<"ISD::FSHR"      , SDTIntShiftDOp>;
414def and        : SDNode<"ISD::AND"       , SDTIntBinOp,
415                        [SDNPCommutative, SDNPAssociative]>;
416def or         : SDNode<"ISD::OR"        , SDTIntBinOp,
417                        [SDNPCommutative, SDNPAssociative]>;
418def xor        : SDNode<"ISD::XOR"       , SDTIntBinOp,
419                        [SDNPCommutative, SDNPAssociative]>;
420def addc       : SDNode<"ISD::ADDC"      , SDTIntBinOp,
421                        [SDNPCommutative, SDNPOutGlue]>;
422def adde       : SDNode<"ISD::ADDE"      , SDTIntBinOp,
423                        [SDNPCommutative, SDNPOutGlue, SDNPInGlue]>;
424def subc       : SDNode<"ISD::SUBC"      , SDTIntBinOp,
425                        [SDNPOutGlue]>;
426def sube       : SDNode<"ISD::SUBE"      , SDTIntBinOp,
427                        [SDNPOutGlue, SDNPInGlue]>;
428def smin       : SDNode<"ISD::SMIN"      , SDTIntBinOp,
429                                  [SDNPCommutative, SDNPAssociative]>;
430def smax       : SDNode<"ISD::SMAX"      , SDTIntBinOp,
431                                  [SDNPCommutative, SDNPAssociative]>;
432def umin       : SDNode<"ISD::UMIN"      , SDTIntBinOp,
433                                  [SDNPCommutative, SDNPAssociative]>;
434def umax       : SDNode<"ISD::UMAX"      , SDTIntBinOp,
435                                  [SDNPCommutative, SDNPAssociative]>;
436
437def saddsat    : SDNode<"ISD::SADDSAT"   , SDTIntBinOp, [SDNPCommutative]>;
438def uaddsat    : SDNode<"ISD::UADDSAT"   , SDTIntBinOp, [SDNPCommutative]>;
439def ssubsat    : SDNode<"ISD::SSUBSAT"   , SDTIntBinOp>;
440def usubsat    : SDNode<"ISD::USUBSAT"   , SDTIntBinOp>;
441def sshlsat    : SDNode<"ISD::SSHLSAT"   , SDTIntBinOp>;
442def ushlsat    : SDNode<"ISD::USHLSAT"   , SDTIntBinOp>;
443
444def smulfix    : SDNode<"ISD::SMULFIX"   , SDTIntScaledBinOp, [SDNPCommutative]>;
445def smulfixsat : SDNode<"ISD::SMULFIXSAT", SDTIntScaledBinOp, [SDNPCommutative]>;
446def umulfix    : SDNode<"ISD::UMULFIX"   , SDTIntScaledBinOp, [SDNPCommutative]>;
447def umulfixsat : SDNode<"ISD::UMULFIXSAT", SDTIntScaledBinOp, [SDNPCommutative]>;
448def sdivfix    : SDNode<"ISD::SDIVFIX"   , SDTIntScaledBinOp>;
449def sdivfixsat : SDNode<"ISD::SDIVFIXSAT", SDTIntScaledBinOp>;
450def udivfix    : SDNode<"ISD::UDIVFIX"   , SDTIntScaledBinOp>;
451def udivfixsat : SDNode<"ISD::UDIVFIXSAT", SDTIntScaledBinOp>;
452
453def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
454def sext_invec : SDNode<"ISD::SIGN_EXTEND_VECTOR_INREG", SDTExtInvec>;
455def zext_invec : SDNode<"ISD::ZERO_EXTEND_VECTOR_INREG", SDTExtInvec>;
456
457def abs        : SDNode<"ISD::ABS"        , SDTIntUnaryOp>;
458def bitreverse : SDNode<"ISD::BITREVERSE" , SDTIntUnaryOp>;
459def bswap      : SDNode<"ISD::BSWAP"      , SDTIntUnaryOp>;
460def ctlz       : SDNode<"ISD::CTLZ"       , SDTIntBitCountUnaryOp>;
461def cttz       : SDNode<"ISD::CTTZ"       , SDTIntBitCountUnaryOp>;
462def ctpop      : SDNode<"ISD::CTPOP"      , SDTIntBitCountUnaryOp>;
463def ctlz_zero_undef : SDNode<"ISD::CTLZ_ZERO_UNDEF", SDTIntBitCountUnaryOp>;
464def cttz_zero_undef : SDNode<"ISD::CTTZ_ZERO_UNDEF", SDTIntBitCountUnaryOp>;
465def sext       : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
466def zext       : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
467def anyext     : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
468def trunc      : SDNode<"ISD::TRUNCATE"   , SDTIntTruncOp>;
469def bitconvert : SDNode<"ISD::BITCAST"    , SDTUnaryOp>;
470def addrspacecast : SDNode<"ISD::ADDRSPACECAST", SDTUnaryOp>;
471def freeze     : SDNode<"ISD::FREEZE"     , SDTFreeze>;
472def extractelt : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTVecExtract>;
473def insertelt  : SDNode<"ISD::INSERT_VECTOR_ELT", SDTVecInsert>;
474
475def vecreduce_add  : SDNode<"ISD::VECREDUCE_ADD", SDTVecReduce>;
476def vecreduce_smax  : SDNode<"ISD::VECREDUCE_SMAX", SDTVecReduce>;
477def vecreduce_umax  : SDNode<"ISD::VECREDUCE_UMAX", SDTVecReduce>;
478def vecreduce_smin  : SDNode<"ISD::VECREDUCE_SMIN", SDTVecReduce>;
479def vecreduce_umin  : SDNode<"ISD::VECREDUCE_UMIN", SDTVecReduce>;
480def vecreduce_fadd  : SDNode<"ISD::VECREDUCE_FADD", SDTFPVecReduce>;
481def vecreduce_fmin  : SDNode<"ISD::VECREDUCE_FMIN", SDTFPVecReduce>;
482def vecreduce_fmax  : SDNode<"ISD::VECREDUCE_FMAX", SDTFPVecReduce>;
483def vecreduce_fminimum : SDNode<"ISD::VECREDUCE_FMINIMUM", SDTFPVecReduce>;
484def vecreduce_fmaximum : SDNode<"ISD::VECREDUCE_FMAXIMUM", SDTFPVecReduce>;
485
486def fadd       : SDNode<"ISD::FADD"       , SDTFPBinOp, [SDNPCommutative]>;
487def fsub       : SDNode<"ISD::FSUB"       , SDTFPBinOp>;
488def fmul       : SDNode<"ISD::FMUL"       , SDTFPBinOp, [SDNPCommutative]>;
489def fdiv       : SDNode<"ISD::FDIV"       , SDTFPBinOp>;
490def frem       : SDNode<"ISD::FREM"       , SDTFPBinOp>;
491def fma        : SDNode<"ISD::FMA"        , SDTFPTernaryOp, [SDNPCommutative]>;
492def fmad       : SDNode<"ISD::FMAD"       , SDTFPTernaryOp, [SDNPCommutative]>;
493def fabs       : SDNode<"ISD::FABS"       , SDTFPUnaryOp>;
494def fminnum    : SDNode<"ISD::FMINNUM"    , SDTFPBinOp,
495                                  [SDNPCommutative, SDNPAssociative]>;
496def fmaxnum    : SDNode<"ISD::FMAXNUM"    , SDTFPBinOp,
497                                  [SDNPCommutative, SDNPAssociative]>;
498def fminnum_ieee : SDNode<"ISD::FMINNUM_IEEE", SDTFPBinOp,
499                          [SDNPCommutative]>;
500def fmaxnum_ieee  : SDNode<"ISD::FMAXNUM_IEEE", SDTFPBinOp,
501                           [SDNPCommutative]>;
502def fminimum   : SDNode<"ISD::FMINIMUM"   , SDTFPBinOp,
503                        [SDNPCommutative, SDNPAssociative]>;
504def fmaximum   : SDNode<"ISD::FMAXIMUM"   , SDTFPBinOp,
505                        [SDNPCommutative, SDNPAssociative]>;
506def fgetsign   : SDNode<"ISD::FGETSIGN"   , SDTFPToIntOp>;
507def fcanonicalize : SDNode<"ISD::FCANONICALIZE", SDTFPUnaryOp>;
508def fneg       : SDNode<"ISD::FNEG"       , SDTFPUnaryOp>;
509def fsqrt      : SDNode<"ISD::FSQRT"      , SDTFPUnaryOp>;
510def fsin       : SDNode<"ISD::FSIN"       , SDTFPUnaryOp>;
511def fcos       : SDNode<"ISD::FCOS"       , SDTFPUnaryOp>;
512def fexp2      : SDNode<"ISD::FEXP2"      , SDTFPUnaryOp>;
513def fexp10     : SDNode<"ISD::FEXP10"     , SDTFPUnaryOp>;
514def fpow       : SDNode<"ISD::FPOW"       , SDTFPBinOp>;
515def flog2      : SDNode<"ISD::FLOG2"      , SDTFPUnaryOp>;
516def fldexp     : SDNode<"ISD::FLDEXP"     , SDTFPExpOp>;
517def frint      : SDNode<"ISD::FRINT"      , SDTFPUnaryOp>;
518def ftrunc     : SDNode<"ISD::FTRUNC"     , SDTFPUnaryOp>;
519def fceil      : SDNode<"ISD::FCEIL"      , SDTFPUnaryOp>;
520def ffloor     : SDNode<"ISD::FFLOOR"     , SDTFPUnaryOp>;
521def fnearbyint : SDNode<"ISD::FNEARBYINT" , SDTFPUnaryOp>;
522def fround     : SDNode<"ISD::FROUND"     , SDTFPUnaryOp>;
523def froundeven : SDNode<"ISD::FROUNDEVEN" , SDTFPUnaryOp>;
524
525def lround     : SDNode<"ISD::LROUND"     , SDTFPToIntOp>;
526def llround    : SDNode<"ISD::LLROUND"    , SDTFPToIntOp>;
527def lrint      : SDNode<"ISD::LRINT"      , SDTFPToIntOp>;
528def llrint     : SDNode<"ISD::LLRINT"     , SDTFPToIntOp>;
529
530def fpround    : SDNode<"ISD::FP_ROUND"   , SDTFPRoundOp>;
531def fpextend   : SDNode<"ISD::FP_EXTEND"  , SDTFPExtendOp>;
532def fcopysign  : SDNode<"ISD::FCOPYSIGN"  , SDTFPSignOp>;
533
534def is_fpclass : SDNode<"ISD::IS_FPCLASS" , SDIsFPClassOp>;
535
536def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
537def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
538def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
539def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
540def fp_to_sint_sat : SDNode<"ISD::FP_TO_SINT_SAT" , SDTFPToIntSatOp>;
541def fp_to_uint_sat : SDNode<"ISD::FP_TO_UINT_SAT" , SDTFPToIntSatOp>;
542def f16_to_fp  : SDNode<"ISD::FP16_TO_FP" , SDTIntToFPOp>;
543def fp_to_f16  : SDNode<"ISD::FP_TO_FP16" , SDTFPToIntOp>;
544
545def strict_fadd       : SDNode<"ISD::STRICT_FADD",
546                               SDTFPBinOp, [SDNPHasChain, SDNPCommutative]>;
547def strict_fsub       : SDNode<"ISD::STRICT_FSUB",
548                               SDTFPBinOp, [SDNPHasChain]>;
549def strict_fmul       : SDNode<"ISD::STRICT_FMUL",
550                               SDTFPBinOp, [SDNPHasChain, SDNPCommutative]>;
551def strict_fdiv       : SDNode<"ISD::STRICT_FDIV",
552                               SDTFPBinOp, [SDNPHasChain]>;
553def strict_frem       : SDNode<"ISD::STRICT_FREM",
554                               SDTFPBinOp, [SDNPHasChain]>;
555def strict_fma        : SDNode<"ISD::STRICT_FMA",
556                               SDTFPTernaryOp, [SDNPHasChain, SDNPCommutative]>;
557def strict_fsqrt      : SDNode<"ISD::STRICT_FSQRT",
558                               SDTFPUnaryOp, [SDNPHasChain]>;
559def strict_fsin       : SDNode<"ISD::STRICT_FSIN",
560                               SDTFPUnaryOp, [SDNPHasChain]>;
561def strict_fcos       : SDNode<"ISD::STRICT_FCOS",
562                               SDTFPUnaryOp, [SDNPHasChain]>;
563def strict_fexp2      : SDNode<"ISD::STRICT_FEXP2",
564                               SDTFPUnaryOp, [SDNPHasChain]>;
565def strict_fpow       : SDNode<"ISD::STRICT_FPOW",
566                               SDTFPBinOp, [SDNPHasChain]>;
567def strict_fldexp       : SDNode<"ISD::STRICT_FLDEXP",
568                               SDTFPExpOp, [SDNPHasChain]>;
569def strict_flog2      : SDNode<"ISD::STRICT_FLOG2",
570                               SDTFPUnaryOp, [SDNPHasChain]>;
571def strict_frint      : SDNode<"ISD::STRICT_FRINT",
572                               SDTFPUnaryOp, [SDNPHasChain]>;
573def strict_lrint      : SDNode<"ISD::STRICT_LRINT",
574                               SDTFPToIntOp, [SDNPHasChain]>;
575def strict_llrint     : SDNode<"ISD::STRICT_LLRINT",
576                               SDTFPToIntOp, [SDNPHasChain]>;
577def strict_fnearbyint : SDNode<"ISD::STRICT_FNEARBYINT",
578                               SDTFPUnaryOp, [SDNPHasChain]>;
579def strict_fceil      : SDNode<"ISD::STRICT_FCEIL",
580                               SDTFPUnaryOp, [SDNPHasChain]>;
581def strict_ffloor     : SDNode<"ISD::STRICT_FFLOOR",
582                               SDTFPUnaryOp, [SDNPHasChain]>;
583def strict_lround     : SDNode<"ISD::STRICT_LROUND",
584                               SDTFPToIntOp, [SDNPHasChain]>;
585def strict_llround    : SDNode<"ISD::STRICT_LLROUND",
586                               SDTFPToIntOp, [SDNPHasChain]>;
587def strict_fround     : SDNode<"ISD::STRICT_FROUND",
588                               SDTFPUnaryOp, [SDNPHasChain]>;
589def strict_froundeven : SDNode<"ISD::STRICT_FROUNDEVEN",
590                               SDTFPUnaryOp, [SDNPHasChain]>;
591def strict_ftrunc     : SDNode<"ISD::STRICT_FTRUNC",
592                               SDTFPUnaryOp, [SDNPHasChain]>;
593def strict_fminnum    : SDNode<"ISD::STRICT_FMINNUM",
594                               SDTFPBinOp, [SDNPHasChain,
595                                            SDNPCommutative, SDNPAssociative]>;
596def strict_fmaxnum    : SDNode<"ISD::STRICT_FMAXNUM",
597                               SDTFPBinOp, [SDNPHasChain,
598                                            SDNPCommutative, SDNPAssociative]>;
599def strict_fminimum   : SDNode<"ISD::STRICT_FMINIMUM",
600                               SDTFPBinOp, [SDNPHasChain,
601                                            SDNPCommutative, SDNPAssociative]>;
602def strict_fmaximum   : SDNode<"ISD::STRICT_FMAXIMUM",
603                               SDTFPBinOp, [SDNPHasChain,
604                                            SDNPCommutative, SDNPAssociative]>;
605def strict_fpround    : SDNode<"ISD::STRICT_FP_ROUND",
606                               SDTFPRoundOp, [SDNPHasChain]>;
607def strict_fpextend   : SDNode<"ISD::STRICT_FP_EXTEND",
608                               SDTFPExtendOp, [SDNPHasChain]>;
609def strict_fp_to_sint : SDNode<"ISD::STRICT_FP_TO_SINT",
610                               SDTFPToIntOp, [SDNPHasChain]>;
611def strict_fp_to_uint : SDNode<"ISD::STRICT_FP_TO_UINT",
612                               SDTFPToIntOp, [SDNPHasChain]>;
613def strict_sint_to_fp : SDNode<"ISD::STRICT_SINT_TO_FP",
614                               SDTIntToFPOp, [SDNPHasChain]>;
615def strict_uint_to_fp : SDNode<"ISD::STRICT_UINT_TO_FP",
616                               SDTIntToFPOp, [SDNPHasChain]>;
617def strict_fsetcc  : SDNode<"ISD::STRICT_FSETCC",  SDTSetCC, [SDNPHasChain]>;
618def strict_fsetccs : SDNode<"ISD::STRICT_FSETCCS", SDTSetCC, [SDNPHasChain]>;
619
620def get_fpenv      : SDNode<"ISD::GET_FPENV", SDTGetFPStateOp, [SDNPHasChain]>;
621def set_fpenv      : SDNode<"ISD::SET_FPENV", SDTSetFPStateOp, [SDNPHasChain]>;
622def reset_fpenv    : SDNode<"ISD::RESET_FPENV", SDTNone, [SDNPHasChain]>;
623def get_fpmode     : SDNode<"ISD::GET_FPMODE", SDTGetFPStateOp, [SDNPHasChain]>;
624def set_fpmode     : SDNode<"ISD::SET_FPMODE", SDTSetFPStateOp, [SDNPHasChain]>;
625def reset_fpmode   : SDNode<"ISD::RESET_FPMODE", SDTNone, [SDNPHasChain]>;
626
627def setcc      : SDNode<"ISD::SETCC"      , SDTSetCC>;
628def select     : SDNode<"ISD::SELECT"     , SDTSelect>;
629def vselect    : SDNode<"ISD::VSELECT"    , SDTVSelect>;
630def selectcc   : SDNode<"ISD::SELECT_CC"  , SDTSelectCC>;
631
632def brcc       : SDNode<"ISD::BR_CC"      , SDTBrCC,   [SDNPHasChain]>;
633def brcond     : SDNode<"ISD::BRCOND"     , SDTBrcond, [SDNPHasChain]>;
634def brind      : SDNode<"ISD::BRIND"      , SDTBrind,  [SDNPHasChain]>;
635def br         : SDNode<"ISD::BR"         , SDTBr,     [SDNPHasChain]>;
636def catchret   : SDNode<"ISD::CATCHRET"   , SDTCatchret,
637                        [SDNPHasChain, SDNPSideEffect]>;
638def cleanupret : SDNode<"ISD::CLEANUPRET" , SDTNone,   [SDNPHasChain]>;
639
640def trap       : SDNode<"ISD::TRAP"       , SDTNone,
641                        [SDNPHasChain, SDNPSideEffect]>;
642def debugtrap  : SDNode<"ISD::DEBUGTRAP"  , SDTNone,
643                        [SDNPHasChain, SDNPSideEffect]>;
644def ubsantrap  : SDNode<"ISD::UBSANTRAP"  , SDTUBSANTrap,
645                        [SDNPHasChain, SDNPSideEffect]>;
646
647def prefetch   : SDNode<"ISD::PREFETCH"   , SDTPrefetch,
648                        [SDNPHasChain, SDNPMayLoad, SDNPMayStore,
649                         SDNPMemOperand]>;
650
651def readcyclecounter : SDNode<"ISD::READCYCLECOUNTER", SDTIntLeaf,
652                     [SDNPHasChain, SDNPSideEffect]>;
653
654def membarrier : SDNode<"ISD::MEMBARRIER", SDTNone,
655                        [SDNPHasChain, SDNPSideEffect]>;
656
657def jump_table_debug_info : SDNode<"ISD::JUMP_TABLE_DEBUG_INFO", SDTNone,
658                        [SDNPHasChain]>;
659
660def atomic_fence : SDNode<"ISD::ATOMIC_FENCE" , SDTAtomicFence,
661                          [SDNPHasChain, SDNPSideEffect]>;
662
663def atomic_cmp_swap : SDNode<"ISD::ATOMIC_CMP_SWAP" , SDTAtomic3,
664                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
665def atomic_load_add : SDNode<"ISD::ATOMIC_LOAD_ADD" , SDTAtomic2,
666                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
667def atomic_swap     : SDNode<"ISD::ATOMIC_SWAP", SDTAtomic2,
668                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
669def atomic_load_sub : SDNode<"ISD::ATOMIC_LOAD_SUB" , SDTAtomic2,
670                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
671def atomic_load_and : SDNode<"ISD::ATOMIC_LOAD_AND" , SDTAtomic2,
672                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
673def atomic_load_clr : SDNode<"ISD::ATOMIC_LOAD_CLR" , SDTAtomic2,
674                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
675def atomic_load_or  : SDNode<"ISD::ATOMIC_LOAD_OR" , SDTAtomic2,
676                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
677def atomic_load_xor : SDNode<"ISD::ATOMIC_LOAD_XOR" , SDTAtomic2,
678                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
679def atomic_load_nand: SDNode<"ISD::ATOMIC_LOAD_NAND", SDTAtomic2,
680                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
681def atomic_load_min : SDNode<"ISD::ATOMIC_LOAD_MIN", SDTAtomic2,
682                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
683def atomic_load_max : SDNode<"ISD::ATOMIC_LOAD_MAX", SDTAtomic2,
684                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
685def atomic_load_umin : SDNode<"ISD::ATOMIC_LOAD_UMIN", SDTAtomic2,
686                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
687def atomic_load_umax : SDNode<"ISD::ATOMIC_LOAD_UMAX", SDTAtomic2,
688                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
689def atomic_load_fadd : SDNode<"ISD::ATOMIC_LOAD_FADD" , SDTFPAtomic2,
690                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
691def atomic_load_fsub : SDNode<"ISD::ATOMIC_LOAD_FSUB" , SDTFPAtomic2,
692                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
693def atomic_load_fmax : SDNode<"ISD::ATOMIC_LOAD_FMAX", SDTFPAtomic2,
694                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
695def atomic_load_fmin : SDNode<"ISD::ATOMIC_LOAD_FMIN", SDTFPAtomic2,
696                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
697def atomic_load_uinc_wrap : SDNode<"ISD::ATOMIC_LOAD_UINC_WRAP", SDTAtomic2,
698                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
699def atomic_load_udec_wrap : SDNode<"ISD::ATOMIC_LOAD_UDEC_WRAP", SDTAtomic2,
700                    [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
701
702def atomic_load      : SDNode<"ISD::ATOMIC_LOAD", SDTAtomicLoad,
703                    [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
704def atomic_store     : SDNode<"ISD::ATOMIC_STORE", SDTAtomicStore,
705                    [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
706
707def masked_st    : SDNode<"ISD::MSTORE",  SDTMaskedStore,
708                       [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
709def masked_ld    : SDNode<"ISD::MLOAD",  SDTMaskedLoad,
710                       [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
711
712def masked_gather : SDNode<"ISD::MGATHER", SDTMaskedGather,
713                           [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
714
715def masked_scatter : SDNode<"ISD::MSCATTER", SDTMaskedScatter,
716                            [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
717
718// Do not use ld, st directly. Use load, extload, sextload, zextload, store,
719// and truncst (see below).
720def ld         : SDNode<"ISD::LOAD"       , SDTLoad,
721                        [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
722def st         : SDNode<"ISD::STORE"      , SDTStore,
723                        [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
724def ist        : SDNode<"ISD::STORE"      , SDTIStore,
725                        [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
726
727def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
728def vector_reverse : SDNode<"ISD::VECTOR_REVERSE", SDTVecReverse>;
729def vector_splice : SDNode<"ISD::VECTOR_SPLICE", SDTVecSlice, []>;
730def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, -1, []>, []>;
731def splat_vector : SDNode<"ISD::SPLAT_VECTOR", SDTypeProfile<1, 1, []>, []>;
732def step_vector : SDNode<"ISD::STEP_VECTOR", SDTypeProfile<1, 1,
733                       [SDTCisVec<0>, SDTCisInt<1>]>, []>;
734def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
735                              []>;
736
737// vector_extract/vector_insert are deprecated. extractelt/insertelt
738// are preferred.
739def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
740    SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
741def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
742    SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
743def concat_vectors : SDNode<"ISD::CONCAT_VECTORS",
744    SDTypeProfile<1, 2, [SDTCisSubVecOfVec<1, 0>, SDTCisSameAs<1, 2>]>,[]>;
745
746// This operator does not do subvector type checking.  The ARM
747// backend, at least, needs it.
748def vector_extract_subvec : SDNode<"ISD::EXTRACT_SUBVECTOR",
749    SDTypeProfile<1, 2, [SDTCisInt<2>, SDTCisVec<1>, SDTCisVec<0>]>,
750    []>;
751def vector_insert_subvec : SDNode<"ISD::INSERT_SUBVECTOR",
752    SDTypeProfile<1, 3, [SDTCisVec<0>, SDTCisSameAs<0, 1>, SDTCisVec<2>, SDTCisInt<3>]>,
753    []>;
754
755// This operator does subvector type checking.
756def extract_subvector : SDNode<"ISD::EXTRACT_SUBVECTOR", SDTSubVecExtract, []>;
757def insert_subvector : SDNode<"ISD::INSERT_SUBVECTOR", SDTSubVecInsert, []>;
758
759// Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
760// these internally.  Don't reference these directly.
761def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
762                            SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
763                            [SDNPHasChain]>;
764def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
765                               SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
766                               [SDNPHasChain]>;
767def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
768                                SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
769
770def SDT_assert : SDTypeProfile<1, 1,
771  [SDTCisInt<0>, SDTCisInt<1>, SDTCisSameAs<1, 0>]>;
772def assertsext : SDNode<"ISD::AssertSext", SDT_assert>;
773def assertzext : SDNode<"ISD::AssertZext", SDT_assert>;
774def assertalign : SDNode<"ISD::AssertAlign", SDT_assert>;
775
776//===----------------------------------------------------------------------===//
777// Selection DAG Condition Codes
778
779class CondCode<string fcmpName = "", string icmpName = ""> {
780  string ICmpPredicate = icmpName;
781  string FCmpPredicate = fcmpName;
782}
783
784// ISD::CondCode enums, and mapping to CmpInst::Predicate names
785def SETOEQ : CondCode<"FCMP_OEQ">;
786def SETOGT : CondCode<"FCMP_OGT">;
787def SETOGE : CondCode<"FCMP_OGE">;
788def SETOLT : CondCode<"FCMP_OLT">;
789def SETOLE : CondCode<"FCMP_OLE">;
790def SETONE : CondCode<"FCMP_ONE">;
791def SETO   : CondCode<"FCMP_ORD">;
792def SETUO  : CondCode<"FCMP_UNO">;
793def SETUEQ : CondCode<"FCMP_UEQ">;
794def SETUGT : CondCode<"FCMP_UGT", "ICMP_UGT">;
795def SETUGE : CondCode<"FCMP_UGE", "ICMP_UGE">;
796def SETULT : CondCode<"FCMP_ULT", "ICMP_ULT">;
797def SETULE : CondCode<"FCMP_ULE", "ICMP_ULE">;
798def SETUNE : CondCode<"FCMP_UNE">;
799def SETEQ : CondCode<"", "ICMP_EQ">;
800def SETGT : CondCode<"", "ICMP_SGT">;
801def SETGE : CondCode<"", "ICMP_SGE">;
802def SETLT : CondCode<"", "ICMP_SLT">;
803def SETLE : CondCode<"", "ICMP_SLE">;
804def SETNE : CondCode<"", "ICMP_NE">;
805
806//===----------------------------------------------------------------------===//
807// Selection DAG Node Transformation Functions.
808//
809// This mechanism allows targets to manipulate nodes in the output DAG once a
810// match has been formed.  This is typically used to manipulate immediate
811// values.
812//
813class SDNodeXForm<SDNode opc, code xformFunction> {
814  SDNode Opcode = opc;
815  code XFormFunction = xformFunction;
816}
817
818def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
819
820//===----------------------------------------------------------------------===//
821// Selection DAG Pattern Fragments.
822//
823// Pattern fragments are reusable chunks of dags that match specific things.
824// They can take arguments and have C++ predicates that control whether they
825// match.  They are intended to make the patterns for common instructions more
826// compact and readable.
827//
828
829/// PatFrags - Represents a set of pattern fragments.  Each single fragment
830/// can match something on the DAG, from a single node to multiple nested other
831/// fragments.   The whole set of fragments matches if any of the single
832/// fragments match.  This allows e.g. matching and "add with overflow" and
833/// a regular "add" with the same fragment set.
834///
835class PatFrags<dag ops, list<dag> frags, code pred = [{}],
836               SDNodeXForm xform = NOOP_SDNodeXForm> : SDPatternOperator {
837  dag Operands = ops;
838  list<dag> Fragments = frags;
839  code PredicateCode = pred;
840  code GISelPredicateCode = [{}];
841  code ImmediateCode = [{}];
842  SDNodeXForm OperandTransform = xform;
843
844  // When this is set, the PredicateCode may refer to a constant Operands
845  // vector which contains the captured nodes of the DAG, in the order listed
846  // by the Operands field above.
847  //
848  // This is useful when Fragments involves associative / commutative
849  // operators: a single piece of code can easily refer to all operands even
850  // when re-associated / commuted variants of the fragment are matched.
851  bit PredicateCodeUsesOperands = false;
852
853  // Define a few pre-packaged predicates. This helps GlobalISel import
854  // existing rules from SelectionDAG for many common cases.
855  // They will be tested prior to the code in pred and must not be used in
856  // ImmLeaf and its subclasses.
857
858  // If set to true, a predicate is added that checks for the absence of use of
859  // the first result.
860  bit HasNoUse = ?;
861
862  // Is the desired pre-packaged predicate for a load?
863  bit IsLoad = ?;
864  // Is the desired pre-packaged predicate for a store?
865  bit IsStore = ?;
866  // Is the desired pre-packaged predicate for an atomic?
867  bit IsAtomic = ?;
868
869  // cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
870  // cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
871  bit IsUnindexed = ?;
872
873  // cast<LoadSDNode>(N)->getExtensionType() != ISD::NON_EXTLOAD
874  bit IsNonExtLoad = ?;
875  // cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
876  bit IsAnyExtLoad = ?;
877  // cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
878  bit IsSignExtLoad = ?;
879  // cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
880  bit IsZeroExtLoad = ?;
881  // !cast<StoreSDNode>(N)->isTruncatingStore();
882  // cast<StoreSDNode>(N)->isTruncatingStore();
883  bit IsTruncStore = ?;
884
885  // cast<MemSDNode>(N)->getAddressSpace() ==
886  // If this empty, accept any address space.
887  list<int> AddressSpaces = ?;
888
889  // cast<MemSDNode>(N)->getAlign() >=
890  // If this is empty, accept any alignment.
891  int MinAlignment = ?;
892
893  // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Monotonic
894  bit IsAtomicOrderingMonotonic = ?;
895  // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Acquire
896  bit IsAtomicOrderingAcquire = ?;
897  // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::Release
898  bit IsAtomicOrderingRelease = ?;
899  // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::AcquireRelease
900  bit IsAtomicOrderingAcquireRelease = ?;
901  // cast<AtomicSDNode>(N)->getOrdering() == AtomicOrdering::SequentiallyConsistent
902  bit IsAtomicOrderingSequentiallyConsistent = ?;
903
904  // isAcquireOrStronger(cast<AtomicSDNode>(N)->getOrdering())
905  // !isAcquireOrStronger(cast<AtomicSDNode>(N)->getOrdering())
906  bit IsAtomicOrderingAcquireOrStronger = ?;
907
908  // isReleaseOrStronger(cast<AtomicSDNode>(N)->getOrdering())
909  // !isReleaseOrStronger(cast<AtomicSDNode>(N)->getOrdering())
910  bit IsAtomicOrderingReleaseOrStronger = ?;
911
912  // cast<LoadSDNode>(N)->getMemoryVT() == MVT::<VT>;
913  // cast<StoreSDNode>(N)->getMemoryVT() == MVT::<VT>;
914  ValueType MemoryVT = ?;
915  // cast<LoadSDNode>(N)->getMemoryVT().getScalarType() == MVT::<VT>;
916  // cast<StoreSDNode>(N)->getMemoryVT().getScalarType() == MVT::<VT>;
917  ValueType ScalarMemoryVT = ?;
918}
919
920// Patterns and PatFrags can also subclass GISelFlags to set flags that affect
921// how GlobalISel behaves when matching them.
922class GISelFlags {
923  bit GIIgnoreCopies = ?;
924}
925
926// PatFrag - A version of PatFrags matching only a single fragment.
927class PatFrag<dag ops, dag frag, code pred = [{}],
928              SDNodeXForm xform = NOOP_SDNodeXForm>
929  : PatFrags<ops, [frag], pred, xform>;
930
931// OutPatFrag is a pattern fragment that is used as part of an output pattern
932// (not an input pattern). These do not have predicates or transforms, but are
933// used to avoid repeated subexpressions in output patterns.
934class OutPatFrag<dag ops, dag frag>
935 : PatFrag<ops, frag, [{}], NOOP_SDNodeXForm>;
936
937// PatLeaf's are pattern fragments that have no operands.  This is just a helper
938// to define immediates and other common things concisely.
939class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
940 : PatFrag<(ops), frag, pred, xform>;
941
942
943// ImmLeaf is a pattern fragment with a constraint on the immediate.  The
944// constraint is a function that is run on the immediate (always with the value
945// sign extended out to an int64_t) as Imm.  For example:
946//
947//  def immSExt8 : ImmLeaf<i16, [{ return (char)Imm == Imm; }]>;
948//
949// this is a more convenient form to match 'imm' nodes in than PatLeaf and also
950// is preferred over using PatLeaf because it allows the code generator to
951// reason more about the constraint.
952//
953// If FastIsel should ignore all instructions that have an operand of this type,
954// the FastIselShouldIgnore flag can be set.  This is an optimization to reduce
955// the code size of the generated fast instruction selector.
956class ImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm,
957              SDNode ImmNode = imm>
958  : PatFrag<(ops), (vt ImmNode), [{}], xform> {
959  let ImmediateCode = pred;
960  bit FastIselShouldIgnore = false;
961
962  // Is the data type of the immediate an APInt?
963  bit IsAPInt = false;
964
965  // Is the data type of the immediate an APFloat?
966  bit IsAPFloat = false;
967}
968
969// Convenience wrapper for ImmLeaf to use timm/TargetConstant instead
970// of imm/Constant.
971class TImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm,
972  SDNode ImmNode = timm> : ImmLeaf<vt, pred, xform, ImmNode>;
973
974// An ImmLeaf except that Imm is an APInt. This is useful when you need to
975// zero-extend the immediate instead of sign-extend it.
976//
977// Note that FastISel does not currently understand IntImmLeaf and will not
978// generate code for rules that make use of it. As such, it does not make sense
979// to replace ImmLeaf with IntImmLeaf. However, replacing PatLeaf with an
980// IntImmLeaf will allow GlobalISel to import the rule.
981class IntImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
982    : ImmLeaf<vt, pred, xform> {
983  let IsAPInt = true;
984  let FastIselShouldIgnore = true;
985}
986
987// An ImmLeaf except that Imm is an APFloat.
988//
989// Note that FastISel does not currently understand FPImmLeaf and will not
990// generate code for rules that make use of it.
991class FPImmLeaf<ValueType vt, code pred, SDNodeXForm xform = NOOP_SDNodeXForm>
992  : ImmLeaf<vt, pred, xform, fpimm> {
993  let IsAPFloat = true;
994  let FastIselShouldIgnore = true;
995}
996
997// Leaf fragments.
998
999def vtInt      : PatLeaf<(vt),  [{ return N->getVT().isInteger(); }]>;
1000def vtFP       : PatLeaf<(vt),  [{ return N->getVT().isFloatingPoint(); }]>;
1001
1002// Use ISD::isConstantSplatVectorAllOnes or ISD::isConstantSplatVectorAllZeros
1003// to look for the corresponding build_vector or splat_vector. Will look through
1004// bitcasts and check for either opcode, except when used as a pattern root.
1005// When used as a pattern root, only fixed-length build_vector and scalable
1006// splat_vector are supported.
1007def immAllOnesV  : SDPatternOperator; // ISD::isConstantSplatVectorAllOnes
1008def immAllZerosV : SDPatternOperator; // ISD::isConstantSplatVectorAllZeros
1009
1010// Other helper fragments.
1011def not  : PatFrag<(ops node:$in), (xor node:$in, -1)>;
1012def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
1013def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
1014
1015def zanyext : PatFrags<(ops node:$op),
1016                       [(zext node:$op),
1017                        (anyext node:$op)]>;
1018
1019// null_frag - The null pattern operator is used in multiclass instantiations
1020// which accept an SDPatternOperator for use in matching patterns for internal
1021// definitions. When expanding a pattern, if the null fragment is referenced
1022// in the expansion, the pattern is discarded and it is as-if '[]' had been
1023// specified. This allows multiclasses to have the isel patterns be optional.
1024def null_frag : SDPatternOperator;
1025
1026// load fragments.
1027def unindexedload : PatFrag<(ops node:$ptr), (ld node:$ptr)> {
1028  let IsLoad = true;
1029  let IsUnindexed = true;
1030}
1031def load : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
1032  let IsLoad = true;
1033  let IsNonExtLoad = true;
1034}
1035
1036// extending load fragments.
1037def extload   : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
1038  let IsLoad = true;
1039  let IsAnyExtLoad = true;
1040}
1041def sextload  : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
1042  let IsLoad = true;
1043  let IsSignExtLoad = true;
1044}
1045def zextload  : PatFrag<(ops node:$ptr), (unindexedload node:$ptr)> {
1046  let IsLoad = true;
1047  let IsZeroExtLoad = true;
1048}
1049
1050def extloadi1  : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1051  let IsLoad = true;
1052  let MemoryVT = i1;
1053}
1054def extloadi8  : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1055  let IsLoad = true;
1056  let MemoryVT = i8;
1057}
1058def extloadi16 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1059  let IsLoad = true;
1060  let MemoryVT = i16;
1061}
1062def extloadi32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1063  let IsLoad = true;
1064  let MemoryVT = i32;
1065}
1066def extloadi64 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1067  let IsLoad = true;
1068  let MemoryVT = i64;
1069}
1070def extloadf16 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1071  let IsLoad = true;
1072  let MemoryVT = f16;
1073}
1074def extloadf32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1075  let IsLoad = true;
1076  let MemoryVT = f32;
1077}
1078def extloadf64 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1079  let IsLoad = true;
1080  let MemoryVT = f64;
1081}
1082
1083def sextloadi1  : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1084  let IsLoad = true;
1085  let MemoryVT = i1;
1086}
1087def sextloadi8  : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1088  let IsLoad = true;
1089  let MemoryVT = i8;
1090}
1091def sextloadi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1092  let IsLoad = true;
1093  let MemoryVT = i16;
1094}
1095def sextloadi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1096  let IsLoad = true;
1097  let MemoryVT = i32;
1098}
1099def sextloadi64 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1100  let IsLoad = true;
1101  let MemoryVT = i64;
1102}
1103
1104def zextloadi1  : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1105  let IsLoad = true;
1106  let MemoryVT = i1;
1107}
1108def zextloadi8  : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1109  let IsLoad = true;
1110  let MemoryVT = i8;
1111}
1112def zextloadi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1113  let IsLoad = true;
1114  let MemoryVT = i16;
1115}
1116def zextloadi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1117  let IsLoad = true;
1118  let MemoryVT = i32;
1119}
1120def zextloadi64 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1121  let IsLoad = true;
1122  let MemoryVT = i64;
1123}
1124
1125def extloadvi1  : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1126  let IsLoad = true;
1127  let ScalarMemoryVT = i1;
1128}
1129def extloadvi8  : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1130  let IsLoad = true;
1131  let ScalarMemoryVT = i8;
1132}
1133def extloadvi16 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1134  let IsLoad = true;
1135  let ScalarMemoryVT = i16;
1136}
1137def extloadvi32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1138  let IsLoad = true;
1139  let ScalarMemoryVT = i32;
1140}
1141def extloadvf16 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1142  let IsLoad = true;
1143  let ScalarMemoryVT = f16;
1144}
1145def extloadvf32 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1146  let IsLoad = true;
1147  let ScalarMemoryVT = f32;
1148}
1149def extloadvf64 : PatFrag<(ops node:$ptr), (extload node:$ptr)> {
1150  let IsLoad = true;
1151  let ScalarMemoryVT = f64;
1152}
1153
1154def sextloadvi1  : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1155  let IsLoad = true;
1156  let ScalarMemoryVT = i1;
1157}
1158def sextloadvi8  : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1159  let IsLoad = true;
1160  let ScalarMemoryVT = i8;
1161}
1162def sextloadvi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1163  let IsLoad = true;
1164  let ScalarMemoryVT = i16;
1165}
1166def sextloadvi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr)> {
1167  let IsLoad = true;
1168  let ScalarMemoryVT = i32;
1169}
1170
1171def zextloadvi1  : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1172  let IsLoad = true;
1173  let ScalarMemoryVT = i1;
1174}
1175def zextloadvi8  : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1176  let IsLoad = true;
1177  let ScalarMemoryVT = i8;
1178}
1179def zextloadvi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1180  let IsLoad = true;
1181  let ScalarMemoryVT = i16;
1182}
1183def zextloadvi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr)> {
1184  let IsLoad = true;
1185  let ScalarMemoryVT = i32;
1186}
1187
1188// store fragments.
1189def unindexedstore : PatFrag<(ops node:$val, node:$ptr),
1190                             (st node:$val, node:$ptr)> {
1191  let IsStore = true;
1192  let IsUnindexed = true;
1193}
1194def store : PatFrag<(ops node:$val, node:$ptr),
1195                    (unindexedstore node:$val, node:$ptr)> {
1196  let IsStore = true;
1197  let IsTruncStore = false;
1198}
1199
1200// truncstore fragments.
1201def truncstore : PatFrag<(ops node:$val, node:$ptr),
1202                         (unindexedstore node:$val, node:$ptr)> {
1203  let IsStore = true;
1204  let IsTruncStore = true;
1205}
1206def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
1207                           (truncstore node:$val, node:$ptr)> {
1208  let IsStore = true;
1209  let MemoryVT = i8;
1210  let IsTruncStore = true;
1211}
1212def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
1213                            (truncstore node:$val, node:$ptr)> {
1214  let IsStore = true;
1215  let MemoryVT = i16;
1216  let IsTruncStore = true;
1217}
1218def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
1219                            (truncstore node:$val, node:$ptr)> {
1220  let IsStore = true;
1221  let MemoryVT = i32;
1222  let IsTruncStore = true;
1223}
1224def truncstorei64 : PatFrag<(ops node:$val, node:$ptr),
1225                            (truncstore node:$val, node:$ptr)> {
1226  let IsStore = true;
1227  let MemoryVT = i64;
1228  let IsTruncStore = true;
1229}
1230def truncstoref16 : PatFrag<(ops node:$val, node:$ptr),
1231                            (truncstore node:$val, node:$ptr)> {
1232  let IsStore = true;
1233  let MemoryVT = f16;
1234}
1235def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
1236                            (truncstore node:$val, node:$ptr)> {
1237  let IsStore = true;
1238  let MemoryVT = f32;
1239}
1240def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
1241                            (truncstore node:$val, node:$ptr)> {
1242  let IsStore = true;
1243  let MemoryVT = f64;
1244}
1245
1246def truncstorevi8 : PatFrag<(ops node:$val, node:$ptr),
1247                            (truncstore node:$val, node:$ptr)> {
1248  let IsStore = true;
1249  let ScalarMemoryVT = i8;
1250}
1251
1252def truncstorevi16 : PatFrag<(ops node:$val, node:$ptr),
1253                             (truncstore node:$val, node:$ptr)> {
1254  let IsStore = true;
1255  let ScalarMemoryVT = i16;
1256}
1257
1258def truncstorevi32 : PatFrag<(ops node:$val, node:$ptr),
1259                             (truncstore node:$val, node:$ptr)> {
1260  let IsStore = true;
1261  let ScalarMemoryVT = i32;
1262}
1263
1264// indexed store fragments.
1265def istore : PatFrag<(ops node:$val, node:$base, node:$offset),
1266                     (ist node:$val, node:$base, node:$offset)> {
1267  let IsStore = true;
1268  let IsTruncStore = false;
1269}
1270
1271def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
1272                        (istore node:$val, node:$base, node:$offset), [{
1273  ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1274  return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
1275}]>;
1276
1277def itruncstore : PatFrag<(ops node:$val, node:$base, node:$offset),
1278                          (ist node:$val, node:$base, node:$offset)> {
1279  let IsStore = true;
1280  let IsTruncStore = true;
1281}
1282def pre_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
1283                          (itruncstore node:$val, node:$base, node:$offset), [{
1284  ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1285  return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
1286}]>;
1287def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
1288                            (pre_truncst node:$val, node:$base, node:$offset)> {
1289  let IsStore = true;
1290  let MemoryVT = i1;
1291}
1292def pre_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1293                            (pre_truncst node:$val, node:$base, node:$offset)> {
1294  let IsStore = true;
1295  let MemoryVT = i8;
1296}
1297def pre_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1298                             (pre_truncst node:$val, node:$base, node:$offset)> {
1299  let IsStore = true;
1300  let MemoryVT = i16;
1301}
1302def pre_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1303                             (pre_truncst node:$val, node:$base, node:$offset)> {
1304  let IsStore = true;
1305  let MemoryVT = i32;
1306}
1307def pre_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1308                             (pre_truncst node:$val, node:$base, node:$offset)> {
1309  let IsStore = true;
1310  let MemoryVT = f32;
1311}
1312def pre_truncstvi8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1313                             (pre_truncst node:$val, node:$base, node:$offset)> {
1314  let IsStore = true;
1315  let ScalarMemoryVT = i8;
1316}
1317def pre_truncstvi16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1318                              (pre_truncst node:$val, node:$base, node:$offset)> {
1319  let IsStore = true;
1320  let ScalarMemoryVT = i16;
1321}
1322
1323def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
1324                         (istore node:$val, node:$ptr, node:$offset), [{
1325  ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1326  return AM == ISD::POST_INC || AM == ISD::POST_DEC;
1327}]>;
1328
1329def post_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
1330                           (itruncstore node:$val, node:$base, node:$offset), [{
1331  ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
1332  return AM == ISD::POST_INC || AM == ISD::POST_DEC;
1333}]>;
1334def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
1335                             (post_truncst node:$val, node:$base, node:$offset)> {
1336  let IsStore = true;
1337  let MemoryVT = i1;
1338}
1339def post_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1340                             (post_truncst node:$val, node:$base, node:$offset)> {
1341  let IsStore = true;
1342  let MemoryVT = i8;
1343}
1344def post_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1345                              (post_truncst node:$val, node:$base, node:$offset)> {
1346  let IsStore = true;
1347  let MemoryVT = i16;
1348}
1349def post_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1350                              (post_truncst node:$val, node:$base, node:$offset)> {
1351  let IsStore = true;
1352  let MemoryVT = i32;
1353}
1354def post_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
1355                              (post_truncst node:$val, node:$base, node:$offset)> {
1356  let IsStore = true;
1357  let MemoryVT = f32;
1358}
1359def post_truncstvi8 : PatFrag<(ops node:$val, node:$base, node:$offset),
1360                              (post_truncst node:$val, node:$base, node:$offset)> {
1361  let IsStore = true;
1362  let ScalarMemoryVT = i8;
1363}
1364def post_truncstvi16 : PatFrag<(ops node:$val, node:$base, node:$offset),
1365                               (post_truncst node:$val, node:$base, node:$offset)> {
1366  let IsStore = true;
1367  let ScalarMemoryVT = i16;
1368}
1369
1370// A helper for matching undef or freeze undef
1371def undef_or_freeze_undef : PatFrags<(ops), [(undef), (freeze undef)]>;
1372
1373// TODO: Split these into volatile and unordered flavors to enable
1374// selectively legal optimizations for each.  (See D66309)
1375def simple_load : PatFrag<(ops node:$ptr),
1376                          (load node:$ptr), [{
1377  return cast<LoadSDNode>(N)->isSimple();
1378}]>;
1379def simple_store : PatFrag<(ops node:$val, node:$ptr),
1380                           (store node:$val, node:$ptr), [{
1381  return cast<StoreSDNode>(N)->isSimple();
1382}]>;
1383
1384// nontemporal store fragments.
1385def nontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1386                               (store node:$val, node:$ptr), [{
1387  return cast<StoreSDNode>(N)->isNonTemporal();
1388}]>;
1389
1390def alignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1391                                      (nontemporalstore node:$val, node:$ptr), [{
1392  StoreSDNode *St = cast<StoreSDNode>(N);
1393  return St->getAlign() >= St->getMemoryVT().getStoreSize();
1394}]>;
1395
1396def unalignednontemporalstore : PatFrag<(ops node:$val, node:$ptr),
1397                                        (nontemporalstore node:$val, node:$ptr), [{
1398  StoreSDNode *St = cast<StoreSDNode>(N);
1399  return St->getAlignment() < St->getMemoryVT().getStoreSize();
1400}]>;
1401
1402// nontemporal load fragments.
1403def nontemporalload : PatFrag<(ops node:$ptr),
1404                               (load node:$ptr), [{
1405  return cast<LoadSDNode>(N)->isNonTemporal();
1406}]>;
1407
1408def alignednontemporalload : PatFrag<(ops node:$ptr),
1409                                      (nontemporalload node:$ptr), [{
1410  LoadSDNode *Ld = cast<LoadSDNode>(N);
1411  return Ld->getAlign() >= Ld->getMemoryVT().getStoreSize();
1412}]>;
1413
1414// setcc convenience fragments.
1415def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
1416                     (setcc node:$lhs, node:$rhs, SETOEQ)>;
1417def setogt : PatFrag<(ops node:$lhs, node:$rhs),
1418                     (setcc node:$lhs, node:$rhs, SETOGT)>;
1419def setoge : PatFrag<(ops node:$lhs, node:$rhs),
1420                     (setcc node:$lhs, node:$rhs, SETOGE)>;
1421def setolt : PatFrag<(ops node:$lhs, node:$rhs),
1422                     (setcc node:$lhs, node:$rhs, SETOLT)>;
1423def setole : PatFrag<(ops node:$lhs, node:$rhs),
1424                     (setcc node:$lhs, node:$rhs, SETOLE)>;
1425def setone : PatFrag<(ops node:$lhs, node:$rhs),
1426                     (setcc node:$lhs, node:$rhs, SETONE)>;
1427def seto   : PatFrag<(ops node:$lhs, node:$rhs),
1428                     (setcc node:$lhs, node:$rhs, SETO)>;
1429def setuo  : PatFrag<(ops node:$lhs, node:$rhs),
1430                     (setcc node:$lhs, node:$rhs, SETUO)>;
1431def setueq : PatFrag<(ops node:$lhs, node:$rhs),
1432                     (setcc node:$lhs, node:$rhs, SETUEQ)>;
1433def setugt : PatFrag<(ops node:$lhs, node:$rhs),
1434                     (setcc node:$lhs, node:$rhs, SETUGT)>;
1435def setuge : PatFrag<(ops node:$lhs, node:$rhs),
1436                     (setcc node:$lhs, node:$rhs, SETUGE)>;
1437def setult : PatFrag<(ops node:$lhs, node:$rhs),
1438                     (setcc node:$lhs, node:$rhs, SETULT)>;
1439def setule : PatFrag<(ops node:$lhs, node:$rhs),
1440                     (setcc node:$lhs, node:$rhs, SETULE)>;
1441def setune : PatFrag<(ops node:$lhs, node:$rhs),
1442                     (setcc node:$lhs, node:$rhs, SETUNE)>;
1443def seteq  : PatFrag<(ops node:$lhs, node:$rhs),
1444                     (setcc node:$lhs, node:$rhs, SETEQ)>;
1445def setgt  : PatFrag<(ops node:$lhs, node:$rhs),
1446                     (setcc node:$lhs, node:$rhs, SETGT)>;
1447def setge  : PatFrag<(ops node:$lhs, node:$rhs),
1448                     (setcc node:$lhs, node:$rhs, SETGE)>;
1449def setlt  : PatFrag<(ops node:$lhs, node:$rhs),
1450                     (setcc node:$lhs, node:$rhs, SETLT)>;
1451def setle  : PatFrag<(ops node:$lhs, node:$rhs),
1452                     (setcc node:$lhs, node:$rhs, SETLE)>;
1453def setne  : PatFrag<(ops node:$lhs, node:$rhs),
1454                     (setcc node:$lhs, node:$rhs, SETNE)>;
1455
1456// We don't have strict FP extended loads as single DAG nodes, but we can
1457// still provide convenience fragments to match those operations.
1458def strict_extloadf32 : PatFrag<(ops node:$ptr),
1459                                (strict_fpextend (f32 (load node:$ptr)))>;
1460def strict_extloadf64 : PatFrag<(ops node:$ptr),
1461                                (strict_fpextend (f64 (load node:$ptr)))>;
1462
1463// Convenience fragments to match both strict and non-strict fp operations
1464def any_fadd       : PatFrags<(ops node:$lhs, node:$rhs),
1465                              [(strict_fadd node:$lhs, node:$rhs),
1466                               (fadd node:$lhs, node:$rhs)]>;
1467def any_fsub       : PatFrags<(ops node:$lhs, node:$rhs),
1468                              [(strict_fsub node:$lhs, node:$rhs),
1469                               (fsub node:$lhs, node:$rhs)]>;
1470def any_fmul       : PatFrags<(ops node:$lhs, node:$rhs),
1471                              [(strict_fmul node:$lhs, node:$rhs),
1472                               (fmul node:$lhs, node:$rhs)]>;
1473def any_fdiv       : PatFrags<(ops node:$lhs, node:$rhs),
1474                              [(strict_fdiv node:$lhs, node:$rhs),
1475                               (fdiv node:$lhs, node:$rhs)]>;
1476def any_frem       : PatFrags<(ops node:$lhs, node:$rhs),
1477                              [(strict_frem node:$lhs, node:$rhs),
1478                               (frem node:$lhs, node:$rhs)]>;
1479def any_fma        : PatFrags<(ops node:$src1, node:$src2, node:$src3),
1480                              [(strict_fma node:$src1, node:$src2, node:$src3),
1481                               (fma node:$src1, node:$src2, node:$src3)]>;
1482def any_fsqrt      : PatFrags<(ops node:$src),
1483                              [(strict_fsqrt node:$src),
1484                               (fsqrt node:$src)]>;
1485def any_fsin       : PatFrags<(ops node:$src),
1486                              [(strict_fsin node:$src),
1487                               (fsin node:$src)]>;
1488def any_fcos       : PatFrags<(ops node:$src),
1489                              [(strict_fcos node:$src),
1490                               (fcos node:$src)]>;
1491def any_fexp2      : PatFrags<(ops node:$src),
1492                              [(strict_fexp2 node:$src),
1493                               (fexp2 node:$src)]>;
1494def any_fpow       : PatFrags<(ops node:$lhs, node:$rhs),
1495                              [(strict_fpow node:$lhs, node:$rhs),
1496                               (fpow node:$lhs, node:$rhs)]>;
1497def any_fldexp      : PatFrags<(ops node:$lhs, node:$rhs),
1498                              [(strict_fldexp node:$lhs, node:$rhs),
1499                               (fldexp node:$lhs, node:$rhs)]>;
1500def any_flog2      : PatFrags<(ops node:$src),
1501                              [(strict_flog2 node:$src),
1502                               (flog2 node:$src)]>;
1503def any_frint      : PatFrags<(ops node:$src),
1504                              [(strict_frint node:$src),
1505                               (frint node:$src)]>;
1506def any_lrint      : PatFrags<(ops node:$src),
1507                              [(strict_lrint node:$src),
1508                               (lrint node:$src)]>;
1509def any_llrint     : PatFrags<(ops node:$src),
1510                              [(strict_llrint node:$src),
1511                               (llrint node:$src)]>;
1512def any_fnearbyint : PatFrags<(ops node:$src),
1513                              [(strict_fnearbyint node:$src),
1514                               (fnearbyint node:$src)]>;
1515def any_fceil      : PatFrags<(ops node:$src),
1516                              [(strict_fceil node:$src),
1517                               (fceil node:$src)]>;
1518def any_ffloor     : PatFrags<(ops node:$src),
1519                              [(strict_ffloor node:$src),
1520                               (ffloor node:$src)]>;
1521def any_lround     : PatFrags<(ops node:$src),
1522                              [(strict_lround node:$src),
1523                               (lround node:$src)]>;
1524def any_llround    : PatFrags<(ops node:$src),
1525                              [(strict_llround node:$src),
1526                               (llround node:$src)]>;
1527def any_fround     : PatFrags<(ops node:$src),
1528                              [(strict_fround node:$src),
1529                               (fround node:$src)]>;
1530def any_froundeven : PatFrags<(ops node:$src),
1531                              [(strict_froundeven node:$src),
1532                               (froundeven node:$src)]>;
1533def any_ftrunc     : PatFrags<(ops node:$src),
1534                              [(strict_ftrunc node:$src),
1535                               (ftrunc node:$src)]>;
1536def any_fmaxnum    : PatFrags<(ops node:$lhs, node:$rhs),
1537                              [(strict_fmaxnum node:$lhs, node:$rhs),
1538                               (fmaxnum node:$lhs, node:$rhs)]>;
1539def any_fminnum    : PatFrags<(ops node:$lhs, node:$rhs),
1540                              [(strict_fminnum node:$lhs, node:$rhs),
1541                               (fminnum node:$lhs, node:$rhs)]>;
1542def any_fmaximum   : PatFrags<(ops node:$lhs, node:$rhs),
1543                              [(strict_fmaximum node:$lhs, node:$rhs),
1544                               (fmaximum node:$lhs, node:$rhs)]>;
1545def any_fminimum   : PatFrags<(ops node:$lhs, node:$rhs),
1546                              [(strict_fminimum node:$lhs, node:$rhs),
1547                               (fminimum node:$lhs, node:$rhs)]>;
1548def any_fpround    : PatFrags<(ops node:$src),
1549                              [(strict_fpround node:$src),
1550                               (fpround node:$src)]>;
1551def any_fpextend   : PatFrags<(ops node:$src),
1552                              [(strict_fpextend node:$src),
1553                               (fpextend node:$src)]>;
1554def any_extloadf32 : PatFrags<(ops node:$ptr),
1555                              [(strict_extloadf32 node:$ptr),
1556                               (extloadf32 node:$ptr)]>;
1557def any_extloadf64 : PatFrags<(ops node:$ptr),
1558                              [(strict_extloadf64 node:$ptr),
1559                               (extloadf64 node:$ptr)]>;
1560def any_fp_to_sint : PatFrags<(ops node:$src),
1561                              [(strict_fp_to_sint node:$src),
1562                               (fp_to_sint node:$src)]>;
1563def any_fp_to_uint : PatFrags<(ops node:$src),
1564                              [(strict_fp_to_uint node:$src),
1565                               (fp_to_uint node:$src)]>;
1566def any_sint_to_fp : PatFrags<(ops node:$src),
1567                              [(strict_sint_to_fp node:$src),
1568                               (sint_to_fp node:$src)]>;
1569def any_uint_to_fp : PatFrags<(ops node:$src),
1570                              [(strict_uint_to_fp node:$src),
1571                               (uint_to_fp node:$src)]>;
1572def any_fsetcc : PatFrags<(ops node:$lhs, node:$rhs, node:$pred),
1573                          [(strict_fsetcc node:$lhs, node:$rhs, node:$pred),
1574                           (setcc node:$lhs, node:$rhs, node:$pred)]>;
1575def any_fsetccs : PatFrags<(ops node:$lhs, node:$rhs, node:$pred),
1576                          [(strict_fsetccs node:$lhs, node:$rhs, node:$pred),
1577                           (setcc node:$lhs, node:$rhs, node:$pred)]>;
1578
1579multiclass binary_atomic_op_ord {
1580  def NAME#_monotonic : PatFrag<(ops node:$ptr, node:$val),
1581      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$val)> {
1582    let IsAtomic = true;
1583    let IsAtomicOrderingMonotonic = true;
1584  }
1585  def NAME#_acquire : PatFrag<(ops node:$ptr, node:$val),
1586      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$val)> {
1587    let IsAtomic = true;
1588    let IsAtomicOrderingAcquire = true;
1589  }
1590  def NAME#_release : PatFrag<(ops node:$ptr, node:$val),
1591      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$val)> {
1592    let IsAtomic = true;
1593    let IsAtomicOrderingRelease = true;
1594  }
1595  def NAME#_acq_rel : PatFrag<(ops node:$ptr, node:$val),
1596      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$val)> {
1597    let IsAtomic = true;
1598    let IsAtomicOrderingAcquireRelease = true;
1599  }
1600  def NAME#_seq_cst : PatFrag<(ops node:$ptr, node:$val),
1601      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$val)> {
1602    let IsAtomic = true;
1603    let IsAtomicOrderingSequentiallyConsistent = true;
1604  }
1605}
1606
1607multiclass ternary_atomic_op_ord {
1608  def NAME#_monotonic : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1609      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$cmp, node:$val)> {
1610    let IsAtomic = true;
1611    let IsAtomicOrderingMonotonic = true;
1612  }
1613  def NAME#_acquire : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1614      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$cmp, node:$val)> {
1615    let IsAtomic = true;
1616    let IsAtomicOrderingAcquire = true;
1617  }
1618  def NAME#_release : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1619      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$cmp, node:$val)> {
1620    let IsAtomic = true;
1621    let IsAtomicOrderingRelease = true;
1622  }
1623  def NAME#_acq_rel : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1624      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$cmp, node:$val)> {
1625    let IsAtomic = true;
1626    let IsAtomicOrderingAcquireRelease = true;
1627  }
1628  def NAME#_seq_cst : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1629      (!cast<SDPatternOperator>(NAME) node:$ptr, node:$cmp, node:$val)> {
1630    let IsAtomic = true;
1631    let IsAtomicOrderingSequentiallyConsistent = true;
1632  }
1633}
1634
1635multiclass binary_atomic_op<SDNode atomic_op, bit IsInt = 1> {
1636  def _8 : PatFrag<(ops node:$ptr, node:$val),
1637                   (atomic_op  node:$ptr, node:$val)> {
1638    let IsAtomic = true;
1639    let MemoryVT = !if(IsInt, i8, ?);
1640  }
1641  def _16 : PatFrag<(ops node:$ptr, node:$val),
1642                    (atomic_op node:$ptr, node:$val)> {
1643    let IsAtomic = true;
1644    let MemoryVT = !if(IsInt, i16, f16);
1645  }
1646  def _32 : PatFrag<(ops node:$ptr, node:$val),
1647                    (atomic_op node:$ptr, node:$val)> {
1648    let IsAtomic = true;
1649    let MemoryVT = !if(IsInt, i32, f32);
1650  }
1651  def _64 : PatFrag<(ops node:$ptr, node:$val),
1652                    (atomic_op node:$ptr, node:$val)> {
1653    let IsAtomic = true;
1654    let MemoryVT = !if(IsInt, i64, f64);
1655  }
1656
1657  defm NAME#_8  : binary_atomic_op_ord;
1658  defm NAME#_16 : binary_atomic_op_ord;
1659  defm NAME#_32 : binary_atomic_op_ord;
1660  defm NAME#_64 : binary_atomic_op_ord;
1661}
1662
1663multiclass ternary_atomic_op<SDNode atomic_op> {
1664  def _8 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1665                   (atomic_op  node:$ptr, node:$cmp, node:$val)> {
1666    let IsAtomic = true;
1667    let MemoryVT = i8;
1668  }
1669  def _16 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1670                    (atomic_op node:$ptr, node:$cmp, node:$val)> {
1671    let IsAtomic = true;
1672    let MemoryVT = i16;
1673  }
1674  def _32 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1675                    (atomic_op node:$ptr, node:$cmp, node:$val)> {
1676    let IsAtomic = true;
1677    let MemoryVT = i32;
1678  }
1679  def _64 : PatFrag<(ops node:$ptr, node:$cmp, node:$val),
1680                    (atomic_op node:$ptr, node:$cmp, node:$val)> {
1681    let IsAtomic = true;
1682    let MemoryVT = i64;
1683  }
1684
1685  defm NAME#_8  : ternary_atomic_op_ord;
1686  defm NAME#_16 : ternary_atomic_op_ord;
1687  defm NAME#_32 : ternary_atomic_op_ord;
1688  defm NAME#_64 : ternary_atomic_op_ord;
1689}
1690
1691defm atomic_load_add  : binary_atomic_op<atomic_load_add>;
1692defm atomic_swap      : binary_atomic_op<atomic_swap>;
1693defm atomic_load_sub  : binary_atomic_op<atomic_load_sub>;
1694defm atomic_load_and  : binary_atomic_op<atomic_load_and>;
1695defm atomic_load_clr  : binary_atomic_op<atomic_load_clr>;
1696defm atomic_load_or   : binary_atomic_op<atomic_load_or>;
1697defm atomic_load_xor  : binary_atomic_op<atomic_load_xor>;
1698defm atomic_load_nand : binary_atomic_op<atomic_load_nand>;
1699defm atomic_load_min  : binary_atomic_op<atomic_load_min>;
1700defm atomic_load_max  : binary_atomic_op<atomic_load_max>;
1701defm atomic_load_umin : binary_atomic_op<atomic_load_umin>;
1702defm atomic_load_umax : binary_atomic_op<atomic_load_umax>;
1703defm atomic_cmp_swap  : ternary_atomic_op<atomic_cmp_swap>;
1704
1705/// Atomic load which zeroes the excess high bits.
1706def atomic_load_zext :
1707  PatFrag<(ops node:$ptr), (atomic_load node:$ptr)> {
1708  let IsAtomic = true; // FIXME: Should be IsLoad and/or IsAtomic?
1709  let IsZeroExtLoad = true;
1710}
1711
1712/// Atomic load which sign extends the excess high bits.
1713def atomic_load_sext :
1714  PatFrag<(ops node:$ptr), (atomic_load node:$ptr)> {
1715  let IsAtomic = true; // FIXME: Should be IsLoad and/or IsAtomic?
1716  let IsSignExtLoad = true;
1717}
1718
1719def atomic_load_8 :
1720  PatFrag<(ops node:$ptr),
1721          (atomic_load node:$ptr)> {
1722  let IsAtomic = true;
1723  let MemoryVT = i8;
1724}
1725
1726def atomic_load_16 :
1727  PatFrag<(ops node:$ptr),
1728          (atomic_load node:$ptr)> {
1729  let IsAtomic = true;
1730  let MemoryVT = i16;
1731}
1732
1733def atomic_load_32 :
1734  PatFrag<(ops node:$ptr),
1735          (atomic_load node:$ptr)> {
1736  let IsAtomic = true;
1737  let MemoryVT = i32;
1738}
1739def atomic_load_64 :
1740  PatFrag<(ops node:$ptr),
1741          (atomic_load node:$ptr)> {
1742  let IsAtomic = true;
1743  let MemoryVT = i64;
1744}
1745
1746def atomic_load_zext_8 :
1747  PatFrag<(ops node:$ptr), (atomic_load_zext node:$ptr)> {
1748  let IsAtomic = true; // FIXME: Should be IsLoad and/or IsAtomic?
1749  let MemoryVT = i8;
1750}
1751
1752def atomic_load_zext_16 :
1753  PatFrag<(ops node:$ptr), (atomic_load_zext node:$ptr)> {
1754  let IsAtomic = true; // FIXME: Should be IsLoad and/or IsAtomic?
1755  let MemoryVT = i16;
1756}
1757
1758def atomic_load_sext_8 :
1759  PatFrag<(ops node:$ptr), (atomic_load_sext node:$ptr)> {
1760  let IsAtomic = true; // FIXME: Should be IsLoad and/or IsAtomic?
1761  let MemoryVT = i8;
1762}
1763
1764def atomic_load_sext_16 :
1765  PatFrag<(ops node:$ptr), (atomic_load_sext node:$ptr)> {
1766  let IsAtomic = true; // FIXME: Should be IsLoad and/or IsAtomic?
1767  let MemoryVT = i16;
1768}
1769
1770// Atomic load which zeroes or anyextends the high bits.
1771def atomic_load_az_8 : PatFrags<(ops node:$op),
1772                                [(atomic_load_8 node:$op),
1773                                 (atomic_load_zext_8 node:$op)]>;
1774
1775// Atomic load which zeroes or anyextends the high bits.
1776def atomic_load_az_16 : PatFrags<(ops node:$op),
1777                                 [(atomic_load_16 node:$op),
1778                                  (atomic_load_zext_16 node:$op)]>;
1779
1780def nonext_masked_gather :
1781  PatFrag<(ops node:$def, node:$pred, node:$ptr, node:$idx),
1782          (masked_gather node:$def, node:$pred, node:$ptr, node:$idx), [{
1783  return cast<MaskedGatherSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1784}]>;
1785
1786// Any extending masked gather fragments.
1787def ext_masked_gather_i8 :
1788  PatFrag<(ops node:$def, node:$pred, node:$ptr, node:$idx),
1789          (masked_gather node:$def, node:$pred, node:$ptr, node:$idx), [{
1790  auto MGN = cast<MaskedGatherSDNode>(N);
1791  return MGN->getExtensionType() == ISD::EXTLOAD &&
1792         MGN->getMemoryVT().getScalarType() == MVT::i8;
1793}]>;
1794def ext_masked_gather_i16 :
1795  PatFrag<(ops node:$def, node:$pred, node:$ptr, node:$idx),
1796          (masked_gather node:$def, node:$pred, node:$ptr, node:$idx), [{
1797  auto MGN = cast<MaskedGatherSDNode>(N);
1798  return MGN->getExtensionType() == ISD::EXTLOAD &&
1799         MGN->getMemoryVT().getScalarType() == MVT::i16;
1800}]>;
1801def ext_masked_gather_i32 :
1802  PatFrag<(ops node:$def, node:$pred, node:$ptr, node:$idx),
1803          (masked_gather node:$def, node:$pred, node:$ptr, node:$idx), [{
1804  auto MGN = cast<MaskedGatherSDNode>(N);
1805  return MGN->getExtensionType() == ISD::EXTLOAD &&
1806         MGN->getMemoryVT().getScalarType() == MVT::i32;
1807}]>;
1808
1809// Sign extending masked gather fragments.
1810def sext_masked_gather_i8 :
1811  PatFrag<(ops node:$def, node:$pred, node:$ptr, node:$idx),
1812          (masked_gather node:$def, node:$pred, node:$ptr, node:$idx), [{
1813  auto MGN = cast<MaskedGatherSDNode>(N);
1814  return MGN->getExtensionType() == ISD::SEXTLOAD &&
1815         MGN->getMemoryVT().getScalarType() == MVT::i8;
1816}]>;
1817def sext_masked_gather_i16 :
1818  PatFrag<(ops node:$def, node:$pred, node:$ptr, node:$idx),
1819          (masked_gather node:$def, node:$pred, node:$ptr, node:$idx), [{
1820  auto MGN = cast<MaskedGatherSDNode>(N);
1821  return MGN->getExtensionType() == ISD::SEXTLOAD &&
1822         MGN->getMemoryVT().getScalarType() == MVT::i16;
1823}]>;
1824def sext_masked_gather_i32 :
1825  PatFrag<(ops node:$def, node:$pred, node:$ptr, node:$idx),
1826          (masked_gather node:$def, node:$pred, node:$ptr, node:$idx), [{
1827  auto MGN = cast<MaskedGatherSDNode>(N);
1828  return MGN->getExtensionType() == ISD::SEXTLOAD &&
1829         MGN->getMemoryVT().getScalarType() == MVT::i32;
1830}]>;
1831
1832// Zero extending masked gather fragments.
1833def zext_masked_gather_i8 :
1834  PatFrag<(ops node:$def, node:$pred, node:$ptr, node:$idx),
1835          (masked_gather node:$def, node:$pred, node:$ptr, node:$idx), [{
1836  auto MGN = cast<MaskedGatherSDNode>(N);
1837  return MGN->getExtensionType() == ISD::ZEXTLOAD &&
1838         MGN->getMemoryVT().getScalarType() == MVT::i8;
1839}]>;
1840def zext_masked_gather_i16 :
1841  PatFrag<(ops node:$def, node:$pred, node:$ptr, node:$idx),
1842          (masked_gather node:$def, node:$pred, node:$ptr, node:$idx), [{
1843  auto MGN = cast<MaskedGatherSDNode>(N);
1844  return MGN->getExtensionType() == ISD::ZEXTLOAD &&
1845         MGN->getMemoryVT().getScalarType() == MVT::i16;
1846}]>;
1847def zext_masked_gather_i32 :
1848  PatFrag<(ops node:$def, node:$pred, node:$ptr, node:$idx),
1849          (masked_gather node:$def, node:$pred, node:$ptr, node:$idx), [{
1850  auto MGN = cast<MaskedGatherSDNode>(N);
1851  return MGN->getExtensionType() == ISD::ZEXTLOAD &&
1852         MGN->getMemoryVT().getScalarType() == MVT::i32;
1853}]>;
1854
1855// Any/Zero extending masked gather fragments.
1856def azext_masked_gather_i8 :
1857  PatFrags<(ops node:$def, node:$pred, node:$ptr, node:$idx),
1858           [(ext_masked_gather_i8 node:$def, node:$pred, node:$ptr, node:$idx),
1859            (zext_masked_gather_i8 node:$def, node:$pred, node:$ptr, node:$idx)]>;
1860def azext_masked_gather_i16 :
1861  PatFrags<(ops node:$def, node:$pred, node:$ptr, node:$idx),
1862           [(ext_masked_gather_i16 node:$def, node:$pred, node:$ptr, node:$idx),
1863            (zext_masked_gather_i16 node:$def, node:$pred, node:$ptr, node:$idx)]>;
1864def azext_masked_gather_i32 :
1865  PatFrags<(ops node:$def, node:$pred, node:$ptr, node:$idx),
1866           [(ext_masked_gather_i32 node:$def, node:$pred, node:$ptr, node:$idx),
1867            (zext_masked_gather_i32 node:$def, node:$pred, node:$ptr, node:$idx)]>;
1868
1869def nontrunc_masked_scatter :
1870  PatFrag<(ops node:$val, node:$pred, node:$ptr, node:$idx),
1871          (masked_scatter node:$val, node:$pred, node:$ptr, node:$idx), [{
1872  return !cast<MaskedScatterSDNode>(N)->isTruncatingStore();
1873}]>;
1874
1875// Truncating masked scatter fragments.
1876def trunc_masked_scatter_i8 :
1877  PatFrag<(ops node:$val, node:$pred, node:$ptr, node:$idx),
1878          (masked_scatter node:$val, node:$pred, node:$ptr, node:$idx), [{
1879  auto MSN = cast<MaskedScatterSDNode>(N);
1880  return MSN->isTruncatingStore() &&
1881         MSN->getMemoryVT().getScalarType() == MVT::i8;
1882}]>;
1883def trunc_masked_scatter_i16 :
1884  PatFrag<(ops node:$val, node:$pred, node:$ptr, node:$idx),
1885          (masked_scatter node:$val, node:$pred, node:$ptr, node:$idx), [{
1886  auto MSN = cast<MaskedScatterSDNode>(N);
1887  return MSN->isTruncatingStore() &&
1888         MSN->getMemoryVT().getScalarType() == MVT::i16;
1889}]>;
1890def trunc_masked_scatter_i32 :
1891  PatFrag<(ops node:$val, node:$pred, node:$ptr, node:$idx),
1892          (masked_scatter node:$val, node:$pred, node:$ptr, node:$idx), [{
1893  auto MSN = cast<MaskedScatterSDNode>(N);
1894  return MSN->isTruncatingStore() &&
1895         MSN->getMemoryVT().getScalarType() == MVT::i32;
1896}]>;
1897
1898
1899def atomic_store_8 :
1900  PatFrag<(ops node:$val, node:$ptr),
1901          (atomic_store node:$val, node:$ptr)> {
1902  let IsAtomic = true;
1903  let MemoryVT = i8;
1904}
1905
1906def atomic_store_16 :
1907  PatFrag<(ops node:$val, node:$ptr),
1908          (atomic_store node:$val, node:$ptr)> {
1909  let IsAtomic = true;
1910  let MemoryVT = i16;
1911}
1912
1913def atomic_store_32 :
1914  PatFrag<(ops node:$val, node:$ptr),
1915          (atomic_store node:$val, node:$ptr)> {
1916  let IsAtomic = true;
1917  let MemoryVT = i32;
1918}
1919
1920def atomic_store_64 :
1921  PatFrag<(ops node:$val, node:$ptr),
1922          (atomic_store node:$val, node:$ptr)> {
1923  let IsAtomic = true;
1924  let MemoryVT = i64;
1925}
1926
1927//===----------------------------------------------------------------------===//
1928// Selection DAG Pattern Support.
1929//
1930// Patterns are what are actually matched against by the target-flavored
1931// instruction selection DAG.  Instructions defined by the target implicitly
1932// define patterns in most cases, but patterns can also be explicitly added when
1933// an operation is defined by a sequence of instructions (e.g. loading a large
1934// immediate value on RISC targets that do not support immediates as large as
1935// their GPRs).
1936//
1937
1938class Pattern<dag patternToMatch, list<dag> resultInstrs> {
1939  dag             PatternToMatch  = patternToMatch;
1940  list<dag>       ResultInstrs    = resultInstrs;
1941  list<Predicate> Predicates      = [];  // See class Instruction in Target.td.
1942  int             AddedComplexity = 0;   // See class Instruction in Target.td.
1943}
1944
1945// Pat - A simple (but common) form of a pattern, which produces a simple result
1946// not needing a full list.
1947class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
1948
1949//===----------------------------------------------------------------------===//
1950// Complex pattern definitions.
1951//
1952
1953// Complex patterns, e.g. X86 addressing mode, requires pattern matching code
1954// in C++. Ty is the type of return value; NumOperands is the number of operands
1955// returned by the select function; SelectFunc is the name of the function used
1956// to pattern match the max. pattern; RootNodes are the list of possible root nodes
1957// of the sub-dags to match.
1958// e.g. X86 addressing mode - def addr : ComplexPattern<iPTR, 4, "SelectAddr", [add]>;
1959//
1960class ComplexPattern<ValueType ty, int numops, string fn,
1961                     list<SDNode> roots = [], list<SDNodeProperty> props = [],
1962                     int complexity = -1> {
1963  ValueType Ty = ty;
1964  int NumOperands = numops;
1965  string SelectFunc = fn;
1966  list<SDNode> RootNodes = roots;
1967  list<SDNodeProperty> Properties = props;
1968  int Complexity = complexity;
1969}
1970