ddf18d88ac7bfa332b22e524133d74b23ac9fe9b
[oota-llvm.git] / lib / Target / Mips / MipsInstrInfo.td
1 //===- MipsInstrInfo.td - Mips Register defs --------------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
11 // Instruction format superclass
12 //===----------------------------------------------------------------------===//
13
14 include "MipsInstrFormats.td"
15
16 //===----------------------------------------------------------------------===//
17 // Mips profiles and nodes
18 //===----------------------------------------------------------------------===//
19
20 def SDT_MipsRet          : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
21 def SDT_MipsJmpLink      : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
22 def SDT_MipsSelectCC     : SDTypeProfile<1, 3, [SDTCisSameAs<0, 2>, 
23                                          SDTCisSameAs<2, 3>, SDTCisInt<1>]>;
24 def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
25 def SDT_MipsCallSeqEnd   : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
26
27 // Call
28 def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink, [SDNPHasChain,
29                          SDNPOutFlag]>;
30
31 // Hi and Lo nodes are used to handle global addresses. Used on 
32 // MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol 
33 // static model. (nothing to do with Mips Registers Hi and Lo)
34 def MipsHi    : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
35 def MipsLo    : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
36 def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
37
38 // Return
39 def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain, 
40                      SDNPOptInFlag]>;
41
42 // These are target-independent nodes, but have target-specific formats.
43 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
44                            [SDNPHasChain, SDNPOutFlag]>;
45 def callseq_end   : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
46                            [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
47
48 // Select Condition Code
49 def MipsSelectCC  : SDNode<"MipsISD::SelectCC", SDT_MipsSelectCC>;
50
51 //===----------------------------------------------------------------------===//
52 // Mips Instruction Predicate Definitions.
53 //===----------------------------------------------------------------------===//
54 def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
55
56 //===----------------------------------------------------------------------===//
57 // Mips Operand, Complex Patterns and Transformations Definitions.
58 //===----------------------------------------------------------------------===//
59
60 // Instruction operand types
61 def brtarget    : Operand<OtherVT>;
62 def calltarget  : Operand<i32>;
63 def uimm16      : Operand<i32>;
64 def simm16      : Operand<i32>;
65 def shamt       : Operand<i32>;
66
67 // Address operand
68 def mem : Operand<i32> {
69   let PrintMethod = "printMemOperand";
70   let MIOperandInfo = (ops simm16, CPURegs);
71 }
72
73 // Transformation Function - get the lower 16 bits.
74 def LO16 : SDNodeXForm<imm, [{
75   return getI32Imm((unsigned)N->getValue() & 0xFFFF);
76 }]>;
77
78 // Transformation Function - get the higher 16 bits.
79 def HI16 : SDNodeXForm<imm, [{
80   return getI32Imm((unsigned)N->getValue() >> 16);
81 }]>;
82
83 // Node immediate fits as 16-bit sign extended on target immediate.
84 // e.g. addi, andi
85 def immSExt16  : PatLeaf<(imm), [{
86   if (N->getValueType(0) == MVT::i32)
87     return (int32_t)N->getValue() == (short)N->getValue();
88   else
89     return (int64_t)N->getValue() == (short)N->getValue();
90 }]>;
91
92 // Node immediate fits as 16-bit zero extended on target immediate.
93 // The LO16 param means that only the lower 16 bits of the node
94 // immediate are caught.
95 // e.g. addiu, sltiu
96 def immZExt16  : PatLeaf<(imm), [{
97   if (N->getValueType(0) == MVT::i32)
98     return (uint32_t)N->getValue() == (unsigned short)N->getValue();
99   else
100     return (uint64_t)N->getValue() == (unsigned short)N->getValue();
101 }], LO16>;
102
103 // shamt field must fit in 5 bits.
104 def immZExt5 : PatLeaf<(imm), [{
105   return N->getValue() == ((N->getValue()) & 0x1f) ;
106 }]>;
107
108 // Mips Address Mode! SDNode frameindex could possibily be a match
109 // since load and store instructions from stack used it.
110 def addr : ComplexPattern<i32, 2, "SelectAddr", [frameindex], []>;
111
112 //===----------------------------------------------------------------------===//
113 // Instructions specific format
114 //===----------------------------------------------------------------------===//
115
116 // Arithmetic 3 register operands
117 let isCommutable = 1 in
118 class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
119              InstrItinClass itin>:
120   FR< op,
121       func,
122       (outs CPURegs:$dst),
123       (ins CPURegs:$b, CPURegs:$c),
124       !strconcat(instr_asm, "\t$dst, $b, $c"),
125       [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
126
127 let isCommutable = 1 in
128 class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
129   FR< op,
130       func,
131       (outs CPURegs:$dst),
132       (ins CPURegs:$b, CPURegs:$c),
133       !strconcat(instr_asm, "\t$dst, $b, $c"),
134       [], IIAlu>;
135
136 // Arithmetic 2 register operands
137 class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
138              Operand Od, PatLeaf imm_type> :
139   FI< op,
140       (outs CPURegs:$dst),
141       (ins CPURegs:$b, Od:$c),
142       !strconcat(instr_asm, "\t$dst, $b, $c"),
143       [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
144
145 // Arithmetic Multiply ADD/SUB
146 let rd=0 in
147 class MArithR<bits<6> func, string instr_asm> :
148   FR< 0x1c,
149       func,
150       (outs CPURegs:$rs),
151       (ins CPURegs:$rt),
152       !strconcat(instr_asm, "\t$rs, $rt"),
153       [], IIImul>;
154
155 //  Logical
156 class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
157   FR< 0x00,
158       func,
159       (outs CPURegs:$dst),
160       (ins CPURegs:$b, CPURegs:$c),
161       !strconcat(instr_asm, "\t$dst, $b, $c"),
162       [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
163
164 class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
165   FI< op,
166       (outs CPURegs:$dst),
167       (ins CPURegs:$b, uimm16:$c),
168       !strconcat(instr_asm, "\t$dst, $b, $c"),
169       [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
170
171 class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
172   FR< op,
173       func,
174       (outs CPURegs:$dst),
175       (ins CPURegs:$b, CPURegs:$c),
176       !strconcat(instr_asm, "\t$dst, $b, $c"),
177       [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
178
179 // Shifts
180 let rt = 0 in
181 class LogicR_shift_imm<bits<6> func, string instr_asm, SDNode OpNode>:
182   FR< 0x00,
183       func,
184       (outs CPURegs:$dst),
185       (ins CPURegs:$b, shamt:$c),
186       !strconcat(instr_asm, "\t$dst, $b, $c"),
187       [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu>;
188
189 class LogicR_shift_reg<bits<6> func, string instr_asm, SDNode OpNode>:
190   FR< 0x00,
191       func,
192       (outs CPURegs:$dst),
193       (ins CPURegs:$b, CPURegs:$c),
194       !strconcat(instr_asm, "\t$dst, $b, $c"),
195       [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
196
197 // Load Upper Imediate
198 class LoadUpper<bits<6> op, string instr_asm>:
199   FI< op,
200       (outs CPURegs:$dst),
201       (ins uimm16:$imm),
202       !strconcat(instr_asm, "\t$dst, $imm"),
203       [], IIAlu>;
204
205 // Memory Load/Store
206 let isSimpleLoad = 1, hasDelaySlot = 1 in
207 class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
208   FI< op,
209       (outs CPURegs:$dst),
210       (ins mem:$addr),
211       !strconcat(instr_asm, "\t$dst, $addr"),
212       [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
213
214 class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
215   FI< op,
216       (outs),
217       (ins CPURegs:$dst, mem:$addr),
218       !strconcat(instr_asm, "\t$dst, $addr"),
219       [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
220
221 // Conditional Branch
222 let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
223 class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
224   FI< op,
225       (outs),
226       (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
227       !strconcat(instr_asm, "\t$a, $b, $offset"),
228       [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
229       IIBranch>;
230
231
232 class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
233   FI< op,
234       (outs),
235       (ins CPURegs:$src, brtarget:$offset),
236       !strconcat(instr_asm, "\t$src, $offset"),
237       [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
238       IIBranch>;
239 }
240
241 // SetCC
242 class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
243       PatFrag cond_op>:
244   FR< op,
245       func,
246       (outs CPURegs:$dst),
247       (ins CPURegs:$b, CPURegs:$c),
248       !strconcat(instr_asm, "\t$dst, $b, $c"),
249       [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
250       IIAlu>;
251
252 class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
253       Operand Od, PatLeaf imm_type>:
254   FI< op,
255       (outs CPURegs:$dst),
256       (ins CPURegs:$b, Od:$c),
257       !strconcat(instr_asm, "\t$dst, $b, $c"),
258       [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
259       IIAlu>;
260
261 // Unconditional branch
262 let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
263 class JumpFJ<bits<6> op, string instr_asm>:
264   FJ< op,
265       (outs),
266       (ins brtarget:$target),
267       !strconcat(instr_asm, "\t$target"),
268       [(br bb:$target)], IIBranch>;
269
270 let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
271 class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
272   FR< op,
273       func,
274       (outs),
275       (ins CPURegs:$target),
276       !strconcat(instr_asm, "\t$target"),
277       [(brind CPURegs:$target)], IIBranch>;
278
279 // Jump and Link (Call)
280 let isCall=1, hasDelaySlot=1,
281   // All calls clobber the non-callee saved registers...
282   Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2,
283           T3, T4, T5, T6, T7, T8, T9, K0, K1], Uses = [GP] in {
284   class JumpLink<bits<6> op, string instr_asm>:
285     FJ< op,
286         (outs),
287         (ins calltarget:$target),
288         !strconcat(instr_asm, "\t$target"),
289         [(MipsJmpLink imm:$target)], IIBranch>;
290
291   let rd=31 in
292   class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
293     FR< op,
294         func,
295         (outs),
296         (ins CPURegs:$rs),
297         !strconcat(instr_asm, "\t$rs"),
298         [(MipsJmpLink CPURegs:$rs)], IIBranch>;
299
300   class BranchLink<string instr_asm>:
301     FI< 0x1,
302         (outs),
303         (ins CPURegs:$rs, brtarget:$target),
304         !strconcat(instr_asm, "\t$rs, $target"),
305         [], IIBranch>;
306 }
307
308 // Mul, Div
309 class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
310   FR< 0x00,
311       func,
312       (outs),
313       (ins CPURegs:$a, CPURegs:$b),
314       !strconcat(instr_asm, "\t$a, $b"),
315       [], itin>;
316
317 // Move from Hi/Lo
318 class MoveFromLOHI<bits<6> func, string instr_asm>:
319   FR< 0x00,
320       func,
321       (outs CPURegs:$dst),
322       (ins),
323       !strconcat(instr_asm, "\t$dst"),
324       [], IIHiLo>;
325
326 class MoveToLOHI<bits<6> func, string instr_asm>:
327   FR< 0x00,
328       func,
329       (outs),
330       (ins CPURegs:$src),
331       !strconcat(instr_asm, "\t$src"),
332       [], IIHiLo>;
333
334 // Count Leading Ones/Zeros in Word
335 class CountLeading<bits<6> func, string instr_asm>:
336   FR< 0x1c,
337       func,
338       (outs CPURegs:$dst),
339       (ins CPURegs:$src),
340       !strconcat(instr_asm, "\t$dst, $src"),
341       [], IIAlu>;
342
343 class EffectiveAddress<string instr_asm> :
344   FI<0x09,
345      (outs CPURegs:$dst),
346      (ins mem:$addr),
347      instr_asm,
348      [(set CPURegs:$dst, addr:$addr)], IIAlu>;
349
350 class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
351   FR< 0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
352       !strconcat(instr_asm, "\t$dst, $src"),
353       [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
354
355
356 //===----------------------------------------------------------------------===//
357 // Pseudo instructions
358 //===----------------------------------------------------------------------===//
359
360 // As stack alignment is always done with addiu, we need a 16-bit immediate
361 let Defs = [SP], Uses = [SP] in {
362 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
363                                   "!ADJCALLSTACKDOWN $amt",
364                                   [(callseq_start imm:$amt)]>;
365 def ADJCALLSTACKUP   : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
366                                   "!ADJCALLSTACKUP $amt1",
367                                   [(callseq_end imm:$amt1, imm:$amt2)]>;
368 }
369
370 // Some assembly macros need to avoid pseudoinstructions and assembler
371 // automatic reodering, we should reorder ourselves.
372 def MACRO     : MipsPseudo<(outs), (ins), ".set\tmacro",     []>;
373 def REORDER   : MipsPseudo<(outs), (ins), ".set\treorder",   []>;
374 def NOMACRO   : MipsPseudo<(outs), (ins), ".set\tnomacro",   []>;
375 def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
376
377 // When handling PIC code the assembler needs .cpload and .cprestore
378 // directives. If the real instructions corresponding these directives
379 // are used, we have the same behavior, but get also a bunch of warnings
380 // from the assembler.
381 def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
382 def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), ".cprestore\t$loc\n", []>;
383
384 // The supported Mips ISAs dont have any instruction close to the SELECT_CC 
385 // operation. The solution is to create a Mips pseudo SELECT_CC instruction
386 // (MipsSelectCC), use LowerSELECT_CC to generate this instruction and finally 
387 // replace it for real supported nodes into EmitInstrWithCustomInserter
388 let usesCustomDAGSchedInserter = 1 in {
389   class PseudoSelCC<RegisterClass RC, string asmstr>: 
390     MipsPseudo<(outs RC:$dst), (ins CPURegs:$CmpRes, RC:$T, RC:$F), asmstr, 
391     [(set RC:$dst, (MipsSelectCC CPURegs:$CmpRes, RC:$T, RC:$F))]>;
392 }
393
394 def Select_CC : PseudoSelCC<CPURegs, "# MipsSelect_CC_i32">;
395
396 //===----------------------------------------------------------------------===//
397 // Instruction definition
398 //===----------------------------------------------------------------------===//
399
400 //===----------------------------------------------------------------------===//
401 // MipsI Instructions
402 //===----------------------------------------------------------------------===//
403
404 /// Arithmetic Instructions (ALU Immediate)
405 def ADDiu   : ArithI<0x09, "addiu", add, uimm16, immZExt16>;
406 def ADDi    : ArithI<0x08, "addi",  add, simm16, immSExt16>;
407 def SLTi    : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
408 def SLTiu   : SetCC_I<0x0b, "sltiu", setult, uimm16, immZExt16>;
409 def ANDi    : LogicI<0x0c, "andi", and>;
410 def ORi     : LogicI<0x0d, "ori",  or>;
411 def XORi    : LogicI<0x0e, "xori",  xor>;
412 def LUi     : LoadUpper<0x0f, "lui">;
413
414 /// Arithmetic Instructions (3-Operand, R-Type)
415 def ADDu    : ArithR<0x00, 0x21, "addu", add, IIAlu>;
416 def SUBu    : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
417 def ADD     : ArithOverflowR<0x00, 0x20, "add">;
418 def SUB     : ArithOverflowR<0x00, 0x22, "sub">;
419 def SLT     : SetCC_R<0x00, 0x2a, "slt", setlt>;
420 def SLTu    : SetCC_R<0x00, 0x2b, "sltu", setult>;
421 def AND     : LogicR<0x24, "and", and>;
422 def OR      : LogicR<0x25, "or",  or>;
423 def XOR     : LogicR<0x26, "xor", xor>;
424 def NOR     : LogicNOR<0x00, 0x27, "nor">;
425
426 /// Shift Instructions
427 def SLL     : LogicR_shift_imm<0x00, "sll", shl>;
428 def SRL     : LogicR_shift_imm<0x02, "srl", srl>;
429 def SRA     : LogicR_shift_imm<0x03, "sra", sra>;
430 def SLLV    : LogicR_shift_reg<0x04, "sllv", shl>;
431 def SRLV    : LogicR_shift_reg<0x06, "srlv", srl>;
432 def SRAV    : LogicR_shift_reg<0x07, "srav", sra>;
433
434 /// Load and Store Instructions
435 def LB      : LoadM<0x20, "lb",  sextloadi8>;
436 def LBu     : LoadM<0x24, "lbu", zextloadi8>;
437 def LH      : LoadM<0x21, "lh",  sextloadi16>;
438 def LHu     : LoadM<0x25, "lhu", zextloadi16>;
439 def LW      : LoadM<0x23, "lw",  load>;
440 def SB      : StoreM<0x28, "sb", truncstorei8>;
441 def SH      : StoreM<0x29, "sh", truncstorei16>;
442 def SW      : StoreM<0x2b, "sw", store>;
443
444 /// Jump and Branch Instructions
445 def J       : JumpFJ<0x02, "j">;
446 def JR      : JumpFR<0x00, 0x08, "jr">;
447 def JAL     : JumpLink<0x03, "jal">;
448 def JALR    : JumpLinkReg<0x00, 0x09, "jalr">;
449 def BEQ     : CBranch<0x04, "beq", seteq>;
450 def BNE     : CBranch<0x05, "bne", setne>;
451
452 let rt=1 in
453   def BGEZ  : CBranchZero<0x01, "bgez", setge>;
454
455 let rt=0 in {
456   def BGTZ  : CBranchZero<0x07, "bgtz", setgt>;
457   def BLEZ  : CBranchZero<0x07, "blez", setle>;
458   def BLTZ  : CBranchZero<0x01, "bltz", setlt>;
459 }
460
461 def BGEZAL  : BranchLink<"bgezal">;
462 def BLTZAL  : BranchLink<"bltzal">;
463
464 let isReturn=1, isTerminator=1, hasDelaySlot=1,
465     isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
466   def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
467                 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
468
469 /// Multiply and Divide Instructions. 
470 let Defs = [HI, LO] in {
471   def MULT    : MulDiv<0x18, "mult", IIImul>;
472   def MULTu   : MulDiv<0x19, "multu", IIImul>;
473   def DIV     : MulDiv<0x1a, "div", IIIdiv>;
474   def DIVu    : MulDiv<0x1b, "divu", IIIdiv>;
475 }
476
477 let Defs = [HI] in
478   def MTHI  : MoveToLOHI<0x11, "mthi">;
479 let Defs = [LO] in
480   def MTLO  : MoveToLOHI<0x13, "mtlo">;
481
482 let Uses = [HI] in
483   def MFHI  : MoveFromLOHI<0x10, "mfhi">;
484 let Uses = [LO] in
485   def MFLO  : MoveFromLOHI<0x12, "mflo">;
486
487 /// Sign Ext In Register Instructions.
488 let Predicates = [HasSEInReg] in {
489   let shamt = 0x10, rs = 0 in 
490     def SEB : SignExtInReg<0x21, "seb", i8>;
491
492   let shamt = 0x18, rs = 0 in 
493     def SEH : SignExtInReg<0x20, "seh", i16>;
494 }
495
496 /// No operation
497 let addr=0 in
498   def NOP   : FJ<0, (outs), (ins), "nop", [], IIAlu>;
499
500 // FrameIndexes are legalized when they are operands from load/store
501 // instructions. The same not happens for stack address copies, so an
502 // add op with mem ComplexPattern is used and the stack address copy
503 // can be matched. It's similar to Sparc LEA_ADDRi
504 def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
505
506 // Count Leading
507 // CLO/CLZ are part of the newer MIPS32(tm) instruction
508 // set and not older Mips I keep this for future use
509 // though. 
510 //def CLO     : CountLeading<0x21, "clo">;
511 //def CLZ     : CountLeading<0x20, "clz">;
512
513 // MADD*/MSUB* are not part of MipsI either.
514 //def MADD    : MArithR<0x00, "madd">;
515 //def MADDU   : MArithR<0x01, "maddu">;
516 //def MSUB    : MArithR<0x04, "msub">;
517 //def MSUBU   : MArithR<0x05, "msubu">;
518
519 // MUL is a assembly macro in the current used ISAs. In recent ISA's
520 // it is a real instruction.
521 //def MUL   : ArithR<0x1c, 0x02, "mul", mul, IIImul>;
522
523 //===----------------------------------------------------------------------===//
524 //  Arbitrary patterns that map to one or more instructions
525 //===----------------------------------------------------------------------===//
526
527 // Small immediates
528 def : Pat<(i32 immSExt16:$in),
529           (ADDiu ZERO, imm:$in)>;
530 def : Pat<(i32 immZExt16:$in),
531           (ORi ZERO, imm:$in)>;
532
533 // Arbitrary immediates
534 def : Pat<(i32 imm:$imm),
535           (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
536
537 // Carry patterns
538 def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
539           (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
540 def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
541           (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
542 def : Pat<(addc  CPURegs:$src, imm:$imm),
543           (ADDiu CPURegs:$src, imm:$imm)>;
544
545 // Call
546 def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
547           (JAL tglobaladdr:$dst)>;
548 def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
549           (JAL texternalsym:$dst)>;
550 def : Pat<(MipsJmpLink CPURegs:$dst),
551           (JALR CPURegs:$dst)>;
552
553 // hi/lo relocs
554 def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
555 def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
556           (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
557
558 def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
559 def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
560           (ADDiu CPURegs:$hi, tjumptable:$lo)>;
561
562 def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
563 def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
564           (ADDiu CPURegs:$hi, tconstpool:$lo)>;
565
566 // gp_rel relocs
567 def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)), 
568           (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
569 def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)), 
570           (ADDiu CPURegs:$gp, tconstpool:$in)>;
571
572 // Mips does not have "not", so we expand our way
573 def : Pat<(not CPURegs:$in),
574           (NOR CPURegs:$in, ZERO)>;
575
576 // extended load and stores
577 def : Pat<(i32 (extloadi1  addr:$src)), (LBu addr:$src)>;
578 def : Pat<(i32 (extloadi8  addr:$src)), (LBu addr:$src)>;
579 def : Pat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
580
581 // peepholes
582 def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
583
584 // brcond patterns
585 // direct match equal/notequal zero branches
586 def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
587           (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
588 def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
589           (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
590
591 def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
592           (BGEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
593 def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
594           (BGEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
595
596 def : Pat<(brcond (setgt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
597           (BGTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
598 def : Pat<(brcond (setugt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
599           (BGTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
600
601 def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
602           (BLEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
603 def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
604           (BLEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
605
606 def : Pat<(brcond (setlt CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
607           (BNE (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
608 def : Pat<(brcond (setult CPURegs:$lhs, immZExt16:$rhs), bb:$dst),
609           (BNE (SLTiu CPURegs:$lhs, immZExt16:$rhs), ZERO, bb:$dst)>;
610 def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
611           (BNE (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
612 def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
613           (BNE (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
614
615 def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
616           (BLTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
617 def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
618           (BLTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
619
620 // generic brcond pattern
621 def : Pat<(brcond CPURegs:$cond, bb:$dst),
622           (BNE CPURegs:$cond, ZERO, bb:$dst)>;
623
624 // setcc patterns, only matched when there
625 // is no brcond following a setcc operation
626 def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
627           (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
628 def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
629           (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
630
631 def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
632           (SLT CPURegs:$rhs, CPURegs:$lhs)>;
633 def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
634           (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
635
636 def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
637           (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
638 def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
639           (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
640
641 def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
642           (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
643               (SLT CPURegs:$rhs, CPURegs:$lhs))>;
644
645 def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
646           (XORi (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
647                     (SLT CPURegs:$rhs, CPURegs:$lhs)), 1)>;
648
649 def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
650           (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
651 def : Pat<(setuge CPURegs:$lhs, immZExt16:$rhs),
652           (XORi (SLTiu CPURegs:$lhs, immZExt16:$rhs), 1)>;
653
654 //===----------------------------------------------------------------------===//
655 // Floating Point Support
656 //===----------------------------------------------------------------------===//
657
658 include "MipsInstrFPU.td"
659