1 //===- Mips16InstrInfo.td - Target Description for Mips16 -*- 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 // This file describes Mips16 instructions.
12 //===----------------------------------------------------------------------===//
18 ComplexPattern<iPTR, 3, "selectAddr16", [frameindex], [SDNPWantParent]>;
22 def mem16 : Operand<i32> {
23 let PrintMethod = "printMemOperand";
24 let MIOperandInfo = (ops CPU16Regs, simm16, CPU16RegsPlusSP);
25 let EncoderMethod = "getMemEncoding";
28 def mem16_ea : Operand<i32> {
29 let PrintMethod = "printMemOperandEA";
30 let MIOperandInfo = (ops CPU16RegsPlusSP, simm16);
31 let EncoderMethod = "getMemEncoding";
36 // I8 instruction format
39 class FI816_ins_base<bits<3> _func, string asmstr,
40 string asmstr2, InstrItinClass itin>:
41 FI816<_func, (outs), (ins simm16:$imm), !strconcat(asmstr, asmstr2),
45 class FI816_SP_ins<bits<3> _func, string asmstr,
47 FI816_ins_base<_func, asmstr, "\t$$sp, $imm # 16 bit inst", itin>;
50 // RI instruction format
54 class FRI16_ins_base<bits<5> op, string asmstr, string asmstr2,
56 FRI16<op, (outs CPU16Regs:$rx), (ins simm16:$imm),
57 !strconcat(asmstr, asmstr2), [], itin>;
59 class FRI16_ins<bits<5> op, string asmstr,
61 FRI16_ins_base<op, asmstr, "\t$rx, $imm \t# 16 bit inst", itin>;
63 class FRI16R_ins_base<bits<5> op, string asmstr, string asmstr2,
65 FRI16<op, (outs), (ins CPU16Regs:$rx, simm16:$imm),
66 !strconcat(asmstr, asmstr2), [], itin>;
68 class FRI16R_ins<bits<5> op, string asmstr,
70 FRI16R_ins_base<op, asmstr, "\t$rx, $imm \t# 16 bit inst", itin>;
72 class F2RI16_ins<bits<5> _op, string asmstr,
74 FRI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
75 !strconcat(asmstr, "\t$rx, $imm\t# 16 bit inst"), [], itin> {
76 let Constraints = "$rx_ = $rx";
79 class FRI16_B_ins<bits<5> _op, string asmstr,
81 FRI16<_op, (outs), (ins CPU16Regs:$rx, brtarget:$imm),
82 !strconcat(asmstr, "\t$rx, $imm # 16 bit inst"), [], itin>;
84 // Compare a register and immediate and place result in CC
87 // EXT-CCRR Instruction format
89 class FEXT_CCRXI16_ins<string asmstr>:
90 MipsPseudo16<(outs CPU16Regs:$cc), (ins CPU16Regs:$rx, simm16:$imm),
91 !strconcat(asmstr, "\t$rx, $imm\n\tmove\t$cc, $$t8"), []> {
93 let usesCustomInserter = 1;
96 // JAL and JALX instruction format
98 class FJAL16_ins<bits<1> _X, string asmstr,
100 FJAL16<_X, (outs), (ins simm20:$imm),
101 !strconcat(asmstr, "\t$imm\n\tnop"),[],
106 // EXT-I instruction format
108 class FEXT_I16_ins<bits<5> eop, string asmstr, InstrItinClass itin> :
109 FEXT_I16<eop, (outs), (ins brtarget:$imm16),
110 !strconcat(asmstr, "\t$imm16"),[], itin>;
113 // EXT-I8 instruction format
116 class FEXT_I816_ins_base<bits<3> _func, string asmstr,
117 string asmstr2, InstrItinClass itin>:
118 FEXT_I816<_func, (outs), (ins simm16:$imm), !strconcat(asmstr, asmstr2),
121 class FEXT_I816_ins<bits<3> _func, string asmstr,
122 InstrItinClass itin>:
123 FEXT_I816_ins_base<_func, asmstr, "\t$imm", itin>;
125 class FEXT_I816_SP_ins<bits<3> _func, string asmstr,
126 InstrItinClass itin>:
127 FEXT_I816_ins_base<_func, asmstr, "\t$$sp, $imm", itin>;
130 // Assembler formats in alphabetical order.
131 // Natural and pseudos are mixed together.
133 // Compare two registers and place result in CC
134 // Implicit use of T8
136 // CC-RR Instruction format
138 class FCCRR16_ins<string asmstr> :
139 MipsPseudo16<(outs CPU16Regs:$cc), (ins CPU16Regs:$rx, CPU16Regs:$ry),
140 !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$cc, $$t8"), []> {
142 let usesCustomInserter = 1;
146 // EXT-RI instruction format
149 class FEXT_RI16_ins_base<bits<5> _op, string asmstr, string asmstr2,
150 InstrItinClass itin>:
151 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins simm16:$imm),
152 !strconcat(asmstr, asmstr2), [], itin>;
154 class FEXT_RI16_ins<bits<5> _op, string asmstr,
155 InstrItinClass itin>:
156 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
158 class FEXT_RI16R_ins_base<bits<5> _op, string asmstr, string asmstr2,
159 InstrItinClass itin>:
160 FEXT_RI16<_op, (outs ), (ins CPU16Regs:$rx, simm16:$imm),
161 !strconcat(asmstr, asmstr2), [], itin>;
163 class FEXT_RI16R_ins<bits<5> _op, string asmstr,
164 InstrItinClass itin>:
165 FEXT_RI16R_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
167 class FEXT_RI16_PC_ins<bits<5> _op, string asmstr, InstrItinClass itin>:
168 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $$pc, $imm", itin>;
170 class FEXT_RI16_B_ins<bits<5> _op, string asmstr,
171 InstrItinClass itin>:
172 FEXT_RI16<_op, (outs), (ins CPU16Regs:$rx, brtarget:$imm),
173 !strconcat(asmstr, "\t$rx, $imm"), [], itin>;
175 class FEXT_2RI16_ins<bits<5> _op, string asmstr,
176 InstrItinClass itin>:
177 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
178 !strconcat(asmstr, "\t$rx, $imm"), [], itin> {
179 let Constraints = "$rx_ = $rx";
183 // this has an explicit sp argument that we ignore to work around a problem
185 class FEXT_RI16_SP_explicit_ins<bits<5> _op, string asmstr,
186 InstrItinClass itin>:
187 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPUSPReg:$ry, simm16:$imm),
188 !strconcat(asmstr, "\t$rx, $imm ( $ry ); "), [], itin>;
190 class FEXT_RI16_SP_Store_explicit_ins<bits<5> _op, string asmstr,
191 InstrItinClass itin>:
192 FEXT_RI16<_op, (outs), (ins CPU16Regs:$rx, CPUSPReg:$ry, simm16:$imm),
193 !strconcat(asmstr, "\t$rx, $imm ( $ry ); "), [], itin>;
196 // EXT-RRI instruction format
199 class FEXT_RRI16_mem_ins<bits<5> op, string asmstr, Operand MemOpnd,
200 InstrItinClass itin>:
201 FEXT_RRI16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
202 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
204 class FEXT_RRI16_mem2_ins<bits<5> op, string asmstr, Operand MemOpnd,
205 InstrItinClass itin>:
206 FEXT_RRI16<op, (outs ), (ins CPU16Regs:$ry, MemOpnd:$addr),
207 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
211 // EXT-RRI-A instruction format
214 class FEXT_RRI_A16_mem_ins<bits<1> op, string asmstr, Operand MemOpnd,
215 InstrItinClass itin>:
216 FEXT_RRI_A16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
217 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
220 // EXT-SHIFT instruction format
222 class FEXT_SHIFT16_ins<bits<2> _f, string asmstr, InstrItinClass itin>:
223 FEXT_SHIFT16<_f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry, shamt:$sa),
224 !strconcat(asmstr, "\t$rx, $ry, $sa"), [], itin>;
229 class FEXT_T8I816_ins<string asmstr, string asmstr2>:
231 (ins CPU16Regs:$rx, CPU16Regs:$ry, brtarget:$imm),
232 !strconcat(asmstr2, !strconcat("\t$rx, $ry\n\t",
233 !strconcat(asmstr, "\t$imm"))),[]> {
235 let usesCustomInserter = 1;
241 class FEXT_T8I8I16_ins<string asmstr, string asmstr2>:
243 (ins CPU16Regs:$rx, simm16:$imm, brtarget:$targ),
244 !strconcat(asmstr2, !strconcat("\t$rx, $imm\n\t",
245 !strconcat(asmstr, "\t$targ"))), []> {
247 let usesCustomInserter = 1;
253 // I8_MOVR32 instruction format (used only by the MOVR32 instructio
255 class FI8_MOVR3216_ins<string asmstr, InstrItinClass itin>:
256 FI8_MOVR3216<(outs CPU16Regs:$rz), (ins GPR32:$r32),
257 !strconcat(asmstr, "\t$rz, $r32"), [], itin>;
260 // I8_MOV32R instruction format (used only by MOV32R instruction)
263 class FI8_MOV32R16_ins<string asmstr, InstrItinClass itin>:
264 FI8_MOV32R16<(outs GPR32:$r32), (ins CPU16Regs:$rz),
265 !strconcat(asmstr, "\t$r32, $rz"), [], itin>;
268 // This are pseudo formats for multiply
269 // This first one can be changed to non pseudo now.
273 class FMULT16_ins<string asmstr, InstrItinClass itin> :
274 MipsPseudo16<(outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
275 !strconcat(asmstr, "\t$rx, $ry"), []>;
280 class FMULT16_LO_ins<string asmstr, InstrItinClass itin> :
281 MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
282 !strconcat(asmstr, "\t$rx, $ry\n\tmflo\t$rz"), []> {
287 // RR-type instruction format
290 class FRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
291 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
292 !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
295 class FRRBreakNull16_ins<string asmstr, InstrItinClass itin> :
296 FRRBreak16<(outs), (ins), asmstr, [], itin> {
300 class FRR16R_ins<bits<5> f, string asmstr, InstrItinClass itin> :
301 FRR16<f, (outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
302 !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
305 class FRRTR16_ins<string asmstr> :
306 MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
307 !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$rz, $$t8"), []> ;
310 // maybe refactor but need a $zero as a dummy first parameter
312 class FRR16_div_ins<bits<5> f, string asmstr, InstrItinClass itin> :
313 FRR16<f, (outs ), (ins CPU16Regs:$rx, CPU16Regs:$ry),
314 !strconcat(asmstr, "\t$$zero, $rx, $ry"), [], itin> ;
316 class FUnaryRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
317 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
318 !strconcat(asmstr, "\t$rx, $ry"), [], itin> ;
321 class FRR16_M_ins<bits<5> f, string asmstr,
322 InstrItinClass itin> :
323 FRR16<f, (outs CPU16Regs:$rx), (ins),
324 !strconcat(asmstr, "\t$rx"), [], itin>;
326 class FRxRxRy16_ins<bits<5> f, string asmstr,
327 InstrItinClass itin> :
328 FRR16<f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
329 !strconcat(asmstr, "\t$rz, $ry"),
331 let Constraints = "$rx = $rz";
335 class FRR16_JALRC_RA_only_ins<bits<1> nd_, bits<1> l_,
336 string asmstr, InstrItinClass itin>:
337 FRR16_JALRC<nd_, l_, 1, (outs), (ins), !strconcat(asmstr, "\t $$ra"),
341 class FRR16_JALRC_ins<bits<1> nd, bits<1> l, bits<1> ra,
342 string asmstr, InstrItinClass itin>:
343 FRR16_JALRC<nd, l, ra, (outs), (ins CPU16Regs:$rx),
344 !strconcat(asmstr, "\t $rx"), [], itin> ;
347 // RRR-type instruction format
350 class FRRR16_ins<bits<2> _f, string asmstr, InstrItinClass itin> :
351 FRRR16<_f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
352 !strconcat(asmstr, "\t$rz, $rx, $ry"), [], itin>;
355 // These Sel patterns support the generation of conditional move
356 // pseudo instructions.
358 // The nomenclature uses the components making up the pseudo and may
359 // be a bit counter intuitive when compared with the end result we seek.
360 // For example using a bqez in the example directly below results in the
361 // conditional move being done if the tested register is not zero.
362 // I considered in easier to check by keeping the pseudo consistent with
363 // it's components but it could have been done differently.
365 // The simplest case is when can test and operand directly and do the
366 // conditional move based on a simple mips16 conditional
367 // branch instruction.
369 // if $op == beqz or bnez:
374 // if $op == beqz, then if $rt != 0, then the conditional assignment
375 // $rd = $rs is done.
377 // if $op == bnez, then if $rt == 0, then the conditional assignment
378 // $rd = $rs is done.
380 // So this pseudo class only has one operand, i.e. op
382 class Sel<string op>:
383 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
385 !strconcat(op, "\t$rt, .+4\n\t\n\tmove $rd, $rs"), []> {
386 //let isCodeGenOnly=1;
387 let Constraints = "$rd = $rd_";
388 let usesCustomInserter = 1;
392 // The next two instruction classes allow for an operand which tests
393 // two operands and returns a value in register T8 and
394 //then does a conditional branch based on the value of T8
397 // op2 can be cmpi or slti/sltiu
398 // op1 can bteqz or btnez
399 // the operands for op2 are a register and a signed constant
401 // $op2 $t, $imm ;test register t and branch conditionally
402 // $op1 .+4 ;op1 is a conditional branch
406 class SeliT<string op1, string op2>:
407 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
408 CPU16Regs:$rl, simm16:$imm),
410 !strconcat("\t$rl, $imm\n\t",
411 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
413 let Constraints = "$rd = $rd_";
414 let usesCustomInserter = 1;
418 // op2 can be cmp or slt/sltu
419 // op1 can be bteqz or btnez
420 // the operands for op2 are two registers
421 // op1 is a conditional branch
424 // $op2 $rl, $rr ;test registers rl,rr
425 // $op1 .+4 ;op2 is a conditional branch
429 class SelT<string op1, string op2>:
430 MipsPseudo16<(outs CPU16Regs:$rd_),
431 (ins CPU16Regs:$rd, CPU16Regs:$rs,
432 CPU16Regs:$rl, CPU16Regs:$rr),
434 !strconcat("\t$rl, $rr\n\t",
435 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
437 let Constraints = "$rd = $rd_";
438 let usesCustomInserter = 1;
444 def imm32: Operand<i32>;
447 MipsPseudo16<(outs), (ins imm32:$imm), "\t.word $imm", []>;
450 MipsPseudo16<(outs CPU16Regs:$rx), (ins imm32:$imm),
451 "lw\t$rx, 1f\n\tb\t2f\n\t.align\t2\n1: \t.word\t$imm\n2:", []>;
455 // Some general instruction class info
459 class ArithLogic16Defs<bit isCom=0> {
461 bit isCommutable = isCom;
462 bit isReMaterializable = 1;
463 bit neverHasSideEffects = 1;
468 bit isTerminator = 1;
474 bit isTerminator = 1;
487 // Format: ADDIU rx, immediate MIPS16e
488 // Purpose: Add Immediate Unsigned Word (2-Operand, Extended)
489 // To add a constant to a 32-bit integer.
491 def AddiuRxImmX16: FEXT_RI16_ins<0b01001, "addiu", IIAlu>;
493 def AddiuRxRxImm16: F2RI16_ins<0b01001, "addiu", IIAlu>,
494 ArithLogic16Defs<0> {
495 let AddedComplexity = 5;
497 def AddiuRxRxImmX16: FEXT_2RI16_ins<0b01001, "addiu", IIAlu>,
498 ArithLogic16Defs<0> {
499 let isCodeGenOnly = 1;
502 def AddiuRxRyOffMemX16:
503 FEXT_RRI_A16_mem_ins<0, "addiu", mem16_ea, IIAlu>;
507 // Format: ADDIU rx, pc, immediate MIPS16e
508 // Purpose: Add Immediate Unsigned Word (3-Operand, PC-Relative, Extended)
509 // To add a constant to the program counter.
511 def AddiuRxPcImmX16: FEXT_RI16_PC_ins<0b00001, "addiu", IIAlu>;
514 // Format: ADDIU sp, immediate MIPS16e
515 // Purpose: Add Immediate Unsigned Word (2-Operand, SP-Relative, Extended)
516 // To add a constant to the stack pointer.
519 : FI816_SP_ins<0b011, "addiu", IIAlu> {
522 let AddedComplexity = 5;
526 : FEXT_I816_SP_ins<0b011, "addiu", IIAlu> {
532 // Format: ADDU rz, rx, ry MIPS16e
533 // Purpose: Add Unsigned Word (3-Operand)
534 // To add 32-bit integers.
537 def AdduRxRyRz16: FRRR16_ins<01, "addu", IIAlu>, ArithLogic16Defs<1>;
540 // Format: AND rx, ry MIPS16e
542 // To do a bitwise logical AND.
544 def AndRxRxRy16: FRxRxRy16_ins<0b01100, "and", IIAlu>, ArithLogic16Defs<1>;
548 // Format: BEQZ rx, offset MIPS16e
549 // Purpose: Branch on Equal to Zero
550 // To test a GPR then do a PC-relative conditional branch.
552 def BeqzRxImm16: FRI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
556 // Format: BEQZ rx, offset MIPS16e
557 // Purpose: Branch on Equal to Zero (Extended)
558 // To test a GPR then do a PC-relative conditional branch.
560 def BeqzRxImmX16: FEXT_RI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
562 // Format: B offset MIPS16e
563 // Purpose: Unconditional Branch
564 // To do an unconditional PC-relative branch.
566 def BimmX16: FEXT_I16_ins<0b00010, "b", IIAlu>, branch16;
569 // Format: BNEZ rx, offset MIPS16e
570 // Purpose: Branch on Not Equal to Zero
571 // To test a GPR then do a PC-relative conditional branch.
573 def BnezRxImm16: FRI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
576 // Format: BNEZ rx, offset MIPS16e
577 // Purpose: Branch on Not Equal to Zero (Extended)
578 // To test a GPR then do a PC-relative conditional branch.
580 def BnezRxImmX16: FEXT_RI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
584 //Format: BREAK immediate
585 // Purpose: Breakpoint
586 // To cause a Breakpoint exception.
588 def Break16: FRRBreakNull16_ins<"break 0", NoItinerary>;
590 // Format: BTEQZ offset MIPS16e
591 // Purpose: Branch on T Equal to Zero (Extended)
592 // To test special register T then do a PC-relative conditional branch.
594 def BteqzX16: FEXT_I816_ins<0b000, "bteqz", IIAlu>, cbranch16 {
598 def BteqzT8CmpX16: FEXT_T8I816_ins<"bteqz", "cmp">, cbranch16;
600 def BteqzT8CmpiX16: FEXT_T8I8I16_ins<"bteqz", "cmpi">,
603 def BteqzT8SltX16: FEXT_T8I816_ins<"bteqz", "slt">, cbranch16;
605 def BteqzT8SltuX16: FEXT_T8I816_ins<"bteqz", "sltu">, cbranch16;
607 def BteqzT8SltiX16: FEXT_T8I8I16_ins<"bteqz", "slti">, cbranch16;
609 def BteqzT8SltiuX16: FEXT_T8I8I16_ins<"bteqz", "sltiu">,
613 // Format: BTNEZ offset MIPS16e
614 // Purpose: Branch on T Not Equal to Zero (Extended)
615 // To test special register T then do a PC-relative conditional branch.
617 def BtnezX16: FEXT_I816_ins<0b001, "btnez", IIAlu> ,cbranch16 {
621 def BtnezT8CmpX16: FEXT_T8I816_ins<"btnez", "cmp">, cbranch16;
623 def BtnezT8CmpiX16: FEXT_T8I8I16_ins<"btnez", "cmpi">, cbranch16;
625 def BtnezT8SltX16: FEXT_T8I816_ins<"btnez", "slt">, cbranch16;
627 def BtnezT8SltuX16: FEXT_T8I816_ins<"btnez", "sltu">, cbranch16;
629 def BtnezT8SltiX16: FEXT_T8I8I16_ins<"btnez", "slti">, cbranch16;
631 def BtnezT8SltiuX16: FEXT_T8I8I16_ins<"btnez", "sltiu">,
635 // Format: CMP rx, ry MIPS16e
637 // To compare the contents of two GPRs.
639 def CmpRxRy16: FRR16R_ins<0b01010, "cmp", IIAlu> {
644 // Format: CMPI rx, immediate MIPS16e
645 // Purpose: Compare Immediate
646 // To compare a constant with the contents of a GPR.
648 def CmpiRxImm16: FRI16R_ins<0b01110, "cmpi", IIAlu> {
653 // Format: CMPI rx, immediate MIPS16e
654 // Purpose: Compare Immediate (Extended)
655 // To compare a constant with the contents of a GPR.
657 def CmpiRxImmX16: FEXT_RI16R_ins<0b01110, "cmpi", IIAlu> {
663 // Format: DIV rx, ry MIPS16e
664 // Purpose: Divide Word
665 // To divide 32-bit signed integers.
667 def DivRxRy16: FRR16_div_ins<0b11010, "div", IIAlu> {
672 // Format: DIVU rx, ry MIPS16e
673 // Purpose: Divide Unsigned Word
674 // To divide 32-bit unsigned integers.
676 def DivuRxRy16: FRR16_div_ins<0b11011, "divu", IIAlu> {
680 // Format: JAL target MIPS16e
681 // Purpose: Jump and Link
682 // To execute a procedure call within the current 256 MB-aligned
683 // region and preserve the current ISA.
686 def Jal16 : FJAL16_ins<0b0, "jal", IIAlu> {
688 let hasDelaySlot = 0; // not true, but we add the nop for now
695 // Format: JR ra MIPS16e
696 // Purpose: Jump Register Through Register ra
697 // To execute a branch to the instruction address in the return
701 def JrRa16: FRR16_JALRC_RA_only_ins<0, 0, "jr", IIAlu> {
703 let isIndirectBranch = 1;
704 let hasDelaySlot = 1;
709 def JrcRa16: FRR16_JALRC_RA_only_ins<1, 1, "jrc", IIAlu> {
711 let isIndirectBranch = 1;
716 def JrcRx16: FRR16_JALRC_ins<1, 1, 0, "jrc", IIAlu> {
718 let isIndirectBranch = 1;
723 // Format: LB ry, offset(rx) MIPS16e
724 // Purpose: Load Byte (Extended)
725 // To load a byte from memory as a signed value.
727 def LbRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lb", mem16, IILoad>, MayLoad{
728 let isCodeGenOnly = 1;
732 // Format: LBU ry, offset(rx) MIPS16e
733 // Purpose: Load Byte Unsigned (Extended)
734 // To load a byte from memory as a unsigned value.
736 def LbuRxRyOffMemX16:
737 FEXT_RRI16_mem_ins<0b10100, "lbu", mem16, IILoad>, MayLoad {
738 let isCodeGenOnly = 1;
742 // Format: LH ry, offset(rx) MIPS16e
743 // Purpose: Load Halfword signed (Extended)
744 // To load a halfword from memory as a signed value.
746 def LhRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10100, "lh", mem16, IILoad>, MayLoad{
747 let isCodeGenOnly = 1;
751 // Format: LHU ry, offset(rx) MIPS16e
752 // Purpose: Load Halfword unsigned (Extended)
753 // To load a halfword from memory as an unsigned value.
755 def LhuRxRyOffMemX16:
756 FEXT_RRI16_mem_ins<0b10100, "lhu", mem16, IILoad>, MayLoad {
757 let isCodeGenOnly = 1;
761 // Format: LI rx, immediate MIPS16e
762 // Purpose: Load Immediate
763 // To load a constant into a GPR.
765 def LiRxImm16: FRI16_ins<0b01101, "li", IIAlu>;
768 // Format: LI rx, immediate MIPS16e
769 // Purpose: Load Immediate (Extended)
770 // To load a constant into a GPR.
772 def LiRxImmX16: FEXT_RI16_ins<0b01101, "li", IIAlu>;
775 // Format: LW ry, offset(rx) MIPS16e
776 // Purpose: Load Word (Extended)
777 // To load a word from memory as a signed value.
779 def LwRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lw", mem16, IILoad>, MayLoad{
780 let isCodeGenOnly = 1;
783 // Format: LW rx, offset(sp) MIPS16e
784 // Purpose: Load Word (SP-Relative, Extended)
785 // To load an SP-relative word from memory as a signed value.
787 def LwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b10110, "lw", IILoad>, MayLoad{
792 // Format: MOVE r32, rz MIPS16e
794 // To move the contents of a GPR to a GPR.
796 def Move32R16: FI8_MOV32R16_ins<"move", IIAlu>;
799 // Format: MOVE ry, r32 MIPS16e
801 // To move the contents of a GPR to a GPR.
803 def MoveR3216: FI8_MOVR3216_ins<"move", IIAlu>;
806 // Format: MFHI rx MIPS16e
807 // Purpose: Move From HI Register
808 // To copy the special purpose HI register to a GPR.
810 def Mfhi16: FRR16_M_ins<0b10000, "mfhi", IIAlu> {
812 let neverHasSideEffects = 1;
816 // Format: MFLO rx MIPS16e
817 // Purpose: Move From LO Register
818 // To copy the special purpose LO register to a GPR.
820 def Mflo16: FRR16_M_ins<0b10010, "mflo", IIAlu> {
822 let neverHasSideEffects = 1;
826 // Pseudo Instruction for mult
828 def MultRxRy16: FMULT16_ins<"mult", IIAlu> {
829 let isCommutable = 1;
830 let neverHasSideEffects = 1;
834 def MultuRxRy16: FMULT16_ins<"multu", IIAlu> {
835 let isCommutable = 1;
836 let neverHasSideEffects = 1;
841 // Format: MULT rx, ry MIPS16e
842 // Purpose: Multiply Word
843 // To multiply 32-bit signed integers.
845 def MultRxRyRz16: FMULT16_LO_ins<"mult", IIAlu> {
846 let isCommutable = 1;
847 let neverHasSideEffects = 1;
852 // Format: MULTU rx, ry MIPS16e
853 // Purpose: Multiply Unsigned Word
854 // To multiply 32-bit unsigned integers.
856 def MultuRxRyRz16: FMULT16_LO_ins<"multu", IIAlu> {
857 let isCommutable = 1;
858 let neverHasSideEffects = 1;
863 // Format: NEG rx, ry MIPS16e
865 // To negate an integer value.
867 def NegRxRy16: FUnaryRR16_ins<0b11101, "neg", IIAlu>;
870 // Format: NOT rx, ry MIPS16e
872 // To complement an integer value
874 def NotRxRy16: FUnaryRR16_ins<0b01111, "not", IIAlu>;
877 // Format: OR rx, ry MIPS16e
879 // To do a bitwise logical OR.
881 def OrRxRxRy16: FRxRxRy16_ins<0b01101, "or", IIAlu>, ArithLogic16Defs<1>;
884 // Format: RESTORE {ra,}{s0/s1/s0-1,}{framesize}
885 // (All args are optional) MIPS16e
886 // Purpose: Restore Registers and Deallocate Stack Frame
887 // To deallocate a stack frame before exit from a subroutine,
888 // restoring return address and static registers, and adjusting
892 // fixed form for restoring RA and the frame
893 // for direct object emitter, encoding needs to be adjusted for the
896 let ra=1, s=0,s0=1,s1=1 in
898 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
899 "restore\t$$ra, $$s0, $$s1, $$s2, $frame_size", [], IILoad >, MayLoad {
900 let isCodeGenOnly = 1;
901 let Defs = [S0, S1, S2, RA, SP];
905 // Use Restore to increment SP since SP is not a Mip 16 register, this
906 // is an easy way to do that which does not require a register.
908 let ra=0, s=0,s0=0,s1=0 in
910 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
911 "restore\t$frame_size", [], IILoad >, MayLoad {
912 let isCodeGenOnly = 1;
918 // Format: SAVE {ra,}{s0/s1/s0-1,}{framesize} (All arguments are optional)
920 // Purpose: Save Registers and Set Up Stack Frame
921 // To set up a stack frame on entry to a subroutine,
922 // saving return address and static registers, and adjusting stack
924 let ra=1, s=1,s0=1,s1=1 in
926 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
927 "save\t$$ra, $$s0, $$s1, $$s2, $frame_size", [], IIStore >, MayStore {
928 let isCodeGenOnly = 1;
929 let Uses = [RA, SP, S0, S1, S2];
934 // Use Save to decrement the SP by a constant since SP is not
935 // a Mips16 register.
937 let ra=0, s=0,s0=0,s1=0 in
939 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
940 "save\t$frame_size", [], IIStore >, MayStore {
941 let isCodeGenOnly = 1;
946 // Format: SB ry, offset(rx) MIPS16e
947 // Purpose: Store Byte (Extended)
948 // To store a byte to memory.
951 FEXT_RRI16_mem2_ins<0b11000, "sb", mem16, IIStore>, MayStore;
954 // The Sel(T) instructions are pseudos
955 // T means that they use T8 implicitly.
958 // Format: SelBeqZ rd, rs, rt
959 // Purpose: if rt==0, do nothing
962 def SelBeqZ: Sel<"beqz">;
965 // Format: SelTBteqZCmp rd, rs, rl, rr
966 // Purpose: b = Cmp rl, rr.
967 // If b==0 then do nothing.
968 // if b!=0 then rd = rs
970 def SelTBteqZCmp: SelT<"bteqz", "cmp">;
973 // Format: SelTBteqZCmpi rd, rs, rl, rr
974 // Purpose: b = Cmpi rl, imm.
975 // If b==0 then do nothing.
976 // if b!=0 then rd = rs
978 def SelTBteqZCmpi: SeliT<"bteqz", "cmpi">;
981 // Format: SelTBteqZSlt rd, rs, rl, rr
982 // Purpose: b = Slt rl, rr.
983 // If b==0 then do nothing.
984 // if b!=0 then rd = rs
986 def SelTBteqZSlt: SelT<"bteqz", "slt">;
989 // Format: SelTBteqZSlti rd, rs, rl, rr
990 // Purpose: b = Slti rl, imm.
991 // If b==0 then do nothing.
992 // if b!=0 then rd = rs
994 def SelTBteqZSlti: SeliT<"bteqz", "slti">;
997 // Format: SelTBteqZSltu rd, rs, rl, rr
998 // Purpose: b = Sltu rl, rr.
999 // If b==0 then do nothing.
1000 // if b!=0 then rd = rs
1002 def SelTBteqZSltu: SelT<"bteqz", "sltu">;
1005 // Format: SelTBteqZSltiu rd, rs, rl, rr
1006 // Purpose: b = Sltiu rl, imm.
1007 // If b==0 then do nothing.
1008 // if b!=0 then rd = rs
1010 def SelTBteqZSltiu: SeliT<"bteqz", "sltiu">;
1013 // Format: SelBnez rd, rs, rt
1014 // Purpose: if rt!=0, do nothing
1017 def SelBneZ: Sel<"bnez">;
1020 // Format: SelTBtneZCmp rd, rs, rl, rr
1021 // Purpose: b = Cmp rl, rr.
1022 // If b!=0 then do nothing.
1023 // if b0=0 then rd = rs
1025 def SelTBtneZCmp: SelT<"btnez", "cmp">;
1028 // Format: SelTBtnezCmpi rd, rs, rl, rr
1029 // Purpose: b = Cmpi rl, imm.
1030 // If b!=0 then do nothing.
1031 // if b==0 then rd = rs
1033 def SelTBtneZCmpi: SeliT<"btnez", "cmpi">;
1036 // Format: SelTBtneZSlt rd, rs, rl, rr
1037 // Purpose: b = Slt rl, rr.
1038 // If b!=0 then do nothing.
1039 // if b==0 then rd = rs
1041 def SelTBtneZSlt: SelT<"btnez", "slt">;
1044 // Format: SelTBtneZSlti rd, rs, rl, rr
1045 // Purpose: b = Slti rl, imm.
1046 // If b!=0 then do nothing.
1047 // if b==0 then rd = rs
1049 def SelTBtneZSlti: SeliT<"btnez", "slti">;
1052 // Format: SelTBtneZSltu rd, rs, rl, rr
1053 // Purpose: b = Sltu rl, rr.
1054 // If b!=0 then do nothing.
1055 // if b==0 then rd = rs
1057 def SelTBtneZSltu: SelT<"btnez", "sltu">;
1060 // Format: SelTBtneZSltiu rd, rs, rl, rr
1061 // Purpose: b = Slti rl, imm.
1062 // If b!=0 then do nothing.
1063 // if b==0 then rd = rs
1065 def SelTBtneZSltiu: SeliT<"btnez", "sltiu">;
1068 // Format: SH ry, offset(rx) MIPS16e
1069 // Purpose: Store Halfword (Extended)
1070 // To store a halfword to memory.
1072 def ShRxRyOffMemX16:
1073 FEXT_RRI16_mem2_ins<0b11001, "sh", mem16, IIStore>, MayStore;
1076 // Format: SLL rx, ry, sa MIPS16e
1077 // Purpose: Shift Word Left Logical (Extended)
1078 // To execute a left-shift of a word by a fixed number of bits—0 to 31 bits.
1080 def SllX16: FEXT_SHIFT16_ins<0b00, "sll", IIAlu>;
1083 // Format: SLLV ry, rx MIPS16e
1084 // Purpose: Shift Word Left Logical Variable
1085 // To execute a left-shift of a word by a variable number of bits.
1087 def SllvRxRy16 : FRxRxRy16_ins<0b00100, "sllv", IIAlu>;
1089 // Format: SLTI rx, immediate MIPS16e
1090 // Purpose: Set on Less Than Immediate
1091 // To record the result of a less-than comparison with a constant.
1094 def SltiRxImm16: FRI16R_ins<0b01010, "slti", IIAlu> {
1099 // Format: SLTI rx, immediate MIPS16e
1100 // Purpose: Set on Less Than Immediate (Extended)
1101 // To record the result of a less-than comparison with a constant.
1104 def SltiRxImmX16: FEXT_RI16R_ins<0b01010, "slti", IIAlu> {
1108 def SltiCCRxImmX16: FEXT_CCRXI16_ins<"slti">;
1110 // Format: SLTIU rx, immediate MIPS16e
1111 // Purpose: Set on Less Than Immediate Unsigned
1112 // To record the result of a less-than comparison with a constant.
1115 def SltiuRxImm16: FRI16R_ins<0b01011, "sltiu", IIAlu> {
1120 // Format: SLTI rx, immediate MIPS16e
1121 // Purpose: Set on Less Than Immediate Unsigned (Extended)
1122 // To record the result of a less-than comparison with a constant.
1125 def SltiuRxImmX16: FEXT_RI16R_ins<0b01011, "sltiu", IIAlu> {
1129 // Format: SLTIU rx, immediate MIPS16e
1130 // Purpose: Set on Less Than Immediate Unsigned (Extended)
1131 // To record the result of a less-than comparison with a constant.
1133 def SltiuCCRxImmX16: FEXT_CCRXI16_ins<"sltiu">;
1136 // Format: SLT rx, ry MIPS16e
1137 // Purpose: Set on Less Than
1138 // To record the result of a less-than comparison.
1140 def SltRxRy16: FRR16R_ins<0b00010, "slt", IIAlu>{
1144 def SltCCRxRy16: FCCRR16_ins<"slt">;
1146 // Format: SLTU rx, ry MIPS16e
1147 // Purpose: Set on Less Than Unsigned
1148 // To record the result of an unsigned less-than comparison.
1150 def SltuRxRy16: FRR16R_ins<0b00011, "sltu", IIAlu>{
1154 def SltuRxRyRz16: FRRTR16_ins<"sltu"> {
1155 let isCodeGenOnly=1;
1160 def SltuCCRxRy16: FCCRR16_ins<"sltu">;
1162 // Format: SRAV ry, rx MIPS16e
1163 // Purpose: Shift Word Right Arithmetic Variable
1164 // To execute an arithmetic right-shift of a word by a variable
1167 def SravRxRy16: FRxRxRy16_ins<0b00111, "srav", IIAlu>;
1171 // Format: SRA rx, ry, sa MIPS16e
1172 // Purpose: Shift Word Right Arithmetic (Extended)
1173 // To execute an arithmetic right-shift of a word by a fixed
1174 // number of bits—1 to 8 bits.
1176 def SraX16: FEXT_SHIFT16_ins<0b11, "sra", IIAlu>;
1180 // Format: SRLV ry, rx MIPS16e
1181 // Purpose: Shift Word Right Logical Variable
1182 // To execute a logical right-shift of a word by a variable
1185 def SrlvRxRy16: FRxRxRy16_ins<0b00110, "srlv", IIAlu>;
1189 // Format: SRL rx, ry, sa MIPS16e
1190 // Purpose: Shift Word Right Logical (Extended)
1191 // To execute a logical right-shift of a word by a fixed
1192 // number of bits—1 to 31 bits.
1194 def SrlX16: FEXT_SHIFT16_ins<0b10, "srl", IIAlu>;
1197 // Format: SUBU rz, rx, ry MIPS16e
1198 // Purpose: Subtract Unsigned Word
1199 // To subtract 32-bit integers
1201 def SubuRxRyRz16: FRRR16_ins<0b11, "subu", IIAlu>, ArithLogic16Defs<0>;
1204 // Format: SW ry, offset(rx) MIPS16e
1205 // Purpose: Store Word (Extended)
1206 // To store a word to memory.
1208 def SwRxRyOffMemX16:
1209 FEXT_RRI16_mem2_ins<0b11011, "sw", mem16, IIStore>, MayStore;
1212 // Format: SW rx, offset(sp) MIPS16e
1213 // Purpose: Store Word rx (SP-Relative)
1214 // To store an SP-relative word to memory.
1216 def SwRxSpImmX16: FEXT_RI16_SP_Store_explicit_ins
1217 <0b11010, "sw", IIStore>, MayStore;
1221 // Format: XOR rx, ry MIPS16e
1223 // To do a bitwise logical XOR.
1225 def XorRxRxRy16: FRxRxRy16_ins<0b01110, "xor", IIAlu>, ArithLogic16Defs<1>;
1227 class Mips16Pat<dag pattern, dag result> : Pat<pattern, result> {
1228 let Predicates = [InMips16Mode];
1231 // Unary Arith/Logic
1233 class ArithLogicU_pat<PatFrag OpNode, Instruction I> :
1234 Mips16Pat<(OpNode CPU16Regs:$r),
1237 def: ArithLogicU_pat<not, NotRxRy16>;
1238 def: ArithLogicU_pat<ineg, NegRxRy16>;
1240 class ArithLogic16_pat<SDNode OpNode, Instruction I> :
1241 Mips16Pat<(OpNode CPU16Regs:$l, CPU16Regs:$r),
1242 (I CPU16Regs:$l, CPU16Regs:$r)>;
1244 def: ArithLogic16_pat<add, AdduRxRyRz16>;
1245 def: ArithLogic16_pat<and, AndRxRxRy16>;
1246 def: ArithLogic16_pat<mul, MultRxRyRz16>;
1247 def: ArithLogic16_pat<or, OrRxRxRy16>;
1248 def: ArithLogic16_pat<sub, SubuRxRyRz16>;
1249 def: ArithLogic16_pat<xor, XorRxRxRy16>;
1251 // Arithmetic and logical instructions with 2 register operands.
1253 class ArithLogicI16_pat<SDNode OpNode, PatFrag imm_type, Instruction I> :
1254 Mips16Pat<(OpNode CPU16Regs:$in, imm_type:$imm),
1255 (I CPU16Regs:$in, imm_type:$imm)>;
1257 def: ArithLogicI16_pat<add, immSExt8, AddiuRxRxImm16>;
1258 def: ArithLogicI16_pat<add, immSExt16, AddiuRxRxImmX16>;
1259 def: ArithLogicI16_pat<shl, immZExt5, SllX16>;
1260 def: ArithLogicI16_pat<srl, immZExt5, SrlX16>;
1261 def: ArithLogicI16_pat<sra, immZExt5, SraX16>;
1263 class shift_rotate_reg16_pat<SDNode OpNode, Instruction I> :
1264 Mips16Pat<(OpNode CPU16Regs:$r, CPU16Regs:$ra),
1265 (I CPU16Regs:$r, CPU16Regs:$ra)>;
1267 def: shift_rotate_reg16_pat<shl, SllvRxRy16>;
1268 def: shift_rotate_reg16_pat<sra, SravRxRy16>;
1269 def: shift_rotate_reg16_pat<srl, SrlvRxRy16>;
1271 class LoadM16_pat<PatFrag OpNode, Instruction I> :
1272 Mips16Pat<(OpNode addr16:$addr), (I addr16:$addr)>;
1274 def: LoadM16_pat<sextloadi8, LbRxRyOffMemX16>;
1275 def: LoadM16_pat<zextloadi8, LbuRxRyOffMemX16>;
1276 def: LoadM16_pat<sextloadi16, LhRxRyOffMemX16>;
1277 def: LoadM16_pat<zextloadi16, LhuRxRyOffMemX16>;
1278 def: LoadM16_pat<load, LwRxRyOffMemX16>;
1280 class StoreM16_pat<PatFrag OpNode, Instruction I> :
1281 Mips16Pat<(OpNode CPU16Regs:$r, addr16:$addr),
1282 (I CPU16Regs:$r, addr16:$addr)>;
1284 def: StoreM16_pat<truncstorei8, SbRxRyOffMemX16>;
1285 def: StoreM16_pat<truncstorei16, ShRxRyOffMemX16>;
1286 def: StoreM16_pat<store, SwRxRyOffMemX16>;
1288 // Unconditional branch
1289 class UncondBranch16_pat<SDNode OpNode, Instruction I>:
1290 Mips16Pat<(OpNode bb:$imm16), (I bb:$imm16)> {
1291 let Predicates = [InMips16Mode];
1294 def : Mips16Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
1295 (Jal16 tglobaladdr:$dst)>;
1297 def : Mips16Pat<(MipsJmpLink (i32 texternalsym:$dst)),
1298 (Jal16 texternalsym:$dst)>;
1302 (brind CPU16Regs:$rs),
1303 (JrcRx16 CPU16Regs:$rs)>;
1305 // Jump and Link (Call)
1306 let isCall=1, hasDelaySlot=0 in
1308 FRR16_JALRC<0, 0, 0, (outs), (ins CPU16Regs:$rs),
1309 "jalrc \t$rs", [(MipsJmpLink CPU16Regs:$rs)], IIBranch>;
1312 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1,
1313 hasExtraSrcRegAllocReq = 1 in
1314 def RetRA16 : MipsPseudo16<(outs), (ins), "", [(MipsRet)]>;
1319 class SetCC_R16<PatFrag cond_op, Instruction I>:
1320 Mips16Pat<(cond_op CPU16Regs:$rx, CPU16Regs:$ry),
1321 (I CPU16Regs:$rx, CPU16Regs:$ry)>;
1323 class SetCC_I16<PatFrag cond_op, PatLeaf imm_type, Instruction I>:
1324 Mips16Pat<(cond_op CPU16Regs:$rx, imm_type:$imm16),
1325 (I CPU16Regs:$rx, imm_type:$imm16)>;
1328 def: Mips16Pat<(i32 addr16:$addr),
1329 (AddiuRxRyOffMemX16 addr16:$addr)>;
1332 // Large (>16 bit) immediate loads
1333 def : Mips16Pat<(i32 imm:$imm),
1334 (OrRxRxRy16 (SllX16 (LiRxImmX16 (HI16 imm:$imm)), 16),
1335 (LiRxImmX16 (LO16 imm:$imm)))>;
1337 // Carry MipsPatterns
1338 def : Mips16Pat<(subc CPU16Regs:$lhs, CPU16Regs:$rhs),
1339 (SubuRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1340 def : Mips16Pat<(addc CPU16Regs:$lhs, CPU16Regs:$rhs),
1341 (AdduRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1342 def : Mips16Pat<(addc CPU16Regs:$src, immSExt16:$imm),
1343 (AddiuRxRxImmX16 CPU16Regs:$src, imm:$imm)>;
1346 // Some branch conditional patterns are not generated by llvm at this time.
1347 // Some are for seemingly arbitrary reasons not used: i.e. with signed number
1348 // comparison they are used and for unsigned a different pattern is used.
1349 // I am pushing upstream from the full mips16 port and it seemed that I needed
1350 // these earlier and the mips32 port has these but now I cannot create test
1351 // cases that use these patterns. While I sort this all out I will leave these
1352 // extra patterns commented out and if I can be sure they are really not used,
1353 // I will delete the code. I don't want to check the code in uncommented without
1354 // a valid test case. In some cases, the compiler is generating patterns with
1355 // setcc instead and earlier I had implemented setcc first so may have masked
1356 // the problem. The setcc variants are suboptimal for mips16 so I may wantto
1357 // figure out how to enable the brcond patterns or else possibly new
1358 // combinations of of brcond and setcc.
1364 <(brcond (i32 (seteq CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1365 (BteqzT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1370 <(brcond (i32 (seteq CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1371 (BteqzT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1375 <(brcond (i32 (seteq CPU16Regs:$rx, 0)), bb:$targ16),
1376 (BeqzRxImmX16 CPU16Regs:$rx, bb:$targ16)
1380 // bcond-setgt (do we need to have this pair of setlt, setgt??)
1383 <(brcond (i32 (setgt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1384 (BtnezT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1391 <(brcond (i32 (setge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1392 (BteqzT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1396 // never called because compiler transforms a >= k to a > (k-1)
1398 <(brcond (i32 (setge CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1399 (BteqzT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1406 <(brcond (i32 (setlt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1407 (BtnezT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1411 <(brcond (i32 (setlt CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1412 (BtnezT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1419 <(brcond (i32 (setle CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1420 (BteqzT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1427 <(brcond (i32 (setne CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1428 (BtnezT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1432 <(brcond (i32 (setne CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1433 (BtnezT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1437 <(brcond (i32 (setne CPU16Regs:$rx, 0)), bb:$targ16),
1438 (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1442 // This needs to be there but I forget which code will generate it
1445 <(brcond CPU16Regs:$rx, bb:$targ16),
1446 (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1455 // <(brcond (i32 (setugt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1456 // (BtnezT8SltuX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1463 // <(brcond (i32 (setuge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1464 // (BteqzT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1472 // <(brcond (i32 (setult CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1473 // (BtnezT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1476 def: UncondBranch16_pat<br, BimmX16>;
1479 def: Mips16Pat<(i32 immSExt16:$in),
1480 (AddiuRxRxImmX16 (Move32R16 ZERO), immSExt16:$in)>;
1482 def: Mips16Pat<(i32 immZExt16:$in), (LiRxImmX16 immZExt16:$in)>;
1488 <(MipsDivRem16 CPU16Regs:$rx, CPU16Regs:$ry),
1489 (DivRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1495 <(MipsDivRemU16 CPU16Regs:$rx, CPU16Regs:$ry),
1496 (DivuRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1501 // if !(a < b) x = y
1503 def : Mips16Pat<(select (i32 (setge CPU16Regs:$a, CPU16Regs:$b)),
1504 CPU16Regs:$x, CPU16Regs:$y),
1505 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1506 CPU16Regs:$a, CPU16Regs:$b)>;
1513 def : Mips16Pat<(select (i32 (setgt CPU16Regs:$a, CPU16Regs:$b)),
1514 CPU16Regs:$x, CPU16Regs:$y),
1515 (SelTBtneZSlt CPU16Regs:$x, CPU16Regs:$y,
1516 CPU16Regs:$b, CPU16Regs:$a)>;
1521 // if !(a < b) x = y;
1524 (select (i32 (setuge CPU16Regs:$a, CPU16Regs:$b)),
1525 CPU16Regs:$x, CPU16Regs:$y),
1526 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1527 CPU16Regs:$a, CPU16Regs:$b)>;
1534 def : Mips16Pat<(select (i32 (setugt CPU16Regs:$a, CPU16Regs:$b)),
1535 CPU16Regs:$x, CPU16Regs:$y),
1536 (SelTBtneZSltu CPU16Regs:$x, CPU16Regs:$y,
1537 CPU16Regs:$b, CPU16Regs:$a)>;
1541 // due to an llvm optimization, i don't think that this will ever
1542 // be used. This is transformed into x = (a > k-1)?x:y
1547 // (select (i32 (setge CPU16Regs:$lhs, immSExt16:$rhs)),
1548 // CPU16Regs:$T, CPU16Regs:$F),
1549 // (SelTBteqZSlti CPU16Regs:$T, CPU16Regs:$F,
1550 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1553 // (select (i32 (setuge CPU16Regs:$lhs, immSExt16:$rhs)),
1554 // CPU16Regs:$T, CPU16Regs:$F),
1555 // (SelTBteqZSltiu CPU16Regs:$T, CPU16Regs:$F,
1556 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1561 // if !(a < k) x = y;
1564 (select (i32 (setlt CPU16Regs:$a, immSExt16:$b)),
1565 CPU16Regs:$x, CPU16Regs:$y),
1566 (SelTBtneZSlti CPU16Regs:$x, CPU16Regs:$y,
1567 CPU16Regs:$a, immSExt16:$b)>;
1573 // x = (a <= b)? x : y
1577 def : Mips16Pat<(select (i32 (setle CPU16Regs:$a, CPU16Regs:$b)),
1578 CPU16Regs:$x, CPU16Regs:$y),
1579 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1580 CPU16Regs:$b, CPU16Regs:$a)>;
1584 // x = (a <= b)? x : y
1588 def : Mips16Pat<(select (i32 (setule CPU16Regs:$a, CPU16Regs:$b)),
1589 CPU16Regs:$x, CPU16Regs:$y),
1590 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1591 CPU16Regs:$b, CPU16Regs:$a)>;
1595 // x = (a == b)? x : y
1597 // if (a != b) x = y
1599 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, CPU16Regs:$b)),
1600 CPU16Regs:$x, CPU16Regs:$y),
1601 (SelTBteqZCmp CPU16Regs:$x, CPU16Regs:$y,
1602 CPU16Regs:$b, CPU16Regs:$a)>;
1606 // x = (a == 0)? x : y
1608 // if (a != 0) x = y
1610 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, 0)),
1611 CPU16Regs:$x, CPU16Regs:$y),
1612 (SelBeqZ CPU16Regs:$x, CPU16Regs:$y,
1618 // x = (a == k)? x : y
1620 // if (a != k) x = y
1622 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, immZExt16:$k)),
1623 CPU16Regs:$x, CPU16Regs:$y),
1624 (SelTBteqZCmpi CPU16Regs:$x, CPU16Regs:$y,
1625 CPU16Regs:$a, immZExt16:$k)>;
1630 // x = (a != b)? x : y
1632 // if (a == b) x = y
1635 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, CPU16Regs:$b)),
1636 CPU16Regs:$x, CPU16Regs:$y),
1637 (SelTBtneZCmp CPU16Regs:$x, CPU16Regs:$y,
1638 CPU16Regs:$b, CPU16Regs:$a)>;
1642 // x = (a != 0)? x : y
1644 // if (a == 0) x = y
1646 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, 0)),
1647 CPU16Regs:$x, CPU16Regs:$y),
1648 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1656 def : Mips16Pat<(select CPU16Regs:$a,
1657 CPU16Regs:$x, CPU16Regs:$y),
1658 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1664 // x = (a != k)? x : y
1666 // if (a == k) x = y
1668 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, immZExt16:$k)),
1669 CPU16Regs:$x, CPU16Regs:$y),
1670 (SelTBtneZCmpi CPU16Regs:$x, CPU16Regs:$y,
1671 CPU16Regs:$a, immZExt16:$k)>;
1674 // When writing C code to test setxx these patterns,
1675 // some will be transformed into
1676 // other things. So we test using C code but using -O3 and -O0
1681 <(seteq CPU16Regs:$lhs,CPU16Regs:$rhs),
1682 (SltiuCCRxImmX16 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs), 1)>;
1685 <(seteq CPU16Regs:$lhs, 0),
1686 (SltiuCCRxImmX16 CPU16Regs:$lhs, 1)>;
1694 <(setge CPU16Regs:$lhs, CPU16Regs:$rhs),
1695 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1699 // For constants, llvm transforms this to:
1700 // x > (k -1) and then reverses the operands to use setlt. So this pattern
1701 // is not used now by the compiler. (Presumably checking that k-1 does not
1702 // overflow). The compiler never uses this at a the current time, due to
1703 // other optimizations.
1706 // <(setge CPU16Regs:$lhs, immSExt16:$rhs),
1707 // (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, immSExt16:$rhs),
1708 // (LiRxImmX16 1))>;
1710 // This catches the x >= -32768 case by transforming it to x > -32769
1713 <(setgt CPU16Regs:$lhs, -32769),
1714 (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, -32768),
1723 <(setgt CPU16Regs:$lhs, CPU16Regs:$rhs),
1724 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1730 <(setle CPU16Regs:$lhs, CPU16Regs:$rhs),
1731 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImm16 1))>;
1736 def: SetCC_R16<setlt, SltCCRxRy16>;
1738 def: SetCC_I16<setlt, immSExt16, SltiCCRxImmX16>;
1744 <(setne CPU16Regs:$lhs,CPU16Regs:$rhs),
1745 (SltuCCRxRy16 (LiRxImmX16 0),
1746 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs))>;
1753 <(setuge CPU16Regs:$lhs, CPU16Regs:$rhs),
1754 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1757 // this pattern will never be used because the compiler will transform
1758 // x >= k to x > (k - 1) and then use SLT
1761 // <(setuge CPU16Regs:$lhs, immZExt16:$rhs),
1762 // (XorRxRxRy16 (SltiuCCRxImmX16 CPU16Regs:$lhs, immZExt16:$rhs),
1763 // (LiRxImmX16 1))>;
1769 <(setugt CPU16Regs:$lhs, CPU16Regs:$rhs),
1770 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1776 <(setule CPU16Regs:$lhs, CPU16Regs:$rhs),
1777 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImmX16 1))>;
1782 def: SetCC_R16<setult, SltuCCRxRy16>;
1784 def: SetCC_I16<setult, immSExt16, SltiuCCRxImmX16>;
1786 def: Mips16Pat<(add CPU16Regs:$hi, (MipsLo tglobaladdr:$lo)),
1787 (AddiuRxRxImmX16 CPU16Regs:$hi, tglobaladdr:$lo)>;
1791 def : Mips16Pat<(MipsHi tglobaladdr:$in),
1792 (SllX16 (LiRxImmX16 tglobaladdr:$in), 16)>;
1793 def : Mips16Pat<(MipsHi tjumptable:$in),
1794 (SllX16 (LiRxImmX16 tjumptable:$in), 16)>;
1795 def : Mips16Pat<(MipsHi tglobaltlsaddr:$in),
1796 (SllX16 (LiRxImmX16 tglobaltlsaddr:$in), 16)>;
1799 class Wrapper16Pat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1800 Mips16Pat<(MipsWrapper RC:$gp, node:$in),
1801 (ADDiuOp RC:$gp, node:$in)>;
1804 def : Wrapper16Pat<tglobaladdr, AddiuRxRxImmX16, CPU16Regs>;
1805 def : Wrapper16Pat<tglobaltlsaddr, AddiuRxRxImmX16, CPU16Regs>;
1807 def : Mips16Pat<(i32 (extloadi8 addr16:$src)),
1808 (LbuRxRyOffMemX16 addr16:$src)>;
1809 def : Mips16Pat<(i32 (extloadi16 addr16:$src)),
1810 (LhuRxRyOffMemX16 addr16:$src)>;
1812 def: Mips16Pat<(trap), (Break16)>;