xref: /aosp_15_r20/external/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker//===- NVPTXInstrInfo.td - NVPTX Instruction defs -------------*- tblgen-*-===//
2*9880d681SAndroid Build Coastguard Worker//
3*9880d681SAndroid Build Coastguard Worker//                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker//
5*9880d681SAndroid Build Coastguard Worker// This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker// License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker//
8*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker//
10*9880d681SAndroid Build Coastguard Worker// This file describes the PTX instructions in TableGen format.
11*9880d681SAndroid Build Coastguard Worker//
12*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Workerinclude "NVPTXInstrFormats.td"
15*9880d681SAndroid Build Coastguard Worker
16*9880d681SAndroid Build Coastguard Worker// A NOP instruction
17*9880d681SAndroid Build Coastguard Workerlet hasSideEffects = 0 in {
18*9880d681SAndroid Build Coastguard Worker  def NOP : NVPTXInst<(outs), (ins), "", []>;
19*9880d681SAndroid Build Coastguard Worker}
20*9880d681SAndroid Build Coastguard Worker
21*9880d681SAndroid Build Coastguard Worker// List of vector specific properties
22*9880d681SAndroid Build Coastguard Workerdef isVecLD      : VecInstTypeEnum<1>;
23*9880d681SAndroid Build Coastguard Workerdef isVecST      : VecInstTypeEnum<2>;
24*9880d681SAndroid Build Coastguard Workerdef isVecBuild   : VecInstTypeEnum<3>;
25*9880d681SAndroid Build Coastguard Workerdef isVecShuffle : VecInstTypeEnum<4>;
26*9880d681SAndroid Build Coastguard Workerdef isVecExtract : VecInstTypeEnum<5>;
27*9880d681SAndroid Build Coastguard Workerdef isVecInsert  : VecInstTypeEnum<6>;
28*9880d681SAndroid Build Coastguard Workerdef isVecDest    : VecInstTypeEnum<7>;
29*9880d681SAndroid Build Coastguard Workerdef isVecOther   : VecInstTypeEnum<15>;
30*9880d681SAndroid Build Coastguard Worker
31*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
32*9880d681SAndroid Build Coastguard Worker// NVPTX Operand Definitions.
33*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
34*9880d681SAndroid Build Coastguard Worker
35*9880d681SAndroid Build Coastguard Workerdef brtarget    : Operand<OtherVT>;
36*9880d681SAndroid Build Coastguard Worker
37*9880d681SAndroid Build Coastguard Worker// CVT conversion modes
38*9880d681SAndroid Build Coastguard Worker// These must match the enum in NVPTX.h
39*9880d681SAndroid Build Coastguard Workerdef CvtNONE : PatLeaf<(i32 0x0)>;
40*9880d681SAndroid Build Coastguard Workerdef CvtRNI  : PatLeaf<(i32 0x1)>;
41*9880d681SAndroid Build Coastguard Workerdef CvtRZI  : PatLeaf<(i32 0x2)>;
42*9880d681SAndroid Build Coastguard Workerdef CvtRMI  : PatLeaf<(i32 0x3)>;
43*9880d681SAndroid Build Coastguard Workerdef CvtRPI  : PatLeaf<(i32 0x4)>;
44*9880d681SAndroid Build Coastguard Workerdef CvtRN   : PatLeaf<(i32 0x5)>;
45*9880d681SAndroid Build Coastguard Workerdef CvtRZ   : PatLeaf<(i32 0x6)>;
46*9880d681SAndroid Build Coastguard Workerdef CvtRM   : PatLeaf<(i32 0x7)>;
47*9880d681SAndroid Build Coastguard Workerdef CvtRP   : PatLeaf<(i32 0x8)>;
48*9880d681SAndroid Build Coastguard Worker
49*9880d681SAndroid Build Coastguard Workerdef CvtNONE_FTZ : PatLeaf<(i32 0x10)>;
50*9880d681SAndroid Build Coastguard Workerdef CvtRNI_FTZ  : PatLeaf<(i32 0x11)>;
51*9880d681SAndroid Build Coastguard Workerdef CvtRZI_FTZ  : PatLeaf<(i32 0x12)>;
52*9880d681SAndroid Build Coastguard Workerdef CvtRMI_FTZ  : PatLeaf<(i32 0x13)>;
53*9880d681SAndroid Build Coastguard Workerdef CvtRPI_FTZ  : PatLeaf<(i32 0x14)>;
54*9880d681SAndroid Build Coastguard Workerdef CvtRN_FTZ   : PatLeaf<(i32 0x15)>;
55*9880d681SAndroid Build Coastguard Workerdef CvtRZ_FTZ   : PatLeaf<(i32 0x16)>;
56*9880d681SAndroid Build Coastguard Workerdef CvtRM_FTZ   : PatLeaf<(i32 0x17)>;
57*9880d681SAndroid Build Coastguard Workerdef CvtRP_FTZ   : PatLeaf<(i32 0x18)>;
58*9880d681SAndroid Build Coastguard Worker
59*9880d681SAndroid Build Coastguard Workerdef CvtSAT      : PatLeaf<(i32 0x20)>;
60*9880d681SAndroid Build Coastguard Workerdef CvtSAT_FTZ  : PatLeaf<(i32 0x30)>;
61*9880d681SAndroid Build Coastguard Worker
62*9880d681SAndroid Build Coastguard Workerdef CvtMode : Operand<i32> {
63*9880d681SAndroid Build Coastguard Worker  let PrintMethod = "printCvtMode";
64*9880d681SAndroid Build Coastguard Worker}
65*9880d681SAndroid Build Coastguard Worker
66*9880d681SAndroid Build Coastguard Worker// Compare modes
67*9880d681SAndroid Build Coastguard Worker// These must match the enum in NVPTX.h
68*9880d681SAndroid Build Coastguard Workerdef CmpEQ   : PatLeaf<(i32 0)>;
69*9880d681SAndroid Build Coastguard Workerdef CmpNE   : PatLeaf<(i32 1)>;
70*9880d681SAndroid Build Coastguard Workerdef CmpLT   : PatLeaf<(i32 2)>;
71*9880d681SAndroid Build Coastguard Workerdef CmpLE   : PatLeaf<(i32 3)>;
72*9880d681SAndroid Build Coastguard Workerdef CmpGT   : PatLeaf<(i32 4)>;
73*9880d681SAndroid Build Coastguard Workerdef CmpGE   : PatLeaf<(i32 5)>;
74*9880d681SAndroid Build Coastguard Workerdef CmpLO   : PatLeaf<(i32 6)>;
75*9880d681SAndroid Build Coastguard Workerdef CmpLS   : PatLeaf<(i32 7)>;
76*9880d681SAndroid Build Coastguard Workerdef CmpHI   : PatLeaf<(i32 8)>;
77*9880d681SAndroid Build Coastguard Workerdef CmpHS   : PatLeaf<(i32 9)>;
78*9880d681SAndroid Build Coastguard Workerdef CmpEQU  : PatLeaf<(i32 10)>;
79*9880d681SAndroid Build Coastguard Workerdef CmpNEU  : PatLeaf<(i32 11)>;
80*9880d681SAndroid Build Coastguard Workerdef CmpLTU  : PatLeaf<(i32 12)>;
81*9880d681SAndroid Build Coastguard Workerdef CmpLEU  : PatLeaf<(i32 13)>;
82*9880d681SAndroid Build Coastguard Workerdef CmpGTU  : PatLeaf<(i32 14)>;
83*9880d681SAndroid Build Coastguard Workerdef CmpGEU  : PatLeaf<(i32 15)>;
84*9880d681SAndroid Build Coastguard Workerdef CmpNUM  : PatLeaf<(i32 16)>;
85*9880d681SAndroid Build Coastguard Workerdef CmpNAN  : PatLeaf<(i32 17)>;
86*9880d681SAndroid Build Coastguard Worker
87*9880d681SAndroid Build Coastguard Workerdef CmpEQ_FTZ   : PatLeaf<(i32 0x100)>;
88*9880d681SAndroid Build Coastguard Workerdef CmpNE_FTZ   : PatLeaf<(i32 0x101)>;
89*9880d681SAndroid Build Coastguard Workerdef CmpLT_FTZ   : PatLeaf<(i32 0x102)>;
90*9880d681SAndroid Build Coastguard Workerdef CmpLE_FTZ   : PatLeaf<(i32 0x103)>;
91*9880d681SAndroid Build Coastguard Workerdef CmpGT_FTZ   : PatLeaf<(i32 0x104)>;
92*9880d681SAndroid Build Coastguard Workerdef CmpGE_FTZ   : PatLeaf<(i32 0x105)>;
93*9880d681SAndroid Build Coastguard Workerdef CmpLO_FTZ   : PatLeaf<(i32 0x106)>;
94*9880d681SAndroid Build Coastguard Workerdef CmpLS_FTZ   : PatLeaf<(i32 0x107)>;
95*9880d681SAndroid Build Coastguard Workerdef CmpHI_FTZ   : PatLeaf<(i32 0x108)>;
96*9880d681SAndroid Build Coastguard Workerdef CmpHS_FTZ   : PatLeaf<(i32 0x109)>;
97*9880d681SAndroid Build Coastguard Workerdef CmpEQU_FTZ  : PatLeaf<(i32 0x10A)>;
98*9880d681SAndroid Build Coastguard Workerdef CmpNEU_FTZ  : PatLeaf<(i32 0x10B)>;
99*9880d681SAndroid Build Coastguard Workerdef CmpLTU_FTZ  : PatLeaf<(i32 0x10C)>;
100*9880d681SAndroid Build Coastguard Workerdef CmpLEU_FTZ  : PatLeaf<(i32 0x10D)>;
101*9880d681SAndroid Build Coastguard Workerdef CmpGTU_FTZ  : PatLeaf<(i32 0x10E)>;
102*9880d681SAndroid Build Coastguard Workerdef CmpGEU_FTZ  : PatLeaf<(i32 0x10F)>;
103*9880d681SAndroid Build Coastguard Workerdef CmpNUM_FTZ  : PatLeaf<(i32 0x110)>;
104*9880d681SAndroid Build Coastguard Workerdef CmpNAN_FTZ  : PatLeaf<(i32 0x111)>;
105*9880d681SAndroid Build Coastguard Worker
106*9880d681SAndroid Build Coastguard Workerdef CmpMode : Operand<i32> {
107*9880d681SAndroid Build Coastguard Worker  let PrintMethod = "printCmpMode";
108*9880d681SAndroid Build Coastguard Worker}
109*9880d681SAndroid Build Coastguard Worker
110*9880d681SAndroid Build Coastguard Workerdef F32ConstZero : Operand<f32>, PatLeaf<(f32 fpimm)>, SDNodeXForm<fpimm, [{
111*9880d681SAndroid Build Coastguard Worker    return CurDAG->getTargetConstantFP(0.0, MVT::f32);
112*9880d681SAndroid Build Coastguard Worker  }]>;
113*9880d681SAndroid Build Coastguard Workerdef F32ConstOne : Operand<f32>, PatLeaf<(f32 fpimm)>, SDNodeXForm<fpimm, [{
114*9880d681SAndroid Build Coastguard Worker    return CurDAG->getTargetConstantFP(1.0, MVT::f32);
115*9880d681SAndroid Build Coastguard Worker  }]>;
116*9880d681SAndroid Build Coastguard Worker
117*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
118*9880d681SAndroid Build Coastguard Worker// NVPTX Instruction Predicate Definitions
119*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
120*9880d681SAndroid Build Coastguard Worker
121*9880d681SAndroid Build Coastguard Worker
122*9880d681SAndroid Build Coastguard Workerdef hasAtomRedG32 : Predicate<"Subtarget->hasAtomRedG32()">;
123*9880d681SAndroid Build Coastguard Workerdef hasAtomRedS32 : Predicate<"Subtarget->hasAtomRedS32()">;
124*9880d681SAndroid Build Coastguard Workerdef hasAtomRedGen32 : Predicate<"Subtarget->hasAtomRedGen32()">;
125*9880d681SAndroid Build Coastguard Workerdef useAtomRedG32forGen32 :
126*9880d681SAndroid Build Coastguard Worker  Predicate<"!Subtarget->hasAtomRedGen32() && Subtarget->hasAtomRedG32()">;
127*9880d681SAndroid Build Coastguard Workerdef hasBrkPt : Predicate<"Subtarget->hasBrkPt()">;
128*9880d681SAndroid Build Coastguard Workerdef hasAtomRedG64 : Predicate<"Subtarget->hasAtomRedG64()">;
129*9880d681SAndroid Build Coastguard Workerdef hasAtomRedS64 : Predicate<"Subtarget->hasAtomRedS64()">;
130*9880d681SAndroid Build Coastguard Workerdef hasAtomRedGen64 : Predicate<"Subtarget->hasAtomRedGen64()">;
131*9880d681SAndroid Build Coastguard Workerdef useAtomRedG64forGen64 :
132*9880d681SAndroid Build Coastguard Worker  Predicate<"!Subtarget->hasAtomRedGen64() && Subtarget->hasAtomRedG64()">;
133*9880d681SAndroid Build Coastguard Workerdef hasAtomAddF32 : Predicate<"Subtarget->hasAtomAddF32()">;
134*9880d681SAndroid Build Coastguard Workerdef hasVote : Predicate<"Subtarget->hasVote()">;
135*9880d681SAndroid Build Coastguard Workerdef hasDouble : Predicate<"Subtarget->hasDouble()">;
136*9880d681SAndroid Build Coastguard Workerdef reqPTX20 : Predicate<"Subtarget->reqPTX20()">;
137*9880d681SAndroid Build Coastguard Workerdef hasLDG : Predicate<"Subtarget->hasLDG()">;
138*9880d681SAndroid Build Coastguard Workerdef hasLDU : Predicate<"Subtarget->hasLDU()">;
139*9880d681SAndroid Build Coastguard Workerdef hasGenericLdSt : Predicate<"Subtarget->hasGenericLdSt()">;
140*9880d681SAndroid Build Coastguard Worker
141*9880d681SAndroid Build Coastguard Workerdef doF32FTZ : Predicate<"useF32FTZ()">;
142*9880d681SAndroid Build Coastguard Workerdef doNoF32FTZ : Predicate<"!useF32FTZ()">;
143*9880d681SAndroid Build Coastguard Worker
144*9880d681SAndroid Build Coastguard Workerdef doMulWide      : Predicate<"doMulWide">;
145*9880d681SAndroid Build Coastguard Worker
146*9880d681SAndroid Build Coastguard Workerdef allowFMA : Predicate<"allowFMA()">;
147*9880d681SAndroid Build Coastguard Workerdef noFMA : Predicate<"!allowFMA()">;
148*9880d681SAndroid Build Coastguard Worker
149*9880d681SAndroid Build Coastguard Workerdef do_DIVF32_APPROX : Predicate<"getDivF32Level()==0">;
150*9880d681SAndroid Build Coastguard Workerdef do_DIVF32_FULL : Predicate<"getDivF32Level()==1">;
151*9880d681SAndroid Build Coastguard Worker
152*9880d681SAndroid Build Coastguard Workerdef do_SQRTF32_APPROX : Predicate<"!usePrecSqrtF32()">;
153*9880d681SAndroid Build Coastguard Workerdef do_SQRTF32_RN : Predicate<"usePrecSqrtF32()">;
154*9880d681SAndroid Build Coastguard Worker
155*9880d681SAndroid Build Coastguard Workerdef hasHWROT32 : Predicate<"Subtarget->hasHWROT32()">;
156*9880d681SAndroid Build Coastguard Workerdef noHWROT32 : Predicate<"!Subtarget->hasHWROT32()">;
157*9880d681SAndroid Build Coastguard Worker
158*9880d681SAndroid Build Coastguard Workerdef true : Predicate<"1">;
159*9880d681SAndroid Build Coastguard Worker
160*9880d681SAndroid Build Coastguard Workerdef hasPTX31 : Predicate<"Subtarget->getPTXVersion() >= 31">;
161*9880d681SAndroid Build Coastguard Worker
162*9880d681SAndroid Build Coastguard Worker
163*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
164*9880d681SAndroid Build Coastguard Worker// Some Common Instruction Class Templates
165*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
166*9880d681SAndroid Build Coastguard Worker
167*9880d681SAndroid Build Coastguard Worker// Template for instructions which take three int64, int32, or int16 args.
168*9880d681SAndroid Build Coastguard Worker// The instructions are named "<OpcStr><Width>" (e.g. "add.s64").
169*9880d681SAndroid Build Coastguard Workermulticlass I3<string OpcStr, SDNode OpNode> {
170*9880d681SAndroid Build Coastguard Worker  def i64rr :
171*9880d681SAndroid Build Coastguard Worker    NVPTXInst<(outs Int64Regs:$dst), (ins Int64Regs:$a, Int64Regs:$b),
172*9880d681SAndroid Build Coastguard Worker              !strconcat(OpcStr, "64 \t$dst, $a, $b;"),
173*9880d681SAndroid Build Coastguard Worker              [(set Int64Regs:$dst, (OpNode Int64Regs:$a, Int64Regs:$b))]>;
174*9880d681SAndroid Build Coastguard Worker  def i64ri :
175*9880d681SAndroid Build Coastguard Worker    NVPTXInst<(outs Int64Regs:$dst), (ins Int64Regs:$a, i64imm:$b),
176*9880d681SAndroid Build Coastguard Worker              !strconcat(OpcStr, "64 \t$dst, $a, $b;"),
177*9880d681SAndroid Build Coastguard Worker              [(set Int64Regs:$dst, (OpNode Int64Regs:$a, imm:$b))]>;
178*9880d681SAndroid Build Coastguard Worker  def i32rr :
179*9880d681SAndroid Build Coastguard Worker    NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$a, Int32Regs:$b),
180*9880d681SAndroid Build Coastguard Worker              !strconcat(OpcStr, "32 \t$dst, $a, $b;"),
181*9880d681SAndroid Build Coastguard Worker              [(set Int32Regs:$dst, (OpNode Int32Regs:$a, Int32Regs:$b))]>;
182*9880d681SAndroid Build Coastguard Worker  def i32ri :
183*9880d681SAndroid Build Coastguard Worker    NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$a, i32imm:$b),
184*9880d681SAndroid Build Coastguard Worker              !strconcat(OpcStr, "32 \t$dst, $a, $b;"),
185*9880d681SAndroid Build Coastguard Worker              [(set Int32Regs:$dst, (OpNode Int32Regs:$a, imm:$b))]>;
186*9880d681SAndroid Build Coastguard Worker  def i16rr :
187*9880d681SAndroid Build Coastguard Worker    NVPTXInst<(outs Int16Regs:$dst), (ins Int16Regs:$a, Int16Regs:$b),
188*9880d681SAndroid Build Coastguard Worker              !strconcat(OpcStr, "16 \t$dst, $a, $b;"),
189*9880d681SAndroid Build Coastguard Worker              [(set Int16Regs:$dst, (OpNode Int16Regs:$a, Int16Regs:$b))]>;
190*9880d681SAndroid Build Coastguard Worker  def i16ri :
191*9880d681SAndroid Build Coastguard Worker    NVPTXInst<(outs Int16Regs:$dst), (ins Int16Regs:$a, i16imm:$b),
192*9880d681SAndroid Build Coastguard Worker              !strconcat(OpcStr, "16 \t$dst, $a, $b;"),
193*9880d681SAndroid Build Coastguard Worker              [(set Int16Regs:$dst, (OpNode Int16Regs:$a, (imm):$b))]>;
194*9880d681SAndroid Build Coastguard Worker}
195*9880d681SAndroid Build Coastguard Worker
196*9880d681SAndroid Build Coastguard Worker// Template for instructions which take 3 int32 args.  The instructions are
197*9880d681SAndroid Build Coastguard Worker// named "<OpcStr>.s32" (e.g. "addc.cc.s32").
198*9880d681SAndroid Build Coastguard Workermulticlass ADD_SUB_INT_32<string OpcStr, SDNode OpNode> {
199*9880d681SAndroid Build Coastguard Worker   def i32rr :
200*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$a, Int32Regs:$b),
201*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, ".s32 \t$dst, $a, $b;"),
202*9880d681SAndroid Build Coastguard Worker               [(set Int32Regs:$dst, (OpNode Int32Regs:$a, Int32Regs:$b))]>;
203*9880d681SAndroid Build Coastguard Worker   def i32ri :
204*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$a, i32imm:$b),
205*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, ".s32 \t$dst, $a, $b;"),
206*9880d681SAndroid Build Coastguard Worker               [(set Int32Regs:$dst, (OpNode Int32Regs:$a, imm:$b))]>;
207*9880d681SAndroid Build Coastguard Worker}
208*9880d681SAndroid Build Coastguard Worker
209*9880d681SAndroid Build Coastguard Worker// Template for instructions which take three fp64 or fp32 args.  The
210*9880d681SAndroid Build Coastguard Worker// instructions are named "<OpcStr>.f<Width>" (e.g. "add.f64").
211*9880d681SAndroid Build Coastguard Worker//
212*9880d681SAndroid Build Coastguard Worker// Also defines ftz (flush subnormal inputs and results to sign-preserving
213*9880d681SAndroid Build Coastguard Worker// zero) variants for fp32 functions.
214*9880d681SAndroid Build Coastguard Workermulticlass F3<string OpcStr, SDNode OpNode> {
215*9880d681SAndroid Build Coastguard Worker   def f64rr :
216*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Float64Regs:$dst),
217*9880d681SAndroid Build Coastguard Worker               (ins Float64Regs:$a, Float64Regs:$b),
218*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, ".f64 \t$dst, $a, $b;"),
219*9880d681SAndroid Build Coastguard Worker               [(set Float64Regs:$dst, (OpNode Float64Regs:$a, Float64Regs:$b))]>,
220*9880d681SAndroid Build Coastguard Worker               Requires<[allowFMA]>;
221*9880d681SAndroid Build Coastguard Worker   def f64ri :
222*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Float64Regs:$dst),
223*9880d681SAndroid Build Coastguard Worker               (ins Float64Regs:$a, f64imm:$b),
224*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, ".f64 \t$dst, $a, $b;"),
225*9880d681SAndroid Build Coastguard Worker               [(set Float64Regs:$dst, (OpNode Float64Regs:$a, fpimm:$b))]>,
226*9880d681SAndroid Build Coastguard Worker               Requires<[allowFMA]>;
227*9880d681SAndroid Build Coastguard Worker   def f32rr_ftz :
228*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Float32Regs:$dst),
229*9880d681SAndroid Build Coastguard Worker               (ins Float32Regs:$a, Float32Regs:$b),
230*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, ".ftz.f32 \t$dst, $a, $b;"),
231*9880d681SAndroid Build Coastguard Worker               [(set Float32Regs:$dst, (OpNode Float32Regs:$a, Float32Regs:$b))]>,
232*9880d681SAndroid Build Coastguard Worker               Requires<[allowFMA, doF32FTZ]>;
233*9880d681SAndroid Build Coastguard Worker   def f32ri_ftz :
234*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Float32Regs:$dst),
235*9880d681SAndroid Build Coastguard Worker               (ins Float32Regs:$a, f32imm:$b),
236*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, ".ftz.f32 \t$dst, $a, $b;"),
237*9880d681SAndroid Build Coastguard Worker               [(set Float32Regs:$dst, (OpNode Float32Regs:$a, fpimm:$b))]>,
238*9880d681SAndroid Build Coastguard Worker               Requires<[allowFMA, doF32FTZ]>;
239*9880d681SAndroid Build Coastguard Worker   def f32rr :
240*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Float32Regs:$dst),
241*9880d681SAndroid Build Coastguard Worker               (ins Float32Regs:$a, Float32Regs:$b),
242*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, ".f32 \t$dst, $a, $b;"),
243*9880d681SAndroid Build Coastguard Worker               [(set Float32Regs:$dst, (OpNode Float32Regs:$a, Float32Regs:$b))]>,
244*9880d681SAndroid Build Coastguard Worker               Requires<[allowFMA]>;
245*9880d681SAndroid Build Coastguard Worker   def f32ri :
246*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Float32Regs:$dst),
247*9880d681SAndroid Build Coastguard Worker               (ins Float32Regs:$a, f32imm:$b),
248*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, ".f32 \t$dst, $a, $b;"),
249*9880d681SAndroid Build Coastguard Worker               [(set Float32Regs:$dst, (OpNode Float32Regs:$a, fpimm:$b))]>,
250*9880d681SAndroid Build Coastguard Worker               Requires<[allowFMA]>;
251*9880d681SAndroid Build Coastguard Worker}
252*9880d681SAndroid Build Coastguard Worker
253*9880d681SAndroid Build Coastguard Worker// Same as F3, but defines ".rn" variants (round to nearest even).
254*9880d681SAndroid Build Coastguard Workermulticlass F3_rn<string OpcStr, SDNode OpNode> {
255*9880d681SAndroid Build Coastguard Worker   def f64rr :
256*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Float64Regs:$dst),
257*9880d681SAndroid Build Coastguard Worker               (ins Float64Regs:$a, Float64Regs:$b),
258*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, ".rn.f64 \t$dst, $a, $b;"),
259*9880d681SAndroid Build Coastguard Worker               [(set Float64Regs:$dst, (OpNode Float64Regs:$a, Float64Regs:$b))]>,
260*9880d681SAndroid Build Coastguard Worker               Requires<[noFMA]>;
261*9880d681SAndroid Build Coastguard Worker   def f64ri :
262*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Float64Regs:$dst),
263*9880d681SAndroid Build Coastguard Worker               (ins Float64Regs:$a, f64imm:$b),
264*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, ".rn.f64 \t$dst, $a, $b;"),
265*9880d681SAndroid Build Coastguard Worker               [(set Float64Regs:$dst, (OpNode Float64Regs:$a, fpimm:$b))]>,
266*9880d681SAndroid Build Coastguard Worker               Requires<[noFMA]>;
267*9880d681SAndroid Build Coastguard Worker   def f32rr_ftz :
268*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Float32Regs:$dst),
269*9880d681SAndroid Build Coastguard Worker               (ins Float32Regs:$a, Float32Regs:$b),
270*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, ".rn.ftz.f32 \t$dst, $a, $b;"),
271*9880d681SAndroid Build Coastguard Worker               [(set Float32Regs:$dst, (OpNode Float32Regs:$a, Float32Regs:$b))]>,
272*9880d681SAndroid Build Coastguard Worker               Requires<[noFMA, doF32FTZ]>;
273*9880d681SAndroid Build Coastguard Worker   def f32ri_ftz :
274*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Float32Regs:$dst),
275*9880d681SAndroid Build Coastguard Worker               (ins Float32Regs:$a, f32imm:$b),
276*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, ".rn.ftz.f32 \t$dst, $a, $b;"),
277*9880d681SAndroid Build Coastguard Worker               [(set Float32Regs:$dst, (OpNode Float32Regs:$a, fpimm:$b))]>,
278*9880d681SAndroid Build Coastguard Worker               Requires<[noFMA, doF32FTZ]>;
279*9880d681SAndroid Build Coastguard Worker   def f32rr :
280*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Float32Regs:$dst),
281*9880d681SAndroid Build Coastguard Worker               (ins Float32Regs:$a, Float32Regs:$b),
282*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, ".rn.f32 \t$dst, $a, $b;"),
283*9880d681SAndroid Build Coastguard Worker               [(set Float32Regs:$dst, (OpNode Float32Regs:$a, Float32Regs:$b))]>,
284*9880d681SAndroid Build Coastguard Worker               Requires<[noFMA]>;
285*9880d681SAndroid Build Coastguard Worker   def f32ri :
286*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Float32Regs:$dst),
287*9880d681SAndroid Build Coastguard Worker               (ins Float32Regs:$a, f32imm:$b),
288*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, ".rn.f32 \t$dst, $a, $b;"),
289*9880d681SAndroid Build Coastguard Worker               [(set Float32Regs:$dst, (OpNode Float32Regs:$a, fpimm:$b))]>,
290*9880d681SAndroid Build Coastguard Worker               Requires<[noFMA]>;
291*9880d681SAndroid Build Coastguard Worker}
292*9880d681SAndroid Build Coastguard Worker
293*9880d681SAndroid Build Coastguard Worker// Template for operations which take two f32 or f64 operands.  Provides three
294*9880d681SAndroid Build Coastguard Worker// instructions: <OpcStr>.f64, <OpcStr>.f32, and <OpcStr>.ftz.f32 (flush
295*9880d681SAndroid Build Coastguard Worker// subnormal inputs and results to zero).
296*9880d681SAndroid Build Coastguard Workermulticlass F2<string OpcStr, SDNode OpNode> {
297*9880d681SAndroid Build Coastguard Worker   def f64 :     NVPTXInst<(outs Float64Regs:$dst), (ins Float64Regs:$a),
298*9880d681SAndroid Build Coastguard Worker                           !strconcat(OpcStr, ".f64 \t$dst, $a;"),
299*9880d681SAndroid Build Coastguard Worker                           [(set Float64Regs:$dst, (OpNode Float64Regs:$a))]>;
300*9880d681SAndroid Build Coastguard Worker   def f32_ftz : NVPTXInst<(outs Float32Regs:$dst), (ins Float32Regs:$a),
301*9880d681SAndroid Build Coastguard Worker                           !strconcat(OpcStr, ".ftz.f32 \t$dst, $a;"),
302*9880d681SAndroid Build Coastguard Worker                           [(set Float32Regs:$dst, (OpNode Float32Regs:$a))]>,
303*9880d681SAndroid Build Coastguard Worker                           Requires<[doF32FTZ]>;
304*9880d681SAndroid Build Coastguard Worker   def f32 :     NVPTXInst<(outs Float32Regs:$dst), (ins Float32Regs:$a),
305*9880d681SAndroid Build Coastguard Worker                           !strconcat(OpcStr, ".f32 \t$dst, $a;"),
306*9880d681SAndroid Build Coastguard Worker                           [(set Float32Regs:$dst, (OpNode Float32Regs:$a))]>;
307*9880d681SAndroid Build Coastguard Worker}
308*9880d681SAndroid Build Coastguard Worker
309*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
310*9880d681SAndroid Build Coastguard Worker// NVPTX Instructions.
311*9880d681SAndroid Build Coastguard Worker//===----------------------------------------------------------------------===//
312*9880d681SAndroid Build Coastguard Worker
313*9880d681SAndroid Build Coastguard Worker//-----------------------------------
314*9880d681SAndroid Build Coastguard Worker// Type Conversion
315*9880d681SAndroid Build Coastguard Worker//-----------------------------------
316*9880d681SAndroid Build Coastguard Worker
317*9880d681SAndroid Build Coastguard Workerlet hasSideEffects = 0 in {
318*9880d681SAndroid Build Coastguard Worker  // Generate a cvt to the given type from all possible types.  Each instance
319*9880d681SAndroid Build Coastguard Worker  // takes a CvtMode immediate that defines the conversion mode to use.  It can
320*9880d681SAndroid Build Coastguard Worker  // be CvtNONE to omit a conversion mode.
321*9880d681SAndroid Build Coastguard Worker  multiclass CVT_FROM_ALL<string FromName, RegisterClass RC> {
322*9880d681SAndroid Build Coastguard Worker    def _s8 :
323*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs RC:$dst),
324*9880d681SAndroid Build Coastguard Worker                (ins Int16Regs:$src, CvtMode:$mode),
325*9880d681SAndroid Build Coastguard Worker                !strconcat("cvt${mode:base}${mode:ftz}${mode:sat}.",
326*9880d681SAndroid Build Coastguard Worker                FromName, ".s8\t$dst, $src;"), []>;
327*9880d681SAndroid Build Coastguard Worker    def _u8 :
328*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs RC:$dst),
329*9880d681SAndroid Build Coastguard Worker                (ins Int16Regs:$src, CvtMode:$mode),
330*9880d681SAndroid Build Coastguard Worker                !strconcat("cvt${mode:base}${mode:ftz}${mode:sat}.",
331*9880d681SAndroid Build Coastguard Worker                FromName, ".u8\t$dst, $src;"), []>;
332*9880d681SAndroid Build Coastguard Worker    def _s16 :
333*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs RC:$dst),
334*9880d681SAndroid Build Coastguard Worker                (ins Int16Regs:$src, CvtMode:$mode),
335*9880d681SAndroid Build Coastguard Worker                !strconcat("cvt${mode:base}${mode:ftz}${mode:sat}.",
336*9880d681SAndroid Build Coastguard Worker                FromName, ".s16\t$dst, $src;"), []>;
337*9880d681SAndroid Build Coastguard Worker    def _u16 :
338*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs RC:$dst),
339*9880d681SAndroid Build Coastguard Worker                (ins Int16Regs:$src, CvtMode:$mode),
340*9880d681SAndroid Build Coastguard Worker                !strconcat("cvt${mode:base}${mode:ftz}${mode:sat}.",
341*9880d681SAndroid Build Coastguard Worker                FromName, ".u16\t$dst, $src;"), []>;
342*9880d681SAndroid Build Coastguard Worker    def _f16 :
343*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs RC:$dst),
344*9880d681SAndroid Build Coastguard Worker                (ins Int16Regs:$src, CvtMode:$mode),
345*9880d681SAndroid Build Coastguard Worker                !strconcat("cvt${mode:base}${mode:ftz}${mode:sat}.",
346*9880d681SAndroid Build Coastguard Worker                FromName, ".f16\t$dst, $src;"), []>;
347*9880d681SAndroid Build Coastguard Worker    def _s32 :
348*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs RC:$dst),
349*9880d681SAndroid Build Coastguard Worker                (ins Int32Regs:$src, CvtMode:$mode),
350*9880d681SAndroid Build Coastguard Worker                !strconcat("cvt${mode:base}${mode:ftz}${mode:sat}.",
351*9880d681SAndroid Build Coastguard Worker                FromName, ".s32\t$dst, $src;"), []>;
352*9880d681SAndroid Build Coastguard Worker    def _u32 :
353*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs RC:$dst),
354*9880d681SAndroid Build Coastguard Worker                (ins Int32Regs:$src, CvtMode:$mode),
355*9880d681SAndroid Build Coastguard Worker                !strconcat("cvt${mode:base}${mode:ftz}${mode:sat}.",
356*9880d681SAndroid Build Coastguard Worker                FromName, ".u32\t$dst, $src;"), []>;
357*9880d681SAndroid Build Coastguard Worker    def _s64 :
358*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs RC:$dst),
359*9880d681SAndroid Build Coastguard Worker                (ins Int64Regs:$src, CvtMode:$mode),
360*9880d681SAndroid Build Coastguard Worker                !strconcat("cvt${mode:base}${mode:ftz}${mode:sat}.",
361*9880d681SAndroid Build Coastguard Worker                FromName, ".s64\t$dst, $src;"), []>;
362*9880d681SAndroid Build Coastguard Worker    def _u64 :
363*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs RC:$dst),
364*9880d681SAndroid Build Coastguard Worker                (ins Int64Regs:$src, CvtMode:$mode),
365*9880d681SAndroid Build Coastguard Worker                !strconcat("cvt${mode:base}${mode:ftz}${mode:sat}.",
366*9880d681SAndroid Build Coastguard Worker                FromName, ".u64\t$dst, $src;"), []>;
367*9880d681SAndroid Build Coastguard Worker    def _f32 :
368*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs RC:$dst),
369*9880d681SAndroid Build Coastguard Worker                (ins Float32Regs:$src, CvtMode:$mode),
370*9880d681SAndroid Build Coastguard Worker                !strconcat("cvt${mode:base}${mode:ftz}${mode:sat}.",
371*9880d681SAndroid Build Coastguard Worker                FromName, ".f32\t$dst, $src;"), []>;
372*9880d681SAndroid Build Coastguard Worker    def _f64 :
373*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs RC:$dst),
374*9880d681SAndroid Build Coastguard Worker                (ins Float64Regs:$src, CvtMode:$mode),
375*9880d681SAndroid Build Coastguard Worker                !strconcat("cvt${mode:base}${mode:ftz}${mode:sat}.",
376*9880d681SAndroid Build Coastguard Worker                FromName, ".f64\t$dst, $src;"), []>;
377*9880d681SAndroid Build Coastguard Worker  }
378*9880d681SAndroid Build Coastguard Worker
379*9880d681SAndroid Build Coastguard Worker  // Generate cvts from all types to all types.
380*9880d681SAndroid Build Coastguard Worker  defm CVT_s8  : CVT_FROM_ALL<"s8",  Int16Regs>;
381*9880d681SAndroid Build Coastguard Worker  defm CVT_u8  : CVT_FROM_ALL<"u8",  Int16Regs>;
382*9880d681SAndroid Build Coastguard Worker  defm CVT_s16 : CVT_FROM_ALL<"s16", Int16Regs>;
383*9880d681SAndroid Build Coastguard Worker  defm CVT_u16 : CVT_FROM_ALL<"u16", Int16Regs>;
384*9880d681SAndroid Build Coastguard Worker  defm CVT_f16 : CVT_FROM_ALL<"f16", Int16Regs>;
385*9880d681SAndroid Build Coastguard Worker  defm CVT_s32 : CVT_FROM_ALL<"s32", Int32Regs>;
386*9880d681SAndroid Build Coastguard Worker  defm CVT_u32 : CVT_FROM_ALL<"u32", Int32Regs>;
387*9880d681SAndroid Build Coastguard Worker  defm CVT_s64 : CVT_FROM_ALL<"s64", Int64Regs>;
388*9880d681SAndroid Build Coastguard Worker  defm CVT_u64 : CVT_FROM_ALL<"u64", Int64Regs>;
389*9880d681SAndroid Build Coastguard Worker  defm CVT_f32 : CVT_FROM_ALL<"f32", Float32Regs>;
390*9880d681SAndroid Build Coastguard Worker  defm CVT_f64 : CVT_FROM_ALL<"f64", Float64Regs>;
391*9880d681SAndroid Build Coastguard Worker
392*9880d681SAndroid Build Coastguard Worker  // These cvts are different from those above: The source and dest registers
393*9880d681SAndroid Build Coastguard Worker  // are of the same type.
394*9880d681SAndroid Build Coastguard Worker  def CVT_INREG_s16_s8 :  NVPTXInst<(outs Int16Regs:$dst), (ins Int16Regs:$src),
395*9880d681SAndroid Build Coastguard Worker                                    "cvt.s16.s8 \t$dst, $src;", []>;
396*9880d681SAndroid Build Coastguard Worker  def CVT_INREG_s32_s8 :  NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$src),
397*9880d681SAndroid Build Coastguard Worker                                    "cvt.s32.s8 \t$dst, $src;", []>;
398*9880d681SAndroid Build Coastguard Worker  def CVT_INREG_s32_s16 : NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$src),
399*9880d681SAndroid Build Coastguard Worker                                    "cvt.s32.s16 \t$dst, $src;", []>;
400*9880d681SAndroid Build Coastguard Worker  def CVT_INREG_s64_s8 :  NVPTXInst<(outs Int64Regs:$dst), (ins Int64Regs:$src),
401*9880d681SAndroid Build Coastguard Worker                                    "cvt.s64.s8 \t$dst, $src;", []>;
402*9880d681SAndroid Build Coastguard Worker  def CVT_INREG_s64_s16 : NVPTXInst<(outs Int64Regs:$dst), (ins Int64Regs:$src),
403*9880d681SAndroid Build Coastguard Worker                                    "cvt.s64.s16 \t$dst, $src;", []>;
404*9880d681SAndroid Build Coastguard Worker  def CVT_INREG_s64_s32 : NVPTXInst<(outs Int64Regs:$dst), (ins Int64Regs:$src),
405*9880d681SAndroid Build Coastguard Worker                                    "cvt.s64.s32 \t$dst, $src;", []>;
406*9880d681SAndroid Build Coastguard Worker}
407*9880d681SAndroid Build Coastguard Worker
408*9880d681SAndroid Build Coastguard Worker//-----------------------------------
409*9880d681SAndroid Build Coastguard Worker// Integer Arithmetic
410*9880d681SAndroid Build Coastguard Worker//-----------------------------------
411*9880d681SAndroid Build Coastguard Worker
412*9880d681SAndroid Build Coastguard Worker// Template for xor masquerading as int1 arithmetic.
413*9880d681SAndroid Build Coastguard Workermulticlass ADD_SUB_i1<SDNode OpNode> {
414*9880d681SAndroid Build Coastguard Worker   def _rr: NVPTXInst<(outs Int1Regs:$dst), (ins Int1Regs:$a, Int1Regs:$b),
415*9880d681SAndroid Build Coastguard Worker                      "xor.pred \t$dst, $a, $b;",
416*9880d681SAndroid Build Coastguard Worker                      [(set Int1Regs:$dst, (OpNode Int1Regs:$a, Int1Regs:$b))]>;
417*9880d681SAndroid Build Coastguard Worker   def _ri: NVPTXInst<(outs Int1Regs:$dst), (ins Int1Regs:$a, i1imm:$b),
418*9880d681SAndroid Build Coastguard Worker                      "xor.pred \t$dst, $a, $b;",
419*9880d681SAndroid Build Coastguard Worker                      [(set Int1Regs:$dst, (OpNode Int1Regs:$a, (imm):$b))]>;
420*9880d681SAndroid Build Coastguard Worker}
421*9880d681SAndroid Build Coastguard Worker
422*9880d681SAndroid Build Coastguard Worker// int1 addition and subtraction are both just xor.
423*9880d681SAndroid Build Coastguard Workerdefm ADD_i1 : ADD_SUB_i1<add>;
424*9880d681SAndroid Build Coastguard Workerdefm SUB_i1 : ADD_SUB_i1<sub>;
425*9880d681SAndroid Build Coastguard Worker
426*9880d681SAndroid Build Coastguard Worker// int16, int32, and int64 signed addition.  Since nvptx is 2's compliment, we
427*9880d681SAndroid Build Coastguard Worker// also use these for unsigned arithmetic.
428*9880d681SAndroid Build Coastguard Workerdefm ADD : I3<"add.s", add>;
429*9880d681SAndroid Build Coastguard Workerdefm SUB : I3<"sub.s", sub>;
430*9880d681SAndroid Build Coastguard Worker
431*9880d681SAndroid Build Coastguard Worker// int32 addition and subtraction with carry-out.
432*9880d681SAndroid Build Coastguard Worker// FIXME: PTX 4.3 adds a 64-bit add.cc (and maybe also 64-bit addc.cc?).
433*9880d681SAndroid Build Coastguard Workerdefm ADDCC : ADD_SUB_INT_32<"add.cc", addc>;
434*9880d681SAndroid Build Coastguard Workerdefm SUBCC : ADD_SUB_INT_32<"sub.cc", subc>;
435*9880d681SAndroid Build Coastguard Worker
436*9880d681SAndroid Build Coastguard Worker// int32 addition and subtraction with carry-in and carry-out.
437*9880d681SAndroid Build Coastguard Workerdefm ADDCCC : ADD_SUB_INT_32<"addc.cc", adde>;
438*9880d681SAndroid Build Coastguard Workerdefm SUBCCC : ADD_SUB_INT_32<"subc.cc", sube>;
439*9880d681SAndroid Build Coastguard Worker
440*9880d681SAndroid Build Coastguard Workerdefm MULT : I3<"mul.lo.s", mul>;
441*9880d681SAndroid Build Coastguard Worker
442*9880d681SAndroid Build Coastguard Workerdefm MULTHS : I3<"mul.hi.s", mulhs>;
443*9880d681SAndroid Build Coastguard Workerdefm MULTHU : I3<"mul.hi.u", mulhu>;
444*9880d681SAndroid Build Coastguard Worker
445*9880d681SAndroid Build Coastguard Workerdefm SDIV : I3<"div.s", sdiv>;
446*9880d681SAndroid Build Coastguard Workerdefm UDIV : I3<"div.u", udiv>;
447*9880d681SAndroid Build Coastguard Worker
448*9880d681SAndroid Build Coastguard Worker// The ri versions of rem.s and rem.u won't be selected; DAGCombiner::visitSREM
449*9880d681SAndroid Build Coastguard Worker// will lower it.
450*9880d681SAndroid Build Coastguard Workerdefm SREM : I3<"rem.s", srem>;
451*9880d681SAndroid Build Coastguard Workerdefm UREM : I3<"rem.u", urem>;
452*9880d681SAndroid Build Coastguard Worker
453*9880d681SAndroid Build Coastguard Worker
454*9880d681SAndroid Build Coastguard Worker//
455*9880d681SAndroid Build Coastguard Worker// Wide multiplication
456*9880d681SAndroid Build Coastguard Worker//
457*9880d681SAndroid Build Coastguard Workerdef MULWIDES64 :
458*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int64Regs:$dst), (ins Int32Regs:$a, Int32Regs:$b),
459*9880d681SAndroid Build Coastguard Worker            "mul.wide.s32 \t$dst, $a, $b;", []>;
460*9880d681SAndroid Build Coastguard Workerdef MULWIDES64Imm :
461*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int64Regs:$dst), (ins Int32Regs:$a, i32imm:$b),
462*9880d681SAndroid Build Coastguard Worker            "mul.wide.s32 \t$dst, $a, $b;", []>;
463*9880d681SAndroid Build Coastguard Workerdef MULWIDES64Imm64 :
464*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int64Regs:$dst), (ins Int32Regs:$a, i64imm:$b),
465*9880d681SAndroid Build Coastguard Worker            "mul.wide.s32 \t$dst, $a, $b;", []>;
466*9880d681SAndroid Build Coastguard Worker
467*9880d681SAndroid Build Coastguard Workerdef MULWIDEU64 :
468*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int64Regs:$dst), (ins Int32Regs:$a, Int32Regs:$b),
469*9880d681SAndroid Build Coastguard Worker            "mul.wide.u32 \t$dst, $a, $b;", []>;
470*9880d681SAndroid Build Coastguard Workerdef MULWIDEU64Imm :
471*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int64Regs:$dst), (ins Int32Regs:$a, i32imm:$b),
472*9880d681SAndroid Build Coastguard Worker            "mul.wide.u32 \t$dst, $a, $b;", []>;
473*9880d681SAndroid Build Coastguard Workerdef MULWIDEU64Imm64 :
474*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int64Regs:$dst), (ins Int32Regs:$a, i64imm:$b),
475*9880d681SAndroid Build Coastguard Worker            "mul.wide.u32 \t$dst, $a, $b;", []>;
476*9880d681SAndroid Build Coastguard Worker
477*9880d681SAndroid Build Coastguard Workerdef MULWIDES32 :
478*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst), (ins Int16Regs:$a, Int16Regs:$b),
479*9880d681SAndroid Build Coastguard Worker            "mul.wide.s16 \t$dst, $a, $b;", []>;
480*9880d681SAndroid Build Coastguard Workerdef MULWIDES32Imm :
481*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst), (ins Int16Regs:$a, i16imm:$b),
482*9880d681SAndroid Build Coastguard Worker            "mul.wide.s16 \t$dst, $a, $b;", []>;
483*9880d681SAndroid Build Coastguard Workerdef MULWIDES32Imm32 :
484*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst), (ins Int16Regs:$a, i32imm:$b),
485*9880d681SAndroid Build Coastguard Worker            "mul.wide.s16 \t$dst, $a, $b;", []>;
486*9880d681SAndroid Build Coastguard Worker
487*9880d681SAndroid Build Coastguard Workerdef MULWIDEU32 :
488*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst), (ins Int16Regs:$a, Int16Regs:$b),
489*9880d681SAndroid Build Coastguard Worker            "mul.wide.u16 \t$dst, $a, $b;", []>;
490*9880d681SAndroid Build Coastguard Workerdef MULWIDEU32Imm :
491*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst), (ins Int16Regs:$a, i16imm:$b),
492*9880d681SAndroid Build Coastguard Worker            "mul.wide.u16 \t$dst, $a, $b;", []>;
493*9880d681SAndroid Build Coastguard Workerdef MULWIDEU32Imm32 :
494*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst), (ins Int16Regs:$a, i32imm:$b),
495*9880d681SAndroid Build Coastguard Worker            "mul.wide.u16 \t$dst, $a, $b;", []>;
496*9880d681SAndroid Build Coastguard Worker
497*9880d681SAndroid Build Coastguard Workerdef SDTMulWide : SDTypeProfile<1, 2, [SDTCisSameAs<1, 2>]>;
498*9880d681SAndroid Build Coastguard Workerdef mul_wide_signed : SDNode<"NVPTXISD::MUL_WIDE_SIGNED", SDTMulWide>;
499*9880d681SAndroid Build Coastguard Workerdef mul_wide_unsigned : SDNode<"NVPTXISD::MUL_WIDE_UNSIGNED", SDTMulWide>;
500*9880d681SAndroid Build Coastguard Worker
501*9880d681SAndroid Build Coastguard Worker// Matchers for signed, unsigned mul.wide ISD nodes.
502*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (mul_wide_signed Int16Regs:$a, Int16Regs:$b)),
503*9880d681SAndroid Build Coastguard Worker          (MULWIDES32 Int16Regs:$a, Int16Regs:$b)>,
504*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
505*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (mul_wide_signed Int16Regs:$a, imm:$b)),
506*9880d681SAndroid Build Coastguard Worker          (MULWIDES32Imm Int16Regs:$a, imm:$b)>,
507*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
508*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (mul_wide_unsigned Int16Regs:$a, Int16Regs:$b)),
509*9880d681SAndroid Build Coastguard Worker          (MULWIDEU32 Int16Regs:$a, Int16Regs:$b)>,
510*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
511*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (mul_wide_unsigned Int16Regs:$a, imm:$b)),
512*9880d681SAndroid Build Coastguard Worker          (MULWIDEU32Imm Int16Regs:$a, imm:$b)>,
513*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
514*9880d681SAndroid Build Coastguard Worker
515*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (mul_wide_signed Int32Regs:$a, Int32Regs:$b)),
516*9880d681SAndroid Build Coastguard Worker          (MULWIDES64 Int32Regs:$a, Int32Regs:$b)>,
517*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
518*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (mul_wide_signed Int32Regs:$a, imm:$b)),
519*9880d681SAndroid Build Coastguard Worker          (MULWIDES64Imm Int32Regs:$a, imm:$b)>,
520*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
521*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (mul_wide_unsigned Int32Regs:$a, Int32Regs:$b)),
522*9880d681SAndroid Build Coastguard Worker          (MULWIDEU64 Int32Regs:$a, Int32Regs:$b)>,
523*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
524*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (mul_wide_unsigned Int32Regs:$a, imm:$b)),
525*9880d681SAndroid Build Coastguard Worker          (MULWIDEU64Imm Int32Regs:$a, imm:$b)>,
526*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
527*9880d681SAndroid Build Coastguard Worker
528*9880d681SAndroid Build Coastguard Worker// Predicates used for converting some patterns to mul.wide.
529*9880d681SAndroid Build Coastguard Workerdef SInt32Const : PatLeaf<(imm), [{
530*9880d681SAndroid Build Coastguard Worker  const APInt &v = N->getAPIntValue();
531*9880d681SAndroid Build Coastguard Worker  return v.isSignedIntN(32);
532*9880d681SAndroid Build Coastguard Worker}]>;
533*9880d681SAndroid Build Coastguard Worker
534*9880d681SAndroid Build Coastguard Workerdef UInt32Const : PatLeaf<(imm), [{
535*9880d681SAndroid Build Coastguard Worker  const APInt &v = N->getAPIntValue();
536*9880d681SAndroid Build Coastguard Worker  return v.isIntN(32);
537*9880d681SAndroid Build Coastguard Worker}]>;
538*9880d681SAndroid Build Coastguard Worker
539*9880d681SAndroid Build Coastguard Workerdef SInt16Const : PatLeaf<(imm), [{
540*9880d681SAndroid Build Coastguard Worker  const APInt &v = N->getAPIntValue();
541*9880d681SAndroid Build Coastguard Worker  return v.isSignedIntN(16);
542*9880d681SAndroid Build Coastguard Worker}]>;
543*9880d681SAndroid Build Coastguard Worker
544*9880d681SAndroid Build Coastguard Workerdef UInt16Const : PatLeaf<(imm), [{
545*9880d681SAndroid Build Coastguard Worker  const APInt &v = N->getAPIntValue();
546*9880d681SAndroid Build Coastguard Worker  return v.isIntN(16);
547*9880d681SAndroid Build Coastguard Worker}]>;
548*9880d681SAndroid Build Coastguard Worker
549*9880d681SAndroid Build Coastguard Workerdef Int5Const : PatLeaf<(imm), [{
550*9880d681SAndroid Build Coastguard Worker  // Check if 0 <= v < 32; only then will the result of (x << v) be an int32.
551*9880d681SAndroid Build Coastguard Worker  const APInt &v = N->getAPIntValue();
552*9880d681SAndroid Build Coastguard Worker  return v.sge(0) && v.slt(32);
553*9880d681SAndroid Build Coastguard Worker}]>;
554*9880d681SAndroid Build Coastguard Worker
555*9880d681SAndroid Build Coastguard Workerdef Int4Const : PatLeaf<(imm), [{
556*9880d681SAndroid Build Coastguard Worker  // Check if 0 <= v < 16; only then will the result of (x << v) be an int16.
557*9880d681SAndroid Build Coastguard Worker  const APInt &v = N->getAPIntValue();
558*9880d681SAndroid Build Coastguard Worker  return v.sge(0) && v.slt(16);
559*9880d681SAndroid Build Coastguard Worker}]>;
560*9880d681SAndroid Build Coastguard Worker
561*9880d681SAndroid Build Coastguard Workerdef SHL2MUL32 : SDNodeXForm<imm, [{
562*9880d681SAndroid Build Coastguard Worker  const APInt &v = N->getAPIntValue();
563*9880d681SAndroid Build Coastguard Worker  APInt temp(32, 1);
564*9880d681SAndroid Build Coastguard Worker  return CurDAG->getTargetConstant(temp.shl(v), SDLoc(N), MVT::i32);
565*9880d681SAndroid Build Coastguard Worker}]>;
566*9880d681SAndroid Build Coastguard Worker
567*9880d681SAndroid Build Coastguard Workerdef SHL2MUL16 : SDNodeXForm<imm, [{
568*9880d681SAndroid Build Coastguard Worker  const APInt &v = N->getAPIntValue();
569*9880d681SAndroid Build Coastguard Worker  APInt temp(16, 1);
570*9880d681SAndroid Build Coastguard Worker  return CurDAG->getTargetConstant(temp.shl(v), SDLoc(N), MVT::i16);
571*9880d681SAndroid Build Coastguard Worker}]>;
572*9880d681SAndroid Build Coastguard Worker
573*9880d681SAndroid Build Coastguard Worker// Convert "sign/zero-extend, then shift left by an immediate" to mul.wide.
574*9880d681SAndroid Build Coastguard Workerdef : Pat<(shl (sext Int32Regs:$a), (i32 Int5Const:$b)),
575*9880d681SAndroid Build Coastguard Worker          (MULWIDES64Imm Int32Regs:$a, (SHL2MUL32 node:$b))>,
576*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
577*9880d681SAndroid Build Coastguard Workerdef : Pat<(shl (zext Int32Regs:$a), (i32 Int5Const:$b)),
578*9880d681SAndroid Build Coastguard Worker          (MULWIDEU64Imm Int32Regs:$a, (SHL2MUL32 node:$b))>,
579*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
580*9880d681SAndroid Build Coastguard Worker
581*9880d681SAndroid Build Coastguard Workerdef : Pat<(shl (sext Int16Regs:$a), (i16 Int4Const:$b)),
582*9880d681SAndroid Build Coastguard Worker          (MULWIDES32Imm Int16Regs:$a, (SHL2MUL16 node:$b))>,
583*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
584*9880d681SAndroid Build Coastguard Workerdef : Pat<(shl (zext Int16Regs:$a), (i16 Int4Const:$b)),
585*9880d681SAndroid Build Coastguard Worker          (MULWIDEU32Imm Int16Regs:$a, (SHL2MUL16 node:$b))>,
586*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
587*9880d681SAndroid Build Coastguard Worker
588*9880d681SAndroid Build Coastguard Worker// Convert "sign/zero-extend then multiply" to mul.wide.
589*9880d681SAndroid Build Coastguard Workerdef : Pat<(mul (sext Int32Regs:$a), (sext Int32Regs:$b)),
590*9880d681SAndroid Build Coastguard Worker          (MULWIDES64 Int32Regs:$a, Int32Regs:$b)>,
591*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
592*9880d681SAndroid Build Coastguard Workerdef : Pat<(mul (sext Int32Regs:$a), (i64 SInt32Const:$b)),
593*9880d681SAndroid Build Coastguard Worker          (MULWIDES64Imm64 Int32Regs:$a, (i64 SInt32Const:$b))>,
594*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
595*9880d681SAndroid Build Coastguard Worker
596*9880d681SAndroid Build Coastguard Workerdef : Pat<(mul (zext Int32Regs:$a), (zext Int32Regs:$b)),
597*9880d681SAndroid Build Coastguard Worker          (MULWIDEU64 Int32Regs:$a, Int32Regs:$b)>,
598*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
599*9880d681SAndroid Build Coastguard Workerdef : Pat<(mul (zext Int32Regs:$a), (i64 UInt32Const:$b)),
600*9880d681SAndroid Build Coastguard Worker          (MULWIDEU64Imm64 Int32Regs:$a, (i64 UInt32Const:$b))>,
601*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
602*9880d681SAndroid Build Coastguard Worker
603*9880d681SAndroid Build Coastguard Workerdef : Pat<(mul (sext Int16Regs:$a), (sext Int16Regs:$b)),
604*9880d681SAndroid Build Coastguard Worker          (MULWIDES32 Int16Regs:$a, Int16Regs:$b)>,
605*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
606*9880d681SAndroid Build Coastguard Workerdef : Pat<(mul (sext Int16Regs:$a), (i32 SInt16Const:$b)),
607*9880d681SAndroid Build Coastguard Worker          (MULWIDES32Imm32 Int16Regs:$a, (i32 SInt16Const:$b))>,
608*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
609*9880d681SAndroid Build Coastguard Worker
610*9880d681SAndroid Build Coastguard Workerdef : Pat<(mul (zext Int16Regs:$a), (zext Int16Regs:$b)),
611*9880d681SAndroid Build Coastguard Worker          (MULWIDEU32 Int16Regs:$a, Int16Regs:$b)>,
612*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
613*9880d681SAndroid Build Coastguard Workerdef : Pat<(mul (zext Int16Regs:$a), (i32 UInt16Const:$b)),
614*9880d681SAndroid Build Coastguard Worker          (MULWIDEU32Imm32 Int16Regs:$a, (i32 UInt16Const:$b))>,
615*9880d681SAndroid Build Coastguard Worker      Requires<[doMulWide]>;
616*9880d681SAndroid Build Coastguard Worker
617*9880d681SAndroid Build Coastguard Worker//
618*9880d681SAndroid Build Coastguard Worker// Integer multiply-add
619*9880d681SAndroid Build Coastguard Worker//
620*9880d681SAndroid Build Coastguard Workerdef SDTIMAD :
621*9880d681SAndroid Build Coastguard Worker  SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<2>,
622*9880d681SAndroid Build Coastguard Worker                       SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>]>;
623*9880d681SAndroid Build Coastguard Workerdef imad : SDNode<"NVPTXISD::IMAD", SDTIMAD>;
624*9880d681SAndroid Build Coastguard Worker
625*9880d681SAndroid Build Coastguard Workerdef MAD16rrr :
626*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int16Regs:$dst),
627*9880d681SAndroid Build Coastguard Worker            (ins Int16Regs:$a, Int16Regs:$b, Int16Regs:$c),
628*9880d681SAndroid Build Coastguard Worker            "mad.lo.s16 \t$dst, $a, $b, $c;",
629*9880d681SAndroid Build Coastguard Worker            [(set Int16Regs:$dst, (imad Int16Regs:$a, Int16Regs:$b, Int16Regs:$c))]>;
630*9880d681SAndroid Build Coastguard Workerdef MAD16rri :
631*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int16Regs:$dst),
632*9880d681SAndroid Build Coastguard Worker            (ins Int16Regs:$a, Int16Regs:$b, i16imm:$c),
633*9880d681SAndroid Build Coastguard Worker            "mad.lo.s16 \t$dst, $a, $b, $c;",
634*9880d681SAndroid Build Coastguard Worker            [(set Int16Regs:$dst, (imad Int16Regs:$a, Int16Regs:$b, imm:$c))]>;
635*9880d681SAndroid Build Coastguard Workerdef MAD16rir :
636*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int16Regs:$dst),
637*9880d681SAndroid Build Coastguard Worker            (ins Int16Regs:$a, i16imm:$b, Int16Regs:$c),
638*9880d681SAndroid Build Coastguard Worker            "mad.lo.s16 \t$dst, $a, $b, $c;",
639*9880d681SAndroid Build Coastguard Worker            [(set Int16Regs:$dst, (imad Int16Regs:$a, imm:$b, Int16Regs:$c))]>;
640*9880d681SAndroid Build Coastguard Workerdef MAD16rii :
641*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int16Regs:$dst),
642*9880d681SAndroid Build Coastguard Worker            (ins Int16Regs:$a, i16imm:$b, i16imm:$c),
643*9880d681SAndroid Build Coastguard Worker            "mad.lo.s16 \t$dst, $a, $b, $c;",
644*9880d681SAndroid Build Coastguard Worker            [(set Int16Regs:$dst, (imad Int16Regs:$a, imm:$b, imm:$c))]>;
645*9880d681SAndroid Build Coastguard Worker
646*9880d681SAndroid Build Coastguard Workerdef MAD32rrr :
647*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst),
648*9880d681SAndroid Build Coastguard Worker            (ins Int32Regs:$a, Int32Regs:$b, Int32Regs:$c),
649*9880d681SAndroid Build Coastguard Worker            "mad.lo.s32 \t$dst, $a, $b, $c;",
650*9880d681SAndroid Build Coastguard Worker            [(set Int32Regs:$dst, (imad Int32Regs:$a, Int32Regs:$b, Int32Regs:$c))]>;
651*9880d681SAndroid Build Coastguard Workerdef MAD32rri :
652*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst),
653*9880d681SAndroid Build Coastguard Worker            (ins Int32Regs:$a, Int32Regs:$b, i32imm:$c),
654*9880d681SAndroid Build Coastguard Worker            "mad.lo.s32 \t$dst, $a, $b, $c;",
655*9880d681SAndroid Build Coastguard Worker            [(set Int32Regs:$dst, (imad Int32Regs:$a, Int32Regs:$b, imm:$c))]>;
656*9880d681SAndroid Build Coastguard Workerdef MAD32rir :
657*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst),
658*9880d681SAndroid Build Coastguard Worker            (ins Int32Regs:$a, i32imm:$b, Int32Regs:$c),
659*9880d681SAndroid Build Coastguard Worker            "mad.lo.s32 \t$dst, $a, $b, $c;",
660*9880d681SAndroid Build Coastguard Worker            [(set Int32Regs:$dst, (imad Int32Regs:$a, imm:$b, Int32Regs:$c))]>;
661*9880d681SAndroid Build Coastguard Workerdef MAD32rii :
662*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst),
663*9880d681SAndroid Build Coastguard Worker            (ins Int32Regs:$a, i32imm:$b, i32imm:$c),
664*9880d681SAndroid Build Coastguard Worker            "mad.lo.s32 \t$dst, $a, $b, $c;",
665*9880d681SAndroid Build Coastguard Worker            [(set Int32Regs:$dst, (imad Int32Regs:$a, imm:$b, imm:$c))]>;
666*9880d681SAndroid Build Coastguard Worker
667*9880d681SAndroid Build Coastguard Workerdef MAD64rrr :
668*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int64Regs:$dst),
669*9880d681SAndroid Build Coastguard Worker            (ins Int64Regs:$a, Int64Regs:$b, Int64Regs:$c),
670*9880d681SAndroid Build Coastguard Worker            "mad.lo.s64 \t$dst, $a, $b, $c;",
671*9880d681SAndroid Build Coastguard Worker            [(set Int64Regs:$dst, (imad Int64Regs:$a, Int64Regs:$b, Int64Regs:$c))]>;
672*9880d681SAndroid Build Coastguard Workerdef MAD64rri :
673*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int64Regs:$dst),
674*9880d681SAndroid Build Coastguard Worker            (ins Int64Regs:$a, Int64Regs:$b, i64imm:$c),
675*9880d681SAndroid Build Coastguard Worker            "mad.lo.s64 \t$dst, $a, $b, $c;",
676*9880d681SAndroid Build Coastguard Worker            [(set Int64Regs:$dst, (imad Int64Regs:$a, Int64Regs:$b, imm:$c))]>;
677*9880d681SAndroid Build Coastguard Workerdef MAD64rir :
678*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int64Regs:$dst),
679*9880d681SAndroid Build Coastguard Worker            (ins Int64Regs:$a, i64imm:$b, Int64Regs:$c),
680*9880d681SAndroid Build Coastguard Worker            "mad.lo.s64 \t$dst, $a, $b, $c;",
681*9880d681SAndroid Build Coastguard Worker            [(set Int64Regs:$dst, (imad Int64Regs:$a, imm:$b, Int64Regs:$c))]>;
682*9880d681SAndroid Build Coastguard Workerdef MAD64rii :
683*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int64Regs:$dst),
684*9880d681SAndroid Build Coastguard Worker            (ins Int64Regs:$a, i64imm:$b, i64imm:$c),
685*9880d681SAndroid Build Coastguard Worker            "mad.lo.s64 \t$dst, $a, $b, $c;",
686*9880d681SAndroid Build Coastguard Worker            [(set Int64Regs:$dst, (imad Int64Regs:$a, imm:$b, imm:$c))]>;
687*9880d681SAndroid Build Coastguard Worker
688*9880d681SAndroid Build Coastguard Workerdef INEG16 :
689*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int16Regs:$dst), (ins Int16Regs:$src),
690*9880d681SAndroid Build Coastguard Worker            "neg.s16 \t$dst, $src;",
691*9880d681SAndroid Build Coastguard Worker            [(set Int16Regs:$dst, (ineg Int16Regs:$src))]>;
692*9880d681SAndroid Build Coastguard Workerdef INEG32 :
693*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$src),
694*9880d681SAndroid Build Coastguard Worker            "neg.s32 \t$dst, $src;",
695*9880d681SAndroid Build Coastguard Worker            [(set Int32Regs:$dst, (ineg Int32Regs:$src))]>;
696*9880d681SAndroid Build Coastguard Workerdef INEG64 :
697*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int64Regs:$dst), (ins Int64Regs:$src),
698*9880d681SAndroid Build Coastguard Worker            "neg.s64 \t$dst, $src;",
699*9880d681SAndroid Build Coastguard Worker            [(set Int64Regs:$dst, (ineg Int64Regs:$src))]>;
700*9880d681SAndroid Build Coastguard Worker
701*9880d681SAndroid Build Coastguard Worker//-----------------------------------
702*9880d681SAndroid Build Coastguard Worker// Floating Point Arithmetic
703*9880d681SAndroid Build Coastguard Worker//-----------------------------------
704*9880d681SAndroid Build Coastguard Worker
705*9880d681SAndroid Build Coastguard Worker// Constant 1.0f
706*9880d681SAndroid Build Coastguard Workerdef FloatConst1 : PatLeaf<(fpimm), [{
707*9880d681SAndroid Build Coastguard Worker  return &N->getValueAPF().getSemantics() == &llvm::APFloat::IEEEsingle &&
708*9880d681SAndroid Build Coastguard Worker         N->getValueAPF().convertToFloat() == 1.0f;
709*9880d681SAndroid Build Coastguard Worker}]>;
710*9880d681SAndroid Build Coastguard Worker// Constant 1.0 (double)
711*9880d681SAndroid Build Coastguard Workerdef DoubleConst1 : PatLeaf<(fpimm), [{
712*9880d681SAndroid Build Coastguard Worker  return &N->getValueAPF().getSemantics() == &llvm::APFloat::IEEEdouble &&
713*9880d681SAndroid Build Coastguard Worker         N->getValueAPF().convertToDouble() == 1.0;
714*9880d681SAndroid Build Coastguard Worker}]>;
715*9880d681SAndroid Build Coastguard Worker
716*9880d681SAndroid Build Coastguard Workerdefm FADD : F3<"add", fadd>;
717*9880d681SAndroid Build Coastguard Workerdefm FSUB : F3<"sub", fsub>;
718*9880d681SAndroid Build Coastguard Workerdefm FMUL : F3<"mul", fmul>;
719*9880d681SAndroid Build Coastguard Worker
720*9880d681SAndroid Build Coastguard Workerdefm FADD_rn : F3_rn<"add", fadd>;
721*9880d681SAndroid Build Coastguard Workerdefm FSUB_rn : F3_rn<"sub", fsub>;
722*9880d681SAndroid Build Coastguard Workerdefm FMUL_rn : F3_rn<"mul", fmul>;
723*9880d681SAndroid Build Coastguard Worker
724*9880d681SAndroid Build Coastguard Workerdefm FABS  : F2<"abs", fabs>;
725*9880d681SAndroid Build Coastguard Workerdefm FNEG  : F2<"neg", fneg>;
726*9880d681SAndroid Build Coastguard Workerdefm FSQRT : F2<"sqrt.rn", fsqrt>;
727*9880d681SAndroid Build Coastguard Worker
728*9880d681SAndroid Build Coastguard Worker//
729*9880d681SAndroid Build Coastguard Worker// F64 division
730*9880d681SAndroid Build Coastguard Worker//
731*9880d681SAndroid Build Coastguard Workerdef FDIV641r :
732*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float64Regs:$dst),
733*9880d681SAndroid Build Coastguard Worker            (ins f64imm:$a, Float64Regs:$b),
734*9880d681SAndroid Build Coastguard Worker            "rcp.rn.f64 \t$dst, $b;",
735*9880d681SAndroid Build Coastguard Worker            [(set Float64Regs:$dst, (fdiv DoubleConst1:$a, Float64Regs:$b))]>;
736*9880d681SAndroid Build Coastguard Workerdef FDIV64rr :
737*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float64Regs:$dst),
738*9880d681SAndroid Build Coastguard Worker            (ins Float64Regs:$a, Float64Regs:$b),
739*9880d681SAndroid Build Coastguard Worker            "div.rn.f64 \t$dst, $a, $b;",
740*9880d681SAndroid Build Coastguard Worker            [(set Float64Regs:$dst, (fdiv Float64Regs:$a, Float64Regs:$b))]>;
741*9880d681SAndroid Build Coastguard Workerdef FDIV64ri :
742*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float64Regs:$dst),
743*9880d681SAndroid Build Coastguard Worker            (ins Float64Regs:$a, f64imm:$b),
744*9880d681SAndroid Build Coastguard Worker            "div.rn.f64 \t$dst, $a, $b;",
745*9880d681SAndroid Build Coastguard Worker            [(set Float64Regs:$dst, (fdiv Float64Regs:$a, fpimm:$b))]>;
746*9880d681SAndroid Build Coastguard Worker
747*9880d681SAndroid Build Coastguard Worker//
748*9880d681SAndroid Build Coastguard Worker// F32 Approximate reciprocal
749*9880d681SAndroid Build Coastguard Worker//
750*9880d681SAndroid Build Coastguard Workerdef FDIV321r_ftz :
751*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
752*9880d681SAndroid Build Coastguard Worker            (ins f32imm:$a, Float32Regs:$b),
753*9880d681SAndroid Build Coastguard Worker            "rcp.approx.ftz.f32 \t$dst, $b;",
754*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv FloatConst1:$a, Float32Regs:$b))]>,
755*9880d681SAndroid Build Coastguard Worker            Requires<[do_DIVF32_APPROX, doF32FTZ]>;
756*9880d681SAndroid Build Coastguard Workerdef FDIV321r :
757*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
758*9880d681SAndroid Build Coastguard Worker            (ins f32imm:$a, Float32Regs:$b),
759*9880d681SAndroid Build Coastguard Worker            "rcp.approx.f32 \t$dst, $b;",
760*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv FloatConst1:$a, Float32Regs:$b))]>,
761*9880d681SAndroid Build Coastguard Worker            Requires<[do_DIVF32_APPROX]>;
762*9880d681SAndroid Build Coastguard Worker//
763*9880d681SAndroid Build Coastguard Worker// F32 Approximate division
764*9880d681SAndroid Build Coastguard Worker//
765*9880d681SAndroid Build Coastguard Workerdef FDIV32approxrr_ftz :
766*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
767*9880d681SAndroid Build Coastguard Worker            (ins Float32Regs:$a, Float32Regs:$b),
768*9880d681SAndroid Build Coastguard Worker            "div.approx.ftz.f32 \t$dst, $a, $b;",
769*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv Float32Regs:$a, Float32Regs:$b))]>,
770*9880d681SAndroid Build Coastguard Worker            Requires<[do_DIVF32_APPROX, doF32FTZ]>;
771*9880d681SAndroid Build Coastguard Workerdef FDIV32approxri_ftz :
772*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
773*9880d681SAndroid Build Coastguard Worker            (ins Float32Regs:$a, f32imm:$b),
774*9880d681SAndroid Build Coastguard Worker            "div.approx.ftz.f32 \t$dst, $a, $b;",
775*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv Float32Regs:$a, fpimm:$b))]>,
776*9880d681SAndroid Build Coastguard Worker            Requires<[do_DIVF32_APPROX, doF32FTZ]>;
777*9880d681SAndroid Build Coastguard Workerdef FDIV32approxrr :
778*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
779*9880d681SAndroid Build Coastguard Worker            (ins Float32Regs:$a, Float32Regs:$b),
780*9880d681SAndroid Build Coastguard Worker            "div.approx.f32 \t$dst, $a, $b;",
781*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv Float32Regs:$a, Float32Regs:$b))]>,
782*9880d681SAndroid Build Coastguard Worker            Requires<[do_DIVF32_APPROX]>;
783*9880d681SAndroid Build Coastguard Workerdef FDIV32approxri :
784*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
785*9880d681SAndroid Build Coastguard Worker            (ins Float32Regs:$a, f32imm:$b),
786*9880d681SAndroid Build Coastguard Worker            "div.approx.f32 \t$dst, $a, $b;",
787*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv Float32Regs:$a, fpimm:$b))]>,
788*9880d681SAndroid Build Coastguard Worker            Requires<[do_DIVF32_APPROX]>;
789*9880d681SAndroid Build Coastguard Worker//
790*9880d681SAndroid Build Coastguard Worker// F32 Semi-accurate reciprocal
791*9880d681SAndroid Build Coastguard Worker//
792*9880d681SAndroid Build Coastguard Worker// rcp.approx gives the same result as div.full(1.0f, a) and is faster.
793*9880d681SAndroid Build Coastguard Worker//
794*9880d681SAndroid Build Coastguard Workerdef FDIV321r_approx_ftz :
795*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
796*9880d681SAndroid Build Coastguard Worker            (ins f32imm:$a, Float32Regs:$b),
797*9880d681SAndroid Build Coastguard Worker            "rcp.approx.ftz.f32 \t$dst, $b;",
798*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv FloatConst1:$a, Float32Regs:$b))]>,
799*9880d681SAndroid Build Coastguard Worker            Requires<[do_DIVF32_FULL, doF32FTZ]>;
800*9880d681SAndroid Build Coastguard Workerdef FDIV321r_approx :
801*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
802*9880d681SAndroid Build Coastguard Worker            (ins f32imm:$a, Float32Regs:$b),
803*9880d681SAndroid Build Coastguard Worker            "rcp.approx.f32 \t$dst, $b;",
804*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv FloatConst1:$a, Float32Regs:$b))]>,
805*9880d681SAndroid Build Coastguard Worker            Requires<[do_DIVF32_FULL]>;
806*9880d681SAndroid Build Coastguard Worker//
807*9880d681SAndroid Build Coastguard Worker// F32 Semi-accurate division
808*9880d681SAndroid Build Coastguard Worker//
809*9880d681SAndroid Build Coastguard Workerdef FDIV32rr_ftz :
810*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
811*9880d681SAndroid Build Coastguard Worker            (ins Float32Regs:$a, Float32Regs:$b),
812*9880d681SAndroid Build Coastguard Worker            "div.full.ftz.f32 \t$dst, $a, $b;",
813*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv Float32Regs:$a, Float32Regs:$b))]>,
814*9880d681SAndroid Build Coastguard Worker            Requires<[do_DIVF32_FULL, doF32FTZ]>;
815*9880d681SAndroid Build Coastguard Workerdef FDIV32ri_ftz :
816*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
817*9880d681SAndroid Build Coastguard Worker            (ins Float32Regs:$a, f32imm:$b),
818*9880d681SAndroid Build Coastguard Worker            "div.full.ftz.f32 \t$dst, $a, $b;",
819*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv Float32Regs:$a, fpimm:$b))]>,
820*9880d681SAndroid Build Coastguard Worker            Requires<[do_DIVF32_FULL, doF32FTZ]>;
821*9880d681SAndroid Build Coastguard Workerdef FDIV32rr :
822*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
823*9880d681SAndroid Build Coastguard Worker            (ins Float32Regs:$a, Float32Regs:$b),
824*9880d681SAndroid Build Coastguard Worker            "div.full.f32 \t$dst, $a, $b;",
825*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv Float32Regs:$a, Float32Regs:$b))]>,
826*9880d681SAndroid Build Coastguard Worker            Requires<[do_DIVF32_FULL]>;
827*9880d681SAndroid Build Coastguard Workerdef FDIV32ri :
828*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
829*9880d681SAndroid Build Coastguard Worker            (ins Float32Regs:$a, f32imm:$b),
830*9880d681SAndroid Build Coastguard Worker            "div.full.f32 \t$dst, $a, $b;",
831*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv Float32Regs:$a, fpimm:$b))]>,
832*9880d681SAndroid Build Coastguard Worker            Requires<[do_DIVF32_FULL]>;
833*9880d681SAndroid Build Coastguard Worker//
834*9880d681SAndroid Build Coastguard Worker// F32 Accurate reciprocal
835*9880d681SAndroid Build Coastguard Worker//
836*9880d681SAndroid Build Coastguard Workerdef FDIV321r_prec_ftz :
837*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
838*9880d681SAndroid Build Coastguard Worker            (ins f32imm:$a, Float32Regs:$b),
839*9880d681SAndroid Build Coastguard Worker            "rcp.rn.ftz.f32 \t$dst, $b;",
840*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv FloatConst1:$a, Float32Regs:$b))]>,
841*9880d681SAndroid Build Coastguard Worker            Requires<[reqPTX20, doF32FTZ]>;
842*9880d681SAndroid Build Coastguard Workerdef FDIV321r_prec :
843*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
844*9880d681SAndroid Build Coastguard Worker            (ins f32imm:$a, Float32Regs:$b),
845*9880d681SAndroid Build Coastguard Worker            "rcp.rn.f32 \t$dst, $b;",
846*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv FloatConst1:$a, Float32Regs:$b))]>,
847*9880d681SAndroid Build Coastguard Worker            Requires<[reqPTX20]>;
848*9880d681SAndroid Build Coastguard Worker//
849*9880d681SAndroid Build Coastguard Worker// F32 Accurate division
850*9880d681SAndroid Build Coastguard Worker//
851*9880d681SAndroid Build Coastguard Workerdef FDIV32rr_prec_ftz :
852*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
853*9880d681SAndroid Build Coastguard Worker            (ins Float32Regs:$a, Float32Regs:$b),
854*9880d681SAndroid Build Coastguard Worker            "div.rn.ftz.f32 \t$dst, $a, $b;",
855*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv Float32Regs:$a, Float32Regs:$b))]>,
856*9880d681SAndroid Build Coastguard Worker            Requires<[doF32FTZ, reqPTX20]>;
857*9880d681SAndroid Build Coastguard Workerdef FDIV32ri_prec_ftz :
858*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
859*9880d681SAndroid Build Coastguard Worker            (ins Float32Regs:$a, f32imm:$b),
860*9880d681SAndroid Build Coastguard Worker            "div.rn.ftz.f32 \t$dst, $a, $b;",
861*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv Float32Regs:$a, fpimm:$b))]>,
862*9880d681SAndroid Build Coastguard Worker            Requires<[doF32FTZ, reqPTX20]>;
863*9880d681SAndroid Build Coastguard Workerdef FDIV32rr_prec :
864*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
865*9880d681SAndroid Build Coastguard Worker            (ins Float32Regs:$a, Float32Regs:$b),
866*9880d681SAndroid Build Coastguard Worker            "div.rn.f32 \t$dst, $a, $b;",
867*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv Float32Regs:$a, Float32Regs:$b))]>,
868*9880d681SAndroid Build Coastguard Worker            Requires<[reqPTX20]>;
869*9880d681SAndroid Build Coastguard Workerdef FDIV32ri_prec :
870*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Float32Regs:$dst),
871*9880d681SAndroid Build Coastguard Worker            (ins Float32Regs:$a, f32imm:$b),
872*9880d681SAndroid Build Coastguard Worker            "div.rn.f32 \t$dst, $a, $b;",
873*9880d681SAndroid Build Coastguard Worker            [(set Float32Regs:$dst, (fdiv Float32Regs:$a, fpimm:$b))]>,
874*9880d681SAndroid Build Coastguard Worker            Requires<[reqPTX20]>;
875*9880d681SAndroid Build Coastguard Worker
876*9880d681SAndroid Build Coastguard Worker//
877*9880d681SAndroid Build Coastguard Worker// F32 rsqrt
878*9880d681SAndroid Build Coastguard Worker//
879*9880d681SAndroid Build Coastguard Worker
880*9880d681SAndroid Build Coastguard Workerdef RSQRTF32approx1r : NVPTXInst<(outs Float32Regs:$dst), (ins Float32Regs:$b),
881*9880d681SAndroid Build Coastguard Worker                       "rsqrt.approx.f32 \t$dst, $b;", []>;
882*9880d681SAndroid Build Coastguard Worker
883*9880d681SAndroid Build Coastguard Worker// Convert 1.0f/sqrt(x) to rsqrt.approx.f32.  (There is an rsqrt.approx.f64, but
884*9880d681SAndroid Build Coastguard Worker// it's emulated in software.)
885*9880d681SAndroid Build Coastguard Workerdef: Pat<(fdiv FloatConst1, (int_nvvm_sqrt_f Float32Regs:$b)),
886*9880d681SAndroid Build Coastguard Worker         (RSQRTF32approx1r Float32Regs:$b)>,
887*9880d681SAndroid Build Coastguard Worker         Requires<[do_DIVF32_FULL, do_SQRTF32_APPROX, doNoF32FTZ]>;
888*9880d681SAndroid Build Coastguard Worker
889*9880d681SAndroid Build Coastguard Workermulticlass FMA<string OpcStr, RegisterClass RC, Operand ImmCls, Predicate Pred> {
890*9880d681SAndroid Build Coastguard Worker   def rrr : NVPTXInst<(outs RC:$dst), (ins RC:$a, RC:$b, RC:$c),
891*9880d681SAndroid Build Coastguard Worker                       !strconcat(OpcStr, " \t$dst, $a, $b, $c;"),
892*9880d681SAndroid Build Coastguard Worker                       [(set RC:$dst, (fma RC:$a, RC:$b, RC:$c))]>,
893*9880d681SAndroid Build Coastguard Worker                       Requires<[Pred]>;
894*9880d681SAndroid Build Coastguard Worker   def rri : NVPTXInst<(outs RC:$dst),
895*9880d681SAndroid Build Coastguard Worker                       (ins RC:$a, RC:$b, ImmCls:$c),
896*9880d681SAndroid Build Coastguard Worker                       !strconcat(OpcStr, " \t$dst, $a, $b, $c;"),
897*9880d681SAndroid Build Coastguard Worker                       [(set RC:$dst, (fma RC:$a, RC:$b, fpimm:$c))]>,
898*9880d681SAndroid Build Coastguard Worker                       Requires<[Pred]>;
899*9880d681SAndroid Build Coastguard Worker   def rir : NVPTXInst<(outs RC:$dst),
900*9880d681SAndroid Build Coastguard Worker                       (ins RC:$a, ImmCls:$b, RC:$c),
901*9880d681SAndroid Build Coastguard Worker                       !strconcat(OpcStr, " \t$dst, $a, $b, $c;"),
902*9880d681SAndroid Build Coastguard Worker                       [(set RC:$dst, (fma RC:$a, fpimm:$b, RC:$c))]>,
903*9880d681SAndroid Build Coastguard Worker                       Requires<[Pred]>;
904*9880d681SAndroid Build Coastguard Worker   def rii : NVPTXInst<(outs RC:$dst),
905*9880d681SAndroid Build Coastguard Worker                       (ins RC:$a, ImmCls:$b, ImmCls:$c),
906*9880d681SAndroid Build Coastguard Worker                       !strconcat(OpcStr, " \t$dst, $a, $b, $c;"),
907*9880d681SAndroid Build Coastguard Worker                       [(set RC:$dst, (fma RC:$a, fpimm:$b, fpimm:$c))]>,
908*9880d681SAndroid Build Coastguard Worker                       Requires<[Pred]>;
909*9880d681SAndroid Build Coastguard Worker}
910*9880d681SAndroid Build Coastguard Worker
911*9880d681SAndroid Build Coastguard Workerdefm FMA32_ftz : FMA<"fma.rn.ftz.f32", Float32Regs, f32imm, doF32FTZ>;
912*9880d681SAndroid Build Coastguard Workerdefm FMA32     : FMA<"fma.rn.f32", Float32Regs, f32imm, true>;
913*9880d681SAndroid Build Coastguard Workerdefm FMA64     : FMA<"fma.rn.f64", Float64Regs, f64imm, true>;
914*9880d681SAndroid Build Coastguard Worker
915*9880d681SAndroid Build Coastguard Worker// sin/cos
916*9880d681SAndroid Build Coastguard Workerdef SINF:  NVPTXInst<(outs Float32Regs:$dst), (ins Float32Regs:$src),
917*9880d681SAndroid Build Coastguard Worker                      "sin.approx.f32 \t$dst, $src;",
918*9880d681SAndroid Build Coastguard Worker                      [(set Float32Regs:$dst, (fsin Float32Regs:$src))]>;
919*9880d681SAndroid Build Coastguard Workerdef COSF:  NVPTXInst<(outs Float32Regs:$dst), (ins Float32Regs:$src),
920*9880d681SAndroid Build Coastguard Worker                      "cos.approx.f32 \t$dst, $src;",
921*9880d681SAndroid Build Coastguard Worker                      [(set Float32Regs:$dst, (fcos Float32Regs:$src))]>;
922*9880d681SAndroid Build Coastguard Worker
923*9880d681SAndroid Build Coastguard Worker// Lower (frem x, y) into (sub x, (mul (floor (div x, y)) y)),
924*9880d681SAndroid Build Coastguard Worker// i.e. "poor man's fmod()"
925*9880d681SAndroid Build Coastguard Worker
926*9880d681SAndroid Build Coastguard Worker// frem - f32 FTZ
927*9880d681SAndroid Build Coastguard Workerdef : Pat<(frem Float32Regs:$x, Float32Regs:$y),
928*9880d681SAndroid Build Coastguard Worker          (FSUBf32rr_ftz Float32Regs:$x, (FMULf32rr_ftz (CVT_f32_f32
929*9880d681SAndroid Build Coastguard Worker            (FDIV32rr_prec_ftz Float32Regs:$x, Float32Regs:$y), CvtRMI_FTZ),
930*9880d681SAndroid Build Coastguard Worker             Float32Regs:$y))>,
931*9880d681SAndroid Build Coastguard Worker          Requires<[doF32FTZ]>;
932*9880d681SAndroid Build Coastguard Workerdef : Pat<(frem Float32Regs:$x, fpimm:$y),
933*9880d681SAndroid Build Coastguard Worker          (FSUBf32rr_ftz Float32Regs:$x, (FMULf32ri_ftz (CVT_f32_f32
934*9880d681SAndroid Build Coastguard Worker            (FDIV32ri_prec_ftz Float32Regs:$x, fpimm:$y), CvtRMI_FTZ),
935*9880d681SAndroid Build Coastguard Worker             fpimm:$y))>,
936*9880d681SAndroid Build Coastguard Worker          Requires<[doF32FTZ]>;
937*9880d681SAndroid Build Coastguard Worker
938*9880d681SAndroid Build Coastguard Worker// frem - f32
939*9880d681SAndroid Build Coastguard Workerdef : Pat<(frem Float32Regs:$x, Float32Regs:$y),
940*9880d681SAndroid Build Coastguard Worker          (FSUBf32rr Float32Regs:$x, (FMULf32rr (CVT_f32_f32
941*9880d681SAndroid Build Coastguard Worker            (FDIV32rr_prec Float32Regs:$x, Float32Regs:$y), CvtRMI),
942*9880d681SAndroid Build Coastguard Worker             Float32Regs:$y))>;
943*9880d681SAndroid Build Coastguard Workerdef : Pat<(frem Float32Regs:$x, fpimm:$y),
944*9880d681SAndroid Build Coastguard Worker          (FSUBf32rr Float32Regs:$x, (FMULf32ri (CVT_f32_f32
945*9880d681SAndroid Build Coastguard Worker            (FDIV32ri_prec Float32Regs:$x, fpimm:$y), CvtRMI),
946*9880d681SAndroid Build Coastguard Worker             fpimm:$y))>;
947*9880d681SAndroid Build Coastguard Worker
948*9880d681SAndroid Build Coastguard Worker// frem - f64
949*9880d681SAndroid Build Coastguard Workerdef : Pat<(frem Float64Regs:$x, Float64Regs:$y),
950*9880d681SAndroid Build Coastguard Worker          (FSUBf64rr Float64Regs:$x, (FMULf64rr (CVT_f64_f64
951*9880d681SAndroid Build Coastguard Worker            (FDIV64rr Float64Regs:$x, Float64Regs:$y), CvtRMI),
952*9880d681SAndroid Build Coastguard Worker             Float64Regs:$y))>;
953*9880d681SAndroid Build Coastguard Workerdef : Pat<(frem Float64Regs:$x, fpimm:$y),
954*9880d681SAndroid Build Coastguard Worker          (FSUBf64rr Float64Regs:$x, (FMULf64ri (CVT_f64_f64
955*9880d681SAndroid Build Coastguard Worker            (FDIV64ri Float64Regs:$x, fpimm:$y), CvtRMI),
956*9880d681SAndroid Build Coastguard Worker             fpimm:$y))>;
957*9880d681SAndroid Build Coastguard Worker
958*9880d681SAndroid Build Coastguard Worker//-----------------------------------
959*9880d681SAndroid Build Coastguard Worker// Bitwise operations
960*9880d681SAndroid Build Coastguard Worker//-----------------------------------
961*9880d681SAndroid Build Coastguard Worker
962*9880d681SAndroid Build Coastguard Worker// Template for three-arg bitwise operations.  Takes three args, Creates .b16,
963*9880d681SAndroid Build Coastguard Worker// .b32, .b64, and .pred (predicate registers -- i.e., i1) versions of OpcStr.
964*9880d681SAndroid Build Coastguard Workermulticlass BITWISE<string OpcStr, SDNode OpNode> {
965*9880d681SAndroid Build Coastguard Worker  def b1rr :
966*9880d681SAndroid Build Coastguard Worker    NVPTXInst<(outs Int1Regs:$dst), (ins Int1Regs:$a, Int1Regs:$b),
967*9880d681SAndroid Build Coastguard Worker              !strconcat(OpcStr, ".pred  \t$dst, $a, $b;"),
968*9880d681SAndroid Build Coastguard Worker              [(set Int1Regs:$dst, (OpNode Int1Regs:$a, Int1Regs:$b))]>;
969*9880d681SAndroid Build Coastguard Worker  def b1ri :
970*9880d681SAndroid Build Coastguard Worker    NVPTXInst<(outs Int1Regs:$dst), (ins Int1Regs:$a, i1imm:$b),
971*9880d681SAndroid Build Coastguard Worker              !strconcat(OpcStr, ".pred  \t$dst, $a, $b;"),
972*9880d681SAndroid Build Coastguard Worker              [(set Int1Regs:$dst, (OpNode Int1Regs:$a, imm:$b))]>;
973*9880d681SAndroid Build Coastguard Worker  def b16rr :
974*9880d681SAndroid Build Coastguard Worker    NVPTXInst<(outs Int16Regs:$dst), (ins Int16Regs:$a, Int16Regs:$b),
975*9880d681SAndroid Build Coastguard Worker              !strconcat(OpcStr, ".b16  \t$dst, $a, $b;"),
976*9880d681SAndroid Build Coastguard Worker              [(set Int16Regs:$dst, (OpNode Int16Regs:$a, Int16Regs:$b))]>;
977*9880d681SAndroid Build Coastguard Worker  def b16ri :
978*9880d681SAndroid Build Coastguard Worker    NVPTXInst<(outs Int16Regs:$dst), (ins Int16Regs:$a, i16imm:$b),
979*9880d681SAndroid Build Coastguard Worker              !strconcat(OpcStr, ".b16  \t$dst, $a, $b;"),
980*9880d681SAndroid Build Coastguard Worker              [(set Int16Regs:$dst, (OpNode Int16Regs:$a, imm:$b))]>;
981*9880d681SAndroid Build Coastguard Worker  def b32rr :
982*9880d681SAndroid Build Coastguard Worker    NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$a, Int32Regs:$b),
983*9880d681SAndroid Build Coastguard Worker              !strconcat(OpcStr, ".b32  \t$dst, $a, $b;"),
984*9880d681SAndroid Build Coastguard Worker              [(set Int32Regs:$dst, (OpNode Int32Regs:$a, Int32Regs:$b))]>;
985*9880d681SAndroid Build Coastguard Worker  def b32ri :
986*9880d681SAndroid Build Coastguard Worker    NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$a, i32imm:$b),
987*9880d681SAndroid Build Coastguard Worker              !strconcat(OpcStr, ".b32  \t$dst, $a, $b;"),
988*9880d681SAndroid Build Coastguard Worker              [(set Int32Regs:$dst, (OpNode Int32Regs:$a, imm:$b))]>;
989*9880d681SAndroid Build Coastguard Worker  def b64rr :
990*9880d681SAndroid Build Coastguard Worker    NVPTXInst<(outs Int64Regs:$dst), (ins Int64Regs:$a, Int64Regs:$b),
991*9880d681SAndroid Build Coastguard Worker              !strconcat(OpcStr, ".b64  \t$dst, $a, $b;"),
992*9880d681SAndroid Build Coastguard Worker              [(set Int64Regs:$dst, (OpNode Int64Regs:$a, Int64Regs:$b))]>;
993*9880d681SAndroid Build Coastguard Worker  def b64ri :
994*9880d681SAndroid Build Coastguard Worker    NVPTXInst<(outs Int64Regs:$dst), (ins Int64Regs:$a, i64imm:$b),
995*9880d681SAndroid Build Coastguard Worker              !strconcat(OpcStr, ".b64  \t$dst, $a, $b;"),
996*9880d681SAndroid Build Coastguard Worker              [(set Int64Regs:$dst, (OpNode Int64Regs:$a, imm:$b))]>;
997*9880d681SAndroid Build Coastguard Worker}
998*9880d681SAndroid Build Coastguard Worker
999*9880d681SAndroid Build Coastguard Workerdefm OR  : BITWISE<"or", or>;
1000*9880d681SAndroid Build Coastguard Workerdefm AND : BITWISE<"and", and>;
1001*9880d681SAndroid Build Coastguard Workerdefm XOR : BITWISE<"xor", xor>;
1002*9880d681SAndroid Build Coastguard Worker
1003*9880d681SAndroid Build Coastguard Workerdef NOT1  : NVPTXInst<(outs Int1Regs:$dst), (ins Int1Regs:$src),
1004*9880d681SAndroid Build Coastguard Worker                      "not.pred \t$dst, $src;",
1005*9880d681SAndroid Build Coastguard Worker                      [(set Int1Regs:$dst, (not Int1Regs:$src))]>;
1006*9880d681SAndroid Build Coastguard Workerdef NOT16 : NVPTXInst<(outs Int16Regs:$dst), (ins Int16Regs:$src),
1007*9880d681SAndroid Build Coastguard Worker                      "not.b16 \t$dst, $src;",
1008*9880d681SAndroid Build Coastguard Worker                      [(set Int16Regs:$dst, (not Int16Regs:$src))]>;
1009*9880d681SAndroid Build Coastguard Workerdef NOT32 : NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$src),
1010*9880d681SAndroid Build Coastguard Worker                      "not.b32 \t$dst, $src;",
1011*9880d681SAndroid Build Coastguard Worker                      [(set Int32Regs:$dst, (not Int32Regs:$src))]>;
1012*9880d681SAndroid Build Coastguard Workerdef NOT64 : NVPTXInst<(outs Int64Regs:$dst), (ins Int64Regs:$src),
1013*9880d681SAndroid Build Coastguard Worker                       "not.b64 \t$dst, $src;",
1014*9880d681SAndroid Build Coastguard Worker                       [(set Int64Regs:$dst, (not Int64Regs:$src))]>;
1015*9880d681SAndroid Build Coastguard Worker
1016*9880d681SAndroid Build Coastguard Worker// Template for left/right shifts.  Takes three operands,
1017*9880d681SAndroid Build Coastguard Worker//   [dest (reg), src (reg), shift (reg or imm)].
1018*9880d681SAndroid Build Coastguard Worker// dest and src may be int64, int32, or int16, but shift is always int32.
1019*9880d681SAndroid Build Coastguard Worker//
1020*9880d681SAndroid Build Coastguard Worker// This template also defines a 32-bit shift (imm, imm) instruction.
1021*9880d681SAndroid Build Coastguard Workermulticlass SHIFT<string OpcStr, SDNode OpNode> {
1022*9880d681SAndroid Build Coastguard Worker   def i64rr :
1023*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Int64Regs:$dst), (ins Int64Regs:$a, Int32Regs:$b),
1024*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, "64 \t$dst, $a, $b;"),
1025*9880d681SAndroid Build Coastguard Worker               [(set Int64Regs:$dst, (OpNode Int64Regs:$a, Int32Regs:$b))]>;
1026*9880d681SAndroid Build Coastguard Worker   def i64ri :
1027*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Int64Regs:$dst), (ins Int64Regs:$a, i32imm:$b),
1028*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, "64 \t$dst, $a, $b;"),
1029*9880d681SAndroid Build Coastguard Worker               [(set Int64Regs:$dst, (OpNode Int64Regs:$a, (i32 imm:$b)))]>;
1030*9880d681SAndroid Build Coastguard Worker   def i32rr :
1031*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$a, Int32Regs:$b),
1032*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, "32 \t$dst, $a, $b;"),
1033*9880d681SAndroid Build Coastguard Worker               [(set Int32Regs:$dst, (OpNode Int32Regs:$a, Int32Regs:$b))]>;
1034*9880d681SAndroid Build Coastguard Worker   def i32ri :
1035*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$a, i32imm:$b),
1036*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, "32 \t$dst, $a, $b;"),
1037*9880d681SAndroid Build Coastguard Worker               [(set Int32Regs:$dst, (OpNode Int32Regs:$a, (i32 imm:$b)))]>;
1038*9880d681SAndroid Build Coastguard Worker   def i32ii :
1039*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Int32Regs:$dst), (ins i32imm:$a, i32imm:$b),
1040*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, "32 \t$dst, $a, $b;"),
1041*9880d681SAndroid Build Coastguard Worker               [(set Int32Regs:$dst, (OpNode (i32 imm:$a), (i32 imm:$b)))]>;
1042*9880d681SAndroid Build Coastguard Worker   def i16rr :
1043*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Int16Regs:$dst), (ins Int16Regs:$a, Int32Regs:$b),
1044*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, "16 \t$dst, $a, $b;"),
1045*9880d681SAndroid Build Coastguard Worker               [(set Int16Regs:$dst, (OpNode Int16Regs:$a, Int32Regs:$b))]>;
1046*9880d681SAndroid Build Coastguard Worker   def i16ri :
1047*9880d681SAndroid Build Coastguard Worker     NVPTXInst<(outs Int16Regs:$dst), (ins Int16Regs:$a, i32imm:$b),
1048*9880d681SAndroid Build Coastguard Worker               !strconcat(OpcStr, "16 \t$dst, $a, $b;"),
1049*9880d681SAndroid Build Coastguard Worker               [(set Int16Regs:$dst, (OpNode Int16Regs:$a, (i32 imm:$b)))]>;
1050*9880d681SAndroid Build Coastguard Worker}
1051*9880d681SAndroid Build Coastguard Worker
1052*9880d681SAndroid Build Coastguard Workerdefm SHL : SHIFT<"shl.b", shl>;
1053*9880d681SAndroid Build Coastguard Workerdefm SRA : SHIFT<"shr.s", sra>;
1054*9880d681SAndroid Build Coastguard Workerdefm SRL : SHIFT<"shr.u", srl>;
1055*9880d681SAndroid Build Coastguard Worker
1056*9880d681SAndroid Build Coastguard Worker//
1057*9880d681SAndroid Build Coastguard Worker// Rotate: Use ptx shf instruction if available.
1058*9880d681SAndroid Build Coastguard Worker//
1059*9880d681SAndroid Build Coastguard Worker
1060*9880d681SAndroid Build Coastguard Worker// 32 bit r2 = rotl r1, n
1061*9880d681SAndroid Build Coastguard Worker//    =>
1062*9880d681SAndroid Build Coastguard Worker//        r2 = shf.l r1, r1, n
1063*9880d681SAndroid Build Coastguard Workerdef ROTL32imm_hw :
1064*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$src, i32imm:$amt),
1065*9880d681SAndroid Build Coastguard Worker            "shf.l.wrap.b32 \t$dst, $src, $src, $amt;",
1066*9880d681SAndroid Build Coastguard Worker            [(set Int32Regs:$dst, (rotl Int32Regs:$src, (i32 imm:$amt)))]>,
1067*9880d681SAndroid Build Coastguard Worker           Requires<[hasHWROT32]>;
1068*9880d681SAndroid Build Coastguard Worker
1069*9880d681SAndroid Build Coastguard Workerdef ROTL32reg_hw :
1070*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$src, Int32Regs:$amt),
1071*9880d681SAndroid Build Coastguard Worker            "shf.l.wrap.b32 \t$dst, $src, $src, $amt;",
1072*9880d681SAndroid Build Coastguard Worker            [(set Int32Regs:$dst, (rotl Int32Regs:$src, Int32Regs:$amt))]>,
1073*9880d681SAndroid Build Coastguard Worker           Requires<[hasHWROT32]>;
1074*9880d681SAndroid Build Coastguard Worker
1075*9880d681SAndroid Build Coastguard Worker// 32 bit r2 = rotr r1, n
1076*9880d681SAndroid Build Coastguard Worker//    =>
1077*9880d681SAndroid Build Coastguard Worker//        r2 = shf.r r1, r1, n
1078*9880d681SAndroid Build Coastguard Workerdef ROTR32imm_hw :
1079*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$src, i32imm:$amt),
1080*9880d681SAndroid Build Coastguard Worker            "shf.r.wrap.b32 \t$dst, $src, $src, $amt;",
1081*9880d681SAndroid Build Coastguard Worker            [(set Int32Regs:$dst, (rotr Int32Regs:$src, (i32 imm:$amt)))]>,
1082*9880d681SAndroid Build Coastguard Worker           Requires<[hasHWROT32]>;
1083*9880d681SAndroid Build Coastguard Worker
1084*9880d681SAndroid Build Coastguard Workerdef ROTR32reg_hw :
1085*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$src, Int32Regs:$amt),
1086*9880d681SAndroid Build Coastguard Worker            "shf.r.wrap.b32 \t$dst, $src, $src, $amt;",
1087*9880d681SAndroid Build Coastguard Worker            [(set Int32Regs:$dst, (rotr Int32Regs:$src, Int32Regs:$amt))]>,
1088*9880d681SAndroid Build Coastguard Worker           Requires<[hasHWROT32]>;
1089*9880d681SAndroid Build Coastguard Worker
1090*9880d681SAndroid Build Coastguard Worker// 32-bit software rotate by immediate.  $amt2 should equal 32 - $amt1.
1091*9880d681SAndroid Build Coastguard Workerdef ROT32imm_sw :
1092*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst),
1093*9880d681SAndroid Build Coastguard Worker            (ins Int32Regs:$src, i32imm:$amt1, i32imm:$amt2),
1094*9880d681SAndroid Build Coastguard Worker            "{{\n\t"
1095*9880d681SAndroid Build Coastguard Worker            ".reg .b32 %lhs;\n\t"
1096*9880d681SAndroid Build Coastguard Worker            ".reg .b32 %rhs;\n\t"
1097*9880d681SAndroid Build Coastguard Worker            "shl.b32 \t%lhs, $src, $amt1;\n\t"
1098*9880d681SAndroid Build Coastguard Worker            "shr.b32 \t%rhs, $src, $amt2;\n\t"
1099*9880d681SAndroid Build Coastguard Worker            "add.u32 \t$dst, %lhs, %rhs;\n\t"
1100*9880d681SAndroid Build Coastguard Worker            "}}",
1101*9880d681SAndroid Build Coastguard Worker            []>;
1102*9880d681SAndroid Build Coastguard Worker
1103*9880d681SAndroid Build Coastguard Workerdef SUB_FRM_32 : SDNodeXForm<imm, [{
1104*9880d681SAndroid Build Coastguard Worker  return CurDAG->getTargetConstant(32 - N->getZExtValue(), SDLoc(N), MVT::i32);
1105*9880d681SAndroid Build Coastguard Worker}]>;
1106*9880d681SAndroid Build Coastguard Worker
1107*9880d681SAndroid Build Coastguard Workerdef : Pat<(rotl Int32Regs:$src, (i32 imm:$amt)),
1108*9880d681SAndroid Build Coastguard Worker          (ROT32imm_sw Int32Regs:$src, imm:$amt, (SUB_FRM_32 node:$amt))>,
1109*9880d681SAndroid Build Coastguard Worker      Requires<[noHWROT32]>;
1110*9880d681SAndroid Build Coastguard Workerdef : Pat<(rotr Int32Regs:$src, (i32 imm:$amt)),
1111*9880d681SAndroid Build Coastguard Worker          (ROT32imm_sw Int32Regs:$src, (SUB_FRM_32 node:$amt), imm:$amt)>,
1112*9880d681SAndroid Build Coastguard Worker      Requires<[noHWROT32]>;
1113*9880d681SAndroid Build Coastguard Worker
1114*9880d681SAndroid Build Coastguard Worker// 32-bit software rotate left by register.
1115*9880d681SAndroid Build Coastguard Workerdef ROTL32reg_sw :
1116*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$src, Int32Regs:$amt),
1117*9880d681SAndroid Build Coastguard Worker            "{{\n\t"
1118*9880d681SAndroid Build Coastguard Worker            ".reg .b32 %lhs;\n\t"
1119*9880d681SAndroid Build Coastguard Worker            ".reg .b32 %rhs;\n\t"
1120*9880d681SAndroid Build Coastguard Worker            ".reg .b32 %amt2;\n\t"
1121*9880d681SAndroid Build Coastguard Worker            "shl.b32 \t%lhs, $src, $amt;\n\t"
1122*9880d681SAndroid Build Coastguard Worker            "sub.s32 \t%amt2, 32, $amt;\n\t"
1123*9880d681SAndroid Build Coastguard Worker            "shr.b32 \t%rhs, $src, %amt2;\n\t"
1124*9880d681SAndroid Build Coastguard Worker            "add.u32 \t$dst, %lhs, %rhs;\n\t"
1125*9880d681SAndroid Build Coastguard Worker            "}}",
1126*9880d681SAndroid Build Coastguard Worker            [(set Int32Regs:$dst, (rotl Int32Regs:$src, Int32Regs:$amt))]>,
1127*9880d681SAndroid Build Coastguard Worker           Requires<[noHWROT32]>;
1128*9880d681SAndroid Build Coastguard Worker
1129*9880d681SAndroid Build Coastguard Worker// 32-bit software rotate right by register.
1130*9880d681SAndroid Build Coastguard Workerdef ROTR32reg_sw :
1131*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$src, Int32Regs:$amt),
1132*9880d681SAndroid Build Coastguard Worker            "{{\n\t"
1133*9880d681SAndroid Build Coastguard Worker            ".reg .b32 %lhs;\n\t"
1134*9880d681SAndroid Build Coastguard Worker            ".reg .b32 %rhs;\n\t"
1135*9880d681SAndroid Build Coastguard Worker            ".reg .b32 %amt2;\n\t"
1136*9880d681SAndroid Build Coastguard Worker            "shr.b32 \t%lhs, $src, $amt;\n\t"
1137*9880d681SAndroid Build Coastguard Worker            "sub.s32 \t%amt2, 32, $amt;\n\t"
1138*9880d681SAndroid Build Coastguard Worker            "shl.b32 \t%rhs, $src, %amt2;\n\t"
1139*9880d681SAndroid Build Coastguard Worker            "add.u32 \t$dst, %lhs, %rhs;\n\t"
1140*9880d681SAndroid Build Coastguard Worker            "}}",
1141*9880d681SAndroid Build Coastguard Worker            [(set Int32Regs:$dst, (rotr Int32Regs:$src, Int32Regs:$amt))]>,
1142*9880d681SAndroid Build Coastguard Worker           Requires<[noHWROT32]>;
1143*9880d681SAndroid Build Coastguard Worker
1144*9880d681SAndroid Build Coastguard Worker// 64-bit software rotate by immediate.  $amt2 should equal 64 - $amt1.
1145*9880d681SAndroid Build Coastguard Workerdef ROT64imm_sw :
1146*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int64Regs:$dst),
1147*9880d681SAndroid Build Coastguard Worker            (ins Int64Regs:$src, i32imm:$amt1, i32imm:$amt2),
1148*9880d681SAndroid Build Coastguard Worker            "{{\n\t"
1149*9880d681SAndroid Build Coastguard Worker            ".reg .b64 %lhs;\n\t"
1150*9880d681SAndroid Build Coastguard Worker            ".reg .b64 %rhs;\n\t"
1151*9880d681SAndroid Build Coastguard Worker            "shl.b64 \t%lhs, $src, $amt1;\n\t"
1152*9880d681SAndroid Build Coastguard Worker            "shr.b64 \t%rhs, $src, $amt2;\n\t"
1153*9880d681SAndroid Build Coastguard Worker            "add.u64 \t$dst, %lhs, %rhs;\n\t"
1154*9880d681SAndroid Build Coastguard Worker            "}}",
1155*9880d681SAndroid Build Coastguard Worker            []>;
1156*9880d681SAndroid Build Coastguard Worker
1157*9880d681SAndroid Build Coastguard Workerdef SUB_FRM_64 : SDNodeXForm<imm, [{
1158*9880d681SAndroid Build Coastguard Worker    return CurDAG->getTargetConstant(64-N->getZExtValue(), SDLoc(N), MVT::i32);
1159*9880d681SAndroid Build Coastguard Worker}]>;
1160*9880d681SAndroid Build Coastguard Worker
1161*9880d681SAndroid Build Coastguard Workerdef : Pat<(rotl Int64Regs:$src, (i32 imm:$amt)),
1162*9880d681SAndroid Build Coastguard Worker          (ROT64imm_sw Int64Regs:$src, imm:$amt, (SUB_FRM_64 node:$amt))>;
1163*9880d681SAndroid Build Coastguard Workerdef : Pat<(rotr Int64Regs:$src, (i32 imm:$amt)),
1164*9880d681SAndroid Build Coastguard Worker          (ROT64imm_sw Int64Regs:$src, (SUB_FRM_64 node:$amt), imm:$amt)>;
1165*9880d681SAndroid Build Coastguard Worker
1166*9880d681SAndroid Build Coastguard Worker// 64-bit software rotate left by register.
1167*9880d681SAndroid Build Coastguard Workerdef ROTL64reg_sw :
1168*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int64Regs:$dst), (ins Int64Regs:$src, Int32Regs:$amt),
1169*9880d681SAndroid Build Coastguard Worker            "{{\n\t"
1170*9880d681SAndroid Build Coastguard Worker            ".reg .b64 %lhs;\n\t"
1171*9880d681SAndroid Build Coastguard Worker            ".reg .b64 %rhs;\n\t"
1172*9880d681SAndroid Build Coastguard Worker            ".reg .u32 %amt2;\n\t"
1173*9880d681SAndroid Build Coastguard Worker            "shl.b64 \t%lhs, $src, $amt;\n\t"
1174*9880d681SAndroid Build Coastguard Worker            "sub.u32 \t%amt2, 64, $amt;\n\t"
1175*9880d681SAndroid Build Coastguard Worker            "shr.b64 \t%rhs, $src, %amt2;\n\t"
1176*9880d681SAndroid Build Coastguard Worker            "add.u64 \t$dst, %lhs, %rhs;\n\t"
1177*9880d681SAndroid Build Coastguard Worker            "}}",
1178*9880d681SAndroid Build Coastguard Worker            [(set Int64Regs:$dst, (rotl Int64Regs:$src, Int32Regs:$amt))]>;
1179*9880d681SAndroid Build Coastguard Worker
1180*9880d681SAndroid Build Coastguard Workerdef ROTR64reg_sw :
1181*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int64Regs:$dst), (ins Int64Regs:$src, Int32Regs:$amt),
1182*9880d681SAndroid Build Coastguard Worker            "{{\n\t"
1183*9880d681SAndroid Build Coastguard Worker            ".reg .b64 %lhs;\n\t"
1184*9880d681SAndroid Build Coastguard Worker            ".reg .b64 %rhs;\n\t"
1185*9880d681SAndroid Build Coastguard Worker            ".reg .u32 %amt2;\n\t"
1186*9880d681SAndroid Build Coastguard Worker            "shr.b64 \t%lhs, $src, $amt;\n\t"
1187*9880d681SAndroid Build Coastguard Worker            "sub.u32 \t%amt2, 64, $amt;\n\t"
1188*9880d681SAndroid Build Coastguard Worker            "shl.b64 \t%rhs, $src, %amt2;\n\t"
1189*9880d681SAndroid Build Coastguard Worker            "add.u64 \t$dst, %lhs, %rhs;\n\t"
1190*9880d681SAndroid Build Coastguard Worker            "}}",
1191*9880d681SAndroid Build Coastguard Worker            [(set Int64Regs:$dst, (rotr Int64Regs:$src, Int32Regs:$amt))]>;
1192*9880d681SAndroid Build Coastguard Worker
1193*9880d681SAndroid Build Coastguard Worker//
1194*9880d681SAndroid Build Coastguard Worker// Funnnel shift in clamp mode
1195*9880d681SAndroid Build Coastguard Worker//
1196*9880d681SAndroid Build Coastguard Worker
1197*9880d681SAndroid Build Coastguard Worker// Create SDNodes so they can be used in the DAG code, e.g.
1198*9880d681SAndroid Build Coastguard Worker// NVPTXISelLowering (LowerShiftLeftParts and LowerShiftRightParts)
1199*9880d681SAndroid Build Coastguard Workerdef SDTIntShiftDOp :
1200*9880d681SAndroid Build Coastguard Worker  SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
1201*9880d681SAndroid Build Coastguard Worker                       SDTCisInt<0>, SDTCisInt<3>]>;
1202*9880d681SAndroid Build Coastguard Workerdef FUN_SHFL_CLAMP : SDNode<"NVPTXISD::FUN_SHFL_CLAMP", SDTIntShiftDOp, []>;
1203*9880d681SAndroid Build Coastguard Workerdef FUN_SHFR_CLAMP : SDNode<"NVPTXISD::FUN_SHFR_CLAMP", SDTIntShiftDOp, []>;
1204*9880d681SAndroid Build Coastguard Worker
1205*9880d681SAndroid Build Coastguard Workerdef FUNSHFLCLAMP :
1206*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst),
1207*9880d681SAndroid Build Coastguard Worker            (ins Int32Regs:$lo, Int32Regs:$hi, Int32Regs:$amt),
1208*9880d681SAndroid Build Coastguard Worker            "shf.l.clamp.b32 \t$dst, $lo, $hi, $amt;",
1209*9880d681SAndroid Build Coastguard Worker            [(set Int32Regs:$dst,
1210*9880d681SAndroid Build Coastguard Worker              (FUN_SHFL_CLAMP Int32Regs:$lo, Int32Regs:$hi, Int32Regs:$amt))]>;
1211*9880d681SAndroid Build Coastguard Worker
1212*9880d681SAndroid Build Coastguard Workerdef FUNSHFRCLAMP :
1213*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int32Regs:$dst),
1214*9880d681SAndroid Build Coastguard Worker            (ins Int32Regs:$lo, Int32Regs:$hi, Int32Regs:$amt),
1215*9880d681SAndroid Build Coastguard Worker            "shf.r.clamp.b32 \t$dst, $lo, $hi, $amt;",
1216*9880d681SAndroid Build Coastguard Worker            [(set Int32Regs:$dst,
1217*9880d681SAndroid Build Coastguard Worker             (FUN_SHFR_CLAMP Int32Regs:$lo, Int32Regs:$hi, Int32Regs:$amt))]>;
1218*9880d681SAndroid Build Coastguard Worker
1219*9880d681SAndroid Build Coastguard Worker//
1220*9880d681SAndroid Build Coastguard Worker// BFE - bit-field extract
1221*9880d681SAndroid Build Coastguard Worker//
1222*9880d681SAndroid Build Coastguard Worker
1223*9880d681SAndroid Build Coastguard Worker// Template for BFE instructions.  Takes four args,
1224*9880d681SAndroid Build Coastguard Worker//   [dest (reg), src (reg), start (reg or imm), end (reg or imm)].
1225*9880d681SAndroid Build Coastguard Worker// Start may be an imm only if end is also an imm.  FIXME: Is this a
1226*9880d681SAndroid Build Coastguard Worker// restriction in PTX?
1227*9880d681SAndroid Build Coastguard Worker//
1228*9880d681SAndroid Build Coastguard Worker// dest and src may be int32 or int64, but start and end are always int32.
1229*9880d681SAndroid Build Coastguard Workermulticlass BFE<string TyStr, RegisterClass RC> {
1230*9880d681SAndroid Build Coastguard Worker  def rrr
1231*9880d681SAndroid Build Coastguard Worker    : NVPTXInst<(outs RC:$d),
1232*9880d681SAndroid Build Coastguard Worker                (ins RC:$a, Int32Regs:$b, Int32Regs:$c),
1233*9880d681SAndroid Build Coastguard Worker                !strconcat("bfe.", TyStr, " \t$d, $a, $b, $c;"), []>;
1234*9880d681SAndroid Build Coastguard Worker  def rri
1235*9880d681SAndroid Build Coastguard Worker    : NVPTXInst<(outs RC:$d),
1236*9880d681SAndroid Build Coastguard Worker                (ins RC:$a, Int32Regs:$b, i32imm:$c),
1237*9880d681SAndroid Build Coastguard Worker                !strconcat("bfe.", TyStr, " \t$d, $a, $b, $c;"), []>;
1238*9880d681SAndroid Build Coastguard Worker  def rii
1239*9880d681SAndroid Build Coastguard Worker    : NVPTXInst<(outs RC:$d),
1240*9880d681SAndroid Build Coastguard Worker                (ins RC:$a, i32imm:$b, i32imm:$c),
1241*9880d681SAndroid Build Coastguard Worker                !strconcat("bfe.", TyStr, " \t$d, $a, $b, $c;"), []>;
1242*9880d681SAndroid Build Coastguard Worker}
1243*9880d681SAndroid Build Coastguard Worker
1244*9880d681SAndroid Build Coastguard Workerlet hasSideEffects = 0 in {
1245*9880d681SAndroid Build Coastguard Worker  defm BFE_S32 : BFE<"s32", Int32Regs>;
1246*9880d681SAndroid Build Coastguard Worker  defm BFE_U32 : BFE<"u32", Int32Regs>;
1247*9880d681SAndroid Build Coastguard Worker  defm BFE_S64 : BFE<"s64", Int64Regs>;
1248*9880d681SAndroid Build Coastguard Worker  defm BFE_U64 : BFE<"u64", Int64Regs>;
1249*9880d681SAndroid Build Coastguard Worker}
1250*9880d681SAndroid Build Coastguard Worker
1251*9880d681SAndroid Build Coastguard Worker//-----------------------------------
1252*9880d681SAndroid Build Coastguard Worker// Comparison instructions (setp, set)
1253*9880d681SAndroid Build Coastguard Worker//-----------------------------------
1254*9880d681SAndroid Build Coastguard Worker
1255*9880d681SAndroid Build Coastguard Worker// FIXME: This doesn't cover versions of set and setp that combine with a
1256*9880d681SAndroid Build Coastguard Worker// boolean predicate, e.g. setp.eq.and.b16.
1257*9880d681SAndroid Build Coastguard Worker
1258*9880d681SAndroid Build Coastguard Workerlet hasSideEffects = 0 in {
1259*9880d681SAndroid Build Coastguard Worker  multiclass SETP<string TypeStr, RegisterClass RC, Operand ImmCls> {
1260*9880d681SAndroid Build Coastguard Worker    def rr :
1261*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs Int1Regs:$dst), (ins RC:$a, RC:$b, CmpMode:$cmp),
1262*9880d681SAndroid Build Coastguard Worker                !strconcat("setp${cmp:base}${cmp:ftz}.", TypeStr,
1263*9880d681SAndroid Build Coastguard Worker                           "\t$dst, $a, $b;"), []>;
1264*9880d681SAndroid Build Coastguard Worker    def ri :
1265*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs Int1Regs:$dst), (ins RC:$a, ImmCls:$b, CmpMode:$cmp),
1266*9880d681SAndroid Build Coastguard Worker                !strconcat("setp${cmp:base}${cmp:ftz}.", TypeStr,
1267*9880d681SAndroid Build Coastguard Worker                           "\t$dst, $a, $b;"), []>;
1268*9880d681SAndroid Build Coastguard Worker    def ir :
1269*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs Int1Regs:$dst), (ins ImmCls:$a, RC:$b, CmpMode:$cmp),
1270*9880d681SAndroid Build Coastguard Worker                !strconcat("setp${cmp:base}${cmp:ftz}.", TypeStr,
1271*9880d681SAndroid Build Coastguard Worker                           "\t$dst, $a, $b;"), []>;
1272*9880d681SAndroid Build Coastguard Worker  }
1273*9880d681SAndroid Build Coastguard Worker}
1274*9880d681SAndroid Build Coastguard Worker
1275*9880d681SAndroid Build Coastguard Workerdefm SETP_b16 : SETP<"b16", Int16Regs, i16imm>;
1276*9880d681SAndroid Build Coastguard Workerdefm SETP_s16 : SETP<"s16", Int16Regs, i16imm>;
1277*9880d681SAndroid Build Coastguard Workerdefm SETP_u16 : SETP<"u16", Int16Regs, i16imm>;
1278*9880d681SAndroid Build Coastguard Workerdefm SETP_b32 : SETP<"b32", Int32Regs, i32imm>;
1279*9880d681SAndroid Build Coastguard Workerdefm SETP_s32 : SETP<"s32", Int32Regs, i32imm>;
1280*9880d681SAndroid Build Coastguard Workerdefm SETP_u32 : SETP<"u32", Int32Regs, i32imm>;
1281*9880d681SAndroid Build Coastguard Workerdefm SETP_b64 : SETP<"b64", Int64Regs, i64imm>;
1282*9880d681SAndroid Build Coastguard Workerdefm SETP_s64 : SETP<"s64", Int64Regs, i64imm>;
1283*9880d681SAndroid Build Coastguard Workerdefm SETP_u64 : SETP<"u64", Int64Regs, i64imm>;
1284*9880d681SAndroid Build Coastguard Workerdefm SETP_f32 : SETP<"f32", Float32Regs, f32imm>;
1285*9880d681SAndroid Build Coastguard Workerdefm SETP_f64 : SETP<"f64", Float64Regs, f64imm>;
1286*9880d681SAndroid Build Coastguard Worker
1287*9880d681SAndroid Build Coastguard Worker// FIXME: This doesn't appear to be correct.  The "set" mnemonic has the form
1288*9880d681SAndroid Build Coastguard Worker// "set.CmpOp{.ftz}.dtype.stype", where dtype is the type of the destination
1289*9880d681SAndroid Build Coastguard Worker// reg, either u32, s32, or f32.  Anyway these aren't used at the moment.
1290*9880d681SAndroid Build Coastguard Worker
1291*9880d681SAndroid Build Coastguard Workerlet hasSideEffects = 0 in {
1292*9880d681SAndroid Build Coastguard Worker  multiclass SET<string TypeStr, RegisterClass RC, Operand ImmCls> {
1293*9880d681SAndroid Build Coastguard Worker    def rr : NVPTXInst<(outs Int32Regs:$dst),
1294*9880d681SAndroid Build Coastguard Worker                       (ins RC:$a, RC:$b, CmpMode:$cmp),
1295*9880d681SAndroid Build Coastguard Worker                       !strconcat("set$cmp.", TypeStr, "\t$dst, $a, $b;"), []>;
1296*9880d681SAndroid Build Coastguard Worker    def ri : NVPTXInst<(outs Int32Regs:$dst),
1297*9880d681SAndroid Build Coastguard Worker                       (ins RC:$a, ImmCls:$b, CmpMode:$cmp),
1298*9880d681SAndroid Build Coastguard Worker                       !strconcat("set$cmp.", TypeStr, "\t$dst, $a, $b;"), []>;
1299*9880d681SAndroid Build Coastguard Worker    def ir : NVPTXInst<(outs Int32Regs:$dst),
1300*9880d681SAndroid Build Coastguard Worker                       (ins ImmCls:$a, RC:$b, CmpMode:$cmp),
1301*9880d681SAndroid Build Coastguard Worker                       !strconcat("set$cmp.", TypeStr, "\t$dst, $a, $b;"), []>;
1302*9880d681SAndroid Build Coastguard Worker  }
1303*9880d681SAndroid Build Coastguard Worker}
1304*9880d681SAndroid Build Coastguard Worker
1305*9880d681SAndroid Build Coastguard Workerdefm SET_b16 : SET<"b16", Int16Regs, i16imm>;
1306*9880d681SAndroid Build Coastguard Workerdefm SET_s16 : SET<"s16", Int16Regs, i16imm>;
1307*9880d681SAndroid Build Coastguard Workerdefm SET_u16 : SET<"u16", Int16Regs, i16imm>;
1308*9880d681SAndroid Build Coastguard Workerdefm SET_b32 : SET<"b32", Int32Regs, i32imm>;
1309*9880d681SAndroid Build Coastguard Workerdefm SET_s32 : SET<"s32", Int32Regs, i32imm>;
1310*9880d681SAndroid Build Coastguard Workerdefm SET_u32 : SET<"u32", Int32Regs, i32imm>;
1311*9880d681SAndroid Build Coastguard Workerdefm SET_b64 : SET<"b64", Int64Regs, i64imm>;
1312*9880d681SAndroid Build Coastguard Workerdefm SET_s64 : SET<"s64", Int64Regs, i64imm>;
1313*9880d681SAndroid Build Coastguard Workerdefm SET_u64 : SET<"u64", Int64Regs, i64imm>;
1314*9880d681SAndroid Build Coastguard Workerdefm SET_f32 : SET<"f32", Float32Regs, f32imm>;
1315*9880d681SAndroid Build Coastguard Workerdefm SET_f64 : SET<"f64", Float64Regs, f64imm>;
1316*9880d681SAndroid Build Coastguard Worker
1317*9880d681SAndroid Build Coastguard Worker//-----------------------------------
1318*9880d681SAndroid Build Coastguard Worker// Selection instructions (selp)
1319*9880d681SAndroid Build Coastguard Worker//-----------------------------------
1320*9880d681SAndroid Build Coastguard Worker
1321*9880d681SAndroid Build Coastguard Worker// FIXME: Missing slct
1322*9880d681SAndroid Build Coastguard Worker
1323*9880d681SAndroid Build Coastguard Worker// selp instructions that don't have any pattern matches; we explicitly use
1324*9880d681SAndroid Build Coastguard Worker// them within this file.
1325*9880d681SAndroid Build Coastguard Workerlet hasSideEffects = 0 in {
1326*9880d681SAndroid Build Coastguard Worker  multiclass SELP<string TypeStr, RegisterClass RC, Operand ImmCls> {
1327*9880d681SAndroid Build Coastguard Worker    def rr : NVPTXInst<(outs RC:$dst),
1328*9880d681SAndroid Build Coastguard Worker                       (ins RC:$a, RC:$b, Int1Regs:$p),
1329*9880d681SAndroid Build Coastguard Worker                       !strconcat("selp.", TypeStr, "\t$dst, $a, $b, $p;"), []>;
1330*9880d681SAndroid Build Coastguard Worker    def ri : NVPTXInst<(outs RC:$dst),
1331*9880d681SAndroid Build Coastguard Worker                       (ins RC:$a, ImmCls:$b, Int1Regs:$p),
1332*9880d681SAndroid Build Coastguard Worker                       !strconcat("selp.", TypeStr, "\t$dst, $a, $b, $p;"), []>;
1333*9880d681SAndroid Build Coastguard Worker    def ir : NVPTXInst<(outs RC:$dst),
1334*9880d681SAndroid Build Coastguard Worker                       (ins ImmCls:$a, RC:$b, Int1Regs:$p),
1335*9880d681SAndroid Build Coastguard Worker                       !strconcat("selp.", TypeStr, "\t$dst, $a, $b, $p;"), []>;
1336*9880d681SAndroid Build Coastguard Worker    def ii : NVPTXInst<(outs RC:$dst),
1337*9880d681SAndroid Build Coastguard Worker                       (ins ImmCls:$a, ImmCls:$b, Int1Regs:$p),
1338*9880d681SAndroid Build Coastguard Worker                       !strconcat("selp.", TypeStr, "\t$dst, $a, $b, $p;"), []>;
1339*9880d681SAndroid Build Coastguard Worker  }
1340*9880d681SAndroid Build Coastguard Worker
1341*9880d681SAndroid Build Coastguard Worker  multiclass SELP_PATTERN<string TypeStr, RegisterClass RC, Operand ImmCls,
1342*9880d681SAndroid Build Coastguard Worker                          SDNode ImmNode> {
1343*9880d681SAndroid Build Coastguard Worker    def rr :
1344*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs RC:$dst),
1345*9880d681SAndroid Build Coastguard Worker                (ins RC:$a, RC:$b, Int1Regs:$p),
1346*9880d681SAndroid Build Coastguard Worker                !strconcat("selp.", TypeStr, "\t$dst, $a, $b, $p;"),
1347*9880d681SAndroid Build Coastguard Worker                [(set RC:$dst, (select Int1Regs:$p, RC:$a, RC:$b))]>;
1348*9880d681SAndroid Build Coastguard Worker    def ri :
1349*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs RC:$dst),
1350*9880d681SAndroid Build Coastguard Worker                (ins RC:$a, ImmCls:$b, Int1Regs:$p),
1351*9880d681SAndroid Build Coastguard Worker                !strconcat("selp.", TypeStr, "\t$dst, $a, $b, $p;"),
1352*9880d681SAndroid Build Coastguard Worker                [(set RC:$dst, (select Int1Regs:$p, RC:$a, ImmNode:$b))]>;
1353*9880d681SAndroid Build Coastguard Worker    def ir :
1354*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs RC:$dst),
1355*9880d681SAndroid Build Coastguard Worker                (ins ImmCls:$a, RC:$b, Int1Regs:$p),
1356*9880d681SAndroid Build Coastguard Worker                !strconcat("selp.", TypeStr, "\t$dst, $a, $b, $p;"),
1357*9880d681SAndroid Build Coastguard Worker                [(set RC:$dst, (select Int1Regs:$p, ImmNode:$a, RC:$b))]>;
1358*9880d681SAndroid Build Coastguard Worker    def ii :
1359*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs RC:$dst),
1360*9880d681SAndroid Build Coastguard Worker                (ins ImmCls:$a, ImmCls:$b, Int1Regs:$p),
1361*9880d681SAndroid Build Coastguard Worker                !strconcat("selp.", TypeStr, "\t$dst, $a, $b, $p;"),
1362*9880d681SAndroid Build Coastguard Worker                [(set RC:$dst, (select Int1Regs:$p, ImmNode:$a, ImmNode:$b))]>;
1363*9880d681SAndroid Build Coastguard Worker  }
1364*9880d681SAndroid Build Coastguard Worker}
1365*9880d681SAndroid Build Coastguard Worker
1366*9880d681SAndroid Build Coastguard Worker// Don't pattern match on selp.{s,u}{16,32,64} -- selp.b{16,32,64} is just as
1367*9880d681SAndroid Build Coastguard Worker// good.
1368*9880d681SAndroid Build Coastguard Workerdefm SELP_b16 : SELP_PATTERN<"b16", Int16Regs, i16imm, imm>;
1369*9880d681SAndroid Build Coastguard Workerdefm SELP_s16 : SELP<"s16", Int16Regs, i16imm>;
1370*9880d681SAndroid Build Coastguard Workerdefm SELP_u16 : SELP<"u16", Int16Regs, i16imm>;
1371*9880d681SAndroid Build Coastguard Workerdefm SELP_b32 : SELP_PATTERN<"b32", Int32Regs, i32imm, imm>;
1372*9880d681SAndroid Build Coastguard Workerdefm SELP_s32 : SELP<"s32", Int32Regs, i32imm>;
1373*9880d681SAndroid Build Coastguard Workerdefm SELP_u32 : SELP<"u32", Int32Regs, i32imm>;
1374*9880d681SAndroid Build Coastguard Workerdefm SELP_b64 : SELP_PATTERN<"b64", Int64Regs, i64imm, imm>;
1375*9880d681SAndroid Build Coastguard Workerdefm SELP_s64 : SELP<"s64", Int64Regs, i64imm>;
1376*9880d681SAndroid Build Coastguard Workerdefm SELP_u64 : SELP<"u64", Int64Regs, i64imm>;
1377*9880d681SAndroid Build Coastguard Workerdefm SELP_f32 : SELP_PATTERN<"f32", Float32Regs, f32imm, fpimm>;
1378*9880d681SAndroid Build Coastguard Workerdefm SELP_f64 : SELP_PATTERN<"f64", Float64Regs, f64imm, fpimm>;
1379*9880d681SAndroid Build Coastguard Worker
1380*9880d681SAndroid Build Coastguard Worker//-----------------------------------
1381*9880d681SAndroid Build Coastguard Worker// Data Movement (Load / Store, Move)
1382*9880d681SAndroid Build Coastguard Worker//-----------------------------------
1383*9880d681SAndroid Build Coastguard Worker
1384*9880d681SAndroid Build Coastguard Workerdef ADDRri : ComplexPattern<i32, 2, "SelectADDRri", [frameindex],
1385*9880d681SAndroid Build Coastguard Worker                            [SDNPWantRoot]>;
1386*9880d681SAndroid Build Coastguard Workerdef ADDRri64 : ComplexPattern<i64, 2, "SelectADDRri64", [frameindex],
1387*9880d681SAndroid Build Coastguard Worker                              [SDNPWantRoot]>;
1388*9880d681SAndroid Build Coastguard Worker
1389*9880d681SAndroid Build Coastguard Workerdef MEMri : Operand<i32> {
1390*9880d681SAndroid Build Coastguard Worker  let PrintMethod = "printMemOperand";
1391*9880d681SAndroid Build Coastguard Worker  let MIOperandInfo = (ops Int32Regs, i32imm);
1392*9880d681SAndroid Build Coastguard Worker}
1393*9880d681SAndroid Build Coastguard Workerdef MEMri64 : Operand<i64> {
1394*9880d681SAndroid Build Coastguard Worker  let PrintMethod = "printMemOperand";
1395*9880d681SAndroid Build Coastguard Worker  let MIOperandInfo = (ops Int64Regs, i64imm);
1396*9880d681SAndroid Build Coastguard Worker}
1397*9880d681SAndroid Build Coastguard Worker
1398*9880d681SAndroid Build Coastguard Workerdef imem : Operand<iPTR> {
1399*9880d681SAndroid Build Coastguard Worker  let PrintMethod = "printOperand";
1400*9880d681SAndroid Build Coastguard Worker}
1401*9880d681SAndroid Build Coastguard Worker
1402*9880d681SAndroid Build Coastguard Workerdef imemAny : Operand<iPTRAny> {
1403*9880d681SAndroid Build Coastguard Worker  let PrintMethod = "printOperand";
1404*9880d681SAndroid Build Coastguard Worker}
1405*9880d681SAndroid Build Coastguard Worker
1406*9880d681SAndroid Build Coastguard Workerdef LdStCode : Operand<i32> {
1407*9880d681SAndroid Build Coastguard Worker  let PrintMethod = "printLdStCode";
1408*9880d681SAndroid Build Coastguard Worker}
1409*9880d681SAndroid Build Coastguard Worker
1410*9880d681SAndroid Build Coastguard Workerdef SDTWrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
1411*9880d681SAndroid Build Coastguard Workerdef Wrapper    : SDNode<"NVPTXISD::Wrapper", SDTWrapper>;
1412*9880d681SAndroid Build Coastguard Worker
1413*9880d681SAndroid Build Coastguard Worker// Load a memory address into a u32 or u64 register.
1414*9880d681SAndroid Build Coastguard Workerdef MOV_ADDR : NVPTXInst<(outs Int32Regs:$dst), (ins imem:$a),
1415*9880d681SAndroid Build Coastguard Worker                         "mov.u32 \t$dst, $a;",
1416*9880d681SAndroid Build Coastguard Worker                         [(set Int32Regs:$dst, (Wrapper tglobaladdr:$a))]>;
1417*9880d681SAndroid Build Coastguard Workerdef MOV_ADDR64 : NVPTXInst<(outs Int64Regs:$dst), (ins imem:$a),
1418*9880d681SAndroid Build Coastguard Worker                           "mov.u64 \t$dst, $a;",
1419*9880d681SAndroid Build Coastguard Worker                           [(set Int64Regs:$dst, (Wrapper tglobaladdr:$a))]>;
1420*9880d681SAndroid Build Coastguard Worker
1421*9880d681SAndroid Build Coastguard Worker// Get pointer to local stack.
1422*9880d681SAndroid Build Coastguard Workerlet hasSideEffects = 0 in {
1423*9880d681SAndroid Build Coastguard Worker  def MOV_DEPOT_ADDR :    NVPTXInst<(outs Int32Regs:$d), (ins i32imm:$num),
1424*9880d681SAndroid Build Coastguard Worker                                     "mov.u32 \t$d, __local_depot$num;", []>;
1425*9880d681SAndroid Build Coastguard Worker  def MOV_DEPOT_ADDR_64 : NVPTXInst<(outs Int64Regs:$d), (ins i32imm:$num),
1426*9880d681SAndroid Build Coastguard Worker                                    "mov.u64 \t$d, __local_depot$num;", []>;
1427*9880d681SAndroid Build Coastguard Worker}
1428*9880d681SAndroid Build Coastguard Worker
1429*9880d681SAndroid Build Coastguard Worker
1430*9880d681SAndroid Build Coastguard Worker// copyPhysreg is hard-coded in NVPTXInstrInfo.cpp
1431*9880d681SAndroid Build Coastguard Workerlet IsSimpleMove=1, hasSideEffects=0 in {
1432*9880d681SAndroid Build Coastguard Worker  def IMOV1rr :  NVPTXInst<(outs Int1Regs:$dst), (ins Int1Regs:$sss),
1433*9880d681SAndroid Build Coastguard Worker                           "mov.pred \t$dst, $sss;", []>;
1434*9880d681SAndroid Build Coastguard Worker  def IMOV16rr : NVPTXInst<(outs Int16Regs:$dst), (ins Int16Regs:$sss),
1435*9880d681SAndroid Build Coastguard Worker                           "mov.u16 \t$dst, $sss;", []>;
1436*9880d681SAndroid Build Coastguard Worker  def IMOV32rr : NVPTXInst<(outs Int32Regs:$dst), (ins Int32Regs:$sss),
1437*9880d681SAndroid Build Coastguard Worker                           "mov.u32 \t$dst, $sss;", []>;
1438*9880d681SAndroid Build Coastguard Worker  def IMOV64rr : NVPTXInst<(outs Int64Regs:$dst), (ins Int64Regs:$sss),
1439*9880d681SAndroid Build Coastguard Worker                           "mov.u64 \t$dst, $sss;", []>;
1440*9880d681SAndroid Build Coastguard Worker
1441*9880d681SAndroid Build Coastguard Worker  def FMOV32rr : NVPTXInst<(outs Float32Regs:$dst), (ins Float32Regs:$src),
1442*9880d681SAndroid Build Coastguard Worker                           "mov.f32 \t$dst, $src;", []>;
1443*9880d681SAndroid Build Coastguard Worker  def FMOV64rr : NVPTXInst<(outs Float64Regs:$dst), (ins Float64Regs:$src),
1444*9880d681SAndroid Build Coastguard Worker                           "mov.f64 \t$dst, $src;", []>;
1445*9880d681SAndroid Build Coastguard Worker}
1446*9880d681SAndroid Build Coastguard Worker
1447*9880d681SAndroid Build Coastguard Workerdef IMOV1ri : NVPTXInst<(outs Int1Regs:$dst), (ins i1imm:$src),
1448*9880d681SAndroid Build Coastguard Worker                        "mov.pred \t$dst, $src;",
1449*9880d681SAndroid Build Coastguard Worker                        [(set Int1Regs:$dst, imm:$src)]>;
1450*9880d681SAndroid Build Coastguard Workerdef IMOV16ri : NVPTXInst<(outs Int16Regs:$dst), (ins i16imm:$src),
1451*9880d681SAndroid Build Coastguard Worker                         "mov.u16 \t$dst, $src;",
1452*9880d681SAndroid Build Coastguard Worker                         [(set Int16Regs:$dst, imm:$src)]>;
1453*9880d681SAndroid Build Coastguard Workerdef IMOV32ri : NVPTXInst<(outs Int32Regs:$dst), (ins i32imm:$src),
1454*9880d681SAndroid Build Coastguard Worker                         "mov.u32 \t$dst, $src;",
1455*9880d681SAndroid Build Coastguard Worker                         [(set Int32Regs:$dst, imm:$src)]>;
1456*9880d681SAndroid Build Coastguard Workerdef IMOV64i : NVPTXInst<(outs Int64Regs:$dst), (ins i64imm:$src),
1457*9880d681SAndroid Build Coastguard Worker                        "mov.u64 \t$dst, $src;",
1458*9880d681SAndroid Build Coastguard Worker                        [(set Int64Regs:$dst, imm:$src)]>;
1459*9880d681SAndroid Build Coastguard Worker
1460*9880d681SAndroid Build Coastguard Workerdef FMOV32ri : NVPTXInst<(outs Float32Regs:$dst), (ins f32imm:$src),
1461*9880d681SAndroid Build Coastguard Worker                         "mov.f32 \t$dst, $src;",
1462*9880d681SAndroid Build Coastguard Worker                         [(set Float32Regs:$dst, fpimm:$src)]>;
1463*9880d681SAndroid Build Coastguard Workerdef FMOV64ri : NVPTXInst<(outs Float64Regs:$dst), (ins f64imm:$src),
1464*9880d681SAndroid Build Coastguard Worker                         "mov.f64 \t$dst, $src;",
1465*9880d681SAndroid Build Coastguard Worker                         [(set Float64Regs:$dst, fpimm:$src)]>;
1466*9880d681SAndroid Build Coastguard Worker
1467*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (Wrapper texternalsym:$dst)), (IMOV32ri texternalsym:$dst)>;
1468*9880d681SAndroid Build Coastguard Worker
1469*9880d681SAndroid Build Coastguard Worker//---- Copy Frame Index ----
1470*9880d681SAndroid Build Coastguard Workerdef LEA_ADDRi :   NVPTXInst<(outs Int32Regs:$dst), (ins MEMri:$addr),
1471*9880d681SAndroid Build Coastguard Worker                            "add.u32 \t$dst, ${addr:add};",
1472*9880d681SAndroid Build Coastguard Worker                            [(set Int32Regs:$dst, ADDRri:$addr)]>;
1473*9880d681SAndroid Build Coastguard Workerdef LEA_ADDRi64 : NVPTXInst<(outs Int64Regs:$dst), (ins MEMri64:$addr),
1474*9880d681SAndroid Build Coastguard Worker                            "add.u64 \t$dst, ${addr:add};",
1475*9880d681SAndroid Build Coastguard Worker                            [(set Int64Regs:$dst, ADDRri64:$addr)]>;
1476*9880d681SAndroid Build Coastguard Worker
1477*9880d681SAndroid Build Coastguard Worker//-----------------------------------
1478*9880d681SAndroid Build Coastguard Worker// Comparison and Selection
1479*9880d681SAndroid Build Coastguard Worker//-----------------------------------
1480*9880d681SAndroid Build Coastguard Worker
1481*9880d681SAndroid Build Coastguard Workermulticlass ISET_FORMAT<PatFrag OpNode, PatLeaf Mode,
1482*9880d681SAndroid Build Coastguard Worker                       Instruction setp_16rr,
1483*9880d681SAndroid Build Coastguard Worker                       Instruction setp_16ri,
1484*9880d681SAndroid Build Coastguard Worker                       Instruction setp_16ir,
1485*9880d681SAndroid Build Coastguard Worker                       Instruction setp_32rr,
1486*9880d681SAndroid Build Coastguard Worker                       Instruction setp_32ri,
1487*9880d681SAndroid Build Coastguard Worker                       Instruction setp_32ir,
1488*9880d681SAndroid Build Coastguard Worker                       Instruction setp_64rr,
1489*9880d681SAndroid Build Coastguard Worker                       Instruction setp_64ri,
1490*9880d681SAndroid Build Coastguard Worker                       Instruction setp_64ir,
1491*9880d681SAndroid Build Coastguard Worker                       Instruction set_16rr,
1492*9880d681SAndroid Build Coastguard Worker                       Instruction set_16ri,
1493*9880d681SAndroid Build Coastguard Worker                       Instruction set_16ir,
1494*9880d681SAndroid Build Coastguard Worker                       Instruction set_32rr,
1495*9880d681SAndroid Build Coastguard Worker                       Instruction set_32ri,
1496*9880d681SAndroid Build Coastguard Worker                       Instruction set_32ir,
1497*9880d681SAndroid Build Coastguard Worker                       Instruction set_64rr,
1498*9880d681SAndroid Build Coastguard Worker                       Instruction set_64ri,
1499*9880d681SAndroid Build Coastguard Worker                       Instruction set_64ir> {
1500*9880d681SAndroid Build Coastguard Worker  // i16 -> pred
1501*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode Int16Regs:$a, Int16Regs:$b)),
1502*9880d681SAndroid Build Coastguard Worker            (setp_16rr Int16Regs:$a, Int16Regs:$b, Mode)>;
1503*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode Int16Regs:$a, imm:$b)),
1504*9880d681SAndroid Build Coastguard Worker            (setp_16ri Int16Regs:$a, imm:$b, Mode)>;
1505*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode imm:$a, Int16Regs:$b)),
1506*9880d681SAndroid Build Coastguard Worker            (setp_16ir imm:$a, Int16Regs:$b, Mode)>;
1507*9880d681SAndroid Build Coastguard Worker  // i32 -> pred
1508*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode Int32Regs:$a, Int32Regs:$b)),
1509*9880d681SAndroid Build Coastguard Worker            (setp_32rr Int32Regs:$a, Int32Regs:$b, Mode)>;
1510*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode Int32Regs:$a, imm:$b)),
1511*9880d681SAndroid Build Coastguard Worker            (setp_32ri Int32Regs:$a, imm:$b, Mode)>;
1512*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode imm:$a, Int32Regs:$b)),
1513*9880d681SAndroid Build Coastguard Worker            (setp_32ir imm:$a, Int32Regs:$b, Mode)>;
1514*9880d681SAndroid Build Coastguard Worker  // i64 -> pred
1515*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode Int64Regs:$a, Int64Regs:$b)),
1516*9880d681SAndroid Build Coastguard Worker            (setp_64rr Int64Regs:$a, Int64Regs:$b, Mode)>;
1517*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode Int64Regs:$a, imm:$b)),
1518*9880d681SAndroid Build Coastguard Worker            (setp_64ri Int64Regs:$a, imm:$b, Mode)>;
1519*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode imm:$a, Int64Regs:$b)),
1520*9880d681SAndroid Build Coastguard Worker            (setp_64ir imm:$a, Int64Regs:$b, Mode)>;
1521*9880d681SAndroid Build Coastguard Worker
1522*9880d681SAndroid Build Coastguard Worker  // i16 -> i32
1523*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode Int16Regs:$a, Int16Regs:$b)),
1524*9880d681SAndroid Build Coastguard Worker            (set_16rr Int16Regs:$a, Int16Regs:$b, Mode)>;
1525*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode Int16Regs:$a, imm:$b)),
1526*9880d681SAndroid Build Coastguard Worker            (set_16ri Int16Regs:$a, imm:$b, Mode)>;
1527*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode imm:$a, Int16Regs:$b)),
1528*9880d681SAndroid Build Coastguard Worker            (set_16ir imm:$a, Int16Regs:$b, Mode)>;
1529*9880d681SAndroid Build Coastguard Worker  // i32 -> i32
1530*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode Int32Regs:$a, Int32Regs:$b)),
1531*9880d681SAndroid Build Coastguard Worker            (set_32rr Int32Regs:$a, Int32Regs:$b, Mode)>;
1532*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode Int32Regs:$a, imm:$b)),
1533*9880d681SAndroid Build Coastguard Worker            (set_32ri Int32Regs:$a, imm:$b, Mode)>;
1534*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode imm:$a, Int32Regs:$b)),
1535*9880d681SAndroid Build Coastguard Worker            (set_32ir imm:$a, Int32Regs:$b, Mode)>;
1536*9880d681SAndroid Build Coastguard Worker  // i64 -> i32
1537*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode Int64Regs:$a, Int64Regs:$b)),
1538*9880d681SAndroid Build Coastguard Worker            (set_64rr Int64Regs:$a, Int64Regs:$b, Mode)>;
1539*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode Int64Regs:$a, imm:$b)),
1540*9880d681SAndroid Build Coastguard Worker            (set_64ri Int64Regs:$a, imm:$b, Mode)>;
1541*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode imm:$a, Int64Regs:$b)),
1542*9880d681SAndroid Build Coastguard Worker            (set_64ir imm:$a, Int64Regs:$b, Mode)>;
1543*9880d681SAndroid Build Coastguard Worker}
1544*9880d681SAndroid Build Coastguard Worker
1545*9880d681SAndroid Build Coastguard Workermulticlass ISET_FORMAT_SIGNED<PatFrag OpNode, PatLeaf Mode>
1546*9880d681SAndroid Build Coastguard Worker  : ISET_FORMAT<OpNode, Mode,
1547*9880d681SAndroid Build Coastguard Worker                SETP_s16rr, SETP_s16ri, SETP_s16ir,
1548*9880d681SAndroid Build Coastguard Worker                SETP_s32rr, SETP_s32ri, SETP_s32ir,
1549*9880d681SAndroid Build Coastguard Worker                SETP_s64rr, SETP_s64ri, SETP_s64ir,
1550*9880d681SAndroid Build Coastguard Worker                SET_s16rr, SET_s16ri, SET_s16ir,
1551*9880d681SAndroid Build Coastguard Worker                SET_s32rr, SET_s32ri, SET_s32ir,
1552*9880d681SAndroid Build Coastguard Worker                SET_s64rr, SET_s64ri, SET_s64ir> {
1553*9880d681SAndroid Build Coastguard Worker  // TableGen doesn't like empty multiclasses.
1554*9880d681SAndroid Build Coastguard Worker  def : PatLeaf<(i32 0)>;
1555*9880d681SAndroid Build Coastguard Worker}
1556*9880d681SAndroid Build Coastguard Worker
1557*9880d681SAndroid Build Coastguard Workermulticlass ISET_FORMAT_UNSIGNED<PatFrag OpNode, PatLeaf Mode>
1558*9880d681SAndroid Build Coastguard Worker  : ISET_FORMAT<OpNode, Mode,
1559*9880d681SAndroid Build Coastguard Worker                SETP_u16rr, SETP_u16ri, SETP_u16ir,
1560*9880d681SAndroid Build Coastguard Worker                SETP_u32rr, SETP_u32ri, SETP_u32ir,
1561*9880d681SAndroid Build Coastguard Worker                SETP_u64rr, SETP_u64ri, SETP_u64ir,
1562*9880d681SAndroid Build Coastguard Worker                SET_u16rr, SET_u16ri, SET_u16ir,
1563*9880d681SAndroid Build Coastguard Worker                SET_u32rr, SET_u32ri, SET_u32ir,
1564*9880d681SAndroid Build Coastguard Worker                SET_u64rr, SET_u64ri, SET_u64ir> {
1565*9880d681SAndroid Build Coastguard Worker  // TableGen doesn't like empty multiclasses.
1566*9880d681SAndroid Build Coastguard Worker  def : PatLeaf<(i32 0)>;
1567*9880d681SAndroid Build Coastguard Worker}
1568*9880d681SAndroid Build Coastguard Worker
1569*9880d681SAndroid Build Coastguard Workerdefm : ISET_FORMAT_SIGNED<setgt, CmpGT>;
1570*9880d681SAndroid Build Coastguard Workerdefm : ISET_FORMAT_SIGNED<setlt, CmpLT>;
1571*9880d681SAndroid Build Coastguard Workerdefm : ISET_FORMAT_SIGNED<setge, CmpGE>;
1572*9880d681SAndroid Build Coastguard Workerdefm : ISET_FORMAT_SIGNED<setle, CmpLE>;
1573*9880d681SAndroid Build Coastguard Workerdefm : ISET_FORMAT_SIGNED<seteq, CmpEQ>;
1574*9880d681SAndroid Build Coastguard Workerdefm : ISET_FORMAT_SIGNED<setne, CmpNE>;
1575*9880d681SAndroid Build Coastguard Workerdefm : ISET_FORMAT_UNSIGNED<setugt, CmpGT>;
1576*9880d681SAndroid Build Coastguard Workerdefm : ISET_FORMAT_UNSIGNED<setult, CmpLT>;
1577*9880d681SAndroid Build Coastguard Workerdefm : ISET_FORMAT_UNSIGNED<setuge, CmpGE>;
1578*9880d681SAndroid Build Coastguard Workerdefm : ISET_FORMAT_UNSIGNED<setule, CmpLE>;
1579*9880d681SAndroid Build Coastguard Workerdefm : ISET_FORMAT_UNSIGNED<setueq, CmpEQ>;
1580*9880d681SAndroid Build Coastguard Workerdefm : ISET_FORMAT_UNSIGNED<setune, CmpNE>;
1581*9880d681SAndroid Build Coastguard Worker
1582*9880d681SAndroid Build Coastguard Worker// i1 compares
1583*9880d681SAndroid Build Coastguard Workerdef : Pat<(setne Int1Regs:$a, Int1Regs:$b),
1584*9880d681SAndroid Build Coastguard Worker          (XORb1rr Int1Regs:$a, Int1Regs:$b)>;
1585*9880d681SAndroid Build Coastguard Workerdef : Pat<(setune Int1Regs:$a, Int1Regs:$b),
1586*9880d681SAndroid Build Coastguard Worker          (XORb1rr Int1Regs:$a, Int1Regs:$b)>;
1587*9880d681SAndroid Build Coastguard Worker
1588*9880d681SAndroid Build Coastguard Workerdef : Pat<(seteq Int1Regs:$a, Int1Regs:$b),
1589*9880d681SAndroid Build Coastguard Worker          (NOT1 (XORb1rr Int1Regs:$a, Int1Regs:$b))>;
1590*9880d681SAndroid Build Coastguard Workerdef : Pat<(setueq Int1Regs:$a, Int1Regs:$b),
1591*9880d681SAndroid Build Coastguard Worker          (NOT1 (XORb1rr Int1Regs:$a, Int1Regs:$b))>;
1592*9880d681SAndroid Build Coastguard Worker
1593*9880d681SAndroid Build Coastguard Worker// i1 compare -> i32
1594*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (setne Int1Regs:$a, Int1Regs:$b)),
1595*9880d681SAndroid Build Coastguard Worker          (SELP_u32ii -1, 0, (XORb1rr Int1Regs:$a, Int1Regs:$b))>;
1596*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (setne Int1Regs:$a, Int1Regs:$b)),
1597*9880d681SAndroid Build Coastguard Worker          (SELP_u32ii 0, -1, (XORb1rr Int1Regs:$a, Int1Regs:$b))>;
1598*9880d681SAndroid Build Coastguard Worker
1599*9880d681SAndroid Build Coastguard Worker
1600*9880d681SAndroid Build Coastguard Worker
1601*9880d681SAndroid Build Coastguard Workermulticlass FSET_FORMAT<PatFrag OpNode, PatLeaf Mode, PatLeaf ModeFTZ> {
1602*9880d681SAndroid Build Coastguard Worker  // f32 -> pred
1603*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode Float32Regs:$a, Float32Regs:$b)),
1604*9880d681SAndroid Build Coastguard Worker            (SETP_f32rr Float32Regs:$a, Float32Regs:$b, ModeFTZ)>,
1605*9880d681SAndroid Build Coastguard Worker        Requires<[doF32FTZ]>;
1606*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode Float32Regs:$a, Float32Regs:$b)),
1607*9880d681SAndroid Build Coastguard Worker            (SETP_f32rr Float32Regs:$a, Float32Regs:$b, Mode)>;
1608*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode Float32Regs:$a, fpimm:$b)),
1609*9880d681SAndroid Build Coastguard Worker            (SETP_f32ri Float32Regs:$a, fpimm:$b, ModeFTZ)>,
1610*9880d681SAndroid Build Coastguard Worker        Requires<[doF32FTZ]>;
1611*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode Float32Regs:$a, fpimm:$b)),
1612*9880d681SAndroid Build Coastguard Worker            (SETP_f32ri Float32Regs:$a, fpimm:$b, Mode)>;
1613*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode fpimm:$a, Float32Regs:$b)),
1614*9880d681SAndroid Build Coastguard Worker            (SETP_f32ir fpimm:$a, Float32Regs:$b, ModeFTZ)>,
1615*9880d681SAndroid Build Coastguard Worker        Requires<[doF32FTZ]>;
1616*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode fpimm:$a, Float32Regs:$b)),
1617*9880d681SAndroid Build Coastguard Worker            (SETP_f32ir fpimm:$a, Float32Regs:$b, Mode)>;
1618*9880d681SAndroid Build Coastguard Worker
1619*9880d681SAndroid Build Coastguard Worker  // f64 -> pred
1620*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode Float64Regs:$a, Float64Regs:$b)),
1621*9880d681SAndroid Build Coastguard Worker            (SETP_f64rr Float64Regs:$a, Float64Regs:$b, Mode)>;
1622*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode Float64Regs:$a, fpimm:$b)),
1623*9880d681SAndroid Build Coastguard Worker            (SETP_f64ri Float64Regs:$a, fpimm:$b, Mode)>;
1624*9880d681SAndroid Build Coastguard Worker  def : Pat<(i1 (OpNode fpimm:$a, Float64Regs:$b)),
1625*9880d681SAndroid Build Coastguard Worker            (SETP_f64ir fpimm:$a, Float64Regs:$b, Mode)>;
1626*9880d681SAndroid Build Coastguard Worker
1627*9880d681SAndroid Build Coastguard Worker  // f32 -> i32
1628*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode Float32Regs:$a, Float32Regs:$b)),
1629*9880d681SAndroid Build Coastguard Worker            (SET_f32rr Float32Regs:$a, Float32Regs:$b, ModeFTZ)>,
1630*9880d681SAndroid Build Coastguard Worker        Requires<[doF32FTZ]>;
1631*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode Float32Regs:$a, Float32Regs:$b)),
1632*9880d681SAndroid Build Coastguard Worker            (SET_f32rr Float32Regs:$a, Float32Regs:$b, Mode)>;
1633*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode Float32Regs:$a, fpimm:$b)),
1634*9880d681SAndroid Build Coastguard Worker            (SET_f32ri Float32Regs:$a, fpimm:$b, ModeFTZ)>,
1635*9880d681SAndroid Build Coastguard Worker        Requires<[doF32FTZ]>;
1636*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode Float32Regs:$a, fpimm:$b)),
1637*9880d681SAndroid Build Coastguard Worker            (SET_f32ri Float32Regs:$a, fpimm:$b, Mode)>;
1638*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode fpimm:$a, Float32Regs:$b)),
1639*9880d681SAndroid Build Coastguard Worker            (SET_f32ir fpimm:$a, Float32Regs:$b, ModeFTZ)>,
1640*9880d681SAndroid Build Coastguard Worker        Requires<[doF32FTZ]>;
1641*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode fpimm:$a, Float32Regs:$b)),
1642*9880d681SAndroid Build Coastguard Worker            (SET_f32ir fpimm:$a, Float32Regs:$b, Mode)>;
1643*9880d681SAndroid Build Coastguard Worker
1644*9880d681SAndroid Build Coastguard Worker  // f64 -> i32
1645*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode Float64Regs:$a, Float64Regs:$b)),
1646*9880d681SAndroid Build Coastguard Worker            (SET_f64rr Float64Regs:$a, Float64Regs:$b, Mode)>;
1647*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode Float64Regs:$a, fpimm:$b)),
1648*9880d681SAndroid Build Coastguard Worker            (SET_f64ri Float64Regs:$a, fpimm:$b, Mode)>;
1649*9880d681SAndroid Build Coastguard Worker  def : Pat<(i32 (OpNode fpimm:$a, Float64Regs:$b)),
1650*9880d681SAndroid Build Coastguard Worker            (SET_f64ir fpimm:$a, Float64Regs:$b, Mode)>;
1651*9880d681SAndroid Build Coastguard Worker}
1652*9880d681SAndroid Build Coastguard Worker
1653*9880d681SAndroid Build Coastguard Workerdefm FSetOGT : FSET_FORMAT<setogt, CmpGT, CmpGT_FTZ>;
1654*9880d681SAndroid Build Coastguard Workerdefm FSetOLT : FSET_FORMAT<setolt, CmpLT, CmpLT_FTZ>;
1655*9880d681SAndroid Build Coastguard Workerdefm FSetOGE : FSET_FORMAT<setoge, CmpGE, CmpGE_FTZ>;
1656*9880d681SAndroid Build Coastguard Workerdefm FSetOLE : FSET_FORMAT<setole, CmpLE, CmpLE_FTZ>;
1657*9880d681SAndroid Build Coastguard Workerdefm FSetOEQ : FSET_FORMAT<setoeq, CmpEQ, CmpEQ_FTZ>;
1658*9880d681SAndroid Build Coastguard Workerdefm FSetONE : FSET_FORMAT<setone, CmpNE, CmpNE_FTZ>;
1659*9880d681SAndroid Build Coastguard Worker
1660*9880d681SAndroid Build Coastguard Workerdefm FSetUGT : FSET_FORMAT<setugt, CmpGTU, CmpGTU_FTZ>;
1661*9880d681SAndroid Build Coastguard Workerdefm FSetULT : FSET_FORMAT<setult, CmpLTU, CmpLTU_FTZ>;
1662*9880d681SAndroid Build Coastguard Workerdefm FSetUGE : FSET_FORMAT<setuge, CmpGEU, CmpGEU_FTZ>;
1663*9880d681SAndroid Build Coastguard Workerdefm FSetULE : FSET_FORMAT<setule, CmpLEU, CmpLEU_FTZ>;
1664*9880d681SAndroid Build Coastguard Workerdefm FSetUEQ : FSET_FORMAT<setueq, CmpEQU, CmpEQU_FTZ>;
1665*9880d681SAndroid Build Coastguard Workerdefm FSetUNE : FSET_FORMAT<setune, CmpNEU, CmpNEU_FTZ>;
1666*9880d681SAndroid Build Coastguard Worker
1667*9880d681SAndroid Build Coastguard Workerdefm FSetGT : FSET_FORMAT<setgt, CmpGT, CmpGT_FTZ>;
1668*9880d681SAndroid Build Coastguard Workerdefm FSetLT : FSET_FORMAT<setlt, CmpLT, CmpLT_FTZ>;
1669*9880d681SAndroid Build Coastguard Workerdefm FSetGE : FSET_FORMAT<setge, CmpGE, CmpGE_FTZ>;
1670*9880d681SAndroid Build Coastguard Workerdefm FSetLE : FSET_FORMAT<setle, CmpLE, CmpLE_FTZ>;
1671*9880d681SAndroid Build Coastguard Workerdefm FSetEQ : FSET_FORMAT<seteq, CmpEQ, CmpEQ_FTZ>;
1672*9880d681SAndroid Build Coastguard Workerdefm FSetNE : FSET_FORMAT<setne, CmpNE, CmpNE_FTZ>;
1673*9880d681SAndroid Build Coastguard Worker
1674*9880d681SAndroid Build Coastguard Workerdefm FSetNUM : FSET_FORMAT<seto, CmpNUM, CmpNUM_FTZ>;
1675*9880d681SAndroid Build Coastguard Workerdefm FSetNAN : FSET_FORMAT<setuo, CmpNAN, CmpNAN_FTZ>;
1676*9880d681SAndroid Build Coastguard Worker
1677*9880d681SAndroid Build Coastguard Worker// FIXME: What is this doing here?  Can it be deleted?
1678*9880d681SAndroid Build Coastguard Worker// def ld_param         : SDNode<"NVPTXISD::LOAD_PARAM", SDTLoad,
1679*9880d681SAndroid Build Coastguard Worker//                         [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
1680*9880d681SAndroid Build Coastguard Worker
1681*9880d681SAndroid Build Coastguard Workerdef SDTDeclareParamProfile :
1682*9880d681SAndroid Build Coastguard Worker  SDTypeProfile<0, 3, [SDTCisInt<0>, SDTCisInt<1>, SDTCisInt<2>]>;
1683*9880d681SAndroid Build Coastguard Workerdef SDTDeclareScalarParamProfile :
1684*9880d681SAndroid Build Coastguard Worker  SDTypeProfile<0, 3, [SDTCisInt<0>, SDTCisInt<1>, SDTCisInt<2>]>;
1685*9880d681SAndroid Build Coastguard Workerdef SDTLoadParamProfile : SDTypeProfile<1, 2, [SDTCisInt<1>, SDTCisInt<2>]>;
1686*9880d681SAndroid Build Coastguard Workerdef SDTLoadParamV2Profile : SDTypeProfile<2, 2, [SDTCisSameAs<0, 1>, SDTCisInt<2>, SDTCisInt<3>]>;
1687*9880d681SAndroid Build Coastguard Workerdef SDTLoadParamV4Profile : SDTypeProfile<4, 2, [SDTCisInt<4>, SDTCisInt<5>]>;
1688*9880d681SAndroid Build Coastguard Workerdef SDTPrintCallProfile : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
1689*9880d681SAndroid Build Coastguard Workerdef SDTPrintCallUniProfile : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
1690*9880d681SAndroid Build Coastguard Workerdef SDTStoreParamProfile : SDTypeProfile<0, 3, [SDTCisInt<0>, SDTCisInt<1>]>;
1691*9880d681SAndroid Build Coastguard Workerdef SDTStoreParamV2Profile : SDTypeProfile<0, 4, [SDTCisInt<0>, SDTCisInt<1>]>;
1692*9880d681SAndroid Build Coastguard Workerdef SDTStoreParamV4Profile : SDTypeProfile<0, 6, [SDTCisInt<0>, SDTCisInt<1>]>;
1693*9880d681SAndroid Build Coastguard Workerdef SDTStoreParam32Profile : SDTypeProfile<0, 3, [SDTCisInt<0>, SDTCisInt<1>]>;
1694*9880d681SAndroid Build Coastguard Workerdef SDTCallArgProfile : SDTypeProfile<0, 2, [SDTCisInt<0>]>;
1695*9880d681SAndroid Build Coastguard Workerdef SDTCallArgMarkProfile : SDTypeProfile<0, 0, []>;
1696*9880d681SAndroid Build Coastguard Workerdef SDTCallVoidProfile : SDTypeProfile<0, 1, []>;
1697*9880d681SAndroid Build Coastguard Workerdef SDTCallValProfile : SDTypeProfile<1, 0, []>;
1698*9880d681SAndroid Build Coastguard Workerdef SDTMoveParamProfile : SDTypeProfile<1, 1, []>;
1699*9880d681SAndroid Build Coastguard Workerdef SDTStoreRetvalProfile : SDTypeProfile<0, 2, [SDTCisInt<0>]>;
1700*9880d681SAndroid Build Coastguard Workerdef SDTStoreRetvalV2Profile : SDTypeProfile<0, 3, [SDTCisInt<0>]>;
1701*9880d681SAndroid Build Coastguard Workerdef SDTStoreRetvalV4Profile : SDTypeProfile<0, 5, [SDTCisInt<0>]>;
1702*9880d681SAndroid Build Coastguard Workerdef SDTPseudoUseParamProfile : SDTypeProfile<0, 1, []>;
1703*9880d681SAndroid Build Coastguard Worker
1704*9880d681SAndroid Build Coastguard Workerdef DeclareParam :
1705*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::DeclareParam", SDTDeclareParamProfile,
1706*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1707*9880d681SAndroid Build Coastguard Workerdef DeclareScalarParam :
1708*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::DeclareScalarParam", SDTDeclareScalarParamProfile,
1709*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1710*9880d681SAndroid Build Coastguard Workerdef DeclareRetParam :
1711*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::DeclareRetParam", SDTDeclareParamProfile,
1712*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1713*9880d681SAndroid Build Coastguard Workerdef DeclareRet :
1714*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::DeclareRet", SDTDeclareScalarParamProfile,
1715*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1716*9880d681SAndroid Build Coastguard Workerdef LoadParam :
1717*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::LoadParam", SDTLoadParamProfile,
1718*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPMayLoad, SDNPOutGlue, SDNPInGlue]>;
1719*9880d681SAndroid Build Coastguard Workerdef LoadParamV2 :
1720*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::LoadParamV2", SDTLoadParamV2Profile,
1721*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPMayLoad, SDNPOutGlue, SDNPInGlue]>;
1722*9880d681SAndroid Build Coastguard Workerdef LoadParamV4 :
1723*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::LoadParamV4", SDTLoadParamV4Profile,
1724*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPMayLoad, SDNPOutGlue, SDNPInGlue]>;
1725*9880d681SAndroid Build Coastguard Workerdef PrintCall :
1726*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::PrintCall", SDTPrintCallProfile,
1727*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1728*9880d681SAndroid Build Coastguard Workerdef PrintConvergentCall :
1729*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::PrintConvergentCall", SDTPrintCallProfile,
1730*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1731*9880d681SAndroid Build Coastguard Workerdef PrintCallUni :
1732*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::PrintCallUni", SDTPrintCallUniProfile,
1733*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1734*9880d681SAndroid Build Coastguard Workerdef PrintConvergentCallUni :
1735*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::PrintConvergentCallUni", SDTPrintCallUniProfile,
1736*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1737*9880d681SAndroid Build Coastguard Workerdef StoreParam :
1738*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::StoreParam", SDTStoreParamProfile,
1739*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1740*9880d681SAndroid Build Coastguard Workerdef StoreParamV2 :
1741*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::StoreParamV2", SDTStoreParamV2Profile,
1742*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1743*9880d681SAndroid Build Coastguard Workerdef StoreParamV4 :
1744*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::StoreParamV4", SDTStoreParamV4Profile,
1745*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1746*9880d681SAndroid Build Coastguard Workerdef StoreParamU32 :
1747*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::StoreParamU32", SDTStoreParam32Profile,
1748*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1749*9880d681SAndroid Build Coastguard Workerdef StoreParamS32 :
1750*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::StoreParamS32", SDTStoreParam32Profile,
1751*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1752*9880d681SAndroid Build Coastguard Workerdef CallArgBegin :
1753*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::CallArgBegin", SDTCallArgMarkProfile,
1754*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1755*9880d681SAndroid Build Coastguard Workerdef CallArg :
1756*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::CallArg", SDTCallArgProfile,
1757*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1758*9880d681SAndroid Build Coastguard Workerdef LastCallArg :
1759*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::LastCallArg", SDTCallArgProfile,
1760*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1761*9880d681SAndroid Build Coastguard Workerdef CallArgEnd :
1762*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::CallArgEnd", SDTCallVoidProfile,
1763*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1764*9880d681SAndroid Build Coastguard Workerdef CallVoid :
1765*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::CallVoid", SDTCallVoidProfile,
1766*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1767*9880d681SAndroid Build Coastguard Workerdef Prototype :
1768*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::Prototype", SDTCallVoidProfile,
1769*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1770*9880d681SAndroid Build Coastguard Workerdef CallVal :
1771*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::CallVal", SDTCallValProfile,
1772*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1773*9880d681SAndroid Build Coastguard Workerdef MoveParam :
1774*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::MoveParam", SDTMoveParamProfile, []>;
1775*9880d681SAndroid Build Coastguard Workerdef StoreRetval :
1776*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::StoreRetval", SDTStoreRetvalProfile,
1777*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPSideEffect]>;
1778*9880d681SAndroid Build Coastguard Workerdef StoreRetvalV2 :
1779*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::StoreRetvalV2", SDTStoreRetvalV2Profile,
1780*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPSideEffect]>;
1781*9880d681SAndroid Build Coastguard Workerdef StoreRetvalV4 :
1782*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::StoreRetvalV4", SDTStoreRetvalV4Profile,
1783*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPSideEffect]>;
1784*9880d681SAndroid Build Coastguard Workerdef PseudoUseParam :
1785*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::PseudoUseParam", SDTPseudoUseParamProfile,
1786*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
1787*9880d681SAndroid Build Coastguard Workerdef RETURNNode :
1788*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::RETURN", SDTCallArgMarkProfile,
1789*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPSideEffect]>;
1790*9880d681SAndroid Build Coastguard Worker
1791*9880d681SAndroid Build Coastguard Workerlet mayLoad = 1 in {
1792*9880d681SAndroid Build Coastguard Worker  class LoadParamMemInst<NVPTXRegClass regclass, string opstr> :
1793*9880d681SAndroid Build Coastguard Worker        NVPTXInst<(outs regclass:$dst), (ins i32imm:$b),
1794*9880d681SAndroid Build Coastguard Worker                  !strconcat(!strconcat("ld.param", opstr),
1795*9880d681SAndroid Build Coastguard Worker                             "\t$dst, [retval0+$b];"),
1796*9880d681SAndroid Build Coastguard Worker                  []>;
1797*9880d681SAndroid Build Coastguard Worker
1798*9880d681SAndroid Build Coastguard Worker  class LoadParamV2MemInst<NVPTXRegClass regclass, string opstr> :
1799*9880d681SAndroid Build Coastguard Worker        NVPTXInst<(outs regclass:$dst, regclass:$dst2), (ins i32imm:$b),
1800*9880d681SAndroid Build Coastguard Worker                  !strconcat("ld.param.v2", opstr,
1801*9880d681SAndroid Build Coastguard Worker                             "\t{{$dst, $dst2}}, [retval0+$b];"), []>;
1802*9880d681SAndroid Build Coastguard Worker
1803*9880d681SAndroid Build Coastguard Worker  class LoadParamV4MemInst<NVPTXRegClass regclass, string opstr> :
1804*9880d681SAndroid Build Coastguard Worker        NVPTXInst<(outs regclass:$dst, regclass:$dst2, regclass:$dst3,
1805*9880d681SAndroid Build Coastguard Worker                        regclass:$dst4),
1806*9880d681SAndroid Build Coastguard Worker                  (ins i32imm:$b),
1807*9880d681SAndroid Build Coastguard Worker                  !strconcat("ld.param.v4", opstr,
1808*9880d681SAndroid Build Coastguard Worker                             "\t{{$dst, $dst2, $dst3, $dst4}}, [retval0+$b];"),
1809*9880d681SAndroid Build Coastguard Worker                  []>;
1810*9880d681SAndroid Build Coastguard Worker}
1811*9880d681SAndroid Build Coastguard Worker
1812*9880d681SAndroid Build Coastguard Workerclass LoadParamRegInst<NVPTXRegClass regclass, string opstr> :
1813*9880d681SAndroid Build Coastguard Worker      NVPTXInst<(outs regclass:$dst), (ins i32imm:$b),
1814*9880d681SAndroid Build Coastguard Worker                !strconcat("mov", opstr, "\t$dst, retval$b;"),
1815*9880d681SAndroid Build Coastguard Worker                [(set regclass:$dst, (LoadParam (i32 0), (i32 imm:$b)))]>;
1816*9880d681SAndroid Build Coastguard Worker
1817*9880d681SAndroid Build Coastguard Workerlet mayStore = 1 in {
1818*9880d681SAndroid Build Coastguard Worker  class StoreParamInst<NVPTXRegClass regclass, string opstr> :
1819*9880d681SAndroid Build Coastguard Worker        NVPTXInst<(outs), (ins regclass:$val, i32imm:$a, i32imm:$b),
1820*9880d681SAndroid Build Coastguard Worker                  !strconcat("st.param", opstr, "\t[param$a+$b], $val;"),
1821*9880d681SAndroid Build Coastguard Worker                  []>;
1822*9880d681SAndroid Build Coastguard Worker
1823*9880d681SAndroid Build Coastguard Worker  class StoreParamV2Inst<NVPTXRegClass regclass, string opstr> :
1824*9880d681SAndroid Build Coastguard Worker        NVPTXInst<(outs), (ins regclass:$val, regclass:$val2,
1825*9880d681SAndroid Build Coastguard Worker                               i32imm:$a, i32imm:$b),
1826*9880d681SAndroid Build Coastguard Worker                  !strconcat("st.param.v2", opstr,
1827*9880d681SAndroid Build Coastguard Worker                             "\t[param$a+$b], {{$val, $val2}};"),
1828*9880d681SAndroid Build Coastguard Worker                  []>;
1829*9880d681SAndroid Build Coastguard Worker
1830*9880d681SAndroid Build Coastguard Worker  class StoreParamV4Inst<NVPTXRegClass regclass, string opstr> :
1831*9880d681SAndroid Build Coastguard Worker        NVPTXInst<(outs), (ins regclass:$val, regclass:$val2, regclass:$val3,
1832*9880d681SAndroid Build Coastguard Worker                               regclass:$val4, i32imm:$a,
1833*9880d681SAndroid Build Coastguard Worker                               i32imm:$b),
1834*9880d681SAndroid Build Coastguard Worker                  !strconcat("st.param.v4", opstr,
1835*9880d681SAndroid Build Coastguard Worker                             "\t[param$a+$b], {{$val, $val2, $val3, $val4}};"),
1836*9880d681SAndroid Build Coastguard Worker                  []>;
1837*9880d681SAndroid Build Coastguard Worker
1838*9880d681SAndroid Build Coastguard Worker  class StoreRetvalInst<NVPTXRegClass regclass, string opstr> :
1839*9880d681SAndroid Build Coastguard Worker        NVPTXInst<(outs), (ins regclass:$val, i32imm:$a),
1840*9880d681SAndroid Build Coastguard Worker                  !strconcat("st.param", opstr, "\t[func_retval0+$a], $val;"),
1841*9880d681SAndroid Build Coastguard Worker                  []>;
1842*9880d681SAndroid Build Coastguard Worker
1843*9880d681SAndroid Build Coastguard Worker  class StoreRetvalV2Inst<NVPTXRegClass regclass, string opstr> :
1844*9880d681SAndroid Build Coastguard Worker        NVPTXInst<(outs), (ins regclass:$val, regclass:$val2, i32imm:$a),
1845*9880d681SAndroid Build Coastguard Worker                  !strconcat("st.param.v2", opstr,
1846*9880d681SAndroid Build Coastguard Worker                             "\t[func_retval0+$a], {{$val, $val2}};"),
1847*9880d681SAndroid Build Coastguard Worker                  []>;
1848*9880d681SAndroid Build Coastguard Worker
1849*9880d681SAndroid Build Coastguard Worker  class StoreRetvalV4Inst<NVPTXRegClass regclass, string opstr> :
1850*9880d681SAndroid Build Coastguard Worker        NVPTXInst<(outs),
1851*9880d681SAndroid Build Coastguard Worker                  (ins regclass:$val, regclass:$val2, regclass:$val3,
1852*9880d681SAndroid Build Coastguard Worker                       regclass:$val4, i32imm:$a),
1853*9880d681SAndroid Build Coastguard Worker                  !strconcat("st.param.v4", opstr,
1854*9880d681SAndroid Build Coastguard Worker                             "\t[func_retval0+$a], {{$val, $val2, $val3, $val4}};"),
1855*9880d681SAndroid Build Coastguard Worker                  []>;
1856*9880d681SAndroid Build Coastguard Worker}
1857*9880d681SAndroid Build Coastguard Worker
1858*9880d681SAndroid Build Coastguard Workerlet isCall=1 in {
1859*9880d681SAndroid Build Coastguard Worker  multiclass CALL<string OpcStr, SDNode OpNode> {
1860*9880d681SAndroid Build Coastguard Worker     def PrintCallNoRetInst : NVPTXInst<(outs), (ins),
1861*9880d681SAndroid Build Coastguard Worker       !strconcat(OpcStr, " "), [(OpNode (i32 0))]>;
1862*9880d681SAndroid Build Coastguard Worker     def PrintCallRetInst1 : NVPTXInst<(outs), (ins),
1863*9880d681SAndroid Build Coastguard Worker       !strconcat(OpcStr, " (retval0), "), [(OpNode (i32 1))]>;
1864*9880d681SAndroid Build Coastguard Worker     def PrintCallRetInst2 : NVPTXInst<(outs), (ins),
1865*9880d681SAndroid Build Coastguard Worker       !strconcat(OpcStr, " (retval0, retval1), "), [(OpNode (i32 2))]>;
1866*9880d681SAndroid Build Coastguard Worker     def PrintCallRetInst3 : NVPTXInst<(outs), (ins),
1867*9880d681SAndroid Build Coastguard Worker       !strconcat(OpcStr, " (retval0, retval1, retval2), "), [(OpNode (i32 3))]>;
1868*9880d681SAndroid Build Coastguard Worker     def PrintCallRetInst4 : NVPTXInst<(outs), (ins),
1869*9880d681SAndroid Build Coastguard Worker       !strconcat(OpcStr, " (retval0, retval1, retval2, retval3), "),
1870*9880d681SAndroid Build Coastguard Worker       [(OpNode (i32 4))]>;
1871*9880d681SAndroid Build Coastguard Worker     def PrintCallRetInst5 : NVPTXInst<(outs), (ins),
1872*9880d681SAndroid Build Coastguard Worker       !strconcat(OpcStr, " (retval0, retval1, retval2, retval3, retval4), "),
1873*9880d681SAndroid Build Coastguard Worker       [(OpNode (i32 5))]>;
1874*9880d681SAndroid Build Coastguard Worker     def PrintCallRetInst6 : NVPTXInst<(outs), (ins),
1875*9880d681SAndroid Build Coastguard Worker       !strconcat(OpcStr, " (retval0, retval1, retval2, retval3, retval4, "
1876*9880d681SAndroid Build Coastguard Worker                            "retval5), "),
1877*9880d681SAndroid Build Coastguard Worker       [(OpNode (i32 6))]>;
1878*9880d681SAndroid Build Coastguard Worker     def PrintCallRetInst7 : NVPTXInst<(outs), (ins),
1879*9880d681SAndroid Build Coastguard Worker       !strconcat(OpcStr, " (retval0, retval1, retval2, retval3, retval4, "
1880*9880d681SAndroid Build Coastguard Worker                            "retval5, retval6), "),
1881*9880d681SAndroid Build Coastguard Worker       [(OpNode (i32 7))]>;
1882*9880d681SAndroid Build Coastguard Worker     def PrintCallRetInst8 : NVPTXInst<(outs), (ins),
1883*9880d681SAndroid Build Coastguard Worker       !strconcat(OpcStr, " (retval0, retval1, retval2, retval3, retval4, "
1884*9880d681SAndroid Build Coastguard Worker                            "retval5, retval6, retval7), "),
1885*9880d681SAndroid Build Coastguard Worker       [(OpNode (i32 8))]>;
1886*9880d681SAndroid Build Coastguard Worker  }
1887*9880d681SAndroid Build Coastguard Worker}
1888*9880d681SAndroid Build Coastguard Worker
1889*9880d681SAndroid Build Coastguard Workerdefm Call : CALL<"call", PrintCall>;
1890*9880d681SAndroid Build Coastguard Workerdefm CallUni : CALL<"call.uni", PrintCallUni>;
1891*9880d681SAndroid Build Coastguard Worker
1892*9880d681SAndroid Build Coastguard Worker// Convergent call instructions.  These are identical to regular calls, except
1893*9880d681SAndroid Build Coastguard Worker// they have the isConvergent bit set.
1894*9880d681SAndroid Build Coastguard Workerlet isConvergent=1 in {
1895*9880d681SAndroid Build Coastguard Worker  defm ConvergentCall : CALL<"call", PrintConvergentCall>;
1896*9880d681SAndroid Build Coastguard Worker  defm ConvergentCallUni : CALL<"call.uni", PrintConvergentCallUni>;
1897*9880d681SAndroid Build Coastguard Worker}
1898*9880d681SAndroid Build Coastguard Worker
1899*9880d681SAndroid Build Coastguard Workerdef LoadParamMemI64    : LoadParamMemInst<Int64Regs, ".b64">;
1900*9880d681SAndroid Build Coastguard Workerdef LoadParamMemI32    : LoadParamMemInst<Int32Regs, ".b32">;
1901*9880d681SAndroid Build Coastguard Workerdef LoadParamMemI16    : LoadParamMemInst<Int16Regs, ".b16">;
1902*9880d681SAndroid Build Coastguard Workerdef LoadParamMemI8     : LoadParamMemInst<Int16Regs, ".b8">;
1903*9880d681SAndroid Build Coastguard Workerdef LoadParamMemV2I64  : LoadParamV2MemInst<Int64Regs, ".b64">;
1904*9880d681SAndroid Build Coastguard Workerdef LoadParamMemV2I32  : LoadParamV2MemInst<Int32Regs, ".b32">;
1905*9880d681SAndroid Build Coastguard Workerdef LoadParamMemV2I16  : LoadParamV2MemInst<Int16Regs, ".b16">;
1906*9880d681SAndroid Build Coastguard Workerdef LoadParamMemV2I8   : LoadParamV2MemInst<Int16Regs, ".b8">;
1907*9880d681SAndroid Build Coastguard Workerdef LoadParamMemV4I32  : LoadParamV4MemInst<Int32Regs, ".b32">;
1908*9880d681SAndroid Build Coastguard Workerdef LoadParamMemV4I16  : LoadParamV4MemInst<Int16Regs, ".b16">;
1909*9880d681SAndroid Build Coastguard Workerdef LoadParamMemV4I8   : LoadParamV4MemInst<Int16Regs, ".b8">;
1910*9880d681SAndroid Build Coastguard Workerdef LoadParamMemF32    : LoadParamMemInst<Float32Regs, ".f32">;
1911*9880d681SAndroid Build Coastguard Workerdef LoadParamMemF64    : LoadParamMemInst<Float64Regs, ".f64">;
1912*9880d681SAndroid Build Coastguard Workerdef LoadParamMemV2F32  : LoadParamV2MemInst<Float32Regs, ".f32">;
1913*9880d681SAndroid Build Coastguard Workerdef LoadParamMemV2F64  : LoadParamV2MemInst<Float64Regs, ".f64">;
1914*9880d681SAndroid Build Coastguard Workerdef LoadParamMemV4F32  : LoadParamV4MemInst<Float32Regs, ".f32">;
1915*9880d681SAndroid Build Coastguard Worker
1916*9880d681SAndroid Build Coastguard Workerdef StoreParamI64    : StoreParamInst<Int64Regs, ".b64">;
1917*9880d681SAndroid Build Coastguard Workerdef StoreParamI32    : StoreParamInst<Int32Regs, ".b32">;
1918*9880d681SAndroid Build Coastguard Worker
1919*9880d681SAndroid Build Coastguard Workerdef StoreParamI16    : StoreParamInst<Int16Regs, ".b16">;
1920*9880d681SAndroid Build Coastguard Workerdef StoreParamI8     : StoreParamInst<Int16Regs, ".b8">;
1921*9880d681SAndroid Build Coastguard Workerdef StoreParamV2I64  : StoreParamV2Inst<Int64Regs, ".b64">;
1922*9880d681SAndroid Build Coastguard Workerdef StoreParamV2I32  : StoreParamV2Inst<Int32Regs, ".b32">;
1923*9880d681SAndroid Build Coastguard Workerdef StoreParamV2I16  : StoreParamV2Inst<Int16Regs, ".b16">;
1924*9880d681SAndroid Build Coastguard Workerdef StoreParamV2I8   : StoreParamV2Inst<Int16Regs, ".b8">;
1925*9880d681SAndroid Build Coastguard Worker
1926*9880d681SAndroid Build Coastguard Workerdef StoreParamV4I32  : StoreParamV4Inst<Int32Regs, ".b32">;
1927*9880d681SAndroid Build Coastguard Workerdef StoreParamV4I16  : StoreParamV4Inst<Int16Regs, ".b16">;
1928*9880d681SAndroid Build Coastguard Workerdef StoreParamV4I8   : StoreParamV4Inst<Int16Regs, ".b8">;
1929*9880d681SAndroid Build Coastguard Worker
1930*9880d681SAndroid Build Coastguard Workerdef StoreParamF32      : StoreParamInst<Float32Regs, ".f32">;
1931*9880d681SAndroid Build Coastguard Workerdef StoreParamF64      : StoreParamInst<Float64Regs, ".f64">;
1932*9880d681SAndroid Build Coastguard Workerdef StoreParamV2F32    : StoreParamV2Inst<Float32Regs, ".f32">;
1933*9880d681SAndroid Build Coastguard Workerdef StoreParamV2F64    : StoreParamV2Inst<Float64Regs, ".f64">;
1934*9880d681SAndroid Build Coastguard Workerdef StoreParamV4F32    : StoreParamV4Inst<Float32Regs, ".f32">;
1935*9880d681SAndroid Build Coastguard Worker
1936*9880d681SAndroid Build Coastguard Workerdef StoreRetvalI64    : StoreRetvalInst<Int64Regs, ".b64">;
1937*9880d681SAndroid Build Coastguard Workerdef StoreRetvalI32    : StoreRetvalInst<Int32Regs, ".b32">;
1938*9880d681SAndroid Build Coastguard Workerdef StoreRetvalI16    : StoreRetvalInst<Int16Regs, ".b16">;
1939*9880d681SAndroid Build Coastguard Workerdef StoreRetvalI8     : StoreRetvalInst<Int16Regs, ".b8">;
1940*9880d681SAndroid Build Coastguard Workerdef StoreRetvalV2I64  : StoreRetvalV2Inst<Int64Regs, ".b64">;
1941*9880d681SAndroid Build Coastguard Workerdef StoreRetvalV2I32  : StoreRetvalV2Inst<Int32Regs, ".b32">;
1942*9880d681SAndroid Build Coastguard Workerdef StoreRetvalV2I16  : StoreRetvalV2Inst<Int16Regs, ".b16">;
1943*9880d681SAndroid Build Coastguard Workerdef StoreRetvalV2I8   : StoreRetvalV2Inst<Int16Regs, ".b8">;
1944*9880d681SAndroid Build Coastguard Workerdef StoreRetvalV4I32  : StoreRetvalV4Inst<Int32Regs, ".b32">;
1945*9880d681SAndroid Build Coastguard Workerdef StoreRetvalV4I16  : StoreRetvalV4Inst<Int16Regs, ".b16">;
1946*9880d681SAndroid Build Coastguard Workerdef StoreRetvalV4I8   : StoreRetvalV4Inst<Int16Regs, ".b8">;
1947*9880d681SAndroid Build Coastguard Worker
1948*9880d681SAndroid Build Coastguard Workerdef StoreRetvalF64    : StoreRetvalInst<Float64Regs, ".f64">;
1949*9880d681SAndroid Build Coastguard Workerdef StoreRetvalF32    : StoreRetvalInst<Float32Regs, ".f32">;
1950*9880d681SAndroid Build Coastguard Workerdef StoreRetvalV2F64  : StoreRetvalV2Inst<Float64Regs, ".f64">;
1951*9880d681SAndroid Build Coastguard Workerdef StoreRetvalV2F32  : StoreRetvalV2Inst<Float32Regs, ".f32">;
1952*9880d681SAndroid Build Coastguard Workerdef StoreRetvalV4F32  : StoreRetvalV4Inst<Float32Regs, ".f32">;
1953*9880d681SAndroid Build Coastguard Worker
1954*9880d681SAndroid Build Coastguard Workerdef CallArgBeginInst : NVPTXInst<(outs), (ins), "(", [(CallArgBegin)]>;
1955*9880d681SAndroid Build Coastguard Workerdef CallArgEndInst1  : NVPTXInst<(outs), (ins), ");", [(CallArgEnd (i32 1))]>;
1956*9880d681SAndroid Build Coastguard Workerdef CallArgEndInst0  : NVPTXInst<(outs), (ins), ")", [(CallArgEnd (i32 0))]>;
1957*9880d681SAndroid Build Coastguard Workerdef RETURNInst       : NVPTXInst<(outs), (ins), "ret;", [(RETURNNode)]>;
1958*9880d681SAndroid Build Coastguard Worker
1959*9880d681SAndroid Build Coastguard Workerclass CallArgInst<NVPTXRegClass regclass> :
1960*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs), (ins regclass:$a), "$a, ",
1961*9880d681SAndroid Build Coastguard Worker            [(CallArg (i32 0), regclass:$a)]>;
1962*9880d681SAndroid Build Coastguard Worker
1963*9880d681SAndroid Build Coastguard Workerclass LastCallArgInst<NVPTXRegClass regclass> :
1964*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs), (ins regclass:$a), "$a",
1965*9880d681SAndroid Build Coastguard Worker            [(LastCallArg (i32 0), regclass:$a)]>;
1966*9880d681SAndroid Build Coastguard Worker
1967*9880d681SAndroid Build Coastguard Workerdef CallArgI64     : CallArgInst<Int64Regs>;
1968*9880d681SAndroid Build Coastguard Workerdef CallArgI32     : CallArgInst<Int32Regs>;
1969*9880d681SAndroid Build Coastguard Workerdef CallArgI16     : CallArgInst<Int16Regs>;
1970*9880d681SAndroid Build Coastguard Workerdef CallArgF64     : CallArgInst<Float64Regs>;
1971*9880d681SAndroid Build Coastguard Workerdef CallArgF32     : CallArgInst<Float32Regs>;
1972*9880d681SAndroid Build Coastguard Worker
1973*9880d681SAndroid Build Coastguard Workerdef LastCallArgI64 : LastCallArgInst<Int64Regs>;
1974*9880d681SAndroid Build Coastguard Workerdef LastCallArgI32 : LastCallArgInst<Int32Regs>;
1975*9880d681SAndroid Build Coastguard Workerdef LastCallArgI16 : LastCallArgInst<Int16Regs>;
1976*9880d681SAndroid Build Coastguard Workerdef LastCallArgF64 : LastCallArgInst<Float64Regs>;
1977*9880d681SAndroid Build Coastguard Workerdef LastCallArgF32 : LastCallArgInst<Float32Regs>;
1978*9880d681SAndroid Build Coastguard Worker
1979*9880d681SAndroid Build Coastguard Workerdef CallArgI32imm : NVPTXInst<(outs), (ins i32imm:$a), "$a, ",
1980*9880d681SAndroid Build Coastguard Worker                              [(CallArg (i32 0), (i32 imm:$a))]>;
1981*9880d681SAndroid Build Coastguard Workerdef LastCallArgI32imm : NVPTXInst<(outs), (ins i32imm:$a), "$a",
1982*9880d681SAndroid Build Coastguard Worker                                  [(LastCallArg (i32 0), (i32 imm:$a))]>;
1983*9880d681SAndroid Build Coastguard Worker
1984*9880d681SAndroid Build Coastguard Workerdef CallArgParam : NVPTXInst<(outs), (ins i32imm:$a), "param$a, ",
1985*9880d681SAndroid Build Coastguard Worker                             [(CallArg (i32 1), (i32 imm:$a))]>;
1986*9880d681SAndroid Build Coastguard Workerdef LastCallArgParam : NVPTXInst<(outs), (ins i32imm:$a), "param$a",
1987*9880d681SAndroid Build Coastguard Worker                                 [(LastCallArg (i32 1), (i32 imm:$a))]>;
1988*9880d681SAndroid Build Coastguard Worker
1989*9880d681SAndroid Build Coastguard Workerdef CallVoidInst :      NVPTXInst<(outs), (ins imem:$addr), "$addr, ",
1990*9880d681SAndroid Build Coastguard Worker                                  [(CallVoid (Wrapper tglobaladdr:$addr))]>;
1991*9880d681SAndroid Build Coastguard Workerdef CallVoidInstReg :   NVPTXInst<(outs), (ins Int32Regs:$addr), "$addr, ",
1992*9880d681SAndroid Build Coastguard Worker                                  [(CallVoid Int32Regs:$addr)]>;
1993*9880d681SAndroid Build Coastguard Workerdef CallVoidInstReg64 : NVPTXInst<(outs), (ins Int64Regs:$addr), "$addr, ",
1994*9880d681SAndroid Build Coastguard Worker                                  [(CallVoid Int64Regs:$addr)]>;
1995*9880d681SAndroid Build Coastguard Workerdef PrototypeInst :     NVPTXInst<(outs), (ins i32imm:$val), ", prototype_$val;",
1996*9880d681SAndroid Build Coastguard Worker                                  [(Prototype (i32 imm:$val))]>;
1997*9880d681SAndroid Build Coastguard Worker
1998*9880d681SAndroid Build Coastguard Workerdef DeclareRetMemInst :
1999*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs), (ins i32imm:$align, i32imm:$size, i32imm:$num),
2000*9880d681SAndroid Build Coastguard Worker            ".param .align $align .b8 retval$num[$size];",
2001*9880d681SAndroid Build Coastguard Worker            [(DeclareRetParam (i32 imm:$align), (i32 imm:$size), (i32 imm:$num))]>;
2002*9880d681SAndroid Build Coastguard Workerdef DeclareRetScalarInst :
2003*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs), (ins i32imm:$size, i32imm:$num),
2004*9880d681SAndroid Build Coastguard Worker            ".param .b$size retval$num;",
2005*9880d681SAndroid Build Coastguard Worker            [(DeclareRet (i32 1), (i32 imm:$size), (i32 imm:$num))]>;
2006*9880d681SAndroid Build Coastguard Workerdef DeclareRetRegInst :
2007*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs), (ins i32imm:$size, i32imm:$num),
2008*9880d681SAndroid Build Coastguard Worker            ".reg .b$size retval$num;",
2009*9880d681SAndroid Build Coastguard Worker            [(DeclareRet (i32 2), (i32 imm:$size), (i32 imm:$num))]>;
2010*9880d681SAndroid Build Coastguard Worker
2011*9880d681SAndroid Build Coastguard Workerdef DeclareParamInst :
2012*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs), (ins i32imm:$align, i32imm:$a, i32imm:$size),
2013*9880d681SAndroid Build Coastguard Worker            ".param .align $align .b8 param$a[$size];",
2014*9880d681SAndroid Build Coastguard Worker            [(DeclareParam (i32 imm:$align), (i32 imm:$a), (i32 imm:$size))]>;
2015*9880d681SAndroid Build Coastguard Workerdef DeclareScalarParamInst :
2016*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs), (ins i32imm:$a, i32imm:$size),
2017*9880d681SAndroid Build Coastguard Worker            ".param .b$size param$a;",
2018*9880d681SAndroid Build Coastguard Worker            [(DeclareScalarParam (i32 imm:$a), (i32 imm:$size), (i32 0))]>;
2019*9880d681SAndroid Build Coastguard Workerdef DeclareScalarRegInst :
2020*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs), (ins i32imm:$a, i32imm:$size),
2021*9880d681SAndroid Build Coastguard Worker            ".reg .b$size param$a;",
2022*9880d681SAndroid Build Coastguard Worker            [(DeclareScalarParam (i32 imm:$a), (i32 imm:$size), (i32 1))]>;
2023*9880d681SAndroid Build Coastguard Worker
2024*9880d681SAndroid Build Coastguard Workerclass MoveParamInst<NVPTXRegClass regclass, string asmstr> :
2025*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs regclass:$dst), (ins regclass:$src),
2026*9880d681SAndroid Build Coastguard Worker            !strconcat("mov", asmstr, "\t$dst, $src;"),
2027*9880d681SAndroid Build Coastguard Worker            [(set regclass:$dst, (MoveParam regclass:$src))]>;
2028*9880d681SAndroid Build Coastguard Worker
2029*9880d681SAndroid Build Coastguard Workerdef MoveParamI64 : MoveParamInst<Int64Regs, ".b64">;
2030*9880d681SAndroid Build Coastguard Workerdef MoveParamI32 : MoveParamInst<Int32Regs, ".b32">;
2031*9880d681SAndroid Build Coastguard Workerdef MoveParamI16 :
2032*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs Int16Regs:$dst), (ins Int16Regs:$src),
2033*9880d681SAndroid Build Coastguard Worker            "cvt.u16.u32\t$dst, $src;",
2034*9880d681SAndroid Build Coastguard Worker            [(set Int16Regs:$dst, (MoveParam Int16Regs:$src))]>;
2035*9880d681SAndroid Build Coastguard Workerdef MoveParamF64 : MoveParamInst<Float64Regs, ".f64">;
2036*9880d681SAndroid Build Coastguard Workerdef MoveParamF32 : MoveParamInst<Float32Regs, ".f32">;
2037*9880d681SAndroid Build Coastguard Worker
2038*9880d681SAndroid Build Coastguard Workerclass PseudoUseParamInst<NVPTXRegClass regclass> :
2039*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs), (ins regclass:$src),
2040*9880d681SAndroid Build Coastguard Worker            "// Pseudo use of $src",
2041*9880d681SAndroid Build Coastguard Worker            [(PseudoUseParam regclass:$src)]>;
2042*9880d681SAndroid Build Coastguard Worker
2043*9880d681SAndroid Build Coastguard Workerdef PseudoUseParamI64 : PseudoUseParamInst<Int64Regs>;
2044*9880d681SAndroid Build Coastguard Workerdef PseudoUseParamI32 : PseudoUseParamInst<Int32Regs>;
2045*9880d681SAndroid Build Coastguard Workerdef PseudoUseParamI16 : PseudoUseParamInst<Int16Regs>;
2046*9880d681SAndroid Build Coastguard Workerdef PseudoUseParamF64 : PseudoUseParamInst<Float64Regs>;
2047*9880d681SAndroid Build Coastguard Workerdef PseudoUseParamF32 : PseudoUseParamInst<Float32Regs>;
2048*9880d681SAndroid Build Coastguard Worker
2049*9880d681SAndroid Build Coastguard Worker
2050*9880d681SAndroid Build Coastguard Worker//
2051*9880d681SAndroid Build Coastguard Worker// Load / Store Handling
2052*9880d681SAndroid Build Coastguard Worker//
2053*9880d681SAndroid Build Coastguard Workermulticlass LD<NVPTXRegClass regclass> {
2054*9880d681SAndroid Build Coastguard Worker  def _avar : NVPTXInst<
2055*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst),
2056*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2057*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, imem:$addr),
2058*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2059*9880d681SAndroid Build Coastguard Worker    "\t$dst, [$addr];", []>;
2060*9880d681SAndroid Build Coastguard Worker  def _areg : NVPTXInst<
2061*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst),
2062*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2063*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, Int32Regs:$addr),
2064*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2065*9880d681SAndroid Build Coastguard Worker    "\t$dst, [$addr];", []>;
2066*9880d681SAndroid Build Coastguard Worker  def _areg_64 : NVPTXInst<
2067*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst),
2068*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2069*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, Int64Regs:$addr),
2070*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2071*9880d681SAndroid Build Coastguard Worker    "\t$dst, [$addr];", []>;
2072*9880d681SAndroid Build Coastguard Worker  def _ari : NVPTXInst<
2073*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst),
2074*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2075*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, Int32Regs:$addr, i32imm:$offset),
2076*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2077*9880d681SAndroid Build Coastguard Worker    "\t$dst, [$addr+$offset];", []>;
2078*9880d681SAndroid Build Coastguard Worker  def _ari_64 : NVPTXInst<
2079*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst),
2080*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec,
2081*9880d681SAndroid Build Coastguard Worker         LdStCode:$Sign, i32imm:$fromWidth, Int64Regs:$addr, i32imm:$offset),
2082*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2083*9880d681SAndroid Build Coastguard Worker    "\t$dst, [$addr+$offset];", []>;
2084*9880d681SAndroid Build Coastguard Worker  def _asi : NVPTXInst<
2085*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst),
2086*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec,
2087*9880d681SAndroid Build Coastguard Worker         LdStCode:$Sign, i32imm:$fromWidth, imem:$addr, i32imm:$offset),
2088*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2089*9880d681SAndroid Build Coastguard Worker    "\t$dst, [$addr+$offset];", []>;
2090*9880d681SAndroid Build Coastguard Worker}
2091*9880d681SAndroid Build Coastguard Worker
2092*9880d681SAndroid Build Coastguard Workerlet mayLoad=1, hasSideEffects=0 in {
2093*9880d681SAndroid Build Coastguard Worker  defm LD_i8  : LD<Int16Regs>;
2094*9880d681SAndroid Build Coastguard Worker  defm LD_i16 : LD<Int16Regs>;
2095*9880d681SAndroid Build Coastguard Worker  defm LD_i32 : LD<Int32Regs>;
2096*9880d681SAndroid Build Coastguard Worker  defm LD_i64 : LD<Int64Regs>;
2097*9880d681SAndroid Build Coastguard Worker  defm LD_f32 : LD<Float32Regs>;
2098*9880d681SAndroid Build Coastguard Worker  defm LD_f64 : LD<Float64Regs>;
2099*9880d681SAndroid Build Coastguard Worker}
2100*9880d681SAndroid Build Coastguard Worker
2101*9880d681SAndroid Build Coastguard Workermulticlass ST<NVPTXRegClass regclass> {
2102*9880d681SAndroid Build Coastguard Worker  def _avar : NVPTXInst<
2103*9880d681SAndroid Build Coastguard Worker    (outs),
2104*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src, LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec,
2105*9880d681SAndroid Build Coastguard Worker         LdStCode:$Sign, i32imm:$toWidth, imem:$addr),
2106*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$toWidth"
2107*9880d681SAndroid Build Coastguard Worker    " \t[$addr], $src;", []>;
2108*9880d681SAndroid Build Coastguard Worker  def _areg : NVPTXInst<
2109*9880d681SAndroid Build Coastguard Worker    (outs),
2110*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src, LdStCode:$isVol, LdStCode:$addsp,
2111*9880d681SAndroid Build Coastguard Worker         LdStCode:$Vec, LdStCode:$Sign, i32imm:$toWidth, Int32Regs:$addr),
2112*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$toWidth"
2113*9880d681SAndroid Build Coastguard Worker    " \t[$addr], $src;", []>;
2114*9880d681SAndroid Build Coastguard Worker  def _areg_64 : NVPTXInst<
2115*9880d681SAndroid Build Coastguard Worker    (outs),
2116*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src, LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec,
2117*9880d681SAndroid Build Coastguard Worker         LdStCode:$Sign, i32imm:$toWidth, Int64Regs:$addr),
2118*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$toWidth"
2119*9880d681SAndroid Build Coastguard Worker    " \t[$addr], $src;", []>;
2120*9880d681SAndroid Build Coastguard Worker  def _ari : NVPTXInst<
2121*9880d681SAndroid Build Coastguard Worker    (outs),
2122*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src, LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec,
2123*9880d681SAndroid Build Coastguard Worker         LdStCode:$Sign, i32imm:$toWidth, Int32Regs:$addr, i32imm:$offset),
2124*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$toWidth"
2125*9880d681SAndroid Build Coastguard Worker    " \t[$addr+$offset], $src;", []>;
2126*9880d681SAndroid Build Coastguard Worker  def _ari_64 : NVPTXInst<
2127*9880d681SAndroid Build Coastguard Worker    (outs),
2128*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src, LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec,
2129*9880d681SAndroid Build Coastguard Worker         LdStCode:$Sign, i32imm:$toWidth, Int64Regs:$addr, i32imm:$offset),
2130*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$toWidth"
2131*9880d681SAndroid Build Coastguard Worker    " \t[$addr+$offset], $src;", []>;
2132*9880d681SAndroid Build Coastguard Worker  def _asi : NVPTXInst<
2133*9880d681SAndroid Build Coastguard Worker    (outs),
2134*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src, LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec,
2135*9880d681SAndroid Build Coastguard Worker         LdStCode:$Sign, i32imm:$toWidth, imem:$addr, i32imm:$offset),
2136*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$toWidth"
2137*9880d681SAndroid Build Coastguard Worker    " \t[$addr+$offset], $src;", []>;
2138*9880d681SAndroid Build Coastguard Worker}
2139*9880d681SAndroid Build Coastguard Worker
2140*9880d681SAndroid Build Coastguard Workerlet mayStore=1, hasSideEffects=0 in {
2141*9880d681SAndroid Build Coastguard Worker  defm ST_i8  : ST<Int16Regs>;
2142*9880d681SAndroid Build Coastguard Worker  defm ST_i16 : ST<Int16Regs>;
2143*9880d681SAndroid Build Coastguard Worker  defm ST_i32 : ST<Int32Regs>;
2144*9880d681SAndroid Build Coastguard Worker  defm ST_i64 : ST<Int64Regs>;
2145*9880d681SAndroid Build Coastguard Worker  defm ST_f32 : ST<Float32Regs>;
2146*9880d681SAndroid Build Coastguard Worker  defm ST_f64 : ST<Float64Regs>;
2147*9880d681SAndroid Build Coastguard Worker}
2148*9880d681SAndroid Build Coastguard Worker
2149*9880d681SAndroid Build Coastguard Worker// The following is used only in and after vector elementizations.  Vector
2150*9880d681SAndroid Build Coastguard Worker// elementization happens at the machine instruction level, so the following
2151*9880d681SAndroid Build Coastguard Worker// instructions never appear in the DAG.
2152*9880d681SAndroid Build Coastguard Workermulticlass LD_VEC<NVPTXRegClass regclass> {
2153*9880d681SAndroid Build Coastguard Worker  def _v2_avar : NVPTXInst<
2154*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst1, regclass:$dst2),
2155*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2156*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, imem:$addr),
2157*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2158*9880d681SAndroid Build Coastguard Worker    "\t{{$dst1, $dst2}}, [$addr];", []>;
2159*9880d681SAndroid Build Coastguard Worker  def _v2_areg : NVPTXInst<
2160*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst1, regclass:$dst2),
2161*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2162*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, Int32Regs:$addr),
2163*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2164*9880d681SAndroid Build Coastguard Worker    "\t{{$dst1, $dst2}}, [$addr];", []>;
2165*9880d681SAndroid Build Coastguard Worker  def _v2_areg_64 : NVPTXInst<
2166*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst1, regclass:$dst2),
2167*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2168*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, Int64Regs:$addr),
2169*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2170*9880d681SAndroid Build Coastguard Worker    "\t{{$dst1, $dst2}}, [$addr];", []>;
2171*9880d681SAndroid Build Coastguard Worker  def _v2_ari : NVPTXInst<
2172*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst1, regclass:$dst2),
2173*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2174*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, Int32Regs:$addr, i32imm:$offset),
2175*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2176*9880d681SAndroid Build Coastguard Worker    "\t{{$dst1, $dst2}}, [$addr+$offset];", []>;
2177*9880d681SAndroid Build Coastguard Worker  def _v2_ari_64 : NVPTXInst<
2178*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst1, regclass:$dst2),
2179*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2180*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, Int64Regs:$addr, i32imm:$offset),
2181*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2182*9880d681SAndroid Build Coastguard Worker    "\t{{$dst1, $dst2}}, [$addr+$offset];", []>;
2183*9880d681SAndroid Build Coastguard Worker  def _v2_asi : NVPTXInst<
2184*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst1, regclass:$dst2),
2185*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2186*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, imem:$addr, i32imm:$offset),
2187*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2188*9880d681SAndroid Build Coastguard Worker    "\t{{$dst1, $dst2}}, [$addr+$offset];", []>;
2189*9880d681SAndroid Build Coastguard Worker  def _v4_avar : NVPTXInst<
2190*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst1, regclass:$dst2, regclass:$dst3, regclass:$dst4),
2191*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2192*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, imem:$addr),
2193*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2194*9880d681SAndroid Build Coastguard Worker    "\t{{$dst1, $dst2, $dst3, $dst4}}, [$addr];", []>;
2195*9880d681SAndroid Build Coastguard Worker  def _v4_areg : NVPTXInst<
2196*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst1, regclass:$dst2, regclass:$dst3, regclass:$dst4),
2197*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2198*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, Int32Regs:$addr),
2199*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2200*9880d681SAndroid Build Coastguard Worker    "\t{{$dst1, $dst2, $dst3, $dst4}}, [$addr];", []>;
2201*9880d681SAndroid Build Coastguard Worker  def _v4_areg_64 : NVPTXInst<
2202*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst1, regclass:$dst2, regclass:$dst3, regclass:$dst4),
2203*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2204*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, Int64Regs:$addr),
2205*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2206*9880d681SAndroid Build Coastguard Worker    "\t{{$dst1, $dst2, $dst3, $dst4}}, [$addr];", []>;
2207*9880d681SAndroid Build Coastguard Worker  def _v4_ari : NVPTXInst<
2208*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst1, regclass:$dst2, regclass:$dst3, regclass:$dst4),
2209*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2210*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, Int32Regs:$addr, i32imm:$offset),
2211*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2212*9880d681SAndroid Build Coastguard Worker    "\t{{$dst1, $dst2, $dst3, $dst4}}, [$addr+$offset];", []>;
2213*9880d681SAndroid Build Coastguard Worker  def _v4_ari_64 : NVPTXInst<
2214*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst1, regclass:$dst2, regclass:$dst3, regclass:$dst4),
2215*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2216*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, Int64Regs:$addr, i32imm:$offset),
2217*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2218*9880d681SAndroid Build Coastguard Worker    "\t{{$dst1, $dst2, $dst3, $dst4}}, [$addr+$offset];", []>;
2219*9880d681SAndroid Build Coastguard Worker  def _v4_asi : NVPTXInst<
2220*9880d681SAndroid Build Coastguard Worker    (outs regclass:$dst1, regclass:$dst2, regclass:$dst3, regclass:$dst4),
2221*9880d681SAndroid Build Coastguard Worker    (ins LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2222*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, imem:$addr, i32imm:$offset),
2223*9880d681SAndroid Build Coastguard Worker    "ld${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2224*9880d681SAndroid Build Coastguard Worker    "\t{{$dst1, $dst2, $dst3, $dst4}}, [$addr+$offset];", []>;
2225*9880d681SAndroid Build Coastguard Worker}
2226*9880d681SAndroid Build Coastguard Workerlet mayLoad=1, hasSideEffects=0 in {
2227*9880d681SAndroid Build Coastguard Worker  defm LDV_i8  : LD_VEC<Int16Regs>;
2228*9880d681SAndroid Build Coastguard Worker  defm LDV_i16 : LD_VEC<Int16Regs>;
2229*9880d681SAndroid Build Coastguard Worker  defm LDV_i32 : LD_VEC<Int32Regs>;
2230*9880d681SAndroid Build Coastguard Worker  defm LDV_i64 : LD_VEC<Int64Regs>;
2231*9880d681SAndroid Build Coastguard Worker  defm LDV_f32 : LD_VEC<Float32Regs>;
2232*9880d681SAndroid Build Coastguard Worker  defm LDV_f64 : LD_VEC<Float64Regs>;
2233*9880d681SAndroid Build Coastguard Worker}
2234*9880d681SAndroid Build Coastguard Worker
2235*9880d681SAndroid Build Coastguard Workermulticlass ST_VEC<NVPTXRegClass regclass> {
2236*9880d681SAndroid Build Coastguard Worker  def _v2_avar : NVPTXInst<
2237*9880d681SAndroid Build Coastguard Worker    (outs),
2238*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src1, regclass:$src2, LdStCode:$isVol, LdStCode:$addsp,
2239*9880d681SAndroid Build Coastguard Worker         LdStCode:$Vec, LdStCode:$Sign, i32imm:$fromWidth, imem:$addr),
2240*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2241*9880d681SAndroid Build Coastguard Worker    "\t[$addr], {{$src1, $src2}};", []>;
2242*9880d681SAndroid Build Coastguard Worker  def _v2_areg : NVPTXInst<
2243*9880d681SAndroid Build Coastguard Worker    (outs),
2244*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src1, regclass:$src2, LdStCode:$isVol, LdStCode:$addsp,
2245*9880d681SAndroid Build Coastguard Worker         LdStCode:$Vec, LdStCode:$Sign, i32imm:$fromWidth, Int32Regs:$addr),
2246*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2247*9880d681SAndroid Build Coastguard Worker    "\t[$addr], {{$src1, $src2}};", []>;
2248*9880d681SAndroid Build Coastguard Worker  def _v2_areg_64 : NVPTXInst<
2249*9880d681SAndroid Build Coastguard Worker    (outs),
2250*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src1, regclass:$src2, LdStCode:$isVol, LdStCode:$addsp,
2251*9880d681SAndroid Build Coastguard Worker         LdStCode:$Vec, LdStCode:$Sign, i32imm:$fromWidth, Int64Regs:$addr),
2252*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2253*9880d681SAndroid Build Coastguard Worker    "\t[$addr], {{$src1, $src2}};", []>;
2254*9880d681SAndroid Build Coastguard Worker  def _v2_ari : NVPTXInst<
2255*9880d681SAndroid Build Coastguard Worker    (outs),
2256*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src1, regclass:$src2, LdStCode:$isVol, LdStCode:$addsp,
2257*9880d681SAndroid Build Coastguard Worker         LdStCode:$Vec, LdStCode:$Sign, i32imm:$fromWidth, Int32Regs:$addr,
2258*9880d681SAndroid Build Coastguard Worker         i32imm:$offset),
2259*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2260*9880d681SAndroid Build Coastguard Worker    "\t[$addr+$offset], {{$src1, $src2}};", []>;
2261*9880d681SAndroid Build Coastguard Worker  def _v2_ari_64 : NVPTXInst<
2262*9880d681SAndroid Build Coastguard Worker    (outs),
2263*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src1, regclass:$src2, LdStCode:$isVol, LdStCode:$addsp,
2264*9880d681SAndroid Build Coastguard Worker         LdStCode:$Vec, LdStCode:$Sign, i32imm:$fromWidth, Int64Regs:$addr,
2265*9880d681SAndroid Build Coastguard Worker         i32imm:$offset),
2266*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2267*9880d681SAndroid Build Coastguard Worker    "\t[$addr+$offset], {{$src1, $src2}};", []>;
2268*9880d681SAndroid Build Coastguard Worker  def _v2_asi : NVPTXInst<
2269*9880d681SAndroid Build Coastguard Worker    (outs),
2270*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src1, regclass:$src2, LdStCode:$isVol, LdStCode:$addsp,
2271*9880d681SAndroid Build Coastguard Worker         LdStCode:$Vec, LdStCode:$Sign, i32imm:$fromWidth, imem:$addr,
2272*9880d681SAndroid Build Coastguard Worker         i32imm:$offset),
2273*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2274*9880d681SAndroid Build Coastguard Worker    "\t[$addr+$offset], {{$src1, $src2}};", []>;
2275*9880d681SAndroid Build Coastguard Worker  def _v4_avar : NVPTXInst<
2276*9880d681SAndroid Build Coastguard Worker    (outs),
2277*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src1, regclass:$src2, regclass:$src3, regclass:$src4,
2278*9880d681SAndroid Build Coastguard Worker         LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2279*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, imem:$addr),
2280*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2281*9880d681SAndroid Build Coastguard Worker    "\t[$addr], {{$src1, $src2, $src3, $src4}};", []>;
2282*9880d681SAndroid Build Coastguard Worker  def _v4_areg : NVPTXInst<
2283*9880d681SAndroid Build Coastguard Worker    (outs),
2284*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src1, regclass:$src2, regclass:$src3, regclass:$src4,
2285*9880d681SAndroid Build Coastguard Worker         LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2286*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, Int32Regs:$addr),
2287*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2288*9880d681SAndroid Build Coastguard Worker    "\t[$addr], {{$src1, $src2, $src3, $src4}};", []>;
2289*9880d681SAndroid Build Coastguard Worker  def _v4_areg_64 : NVPTXInst<
2290*9880d681SAndroid Build Coastguard Worker    (outs),
2291*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src1, regclass:$src2, regclass:$src3, regclass:$src4,
2292*9880d681SAndroid Build Coastguard Worker         LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2293*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, Int64Regs:$addr),
2294*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2295*9880d681SAndroid Build Coastguard Worker    "\t[$addr], {{$src1, $src2, $src3, $src4}};", []>;
2296*9880d681SAndroid Build Coastguard Worker  def _v4_ari : NVPTXInst<
2297*9880d681SAndroid Build Coastguard Worker    (outs),
2298*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src1, regclass:$src2, regclass:$src3, regclass:$src4,
2299*9880d681SAndroid Build Coastguard Worker         LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2300*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, Int32Regs:$addr, i32imm:$offset),
2301*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2302*9880d681SAndroid Build Coastguard Worker    "\t[$addr+$offset], {{$src1, $src2, $src3, $src4}};", []>;
2303*9880d681SAndroid Build Coastguard Worker  def _v4_ari_64 : NVPTXInst<
2304*9880d681SAndroid Build Coastguard Worker    (outs),
2305*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src1, regclass:$src2, regclass:$src3, regclass:$src4,
2306*9880d681SAndroid Build Coastguard Worker         LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2307*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, Int64Regs:$addr, i32imm:$offset),
2308*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}$fromWidth "
2309*9880d681SAndroid Build Coastguard Worker    "\t[$addr+$offset], {{$src1, $src2, $src3, $src4}};", []>;
2310*9880d681SAndroid Build Coastguard Worker  def _v4_asi : NVPTXInst<
2311*9880d681SAndroid Build Coastguard Worker    (outs),
2312*9880d681SAndroid Build Coastguard Worker    (ins regclass:$src1, regclass:$src2, regclass:$src3, regclass:$src4,
2313*9880d681SAndroid Build Coastguard Worker         LdStCode:$isVol, LdStCode:$addsp, LdStCode:$Vec, LdStCode:$Sign,
2314*9880d681SAndroid Build Coastguard Worker         i32imm:$fromWidth, imem:$addr, i32imm:$offset),
2315*9880d681SAndroid Build Coastguard Worker    "st${isVol:volatile}${addsp:addsp}${Vec:vec}.${Sign:sign}"
2316*9880d681SAndroid Build Coastguard Worker    "$fromWidth \t[$addr+$offset], {{$src1, $src2, $src3, $src4}};", []>;
2317*9880d681SAndroid Build Coastguard Worker}
2318*9880d681SAndroid Build Coastguard Worker
2319*9880d681SAndroid Build Coastguard Workerlet mayStore=1, hasSideEffects=0 in {
2320*9880d681SAndroid Build Coastguard Worker  defm STV_i8  : ST_VEC<Int16Regs>;
2321*9880d681SAndroid Build Coastguard Worker  defm STV_i16 : ST_VEC<Int16Regs>;
2322*9880d681SAndroid Build Coastguard Worker  defm STV_i32 : ST_VEC<Int32Regs>;
2323*9880d681SAndroid Build Coastguard Worker  defm STV_i64 : ST_VEC<Int64Regs>;
2324*9880d681SAndroid Build Coastguard Worker  defm STV_f32 : ST_VEC<Float32Regs>;
2325*9880d681SAndroid Build Coastguard Worker  defm STV_f64 : ST_VEC<Float64Regs>;
2326*9880d681SAndroid Build Coastguard Worker}
2327*9880d681SAndroid Build Coastguard Worker
2328*9880d681SAndroid Build Coastguard Worker
2329*9880d681SAndroid Build Coastguard Worker//---- Conversion ----
2330*9880d681SAndroid Build Coastguard Worker
2331*9880d681SAndroid Build Coastguard Workerclass F_BITCONVERT<string SzStr, NVPTXRegClass regclassIn,
2332*9880d681SAndroid Build Coastguard Worker  NVPTXRegClass regclassOut> :
2333*9880d681SAndroid Build Coastguard Worker           NVPTXInst<(outs regclassOut:$d), (ins regclassIn:$a),
2334*9880d681SAndroid Build Coastguard Worker           !strconcat("mov.b", !strconcat(SzStr, " \t $d, $a;")),
2335*9880d681SAndroid Build Coastguard Worker     [(set regclassOut:$d, (bitconvert regclassIn:$a))]>;
2336*9880d681SAndroid Build Coastguard Worker
2337*9880d681SAndroid Build Coastguard Workerdef BITCONVERT_32_I2F : F_BITCONVERT<"32", Int32Regs, Float32Regs>;
2338*9880d681SAndroid Build Coastguard Workerdef BITCONVERT_32_F2I : F_BITCONVERT<"32", Float32Regs, Int32Regs>;
2339*9880d681SAndroid Build Coastguard Workerdef BITCONVERT_64_I2F : F_BITCONVERT<"64", Int64Regs, Float64Regs>;
2340*9880d681SAndroid Build Coastguard Workerdef BITCONVERT_64_F2I : F_BITCONVERT<"64", Float64Regs, Int64Regs>;
2341*9880d681SAndroid Build Coastguard Worker
2342*9880d681SAndroid Build Coastguard Worker// NOTE: pred->fp are currently sub-optimal due to an issue in TableGen where
2343*9880d681SAndroid Build Coastguard Worker// we cannot specify floating-point literals in isel patterns.  Therefore, we
2344*9880d681SAndroid Build Coastguard Worker// use an integer selp to select either 1 or 0 and then cvt to floating-point.
2345*9880d681SAndroid Build Coastguard Worker
2346*9880d681SAndroid Build Coastguard Worker// sint -> f32
2347*9880d681SAndroid Build Coastguard Workerdef : Pat<(f32 (sint_to_fp Int1Regs:$a)),
2348*9880d681SAndroid Build Coastguard Worker          (CVT_f32_s32 (SELP_u32ii 1, 0, Int1Regs:$a), CvtRN)>;
2349*9880d681SAndroid Build Coastguard Workerdef : Pat<(f32 (sint_to_fp Int16Regs:$a)),
2350*9880d681SAndroid Build Coastguard Worker          (CVT_f32_s16 Int16Regs:$a, CvtRN)>;
2351*9880d681SAndroid Build Coastguard Workerdef : Pat<(f32 (sint_to_fp Int32Regs:$a)),
2352*9880d681SAndroid Build Coastguard Worker          (CVT_f32_s32 Int32Regs:$a, CvtRN)>;
2353*9880d681SAndroid Build Coastguard Workerdef : Pat<(f32 (sint_to_fp Int64Regs:$a)),
2354*9880d681SAndroid Build Coastguard Worker          (CVT_f32_s64 Int64Regs:$a, CvtRN)>;
2355*9880d681SAndroid Build Coastguard Worker
2356*9880d681SAndroid Build Coastguard Worker// uint -> f32
2357*9880d681SAndroid Build Coastguard Workerdef : Pat<(f32 (uint_to_fp Int1Regs:$a)),
2358*9880d681SAndroid Build Coastguard Worker          (CVT_f32_u32 (SELP_u32ii 1, 0, Int1Regs:$a), CvtRN)>;
2359*9880d681SAndroid Build Coastguard Workerdef : Pat<(f32 (uint_to_fp Int16Regs:$a)),
2360*9880d681SAndroid Build Coastguard Worker          (CVT_f32_u16 Int16Regs:$a, CvtRN)>;
2361*9880d681SAndroid Build Coastguard Workerdef : Pat<(f32 (uint_to_fp Int32Regs:$a)),
2362*9880d681SAndroid Build Coastguard Worker          (CVT_f32_u32 Int32Regs:$a, CvtRN)>;
2363*9880d681SAndroid Build Coastguard Workerdef : Pat<(f32 (uint_to_fp Int64Regs:$a)),
2364*9880d681SAndroid Build Coastguard Worker          (CVT_f32_u64 Int64Regs:$a, CvtRN)>;
2365*9880d681SAndroid Build Coastguard Worker
2366*9880d681SAndroid Build Coastguard Worker// sint -> f64
2367*9880d681SAndroid Build Coastguard Workerdef : Pat<(f64 (sint_to_fp Int1Regs:$a)),
2368*9880d681SAndroid Build Coastguard Worker          (CVT_f64_s32 (SELP_u32ii 1, 0, Int1Regs:$a), CvtRN)>;
2369*9880d681SAndroid Build Coastguard Workerdef : Pat<(f64 (sint_to_fp Int16Regs:$a)),
2370*9880d681SAndroid Build Coastguard Worker          (CVT_f64_s16 Int16Regs:$a, CvtRN)>;
2371*9880d681SAndroid Build Coastguard Workerdef : Pat<(f64 (sint_to_fp Int32Regs:$a)),
2372*9880d681SAndroid Build Coastguard Worker          (CVT_f64_s32 Int32Regs:$a, CvtRN)>;
2373*9880d681SAndroid Build Coastguard Workerdef : Pat<(f64 (sint_to_fp Int64Regs:$a)),
2374*9880d681SAndroid Build Coastguard Worker          (CVT_f64_s64 Int64Regs:$a, CvtRN)>;
2375*9880d681SAndroid Build Coastguard Worker
2376*9880d681SAndroid Build Coastguard Worker// uint -> f64
2377*9880d681SAndroid Build Coastguard Workerdef : Pat<(f64 (uint_to_fp Int1Regs:$a)),
2378*9880d681SAndroid Build Coastguard Worker          (CVT_f64_u32 (SELP_u32ii 1, 0, Int1Regs:$a), CvtRN)>;
2379*9880d681SAndroid Build Coastguard Workerdef : Pat<(f64 (uint_to_fp Int16Regs:$a)),
2380*9880d681SAndroid Build Coastguard Worker          (CVT_f64_u16 Int16Regs:$a, CvtRN)>;
2381*9880d681SAndroid Build Coastguard Workerdef : Pat<(f64 (uint_to_fp Int32Regs:$a)),
2382*9880d681SAndroid Build Coastguard Worker          (CVT_f64_u32 Int32Regs:$a, CvtRN)>;
2383*9880d681SAndroid Build Coastguard Workerdef : Pat<(f64 (uint_to_fp Int64Regs:$a)),
2384*9880d681SAndroid Build Coastguard Worker          (CVT_f64_u64 Int64Regs:$a, CvtRN)>;
2385*9880d681SAndroid Build Coastguard Worker
2386*9880d681SAndroid Build Coastguard Worker
2387*9880d681SAndroid Build Coastguard Worker// f32 -> sint
2388*9880d681SAndroid Build Coastguard Workerdef : Pat<(i1 (fp_to_sint Float32Regs:$a)),
2389*9880d681SAndroid Build Coastguard Worker          (SETP_b32ri (BITCONVERT_32_F2I Float32Regs:$a), 0, CmpEQ)>;
2390*9880d681SAndroid Build Coastguard Workerdef : Pat<(i16 (fp_to_sint Float32Regs:$a)),
2391*9880d681SAndroid Build Coastguard Worker          (CVT_s16_f32 Float32Regs:$a, CvtRZI_FTZ)>, Requires<[doF32FTZ]>;
2392*9880d681SAndroid Build Coastguard Workerdef : Pat<(i16 (fp_to_sint Float32Regs:$a)),
2393*9880d681SAndroid Build Coastguard Worker          (CVT_s16_f32 Float32Regs:$a, CvtRZI)>;
2394*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (fp_to_sint Float32Regs:$a)),
2395*9880d681SAndroid Build Coastguard Worker          (CVT_s32_f32 Float32Regs:$a, CvtRZI_FTZ)>, Requires<[doF32FTZ]>;
2396*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (fp_to_sint Float32Regs:$a)),
2397*9880d681SAndroid Build Coastguard Worker          (CVT_s32_f32 Float32Regs:$a, CvtRZI)>;
2398*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (fp_to_sint Float32Regs:$a)),
2399*9880d681SAndroid Build Coastguard Worker          (CVT_s64_f32 Float32Regs:$a, CvtRZI_FTZ)>, Requires<[doF32FTZ]>;
2400*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (fp_to_sint Float32Regs:$a)),
2401*9880d681SAndroid Build Coastguard Worker          (CVT_s64_f32 Float32Regs:$a, CvtRZI)>;
2402*9880d681SAndroid Build Coastguard Worker
2403*9880d681SAndroid Build Coastguard Worker// f32 -> uint
2404*9880d681SAndroid Build Coastguard Workerdef : Pat<(i1 (fp_to_uint Float32Regs:$a)),
2405*9880d681SAndroid Build Coastguard Worker          (SETP_b32ri (BITCONVERT_32_F2I Float32Regs:$a), 0, CmpEQ)>;
2406*9880d681SAndroid Build Coastguard Workerdef : Pat<(i16 (fp_to_uint Float32Regs:$a)),
2407*9880d681SAndroid Build Coastguard Worker          (CVT_u16_f32 Float32Regs:$a, CvtRZI_FTZ)>, Requires<[doF32FTZ]>;
2408*9880d681SAndroid Build Coastguard Workerdef : Pat<(i16 (fp_to_uint Float32Regs:$a)),
2409*9880d681SAndroid Build Coastguard Worker          (CVT_u16_f32 Float32Regs:$a, CvtRZI)>;
2410*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (fp_to_uint Float32Regs:$a)),
2411*9880d681SAndroid Build Coastguard Worker          (CVT_u32_f32 Float32Regs:$a, CvtRZI_FTZ)>, Requires<[doF32FTZ]>;
2412*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (fp_to_uint Float32Regs:$a)),
2413*9880d681SAndroid Build Coastguard Worker          (CVT_u32_f32 Float32Regs:$a, CvtRZI)>;
2414*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (fp_to_uint Float32Regs:$a)),
2415*9880d681SAndroid Build Coastguard Worker          (CVT_u64_f32 Float32Regs:$a, CvtRZI_FTZ)>, Requires<[doF32FTZ]>;
2416*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (fp_to_uint Float32Regs:$a)),
2417*9880d681SAndroid Build Coastguard Worker          (CVT_u64_f32 Float32Regs:$a, CvtRZI)>;
2418*9880d681SAndroid Build Coastguard Worker
2419*9880d681SAndroid Build Coastguard Worker// f64 -> sint
2420*9880d681SAndroid Build Coastguard Workerdef : Pat<(i1 (fp_to_sint Float64Regs:$a)),
2421*9880d681SAndroid Build Coastguard Worker          (SETP_b64ri (BITCONVERT_64_F2I Float64Regs:$a), 0, CmpEQ)>;
2422*9880d681SAndroid Build Coastguard Workerdef : Pat<(i16 (fp_to_sint Float64Regs:$a)),
2423*9880d681SAndroid Build Coastguard Worker          (CVT_s16_f64 Float64Regs:$a, CvtRZI)>;
2424*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (fp_to_sint Float64Regs:$a)),
2425*9880d681SAndroid Build Coastguard Worker          (CVT_s32_f64 Float64Regs:$a, CvtRZI)>;
2426*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (fp_to_sint Float64Regs:$a)),
2427*9880d681SAndroid Build Coastguard Worker          (CVT_s64_f64 Float64Regs:$a, CvtRZI)>;
2428*9880d681SAndroid Build Coastguard Worker
2429*9880d681SAndroid Build Coastguard Worker// f64 -> uint
2430*9880d681SAndroid Build Coastguard Workerdef : Pat<(i1 (fp_to_uint Float64Regs:$a)),
2431*9880d681SAndroid Build Coastguard Worker          (SETP_b64ri (BITCONVERT_64_F2I Float64Regs:$a), 0, CmpEQ)>;
2432*9880d681SAndroid Build Coastguard Workerdef : Pat<(i16 (fp_to_uint Float64Regs:$a)),
2433*9880d681SAndroid Build Coastguard Worker          (CVT_u16_f64 Float64Regs:$a, CvtRZI)>;
2434*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (fp_to_uint Float64Regs:$a)),
2435*9880d681SAndroid Build Coastguard Worker          (CVT_u32_f64 Float64Regs:$a, CvtRZI)>;
2436*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (fp_to_uint Float64Regs:$a)),
2437*9880d681SAndroid Build Coastguard Worker          (CVT_u64_f64 Float64Regs:$a, CvtRZI)>;
2438*9880d681SAndroid Build Coastguard Worker
2439*9880d681SAndroid Build Coastguard Worker// sext i1
2440*9880d681SAndroid Build Coastguard Workerdef : Pat<(i16 (sext Int1Regs:$a)),
2441*9880d681SAndroid Build Coastguard Worker          (SELP_s16ii -1, 0, Int1Regs:$a)>;
2442*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (sext Int1Regs:$a)),
2443*9880d681SAndroid Build Coastguard Worker          (SELP_s32ii -1, 0, Int1Regs:$a)>;
2444*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (sext Int1Regs:$a)),
2445*9880d681SAndroid Build Coastguard Worker          (SELP_s64ii -1, 0, Int1Regs:$a)>;
2446*9880d681SAndroid Build Coastguard Worker
2447*9880d681SAndroid Build Coastguard Worker// zext i1
2448*9880d681SAndroid Build Coastguard Workerdef : Pat<(i16 (zext Int1Regs:$a)),
2449*9880d681SAndroid Build Coastguard Worker          (SELP_u16ii 1, 0, Int1Regs:$a)>;
2450*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (zext Int1Regs:$a)),
2451*9880d681SAndroid Build Coastguard Worker          (SELP_u32ii 1, 0, Int1Regs:$a)>;
2452*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (zext Int1Regs:$a)),
2453*9880d681SAndroid Build Coastguard Worker          (SELP_u64ii 1, 0, Int1Regs:$a)>;
2454*9880d681SAndroid Build Coastguard Worker
2455*9880d681SAndroid Build Coastguard Worker// anyext i1
2456*9880d681SAndroid Build Coastguard Workerdef : Pat<(i16 (anyext Int1Regs:$a)),
2457*9880d681SAndroid Build Coastguard Worker          (SELP_u16ii -1, 0, Int1Regs:$a)>;
2458*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (anyext Int1Regs:$a)),
2459*9880d681SAndroid Build Coastguard Worker          (SELP_u32ii -1, 0, Int1Regs:$a)>;
2460*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (anyext Int1Regs:$a)),
2461*9880d681SAndroid Build Coastguard Worker          (SELP_u64ii -1, 0, Int1Regs:$a)>;
2462*9880d681SAndroid Build Coastguard Worker
2463*9880d681SAndroid Build Coastguard Worker// sext i16
2464*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (sext Int16Regs:$a)),
2465*9880d681SAndroid Build Coastguard Worker          (CVT_s32_s16 Int16Regs:$a, CvtNONE)>;
2466*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (sext Int16Regs:$a)),
2467*9880d681SAndroid Build Coastguard Worker          (CVT_s64_s16 Int16Regs:$a, CvtNONE)>;
2468*9880d681SAndroid Build Coastguard Worker
2469*9880d681SAndroid Build Coastguard Worker// zext i16
2470*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (zext Int16Regs:$a)),
2471*9880d681SAndroid Build Coastguard Worker          (CVT_u32_u16 Int16Regs:$a, CvtNONE)>;
2472*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (zext Int16Regs:$a)),
2473*9880d681SAndroid Build Coastguard Worker          (CVT_u64_u16 Int16Regs:$a, CvtNONE)>;
2474*9880d681SAndroid Build Coastguard Worker
2475*9880d681SAndroid Build Coastguard Worker// anyext i16
2476*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (anyext Int16Regs:$a)),
2477*9880d681SAndroid Build Coastguard Worker          (CVT_u32_u16 Int16Regs:$a, CvtNONE)>;
2478*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (anyext Int16Regs:$a)),
2479*9880d681SAndroid Build Coastguard Worker          (CVT_u64_u16 Int16Regs:$a, CvtNONE)>;
2480*9880d681SAndroid Build Coastguard Worker
2481*9880d681SAndroid Build Coastguard Worker// sext i32
2482*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (sext Int32Regs:$a)),
2483*9880d681SAndroid Build Coastguard Worker          (CVT_s64_s32 Int32Regs:$a, CvtNONE)>;
2484*9880d681SAndroid Build Coastguard Worker
2485*9880d681SAndroid Build Coastguard Worker// zext i32
2486*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (zext Int32Regs:$a)),
2487*9880d681SAndroid Build Coastguard Worker          (CVT_u64_u32 Int32Regs:$a, CvtNONE)>;
2488*9880d681SAndroid Build Coastguard Worker
2489*9880d681SAndroid Build Coastguard Worker// anyext i32
2490*9880d681SAndroid Build Coastguard Workerdef : Pat<(i64 (anyext Int32Regs:$a)),
2491*9880d681SAndroid Build Coastguard Worker          (CVT_u64_u32 Int32Regs:$a, CvtNONE)>;
2492*9880d681SAndroid Build Coastguard Worker
2493*9880d681SAndroid Build Coastguard Worker
2494*9880d681SAndroid Build Coastguard Worker// truncate i64
2495*9880d681SAndroid Build Coastguard Workerdef : Pat<(i32 (trunc Int64Regs:$a)),
2496*9880d681SAndroid Build Coastguard Worker          (CVT_u32_u64 Int64Regs:$a, CvtNONE)>;
2497*9880d681SAndroid Build Coastguard Workerdef : Pat<(i16 (trunc Int64Regs:$a)),
2498*9880d681SAndroid Build Coastguard Worker          (CVT_u16_u64 Int64Regs:$a, CvtNONE)>;
2499*9880d681SAndroid Build Coastguard Workerdef : Pat<(i1 (trunc Int64Regs:$a)),
2500*9880d681SAndroid Build Coastguard Worker          (SETP_b64ri (ANDb64ri Int64Regs:$a, 1), 1, CmpEQ)>;
2501*9880d681SAndroid Build Coastguard Worker
2502*9880d681SAndroid Build Coastguard Worker// truncate i32
2503*9880d681SAndroid Build Coastguard Workerdef : Pat<(i16 (trunc Int32Regs:$a)),
2504*9880d681SAndroid Build Coastguard Worker          (CVT_u16_u32 Int32Regs:$a, CvtNONE)>;
2505*9880d681SAndroid Build Coastguard Workerdef : Pat<(i1 (trunc Int32Regs:$a)),
2506*9880d681SAndroid Build Coastguard Worker          (SETP_b32ri (ANDb32ri Int32Regs:$a, 1), 1, CmpEQ)>;
2507*9880d681SAndroid Build Coastguard Worker
2508*9880d681SAndroid Build Coastguard Worker// truncate i16
2509*9880d681SAndroid Build Coastguard Workerdef : Pat<(i1 (trunc Int16Regs:$a)),
2510*9880d681SAndroid Build Coastguard Worker          (SETP_b16ri (ANDb16ri Int16Regs:$a, 1), 1, CmpEQ)>;
2511*9880d681SAndroid Build Coastguard Worker
2512*9880d681SAndroid Build Coastguard Worker// sext_inreg
2513*9880d681SAndroid Build Coastguard Workerdef : Pat<(sext_inreg Int16Regs:$a, i8), (CVT_INREG_s16_s8 Int16Regs:$a)>;
2514*9880d681SAndroid Build Coastguard Workerdef : Pat<(sext_inreg Int32Regs:$a, i8), (CVT_INREG_s32_s8 Int32Regs:$a)>;
2515*9880d681SAndroid Build Coastguard Workerdef : Pat<(sext_inreg Int32Regs:$a, i16), (CVT_INREG_s32_s16 Int32Regs:$a)>;
2516*9880d681SAndroid Build Coastguard Workerdef : Pat<(sext_inreg Int64Regs:$a, i8), (CVT_INREG_s64_s8 Int64Regs:$a)>;
2517*9880d681SAndroid Build Coastguard Workerdef : Pat<(sext_inreg Int64Regs:$a, i16), (CVT_INREG_s64_s16 Int64Regs:$a)>;
2518*9880d681SAndroid Build Coastguard Workerdef : Pat<(sext_inreg Int64Regs:$a, i32), (CVT_INREG_s64_s32 Int64Regs:$a)>;
2519*9880d681SAndroid Build Coastguard Worker
2520*9880d681SAndroid Build Coastguard Worker
2521*9880d681SAndroid Build Coastguard Worker// Select instructions with 32-bit predicates
2522*9880d681SAndroid Build Coastguard Workerdef : Pat<(select Int32Regs:$pred, Int16Regs:$a, Int16Regs:$b),
2523*9880d681SAndroid Build Coastguard Worker          (SELP_b16rr Int16Regs:$a, Int16Regs:$b,
2524*9880d681SAndroid Build Coastguard Worker          (SETP_b32ri (ANDb32ri Int32Regs:$pred, 1), 1, CmpEQ))>;
2525*9880d681SAndroid Build Coastguard Workerdef : Pat<(select Int32Regs:$pred, Int32Regs:$a, Int32Regs:$b),
2526*9880d681SAndroid Build Coastguard Worker          (SELP_b32rr Int32Regs:$a, Int32Regs:$b,
2527*9880d681SAndroid Build Coastguard Worker          (SETP_b32ri (ANDb32ri Int32Regs:$pred, 1), 1, CmpEQ))>;
2528*9880d681SAndroid Build Coastguard Workerdef : Pat<(select Int32Regs:$pred, Int64Regs:$a, Int64Regs:$b),
2529*9880d681SAndroid Build Coastguard Worker          (SELP_b64rr Int64Regs:$a, Int64Regs:$b,
2530*9880d681SAndroid Build Coastguard Worker          (SETP_b32ri (ANDb32ri Int32Regs:$pred, 1), 1, CmpEQ))>;
2531*9880d681SAndroid Build Coastguard Workerdef : Pat<(select Int32Regs:$pred, Float32Regs:$a, Float32Regs:$b),
2532*9880d681SAndroid Build Coastguard Worker          (SELP_f32rr Float32Regs:$a, Float32Regs:$b,
2533*9880d681SAndroid Build Coastguard Worker          (SETP_b32ri (ANDb32ri Int32Regs:$pred, 1), 1, CmpEQ))>;
2534*9880d681SAndroid Build Coastguard Workerdef : Pat<(select Int32Regs:$pred, Float64Regs:$a, Float64Regs:$b),
2535*9880d681SAndroid Build Coastguard Worker          (SELP_f64rr Float64Regs:$a, Float64Regs:$b,
2536*9880d681SAndroid Build Coastguard Worker          (SETP_b32ri (ANDb32ri Int32Regs:$pred, 1), 1, CmpEQ))>;
2537*9880d681SAndroid Build Coastguard Worker
2538*9880d681SAndroid Build Coastguard Worker
2539*9880d681SAndroid Build Coastguard Workerlet hasSideEffects = 0 in {
2540*9880d681SAndroid Build Coastguard Worker  // pack a set of smaller int registers to a larger int register
2541*9880d681SAndroid Build Coastguard Worker  def V4I16toI64 : NVPTXInst<(outs Int64Regs:$d),
2542*9880d681SAndroid Build Coastguard Worker                             (ins Int16Regs:$s1, Int16Regs:$s2,
2543*9880d681SAndroid Build Coastguard Worker                                  Int16Regs:$s3, Int16Regs:$s4),
2544*9880d681SAndroid Build Coastguard Worker                             "mov.b64\t$d, {{$s1, $s2, $s3, $s4}};", []>;
2545*9880d681SAndroid Build Coastguard Worker  def V2I16toI32 : NVPTXInst<(outs Int32Regs:$d),
2546*9880d681SAndroid Build Coastguard Worker                             (ins Int16Regs:$s1, Int16Regs:$s2),
2547*9880d681SAndroid Build Coastguard Worker                             "mov.b32\t$d, {{$s1, $s2}};", []>;
2548*9880d681SAndroid Build Coastguard Worker  def V2I32toI64 : NVPTXInst<(outs Int64Regs:$d),
2549*9880d681SAndroid Build Coastguard Worker                             (ins Int32Regs:$s1, Int32Regs:$s2),
2550*9880d681SAndroid Build Coastguard Worker                             "mov.b64\t$d, {{$s1, $s2}};", []>;
2551*9880d681SAndroid Build Coastguard Worker  def V2F32toF64 : NVPTXInst<(outs Float64Regs:$d),
2552*9880d681SAndroid Build Coastguard Worker                             (ins Float32Regs:$s1, Float32Regs:$s2),
2553*9880d681SAndroid Build Coastguard Worker                             "mov.b64\t$d, {{$s1, $s2}};", []>;
2554*9880d681SAndroid Build Coastguard Worker
2555*9880d681SAndroid Build Coastguard Worker  // unpack a larger int register to a set of smaller int registers
2556*9880d681SAndroid Build Coastguard Worker  def I64toV4I16 : NVPTXInst<(outs Int16Regs:$d1, Int16Regs:$d2,
2557*9880d681SAndroid Build Coastguard Worker                                   Int16Regs:$d3, Int16Regs:$d4),
2558*9880d681SAndroid Build Coastguard Worker                             (ins Int64Regs:$s),
2559*9880d681SAndroid Build Coastguard Worker                             "mov.b64\t{{$d1, $d2, $d3, $d4}}, $s;", []>;
2560*9880d681SAndroid Build Coastguard Worker  def I32toV2I16 : NVPTXInst<(outs Int16Regs:$d1, Int16Regs:$d2),
2561*9880d681SAndroid Build Coastguard Worker                             (ins Int32Regs:$s),
2562*9880d681SAndroid Build Coastguard Worker                             "mov.b32\t{{$d1, $d2}}, $s;", []>;
2563*9880d681SAndroid Build Coastguard Worker  def I64toV2I32 : NVPTXInst<(outs Int32Regs:$d1, Int32Regs:$d2),
2564*9880d681SAndroid Build Coastguard Worker                             (ins Int64Regs:$s),
2565*9880d681SAndroid Build Coastguard Worker                             "mov.b64\t{{$d1, $d2}}, $s;", []>;
2566*9880d681SAndroid Build Coastguard Worker  def F64toV2F32 : NVPTXInst<(outs Float32Regs:$d1, Float32Regs:$d2),
2567*9880d681SAndroid Build Coastguard Worker                             (ins Float64Regs:$s),
2568*9880d681SAndroid Build Coastguard Worker                             "mov.b64\t{{$d1, $d2}}, $s;", []>;
2569*9880d681SAndroid Build Coastguard Worker}
2570*9880d681SAndroid Build Coastguard Worker
2571*9880d681SAndroid Build Coastguard Worker// Count leading zeros
2572*9880d681SAndroid Build Coastguard Workerlet hasSideEffects = 0 in {
2573*9880d681SAndroid Build Coastguard Worker  def CLZr32 : NVPTXInst<(outs Int32Regs:$d), (ins Int32Regs:$a),
2574*9880d681SAndroid Build Coastguard Worker                         "clz.b32\t$d, $a;", []>;
2575*9880d681SAndroid Build Coastguard Worker  def CLZr64 : NVPTXInst<(outs Int32Regs:$d), (ins Int64Regs:$a),
2576*9880d681SAndroid Build Coastguard Worker                         "clz.b64\t$d, $a;", []>;
2577*9880d681SAndroid Build Coastguard Worker}
2578*9880d681SAndroid Build Coastguard Worker
2579*9880d681SAndroid Build Coastguard Worker// 32-bit has a direct PTX instruction
2580*9880d681SAndroid Build Coastguard Workerdef : Pat<(ctlz Int32Regs:$a), (CLZr32 Int32Regs:$a)>;
2581*9880d681SAndroid Build Coastguard Worker
2582*9880d681SAndroid Build Coastguard Worker// For 64-bit, the result in PTX is actually 32-bit so we zero-extend
2583*9880d681SAndroid Build Coastguard Worker// to 64-bit to match the LLVM semantics
2584*9880d681SAndroid Build Coastguard Workerdef : Pat<(ctlz Int64Regs:$a), (CVT_u64_u32 (CLZr64 Int64Regs:$a), CvtNONE)>;
2585*9880d681SAndroid Build Coastguard Worker
2586*9880d681SAndroid Build Coastguard Worker// For 16-bit, we zero-extend to 32-bit, then trunc the result back
2587*9880d681SAndroid Build Coastguard Worker// to 16-bits (ctlz of a 16-bit value is guaranteed to require less
2588*9880d681SAndroid Build Coastguard Worker// than 16 bits to store). We also need to subtract 16 because the
2589*9880d681SAndroid Build Coastguard Worker// high-order 16 zeros were counted.
2590*9880d681SAndroid Build Coastguard Workerdef : Pat<(ctlz Int16Regs:$a),
2591*9880d681SAndroid Build Coastguard Worker          (SUBi16ri (CVT_u16_u32 (CLZr32
2592*9880d681SAndroid Build Coastguard Worker            (CVT_u32_u16 Int16Regs:$a, CvtNONE)),
2593*9880d681SAndroid Build Coastguard Worker           CvtNONE), 16)>;
2594*9880d681SAndroid Build Coastguard Worker
2595*9880d681SAndroid Build Coastguard Worker// Population count
2596*9880d681SAndroid Build Coastguard Workerlet hasSideEffects = 0 in {
2597*9880d681SAndroid Build Coastguard Worker  def POPCr32 : NVPTXInst<(outs Int32Regs:$d), (ins Int32Regs:$a),
2598*9880d681SAndroid Build Coastguard Worker                          "popc.b32\t$d, $a;", []>;
2599*9880d681SAndroid Build Coastguard Worker  def POPCr64 : NVPTXInst<(outs Int32Regs:$d), (ins Int64Regs:$a),
2600*9880d681SAndroid Build Coastguard Worker                          "popc.b64\t$d, $a;", []>;
2601*9880d681SAndroid Build Coastguard Worker}
2602*9880d681SAndroid Build Coastguard Worker
2603*9880d681SAndroid Build Coastguard Worker// 32-bit has a direct PTX instruction
2604*9880d681SAndroid Build Coastguard Workerdef : Pat<(ctpop Int32Regs:$a), (POPCr32 Int32Regs:$a)>;
2605*9880d681SAndroid Build Coastguard Worker
2606*9880d681SAndroid Build Coastguard Worker// For 64-bit, the result in PTX is actually 32-bit so we zero-extend
2607*9880d681SAndroid Build Coastguard Worker// to 64-bit to match the LLVM semantics
2608*9880d681SAndroid Build Coastguard Workerdef : Pat<(ctpop Int64Regs:$a), (CVT_u64_u32 (POPCr64 Int64Regs:$a), CvtNONE)>;
2609*9880d681SAndroid Build Coastguard Worker
2610*9880d681SAndroid Build Coastguard Worker// For 16-bit, we zero-extend to 32-bit, then trunc the result back
2611*9880d681SAndroid Build Coastguard Worker// to 16-bits (ctpop of a 16-bit value is guaranteed to require less
2612*9880d681SAndroid Build Coastguard Worker// than 16 bits to store)
2613*9880d681SAndroid Build Coastguard Workerdef : Pat<(ctpop Int16Regs:$a),
2614*9880d681SAndroid Build Coastguard Worker          (CVT_u16_u32 (POPCr32 (CVT_u32_u16 Int16Regs:$a, CvtNONE)), CvtNONE)>;
2615*9880d681SAndroid Build Coastguard Worker
2616*9880d681SAndroid Build Coastguard Worker// fround f64 -> f32
2617*9880d681SAndroid Build Coastguard Workerdef : Pat<(f32 (fround Float64Regs:$a)),
2618*9880d681SAndroid Build Coastguard Worker          (CVT_f32_f64 Float64Regs:$a, CvtRN_FTZ)>, Requires<[doF32FTZ]>;
2619*9880d681SAndroid Build Coastguard Workerdef : Pat<(f32 (fround Float64Regs:$a)),
2620*9880d681SAndroid Build Coastguard Worker          (CVT_f32_f64 Float64Regs:$a, CvtRN)>;
2621*9880d681SAndroid Build Coastguard Worker
2622*9880d681SAndroid Build Coastguard Worker// fextend f32 -> f64
2623*9880d681SAndroid Build Coastguard Workerdef : Pat<(f64 (fextend Float32Regs:$a)),
2624*9880d681SAndroid Build Coastguard Worker          (CVT_f64_f32 Float32Regs:$a, CvtNONE_FTZ)>, Requires<[doF32FTZ]>;
2625*9880d681SAndroid Build Coastguard Workerdef : Pat<(f64 (fextend Float32Regs:$a)),
2626*9880d681SAndroid Build Coastguard Worker          (CVT_f64_f32 Float32Regs:$a, CvtNONE)>;
2627*9880d681SAndroid Build Coastguard Worker
2628*9880d681SAndroid Build Coastguard Workerdef retflag : SDNode<"NVPTXISD::RET_FLAG", SDTNone,
2629*9880d681SAndroid Build Coastguard Worker                     [SDNPHasChain, SDNPOptInGlue]>;
2630*9880d681SAndroid Build Coastguard Worker
2631*9880d681SAndroid Build Coastguard Worker//-----------------------------------
2632*9880d681SAndroid Build Coastguard Worker// Control-flow
2633*9880d681SAndroid Build Coastguard Worker//-----------------------------------
2634*9880d681SAndroid Build Coastguard Worker
2635*9880d681SAndroid Build Coastguard Workerlet isTerminator=1 in {
2636*9880d681SAndroid Build Coastguard Worker   let isReturn=1, isBarrier=1 in
2637*9880d681SAndroid Build Coastguard Worker      def Return : NVPTXInst<(outs), (ins), "ret;", [(retflag)]>;
2638*9880d681SAndroid Build Coastguard Worker
2639*9880d681SAndroid Build Coastguard Worker   let isBranch=1 in
2640*9880d681SAndroid Build Coastguard Worker      def CBranch : NVPTXInst<(outs), (ins Int1Regs:$a, brtarget:$target),
2641*9880d681SAndroid Build Coastguard Worker                              "@$a bra \t$target;",
2642*9880d681SAndroid Build Coastguard Worker                              [(brcond Int1Regs:$a, bb:$target)]>;
2643*9880d681SAndroid Build Coastguard Worker   let isBranch=1 in
2644*9880d681SAndroid Build Coastguard Worker      def CBranchOther : NVPTXInst<(outs), (ins Int1Regs:$a, brtarget:$target),
2645*9880d681SAndroid Build Coastguard Worker                                   "@!$a bra \t$target;", []>;
2646*9880d681SAndroid Build Coastguard Worker
2647*9880d681SAndroid Build Coastguard Worker   let isBranch=1, isBarrier=1 in
2648*9880d681SAndroid Build Coastguard Worker      def GOTO : NVPTXInst<(outs), (ins brtarget:$target),
2649*9880d681SAndroid Build Coastguard Worker                           "bra.uni \t$target;", [(br bb:$target)]>;
2650*9880d681SAndroid Build Coastguard Worker}
2651*9880d681SAndroid Build Coastguard Worker
2652*9880d681SAndroid Build Coastguard Workerdef : Pat<(brcond Int32Regs:$a, bb:$target),
2653*9880d681SAndroid Build Coastguard Worker          (CBranch (SETP_u32ri Int32Regs:$a, 0, CmpNE), bb:$target)>;
2654*9880d681SAndroid Build Coastguard Worker
2655*9880d681SAndroid Build Coastguard Worker// SelectionDAGBuilder::visitSWitchCase() will invert the condition of a
2656*9880d681SAndroid Build Coastguard Worker// conditional branch if the target block is the next block so that the code
2657*9880d681SAndroid Build Coastguard Worker// can fall through to the target block.  The invertion is done by 'xor
2658*9880d681SAndroid Build Coastguard Worker// condition, 1', which will be translated to (setne condition, -1).  Since ptx
2659*9880d681SAndroid Build Coastguard Worker// supports '@!pred bra target', we should use it.
2660*9880d681SAndroid Build Coastguard Workerdef : Pat<(brcond (i1 (setne Int1Regs:$a, -1)), bb:$target),
2661*9880d681SAndroid Build Coastguard Worker          (CBranchOther Int1Regs:$a, bb:$target)>;
2662*9880d681SAndroid Build Coastguard Worker
2663*9880d681SAndroid Build Coastguard Worker// Call
2664*9880d681SAndroid Build Coastguard Workerdef SDT_NVPTXCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
2665*9880d681SAndroid Build Coastguard Workerdef SDT_NVPTXCallSeqEnd   : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
2666*9880d681SAndroid Build Coastguard Worker
2667*9880d681SAndroid Build Coastguard Workerdef callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_NVPTXCallSeqStart,
2668*9880d681SAndroid Build Coastguard Worker                           [SDNPHasChain, SDNPOutGlue, SDNPSideEffect]>;
2669*9880d681SAndroid Build Coastguard Workerdef callseq_end   : SDNode<"ISD::CALLSEQ_END", SDT_NVPTXCallSeqEnd,
2670*9880d681SAndroid Build Coastguard Worker                           [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
2671*9880d681SAndroid Build Coastguard Worker                            SDNPSideEffect]>;
2672*9880d681SAndroid Build Coastguard Worker
2673*9880d681SAndroid Build Coastguard Workerdef SDT_NVPTXCall : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
2674*9880d681SAndroid Build Coastguard Workerdef call          : SDNode<"NVPTXISD::CALL", SDT_NVPTXCall,
2675*9880d681SAndroid Build Coastguard Worker                           [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
2676*9880d681SAndroid Build Coastguard Workerdef calltarget : Operand<i32>;
2677*9880d681SAndroid Build Coastguard Workerlet isCall=1 in {
2678*9880d681SAndroid Build Coastguard Worker   def CALL : NVPTXInst<(outs), (ins calltarget:$dst), "call \t$dst, (1);", []>;
2679*9880d681SAndroid Build Coastguard Worker}
2680*9880d681SAndroid Build Coastguard Worker
2681*9880d681SAndroid Build Coastguard Workerdef : Pat<(call tglobaladdr:$dst), (CALL tglobaladdr:$dst)>;
2682*9880d681SAndroid Build Coastguard Workerdef : Pat<(call texternalsym:$dst), (CALL texternalsym:$dst)>;
2683*9880d681SAndroid Build Coastguard Worker
2684*9880d681SAndroid Build Coastguard Worker// Pseudo instructions.
2685*9880d681SAndroid Build Coastguard Workerclass Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
2686*9880d681SAndroid Build Coastguard Worker   : NVPTXInst<outs, ins, asmstr, pattern>;
2687*9880d681SAndroid Build Coastguard Worker
2688*9880d681SAndroid Build Coastguard Workerdef Callseq_Start :
2689*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs), (ins i32imm:$amt),
2690*9880d681SAndroid Build Coastguard Worker            "\\{ // callseq $amt\n"
2691*9880d681SAndroid Build Coastguard Worker            "\t.reg .b32 temp_param_reg;",
2692*9880d681SAndroid Build Coastguard Worker           [(callseq_start timm:$amt)]>;
2693*9880d681SAndroid Build Coastguard Workerdef Callseq_End :
2694*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs), (ins i32imm:$amt1, i32imm:$amt2),
2695*9880d681SAndroid Build Coastguard Worker            "\\} // callseq $amt1",
2696*9880d681SAndroid Build Coastguard Worker            [(callseq_end timm:$amt1, timm:$amt2)]>;
2697*9880d681SAndroid Build Coastguard Worker
2698*9880d681SAndroid Build Coastguard Worker// trap instruction
2699*9880d681SAndroid Build Coastguard Workerdef trapinst : NVPTXInst<(outs), (ins), "trap;", [(trap)]>;
2700*9880d681SAndroid Build Coastguard Worker
2701*9880d681SAndroid Build Coastguard Worker// Call prototype wrapper
2702*9880d681SAndroid Build Coastguard Workerdef SDTCallPrototype : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
2703*9880d681SAndroid Build Coastguard Workerdef CallPrototype :
2704*9880d681SAndroid Build Coastguard Worker  SDNode<"NVPTXISD::CallPrototype", SDTCallPrototype,
2705*9880d681SAndroid Build Coastguard Worker         [SDNPHasChain, SDNPOutGlue, SDNPInGlue, SDNPSideEffect]>;
2706*9880d681SAndroid Build Coastguard Workerdef ProtoIdent : Operand<i32> {
2707*9880d681SAndroid Build Coastguard Worker  let PrintMethod = "printProtoIdent";
2708*9880d681SAndroid Build Coastguard Worker}
2709*9880d681SAndroid Build Coastguard Workerdef CALL_PROTOTYPE :
2710*9880d681SAndroid Build Coastguard Worker  NVPTXInst<(outs), (ins ProtoIdent:$ident),
2711*9880d681SAndroid Build Coastguard Worker            "$ident", [(CallPrototype (i32 texternalsym:$ident))]>;
2712*9880d681SAndroid Build Coastguard Worker
2713*9880d681SAndroid Build Coastguard Worker
2714*9880d681SAndroid Build Coastguard Workerinclude "NVPTXIntrinsics.td"
2715*9880d681SAndroid Build Coastguard Worker
2716*9880d681SAndroid Build Coastguard Worker
2717*9880d681SAndroid Build Coastguard Worker//-----------------------------------
2718*9880d681SAndroid Build Coastguard Worker// Notes
2719*9880d681SAndroid Build Coastguard Worker//-----------------------------------
2720*9880d681SAndroid Build Coastguard Worker// BSWAP is currently expanded. The following is a more efficient
2721*9880d681SAndroid Build Coastguard Worker// - for < sm_20, use vector scalar mov, as tesla support native 16-bit register
2722*9880d681SAndroid Build Coastguard Worker// - for sm_20, use pmpt (use vector scalar mov to get the pack and
2723*9880d681SAndroid Build Coastguard Worker//   unpack). sm_20 supports native 32-bit register, but not native 16-bit
2724*9880d681SAndroid Build Coastguard Worker// register.
2725