Changed definition of EXT and INS per Bruno's comments.
[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, [SDTCisVT<0, i32>, SDTCisSameAs<0, 1>,
47                                    SDTCisInt<2>, SDTCisSameAs<2, 3>]>;
48 def SDT_Ins : SDTypeProfile<1, 4, [SDTCisVT<0, i32>, SDTCisSameAs<0, 1>,
49                                    SDTCisInt<2>, 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 IsMips32    : Predicate<"Subtarget.isMips32()">;
129 def IsMips32r2  : Predicate<"Subtarget.isMips32r2()">;
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, 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, hasDelaySlot = 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 (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 (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 class MoveFromLOHI<bits<6> func, string instr_asm>:
363   FR<0x00, func, (outs CPURegs:$dst), (ins),
364      !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
365
366 class MoveToLOHI<bits<6> func, string instr_asm>:
367   FR<0x00, func, (outs), (ins CPURegs:$src),
368      !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
369
370 class EffectiveAddress<string instr_asm> :
371   FI<0x09, (outs CPURegs:$dst), (ins mem_ea:$addr),
372      instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
373
374 // Count Leading Ones/Zeros in Word
375 class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
376   FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
377      !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
378      Requires<[HasBitCount]> {
379   let shamt = 0;
380   let rt = rd;
381 }
382
383 // Sign Extend in Register.
384 class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
385   FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
386      !strconcat(instr_asm, "\t$dst, $src"),
387      [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
388
389 // Byte Swap
390 class ByteSwap<bits<6> func, string instr_asm>:
391   FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
392      !strconcat(instr_asm, "\t$dst, $src"),
393      [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
394
395 // Conditional Move
396 class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
397   FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
398      CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
399      [], NoItinerary>;
400
401 // Read Hardware
402 class ReadHardware: FR<0x1f, 0x3b, (outs CPURegs:$dst), (ins HWRegs:$src),
403     "rdhwr\t$dst, $src", [], IIAlu> {
404   let rs = 0;
405   let shamt = 0;
406 }
407
408 // Ext and Ins
409 class ExtIns<bits<6> _funct, string instr_asm, dag ins,
410              list<dag> pattern, InstrItinClass itin>:
411   FR<0x1f, _funct, (outs CPURegs:$rt), ins,
412      !strconcat(instr_asm, "\t$rt, $rs, $pos, $size"), pattern, itin> {
413   bits<5> src;
414   bits<5> pos;
415   bits<5> size;
416   let rs = src;
417   let rd = size;
418   let shamt = pos;
419 }
420
421 // Atomic instructions with 2 source operands (ATOMIC_SWAP & ATOMIC_LOAD_*).
422 class Atomic2Ops<PatFrag Op, string Opstr> :
423   MipsPseudo<(outs CPURegs:$dst), (ins CPURegs:$ptr, CPURegs:$incr),
424              !strconcat("atomic_", Opstr, "\t$dst, $ptr, $incr"),
425              [(set CPURegs:$dst,
426               (Op CPURegs:$ptr, CPURegs:$incr))]>;
427
428 // Atomic Compare & Swap.
429 class AtomicCmpSwap<PatFrag Op, string Width> :
430   MipsPseudo<(outs CPURegs:$dst), 
431              (ins CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap),
432              !strconcat("atomic_cmp_swap_", Width, 
433                         "\t$dst, $ptr, $cmp, $swap"),
434              [(set CPURegs:$dst,
435               (Op CPURegs:$ptr, CPURegs:$cmp, CPURegs:$swap))]>;
436
437 //===----------------------------------------------------------------------===//
438 // Pseudo instructions
439 //===----------------------------------------------------------------------===//
440
441 // As stack alignment is always done with addiu, we need a 16-bit immediate
442 let Defs = [SP], Uses = [SP] in {
443 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
444                                   "!ADJCALLSTACKDOWN $amt",
445                                   [(callseq_start timm:$amt)]>;
446 def ADJCALLSTACKUP   : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
447                                   "!ADJCALLSTACKUP $amt1",
448                                   [(callseq_end timm:$amt1, timm:$amt2)]>;
449 }
450
451 // Some assembly macros need to avoid pseudoinstructions and assembler
452 // automatic reodering, we should reorder ourselves.
453 def MACRO     : MipsPseudo<(outs), (ins), ".set\tmacro",     []>;
454 def REORDER   : MipsPseudo<(outs), (ins), ".set\treorder",   []>;
455 def NOMACRO   : MipsPseudo<(outs), (ins), ".set\tnomacro",   []>;
456 def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
457
458 // These macros are inserted to prevent GAS from complaining
459 // when using the AT register.
460 def NOAT      : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
461 def ATMACRO   : MipsPseudo<(outs), (ins), ".set\tat", []>;
462
463 // When handling PIC code the assembler needs .cpload and .cprestore
464 // directives. If the real instructions corresponding these directives
465 // are used, we have the same behavior, but get also a bunch of warnings
466 // from the assembler.
467 def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
468 def CPRESTORE : MipsPseudo<(outs), (ins i32imm:$loc), ".cprestore\t$loc", []>;
469
470 let usesCustomInserter = 1 in {
471   def ATOMIC_LOAD_ADD_I8   : Atomic2Ops<atomic_load_add_8, "load_add_8">;
472   def ATOMIC_LOAD_ADD_I16  : Atomic2Ops<atomic_load_add_16, "load_add_16">;
473   def ATOMIC_LOAD_ADD_I32  : Atomic2Ops<atomic_load_add_32, "load_add_32">;
474   def ATOMIC_LOAD_SUB_I8   : Atomic2Ops<atomic_load_sub_8, "load_sub_8">;
475   def ATOMIC_LOAD_SUB_I16  : Atomic2Ops<atomic_load_sub_16, "load_sub_16">;
476   def ATOMIC_LOAD_SUB_I32  : Atomic2Ops<atomic_load_sub_32, "load_sub_32">;
477   def ATOMIC_LOAD_AND_I8   : Atomic2Ops<atomic_load_and_8, "load_and_8">;
478   def ATOMIC_LOAD_AND_I16  : Atomic2Ops<atomic_load_and_16, "load_and_16">;
479   def ATOMIC_LOAD_AND_I32  : Atomic2Ops<atomic_load_and_32, "load_and_32">;
480   def ATOMIC_LOAD_OR_I8    : Atomic2Ops<atomic_load_or_8, "load_or_8">;
481   def ATOMIC_LOAD_OR_I16   : Atomic2Ops<atomic_load_or_16, "load_or_16">;
482   def ATOMIC_LOAD_OR_I32   : Atomic2Ops<atomic_load_or_32, "load_or_32">;
483   def ATOMIC_LOAD_XOR_I8   : Atomic2Ops<atomic_load_xor_8, "load_xor_8">;
484   def ATOMIC_LOAD_XOR_I16  : Atomic2Ops<atomic_load_xor_16, "load_xor_16">;
485   def ATOMIC_LOAD_XOR_I32  : Atomic2Ops<atomic_load_xor_32, "load_xor_32">;
486   def ATOMIC_LOAD_NAND_I8  : Atomic2Ops<atomic_load_nand_8, "load_nand_8">;
487   def ATOMIC_LOAD_NAND_I16 : Atomic2Ops<atomic_load_nand_16, "load_nand_16">;
488   def ATOMIC_LOAD_NAND_I32 : Atomic2Ops<atomic_load_nand_32, "load_nand_32">;
489
490   def ATOMIC_SWAP_I8       : Atomic2Ops<atomic_swap_8, "swap_8">;
491   def ATOMIC_SWAP_I16      : Atomic2Ops<atomic_swap_16, "swap_16">;
492   def ATOMIC_SWAP_I32      : Atomic2Ops<atomic_swap_32, "swap_32">;
493
494   def ATOMIC_CMP_SWAP_I8   : AtomicCmpSwap<atomic_cmp_swap_8, "8">;
495   def ATOMIC_CMP_SWAP_I16  : AtomicCmpSwap<atomic_cmp_swap_16, "16">;
496   def ATOMIC_CMP_SWAP_I32  : AtomicCmpSwap<atomic_cmp_swap_32, "32">;
497 }
498
499 // Unaligned loads and stores.
500 // Replaces LW or SW during MCInstLowering if memory access is unaligned.
501 def ULW :
502   MipsPseudo<(outs CPURegs:$dst), (ins mem:$addr), "ulw\t$dst, $addr", []>;
503 def ULH :
504   MipsPseudo<(outs CPURegs:$dst), (ins mem:$addr), "ulh\t$dst, $addr", []>;
505 def ULHu :
506   MipsPseudo<(outs CPURegs:$dst), (ins mem:$addr), "ulhu\t$dst, $addr", []>;
507 def USW : 
508   MipsPseudo<(outs), (ins CPURegs:$dst, mem:$addr), "usw\t$dst, $addr", []>;
509 def USH : 
510   MipsPseudo<(outs), (ins CPURegs:$dst, mem:$addr), "ush\t$dst, $addr", []>;
511
512 //===----------------------------------------------------------------------===//
513 // Instruction definition
514 //===----------------------------------------------------------------------===//
515
516 //===----------------------------------------------------------------------===//
517 // MipsI Instructions
518 //===----------------------------------------------------------------------===//
519
520 /// Arithmetic Instructions (ALU Immediate)
521 def ADDiu   : ArithI<0x09, "addiu", add, simm16, immSExt16>;
522 def ADDi    : ArithOverflowI<0x08, "addi",  add, simm16, immSExt16>;
523 def SLTi    : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
524 def SLTiu   : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
525 def ANDi    : LogicI<0x0c, "andi", and>;
526 def ORi     : LogicI<0x0d, "ori",  or>;
527 def XORi    : LogicI<0x0e, "xori",  xor>;
528 def LUi     : LoadUpper<0x0f, "lui">;
529
530 /// Arithmetic Instructions (3-Operand, R-Type)
531 def ADDu    : ArithR<0x00, 0x21, "addu", add, IIAlu, 1>;
532 def SUBu    : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
533 def ADD     : ArithOverflowR<0x00, 0x20, "add", 1>;
534 def SUB     : ArithOverflowR<0x00, 0x22, "sub">;
535 def SLT     : SetCC_R<0x00, 0x2a, "slt", setlt>;
536 def SLTu    : SetCC_R<0x00, 0x2b, "sltu", setult>;
537 def AND     : LogicR<0x24, "and", and>;
538 def OR      : LogicR<0x25, "or",  or>;
539 def XOR     : LogicR<0x26, "xor", xor>;
540 def NOR     : LogicNOR<0x00, 0x27, "nor">;
541
542 /// Shift Instructions
543 def SLL     : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
544 def SRL     : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
545 def SRA     : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
546 def SLLV    : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
547 def SRLV    : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
548 def SRAV    : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
549
550 // Rotate Instructions
551 let Predicates = [IsMips32r2] in {
552     def ROTR    : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
553     def ROTRV   : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
554 }
555
556 /// Load and Store Instructions
557 def LB      : LoadM<0x20, "lb",  sextloadi8>;
558 def LBu     : LoadM<0x24, "lbu", zextloadi8>;
559 def LH      : LoadM<0x21, "lh",  sextloadi16>;
560 def LHu     : LoadM<0x25, "lhu", zextloadi16>;
561 def LW      : LoadM<0x23, "lw",  load>;
562 def SB      : StoreM<0x28, "sb", truncstorei8>;
563 def SH      : StoreM<0x29, "sh", truncstorei16>;
564 def SW      : StoreM<0x2b, "sw", store>;
565
566 let hasSideEffects = 1 in
567 def SYNC : MipsInst<(outs), (ins i32imm:$stype), "sync $stype",
568                     [(MipsSync imm:$stype)], NoItinerary>
569 {
570   let opcode = 0;
571   let Inst{25-11} = 0;
572   let Inst{5-0} = 15;
573 }
574
575 /// Load-linked, Store-conditional
576 let mayLoad = 1, hasDelaySlot = 1 in
577   def LL    : FI<0x30, (outs CPURegs:$dst), (ins mem:$addr),
578               "ll\t$dst, $addr", [], IILoad>;
579 let mayStore = 1, Constraints = "$src = $dst" in
580   def SC    : FI<0x38, (outs CPURegs:$dst), (ins CPURegs:$src, mem:$addr),
581               "sc\t$src, $addr", [], IIStore>;
582
583 /// Jump and Branch Instructions
584 def J       : JumpFJ<0x02, "j">;
585 let isIndirectBranch = 1 in
586   def JR      : JumpFR<0x00, 0x08, "jr">;
587 def JAL     : JumpLink<0x03, "jal">;
588 def JALR    : JumpLinkReg<0x00, 0x09, "jalr">;
589 def BEQ     : CBranch<0x04, "beq", seteq>;
590 def BNE     : CBranch<0x05, "bne", setne>;
591
592 let rt=1 in
593   def BGEZ  : CBranchZero<0x01, "bgez", setge>;
594
595 let rt=0 in {
596   def BGTZ  : CBranchZero<0x07, "bgtz", setgt>;
597   def BLEZ  : CBranchZero<0x07, "blez", setle>;
598   def BLTZ  : CBranchZero<0x01, "bltz", setlt>;
599 }
600
601 def BGEZAL  : BranchLink<"bgezal">;
602 def BLTZAL  : BranchLink<"bltzal">;
603
604 let isReturn=1, isTerminator=1, hasDelaySlot=1,
605     isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
606   def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
607                 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
608
609 /// Multiply and Divide Instructions.
610 def MULT    : Mul<0x18, "mult", IIImul>;
611 def MULTu   : Mul<0x19, "multu", IIImul>;
612 def SDIV    : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
613 def UDIV    : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
614
615 let Defs = [HI] in
616   def MTHI  : MoveToLOHI<0x11, "mthi">;
617 let Defs = [LO] in
618   def MTLO  : MoveToLOHI<0x13, "mtlo">;
619
620 let Uses = [HI] in
621   def MFHI  : MoveFromLOHI<0x10, "mfhi">;
622 let Uses = [LO] in
623   def MFLO  : MoveFromLOHI<0x12, "mflo">;
624
625 /// Sign Ext In Register Instructions.
626 let Predicates = [HasSEInReg] in {
627   let shamt = 0x10, rs = 0 in
628     def SEB : SignExtInReg<0x21, "seb", i8>;
629
630   let shamt = 0x18, rs = 0 in
631     def SEH : SignExtInReg<0x20, "seh", i16>;
632 }
633
634 /// Count Leading
635 def CLZ : CountLeading<0b100000, "clz",
636                        [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
637 def CLO : CountLeading<0b100001, "clo",
638                        [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
639
640 /// Byte Swap
641 let Predicates = [HasSwap] in {
642   let shamt = 0x3, rs = 0 in
643     def WSBW : ByteSwap<0x20, "wsbw">;
644 }
645
646 /// Conditional Move
647 def MIPS_CMOV_ZERO  : PatLeaf<(i32 0)>;
648 def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
649
650 // Conditional moves:
651 // These instructions are expanded in
652 // MipsISelLowering::EmitInstrWithCustomInserter if target does not have
653 // conditional move instructions.
654 // flag:int, data:int
655 let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
656   class CondMovIntInt<bits<6> funct, string instr_asm> :
657     FR<0, funct, (outs CPURegs:$dst),
658        (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
659        !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
660
661 def MOVZ_I : CondMovIntInt<0x0a, "movz">;
662 def MOVN_I : CondMovIntInt<0x0b, "movn">;
663
664 /// No operation
665 let addr=0 in
666   def NOP   : FJ<0, (outs), (ins), "nop", [], IIAlu>;
667
668 // FrameIndexes are legalized when they are operands from load/store
669 // instructions. The same not happens for stack address copies, so an
670 // add op with mem ComplexPattern is used and the stack address copy
671 // can be matched. It's similar to Sparc LEA_ADDRi
672 def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, $addr">;
673
674 // DynAlloc node points to dynamically allocated stack space.
675 // $sp is added to the list of implicitly used registers to prevent dead code
676 // elimination from removing instructions that modify $sp.
677 let Uses = [SP] in
678 def DynAlloc : EffectiveAddress<"addiu\t$dst, $addr">;
679
680 // MADD*/MSUB*
681 def MADD  : MArithR<0, "madd", MipsMAdd, 1>;
682 def MADDU : MArithR<1, "maddu", MipsMAddu, 1>;
683 def MSUB  : MArithR<4, "msub", MipsMSub>;
684 def MSUBU : MArithR<5, "msubu", MipsMSubu>;
685
686 // MUL is a assembly macro in the current used ISAs. In recent ISA's
687 // it is a real instruction.
688 def MUL   : ArithR<0x1c, 0x02, "mul", mul, IIImul, 1>, Requires<[IsMips32]>;
689
690 def RDHWR : ReadHardware;
691
692 let Predicates = [IsMips32r2] in {
693
694 def EXT : ExtIns<0, "ext", (ins CPURegs:$rs, uimm16:$pos, uimm16:$size),
695                  [(set CPURegs:$rt, 
696                    (MipsExt CPURegs:$rs, immZExt5:$pos, immZExt5:$size))],
697                  NoItinerary>;
698
699 let Constraints = "$src = $rt" in
700 def INS : ExtIns<4, "ins",
701                  (ins CPURegs:$rs, uimm16:$pos, uimm16:$size, CPURegs:$src),
702                  [(set CPURegs:$rt, 
703                    (MipsIns CPURegs:$rs, immZExt5:$pos, immZExt5:$size,
704                     CPURegs:$src))],
705                  NoItinerary>;
706 }
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<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
742           (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
743 def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
744           (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
745
746 def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
747 def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
748           (ADDiu CPURegs:$hi, tjumptable:$lo)>;
749
750 def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
751 def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
752           (ADDiu CPURegs:$hi, tconstpool:$lo)>;
753
754 // gp_rel relocs
755 def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
756           (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
757 def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
758           (ADDiu CPURegs:$gp, tconstpool:$in)>;
759
760 // tlsgd
761 def : Pat<(add CPURegs:$gp, (MipsTlsGd tglobaltlsaddr:$in)),
762           (ADDiu CPURegs:$gp, tglobaltlsaddr:$in)>;
763
764 // tprel hi/lo
765 def : Pat<(MipsTprelHi tglobaltlsaddr:$in), (LUi tglobaltlsaddr:$in)>;
766 def : Pat<(add CPURegs:$hi, (MipsTprelLo tglobaltlsaddr:$lo)),
767           (ADDiu CPURegs:$hi, tglobaltlsaddr:$lo)>;
768
769 // wrapper_pic
770 class WrapperPICPat<SDNode node>:
771       Pat<(MipsWrapperPIC node:$in),
772           (ADDiu GP, node:$in)>;
773
774 def : WrapperPICPat<tglobaladdr>;
775 def : WrapperPICPat<tconstpool>;
776 def : WrapperPICPat<texternalsym>;
777 def : WrapperPICPat<tblockaddress>;
778 def : WrapperPICPat<tjumptable>;
779
780 // Mips does not have "not", so we expand our way
781 def : Pat<(not CPURegs:$in),
782           (NOR CPURegs:$in, ZERO)>;
783
784 // extended load and stores
785 def : Pat<(extloadi1  addr:$src), (LBu addr:$src)>;
786 def : Pat<(extloadi8  addr:$src), (LBu addr:$src)>;
787 def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
788
789 // peepholes
790 def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
791
792 // brcond patterns
793 def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
794           (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
795 def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
796           (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
797
798 def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
799           (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
800 def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
801           (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
802 def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
803           (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
804 def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
805           (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
806
807 def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
808           (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
809 def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
810           (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
811
812 def : Pat<(brcond CPURegs:$cond, bb:$dst),
813           (BNE CPURegs:$cond, ZERO, bb:$dst)>;
814
815 // select patterns
816 multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
817   def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
818             (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
819   def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
820             (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
821   def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), RC:$T, RC:$F),
822             (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
823   def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), RC:$T, RC:$F),
824             (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
825   def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
826             (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
827   def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
828             (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
829   def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
830             (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
831   def : Pat<(select (seteq CPURegs:$lhs, 0), RC:$T, RC:$F),
832             (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
833 }
834
835 multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
836   def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
837             (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
838   def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
839             (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
840   def : Pat<(select (setne CPURegs:$lhs, 0), RC:$T, RC:$F),
841             (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
842 }
843
844 defm : MovzPats<CPURegs, MOVZ_I>;
845 defm : MovnPats<CPURegs, MOVN_I>;
846
847 // setcc patterns
848 def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
849           (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
850 def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
851           (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
852
853 def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
854           (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
855 def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
856           (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
857
858 def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
859           (SLT CPURegs:$rhs, CPURegs:$lhs)>;
860 def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
861           (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
862
863 def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
864           (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
865 def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
866           (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
867
868 def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
869           (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
870 def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
871           (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
872
873 // select MipsDynAlloc
874 def : Pat<(MipsDynAlloc addr:$f), (DynAlloc addr:$f)>;
875
876 //===----------------------------------------------------------------------===//
877 // Floating Point Support
878 //===----------------------------------------------------------------------===//
879
880 include "MipsInstrFPU.td"
881