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> {
668 let Defs = [HI0, LO0];
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> {
677 let Defs = [HI0, LO0];
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> {
687 let hasDelaySlot = 0; // not true, but we add the nop for now
692 // Format: JR ra MIPS16e
693 // Purpose: Jump Register Through Register ra
694 // To execute a branch to the instruction address in the return
698 def JrRa16: FRR16_JALRC_RA_only_ins<0, 0, "jr", IIAlu> {
700 let isIndirectBranch = 1;
701 let hasDelaySlot = 1;
706 def JrcRa16: FRR16_JALRC_RA_only_ins<1, 1, "jrc", IIAlu> {
708 let isIndirectBranch = 1;
713 def JrcRx16: FRR16_JALRC_ins<1, 1, 0, "jrc", IIAlu> {
715 let isIndirectBranch = 1;
720 // Format: LB ry, offset(rx) MIPS16e
721 // Purpose: Load Byte (Extended)
722 // To load a byte from memory as a signed value.
724 def LbRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lb", mem16, IILoad>, MayLoad{
725 let isCodeGenOnly = 1;
729 // Format: LBU ry, offset(rx) MIPS16e
730 // Purpose: Load Byte Unsigned (Extended)
731 // To load a byte from memory as a unsigned value.
733 def LbuRxRyOffMemX16:
734 FEXT_RRI16_mem_ins<0b10100, "lbu", mem16, IILoad>, MayLoad {
735 let isCodeGenOnly = 1;
739 // Format: LH ry, offset(rx) MIPS16e
740 // Purpose: Load Halfword signed (Extended)
741 // To load a halfword from memory as a signed value.
743 def LhRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10100, "lh", mem16, IILoad>, MayLoad{
744 let isCodeGenOnly = 1;
748 // Format: LHU ry, offset(rx) MIPS16e
749 // Purpose: Load Halfword unsigned (Extended)
750 // To load a halfword from memory as an unsigned value.
752 def LhuRxRyOffMemX16:
753 FEXT_RRI16_mem_ins<0b10100, "lhu", mem16, IILoad>, MayLoad {
754 let isCodeGenOnly = 1;
758 // Format: LI rx, immediate MIPS16e
759 // Purpose: Load Immediate
760 // To load a constant into a GPR.
762 def LiRxImm16: FRI16_ins<0b01101, "li", IIAlu>;
765 // Format: LI rx, immediate MIPS16e
766 // Purpose: Load Immediate (Extended)
767 // To load a constant into a GPR.
769 def LiRxImmX16: FEXT_RI16_ins<0b01101, "li", IIAlu>;
772 // Format: LW ry, offset(rx) MIPS16e
773 // Purpose: Load Word (Extended)
774 // To load a word from memory as a signed value.
776 def LwRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lw", mem16, IILoad>, MayLoad{
777 let isCodeGenOnly = 1;
780 // Format: LW rx, offset(sp) MIPS16e
781 // Purpose: Load Word (SP-Relative, Extended)
782 // To load an SP-relative word from memory as a signed value.
784 def LwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b10110, "lw", IILoad>, MayLoad{
789 // Format: MOVE r32, rz MIPS16e
791 // To move the contents of a GPR to a GPR.
793 def Move32R16: FI8_MOV32R16_ins<"move", IIAlu>;
796 // Format: MOVE ry, r32 MIPS16e
798 // To move the contents of a GPR to a GPR.
800 def MoveR3216: FI8_MOVR3216_ins<"move", IIAlu>;
803 // Format: MFHI rx MIPS16e
804 // Purpose: Move From HI Register
805 // To copy the special purpose HI register to a GPR.
807 def Mfhi16: FRR16_M_ins<0b10000, "mfhi", IIAlu> {
809 let neverHasSideEffects = 1;
813 // Format: MFLO rx MIPS16e
814 // Purpose: Move From LO Register
815 // To copy the special purpose LO register to a GPR.
817 def Mflo16: FRR16_M_ins<0b10010, "mflo", IIAlu> {
819 let neverHasSideEffects = 1;
823 // Pseudo Instruction for mult
825 def MultRxRy16: FMULT16_ins<"mult", IIAlu> {
826 let isCommutable = 1;
827 let neverHasSideEffects = 1;
828 let Defs = [HI0, LO0];
831 def MultuRxRy16: FMULT16_ins<"multu", IIAlu> {
832 let isCommutable = 1;
833 let neverHasSideEffects = 1;
834 let Defs = [HI0, LO0];
838 // Format: MULT rx, ry MIPS16e
839 // Purpose: Multiply Word
840 // To multiply 32-bit signed integers.
842 def MultRxRyRz16: FMULT16_LO_ins<"mult", IIAlu> {
843 let isCommutable = 1;
844 let neverHasSideEffects = 1;
845 let Defs = [HI0, LO0];
849 // Format: MULTU rx, ry MIPS16e
850 // Purpose: Multiply Unsigned Word
851 // To multiply 32-bit unsigned integers.
853 def MultuRxRyRz16: FMULT16_LO_ins<"multu", IIAlu> {
854 let isCommutable = 1;
855 let neverHasSideEffects = 1;
856 let Defs = [HI0, LO0];
860 // Format: NEG rx, ry MIPS16e
862 // To negate an integer value.
864 def NegRxRy16: FUnaryRR16_ins<0b11101, "neg", IIAlu>;
867 // Format: NOT rx, ry MIPS16e
869 // To complement an integer value
871 def NotRxRy16: FUnaryRR16_ins<0b01111, "not", IIAlu>;
874 // Format: OR rx, ry MIPS16e
876 // To do a bitwise logical OR.
878 def OrRxRxRy16: FRxRxRy16_ins<0b01101, "or", IIAlu>, ArithLogic16Defs<1>;
881 // Format: RESTORE {ra,}{s0/s1/s0-1,}{framesize}
882 // (All args are optional) MIPS16e
883 // Purpose: Restore Registers and Deallocate Stack Frame
884 // To deallocate a stack frame before exit from a subroutine,
885 // restoring return address and static registers, and adjusting
889 // fixed form for restoring RA and the frame
890 // for direct object emitter, encoding needs to be adjusted for the
893 let ra=1, s=0,s0=1,s1=1 in
895 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
896 "restore\t$$ra, $$s0, $$s1, $$s2, $frame_size", [], IILoad >, MayLoad {
897 let isCodeGenOnly = 1;
898 let Defs = [S0, S1, S2, RA, SP];
902 // Use Restore to increment SP since SP is not a Mip 16 register, this
903 // is an easy way to do that which does not require a register.
905 let ra=0, s=0,s0=0,s1=0 in
907 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
908 "restore\t$frame_size", [], IILoad >, MayLoad {
909 let isCodeGenOnly = 1;
915 // Format: SAVE {ra,}{s0/s1/s0-1,}{framesize} (All arguments are optional)
917 // Purpose: Save Registers and Set Up Stack Frame
918 // To set up a stack frame on entry to a subroutine,
919 // saving return address and static registers, and adjusting stack
921 let ra=1, s=1,s0=1,s1=1 in
923 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
924 "save\t$$ra, $$s0, $$s1, $$s2, $frame_size", [], IIStore >, MayStore {
925 let isCodeGenOnly = 1;
926 let Uses = [RA, SP, S0, S1, S2];
931 // Use Save to decrement the SP by a constant since SP is not
932 // a Mips16 register.
934 let ra=0, s=0,s0=0,s1=0 in
936 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
937 "save\t$frame_size", [], IIStore >, MayStore {
938 let isCodeGenOnly = 1;
943 // Format: SB ry, offset(rx) MIPS16e
944 // Purpose: Store Byte (Extended)
945 // To store a byte to memory.
948 FEXT_RRI16_mem2_ins<0b11000, "sb", mem16, IIStore>, MayStore;
951 // The Sel(T) instructions are pseudos
952 // T means that they use T8 implicitly.
955 // Format: SelBeqZ rd, rs, rt
956 // Purpose: if rt==0, do nothing
959 def SelBeqZ: Sel<"beqz">;
962 // Format: SelTBteqZCmp rd, rs, rl, rr
963 // Purpose: b = Cmp rl, rr.
964 // If b==0 then do nothing.
965 // if b!=0 then rd = rs
967 def SelTBteqZCmp: SelT<"bteqz", "cmp">;
970 // Format: SelTBteqZCmpi rd, rs, rl, rr
971 // Purpose: b = Cmpi rl, imm.
972 // If b==0 then do nothing.
973 // if b!=0 then rd = rs
975 def SelTBteqZCmpi: SeliT<"bteqz", "cmpi">;
978 // Format: SelTBteqZSlt rd, rs, rl, rr
979 // Purpose: b = Slt rl, rr.
980 // If b==0 then do nothing.
981 // if b!=0 then rd = rs
983 def SelTBteqZSlt: SelT<"bteqz", "slt">;
986 // Format: SelTBteqZSlti rd, rs, rl, rr
987 // Purpose: b = Slti rl, imm.
988 // If b==0 then do nothing.
989 // if b!=0 then rd = rs
991 def SelTBteqZSlti: SeliT<"bteqz", "slti">;
994 // Format: SelTBteqZSltu rd, rs, rl, rr
995 // Purpose: b = Sltu rl, rr.
996 // If b==0 then do nothing.
997 // if b!=0 then rd = rs
999 def SelTBteqZSltu: SelT<"bteqz", "sltu">;
1002 // Format: SelTBteqZSltiu rd, rs, rl, rr
1003 // Purpose: b = Sltiu rl, imm.
1004 // If b==0 then do nothing.
1005 // if b!=0 then rd = rs
1007 def SelTBteqZSltiu: SeliT<"bteqz", "sltiu">;
1010 // Format: SelBnez rd, rs, rt
1011 // Purpose: if rt!=0, do nothing
1014 def SelBneZ: Sel<"bnez">;
1017 // Format: SelTBtneZCmp rd, rs, rl, rr
1018 // Purpose: b = Cmp rl, rr.
1019 // If b!=0 then do nothing.
1020 // if b0=0 then rd = rs
1022 def SelTBtneZCmp: SelT<"btnez", "cmp">;
1025 // Format: SelTBtnezCmpi rd, rs, rl, rr
1026 // Purpose: b = Cmpi rl, imm.
1027 // If b!=0 then do nothing.
1028 // if b==0 then rd = rs
1030 def SelTBtneZCmpi: SeliT<"btnez", "cmpi">;
1033 // Format: SelTBtneZSlt rd, rs, rl, rr
1034 // Purpose: b = Slt rl, rr.
1035 // If b!=0 then do nothing.
1036 // if b==0 then rd = rs
1038 def SelTBtneZSlt: SelT<"btnez", "slt">;
1041 // Format: SelTBtneZSlti rd, rs, rl, rr
1042 // Purpose: b = Slti rl, imm.
1043 // If b!=0 then do nothing.
1044 // if b==0 then rd = rs
1046 def SelTBtneZSlti: SeliT<"btnez", "slti">;
1049 // Format: SelTBtneZSltu rd, rs, rl, rr
1050 // Purpose: b = Sltu rl, rr.
1051 // If b!=0 then do nothing.
1052 // if b==0 then rd = rs
1054 def SelTBtneZSltu: SelT<"btnez", "sltu">;
1057 // Format: SelTBtneZSltiu rd, rs, rl, rr
1058 // Purpose: b = Slti rl, imm.
1059 // If b!=0 then do nothing.
1060 // if b==0 then rd = rs
1062 def SelTBtneZSltiu: SeliT<"btnez", "sltiu">;
1065 // Format: SH ry, offset(rx) MIPS16e
1066 // Purpose: Store Halfword (Extended)
1067 // To store a halfword to memory.
1069 def ShRxRyOffMemX16:
1070 FEXT_RRI16_mem2_ins<0b11001, "sh", mem16, IIStore>, MayStore;
1073 // Format: SLL rx, ry, sa MIPS16e
1074 // Purpose: Shift Word Left Logical (Extended)
1075 // To execute a left-shift of a word by a fixed number of bits—0 to 31 bits.
1077 def SllX16: FEXT_SHIFT16_ins<0b00, "sll", IIAlu>;
1080 // Format: SLLV ry, rx MIPS16e
1081 // Purpose: Shift Word Left Logical Variable
1082 // To execute a left-shift of a word by a variable number of bits.
1084 def SllvRxRy16 : FRxRxRy16_ins<0b00100, "sllv", IIAlu>;
1086 // Format: SLTI rx, immediate MIPS16e
1087 // Purpose: Set on Less Than Immediate
1088 // To record the result of a less-than comparison with a constant.
1091 def SltiRxImm16: FRI16R_ins<0b01010, "slti", IIAlu> {
1096 // Format: SLTI rx, immediate MIPS16e
1097 // Purpose: Set on Less Than Immediate (Extended)
1098 // To record the result of a less-than comparison with a constant.
1101 def SltiRxImmX16: FEXT_RI16R_ins<0b01010, "slti", IIAlu> {
1105 def SltiCCRxImmX16: FEXT_CCRXI16_ins<"slti">;
1107 // Format: SLTIU rx, immediate MIPS16e
1108 // Purpose: Set on Less Than Immediate Unsigned
1109 // To record the result of a less-than comparison with a constant.
1112 def SltiuRxImm16: FRI16R_ins<0b01011, "sltiu", IIAlu> {
1117 // Format: SLTI rx, immediate MIPS16e
1118 // Purpose: Set on Less Than Immediate Unsigned (Extended)
1119 // To record the result of a less-than comparison with a constant.
1122 def SltiuRxImmX16: FEXT_RI16R_ins<0b01011, "sltiu", IIAlu> {
1126 // Format: SLTIU rx, immediate MIPS16e
1127 // Purpose: Set on Less Than Immediate Unsigned (Extended)
1128 // To record the result of a less-than comparison with a constant.
1130 def SltiuCCRxImmX16: FEXT_CCRXI16_ins<"sltiu">;
1133 // Format: SLT rx, ry MIPS16e
1134 // Purpose: Set on Less Than
1135 // To record the result of a less-than comparison.
1137 def SltRxRy16: FRR16R_ins<0b00010, "slt", IIAlu>{
1141 def SltCCRxRy16: FCCRR16_ins<"slt">;
1143 // Format: SLTU rx, ry MIPS16e
1144 // Purpose: Set on Less Than Unsigned
1145 // To record the result of an unsigned less-than comparison.
1147 def SltuRxRy16: FRR16R_ins<0b00011, "sltu", IIAlu>{
1151 def SltuRxRyRz16: FRRTR16_ins<"sltu"> {
1152 let isCodeGenOnly=1;
1157 def SltuCCRxRy16: FCCRR16_ins<"sltu">;
1159 // Format: SRAV ry, rx MIPS16e
1160 // Purpose: Shift Word Right Arithmetic Variable
1161 // To execute an arithmetic right-shift of a word by a variable
1164 def SravRxRy16: FRxRxRy16_ins<0b00111, "srav", IIAlu>;
1168 // Format: SRA rx, ry, sa MIPS16e
1169 // Purpose: Shift Word Right Arithmetic (Extended)
1170 // To execute an arithmetic right-shift of a word by a fixed
1171 // number of bits—1 to 8 bits.
1173 def SraX16: FEXT_SHIFT16_ins<0b11, "sra", IIAlu>;
1177 // Format: SRLV ry, rx MIPS16e
1178 // Purpose: Shift Word Right Logical Variable
1179 // To execute a logical right-shift of a word by a variable
1182 def SrlvRxRy16: FRxRxRy16_ins<0b00110, "srlv", IIAlu>;
1186 // Format: SRL rx, ry, sa MIPS16e
1187 // Purpose: Shift Word Right Logical (Extended)
1188 // To execute a logical right-shift of a word by a fixed
1189 // number of bits—1 to 31 bits.
1191 def SrlX16: FEXT_SHIFT16_ins<0b10, "srl", IIAlu>;
1194 // Format: SUBU rz, rx, ry MIPS16e
1195 // Purpose: Subtract Unsigned Word
1196 // To subtract 32-bit integers
1198 def SubuRxRyRz16: FRRR16_ins<0b11, "subu", IIAlu>, ArithLogic16Defs<0>;
1201 // Format: SW ry, offset(rx) MIPS16e
1202 // Purpose: Store Word (Extended)
1203 // To store a word to memory.
1205 def SwRxRyOffMemX16:
1206 FEXT_RRI16_mem2_ins<0b11011, "sw", mem16, IIStore>, MayStore;
1209 // Format: SW rx, offset(sp) MIPS16e
1210 // Purpose: Store Word rx (SP-Relative)
1211 // To store an SP-relative word to memory.
1213 def SwRxSpImmX16: FEXT_RI16_SP_Store_explicit_ins
1214 <0b11010, "sw", IIStore>, MayStore;
1218 // Format: XOR rx, ry MIPS16e
1220 // To do a bitwise logical XOR.
1222 def XorRxRxRy16: FRxRxRy16_ins<0b01110, "xor", IIAlu>, ArithLogic16Defs<1>;
1224 class Mips16Pat<dag pattern, dag result> : Pat<pattern, result> {
1225 let Predicates = [InMips16Mode];
1228 // Unary Arith/Logic
1230 class ArithLogicU_pat<PatFrag OpNode, Instruction I> :
1231 Mips16Pat<(OpNode CPU16Regs:$r),
1234 def: ArithLogicU_pat<not, NotRxRy16>;
1235 def: ArithLogicU_pat<ineg, NegRxRy16>;
1237 class ArithLogic16_pat<SDNode OpNode, Instruction I> :
1238 Mips16Pat<(OpNode CPU16Regs:$l, CPU16Regs:$r),
1239 (I CPU16Regs:$l, CPU16Regs:$r)>;
1241 def: ArithLogic16_pat<add, AdduRxRyRz16>;
1242 def: ArithLogic16_pat<and, AndRxRxRy16>;
1243 def: ArithLogic16_pat<mul, MultRxRyRz16>;
1244 def: ArithLogic16_pat<or, OrRxRxRy16>;
1245 def: ArithLogic16_pat<sub, SubuRxRyRz16>;
1246 def: ArithLogic16_pat<xor, XorRxRxRy16>;
1248 // Arithmetic and logical instructions with 2 register operands.
1250 class ArithLogicI16_pat<SDNode OpNode, PatFrag imm_type, Instruction I> :
1251 Mips16Pat<(OpNode CPU16Regs:$in, imm_type:$imm),
1252 (I CPU16Regs:$in, imm_type:$imm)>;
1254 def: ArithLogicI16_pat<add, immSExt8, AddiuRxRxImm16>;
1255 def: ArithLogicI16_pat<add, immSExt16, AddiuRxRxImmX16>;
1256 def: ArithLogicI16_pat<shl, immZExt5, SllX16>;
1257 def: ArithLogicI16_pat<srl, immZExt5, SrlX16>;
1258 def: ArithLogicI16_pat<sra, immZExt5, SraX16>;
1260 class shift_rotate_reg16_pat<SDNode OpNode, Instruction I> :
1261 Mips16Pat<(OpNode CPU16Regs:$r, CPU16Regs:$ra),
1262 (I CPU16Regs:$r, CPU16Regs:$ra)>;
1264 def: shift_rotate_reg16_pat<shl, SllvRxRy16>;
1265 def: shift_rotate_reg16_pat<sra, SravRxRy16>;
1266 def: shift_rotate_reg16_pat<srl, SrlvRxRy16>;
1268 class LoadM16_pat<PatFrag OpNode, Instruction I> :
1269 Mips16Pat<(OpNode addr16:$addr), (I addr16:$addr)>;
1271 def: LoadM16_pat<sextloadi8, LbRxRyOffMemX16>;
1272 def: LoadM16_pat<zextloadi8, LbuRxRyOffMemX16>;
1273 def: LoadM16_pat<sextloadi16, LhRxRyOffMemX16>;
1274 def: LoadM16_pat<zextloadi16, LhuRxRyOffMemX16>;
1275 def: LoadM16_pat<load, LwRxRyOffMemX16>;
1277 class StoreM16_pat<PatFrag OpNode, Instruction I> :
1278 Mips16Pat<(OpNode CPU16Regs:$r, addr16:$addr),
1279 (I CPU16Regs:$r, addr16:$addr)>;
1281 def: StoreM16_pat<truncstorei8, SbRxRyOffMemX16>;
1282 def: StoreM16_pat<truncstorei16, ShRxRyOffMemX16>;
1283 def: StoreM16_pat<store, SwRxRyOffMemX16>;
1285 // Unconditional branch
1286 class UncondBranch16_pat<SDNode OpNode, Instruction I>:
1287 Mips16Pat<(OpNode bb:$imm16), (I bb:$imm16)> {
1288 let Predicates = [InMips16Mode];
1291 def : Mips16Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
1292 (Jal16 tglobaladdr:$dst)>;
1294 def : Mips16Pat<(MipsJmpLink (i32 texternalsym:$dst)),
1295 (Jal16 texternalsym:$dst)>;
1299 (brind CPU16Regs:$rs),
1300 (JrcRx16 CPU16Regs:$rs)>;
1302 // Jump and Link (Call)
1303 let isCall=1, hasDelaySlot=0 in
1305 FRR16_JALRC<0, 0, 0, (outs), (ins CPU16Regs:$rs),
1306 "jalrc \t$rs", [(MipsJmpLink CPU16Regs:$rs)], IIBranch>;
1309 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1,
1310 hasExtraSrcRegAllocReq = 1 in
1311 def RetRA16 : MipsPseudo16<(outs), (ins), "", [(MipsRet)]>;
1316 class SetCC_R16<PatFrag cond_op, Instruction I>:
1317 Mips16Pat<(cond_op CPU16Regs:$rx, CPU16Regs:$ry),
1318 (I CPU16Regs:$rx, CPU16Regs:$ry)>;
1320 class SetCC_I16<PatFrag cond_op, PatLeaf imm_type, Instruction I>:
1321 Mips16Pat<(cond_op CPU16Regs:$rx, imm_type:$imm16),
1322 (I CPU16Regs:$rx, imm_type:$imm16)>;
1325 def: Mips16Pat<(i32 addr16:$addr),
1326 (AddiuRxRyOffMemX16 addr16:$addr)>;
1329 // Large (>16 bit) immediate loads
1330 def : Mips16Pat<(i32 imm:$imm),
1331 (OrRxRxRy16 (SllX16 (LiRxImmX16 (HI16 imm:$imm)), 16),
1332 (LiRxImmX16 (LO16 imm:$imm)))>;
1334 // Carry MipsPatterns
1335 def : Mips16Pat<(subc CPU16Regs:$lhs, CPU16Regs:$rhs),
1336 (SubuRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1337 def : Mips16Pat<(addc CPU16Regs:$lhs, CPU16Regs:$rhs),
1338 (AdduRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1339 def : Mips16Pat<(addc CPU16Regs:$src, immSExt16:$imm),
1340 (AddiuRxRxImmX16 CPU16Regs:$src, imm:$imm)>;
1343 // Some branch conditional patterns are not generated by llvm at this time.
1344 // Some are for seemingly arbitrary reasons not used: i.e. with signed number
1345 // comparison they are used and for unsigned a different pattern is used.
1346 // I am pushing upstream from the full mips16 port and it seemed that I needed
1347 // these earlier and the mips32 port has these but now I cannot create test
1348 // cases that use these patterns. While I sort this all out I will leave these
1349 // extra patterns commented out and if I can be sure they are really not used,
1350 // I will delete the code. I don't want to check the code in uncommented without
1351 // a valid test case. In some cases, the compiler is generating patterns with
1352 // setcc instead and earlier I had implemented setcc first so may have masked
1353 // the problem. The setcc variants are suboptimal for mips16 so I may wantto
1354 // figure out how to enable the brcond patterns or else possibly new
1355 // combinations of of brcond and setcc.
1361 <(brcond (i32 (seteq CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1362 (BteqzT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1367 <(brcond (i32 (seteq CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1368 (BteqzT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1372 <(brcond (i32 (seteq CPU16Regs:$rx, 0)), bb:$targ16),
1373 (BeqzRxImmX16 CPU16Regs:$rx, bb:$targ16)
1377 // bcond-setgt (do we need to have this pair of setlt, setgt??)
1380 <(brcond (i32 (setgt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1381 (BtnezT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1388 <(brcond (i32 (setge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1389 (BteqzT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1393 // never called because compiler transforms a >= k to a > (k-1)
1395 <(brcond (i32 (setge CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1396 (BteqzT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1403 <(brcond (i32 (setlt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1404 (BtnezT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1408 <(brcond (i32 (setlt CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1409 (BtnezT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1416 <(brcond (i32 (setle CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1417 (BteqzT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1424 <(brcond (i32 (setne CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1425 (BtnezT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1429 <(brcond (i32 (setne CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1430 (BtnezT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1434 <(brcond (i32 (setne CPU16Regs:$rx, 0)), bb:$targ16),
1435 (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1439 // This needs to be there but I forget which code will generate it
1442 <(brcond CPU16Regs:$rx, bb:$targ16),
1443 (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1452 // <(brcond (i32 (setugt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1453 // (BtnezT8SltuX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1460 // <(brcond (i32 (setuge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1461 // (BteqzT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1469 // <(brcond (i32 (setult CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1470 // (BtnezT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1473 def: UncondBranch16_pat<br, BimmX16>;
1476 def: Mips16Pat<(i32 immSExt16:$in),
1477 (AddiuRxRxImmX16 (Move32R16 ZERO), immSExt16:$in)>;
1479 def: Mips16Pat<(i32 immZExt16:$in), (LiRxImmX16 immZExt16:$in)>;
1485 <(MipsDivRem16 CPU16Regs:$rx, CPU16Regs:$ry),
1486 (DivRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1492 <(MipsDivRemU16 CPU16Regs:$rx, CPU16Regs:$ry),
1493 (DivuRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1498 // if !(a < b) x = y
1500 def : Mips16Pat<(select (i32 (setge CPU16Regs:$a, CPU16Regs:$b)),
1501 CPU16Regs:$x, CPU16Regs:$y),
1502 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1503 CPU16Regs:$a, CPU16Regs:$b)>;
1510 def : Mips16Pat<(select (i32 (setgt CPU16Regs:$a, CPU16Regs:$b)),
1511 CPU16Regs:$x, CPU16Regs:$y),
1512 (SelTBtneZSlt CPU16Regs:$x, CPU16Regs:$y,
1513 CPU16Regs:$b, CPU16Regs:$a)>;
1518 // if !(a < b) x = y;
1521 (select (i32 (setuge CPU16Regs:$a, CPU16Regs:$b)),
1522 CPU16Regs:$x, CPU16Regs:$y),
1523 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1524 CPU16Regs:$a, CPU16Regs:$b)>;
1531 def : Mips16Pat<(select (i32 (setugt CPU16Regs:$a, CPU16Regs:$b)),
1532 CPU16Regs:$x, CPU16Regs:$y),
1533 (SelTBtneZSltu CPU16Regs:$x, CPU16Regs:$y,
1534 CPU16Regs:$b, CPU16Regs:$a)>;
1538 // due to an llvm optimization, i don't think that this will ever
1539 // be used. This is transformed into x = (a > k-1)?x:y
1544 // (select (i32 (setge CPU16Regs:$lhs, immSExt16:$rhs)),
1545 // CPU16Regs:$T, CPU16Regs:$F),
1546 // (SelTBteqZSlti CPU16Regs:$T, CPU16Regs:$F,
1547 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1550 // (select (i32 (setuge CPU16Regs:$lhs, immSExt16:$rhs)),
1551 // CPU16Regs:$T, CPU16Regs:$F),
1552 // (SelTBteqZSltiu CPU16Regs:$T, CPU16Regs:$F,
1553 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1558 // if !(a < k) x = y;
1561 (select (i32 (setlt CPU16Regs:$a, immSExt16:$b)),
1562 CPU16Regs:$x, CPU16Regs:$y),
1563 (SelTBtneZSlti CPU16Regs:$x, CPU16Regs:$y,
1564 CPU16Regs:$a, immSExt16:$b)>;
1570 // x = (a <= b)? x : y
1574 def : Mips16Pat<(select (i32 (setle CPU16Regs:$a, CPU16Regs:$b)),
1575 CPU16Regs:$x, CPU16Regs:$y),
1576 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1577 CPU16Regs:$b, CPU16Regs:$a)>;
1581 // x = (a <= b)? x : y
1585 def : Mips16Pat<(select (i32 (setule CPU16Regs:$a, CPU16Regs:$b)),
1586 CPU16Regs:$x, CPU16Regs:$y),
1587 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1588 CPU16Regs:$b, CPU16Regs:$a)>;
1592 // x = (a == b)? x : y
1594 // if (a != b) x = y
1596 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, CPU16Regs:$b)),
1597 CPU16Regs:$x, CPU16Regs:$y),
1598 (SelTBteqZCmp CPU16Regs:$x, CPU16Regs:$y,
1599 CPU16Regs:$b, CPU16Regs:$a)>;
1603 // x = (a == 0)? x : y
1605 // if (a != 0) x = y
1607 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, 0)),
1608 CPU16Regs:$x, CPU16Regs:$y),
1609 (SelBeqZ CPU16Regs:$x, CPU16Regs:$y,
1615 // x = (a == k)? x : y
1617 // if (a != k) x = y
1619 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, immZExt16:$k)),
1620 CPU16Regs:$x, CPU16Regs:$y),
1621 (SelTBteqZCmpi CPU16Regs:$x, CPU16Regs:$y,
1622 CPU16Regs:$a, immZExt16:$k)>;
1627 // x = (a != b)? x : y
1629 // if (a == b) x = y
1632 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, CPU16Regs:$b)),
1633 CPU16Regs:$x, CPU16Regs:$y),
1634 (SelTBtneZCmp CPU16Regs:$x, CPU16Regs:$y,
1635 CPU16Regs:$b, CPU16Regs:$a)>;
1639 // x = (a != 0)? x : y
1641 // if (a == 0) x = y
1643 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, 0)),
1644 CPU16Regs:$x, CPU16Regs:$y),
1645 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1653 def : Mips16Pat<(select CPU16Regs:$a,
1654 CPU16Regs:$x, CPU16Regs:$y),
1655 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1661 // x = (a != k)? x : y
1663 // if (a == k) x = y
1665 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, immZExt16:$k)),
1666 CPU16Regs:$x, CPU16Regs:$y),
1667 (SelTBtneZCmpi CPU16Regs:$x, CPU16Regs:$y,
1668 CPU16Regs:$a, immZExt16:$k)>;
1671 // When writing C code to test setxx these patterns,
1672 // some will be transformed into
1673 // other things. So we test using C code but using -O3 and -O0
1678 <(seteq CPU16Regs:$lhs,CPU16Regs:$rhs),
1679 (SltiuCCRxImmX16 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs), 1)>;
1682 <(seteq CPU16Regs:$lhs, 0),
1683 (SltiuCCRxImmX16 CPU16Regs:$lhs, 1)>;
1691 <(setge CPU16Regs:$lhs, CPU16Regs:$rhs),
1692 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1696 // For constants, llvm transforms this to:
1697 // x > (k -1) and then reverses the operands to use setlt. So this pattern
1698 // is not used now by the compiler. (Presumably checking that k-1 does not
1699 // overflow). The compiler never uses this at a the current time, due to
1700 // other optimizations.
1703 // <(setge CPU16Regs:$lhs, immSExt16:$rhs),
1704 // (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, immSExt16:$rhs),
1705 // (LiRxImmX16 1))>;
1707 // This catches the x >= -32768 case by transforming it to x > -32769
1710 <(setgt CPU16Regs:$lhs, -32769),
1711 (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, -32768),
1720 <(setgt CPU16Regs:$lhs, CPU16Regs:$rhs),
1721 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1727 <(setle CPU16Regs:$lhs, CPU16Regs:$rhs),
1728 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImm16 1))>;
1733 def: SetCC_R16<setlt, SltCCRxRy16>;
1735 def: SetCC_I16<setlt, immSExt16, SltiCCRxImmX16>;
1741 <(setne CPU16Regs:$lhs,CPU16Regs:$rhs),
1742 (SltuCCRxRy16 (LiRxImmX16 0),
1743 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs))>;
1750 <(setuge CPU16Regs:$lhs, CPU16Regs:$rhs),
1751 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1754 // this pattern will never be used because the compiler will transform
1755 // x >= k to x > (k - 1) and then use SLT
1758 // <(setuge CPU16Regs:$lhs, immZExt16:$rhs),
1759 // (XorRxRxRy16 (SltiuCCRxImmX16 CPU16Regs:$lhs, immZExt16:$rhs),
1760 // (LiRxImmX16 1))>;
1766 <(setugt CPU16Regs:$lhs, CPU16Regs:$rhs),
1767 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1773 <(setule CPU16Regs:$lhs, CPU16Regs:$rhs),
1774 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImmX16 1))>;
1779 def: SetCC_R16<setult, SltuCCRxRy16>;
1781 def: SetCC_I16<setult, immSExt16, SltiuCCRxImmX16>;
1783 def: Mips16Pat<(add CPU16Regs:$hi, (MipsLo tglobaladdr:$lo)),
1784 (AddiuRxRxImmX16 CPU16Regs:$hi, tglobaladdr:$lo)>;
1788 def : Mips16Pat<(MipsHi tglobaladdr:$in),
1789 (SllX16 (LiRxImmX16 tglobaladdr:$in), 16)>;
1790 def : Mips16Pat<(MipsHi tjumptable:$in),
1791 (SllX16 (LiRxImmX16 tjumptable:$in), 16)>;
1792 def : Mips16Pat<(MipsHi tglobaltlsaddr:$in),
1793 (SllX16 (LiRxImmX16 tglobaltlsaddr:$in), 16)>;
1796 class Wrapper16Pat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1797 Mips16Pat<(MipsWrapper RC:$gp, node:$in),
1798 (ADDiuOp RC:$gp, node:$in)>;
1801 def : Wrapper16Pat<tglobaladdr, AddiuRxRxImmX16, CPU16Regs>;
1802 def : Wrapper16Pat<tglobaltlsaddr, AddiuRxRxImmX16, CPU16Regs>;
1804 def : Mips16Pat<(i32 (extloadi8 addr16:$src)),
1805 (LbuRxRyOffMemX16 addr16:$src)>;
1806 def : Mips16Pat<(i32 (extloadi16 addr16:$src)),
1807 (LhuRxRyOffMemX16 addr16:$src)>;
1809 def: Mips16Pat<(trap), (Break16)>;