blob: d4116c431f85100305b37580e3e2f16559b97680 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- MipsInstrInfo.td - Mips Register defs --------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9
10//===----------------------------------------------------------------------===//
11// Instruction format superclass
12//===----------------------------------------------------------------------===//
13
14include "MipsInstrFormats.td"
15
16//===----------------------------------------------------------------------===//
17// Mips profiles and nodes
18//===----------------------------------------------------------------------===//
19
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000020def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
21def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
Bruno Cardoso Lopesda54c7d2008-07-29 19:05:28 +000022def SDT_MipsSelectCC : SDTypeProfile<1, 3, [SDTCisSameAs<0, 2>,
23 SDTCisSameAs<2, 3>, SDTCisInt<1>]>;
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000024def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
25def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
26
Dan Gohmanf17a25c2007-07-18 16:29:46 +000027// Call
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000028def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink, [SDNPHasChain,
29 SDNPOutFlag]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +000031// 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)
Bruno Cardoso Lopes12355a82008-07-21 18:52:34 +000034def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
35def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
36def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000037
Eric Christopher7300ac12007-10-26 04:00:13 +000038// Return
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000039def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
40 SDNPOptInFlag]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041
42// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000043def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
44 [SDNPHasChain, SDNPOutFlag]>;
45def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
46 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
Bill Wendling22f8deb2007-11-13 00:44:25 +000047
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +000048// Select Condition Code
49def MipsSelectCC : SDNode<"MipsISD::SelectCC", SDT_MipsSelectCC>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +000050
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000051//===----------------------------------------------------------------------===//
52// Mips Instruction Predicate Definitions.
53//===----------------------------------------------------------------------===//
Bruno Cardoso Lopesdfd657f2008-07-09 05:32:22 +000054def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +000055
56//===----------------------------------------------------------------------===//
57// Mips Operand, Complex Patterns and Transformations Definitions.
58//===----------------------------------------------------------------------===//
59
Dan Gohmanf17a25c2007-07-18 16:29:46 +000060// Instruction operand types
61def brtarget : Operand<OtherVT>;
62def calltarget : Operand<i32>;
63def uimm16 : Operand<i32>;
64def simm16 : Operand<i32>;
Eric Christopher7300ac12007-10-26 04:00:13 +000065def shamt : Operand<i32>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000066
67// Address operand
68def mem : Operand<i32> {
69 let PrintMethod = "printMemOperand";
70 let MIOperandInfo = (ops simm16, CPURegs);
71}
72
Dan Gohmanf17a25c2007-07-18 16:29:46 +000073// Transformation Function - get the lower 16 bits.
74def LO16 : SDNodeXForm<imm, [{
75 return getI32Imm((unsigned)N->getValue() & 0xFFFF);
76}]>;
77
78// Transformation Function - get the higher 16 bits.
79def 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
85def immSExt16 : PatLeaf<(imm), [{
86 if (N->getValueType(0) == MVT::i32)
87 return (int32_t)N->getValue() == (short)N->getValue();
Eric Christopher7300ac12007-10-26 04:00:13 +000088 else
Dan Gohmanf17a25c2007-07-18 16:29:46 +000089 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
96def immZExt16 : PatLeaf<(imm), [{
97 if (N->getValueType(0) == MVT::i32)
98 return (uint32_t)N->getValue() == (unsigned short)N->getValue();
Eric Christopher7300ac12007-10-26 04:00:13 +000099 else
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000100 return (uint64_t)N->getValue() == (unsigned short)N->getValue();
101}], LO16>;
102
103// shamt field must fit in 5 bits.
104def immZExt5 : PatLeaf<(imm), [{
105 return N->getValue() == ((N->getValue()) & 0x1f) ;
106}]>;
107
Eric Christopher7300ac12007-10-26 04:00:13 +0000108// Mips Address Mode! SDNode frameindex could possibily be a match
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000109// since load and store instructions from stack used it.
110def addr : ComplexPattern<i32, 2, "SelectAddr", [frameindex], []>;
111
112//===----------------------------------------------------------------------===//
113// Instructions specific format
114//===----------------------------------------------------------------------===//
115
116// Arithmetic 3 register operands
Eric Christopher7300ac12007-10-26 04:00:13 +0000117let isCommutable = 1 in
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000118class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Eric Christopher7300ac12007-10-26 04:00:13 +0000119 InstrItinClass itin>:
120 FR< op,
121 func,
122 (outs CPURegs:$dst),
123 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000124 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000125 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000126
Eric Christopher7300ac12007-10-26 04:00:13 +0000127let isCommutable = 1 in
128class 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),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000133 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000134 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000135
136// Arithmetic 2 register operands
Eric Christopher7300ac12007-10-26 04:00:13 +0000137class 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),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000142 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000143 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000144
145// Arithmetic Multiply ADD/SUB
146let rd=0 in
Eric Christopher7300ac12007-10-26 04:00:13 +0000147class MArithR<bits<6> func, string instr_asm> :
148 FR< 0x1c,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000149 func,
Eric Christopher7300ac12007-10-26 04:00:13 +0000150 (outs CPURegs:$rs),
151 (ins CPURegs:$rt),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000152 !strconcat(instr_asm, "\t$rs, $rt"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000153 [], IIImul>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000154
155// Logical
156class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000157 FR< 0x00,
158 func,
159 (outs CPURegs:$dst),
160 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000161 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000162 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000163
164class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
165 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000166 (outs CPURegs:$dst),
167 (ins CPURegs:$b, uimm16:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000168 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopesf2377552008-06-06 06:37:31 +0000169 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000170
171class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000172 FR< op,
173 func,
174 (outs CPURegs:$dst),
175 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000176 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000177 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000178
179// Shifts
180let rt = 0 in
181class LogicR_shift_imm<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000182 FR< 0x00,
183 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000184 (outs CPURegs:$dst),
185 (ins CPURegs:$b, shamt:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000186 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000187 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000188
189class LogicR_shift_reg<bits<6> func, string instr_asm, SDNode OpNode>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000190 FR< 0x00,
191 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000192 (outs CPURegs:$dst),
193 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000194 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000195 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000196
197// Load Upper Imediate
198class LoadUpper<bits<6> op, string instr_asm>:
199 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000200 (outs CPURegs:$dst),
201 (ins uimm16:$imm),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000202 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000203 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000204
Eric Christopher7300ac12007-10-26 04:00:13 +0000205// Memory Load/Store
Chris Lattner1a1932c2008-01-06 23:38:27 +0000206let isSimpleLoad = 1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000207class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
208 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000209 (outs CPURegs:$dst),
210 (ins mem:$addr),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000211 !strconcat(instr_asm, "\t$dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000212 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000213
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000214class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
215 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000216 (outs),
217 (ins CPURegs:$dst, mem:$addr),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000218 !strconcat(instr_asm, "\t$dst, $addr"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000219 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000220
221// Conditional Branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000222let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000223class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
224 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000225 (outs),
226 (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000227 !strconcat(instr_asm, "\t$a, $b, $offset"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000228 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
229 IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000230
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000231
232class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
233 FI< op,
234 (outs),
235 (ins CPURegs:$src, brtarget:$offset),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000236 !strconcat(instr_asm, "\t$src, $offset"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000237 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
238 IIBranch>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000239}
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000240
Eric Christopher7300ac12007-10-26 04:00:13 +0000241// SetCC
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000242class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
243 PatFrag cond_op>:
244 FR< op,
245 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000246 (outs CPURegs:$dst),
247 (ins CPURegs:$b, CPURegs:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000248 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000249 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
250 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000251
252class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
253 Operand Od, PatLeaf imm_type>:
254 FI< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000255 (outs CPURegs:$dst),
256 (ins CPURegs:$b, Od:$c),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000257 !strconcat(instr_asm, "\t$dst, $b, $c"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000258 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
259 IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000260
261// Unconditional branch
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000262let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000263class JumpFJ<bits<6> op, string instr_asm>:
264 FJ< op,
Evan Chengb783fa32007-07-19 01:14:50 +0000265 (outs),
266 (ins brtarget:$target),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000267 !strconcat(instr_asm, "\t$target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000268 [(br bb:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000270let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000271class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
272 FR< op,
273 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000274 (outs),
275 (ins CPURegs:$target),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000276 !strconcat(instr_asm, "\t$target"),
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000277 [(brind CPURegs:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000278
279// Jump and Link (Call)
Eric Christopher7300ac12007-10-26 04:00:13 +0000280let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000281 // All calls clobber the non-callee saved registers...
Bruno Cardoso Lopesf046f872008-08-06 06:14:43 +0000282 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
283 K0, K1, F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13,
284 F14, F15, F16, F17, F18, F19], Uses = [GP] in {
Eric Christopher7300ac12007-10-26 04:00:13 +0000285 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000286 FJ< op,
287 (outs),
288 (ins calltarget:$target),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000289 !strconcat(instr_asm, "\t$target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000290 [(MipsJmpLink imm:$target)], IIBranch>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000291
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000292 let rd=31 in
293 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
294 FR< op,
295 func,
296 (outs),
297 (ins CPURegs:$rs),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000298 !strconcat(instr_asm, "\t$rs"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000299 [(MipsJmpLink CPURegs:$rs)], IIBranch>;
300
301 class BranchLink<string instr_asm>:
302 FI< 0x1,
303 (outs),
304 (ins CPURegs:$rs, brtarget:$target),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000305 !strconcat(instr_asm, "\t$rs, $target"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000306 [], IIBranch>;
307}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000308
Eric Christopher7300ac12007-10-26 04:00:13 +0000309// Mul, Div
310class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
311 FR< 0x00,
312 func,
Evan Chengb783fa32007-07-19 01:14:50 +0000313 (outs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000314 (ins CPURegs:$a, CPURegs:$b),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000315 !strconcat(instr_asm, "\t$a, $b"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000316 [], itin>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000317
Eric Christopher7300ac12007-10-26 04:00:13 +0000318// Move from Hi/Lo
Bruno Cardoso Lopes4f0bb3c2008-08-02 19:42:36 +0000319class MoveFromLOHI<bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000320 FR< 0x00,
321 func,
322 (outs CPURegs:$dst),
Evan Chengb783fa32007-07-19 01:14:50 +0000323 (ins),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000324 !strconcat(instr_asm, "\t$dst"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000325 [], IIHiLo>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000326
Bruno Cardoso Lopes4f0bb3c2008-08-02 19:42:36 +0000327class MoveToLOHI<bits<6> func, string instr_asm>:
328 FR< 0x00,
329 func,
330 (outs),
331 (ins CPURegs:$src),
332 !strconcat(instr_asm, "\t$src"),
333 [], IIHiLo>;
334
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000335// Count Leading Ones/Zeros in Word
336class CountLeading<bits<6> func, string instr_asm>:
Eric Christopher7300ac12007-10-26 04:00:13 +0000337 FR< 0x1c,
338 func,
339 (outs CPURegs:$dst),
340 (ins CPURegs:$src),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000341 !strconcat(instr_asm, "\t$dst, $src"),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000342 [], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000343
Eric Christopher7300ac12007-10-26 04:00:13 +0000344class EffectiveAddress<string instr_asm> :
345 FI<0x09,
346 (outs CPURegs:$dst),
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000347 (ins mem:$addr),
348 instr_asm,
349 [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000350
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000351class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
352 FR< 0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000353 !strconcat(instr_asm, "\t$dst, $src"),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000354 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
355
356
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000357//===----------------------------------------------------------------------===//
358// Pseudo instructions
359//===----------------------------------------------------------------------===//
360
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000361// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000362let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000363def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000364 "!ADJCALLSTACKDOWN $amt",
365 [(callseq_start imm:$amt)]>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000366def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000367 "!ADJCALLSTACKUP $amt1",
368 [(callseq_end imm:$amt1, imm:$amt2)]>;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000369}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000370
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000371// Some assembly macros need to avoid pseudoinstructions and assembler
372// automatic reodering, we should reorder ourselves.
373def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
374def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
375def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
376def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
377
Eric Christopher7300ac12007-10-26 04:00:13 +0000378// When handling PIC code the assembler needs .cpload and .cprestore
379// directives. If the real instructions corresponding these directives
380// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopes2cacce92007-10-09 02:55:31 +0000381// from the assembler.
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000382def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
383def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000384
385// The supported Mips ISAs dont have any instruction close to the SELECT_CC
386// operation. The solution is to create a Mips pseudo SELECT_CC instruction
387// (MipsSelectCC), use LowerSELECT_CC to generate this instruction and finally
388// replace it for real supported nodes into EmitInstrWithCustomInserter
389let usesCustomDAGSchedInserter = 1 in {
Bruno Cardoso Lopesda54c7d2008-07-29 19:05:28 +0000390 class PseudoSelCC<RegisterClass RC, string asmstr>:
391 MipsPseudo<(outs RC:$dst), (ins CPURegs:$CmpRes, RC:$T, RC:$F), asmstr,
392 [(set RC:$dst, (MipsSelectCC CPURegs:$CmpRes, RC:$T, RC:$F))]>;
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000393}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000394
Bruno Cardoso Lopesda54c7d2008-07-29 19:05:28 +0000395def Select_CC : PseudoSelCC<CPURegs, "# MipsSelect_CC_i32">;
396
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000397//===----------------------------------------------------------------------===//
398// Instruction definition
399//===----------------------------------------------------------------------===//
400
401//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000402// MipsI Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000403//===----------------------------------------------------------------------===//
404
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000405/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000406def ADDiu : ArithI<0x09, "addiu", add, uimm16, immZExt16>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000407def ADDi : ArithI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000408def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
409def SLTiu : SetCC_I<0x0b, "sltiu", setult, uimm16, immZExt16>;
410def ANDi : LogicI<0x0c, "andi", and>;
411def ORi : LogicI<0x0d, "ori", or>;
412def XORi : LogicI<0x0e, "xori", xor>;
413def LUi : LoadUpper<0x0f, "lui">;
414
415/// Arithmetic Instructions (3-Operand, R-Type)
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000416def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
417def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000418def ADD : ArithOverflowR<0x00, 0x20, "add">;
419def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000420def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
421def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000422def AND : LogicR<0x24, "and", and>;
423def OR : LogicR<0x25, "or", or>;
424def XOR : LogicR<0x26, "xor", xor>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000425def NOR : LogicNOR<0x00, 0x27, "nor">;
426
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000427/// Shift Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000428def SLL : LogicR_shift_imm<0x00, "sll", shl>;
429def SRL : LogicR_shift_imm<0x02, "srl", srl>;
430def SRA : LogicR_shift_imm<0x03, "sra", sra>;
431def SLLV : LogicR_shift_reg<0x04, "sllv", shl>;
432def SRLV : LogicR_shift_reg<0x06, "srlv", srl>;
433def SRAV : LogicR_shift_reg<0x07, "srav", sra>;
434
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000435/// Load and Store Instructions
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000436def LB : LoadM<0x20, "lb", sextloadi8>;
437def LBu : LoadM<0x24, "lbu", zextloadi8>;
438def LH : LoadM<0x21, "lh", sextloadi16>;
439def LHu : LoadM<0x25, "lhu", zextloadi16>;
440def LW : LoadM<0x23, "lw", load>;
441def SB : StoreM<0x28, "sb", truncstorei8>;
442def SH : StoreM<0x29, "sh", truncstorei16>;
443def SW : StoreM<0x2b, "sw", store>;
444
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000445/// Jump and Branch Instructions
446def J : JumpFJ<0x02, "j">;
447def JR : JumpFR<0x00, 0x08, "jr">;
448def JAL : JumpLink<0x03, "jal">;
449def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000450def BEQ : CBranch<0x04, "beq", seteq>;
451def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000452
Eric Christopher7300ac12007-10-26 04:00:13 +0000453let rt=1 in
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000454 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000455
456let rt=0 in {
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000457 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
458 def BLEZ : CBranchZero<0x07, "blez", setle>;
459 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000460}
461
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000462def BGEZAL : BranchLink<"bgezal">;
463def BLTZAL : BranchLink<"bltzal">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000464
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000465let isReturn=1, isTerminator=1, hasDelaySlot=1,
466 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
467 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
468 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
469
470/// Multiply and Divide Instructions.
Bruno Cardoso Lopes4f0bb3c2008-08-02 19:42:36 +0000471let Defs = [HI, LO] in {
472 def MULT : MulDiv<0x18, "mult", IIImul>;
473 def MULTu : MulDiv<0x19, "multu", IIImul>;
474 def DIV : MulDiv<0x1a, "div", IIIdiv>;
475 def DIVu : MulDiv<0x1b, "divu", IIIdiv>;
476}
477
478let Defs = [HI] in
479 def MTHI : MoveToLOHI<0x11, "mthi">;
480let Defs = [LO] in
481 def MTLO : MoveToLOHI<0x13, "mtlo">;
482
483let Uses = [HI] in
484 def MFHI : MoveFromLOHI<0x10, "mfhi">;
485let Uses = [LO] in
486 def MFLO : MoveFromLOHI<0x12, "mflo">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000487
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000488/// Sign Ext In Register Instructions.
489let Predicates = [HasSEInReg] in {
490 let shamt = 0x10, rs = 0 in
491 def SEB : SignExtInReg<0x21, "seb", i8>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000492
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000493 let shamt = 0x18, rs = 0 in
494 def SEH : SignExtInReg<0x20, "seh", i16>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000495}
496
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000497/// No operation
498let addr=0 in
499 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
500
Eric Christopher7300ac12007-10-26 04:00:13 +0000501// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000502// instructions. The same not happens for stack address copies, so an
503// add op with mem ComplexPattern is used and the stack address copy
504// can be matched. It's similar to Sparc LEA_ADDRi
Bruno Cardoso Lopes29c15352008-07-14 14:42:54 +0000505def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
Bruno Cardoso Lopes96433662007-09-24 20:15:11 +0000506
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000507// Count Leading
508// CLO/CLZ are part of the newer MIPS32(tm) instruction
509// set and not older Mips I keep this for future use
510// though.
511//def CLO : CountLeading<0x21, "clo">;
512//def CLZ : CountLeading<0x20, "clz">;
513
514// MADD*/MSUB* are not part of MipsI either.
515//def MADD : MArithR<0x00, "madd">;
516//def MADDU : MArithR<0x01, "maddu">;
517//def MSUB : MArithR<0x04, "msub">;
518//def MSUBU : MArithR<0x05, "msubu">;
519
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000520// MUL is a assembly macro in the current used ISAs. In recent ISA's
521// it is a real instruction.
522//def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>;
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000523
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000524//===----------------------------------------------------------------------===//
525// Arbitrary patterns that map to one or more instructions
526//===----------------------------------------------------------------------===//
527
528// Small immediates
Eric Christopher7300ac12007-10-26 04:00:13 +0000529def : Pat<(i32 immSExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000530 (ADDiu ZERO, imm:$in)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000531def : Pat<(i32 immZExt16:$in),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000532 (ORi ZERO, imm:$in)>;
533
534// Arbitrary immediates
535def : Pat<(i32 imm:$imm),
536 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
537
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000538// Carry patterns
539def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
540 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
541def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
542 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
543def : Pat<(addc CPURegs:$src, imm:$imm),
544 (ADDiu CPURegs:$src, imm:$imm)>;
545
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000546// Call
547def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
548 (JAL tglobaladdr:$dst)>;
549def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
550 (JAL texternalsym:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000551def : Pat<(MipsJmpLink CPURegs:$dst),
552 (JALR CPURegs:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000553
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +0000554// hi/lo relocs
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000555def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000556def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000557 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +0000558
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000559def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopesea377302007-11-12 19:49:57 +0000560def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
561 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +0000562
563def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
564def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
565 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
566
567// gp_rel relocs
Bruno Cardoso Lopes12355a82008-07-21 18:52:34 +0000568def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
569 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes69ca2ca2008-07-23 16:01:50 +0000570def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
571 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000572
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000573// Mips does not have "not", so we expand our way
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000574def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000575 (NOR CPURegs:$in, ZERO)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000576
Eric Christopher7300ac12007-10-26 04:00:13 +0000577// extended load and stores
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000578def : Pat<(i32 (extloadi1 addr:$src)), (LBu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000579def : Pat<(i32 (extloadi8 addr:$src)), (LBu addr:$src)>;
580def : Pat<(i32 (extloadi16 addr:$src)), (LHu addr:$src)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000581
Bruno Cardoso Lopesed7723d2008-06-06 00:58:26 +0000582// peepholes
Bruno Cardoso Lopes218d5822007-11-05 03:02:32 +0000583def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
584
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000585// brcond patterns
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000586// direct match equal/notequal zero branches
587def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000588 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000589def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
590 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000591
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000592def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000593 (BGEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000594def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000595 (BGEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000596
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000597def : Pat<(brcond (setgt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
598 (BGTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
599def : Pat<(brcond (setugt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
600 (BGTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
601
602def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
603 (BLEZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
604def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
605 (BLEZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
606
607def : Pat<(brcond (setlt CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000608 (BNE (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000609def : Pat<(brcond (setult CPURegs:$lhs, immZExt16:$rhs), bb:$dst),
610 (BNE (SLTiu CPURegs:$lhs, immZExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000611def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
612 (BNE (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
613def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
614 (BNE (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
615
616def : Pat<(brcond (setlt CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
617 (BLTZ (SUB CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
618def : Pat<(brcond (setult CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
619 (BLTZ (SUBu CPURegs:$lhs, CPURegs:$rhs), bb:$dst)>;
620
621// generic brcond pattern
622def : Pat<(brcond CPURegs:$cond, bb:$dst),
623 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
624
Bruno Cardoso Lopes062ac062008-07-30 16:58:59 +0000625// setcc patterns, only matched when there
626// is no brcond following a setcc operation
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000627def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
628 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
629def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
630 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
631
632def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
633 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
634def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
635 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
636
637def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
638 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
639def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
640 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
641
642def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000643 (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000644 (SLT CPURegs:$rhs, CPURegs:$lhs))>;
645
646def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
Eric Christopher7300ac12007-10-26 04:00:13 +0000647 (XORi (OR (SLT CPURegs:$lhs, CPURegs:$rhs),
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000648 (SLT CPURegs:$rhs, CPURegs:$lhs)), 1)>;
Eric Christopher7300ac12007-10-26 04:00:13 +0000649
Bruno Cardoso Lopes34190552007-08-18 02:37:46 +0000650def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
651 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
652def : Pat<(setuge CPURegs:$lhs, immZExt16:$rhs),
653 (XORi (SLTiu CPURegs:$lhs, immZExt16:$rhs), 1)>;
Bruno Cardoso Lopes4fb1f542008-07-05 19:05:21 +0000654
655//===----------------------------------------------------------------------===//
656// Floating Point Support
657//===----------------------------------------------------------------------===//
658
659include "MipsInstrFPU.td"
660