1 //===- MipsInstrInfo.td - Mips Register defs ---------------*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 //===----------------------------------------------------------------------===//
11 // Instruction format superclass
12 //===----------------------------------------------------------------------===//
14 include "MipsInstrFormats.td"
16 //===----------------------------------------------------------------------===//
17 // Mips profiles and nodes
18 //===----------------------------------------------------------------------===//
20 def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
21 def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
22 def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
23 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>,
25 def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
26 def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
27 def SDT_MipsMAddMSub : SDTypeProfile<0, 4,
28 [SDTCisVT<0, i32>, SDTCisSameAs<0, 1>,
31 def SDT_MipsDivRem : SDTypeProfile<0, 2,
36 def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
37 [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue,
40 // Hi and Lo nodes are used to handle global addresses. Used on
41 // MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
42 // static model. (nothing to do with Mips Registers Hi and Lo)
43 def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
44 def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
45 def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
48 def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
51 // These are target-independent nodes, but have target-specific formats.
52 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
53 [SDNPHasChain, SDNPOutGlue]>;
54 def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
55 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
58 def MipsMAdd : SDNode<"MipsISD::MAdd", SDT_MipsMAddMSub,
59 [SDNPOptInGlue, SDNPOutGlue]>;
60 def MipsMAddu : SDNode<"MipsISD::MAddu", SDT_MipsMAddMSub,
61 [SDNPOptInGlue, SDNPOutGlue]>;
62 def MipsMSub : SDNode<"MipsISD::MSub", SDT_MipsMAddMSub,
63 [SDNPOptInGlue, SDNPOutGlue]>;
64 def MipsMSubu : SDNode<"MipsISD::MSubu", SDT_MipsMAddMSub,
65 [SDNPOptInGlue, SDNPOutGlue]>;
68 def MipsDivRem : SDNode<"MipsISD::DivRem", SDT_MipsDivRem,
70 def MipsDivRemU : SDNode<"MipsISD::DivRemU", SDT_MipsDivRem,
73 //===----------------------------------------------------------------------===//
74 // Mips Instruction Predicate Definitions.
75 //===----------------------------------------------------------------------===//
76 def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
77 def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
78 def HasSwap : Predicate<"Subtarget.hasSwap()">;
79 def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
80 def IsMips32 : Predicate<"Subtarget.isMips32()">;
81 def IsMips32r2 : Predicate<"Subtarget.isMips32r2()">;
83 //===----------------------------------------------------------------------===//
84 // Mips Operand, Complex Patterns and Transformations Definitions.
85 //===----------------------------------------------------------------------===//
87 // Instruction operand types
88 def brtarget : Operand<OtherVT>;
89 def calltarget : Operand<i32>;
90 def simm16 : Operand<i32>;
91 def shamt : Operand<i32>;
94 def uimm16 : Operand<i32> {
95 let PrintMethod = "printUnsignedImm";
99 def mem : Operand<i32> {
100 let PrintMethod = "printMemOperand";
101 let MIOperandInfo = (ops simm16, CPURegs);
104 // Transformation Function - get the lower 16 bits.
105 def LO16 : SDNodeXForm<imm, [{
106 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
109 // Transformation Function - get the higher 16 bits.
110 def HI16 : SDNodeXForm<imm, [{
111 return getI32Imm((unsigned)N->getZExtValue() >> 16);
114 // Node immediate fits as 16-bit sign extended on target immediate.
116 def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
118 // Node immediate fits as 16-bit zero extended on target immediate.
119 // The LO16 param means that only the lower 16 bits of the node
120 // immediate are caught.
122 def immZExt16 : PatLeaf<(imm), [{
123 if (N->getValueType(0) == MVT::i32)
124 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
126 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
129 // shamt field must fit in 5 bits.
130 def immZExt5 : PatLeaf<(imm), [{
131 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
134 // Mips Address Mode! SDNode frameindex could possibily be a match
135 // since load and store instructions from stack used it.
136 def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
138 //===----------------------------------------------------------------------===//
139 // Instructions specific format
140 //===----------------------------------------------------------------------===//
142 // Arithmetic 3 register operands
143 let isCommutable = 1 in
144 class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
145 InstrItinClass itin>:
146 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
147 !strconcat(instr_asm, "\t$dst, $b, $c"),
148 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
150 let isCommutable = 1 in
151 class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
152 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
153 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
155 // Arithmetic 2 register operands
156 class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
157 Operand Od, PatLeaf imm_type> :
158 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
159 !strconcat(instr_asm, "\t$dst, $b, $c"),
160 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
162 class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
163 Operand Od, PatLeaf imm_type> :
164 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
165 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
167 // Arithmetic Multiply ADD/SUB
168 let rd = 0, shamt = 0, Defs = [HI, LO], Uses = [HI, LO] in
169 class MArithR<bits<6> func, string instr_asm, SDNode op> :
170 FR<0x1c, func, (outs), (ins CPURegs:$rs, CPURegs:$rt),
171 !strconcat(instr_asm, "\t$rs, $rt"),
172 [(op CPURegs:$rs, CPURegs:$rt, LO, HI)], IIImul>;
175 class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
176 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
177 !strconcat(instr_asm, "\t$dst, $b, $c"),
178 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
180 class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
181 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
182 !strconcat(instr_asm, "\t$dst, $b, $c"),
183 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
185 class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
186 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
187 !strconcat(instr_asm, "\t$dst, $b, $c"),
188 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
191 class LogicR_shift_rotate_imm<bits<6> func, bits<5> _rs, string instr_asm,
193 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
194 !strconcat(instr_asm, "\t$dst, $b, $c"),
195 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu> {
199 class LogicR_shift_rotate_reg<bits<6> func, bits<5> _shamt, string instr_asm,
201 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$c, CPURegs:$b),
202 !strconcat(instr_asm, "\t$dst, $b, $c"),
203 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu> {
207 // Load Upper Imediate
208 class LoadUpper<bits<6> op, string instr_asm>:
212 !strconcat(instr_asm, "\t$dst, $imm"),
216 let canFoldAsLoad = 1, hasDelaySlot = 1 in
217 class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
218 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
219 !strconcat(instr_asm, "\t$dst, $addr"),
220 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
222 class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
223 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
224 !strconcat(instr_asm, "\t$dst, $addr"),
225 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
227 // Conditional Branch
228 let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
229 class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
230 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
231 !strconcat(instr_asm, "\t$a, $b, $offset"),
232 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
235 class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
236 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
237 !strconcat(instr_asm, "\t$src, $offset"),
238 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
243 class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
245 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
246 !strconcat(instr_asm, "\t$dst, $b, $c"),
247 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
250 class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
251 Operand Od, PatLeaf imm_type>:
252 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
253 !strconcat(instr_asm, "\t$dst, $b, $c"),
254 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
257 // Unconditional branch
258 let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
259 class JumpFJ<bits<6> op, string instr_asm>:
260 FJ<op, (outs), (ins brtarget:$target),
261 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
263 let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
264 class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
265 FR<op, func, (outs), (ins CPURegs:$target),
266 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
268 // Jump and Link (Call)
269 let isCall=1, hasDelaySlot=1,
270 // All calls clobber the non-callee saved registers...
271 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
272 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
273 class JumpLink<bits<6> op, string instr_asm>:
274 FJ<op, (outs), (ins calltarget:$target, variable_ops),
275 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
279 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
280 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
281 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
283 class BranchLink<string instr_asm>:
284 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
285 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
289 let Defs = [HI, LO] in {
290 class Mul<bits<6> func, string instr_asm, InstrItinClass itin>:
291 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
292 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
294 class Div<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
295 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
296 !strconcat(instr_asm, "\t$$zero, $a, $b"),
297 [(op CPURegs:$a, CPURegs:$b)], itin>;
301 class MoveFromLOHI<bits<6> func, string instr_asm>:
302 FR<0x00, func, (outs CPURegs:$dst), (ins),
303 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
305 class MoveToLOHI<bits<6> func, string instr_asm>:
306 FR<0x00, func, (outs), (ins CPURegs:$src),
307 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
309 class EffectiveAddress<string instr_asm> :
310 FI<0x09, (outs CPURegs:$dst), (ins mem:$addr),
311 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
313 // Count Leading Ones/Zeros in Word
314 class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
315 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
316 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
317 Requires<[HasBitCount]> {
322 // Sign Extend in Register.
323 class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
324 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
325 !strconcat(instr_asm, "\t$dst, $src"),
326 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
329 class ByteSwap<bits<6> func, string instr_asm>:
330 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
331 !strconcat(instr_asm, "\t$dst, $src"),
332 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
335 class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
336 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
337 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
340 //===----------------------------------------------------------------------===//
341 // Pseudo instructions
342 //===----------------------------------------------------------------------===//
344 // As stack alignment is always done with addiu, we need a 16-bit immediate
345 let Defs = [SP], Uses = [SP] in {
346 def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
347 "!ADJCALLSTACKDOWN $amt",
348 [(callseq_start timm:$amt)]>;
349 def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
350 "!ADJCALLSTACKUP $amt1",
351 [(callseq_end timm:$amt1, timm:$amt2)]>;
354 // Some assembly macros need to avoid pseudoinstructions and assembler
355 // automatic reodering, we should reorder ourselves.
356 def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
357 def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
358 def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
359 def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
361 // These macros are inserted to prevent GAS from complaining
362 // when using the AT register.
363 def NOAT : MipsPseudo<(outs), (ins), ".set\tnoat", []>;
364 def ATMACRO : MipsPseudo<(outs), (ins), ".set\tat", []>;
366 // When handling PIC code the assembler needs .cpload and .cprestore
367 // directives. If the real instructions corresponding these directives
368 // are used, we have the same behavior, but get also a bunch of warnings
369 // from the assembler.
370 def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
371 def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), ".cprestore\t$loc\n", []>;
373 //===----------------------------------------------------------------------===//
374 // Instruction definition
375 //===----------------------------------------------------------------------===//
377 //===----------------------------------------------------------------------===//
378 // MipsI Instructions
379 //===----------------------------------------------------------------------===//
381 /// Arithmetic Instructions (ALU Immediate)
382 def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
383 def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
384 def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
385 def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
386 def ANDi : LogicI<0x0c, "andi", and>;
387 def ORi : LogicI<0x0d, "ori", or>;
388 def XORi : LogicI<0x0e, "xori", xor>;
389 def LUi : LoadUpper<0x0f, "lui">;
391 /// Arithmetic Instructions (3-Operand, R-Type)
392 def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
393 def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
394 def ADD : ArithOverflowR<0x00, 0x20, "add">;
395 def SUB : ArithOverflowR<0x00, 0x22, "sub">;
396 def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
397 def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
398 def AND : LogicR<0x24, "and", and>;
399 def OR : LogicR<0x25, "or", or>;
400 def XOR : LogicR<0x26, "xor", xor>;
401 def NOR : LogicNOR<0x00, 0x27, "nor">;
403 /// Shift Instructions
404 def SLL : LogicR_shift_rotate_imm<0x00, 0x00, "sll", shl>;
405 def SRL : LogicR_shift_rotate_imm<0x02, 0x00, "srl", srl>;
406 def SRA : LogicR_shift_rotate_imm<0x03, 0x00, "sra", sra>;
407 def SLLV : LogicR_shift_rotate_reg<0x04, 0x00, "sllv", shl>;
408 def SRLV : LogicR_shift_rotate_reg<0x06, 0x00, "srlv", srl>;
409 def SRAV : LogicR_shift_rotate_reg<0x07, 0x00, "srav", sra>;
411 // Rotate Instructions
412 let Predicates = [IsMips32r2] in {
413 def ROTR : LogicR_shift_rotate_imm<0x02, 0x01, "rotr", rotr>;
414 def ROTRV : LogicR_shift_rotate_reg<0x06, 0x01, "rotrv", rotr>;
417 /// Load and Store Instructions
418 def LB : LoadM<0x20, "lb", sextloadi8>;
419 def LBu : LoadM<0x24, "lbu", zextloadi8>;
420 def LH : LoadM<0x21, "lh", sextloadi16>;
421 def LHu : LoadM<0x25, "lhu", zextloadi16>;
422 def LW : LoadM<0x23, "lw", load>;
423 def SB : StoreM<0x28, "sb", truncstorei8>;
424 def SH : StoreM<0x29, "sh", truncstorei16>;
425 def SW : StoreM<0x2b, "sw", store>;
427 /// Jump and Branch Instructions
428 def J : JumpFJ<0x02, "j">;
429 def JR : JumpFR<0x00, 0x08, "jr">;
430 def JAL : JumpLink<0x03, "jal">;
431 def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
432 def BEQ : CBranch<0x04, "beq", seteq>;
433 def BNE : CBranch<0x05, "bne", setne>;
436 def BGEZ : CBranchZero<0x01, "bgez", setge>;
439 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
440 def BLEZ : CBranchZero<0x07, "blez", setle>;
441 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
444 def BGEZAL : BranchLink<"bgezal">;
445 def BLTZAL : BranchLink<"bltzal">;
447 let isReturn=1, isTerminator=1, hasDelaySlot=1,
448 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
449 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
450 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
452 /// Multiply and Divide Instructions.
453 def MULT : Mul<0x18, "mult", IIImul>;
454 def MULTu : Mul<0x19, "multu", IIImul>;
455 def SDIV : Div<MipsDivRem, 0x1a, "div", IIIdiv>;
456 def UDIV : Div<MipsDivRemU, 0x1b, "divu", IIIdiv>;
459 def MTHI : MoveToLOHI<0x11, "mthi">;
461 def MTLO : MoveToLOHI<0x13, "mtlo">;
464 def MFHI : MoveFromLOHI<0x10, "mfhi">;
466 def MFLO : MoveFromLOHI<0x12, "mflo">;
468 /// Sign Ext In Register Instructions.
469 let Predicates = [HasSEInReg] in {
470 let shamt = 0x10, rs = 0 in
471 def SEB : SignExtInReg<0x21, "seb", i8>;
473 let shamt = 0x18, rs = 0 in
474 def SEH : SignExtInReg<0x20, "seh", i16>;
478 def CLZ : CountLeading<0b100000, "clz",
479 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
480 def CLO : CountLeading<0b100001, "clo",
481 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
484 let Predicates = [HasSwap] in {
485 let shamt = 0x3, rs = 0 in
486 def WSBW : ByteSwap<0x20, "wsbw">;
490 def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
491 def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
493 // Conditional moves:
494 // These instructions are expanded in MipsISelLowering::EmitInstrWithCustomInserter
495 // if target does not have conditional move instructions.
496 // flag:int, data:int
497 let usesCustomInserter = 1, shamt = 0, Constraints = "$F = $dst" in
498 class CondMovIntInt<bits<6> funct, string instr_asm> :
499 FR<0, funct, (outs CPURegs:$dst),
500 (ins CPURegs:$T, CPURegs:$cond, CPURegs:$F),
501 !strconcat(instr_asm, "\t$dst, $T, $cond"), [], NoItinerary>;
503 def MOVZ_I : CondMovIntInt<0x0a, "movz">;
504 def MOVN_I : CondMovIntInt<0x0b, "movn">;
508 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
510 // FrameIndexes are legalized when they are operands from load/store
511 // instructions. The same not happens for stack address copies, so an
512 // add op with mem ComplexPattern is used and the stack address copy
513 // can be matched. It's similar to Sparc LEA_ADDRi
514 def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
517 def MADD : MArithR<0, "madd", MipsMAdd>;
518 def MADDU : MArithR<1, "maddu", MipsMAddu>;
519 def MSUB : MArithR<4, "msub", MipsMSub>;
520 def MSUBU : MArithR<5, "msubu", MipsMSubu>;
522 // MUL is a assembly macro in the current used ISAs. In recent ISA's
523 // it is a real instruction.
524 def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>, Requires<[IsMips32]>;
526 //===----------------------------------------------------------------------===//
527 // Arbitrary patterns that map to one or more instructions
528 //===----------------------------------------------------------------------===//
531 def : Pat<(i32 immSExt16:$in),
532 (ADDiu ZERO, imm:$in)>;
533 def : Pat<(i32 immZExt16:$in),
534 (ORi ZERO, imm:$in)>;
536 // Arbitrary immediates
537 def : Pat<(i32 imm:$imm),
538 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
541 def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
542 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
543 def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
544 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
545 def : Pat<(addc CPURegs:$src, immSExt16:$imm),
546 (ADDiu CPURegs:$src, imm:$imm)>;
549 def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
550 (JAL tglobaladdr:$dst)>;
551 def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
552 (JAL texternalsym:$dst)>;
553 //def : Pat<(MipsJmpLink CPURegs:$dst),
554 // (JALR CPURegs:$dst)>;
557 def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
558 def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
559 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
560 def : Pat<(add CPURegs:$hi, (MipsLo tblockaddress:$lo)),
561 (ADDiu CPURegs:$hi, tblockaddress:$lo)>;
563 def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
564 def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
565 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
567 def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
568 def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
569 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
572 def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
573 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
574 def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
575 (ADDiu CPURegs:$gp, tconstpool:$in)>;
577 // Mips does not have "not", so we expand our way
578 def : Pat<(not CPURegs:$in),
579 (NOR CPURegs:$in, ZERO)>;
581 // extended load and stores
582 def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
583 def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
584 def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
587 def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
590 def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
591 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
592 def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
593 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
595 def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
596 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
597 def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
598 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
599 def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
600 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
601 def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
602 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
604 def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
605 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
606 def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
607 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
609 def : Pat<(brcond CPURegs:$cond, bb:$dst),
610 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
613 multiclass MovzPats<RegisterClass RC, Instruction MOVZInst> {
614 def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
615 (MOVZInst RC:$T, (SLT CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
616 def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
617 (MOVZInst RC:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
618 def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), RC:$T, RC:$F),
619 (MOVZInst RC:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs), RC:$F)>;
620 def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), RC:$T, RC:$F),
621 (MOVZInst RC:$T, (SLTiu CPURegs:$lh, immSExt16:$rh), RC:$F)>;
622 def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
623 (MOVZInst RC:$T, (SLT CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
624 def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
625 (MOVZInst RC:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs), RC:$F)>;
626 def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
627 (MOVZInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
628 def : Pat<(select (seteq CPURegs:$lhs, 0), RC:$T, RC:$F),
629 (MOVZInst RC:$T, CPURegs:$lhs, RC:$F)>;
632 multiclass MovnPats<RegisterClass RC, Instruction MOVNInst> {
633 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), RC:$T, RC:$F),
634 (MOVNInst RC:$T, (XOR CPURegs:$lhs, CPURegs:$rhs), RC:$F)>;
635 def : Pat<(select CPURegs:$cond, RC:$T, RC:$F),
636 (MOVNInst RC:$T, CPURegs:$cond, RC:$F)>;
637 def : Pat<(select (setne CPURegs:$lhs, 0), RC:$T, RC:$F),
638 (MOVNInst RC:$T, CPURegs:$lhs, RC:$F)>;
641 defm : MovzPats<CPURegs, MOVZ_I>;
642 defm : MovnPats<CPURegs, MOVN_I>;
644 // select patterns with got access
645 let AddedComplexity = 10 in
646 def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs),
647 (i32 tglobaladdr:$T), CPURegs:$F),
648 (MOVN_I CPURegs:$F, (ADDiu GP, tglobaladdr:$T),
649 (XOR CPURegs:$lhs, CPURegs:$rhs))>;
652 def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
653 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
654 def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
655 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
657 def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
658 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
659 def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
660 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
662 def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
663 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
664 def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
665 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
667 def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
668 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
669 def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
670 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
672 def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
673 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
674 def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
675 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
677 //===----------------------------------------------------------------------===//
678 // Floating Point Support
679 //===----------------------------------------------------------------------===//
681 include "MipsInstrFPU.td"