cac64e5987dc87d8232007bf1433138aaae9dbaa
[oota-llvm.git] / lib / Target / Mips / MipsInstrInfo.td
1 //===- MipsInstrInfo.td - Target Description for Mips Target -*- tablegen -*-=//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the Mips implementation of the TargetInstrInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // Instruction format superclass
16 //===----------------------------------------------------------------------===//
17
18 include "MipsInstrFormats.td"
19
20 //===----------------------------------------------------------------------===//
21 // Mips profiles and nodes
22 //===----------------------------------------------------------------------===//
23
24 def SDT_MipsRet          : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
25 def SDT_MipsJmpLink      : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
26 def SDT_MipsCMov         : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
27                                                 SDTCisSameAs<1, 2>,
28                                                 SDTCisSameAs<3, 4>,
29                                                 SDTCisInt<4>]>;
30 def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
31 def SDT_MipsCallSeqEnd   : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
32 def SDT_MipsMAddMSub     : SDTypeProfile<0, 4,
33                                          [SDTCisVT<0, i32>, SDTCisSameAs<0, 1>,
34                                           SDTCisSameAs<1, 2>,
35                                           SDTCisSameAs<2, 3>]>;
36 def SDT_MipsDivRem       : SDTypeProfile<0, 2,
37                                          [SDTCisVT<0, i32>,
38                                           SDTCisSameAs<0, 1>]>;
39
40 def SDT_MipsThreadPointer : SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>;
41
42 def SDT_MipsDynAlloc    : SDTypeProfile<1, 1, [SDTCisVT<0, i32>,
43                                                SDTCisVT<1, iPTR>]>;
44 def SDT_Sync             : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
45
46 def SDT_Ext : SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
47                                    SDTCisVT<2, i32>, SDTCisSameAs<2, 3>]>;
48 def SDT_Ins : SDTypeProfile<1, 4, [SDTCisInt<0>, SDTCisSameAs<0, 1>,
49                                    SDTCisVT<2, i32>, SDTCisSameAs<2, 3>,
50                                    SDTCisSameAs<0, 4>]>;
51
52 // Call
53 def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
54                          [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
55                           SDNPVariadic]>;
56
57 // Hi and Lo nodes are used to handle global addresses. Used on
58 // MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
59 // static model. (nothing to do with Mips Registers Hi and Lo)
60 def MipsHi    : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
61 def MipsLo    : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
62 def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
63
64 // TlsGd node is used to handle General Dynamic TLS
65 def MipsTlsGd : SDNode<"MipsISD::TlsGd", SDTIntUnaryOp>;
66
67 // TprelHi and TprelLo nodes are used to handle Local Exec TLS
68 def MipsTprelHi    : SDNode<"MipsISD::TprelHi", SDTIntUnaryOp>;
69 def MipsTprelLo    : SDNode<"MipsISD::TprelLo", SDTIntUnaryOp>;
70
71 // Thread pointer
72 def MipsThreadPointer: SDNode<"MipsISD::ThreadPointer", SDT_MipsThreadPointer>;
73
74 // Return
75 def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
76                      SDNPOptInGlue]>;
77
78 // These are target-independent nodes, but have target-specific formats.
79 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
80                            [SDNPHasChain, SDNPOutGlue]>;
81 def callseq_end   : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
82                            [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
83
84 // MAdd*/MSub* nodes
85 def MipsMAdd      : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
86                            [SDNPOptInGlue, SDNPOutGlue]>;
87 def MipsMAddu     : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
88                            [SDNPOptInGlue, SDNPOutGlue]>;
89 def MipsMSub      : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
90                            [SDNPOptInGlue, SDNPOutGlue]>;
91 def MipsMSubu     : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
92                            [SDNPOptInGlue, SDNPOutGlue]>;
93
94 // DivRem(u) nodes
95 def MipsDivRem    : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
96                            [SDNPOutGlue]>;
97 def MipsDivRemU   : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
98                            [SDNPOutGlue]>;
99
100 // Target constant nodes that are not part of any isel patterns and remain
101 // unchanged can cause instructions with illegal operands to be emitted.
102 // Wrapper node patterns give the instruction selector a chance to replace
103 // target constant nodes that would otherwise remain unchanged with ADDiu
104 // nodes. Without these wrapper node patterns, the following conditional move
105 // instrucion is emitted when function cmov2 in test/CodeGen/Mips/cmov.ll is
106 // compiled: 
107 //  movn  %got(d)($gp), %got(c)($gp), $4
108 // This instruction is illegal since movn can take only register operands.
109
110 def MipsWrapperPIC    : SDNode<"MipsISD::WrapperPIC",  SDTIntUnaryOp>;
111
112 // Pointer to dynamically allocated stack area.
113 def MipsDynAlloc  : SDNode<"MipsISD::DynAlloc", SDT_MipsDynAlloc,
114                            [SDNPHasChain, SDNPInGlue]>;
115
116 def MipsSync : SDNode<"MipsISD::Sync", SDT_Sync, [SDNPHasChain]>;
117
118 def MipsExt :  SDNode<"MipsISD::Ext", SDT_Ext>;
119 def MipsIns :  SDNode<"MipsISD::Ins", SDT_Ins>;
120
121 //===----------------------------------------------------------------------===//
122 // Mips Instruction Predicate Definitions.
123 //===----------------------------------------------------------------------===//
124 def HasSEInReg  : Predicate<"Subtarget.hasSEInReg()">;
125 def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
126 def HasSwap     : Predicate<"Subtarget.hasSwap()">;
127 def HasCondMov  : Predicate<"Subtarget.hasCondMov()">;
128 def HasMips32    : Predicate<"Subtarget.hasMips32()">;
129 def HasMips32r2  : Predicate<"Subtarget.hasMips32r2()">;
130
131 //===----------------------------------------------------------------------===//
132 // Mips Operand, Complex Patterns and Transformations Definitions.
133 //===----------------------------------------------------------------------===//
134
135 // Instruction operand types
136 def brtarget    : Operand<OtherVT>;
137 def calltarget  : Operand<i32>;
138 def simm16      : Operand<i32>;
139 def shamt       : Operand<i32>;
140
141 // Unsigned Operand
142 def uimm16      : Operand<i32> {
143   let PrintMethod = "printUnsignedImm";
144 }
145
146 // Address operand
147 def mem : Operand<i32> {
148   let PrintMethod = "printMemOperand";
149   let MIOperandInfo = (ops CPURegs, simm16);
150 }
151
152 def mem_ea : Operand<i32> {
153   let PrintMethod = "printMemOperandEA";
154   let MIOperandInfo = (ops CPURegs, simm16);
155 }
156
157 // Transformation Function - get the lower 16 bits.
158 def LO16 : SDNodeXForm<imm, [{
159   return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
160 }]>;
161
162 // Transformation Function - get the higher 16 bits.
163 def HI16 : SDNodeXForm<imm, [{
164   return getI32Imm((unsigned)N->getZExtValue() >> 16);
165 }]>;
166
167 // Node immediate fits as 16-bit sign extended on target immediate.
168 // e.g. addi, andi
169 def immSExt16  : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
170
171 // Node immediate fits as 16-bit zero extended on target immediate.
172 // The LO16 param means that only the lower 16 bits of the node
173 // immediate are caught.
174 // e.g. addiu, sltiu
175 def immZExt16  : PatLeaf<(imm), [{
176   if (N->getValueType(0) == MVT::i32)
177     return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
178   else
179     return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
180 }], LO16>;
181
182 // shamt field must fit in 5 bits.
183 def immZExt5 : PatLeaf<(imm), [{
184   return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
185 }]>;
186
187 // Mips Address Mode! SDNode frameindex could possibily be a match
188 // since load and store instructions from stack used it.
189 def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
190
191 //===----------------------------------------------------------------------===//
192 // Instructions specific format
193 //===----------------------------------------------------------------------===//
194
195 // Arithmetic 3 register operands
196 class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
197              InstrItinClass itin, bit isComm = 0>:
198   FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
199      !strconcat(instr_asm, "\t$dst, $b, $c"),
200      [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin> {
201   let isCommutable = isComm;
202 }
203
204 class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm,
205                      bit isComm = 0>:
206   FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
207      !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu> {
208   let isCommutable = isComm;
209 }
210
211 // Arithmetic 2 register operands
212 class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
213              Operand Od, PatLeaf imm_type> :
214   FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
215      !strconcat(instr_asm, "\t$dst, $b, $c"),
216      [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
217
218 class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
219              Operand Od, PatLeaf imm_type> :
220   FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
221      !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
222
223 // Arithmetic Multiply ADD/SUB
224 let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
225 class MArithR<bits<6> func, string instr_asm, SDNode op, bit isComm = 0> :
226   FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
227      !strconcat(instr_asm, "\t$rs, $rt"),
228      [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul> {
229   let isCommutable = isComm;
230 }
231
232 //  Logical
233 let isCommutable = 1 in
234 class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
235   FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
236      !strconcat(instr_asm, "\t$dst, $b, $c"),
237      [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
238
239 class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
240   FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
241      !strconcat(instr_asm, "\t$dst, $b, $c"),
242      [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
243
244 let isCommutable = 1 in
245 class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
246   FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
247      !strconcat(instr_asm, "\t$dst, $b, $c"),
248      [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
249
250 // Shifts
251 class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
252                               SDNode OpNode>:
253   FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
254      !strconcat(instr_asm, "\t$dst, $b, $c"),
255      [(set CPURegs:$dst, (OpNode CPURegs:$b, (i32 immZExt5:$c)))], IIAlu> {
256   let rs = _rs;
257 }
258
259 class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
260                               SDNode OpNode>:
261   FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
262      !strconcat(instr_asm, "\t$dst, $b, $c"),
263      [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
264   let shamt = _shamt;
265 }
266
267 // Load Upper Imediate
268 class LoadUpper<bits<6> op, string instr_asm>:
269   FI< op,
270       (outs CPURegs:$dst),
271       (ins uimm16:$imm),
272       !strconcat(instr_asm, "\t$dst, $imm"),
273       [], IIAlu>;
274
275 // Memory Load/Store
276 let canFoldAsLoad = 1 in
277 class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
278   FI<op, (outs CPURegs:$dst), (ins mem:$addr),
279      !strconcat(instr_asm, "\t$dst, $addr"),
280      [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
281
282 class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
283   FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
284      !strconcat(instr_asm, "\t$dst, $addr"),
285      [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
286
287 // Conditional Branch
288 let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
289 class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
290   FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
291      !strconcat(instr_asm, "\t$a, $b, $offset"),
292      [(brcond (i32 (cond_op CPURegs:$a, CPURegs:$b)), bb:$offset)],
293      IIBranch>;
294
295 class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
296   FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
297      !strconcat(instr_asm, "\t$src, $offset"),
298      [(brcond (i32 (cond_op CPURegs:$src, 0)), bb:$offset)],
299      IIBranch>;
300 }
301
302 // SetCC
303 class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
304       PatFrag cond_op>:
305   FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
306      !strconcat(instr_asm, "\t$dst, $b, $c"),
307      [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
308      IIAlu>;
309
310 class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
311       Operand Od, PatLeaf imm_type>:
312   FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
313      !strconcat(instr_asm, "\t$dst, $b, $c"),
314      [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
315      IIAlu>;
316
317 // Unconditional branch
318 let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
319 class JumpFJ<bits<6> op, string instr_asm>:
320   FJ<op, (outs), (ins brtarget:$target),
321      !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
322
323 let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
324 class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
325   FR<op, func, (outs), (ins CPURegs:$target),
326      !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
327
328 // Jump and Link (Call)
329 let isCall=1, hasDelaySlot=1,
330   // All calls clobber the non-callee saved registers...
331   Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
332           K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
333   class JumpLink<bits<6> op, string instr_asm>:
334     FJ<op, (outs), (ins calltarget:$target, variable_ops),
335        !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
336        IIBranch>;
337
338   let rd=31 in
339   class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
340     FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
341        !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
342
343   class BranchLink<string instr_asm>:
344     FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
345        !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
346 }
347
348 // Mul, Div
349 let Defs = [HI, LO] in {
350   let isCommutable = 1 in
351   class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
352     FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
353        !strconcat(instr_asm, "\t$a, $b"), [], itin>;
354
355   class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
356             FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
357             !strconcat(instr_asm, "\t$$zero, $a, $b"),
358             [(op CPURegs:$a, CPURegs:$b)], itin>;
359 }
360
361 // Move from Hi/Lo
362 let shamt = 0 in {
363 let rs = 0, rt = 0 in
364 class MoveFromLOHI<bits<6> func, string instr_asm>:
365   FR<0x00, func, (outs CPURegs:$dst), (ins),
366      !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
367
368 let rt = 0, rd = 0 in
369 class MoveToLOHI<bits<6> func, string instr_asm>:
370   FR<0x00, func, (outs), (ins CPURegs:$src),
371      !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
372 }
373
374 class EffectiveAddress<string instr_asm> :
375   FI<0x09, (outs CPURegs:$dst), (ins mem_ea:$addr),
376      instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
377
378 // Count Leading Ones/Zeros in Word
379 class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
380   FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
381      !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
382      Requires<[HasBitCount]> {
383   let shamt = 0;
384   let rt = rd;
385 }
386
387 // Sign Extend in Register.
388 class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
389   FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
390      !strconcat(instr_asm, "\t$dst, $src"),
391      [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
392
393 // Byte Swap
394 class ByteSwap<bits<6> func, string instr_asm>:
395   FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
396      !strconcat(instr_asm, "\t$dst, $src"),
397      [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
398
399 // Conditional Move
400 class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
401   FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
402      CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
403      [], NoItinerary>;
404
405 // Read Hardware
406 class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$dst), (ins HWRegs:$src),
407     "rdhwr\t$dst, $src", [], IIAlu> {
408   let rs = 0;
409   let shamt = 0;
410 }
411
412 // Ext and Ins
413 class ExtIns<bits<6> _funct, string instr_asm, dag outs, dag ins,
414              list<dag> pattern, InstrItinClass itin>:
415   FR<0x1f, _funct, outs, ins, !strconcat(instr_asm, " $rt, $rs, $pos, $sz"),
416      pattern, itin>, Requires<[HasMips32r2]> {
417   bits<5> pos;
418   bits<5> sz;
419   let rd = sz;
420   let shamt = pos;
421 }
422
423 // Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
424 class Atomic2Ops<PatFrag Op, string Opstr> :
425   MipsPseudo<(outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
426              !strconcat("atomic_", Opstr, "\t$dst, $ptr, $incr"),
427              [(set CPURegs:$dst,
428               (Op CPURegs:$ptr, CPURegs:$incr))]>;
429
430 // Atomic Compare & Swap.
431 class AtomicCmpSwap<PatFrag Op, string Width> :
432   MipsPseudo<(outs CPURegs:$dst), 
433              (ins CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap),
434              !strconcat("atomic_cmp_swap_", Width, 
435                         "\t$dst, $ptr, $cmp, $swap"),
436              [(set CPURegs:$dst,
437               (Op CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap))]>;
438
439 //===----------------------------------------------------------------------===//
440 // Pseudo instructions
441 //===----------------------------------------------------------------------===//
442
443 // As stack alignment is always done with addiu, we need a 16-bit immediate
444 let Defs = [SP], Uses = [SP] in {
445 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
446                                   "!ADJCALLSTACKDOWN $amt",
447                                   [(callseq_start timm:$amt)]>;
448 def ADJCALLSTACKUP   : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
449                                   "!ADJCALLSTACKUP $amt1",
450                                   [(callseq_end timm:$amt1, timm:$amt2)]>;
451 }
452
453 // Some assembly macros need to avoid pseudoinstructions and assembler
454 // automatic reodering, we should reorder ourselves.
455 def MACRO     : MipsPseudo<(outs), (ins), ".set\tmacro",     []>;
456 def REORDER   : MipsPseudo<(outs), (ins), ".set\treorder",   []>;
457 def NOMACRO   : MipsPseudo<(outs), (ins), ".set\tnomacro",   []>;
458 def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
459
460 // These macros are inserted to prevent GAS from complaining
461 // when using the AT register.
462 def NOAT      : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
463 def ATMACRO   : MipsPseudo<(outs), (ins), ".set\tat", []>;
464
465 // When handling PIC code the assembler needs .cpload and .cprestore
466 // directives. If the real instructions corresponding these directives
467 // are used, we have the same behavior, but get also a bunch of warnings
468 // from the assembler.
469 def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
470 def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc", []>;
471
472 let usesCustomInserter = 1 in {
473   def ATOMIC_LOAD_ADD_I8   : Atomic2Ops<atomic_load_add_8, "load_add_8">;
474   def ATOMIC_LOAD_ADD_I16  : Atomic2Ops<atomic_load_add_16, "load_add_16">;
475   def ATOMIC_LOAD_ADD_I32  : Atomic2Ops<atomic_load_add_32, "load_add_32">;
476   def ATOMIC_LOAD_SUB_I8   : Atomic2Ops<atomic_load_sub_8, "load_sub_8">;
477   def ATOMIC_LOAD_SUB_I16  : Atomic2Ops<atomic_load_sub_16, "load_sub_16">;
478   def ATOMIC_LOAD_SUB_I32  : Atomic2Ops<atomic_load_sub_32, "load_sub_32">;
479   def ATOMIC_LOAD_AND_I8   : Atomic2Ops<atomic_load_and_8, "load_and_8">;
480   def ATOMIC_LOAD_AND_I16  : Atomic2Ops<atomic_load_and_16, "load_and_16">;
481   def ATOMIC_LOAD_AND_I32  : Atomic2Ops<atomic_load_and_32, "load_and_32">;
482   def ATOMIC_LOAD_OR_I8    : Atomic2Ops<atomic_load_or_8, "load_or_8">;
483   def ATOMIC_LOAD_OR_I16   : Atomic2Ops<atomic_load_or_16, "load_or_16">;
484   def ATOMIC_LOAD_OR_I32   : Atomic2Ops<atomic_load_or_32, "load_or_32">;
485   def ATOMIC_LOAD_XOR_I8   : Atomic2Ops<atomic_load_xor_8, "load_xor_8">;
486   def ATOMIC_LOAD_XOR_I16  : Atomic2Ops<atomic_load_xor_16, "load_xor_16">;
487   def ATOMIC_LOAD_XOR_I32  : Atomic2Ops<atomic_load_xor_32, "load_xor_32">;
488   def ATOMIC_LOAD_NAND_I8  : Atomic2Ops<atomic_load_nand_8, "load_nand_8">;
489   def ATOMIC_LOAD_NAND_I16 : Atomic2Ops<atomic_load_nand_16, "load_nand_16">;
490   def ATOMIC_LOAD_NAND_I32 : Atomic2Ops<atomic_load_nand_32, "load_nand_32">;
491
492   def ATOMIC_SWAP_I8       : Atomic2Ops<atomic_swap_8, "swap_8">;
493   def ATOMIC_SWAP_I16      : Atomic2Ops<atomic_swap_16, "swap_16">;
494   def ATOMIC_SWAP_I32      : Atomic2Ops<atomic_swap_32, "swap_32">;
495
496   def ATOMIC_CMP_SWAP_I8   : AtomicCmpSwap<atomic_cmp_swap_8, "8">;
497   def ATOMIC_CMP_SWAP_I16  : AtomicCmpSwap<atomic_cmp_swap_16, "16">;
498   def ATOMIC_CMP_SWAP_I32  : AtomicCmpSwap<atomic_cmp_swap_32, "32">;
499 }
500
501 // Unaligned loads and stores.
502 // Replaces LW or SW during MCInstLowering if memory access is unaligned.
503 def ULW :
504   MipsPseudo<(outs CPURegs:$dst), (ins mem:$addr), "ulw\t$dst, $addr", []>;
505 def ULH :
506   MipsPseudo<(outs CPURegs:$dst), (ins mem:$addr), "ulh\t$dst, $addr", []>;
507 def ULHu :
508   MipsPseudo<(outs CPURegs:$dst), (ins mem:$addr), "ulhu\t$dst, $addr", []>;
509 def USW : 
510   MipsPseudo<(outs), (ins CPURegs:$dst, mem:$addr), "usw\t$dst, $addr", []>;
511 def USH : 
512   MipsPseudo<(outs), (ins CPURegs:$dst, mem:$addr), "ush\t$dst, $addr", []>;
513
514 //===----------------------------------------------------------------------===//
515 // Instruction definition
516 //===----------------------------------------------------------------------===//
517
518 //===----------------------------------------------------------------------===//
519 // MipsI Instructions
520 //===----------------------------------------------------------------------===//
521
522 /// Arithmetic Instructions (ALU Immediate)
523 def ADDiu   : ArithI<0x09, "addiu", add, simm16, immSExt16>;
524 def ADDi    : ArithOverflowI<0x08, "addi",  add, simm16, immSExt16>;
525 def SLTi    : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
526 def SLTiu   : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
527 def ANDi    : LogicI<0x0c, "andi", and>;
528 def ORi     : LogicI<0x0d, "ori",  or>;
529 def XORi    : LogicI<0x0e, "xori",  xor>;
530 def LUi     : LoadUpper<0x0f, "lui">;
531
532 /// Arithmetic Instructions (3-Operand, R-Type)
533 def ADDu    : ArithR<0x00, 0x21, "addu", add, IIAlu, 1>;
534 def SUBu    : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
535 def ADD     : ArithOverflowR<0x00, 0x20, "add", 1>;
536 def SUB     : ArithOverflowR<0x00, 0x22, "sub">;
537 def SLT     : SetCC_R<0x00, 0x2a, "slt", setlt>;
538 def SLTu    : SetCC_R<0x00, 0x2b, "sltu", setult>;
539 def AND     : LogicR<0x24, "and", and>;
540 def OR      : LogicR<0x25, "or",  or>;
541 def XOR     : LogicR<0x26, "xor", xor>;
542 def NOR     : LogicNOR<0x00, 0x27, "nor">;
543
544 /// Shift Instructions
545 def SLL     : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
546 def SRL     : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
547 def SRA     : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
548 def SLLV    : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
549 def SRLV    : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
550 def SRAV    : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
551
552 // Rotate Instructions
553 let Predicates = [HasMips32r2] in {
554     def ROTR    : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
555     def ROTRV   : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
556 }
557
558 /// Load and Store Instructions
559 def LB      : LoadM<0x20, "lb",  sextloadi8>;
560 def LBu     : LoadM<0x24, "lbu", zextloadi8>;
561 def LH      : LoadM<0x21, "lh",  sextloadi16>;
562 def LHu     : LoadM<0x25, "lhu", zextloadi16>;
563 def LW      : LoadM<0x23, "lw",  load>;
564 def SB      : StoreM<0x28, "sb", truncstorei8>;
565 def SH      : StoreM<0x29, "sh", truncstorei16>;
566 def SW      : StoreM<0x2b, "sw", store>;
567
568 let hasSideEffects = 1 in
569 def SYNC : MipsInst<(outs), (ins i32imm:$stype), "sync $stype",
570                     [(MipsSync imm:$stype)], NoItinerary>
571 {
572   let opcode = 0;
573   let Inst{25-11} = 0;
574   let Inst{5-0} = 15;
575 }
576
577 /// Load-linked, Store-conditional
578 let mayLoad = 1 in
579   def LL    : FI<0x30, (outs CPURegs:$dst), (ins mem:$addr),
580               "ll\t$dst, $addr", [], IILoad>;
581 let mayStore = 1, Constraints = "$src = $dst" in
582   def SC    : FI<0x38, (outs CPURegs:$dst), (ins CPURegs:$src, mem:$addr),
583               "sc\t$src, $addr", [], IIStore>;
584
585 /// Jump and Branch Instructions
586 def J       : JumpFJ<0x02, "j">;
587 let isIndirectBranch = 1 in
588   def JR      : JumpFR<0x00, 0x08, "jr">;
589 def JAL     : JumpLink<0x03, "jal">;
590 def JALR    : JumpLinkReg<0x00, 0x09, "jalr">;
591 def BEQ     : CBranch<0x04, "beq", seteq>;
592 def BNE     : CBranch<0x05, "bne", setne>;
593
594 let rt=1 in
595   def BGEZ  : CBranchZero<0x01, "bgez", setge>;
596
597 let rt=0 in {
598   def BGTZ  : CBranchZero<0x07, "bgtz", setgt>;
599   def BLEZ  : CBranchZero<0x07, "blez", setle>;
600   def BLTZ  : CBranchZero<0x01, "bltz", setlt>;
601 }
602
603 def BGEZAL  : BranchLink<"bgezal">;
604 def BLTZAL  : BranchLink<"bltzal">;
605
606 let isReturn=1, isTerminator=1, hasDelaySlot=1,
607     isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
608   def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
609                 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
610
611 /// Multiply and Divide Instructions.
612 def MULT    : Mul<0x18, "mult", IIImul>;
613 def MULTu   : Mul<0x19, "multu", IIImul>;
614 def SDIV    : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
615 def UDIV    : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
616
617 let Defs = [HI] in
618   def MTHI  : MoveToLOHI<0x11, "mthi">;
619 let Defs = [LO] in
620   def MTLO  : MoveToLOHI<0x13, "mtlo">;
621
622 let Uses = [HI] in
623   def MFHI  : MoveFromLOHI<0x10, "mfhi">;
624 let Uses = [LO] in
625   def MFLO  : MoveFromLOHI<0x12, "mflo">;
626
627 /// Sign Ext In Register Instructions.
628 let Predicates = [HasSEInReg] in {
629   let shamt = 0x10, rs = 0 in
630     def SEB : SignExtInReg<0x21, "seb", i8>;
631
632   let shamt = 0x18, rs = 0 in
633     def SEH : SignExtInReg<0x20, "seh", i16>;
634 }
635
636 /// Count Leading
637 def CLZ : CountLeading<0b100000, "clz",
638                        [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
639 def CLO : CountLeading<0b100001, "clo",
640                        [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
641
642 /// Byte Swap
643 let Predicates = [HasSwap] in {
644   let shamt = 0x3, rs = 0 in
645     def WSBW : ByteSwap<0x20, "wsbw">;
646 }
647
648 /// Conditional Move
649 def MIPS_CMOV_ZERO  : PatLeaf<(i32 0)>;
650 def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
651
652 // Conditional moves:
653 // These instructions are expanded in
654 // MipsISelLowering::EmitInstrWithCustomInserter if target does not have
655 // conditional move instructions.
656 // flag:int, data:int
657 let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
658   class CondMovIntInt<bits<6> funct, string instr_asm> :
659     FR<0, funct, (outs CPURegs:$dst),
660        (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
661        !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
662
663 def MOVZ_I : CondMovIntInt<0x0a, "movz">;
664 def MOVN_I : CondMovIntInt<0x0b, "movn">;
665
666 /// No operation
667 let addr=0 in
668   def NOP   : FJ<0, (outs), (ins), "nop", [], IIAlu>;
669
670 // FrameIndexes are legalized when they are operands from load/store
671 // instructions. The same not happens for stack address copies, so an
672 // add op with mem ComplexPattern is used and the stack address copy
673 // can be matched. It's similar to Sparc LEA_ADDRi
674 def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, $addr">;
675
676 // DynAlloc node points to dynamically allocated stack space.
677 // $sp is added to the list of implicitly used registers to prevent dead code
678 // elimination from removing instructions that modify $sp.
679 let Uses = [SP] in
680 def DynAlloc : EffectiveAddress<"addiu\t$dst, $addr">;
681
682 // MADD*/MSUB*
683 def MADD  : MArithR<0, "madd", MipsMAdd, 1>;
684 def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
685 def MSUB  : MArithR<4, "msub", MipsMSub>;
686 def MSUBU : MArithR<5, "msubu", MipsMSubu>;
687
688 // MUL is a assembly macro in the current used ISAs. In recent ISA's
689 // it is a real instruction.
690 def MUL   : ArithR<0x1c, 0x02, "mul", mul, IIImul, 1>, Requires<[HasMips32]>;
691
692 def RDHWR : ReadHardware;
693
694 def EXT : ExtIns<0, "ext", (outs CPURegs:$rt),
695                  (ins CPURegs:$rs, uimm16:$pos, uimm16:$sz),
696                  [(set CPURegs:$rt,
697                    (MipsExt CPURegs:$rs, immZExt5:$pos, immZExt5:$sz))],
698                  NoItinerary>;
699
700 let Constraints = "$src = $rt" in
701 def INS : ExtIns<4, "ins", (outs CPURegs:$rt),
702                  (ins CPURegs:$rs, uimm16:$pos, uimm16:$sz, CPURegs:$src),
703                  [(set CPURegs:$rt,
704                    (MipsIns CPURegs:$rs, immZExt5:$pos, immZExt5:$sz,
705                     CPURegs:$src))],
706                  NoItinerary>;
707
708 //===----------------------------------------------------------------------===//
709 //  Arbitrary patterns that map to one or more instructions
710 //===----------------------------------------------------------------------===//
711
712 // Small immediates
713 def : Pat<(i32 immSExt16:$in),
714           (ADDiu ZERO, imm:$in)>;
715 def : Pat<(i32 immZExt16:$in),
716           (ORi ZERO, imm:$in)>;
717
718 // Arbitrary immediates
719 def : Pat<(i32 imm:$imm),
720           (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
721
722 // Carry patterns
723 def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
724           (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
725 def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
726           (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
727 def : Pat<(addc  CPURegs:$src, immSExt16:$imm),
728           (ADDiu CPURegs:$src, imm:$imm)>;
729
730 // Call
731 def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
732           (JAL tglobaladdr:$dst)>;
733 def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
734           (JAL texternalsym:$dst)>;
735 //def : Pat<(MipsJmpLink CPURegs:$dst),
736 //          (JALR CPURegs:$dst)>;
737
738 // hi/lo relocs
739 def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
740 def : Pat<(MipsHi tblockaddress:$in), (LUi tblockaddress:$in)>;
741 def : Pat<(MipsLo tglobaladdr:$in), (ADDiu ZERO, tglobaladdr:$in)>;
742 def : Pat<(MipsLo tblockaddress:$in), (ADDiu ZERO, tblockaddress:$in)>;
743 def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
744           (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
745 def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
746           (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
747
748 def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
749 def : Pat<(MipsLo tjumptable:$in), (ADDiu ZERO, tjumptable:$in)>;
750 def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
751           (ADDiu CPURegs:$hi, tjumptable:$lo)>;
752
753 def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
754 def : Pat<(MipsLo tconstpool:$in), (ADDiu ZERO, tconstpool:$in)>;
755 def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
756           (ADDiu CPURegs:$hi, tconstpool:$lo)>;
757
758 // gp_rel relocs
759 def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
760           (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
761 def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
762           (ADDiu CPURegs:$gp, tconstpool:$in)>;
763
764 // tlsgd
765 def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
766           (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
767
768 // tprel hi/lo
769 def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
770 def : Pat<(MipsTprelLo tglobaltlsaddr:$in), (ADDiu ZERO, tglobaltlsaddr:$in)>;
771 def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
772           (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
773
774 // wrapper_pic
775 class WrapperPICPat<SDNode node>:
776       Pat<(MipsWrapperPIC node:$in),
777           (ADDiu GP, node:$in)>;
778
779 def : WrapperPICPat<tglobaladdr>;
780 def : WrapperPICPat<tconstpool>;
781 def : WrapperPICPat<texternalsym>;
782 def : WrapperPICPat<tblockaddress>;
783 def : WrapperPICPat<tjumptable>;
784
785 // Mips does not have "not", so we expand our way
786 def : Pat<(not CPURegs:$in),
787           (NOR CPURegs:$in, ZERO)>;
788
789 // extended load and stores
790 def : Pat<(extloadi1  addr:$src), (LBu addr:$src)>;
791 def : Pat<(extloadi8  addr:$src), (LBu addr:$src)>;
792 def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
793
794 // peepholes
795 def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
796
797 // brcond patterns
798 def : Pat<(brcond (i32 (setne CPURegs:$lhs, 0)), bb:$dst),
799           (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
800 def : Pat<(brcond (i32 (seteq CPURegs:$lhs, 0)), bb:$dst),
801           (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
802
803 def : Pat<(brcond (i32 (setge CPURegs:$lhs, CPURegs:$rhs)), bb:$dst),
804           (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
805 def : Pat<(brcond (i32 (setuge CPURegs:$lhs, CPURegs:$rhs)), bb:$dst),
806           (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
807 def : Pat<(brcond (i32 (setge CPURegs:$lhs, immSExt16:$rhs)), bb:$dst),
808           (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
809 def : Pat<(brcond (i32 (setuge CPURegs:$lhs, immSExt16:$rhs)), bb:$dst),
810           (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
811
812 def : Pat<(brcond (i32 (setle CPURegs:$lhs, CPURegs:$rhs)), bb:$dst),
813           (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
814 def : Pat<(brcond (i32 (setule CPURegs:$lhs, CPURegs:$rhs)), bb:$dst),
815           (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
816
817 def : Pat<(brcond CPURegs:$cond, bb:$dst),
818           (BNE CPURegs:$cond, ZERO, bb:$dst)>;
819
820 // select patterns
821 multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
822   def : Pat<(select (i32 (setge CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
823             (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
824   def : Pat<(select (i32 (setuge CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
825             (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
826   def : Pat<(select (i32 (setge CPURegs:$lhs, immSExt16:$rhs)), RC:$T, RC:$F),
827             (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
828   def : Pat<(select (i32 (setuge CPURegs:$lh, immSExt16:$rh)), RC:$T, RC:$F),
829             (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
830   def : Pat<(select (i32 (setle CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
831             (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
832   def : Pat<(select (i32 (setule CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
833             (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
834   def : Pat<(select (i32 (seteq CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
835             (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
836   def : Pat<(select (i32 (seteq CPURegs:$lhs, 0)), RC:$T, RC:$F),
837             (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
838 }
839
840 multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
841   def : Pat<(select (i32 (setne CPURegs:$lhs, CPURegs:$rhs)), RC:$T, RC:$F),
842             (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
843   def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
844             (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
845   def : Pat<(select (i32 (setne CPURegs:$lhs, 0)), RC:$T, RC:$F),
846             (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
847 }
848
849 defm : MovzPats<CPURegs, MOVZ_I>;
850 defm : MovnPats<CPURegs, MOVN_I>;
851
852 // setcc patterns
853 def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
854           (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
855 def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
856           (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
857
858 def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
859           (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
860 def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
861           (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
862
863 def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
864           (SLT CPURegs:$rhs, CPURegs:$lhs)>;
865 def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
866           (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
867
868 def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
869           (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
870 def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
871           (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
872
873 def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
874           (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
875 def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
876           (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
877
878 // select MipsDynAlloc
879 def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
880
881 //===----------------------------------------------------------------------===//
882 // Floating Point Support
883 //===----------------------------------------------------------------------===//
884
885 include "MipsInstrFPU.td"
886 include "Mips64InstrInfo.td"
887