blob: 61f51e74b0830546708e4bc182c673441e8d422e [file] [log] [blame]
Chris Lattner23e70eb2010-08-17 16:20:04 +00001//===- MipsInstrInfo.td - Mips Register defs ---------------*- tablegen -*-===//
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +00007//
8//===----------------------------------------------------------------------===//
9
10//===----------------------------------------------------------------------===//
11// Instruction format superclass
12//===----------------------------------------------------------------------===//
13
14include "MipsInstrFormats.td"
15
16//===----------------------------------------------------------------------===//
17// Mips profiles and nodes
18//===----------------------------------------------------------------------===//
19
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000020def SDT_MipsRet : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
21def SDT_MipsJmpLink : SDTypeProfile<0, 1, [SDTCisVT<0, iPTR>]>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000022def SDT_MipsSelectCC : SDTypeProfile<1, 3, [SDTCisSameAs<0, 2>,
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +000023 SDTCisSameAs<2, 3>, SDTCisInt<1>]>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000024def SDT_MipsCMov : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>,
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000025 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>,
26 SDTCisInt<4>]>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000027def SDT_MipsCallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>]>;
28def SDT_MipsCallSeqEnd : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
29
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000030// Call
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000031def MipsJmpLink : SDNode<"MipsISD::JmpLink",SDT_MipsJmpLink,
Chris Lattner60e9eac2010-03-19 05:33:51 +000032 [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag,
33 SDNPVariadic]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000034
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000035// Hi and Lo nodes are used to handle global addresses. Used on
36// MipsISelLowering to lower stuff like GlobalAddress, ExternalSymbol
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +000037// static model. (nothing to do with Mips Registers Hi and Lo)
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +000038def MipsHi : SDNode<"MipsISD::Hi", SDTIntUnaryOp>;
39def MipsLo : SDNode<"MipsISD::Lo", SDTIntUnaryOp>;
40def MipsGPRel : SDNode<"MipsISD::GPRel", SDTIntUnaryOp>;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000041
Eric Christopher3c999a22007-10-26 04:00:13 +000042// Return
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +000043def MipsRet : SDNode<"MipsISD::Ret", SDT_MipsRet, [SDNPHasChain,
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000044 SDNPOptInFlag]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000045
46// These are target-independent nodes, but have target-specific formats.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000047def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_MipsCallSeqStart,
48 [SDNPHasChain, SDNPOutFlag]>;
49def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_MipsCallSeqEnd,
50 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
Bill Wendling0f8d9c02007-11-13 00:44:25 +000051
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +000052// Select Condition Code
53def MipsSelectCC : SDNode<"MipsISD::SelectCC", SDT_MipsSelectCC>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +000054
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000055// Conditional Move
56def MipsCMov : SDNode<"MipsISD::CMov", SDT_MipsCMov>;
57
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000058//===----------------------------------------------------------------------===//
59// Mips Instruction Predicate Definitions.
60//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +000061def HasSEInReg : Predicate<"Subtarget.hasSEInReg()">;
62def HasBitCount : Predicate<"Subtarget.hasBitCount()">;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000063def HasSwap : Predicate<"Subtarget.hasSwap()">;
64def HasCondMov : Predicate<"Subtarget.hasCondMov()">;
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +000065
66//===----------------------------------------------------------------------===//
67// Mips Operand, Complex Patterns and Transformations Definitions.
68//===----------------------------------------------------------------------===//
69
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000070// Instruction operand types
71def brtarget : Operand<OtherVT>;
72def calltarget : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000073def simm16 : Operand<i32>;
Eric Christopher3c999a22007-10-26 04:00:13 +000074def shamt : Operand<i32>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000075
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +000076// Unsigned Operand
77def uimm16 : Operand<i32> {
78 let PrintMethod = "printUnsignedImm";
79}
80
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000081// Address operand
82def mem : Operand<i32> {
83 let PrintMethod = "printMemOperand";
84 let MIOperandInfo = (ops simm16, CPURegs);
85}
86
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000087// Transformation Function - get the lower 16 bits.
88def LO16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000089 return getI32Imm((unsigned)N->getZExtValue() & 0xFFFF);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000090}]>;
91
92// Transformation Function - get the higher 16 bits.
93def HI16 : SDNodeXForm<imm, [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +000094 return getI32Imm((unsigned)N->getZExtValue() >> 16);
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +000095}]>;
96
97// Node immediate fits as 16-bit sign extended on target immediate.
98// e.g. addi, andi
Jakob Stoklund Olesen7552a3d2010-08-18 23:56:46 +000099def immSExt16 : PatLeaf<(imm), [{ return isInt<16>(N->getSExtValue()); }]>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000100
101// Node immediate fits as 16-bit zero extended on target immediate.
102// The LO16 param means that only the lower 16 bits of the node
103// immediate are caught.
104// e.g. addiu, sltiu
105def immZExt16 : PatLeaf<(imm), [{
Owen Anderson825b72b2009-08-11 20:47:22 +0000106 if (N->getValueType(0) == MVT::i32)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000107 return (uint32_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Eric Christopher3c999a22007-10-26 04:00:13 +0000108 else
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000109 return (uint64_t)N->getZExtValue() == (unsigned short)N->getZExtValue();
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000110}], LO16>;
111
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000112// shamt field must fit in 5 bits.
113def immZExt5 : PatLeaf<(imm), [{
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000114 return N->getZExtValue() == ((N->getZExtValue()) & 0x1f) ;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000115}]>;
116
Eric Christopher3c999a22007-10-26 04:00:13 +0000117// Mips Address Mode! SDNode frameindex could possibily be a match
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000118// since load and store instructions from stack used it.
Chris Lattnereb079a32010-02-14 21:53:19 +0000119def addr : ComplexPattern<iPTR, 2, "SelectAddr", [frameindex], []>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000120
121//===----------------------------------------------------------------------===//
122// Instructions specific format
123//===----------------------------------------------------------------------===//
124
125// Arithmetic 3 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000126let isCommutable = 1 in
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000127class ArithR<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
Eric Christopher3c999a22007-10-26 04:00:13 +0000128 InstrItinClass itin>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000129 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
130 !strconcat(instr_asm, "\t$dst, $b, $c"),
131 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], itin>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000132
Eric Christopher3c999a22007-10-26 04:00:13 +0000133let isCommutable = 1 in
134class ArithOverflowR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000135 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
136 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000137
138// Arithmetic 2 register operands
Eric Christopher3c999a22007-10-26 04:00:13 +0000139class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
140 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000141 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
142 !strconcat(instr_asm, "\t$dst, $b, $c"),
143 [(set CPURegs:$dst, (OpNode CPURegs:$b, imm_type:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000144
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000145class ArithOverflowI<bits<6> op, string instr_asm, SDNode OpNode,
146 Operand Od, PatLeaf imm_type> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000147 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
148 !strconcat(instr_asm, "\t$dst, $b, $c"), [], IIAlu>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000149
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000150// Arithmetic Multiply ADD/SUB
151let rd=0 in
Eric Christopher3c999a22007-10-26 04:00:13 +0000152class MArithR<bits<6> func, string instr_asm> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000153 FR<0x1c, func, (outs CPURegs:$rs), (ins CPURegs:$rt),
154 !strconcat(instr_asm, "\t$rs, $rt"), [], IIImul>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000155
156// Logical
157class LogicR<bits<6> func, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000158 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
159 !strconcat(instr_asm, "\t$dst, $b, $c"),
160 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000161
162class LogicI<bits<6> op, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000163 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, uimm16:$c),
164 !strconcat(instr_asm, "\t$dst, $b, $c"),
165 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt16:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000166
167class LogicNOR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000168 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
169 !strconcat(instr_asm, "\t$dst, $b, $c"),
170 [(set CPURegs:$dst, (not (or CPURegs:$b, CPURegs:$c)))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000171
172// Shifts
173let rt = 0 in
174class LogicR_shift_imm<bits<6> func, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000175 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, shamt:$c),
176 !strconcat(instr_asm, "\t$dst, $b, $c"),
177 [(set CPURegs:$dst, (OpNode CPURegs:$b, immZExt5:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000178
179class LogicR_shift_reg<bits<6> func, string instr_asm, SDNode OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000180 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
181 !strconcat(instr_asm, "\t$dst, $b, $c"),
182 [(set CPURegs:$dst, (OpNode CPURegs:$b, CPURegs:$c))], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000183
184// Load Upper Imediate
185class LoadUpper<bits<6> op, string instr_asm>:
186 FI< op,
Evan Cheng64d80e32007-07-19 01:14:50 +0000187 (outs CPURegs:$dst),
188 (ins uimm16:$imm),
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000189 !strconcat(instr_asm, "\t$dst, $imm"),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000190 [], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000191
Eric Christopher3c999a22007-10-26 04:00:13 +0000192// Memory Load/Store
Dan Gohman15511cf2008-12-03 18:15:48 +0000193let canFoldAsLoad = 1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000194class LoadM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000195 FI<op, (outs CPURegs:$dst), (ins mem:$addr),
196 !strconcat(instr_asm, "\t$dst, $addr"),
197 [(set CPURegs:$dst, (OpNode addr:$addr))], IILoad>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000198
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000199class StoreM<bits<6> op, string instr_asm, PatFrag OpNode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000200 FI<op, (outs), (ins CPURegs:$dst, mem:$addr),
201 !strconcat(instr_asm, "\t$dst, $addr"),
202 [(OpNode CPURegs:$dst, addr:$addr)], IIStore>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000203
204// Conditional Branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000205let isBranch = 1, isTerminator=1, hasDelaySlot = 1 in {
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000206class CBranch<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000207 FI<op, (outs), (ins CPURegs:$a, CPURegs:$b, brtarget:$offset),
208 !strconcat(instr_asm, "\t$a, $b, $offset"),
209 [(brcond (cond_op CPURegs:$a, CPURegs:$b), bb:$offset)],
210 IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000211
212class CBranchZero<bits<6> op, string instr_asm, PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000213 FI<op, (outs), (ins CPURegs:$src, brtarget:$offset),
214 !strconcat(instr_asm, "\t$src, $offset"),
215 [(brcond (cond_op CPURegs:$src, 0), bb:$offset)],
216 IIBranch>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000217}
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000218
Eric Christopher3c999a22007-10-26 04:00:13 +0000219// SetCC
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000220class SetCC_R<bits<6> op, bits<6> func, string instr_asm,
221 PatFrag cond_op>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000222 FR<op, func, (outs CPURegs:$dst), (ins CPURegs:$b, CPURegs:$c),
223 !strconcat(instr_asm, "\t$dst, $b, $c"),
224 [(set CPURegs:$dst, (cond_op CPURegs:$b, CPURegs:$c))],
225 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000226
227class SetCC_I<bits<6> op, string instr_asm, PatFrag cond_op,
228 Operand Od, PatLeaf imm_type>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000229 FI<op, (outs CPURegs:$dst), (ins CPURegs:$b, Od:$c),
230 !strconcat(instr_asm, "\t$dst, $b, $c"),
231 [(set CPURegs:$dst, (cond_op CPURegs:$b, imm_type:$c))],
232 IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000233
234// Unconditional branch
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000235let isBranch=1, isTerminator=1, isBarrier=1, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000236class JumpFJ<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000237 FJ<op, (outs), (ins brtarget:$target),
238 !strconcat(instr_asm, "\t$target"), [(br bb:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000239
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000240let isBranch=1, isTerminator=1, isBarrier=1, rd=0, hasDelaySlot = 1 in
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000241class JumpFR<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000242 FR<op, func, (outs), (ins CPURegs:$target),
243 !strconcat(instr_asm, "\t$target"), [(brind CPURegs:$target)], IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000244
245// Jump and Link (Call)
Eric Christopher3c999a22007-10-26 04:00:13 +0000246let isCall=1, hasDelaySlot=1,
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000247 // All calls clobber the non-callee saved registers...
Jakob Stoklund Olesende12e432010-02-17 20:18:50 +0000248 Defs = [AT, V0, V1, A0, A1, A2, A3, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9,
249 K0, K1, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9], Uses = [GP] in {
Eric Christopher3c999a22007-10-26 04:00:13 +0000250 class JumpLink<bits<6> op, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000251 FJ<op, (outs), (ins calltarget:$target, variable_ops),
252 !strconcat(instr_asm, "\t$target"), [(MipsJmpLink imm:$target)],
253 IIBranch>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000254
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000255 let rd=31 in
256 class JumpLinkReg<bits<6> op, bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000257 FR<op, func, (outs), (ins CPURegs:$rs, variable_ops),
258 !strconcat(instr_asm, "\t$rs"), [(MipsJmpLink CPURegs:$rs)], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000259
260 class BranchLink<string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000261 FI<0x1, (outs), (ins CPURegs:$rs, brtarget:$target, variable_ops),
262 !strconcat(instr_asm, "\t$rs, $target"), [], IIBranch>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000263}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000264
Eric Christopher3c999a22007-10-26 04:00:13 +0000265// Mul, Div
266class MulDiv<bits<6> func, string instr_asm, InstrItinClass itin>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000267 FR<0x00, func, (outs), (ins CPURegs:$a, CPURegs:$b),
268 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000269
Eric Christopher3c999a22007-10-26 04:00:13 +0000270// Move from Hi/Lo
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000271class MoveFromLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000272 FR<0x00, func, (outs CPURegs:$dst), (ins),
273 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000274
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000275class MoveToLOHI<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000276 FR<0x00, func, (outs), (ins CPURegs:$src),
277 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000278
Eric Christopher3c999a22007-10-26 04:00:13 +0000279class EffectiveAddress<string instr_asm> :
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000280 FI<0x09, (outs CPURegs:$dst), (ins mem:$addr),
281 instr_asm, [(set CPURegs:$dst, addr:$addr)], IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000282
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000283// Count Leading Ones/Zeros in Word
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000284class CountLeading<bits<6> func, string instr_asm, list<dag> pattern>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000285 FR<0x1c, func, (outs CPURegs:$dst), (ins CPURegs:$src),
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000286 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
287 Requires<[HasBitCount]> {
288 let shamt = 0;
289 let rt = rd;
290}
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000291
292// Sign Extend in Register.
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000293class SignExtInReg<bits<6> func, string instr_asm, ValueType vt>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000294 FR<0x3f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
295 !strconcat(instr_asm, "\t$dst, $src"),
296 [(set CPURegs:$dst, (sext_inreg CPURegs:$src, vt))], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000297
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000298// Byte Swap
299class ByteSwap<bits<6> func, string instr_asm>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000300 FR<0x1f, func, (outs CPURegs:$dst), (ins CPURegs:$src),
301 !strconcat(instr_asm, "\t$dst, $src"),
302 [(set CPURegs:$dst, (bswap CPURegs:$src))], NoItinerary>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000303
304// Conditional Move
305class CondMov<bits<6> func, string instr_asm, PatLeaf MovCode>:
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000306 FR<0x00, func, (outs CPURegs:$dst), (ins CPURegs:$F, CPURegs:$T,
307 CPURegs:$cond), !strconcat(instr_asm, "\t$dst, $T, $cond"),
308 [(set CPURegs:$dst, (MipsCMov CPURegs:$F, CPURegs:$T,
309 CPURegs:$cond, MovCode))], NoItinerary>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000310
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000311//===----------------------------------------------------------------------===//
312// Pseudo instructions
313//===----------------------------------------------------------------------===//
314
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000315// As stack alignment is always done with addiu, we need a 16-bit immediate
Evan Cheng071a2792007-09-11 19:55:27 +0000316let Defs = [SP], Uses = [SP] in {
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000317def ADJCALLSTACKDOWN : MipsPseudo<(outs), (ins uimm16:$amt),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000318 "!ADJCALLSTACKDOWN $amt",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000319 [(callseq_start timm:$amt)]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000320def ADJCALLSTACKUP : MipsPseudo<(outs), (ins uimm16:$amt1, uimm16:$amt2),
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000321 "!ADJCALLSTACKUP $amt1",
Chris Lattnere563bbc2008-10-11 22:08:30 +0000322 [(callseq_end timm:$amt1, timm:$amt2)]>;
Evan Cheng071a2792007-09-11 19:55:27 +0000323}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000324
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000325// Some assembly macros need to avoid pseudoinstructions and assembler
326// automatic reodering, we should reorder ourselves.
327def MACRO : MipsPseudo<(outs), (ins), ".set\tmacro", []>;
328def REORDER : MipsPseudo<(outs), (ins), ".set\treorder", []>;
329def NOMACRO : MipsPseudo<(outs), (ins), ".set\tnomacro", []>;
330def NOREORDER : MipsPseudo<(outs), (ins), ".set\tnoreorder", []>;
331
Eric Christopher3c999a22007-10-26 04:00:13 +0000332// When handling PIC code the assembler needs .cpload and .cprestore
333// directives. If the real instructions corresponding these directives
334// are used, we have the same behavior, but get also a bunch of warnings
Bruno Cardoso Lopese78080c2007-10-09 02:55:31 +0000335// from the assembler.
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000336def CPLOAD : MipsPseudo<(outs), (ins CPURegs:$picreg), ".cpload\t$picreg", []>;
337def CPRESTORE : MipsPseudo<(outs), (ins uimm16:$loc), ".cprestore\t$loc\n", []>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000338
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000339// The supported Mips ISAs dont have any instruction close to the SELECT_CC
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000340// operation. The solution is to create a Mips pseudo SELECT_CC instruction
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000341// (MipsSelectCC), use LowerSELECT_CC to generate this instruction and finally
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000342// replace it for real supported nodes into EmitInstrWithCustomInserter
Dan Gohman533297b2009-10-29 18:10:34 +0000343let usesCustomInserter = 1 in {
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000344 class PseudoSelCC<RegisterClass RC, string asmstr>:
345 MipsPseudo<(outs RC:$dst), (ins CPURegs:$CmpRes, RC:$T, RC:$F), asmstr,
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000346 [(set RC:$dst, (MipsSelectCC CPURegs:$CmpRes, RC:$T, RC:$F))]>;
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000347}
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000348
Bruno Cardoso Lopes6d399bd2008-07-29 19:05:28 +0000349def Select_CC : PseudoSelCC<CPURegs, "# MipsSelect_CC_i32">;
350
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000351//===----------------------------------------------------------------------===//
352// Instruction definition
353//===----------------------------------------------------------------------===//
354
355//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000356// MipsI Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000357//===----------------------------------------------------------------------===//
358
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000359/// Arithmetic Instructions (ALU Immediate)
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000360def ADDiu : ArithI<0x09, "addiu", add, simm16, immSExt16>;
361def ADDi : ArithOverflowI<0x08, "addi", add, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000362def SLTi : SetCC_I<0x0a, "slti", setlt, simm16, immSExt16>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000363def SLTiu : SetCC_I<0x0b, "sltiu", setult, simm16, immSExt16>;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000364def ANDi : LogicI<0x0c, "andi", and>;
365def ORi : LogicI<0x0d, "ori", or>;
366def XORi : LogicI<0x0e, "xori", xor>;
367def LUi : LoadUpper<0x0f, "lui">;
368
369/// Arithmetic Instructions (3-Operand, R-Type)
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000370def ADDu : ArithR<0x00, 0x21, "addu", add, IIAlu>;
371def SUBu : ArithR<0x00, 0x23, "subu", sub, IIAlu>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000372def ADD : ArithOverflowR<0x00, 0x20, "add">;
373def SUB : ArithOverflowR<0x00, 0x22, "sub">;
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000374def SLT : SetCC_R<0x00, 0x2a, "slt", setlt>;
375def SLTu : SetCC_R<0x00, 0x2b, "sltu", setult>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000376def AND : LogicR<0x24, "and", and>;
377def OR : LogicR<0x25, "or", or>;
378def XOR : LogicR<0x26, "xor", xor>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000379def NOR : LogicNOR<0x00, 0x27, "nor">;
380
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000381/// Shift Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000382def SLL : LogicR_shift_imm<0x00, "sll", shl>;
383def SRL : LogicR_shift_imm<0x02, "srl", srl>;
384def SRA : LogicR_shift_imm<0x03, "sra", sra>;
385def SLLV : LogicR_shift_reg<0x04, "sllv", shl>;
386def SRLV : LogicR_shift_reg<0x06, "srlv", srl>;
387def SRAV : LogicR_shift_reg<0x07, "srav", sra>;
388
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000389/// Load and Store Instructions
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000390def LB : LoadM<0x20, "lb", sextloadi8>;
391def LBu : LoadM<0x24, "lbu", zextloadi8>;
392def LH : LoadM<0x21, "lh", sextloadi16>;
393def LHu : LoadM<0x25, "lhu", zextloadi16>;
394def LW : LoadM<0x23, "lw", load>;
395def SB : StoreM<0x28, "sb", truncstorei8>;
396def SH : StoreM<0x29, "sh", truncstorei16>;
397def SW : StoreM<0x2b, "sw", store>;
398
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000399/// Jump and Branch Instructions
400def J : JumpFJ<0x02, "j">;
401def JR : JumpFR<0x00, 0x08, "jr">;
402def JAL : JumpLink<0x03, "jal">;
403def JALR : JumpLinkReg<0x00, 0x09, "jalr">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000404def BEQ : CBranch<0x04, "beq", seteq>;
405def BNE : CBranch<0x05, "bne", setne>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000406
Eric Christopher3c999a22007-10-26 04:00:13 +0000407let rt=1 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000408 def BGEZ : CBranchZero<0x01, "bgez", setge>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000409
410let rt=0 in {
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000411 def BGTZ : CBranchZero<0x07, "bgtz", setgt>;
412 def BLEZ : CBranchZero<0x07, "blez", setle>;
413 def BLTZ : CBranchZero<0x01, "bltz", setlt>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000414}
415
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000416def BGEZAL : BranchLink<"bgezal">;
417def BLTZAL : BranchLink<"bltzal">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000418
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000419let isReturn=1, isTerminator=1, hasDelaySlot=1,
420 isBarrier=1, hasCtrlDep=1, rs=0, rt=0, shamt=0 in
421 def RET : FR <0x00, 0x02, (outs), (ins CPURegs:$target),
422 "jr\t$target", [(MipsRet CPURegs:$target)], IIBranch>;
423
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000424/// Multiply and Divide Instructions.
Bruno Cardoso Lopes91ef8492008-08-02 19:42:36 +0000425let Defs = [HI, LO] in {
426 def MULT : MulDiv<0x18, "mult", IIImul>;
427 def MULTu : MulDiv<0x19, "multu", IIImul>;
428 def DIV : MulDiv<0x1a, "div", IIIdiv>;
429 def DIVu : MulDiv<0x1b, "divu", IIIdiv>;
430}
431
432let Defs = [HI] in
433 def MTHI : MoveToLOHI<0x11, "mthi">;
434let Defs = [LO] in
435 def MTLO : MoveToLOHI<0x13, "mtlo">;
436
437let Uses = [HI] in
438 def MFHI : MoveFromLOHI<0x10, "mfhi">;
439let Uses = [LO] in
440 def MFLO : MoveFromLOHI<0x12, "mflo">;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000441
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000442/// Sign Ext In Register Instructions.
443let Predicates = [HasSEInReg] in {
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000444 let shamt = 0x10, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000445 def SEB : SignExtInReg<0x21, "seb", i8>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000446
Bruno Cardoso Lopesd3bdf192009-05-27 17:23:44 +0000447 let shamt = 0x18, rs = 0 in
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000448 def SEH : SignExtInReg<0x20, "seh", i16>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000449}
450
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000451/// Count Leading
Bruno Cardoso Lopesc4bb67c2010-11-10 02:13:22 +0000452def CLZ : CountLeading<0b100000, "clz",
453 [(set CPURegs:$dst, (ctlz CPURegs:$src))]>;
454def CLO : CountLeading<0b100001, "clo",
455 [(set CPURegs:$dst, (ctlz (not CPURegs:$src)))]>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000456
457/// Byte Swap
458let Predicates = [HasSwap] in {
459 let shamt = 0x3, rs = 0 in
460 def WSBW : ByteSwap<0x20, "wsbw">;
461}
462
463/// Conditional Move
464def MIPS_CMOV_ZERO : PatLeaf<(i32 0)>;
465def MIPS_CMOV_NZERO : PatLeaf<(i32 1)>;
466
Eric Christopherc452d792010-06-21 20:19:21 +0000467let Predicates = [HasCondMov], Constraints = "$F = $dst" in {
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000468 def MOVN : CondMov<0x0a, "movn", MIPS_CMOV_NZERO>;
469 def MOVZ : CondMov<0x0b, "movz", MIPS_CMOV_ZERO>;
Bruno Cardoso Lopes65ad4522008-08-08 06:16:31 +0000470}
471
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000472/// No operation
473let addr=0 in
474 def NOP : FJ<0, (outs), (ins), "nop", [], IIAlu>;
475
Eric Christopher3c999a22007-10-26 04:00:13 +0000476// FrameIndexes are legalized when they are operands from load/store
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000477// instructions. The same not happens for stack address copies, so an
478// add op with mem ComplexPattern is used and the stack address copy
479// can be matched. It's similar to Sparc LEA_ADDRi
Bruno Cardoso Lopes43d526d2008-07-14 14:42:54 +0000480def LEA_ADDiu : EffectiveAddress<"addiu\t$dst, ${addr:stackloc}">;
Bruno Cardoso Lopesb42abeb2007-09-24 20:15:11 +0000481
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000482// MADD*/MSUB* are not part of MipsI either.
483//def MADD : MArithR<0x00, "madd">;
484//def MADDU : MArithR<0x01, "maddu">;
485//def MSUB : MArithR<0x04, "msub">;
486//def MSUBU : MArithR<0x05, "msubu">;
487
Bruno Cardoso Lopesf7d66f72008-07-30 16:58:59 +0000488// MUL is a assembly macro in the current used ISAs. In recent ISA's
489// it is a real instruction.
490//def MUL : ArithR<0x1c, 0x02, "mul", mul, IIImul>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000491
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000492//===----------------------------------------------------------------------===//
493// Arbitrary patterns that map to one or more instructions
494//===----------------------------------------------------------------------===//
495
496// Small immediates
Eric Christopher3c999a22007-10-26 04:00:13 +0000497def : Pat<(i32 immSExt16:$in),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000498 (ADDiu ZERO, imm:$in)>;
Eric Christopher3c999a22007-10-26 04:00:13 +0000499def : Pat<(i32 immZExt16:$in),
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000500 (ORi ZERO, imm:$in)>;
501
502// Arbitrary immediates
503def : Pat<(i32 imm:$imm),
504 (ORi (LUi (HI16 imm:$imm)), (LO16 imm:$imm))>;
505
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000506// Carry patterns
507def : Pat<(subc CPURegs:$lhs, CPURegs:$rhs),
508 (SUBu CPURegs:$lhs, CPURegs:$rhs)>;
509def : Pat<(addc CPURegs:$lhs, CPURegs:$rhs),
510 (ADDu CPURegs:$lhs, CPURegs:$rhs)>;
511def : Pat<(addc CPURegs:$src, imm:$imm),
512 (ADDiu CPURegs:$src, imm:$imm)>;
513
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000514// Call
515def : Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
516 (JAL tglobaladdr:$dst)>;
517def : Pat<(MipsJmpLink (i32 texternalsym:$dst)),
518 (JAL texternalsym:$dst)>;
Chris Lattnere0d27532010-02-28 07:23:21 +0000519//def : Pat<(MipsJmpLink CPURegs:$dst),
520// (JALR CPURegs:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000521
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000522// hi/lo relocs
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000523def : Pat<(MipsHi tglobaladdr:$in), (LUi tglobaladdr:$in)>;
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000524def : Pat<(add CPURegs:$hi, (MipsLo tglobaladdr:$lo)),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000525 (ADDiu CPURegs:$hi, tglobaladdr:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000526
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000527def : Pat<(MipsHi tjumptable:$in), (LUi tjumptable:$in)>;
Bruno Cardoso Lopes753a9872007-11-12 19:49:57 +0000528def : Pat<(add CPURegs:$hi, (MipsLo tjumptable:$lo)),
529 (ADDiu CPURegs:$hi, tjumptable:$lo)>;
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000530
531def : Pat<(MipsHi tconstpool:$in), (LUi tconstpool:$in)>;
532def : Pat<(add CPURegs:$hi, (MipsLo tconstpool:$lo)),
533 (ADDiu CPURegs:$hi, tconstpool:$lo)>;
534
535// gp_rel relocs
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000536def : Pat<(add CPURegs:$gp, (MipsGPRel tglobaladdr:$in)),
Bruno Cardoso Lopes91fd5322008-07-21 18:52:34 +0000537 (ADDiu CPURegs:$gp, tglobaladdr:$in)>;
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000538def : Pat<(add CPURegs:$gp, (MipsGPRel tconstpool:$in)),
Bruno Cardoso Lopes92e87f22008-07-23 16:01:50 +0000539 (ADDiu CPURegs:$gp, tconstpool:$in)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000540
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000541// Mips does not have "not", so we expand our way
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000542def : Pat<(not CPURegs:$in),
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000543 (NOR CPURegs:$in, ZERO)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000544
Eric Christopher3c999a22007-10-26 04:00:13 +0000545// extended load and stores
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000546def : Pat<(extloadi1 addr:$src), (LBu addr:$src)>;
547def : Pat<(extloadi8 addr:$src), (LBu addr:$src)>;
548def : Pat<(extloadi16 addr:$src), (LHu addr:$src)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000549
Bruno Cardoso Lopes07cec752008-06-06 00:58:26 +0000550// peepholes
Bruno Cardoso Lopesc7db5612007-11-05 03:02:32 +0000551def : Pat<(store (i32 0), addr:$dst), (SW ZERO, addr:$dst)>;
552
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000553// brcond patterns
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000554def : Pat<(brcond (setne CPURegs:$lhs, 0), bb:$dst),
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000555 (BNE CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000556def : Pat<(brcond (seteq CPURegs:$lhs, 0), bb:$dst),
557 (BEQ CPURegs:$lhs, ZERO, bb:$dst)>;
Bruno Cardoso Lopes332a3d22007-07-11 22:47:02 +0000558
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000559def : Pat<(brcond (setge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000560 (BEQ (SLT CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes972f5892007-06-06 07:42:06 +0000561def : Pat<(brcond (setuge CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000562 (BEQ (SLTu CPURegs:$lhs, CPURegs:$rhs), ZERO, bb:$dst)>;
563def : Pat<(brcond (setge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
564 (BEQ (SLTi CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
565def : Pat<(brcond (setuge CPURegs:$lhs, immSExt16:$rhs), bb:$dst),
566 (BEQ (SLTiu CPURegs:$lhs, immSExt16:$rhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000567
568def : Pat<(brcond (setle CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000569 (BEQ (SLT CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000570def : Pat<(brcond (setule CPURegs:$lhs, CPURegs:$rhs), bb:$dst),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000571 (BEQ (SLTu CPURegs:$rhs, CPURegs:$lhs), ZERO, bb:$dst)>;
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000572
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000573def : Pat<(brcond CPURegs:$cond, bb:$dst),
574 (BNE CPURegs:$cond, ZERO, bb:$dst)>;
575
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000576// select patterns
577def : Pat<(select (setge CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
578 (MOVZ CPURegs:$F, CPURegs:$T, (SLT CPURegs:$lhs, CPURegs:$rhs))>;
579def : Pat<(select (setuge CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
580 (MOVZ CPURegs:$F, CPURegs:$T, (SLTu CPURegs:$lhs, CPURegs:$rhs))>;
581def : Pat<(select (setge CPURegs:$lhs, immSExt16:$rhs), CPURegs:$T, CPURegs:$F),
582 (MOVZ CPURegs:$F, CPURegs:$T, (SLTi CPURegs:$lhs, immSExt16:$rhs))>;
583def : Pat<(select (setuge CPURegs:$lh, immSExt16:$rh), CPURegs:$T, CPURegs:$F),
584 (MOVZ CPURegs:$F, CPURegs:$T, (SLTiu CPURegs:$lh, immSExt16:$rh))>;
585
586def : Pat<(select (setle CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
587 (MOVZ CPURegs:$F, CPURegs:$T, (SLT CPURegs:$rhs, CPURegs:$lhs))>;
588def : Pat<(select (setule CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
589 (MOVZ CPURegs:$F, CPURegs:$T, (SLTu CPURegs:$rhs, CPURegs:$lhs))>;
590
591def : Pat<(select (seteq CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
592 (MOVZ CPURegs:$F, CPURegs:$T, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
593def : Pat<(select (setne CPURegs:$lhs, CPURegs:$rhs), CPURegs:$T, CPURegs:$F),
594 (MOVN CPURegs:$F, CPURegs:$T, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
595
Bruno Cardoso Lopes9e030612010-11-09 17:25:34 +0000596def : Pat<(select CPURegs:$cond, CPURegs:$T, CPURegs:$F),
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000597 (MOVN CPURegs:$F, CPURegs:$T, CPURegs:$cond)>;
598
599// setcc patterns
600def : Pat<(seteq CPURegs:$lhs, CPURegs:$rhs),
601 (SLTu (XOR CPURegs:$lhs, CPURegs:$rhs), 1)>;
602def : Pat<(setne CPURegs:$lhs, CPURegs:$rhs),
603 (SLTu ZERO, (XOR CPURegs:$lhs, CPURegs:$rhs))>;
604
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000605def : Pat<(setle CPURegs:$lhs, CPURegs:$rhs),
606 (XORi (SLT CPURegs:$rhs, CPURegs:$lhs), 1)>;
607def : Pat<(setule CPURegs:$lhs, CPURegs:$rhs),
608 (XORi (SLTu CPURegs:$rhs, CPURegs:$lhs), 1)>;
609
610def : Pat<(setgt CPURegs:$lhs, CPURegs:$rhs),
611 (SLT CPURegs:$rhs, CPURegs:$lhs)>;
612def : Pat<(setugt CPURegs:$lhs, CPURegs:$rhs),
613 (SLTu CPURegs:$rhs, CPURegs:$lhs)>;
614
615def : Pat<(setge CPURegs:$lhs, CPURegs:$rhs),
616 (XORi (SLT CPURegs:$lhs, CPURegs:$rhs), 1)>;
617def : Pat<(setuge CPURegs:$lhs, CPURegs:$rhs),
618 (XORi (SLTu CPURegs:$lhs, CPURegs:$rhs), 1)>;
619
Bruno Cardoso Lopes97105362007-08-18 02:37:46 +0000620def : Pat<(setge CPURegs:$lhs, immSExt16:$rhs),
621 (XORi (SLTi CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes739e4412008-08-13 07:13:40 +0000622def : Pat<(setuge CPURegs:$lhs, immSExt16:$rhs),
623 (XORi (SLTiu CPURegs:$lhs, immSExt16:$rhs), 1)>;
Bruno Cardoso Lopes225ca9c2008-07-05 19:05:21 +0000624
625//===----------------------------------------------------------------------===//
626// Floating Point Support
627//===----------------------------------------------------------------------===//
628
629include "MipsInstrFPU.td"
630