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, CPU16Regs);
25 let EncoderMethod = "getMemEncoding";
28 def mem16_ea : Operand<i32> {
29 let PrintMethod = "printMemOperandEA";
30 let MIOperandInfo = (ops CPU16Regs, 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>;
191 // EXT-RRI instruction format
194 class FEXT_RRI16_mem_ins<bits<5> op, string asmstr, Operand MemOpnd,
195 InstrItinClass itin>:
196 FEXT_RRI16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
197 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
199 class FEXT_RRI16_mem2_ins<bits<5> op, string asmstr, Operand MemOpnd,
200 InstrItinClass itin>:
201 FEXT_RRI16<op, (outs ), (ins CPU16Regs:$ry, MemOpnd:$addr),
202 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
206 // EXT-RRI-A instruction format
209 class FEXT_RRI_A16_mem_ins<bits<1> op, string asmstr, Operand MemOpnd,
210 InstrItinClass itin>:
211 FEXT_RRI_A16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
212 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
215 // EXT-SHIFT instruction format
217 class FEXT_SHIFT16_ins<bits<2> _f, string asmstr, InstrItinClass itin>:
218 FEXT_SHIFT16<_f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry, shamt:$sa),
219 !strconcat(asmstr, "\t$rx, $ry, $sa"), [], itin>;
224 class FEXT_T8I816_ins<string asmstr, string asmstr2>:
226 (ins CPU16Regs:$rx, CPU16Regs:$ry, brtarget:$imm),
227 !strconcat(asmstr2, !strconcat("\t$rx, $ry\n\t",
228 !strconcat(asmstr, "\t$imm"))),[]> {
230 let usesCustomInserter = 1;
236 class FEXT_T8I8I16_ins<string asmstr, string asmstr2>:
238 (ins CPU16Regs:$rx, simm16:$imm, brtarget:$targ),
239 !strconcat(asmstr2, !strconcat("\t$rx, $imm\n\t",
240 !strconcat(asmstr, "\t$targ"))), []> {
242 let usesCustomInserter = 1;
248 // I8_MOVR32 instruction format (used only by the MOVR32 instructio
250 class FI8_MOVR3216_ins<string asmstr, InstrItinClass itin>:
251 FI8_MOVR3216<(outs CPU16Regs:$rz), (ins CPURegs:$r32),
252 !strconcat(asmstr, "\t$rz, $r32"), [], itin>;
255 // I8_MOV32R instruction format (used only by MOV32R instruction)
258 class FI8_MOV32R16_ins<string asmstr, InstrItinClass itin>:
259 FI8_MOV32R16<(outs CPURegs:$r32), (ins CPU16Regs:$rz),
260 !strconcat(asmstr, "\t$r32, $rz"), [], itin>;
263 // This are pseudo formats for multiply
264 // This first one can be changed to non pseudo now.
268 class FMULT16_ins<string asmstr, InstrItinClass itin> :
269 MipsPseudo16<(outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
270 !strconcat(asmstr, "\t$rx, $ry"), []>;
275 class FMULT16_LO_ins<string asmstr, InstrItinClass itin> :
276 MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
277 !strconcat(asmstr, "\t$rx, $ry\n\tmflo\t$rz"), []> {
282 // RR-type instruction format
285 class FRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
286 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
287 !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
290 class FRR16R_ins<bits<5> f, string asmstr, InstrItinClass itin> :
291 FRR16<f, (outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
292 !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
295 class FRRTR16_ins<string asmstr> :
296 MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
297 !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$rz, $$t8"), []> ;
300 // maybe refactor but need a $zero as a dummy first parameter
302 class FRR16_div_ins<bits<5> f, string asmstr, InstrItinClass itin> :
303 FRR16<f, (outs ), (ins CPU16Regs:$rx, CPU16Regs:$ry),
304 !strconcat(asmstr, "\t$$zero, $rx, $ry"), [], itin> ;
306 class FUnaryRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
307 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
308 !strconcat(asmstr, "\t$rx, $ry"), [], itin> ;
311 class FRR16_M_ins<bits<5> f, string asmstr,
312 InstrItinClass itin> :
313 FRR16<f, (outs CPU16Regs:$rx), (ins),
314 !strconcat(asmstr, "\t$rx"), [], itin>;
316 class FRxRxRy16_ins<bits<5> f, string asmstr,
317 InstrItinClass itin> :
318 FRR16<f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
319 !strconcat(asmstr, "\t$rz, $ry"),
321 let Constraints = "$rx = $rz";
325 class FRR16_JALRC_RA_only_ins<bits<1> nd_, bits<1> l_,
326 string asmstr, InstrItinClass itin>:
327 FRR16_JALRC<nd_, l_, 1, (outs), (ins), !strconcat(asmstr, "\t $$ra"),
331 class FRR16_JALRC_ins<bits<1> nd, bits<1> l, bits<1> ra,
332 string asmstr, InstrItinClass itin>:
333 FRR16_JALRC<nd, l, ra, (outs), (ins CPU16Regs:$rx),
334 !strconcat(asmstr, "\t $rx"), [], itin> ;
337 // RRR-type instruction format
340 class FRRR16_ins<bits<2> _f, string asmstr, InstrItinClass itin> :
341 FRRR16<_f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
342 !strconcat(asmstr, "\t$rz, $rx, $ry"), [], itin>;
345 // These Sel patterns support the generation of conditional move
346 // pseudo instructions.
348 // The nomenclature uses the components making up the pseudo and may
349 // be a bit counter intuitive when compared with the end result we seek.
350 // For example using a bqez in the example directly below results in the
351 // conditional move being done if the tested register is not zero.
352 // I considered in easier to check by keeping the pseudo consistent with
353 // it's components but it could have been done differently.
355 // The simplest case is when can test and operand directly and do the
356 // conditional move based on a simple mips16 conditional
357 // branch instruction.
359 // if $op == beqz or bnez:
364 // if $op == beqz, then if $rt != 0, then the conditional assignment
365 // $rd = $rs is done.
367 // if $op == bnez, then if $rt == 0, then the conditional assignment
368 // $rd = $rs is done.
370 // So this pseudo class only has one operand, i.e. op
372 class Sel<string op>:
373 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
375 !strconcat(op, "\t$rt, .+4\n\t\n\tmove $rd, $rs"), []> {
376 //let isCodeGenOnly=1;
377 let Constraints = "$rd = $rd_";
378 let usesCustomInserter = 1;
382 // The next two instruction classes allow for an operand which tests
383 // two operands and returns a value in register T8 and
384 //then does a conditional branch based on the value of T8
387 // op2 can be cmpi or slti/sltiu
388 // op1 can bteqz or btnez
389 // the operands for op2 are a register and a signed constant
391 // $op2 $t, $imm ;test register t and branch conditionally
392 // $op1 .+4 ;op1 is a conditional branch
396 class SeliT<string op1, string op2>:
397 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
398 CPU16Regs:$rl, simm16:$imm),
400 !strconcat("\t$rl, $imm\n\t",
401 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
403 let Constraints = "$rd = $rd_";
404 let usesCustomInserter = 1;
408 // op2 can be cmp or slt/sltu
409 // op1 can be bteqz or btnez
410 // the operands for op2 are two registers
411 // op1 is a conditional branch
414 // $op2 $rl, $rr ;test registers rl,rr
415 // $op1 .+4 ;op2 is a conditional branch
419 class SelT<string op1, string op2>:
420 MipsPseudo16<(outs CPU16Regs:$rd_),
421 (ins CPU16Regs:$rd, CPU16Regs:$rs,
422 CPU16Regs:$rl, CPU16Regs:$rr),
424 !strconcat("\t$rl, $rr\n\t",
425 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
427 let Constraints = "$rd = $rd_";
428 let usesCustomInserter = 1;
434 def imm32: Operand<i32>;
437 MipsPseudo16<(outs), (ins imm32:$imm), "\t.word $imm", []>;
440 MipsPseudo16<(outs), (ins CPU16Regs:$rx, imm32:$imm),
441 "lw\t$rx, 1f\n\tb\t2f\n\t.align\t2\n1: \t.word\t$imm\n2:", []>;
445 // Some general instruction class info
449 class ArithLogic16Defs<bit isCom=0> {
451 bit isCommutable = isCom;
452 bit isReMaterializable = 1;
453 bit neverHasSideEffects = 1;
458 bit isTerminator = 1;
464 bit isTerminator = 1;
477 // Format: ADDIU rx, immediate MIPS16e
478 // Purpose: Add Immediate Unsigned Word (2-Operand, Extended)
479 // To add a constant to a 32-bit integer.
481 def AddiuRxImmX16: FEXT_RI16_ins<0b01001, "addiu", IIAlu>;
483 def AddiuRxRxImm16: F2RI16_ins<0b01001, "addiu", IIAlu>,
484 ArithLogic16Defs<0> {
485 let AddedComplexity = 5;
487 def AddiuRxRxImmX16: FEXT_2RI16_ins<0b01001, "addiu", IIAlu>,
488 ArithLogic16Defs<0> {
489 let isCodeGenOnly = 1;
492 def AddiuRxRyOffMemX16:
493 FEXT_RRI_A16_mem_ins<0, "addiu", mem16_ea, IIAlu>;
497 // Format: ADDIU rx, pc, immediate MIPS16e
498 // Purpose: Add Immediate Unsigned Word (3-Operand, PC-Relative, Extended)
499 // To add a constant to the program counter.
501 def AddiuRxPcImmX16: FEXT_RI16_PC_ins<0b00001, "addiu", IIAlu>;
504 // Format: ADDIU sp, immediate MIPS16e
505 // Purpose: Add Immediate Unsigned Word (2-Operand, SP-Relative, Extended)
506 // To add a constant to the stack pointer.
509 : FI816_SP_ins<0b011, "addiu", IIAlu> {
512 let AddedComplexity = 5;
516 : FEXT_I816_SP_ins<0b011, "addiu", IIAlu> {
522 // Format: ADDU rz, rx, ry MIPS16e
523 // Purpose: Add Unsigned Word (3-Operand)
524 // To add 32-bit integers.
527 def AdduRxRyRz16: FRRR16_ins<01, "addu", IIAlu>, ArithLogic16Defs<1>;
530 // Format: AND rx, ry MIPS16e
532 // To do a bitwise logical AND.
534 def AndRxRxRy16: FRxRxRy16_ins<0b01100, "and", IIAlu>, ArithLogic16Defs<1>;
538 // Format: BEQZ rx, offset MIPS16e
539 // Purpose: Branch on Equal to Zero
540 // To test a GPR then do a PC-relative conditional branch.
542 def BeqzRxImm16: FRI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
546 // Format: BEQZ rx, offset MIPS16e
547 // Purpose: Branch on Equal to Zero (Extended)
548 // To test a GPR then do a PC-relative conditional branch.
550 def BeqzRxImmX16: FEXT_RI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
552 // Format: B offset MIPS16e
553 // Purpose: Unconditional Branch
554 // To do an unconditional PC-relative branch.
556 def BimmX16: FEXT_I16_ins<0b00010, "b", IIAlu>, branch16;
559 // Format: BNEZ rx, offset MIPS16e
560 // Purpose: Branch on Not Equal to Zero
561 // To test a GPR then do a PC-relative conditional branch.
563 def BnezRxImm16: FRI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
566 // Format: BNEZ rx, offset MIPS16e
567 // Purpose: Branch on Not Equal to Zero (Extended)
568 // To test a GPR then do a PC-relative conditional branch.
570 def BnezRxImmX16: FEXT_RI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
573 // Format: BTEQZ offset MIPS16e
574 // Purpose: Branch on T Equal to Zero (Extended)
575 // To test special register T then do a PC-relative conditional branch.
577 def BteqzX16: FEXT_I816_ins<0b000, "bteqz", IIAlu>, cbranch16 {
581 def BteqzT8CmpX16: FEXT_T8I816_ins<"bteqz", "cmp">, cbranch16;
583 def BteqzT8CmpiX16: FEXT_T8I8I16_ins<"bteqz", "cmpi">,
586 def BteqzT8SltX16: FEXT_T8I816_ins<"bteqz", "slt">, cbranch16;
588 def BteqzT8SltuX16: FEXT_T8I816_ins<"bteqz", "sltu">, cbranch16;
590 def BteqzT8SltiX16: FEXT_T8I8I16_ins<"bteqz", "slti">, cbranch16;
592 def BteqzT8SltiuX16: FEXT_T8I8I16_ins<"bteqz", "sltiu">,
596 // Format: BTNEZ offset MIPS16e
597 // Purpose: Branch on T Not Equal to Zero (Extended)
598 // To test special register T then do a PC-relative conditional branch.
600 def BtnezX16: FEXT_I816_ins<0b001, "btnez", IIAlu> ,cbranch16 {
604 def BtnezT8CmpX16: FEXT_T8I816_ins<"btnez", "cmp">, cbranch16;
606 def BtnezT8CmpiX16: FEXT_T8I8I16_ins<"btnez", "cmpi">, cbranch16;
608 def BtnezT8SltX16: FEXT_T8I816_ins<"btnez", "slt">, cbranch16;
610 def BtnezT8SltuX16: FEXT_T8I816_ins<"btnez", "sltu">, cbranch16;
612 def BtnezT8SltiX16: FEXT_T8I8I16_ins<"btnez", "slti">, cbranch16;
614 def BtnezT8SltiuX16: FEXT_T8I8I16_ins<"btnez", "sltiu">,
618 // Format: CMP rx, ry MIPS16e
620 // To compare the contents of two GPRs.
622 def CmpRxRy16: FRR16R_ins<0b01010, "cmp", IIAlu> {
627 // Format: CMPI rx, immediate MIPS16e
628 // Purpose: Compare Immediate
629 // To compare a constant with the contents of a GPR.
631 def CmpiRxImm16: FRI16R_ins<0b01110, "cmpi", IIAlu> {
636 // Format: CMPI rx, immediate MIPS16e
637 // Purpose: Compare Immediate (Extended)
638 // To compare a constant with the contents of a GPR.
640 def CmpiRxImmX16: FEXT_RI16R_ins<0b01110, "cmpi", IIAlu> {
646 // Format: DIV rx, ry MIPS16e
647 // Purpose: Divide Word
648 // To divide 32-bit signed integers.
650 def DivRxRy16: FRR16_div_ins<0b11010, "div", IIAlu> {
655 // Format: DIVU rx, ry MIPS16e
656 // Purpose: Divide Unsigned Word
657 // To divide 32-bit unsigned integers.
659 def DivuRxRy16: FRR16_div_ins<0b11011, "divu", IIAlu> {
663 // Format: JAL target MIPS16e
664 // Purpose: Jump and Link
665 // To execute a procedure call within the current 256 MB-aligned
666 // region and preserve the current ISA.
669 def Jal16 : FJAL16_ins<0b0, "jal", IIAlu> {
671 let hasDelaySlot = 0; // not true, but we add the nop for now
678 // Format: JR ra MIPS16e
679 // Purpose: Jump Register Through Register ra
680 // To execute a branch to the instruction address in the return
684 def JrRa16: FRR16_JALRC_RA_only_ins<0, 0, "jr", IIAlu> {
686 let isIndirectBranch = 1;
687 let hasDelaySlot = 1;
692 def JrcRa16: FRR16_JALRC_RA_only_ins<1, 1, "jrc", IIAlu> {
694 let isIndirectBranch = 1;
699 def JrcRx16: FRR16_JALRC_ins<1, 1, 0, "jrc", IIAlu> {
701 let isIndirectBranch = 1;
706 // Format: LB ry, offset(rx) MIPS16e
707 // Purpose: Load Byte (Extended)
708 // To load a byte from memory as a signed value.
710 def LbRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lb", mem16, IILoad>, MayLoad{
711 let isCodeGenOnly = 1;
715 // Format: LBU ry, offset(rx) MIPS16e
716 // Purpose: Load Byte Unsigned (Extended)
717 // To load a byte from memory as a unsigned value.
719 def LbuRxRyOffMemX16:
720 FEXT_RRI16_mem_ins<0b10100, "lbu", mem16, IILoad>, MayLoad {
721 let isCodeGenOnly = 1;
725 // Format: LH ry, offset(rx) MIPS16e
726 // Purpose: Load Halfword signed (Extended)
727 // To load a halfword from memory as a signed value.
729 def LhRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10100, "lh", mem16, IILoad>, MayLoad{
730 let isCodeGenOnly = 1;
734 // Format: LHU ry, offset(rx) MIPS16e
735 // Purpose: Load Halfword unsigned (Extended)
736 // To load a halfword from memory as an unsigned value.
738 def LhuRxRyOffMemX16:
739 FEXT_RRI16_mem_ins<0b10100, "lhu", mem16, IILoad>, MayLoad {
740 let isCodeGenOnly = 1;
744 // Format: LI rx, immediate MIPS16e
745 // Purpose: Load Immediate
746 // To load a constant into a GPR.
748 def LiRxImm16: FRI16_ins<0b01101, "li", IIAlu>;
751 // Format: LI rx, immediate MIPS16e
752 // Purpose: Load Immediate (Extended)
753 // To load a constant into a GPR.
755 def LiRxImmX16: FEXT_RI16_ins<0b01101, "li", IIAlu>;
758 // Format: LW ry, offset(rx) MIPS16e
759 // Purpose: Load Word (Extended)
760 // To load a word from memory as a signed value.
762 def LwRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lw", mem16, IILoad>, MayLoad{
763 let isCodeGenOnly = 1;
766 // Format: LW rx, offset(sp) MIPS16e
767 // Purpose: Load Word (SP-Relative, Extended)
768 // To load an SP-relative word from memory as a signed value.
770 def LwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b10110, "lw", IILoad>, MayLoad{
775 // Format: MOVE r32, rz MIPS16e
777 // To move the contents of a GPR to a GPR.
779 def Move32R16: FI8_MOV32R16_ins<"move", IIAlu>;
782 // Format: MOVE ry, r32 MIPS16e
784 // To move the contents of a GPR to a GPR.
786 def MoveR3216: FI8_MOVR3216_ins<"move", IIAlu>;
789 // Format: MFHI rx MIPS16e
790 // Purpose: Move From HI Register
791 // To copy the special purpose HI register to a GPR.
793 def Mfhi16: FRR16_M_ins<0b10000, "mfhi", IIAlu> {
795 let neverHasSideEffects = 1;
799 // Format: MFLO rx MIPS16e
800 // Purpose: Move From LO Register
801 // To copy the special purpose LO register to a GPR.
803 def Mflo16: FRR16_M_ins<0b10010, "mflo", IIAlu> {
805 let neverHasSideEffects = 1;
809 // Pseudo Instruction for mult
811 def MultRxRy16: FMULT16_ins<"mult", IIAlu> {
812 let isCommutable = 1;
813 let neverHasSideEffects = 1;
817 def MultuRxRy16: FMULT16_ins<"multu", IIAlu> {
818 let isCommutable = 1;
819 let neverHasSideEffects = 1;
824 // Format: MULT rx, ry MIPS16e
825 // Purpose: Multiply Word
826 // To multiply 32-bit signed integers.
828 def MultRxRyRz16: FMULT16_LO_ins<"mult", IIAlu> {
829 let isCommutable = 1;
830 let neverHasSideEffects = 1;
835 // Format: MULTU rx, ry MIPS16e
836 // Purpose: Multiply Unsigned Word
837 // To multiply 32-bit unsigned integers.
839 def MultuRxRyRz16: FMULT16_LO_ins<"multu", IIAlu> {
840 let isCommutable = 1;
841 let neverHasSideEffects = 1;
846 // Format: NEG rx, ry MIPS16e
848 // To negate an integer value.
850 def NegRxRy16: FUnaryRR16_ins<0b11101, "neg", IIAlu>;
853 // Format: NOT rx, ry MIPS16e
855 // To complement an integer value
857 def NotRxRy16: FUnaryRR16_ins<0b01111, "not", IIAlu>;
860 // Format: OR rx, ry MIPS16e
862 // To do a bitwise logical OR.
864 def OrRxRxRy16: FRxRxRy16_ins<0b01101, "or", IIAlu>, ArithLogic16Defs<1>;
867 // Format: RESTORE {ra,}{s0/s1/s0-1,}{framesize}
868 // (All args are optional) MIPS16e
869 // Purpose: Restore Registers and Deallocate Stack Frame
870 // To deallocate a stack frame before exit from a subroutine,
871 // restoring return address and static registers, and adjusting
875 // fixed form for restoring RA and the frame
876 // for direct object emitter, encoding needs to be adjusted for the
879 let ra=1, s=0,s0=1,s1=1 in
881 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
882 "restore\t$$ra, $$s0, $$s1, $frame_size", [], IILoad >, MayLoad {
883 let isCodeGenOnly = 1;
884 let Defs = [S0, S1, RA, SP];
888 // Use Restore to increment SP since SP is not a Mip 16 register, this
889 // is an easy way to do that which does not require a register.
891 let ra=0, s=0,s0=0,s1=0 in
893 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
894 "restore\t$frame_size", [], IILoad >, MayLoad {
895 let isCodeGenOnly = 1;
901 // Format: SAVE {ra,}{s0/s1/s0-1,}{framesize} (All arguments are optional)
903 // Purpose: Save Registers and Set Up Stack Frame
904 // To set up a stack frame on entry to a subroutine,
905 // saving return address and static registers, and adjusting stack
907 let ra=1, s=1,s0=1,s1=1 in
909 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
910 "save\t$$ra, $$s0, $$s1, $frame_size", [], IIStore >, MayStore {
911 let isCodeGenOnly = 1;
912 let Uses = [RA, SP, S0, S1];
917 // Use Save to decrement the SP by a constant since SP is not
918 // a Mips16 register.
920 let ra=0, s=0,s0=0,s1=0 in
922 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
923 "save\t$frame_size", [], IIStore >, MayStore {
924 let isCodeGenOnly = 1;
929 // Format: SB ry, offset(rx) MIPS16e
930 // Purpose: Store Byte (Extended)
931 // To store a byte to memory.
934 FEXT_RRI16_mem2_ins<0b11000, "sb", mem16, IIStore>, MayStore;
937 // The Sel(T) instructions are pseudos
938 // T means that they use T8 implicitly.
941 // Format: SelBeqZ rd, rs, rt
942 // Purpose: if rt==0, do nothing
945 def SelBeqZ: Sel<"beqz">;
948 // Format: SelTBteqZCmp rd, rs, rl, rr
949 // Purpose: b = Cmp rl, rr.
950 // If b==0 then do nothing.
951 // if b!=0 then rd = rs
953 def SelTBteqZCmp: SelT<"bteqz", "cmp">;
956 // Format: SelTBteqZCmpi rd, rs, rl, rr
957 // Purpose: b = Cmpi rl, imm.
958 // If b==0 then do nothing.
959 // if b!=0 then rd = rs
961 def SelTBteqZCmpi: SeliT<"bteqz", "cmpi">;
964 // Format: SelTBteqZSlt rd, rs, rl, rr
965 // Purpose: b = Slt rl, rr.
966 // If b==0 then do nothing.
967 // if b!=0 then rd = rs
969 def SelTBteqZSlt: SelT<"bteqz", "slt">;
972 // Format: SelTBteqZSlti rd, rs, rl, rr
973 // Purpose: b = Slti rl, imm.
974 // If b==0 then do nothing.
975 // if b!=0 then rd = rs
977 def SelTBteqZSlti: SeliT<"bteqz", "slti">;
980 // Format: SelTBteqZSltu rd, rs, rl, rr
981 // Purpose: b = Sltu rl, rr.
982 // If b==0 then do nothing.
983 // if b!=0 then rd = rs
985 def SelTBteqZSltu: SelT<"bteqz", "sltu">;
988 // Format: SelTBteqZSltiu rd, rs, rl, rr
989 // Purpose: b = Sltiu rl, imm.
990 // If b==0 then do nothing.
991 // if b!=0 then rd = rs
993 def SelTBteqZSltiu: SeliT<"bteqz", "sltiu">;
996 // Format: SelBnez rd, rs, rt
997 // Purpose: if rt!=0, do nothing
1000 def SelBneZ: Sel<"bnez">;
1003 // Format: SelTBtneZCmp rd, rs, rl, rr
1004 // Purpose: b = Cmp rl, rr.
1005 // If b!=0 then do nothing.
1006 // if b0=0 then rd = rs
1008 def SelTBtneZCmp: SelT<"btnez", "cmp">;
1011 // Format: SelTBtnezCmpi rd, rs, rl, rr
1012 // Purpose: b = Cmpi rl, imm.
1013 // If b!=0 then do nothing.
1014 // if b==0 then rd = rs
1016 def SelTBtneZCmpi: SeliT<"btnez", "cmpi">;
1019 // Format: SelTBtneZSlt rd, rs, rl, rr
1020 // Purpose: b = Slt rl, rr.
1021 // If b!=0 then do nothing.
1022 // if b==0 then rd = rs
1024 def SelTBtneZSlt: SelT<"btnez", "slt">;
1027 // Format: SelTBtneZSlti rd, rs, rl, rr
1028 // Purpose: b = Slti rl, imm.
1029 // If b!=0 then do nothing.
1030 // if b==0 then rd = rs
1032 def SelTBtneZSlti: SeliT<"btnez", "slti">;
1035 // Format: SelTBtneZSltu rd, rs, rl, rr
1036 // Purpose: b = Sltu rl, rr.
1037 // If b!=0 then do nothing.
1038 // if b==0 then rd = rs
1040 def SelTBtneZSltu: SelT<"btnez", "sltu">;
1043 // Format: SelTBtneZSltiu rd, rs, rl, rr
1044 // Purpose: b = Slti rl, imm.
1045 // If b!=0 then do nothing.
1046 // if b==0 then rd = rs
1048 def SelTBtneZSltiu: SeliT<"btnez", "sltiu">;
1051 // Format: SH ry, offset(rx) MIPS16e
1052 // Purpose: Store Halfword (Extended)
1053 // To store a halfword to memory.
1055 def ShRxRyOffMemX16:
1056 FEXT_RRI16_mem2_ins<0b11001, "sh", mem16, IIStore>, MayStore;
1059 // Format: SLL rx, ry, sa MIPS16e
1060 // Purpose: Shift Word Left Logical (Extended)
1061 // To execute a left-shift of a word by a fixed number of bits—0 to 31 bits.
1063 def SllX16: FEXT_SHIFT16_ins<0b00, "sll", IIAlu>;
1066 // Format: SLLV ry, rx MIPS16e
1067 // Purpose: Shift Word Left Logical Variable
1068 // To execute a left-shift of a word by a variable number of bits.
1070 def SllvRxRy16 : FRxRxRy16_ins<0b00100, "sllv", IIAlu>;
1072 // Format: SLTI rx, immediate MIPS16e
1073 // Purpose: Set on Less Than Immediate
1074 // To record the result of a less-than comparison with a constant.
1077 def SltiRxImm16: FRI16R_ins<0b01010, "slti", IIAlu> {
1082 // Format: SLTI rx, immediate MIPS16e
1083 // Purpose: Set on Less Than Immediate (Extended)
1084 // To record the result of a less-than comparison with a constant.
1087 def SltiRxImmX16: FEXT_RI16R_ins<0b01010, "slti", IIAlu> {
1091 def SltiCCRxImmX16: FEXT_CCRXI16_ins<"slti">;
1093 // Format: SLTIU rx, immediate MIPS16e
1094 // Purpose: Set on Less Than Immediate Unsigned
1095 // To record the result of a less-than comparison with a constant.
1098 def SltiuRxImm16: FRI16R_ins<0b01011, "sltiu", IIAlu> {
1103 // Format: SLTI rx, immediate MIPS16e
1104 // Purpose: Set on Less Than Immediate Unsigned (Extended)
1105 // To record the result of a less-than comparison with a constant.
1108 def SltiuRxImmX16: FEXT_RI16R_ins<0b01011, "sltiu", IIAlu> {
1112 // Format: SLTIU rx, immediate MIPS16e
1113 // Purpose: Set on Less Than Immediate Unsigned (Extended)
1114 // To record the result of a less-than comparison with a constant.
1116 def SltiuCCRxImmX16: FEXT_CCRXI16_ins<"sltiu">;
1119 // Format: SLT rx, ry MIPS16e
1120 // Purpose: Set on Less Than
1121 // To record the result of a less-than comparison.
1123 def SltRxRy16: FRR16R_ins<0b00010, "slt", IIAlu>{
1127 def SltCCRxRy16: FCCRR16_ins<"slt">;
1129 // Format: SLTU rx, ry MIPS16e
1130 // Purpose: Set on Less Than Unsigned
1131 // To record the result of an unsigned less-than comparison.
1133 def SltuRxRy16: FRR16R_ins<0b00011, "sltu", IIAlu>{
1137 def SltuRxRyRz16: FRRTR16_ins<"sltu"> {
1138 let isCodeGenOnly=1;
1143 def SltuCCRxRy16: FCCRR16_ins<"sltu">;
1145 // Format: SRAV ry, rx MIPS16e
1146 // Purpose: Shift Word Right Arithmetic Variable
1147 // To execute an arithmetic right-shift of a word by a variable
1150 def SravRxRy16: FRxRxRy16_ins<0b00111, "srav", IIAlu>;
1154 // Format: SRA rx, ry, sa MIPS16e
1155 // Purpose: Shift Word Right Arithmetic (Extended)
1156 // To execute an arithmetic right-shift of a word by a fixed
1157 // number of bits—1 to 8 bits.
1159 def SraX16: FEXT_SHIFT16_ins<0b11, "sra", IIAlu>;
1163 // Format: SRLV ry, rx MIPS16e
1164 // Purpose: Shift Word Right Logical Variable
1165 // To execute a logical right-shift of a word by a variable
1168 def SrlvRxRy16: FRxRxRy16_ins<0b00110, "srlv", IIAlu>;
1172 // Format: SRL rx, ry, sa MIPS16e
1173 // Purpose: Shift Word Right Logical (Extended)
1174 // To execute a logical right-shift of a word by a fixed
1175 // number of bits—1 to 31 bits.
1177 def SrlX16: FEXT_SHIFT16_ins<0b10, "srl", IIAlu>;
1180 // Format: SUBU rz, rx, ry MIPS16e
1181 // Purpose: Subtract Unsigned Word
1182 // To subtract 32-bit integers
1184 def SubuRxRyRz16: FRRR16_ins<0b11, "subu", IIAlu>, ArithLogic16Defs<0>;
1187 // Format: SW ry, offset(rx) MIPS16e
1188 // Purpose: Store Word (Extended)
1189 // To store a word to memory.
1191 def SwRxRyOffMemX16:
1192 FEXT_RRI16_mem2_ins<0b11011, "sw", mem16, IIStore>, MayStore;
1195 // Format: SW rx, offset(sp) MIPS16e
1196 // Purpose: Store Word rx (SP-Relative)
1197 // To store an SP-relative word to memory.
1199 def SwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b11010, "sw", IIStore>, MayStore;
1203 // Format: XOR rx, ry MIPS16e
1205 // To do a bitwise logical XOR.
1207 def XorRxRxRy16: FRxRxRy16_ins<0b01110, "xor", IIAlu>, ArithLogic16Defs<1>;
1209 class Mips16Pat<dag pattern, dag result> : Pat<pattern, result> {
1210 let Predicates = [InMips16Mode];
1213 // Unary Arith/Logic
1215 class ArithLogicU_pat<PatFrag OpNode, Instruction I> :
1216 Mips16Pat<(OpNode CPU16Regs:$r),
1219 def: ArithLogicU_pat<not, NotRxRy16>;
1220 def: ArithLogicU_pat<ineg, NegRxRy16>;
1222 class ArithLogic16_pat<SDNode OpNode, Instruction I> :
1223 Mips16Pat<(OpNode CPU16Regs:$l, CPU16Regs:$r),
1224 (I CPU16Regs:$l, CPU16Regs:$r)>;
1226 def: ArithLogic16_pat<add, AdduRxRyRz16>;
1227 def: ArithLogic16_pat<and, AndRxRxRy16>;
1228 def: ArithLogic16_pat<mul, MultRxRyRz16>;
1229 def: ArithLogic16_pat<or, OrRxRxRy16>;
1230 def: ArithLogic16_pat<sub, SubuRxRyRz16>;
1231 def: ArithLogic16_pat<xor, XorRxRxRy16>;
1233 // Arithmetic and logical instructions with 2 register operands.
1235 class ArithLogicI16_pat<SDNode OpNode, PatFrag imm_type, Instruction I> :
1236 Mips16Pat<(OpNode CPU16Regs:$in, imm_type:$imm),
1237 (I CPU16Regs:$in, imm_type:$imm)>;
1239 def: ArithLogicI16_pat<add, immSExt8, AddiuRxRxImm16>;
1240 def: ArithLogicI16_pat<add, immSExt16, AddiuRxRxImmX16>;
1241 def: ArithLogicI16_pat<shl, immZExt5, SllX16>;
1242 def: ArithLogicI16_pat<srl, immZExt5, SrlX16>;
1243 def: ArithLogicI16_pat<sra, immZExt5, SraX16>;
1245 class shift_rotate_reg16_pat<SDNode OpNode, Instruction I> :
1246 Mips16Pat<(OpNode CPU16Regs:$r, CPU16Regs:$ra),
1247 (I CPU16Regs:$r, CPU16Regs:$ra)>;
1249 def: shift_rotate_reg16_pat<shl, SllvRxRy16>;
1250 def: shift_rotate_reg16_pat<sra, SravRxRy16>;
1251 def: shift_rotate_reg16_pat<srl, SrlvRxRy16>;
1253 class LoadM16_pat<PatFrag OpNode, Instruction I> :
1254 Mips16Pat<(OpNode addr16:$addr), (I addr16:$addr)>;
1256 def: LoadM16_pat<sextloadi8, LbRxRyOffMemX16>;
1257 def: LoadM16_pat<zextloadi8, LbuRxRyOffMemX16>;
1258 def: LoadM16_pat<sextloadi16, LhRxRyOffMemX16>;
1259 def: LoadM16_pat<zextloadi16, LhuRxRyOffMemX16>;
1260 def: LoadM16_pat<load, LwRxRyOffMemX16>;
1262 class StoreM16_pat<PatFrag OpNode, Instruction I> :
1263 Mips16Pat<(OpNode CPU16Regs:$r, addr16:$addr),
1264 (I CPU16Regs:$r, addr16:$addr)>;
1266 def: StoreM16_pat<truncstorei8, SbRxRyOffMemX16>;
1267 def: StoreM16_pat<truncstorei16, ShRxRyOffMemX16>;
1268 def: StoreM16_pat<store, SwRxRyOffMemX16>;
1270 // Unconditional branch
1271 class UncondBranch16_pat<SDNode OpNode, Instruction I>:
1272 Mips16Pat<(OpNode bb:$imm16), (I bb:$imm16)> {
1273 let Predicates = [InMips16Mode];
1276 def : Mips16Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
1277 (Jal16 tglobaladdr:$dst)>;
1279 def : Mips16Pat<(MipsJmpLink (i32 texternalsym:$dst)),
1280 (Jal16 texternalsym:$dst)>;
1284 (brind CPU16Regs:$rs),
1285 (JrcRx16 CPU16Regs:$rs)>;
1287 // Jump and Link (Call)
1288 let isCall=1, hasDelaySlot=0 in
1290 FRR16_JALRC<0, 0, 0, (outs), (ins CPU16Regs:$rs),
1291 "jalrc \t$rs", [(MipsJmpLink CPU16Regs:$rs)], IIBranch>;
1294 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1,
1295 hasExtraSrcRegAllocReq = 1 in
1296 def RetRA16 : MipsPseudo16<(outs), (ins), "", [(MipsRet)]>;
1301 class SetCC_R16<PatFrag cond_op, Instruction I>:
1302 Mips16Pat<(cond_op CPU16Regs:$rx, CPU16Regs:$ry),
1303 (I CPU16Regs:$rx, CPU16Regs:$ry)>;
1305 class SetCC_I16<PatFrag cond_op, PatLeaf imm_type, Instruction I>:
1306 Mips16Pat<(cond_op CPU16Regs:$rx, imm_type:$imm16),
1307 (I CPU16Regs:$rx, imm_type:$imm16)>;
1310 def: Mips16Pat<(i32 addr16:$addr),
1311 (AddiuRxRyOffMemX16 addr16:$addr)>;
1314 // Large (>16 bit) immediate loads
1315 def : Mips16Pat<(i32 imm:$imm),
1316 (OrRxRxRy16 (SllX16 (LiRxImmX16 (HI16 imm:$imm)), 16),
1317 (LiRxImmX16 (LO16 imm:$imm)))>;
1319 // Carry MipsPatterns
1320 def : Mips16Pat<(subc CPU16Regs:$lhs, CPU16Regs:$rhs),
1321 (SubuRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1322 def : Mips16Pat<(addc CPU16Regs:$lhs, CPU16Regs:$rhs),
1323 (AdduRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1324 def : Mips16Pat<(addc CPU16Regs:$src, immSExt16:$imm),
1325 (AddiuRxRxImmX16 CPU16Regs:$src, imm:$imm)>;
1328 // Some branch conditional patterns are not generated by llvm at this time.
1329 // Some are for seemingly arbitrary reasons not used: i.e. with signed number
1330 // comparison they are used and for unsigned a different pattern is used.
1331 // I am pushing upstream from the full mips16 port and it seemed that I needed
1332 // these earlier and the mips32 port has these but now I cannot create test
1333 // cases that use these patterns. While I sort this all out I will leave these
1334 // extra patterns commented out and if I can be sure they are really not used,
1335 // I will delete the code. I don't want to check the code in uncommented without
1336 // a valid test case. In some cases, the compiler is generating patterns with
1337 // setcc instead and earlier I had implemented setcc first so may have masked
1338 // the problem. The setcc variants are suboptimal for mips16 so I may wantto
1339 // figure out how to enable the brcond patterns or else possibly new
1340 // combinations of of brcond and setcc.
1346 <(brcond (i32 (seteq CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1347 (BteqzT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1352 <(brcond (i32 (seteq CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1353 (BteqzT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1357 <(brcond (i32 (seteq CPU16Regs:$rx, 0)), bb:$targ16),
1358 (BeqzRxImmX16 CPU16Regs:$rx, bb:$targ16)
1362 // bcond-setgt (do we need to have this pair of setlt, setgt??)
1365 <(brcond (i32 (setgt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1366 (BtnezT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1373 <(brcond (i32 (setge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1374 (BteqzT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1378 // never called because compiler transforms a >= k to a > (k-1)
1380 <(brcond (i32 (setge CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1381 (BteqzT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1388 <(brcond (i32 (setlt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1389 (BtnezT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1393 <(brcond (i32 (setlt CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1394 (BtnezT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1401 <(brcond (i32 (setle CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1402 (BteqzT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1409 <(brcond (i32 (setne CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1410 (BtnezT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1414 <(brcond (i32 (setne CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1415 (BtnezT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1419 <(brcond (i32 (setne CPU16Regs:$rx, 0)), bb:$targ16),
1420 (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1424 // This needs to be there but I forget which code will generate it
1427 <(brcond CPU16Regs:$rx, bb:$targ16),
1428 (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1437 // <(brcond (i32 (setugt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1438 // (BtnezT8SltuX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1445 // <(brcond (i32 (setuge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1446 // (BteqzT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1454 // <(brcond (i32 (setult CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1455 // (BtnezT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1458 def: UncondBranch16_pat<br, BimmX16>;
1461 def: Mips16Pat<(i32 immSExt16:$in),
1462 (AddiuRxRxImmX16 (Move32R16 ZERO), immSExt16:$in)>;
1464 def: Mips16Pat<(i32 immZExt16:$in), (LiRxImmX16 immZExt16:$in)>;
1470 <(MipsDivRem16 CPU16Regs:$rx, CPU16Regs:$ry),
1471 (DivRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1477 <(MipsDivRemU16 CPU16Regs:$rx, CPU16Regs:$ry),
1478 (DivuRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1483 // if !(a < b) x = y
1485 def : Mips16Pat<(select (i32 (setge CPU16Regs:$a, CPU16Regs:$b)),
1486 CPU16Regs:$x, CPU16Regs:$y),
1487 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1488 CPU16Regs:$a, CPU16Regs:$b)>;
1495 def : Mips16Pat<(select (i32 (setgt CPU16Regs:$a, CPU16Regs:$b)),
1496 CPU16Regs:$x, CPU16Regs:$y),
1497 (SelTBtneZSlt CPU16Regs:$x, CPU16Regs:$y,
1498 CPU16Regs:$b, CPU16Regs:$a)>;
1503 // if !(a < b) x = y;
1506 (select (i32 (setuge CPU16Regs:$a, CPU16Regs:$b)),
1507 CPU16Regs:$x, CPU16Regs:$y),
1508 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1509 CPU16Regs:$a, CPU16Regs:$b)>;
1516 def : Mips16Pat<(select (i32 (setugt CPU16Regs:$a, CPU16Regs:$b)),
1517 CPU16Regs:$x, CPU16Regs:$y),
1518 (SelTBtneZSltu CPU16Regs:$x, CPU16Regs:$y,
1519 CPU16Regs:$b, CPU16Regs:$a)>;
1523 // due to an llvm optimization, i don't think that this will ever
1524 // be used. This is transformed into x = (a > k-1)?x:y
1529 // (select (i32 (setge CPU16Regs:$lhs, immSExt16:$rhs)),
1530 // CPU16Regs:$T, CPU16Regs:$F),
1531 // (SelTBteqZSlti CPU16Regs:$T, CPU16Regs:$F,
1532 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1535 // (select (i32 (setuge CPU16Regs:$lhs, immSExt16:$rhs)),
1536 // CPU16Regs:$T, CPU16Regs:$F),
1537 // (SelTBteqZSltiu CPU16Regs:$T, CPU16Regs:$F,
1538 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1543 // if !(a < k) x = y;
1546 (select (i32 (setlt CPU16Regs:$a, immSExt16:$b)),
1547 CPU16Regs:$x, CPU16Regs:$y),
1548 (SelTBtneZSlti CPU16Regs:$x, CPU16Regs:$y,
1549 CPU16Regs:$a, immSExt16:$b)>;
1555 // x = (a <= b)? x : y
1559 def : Mips16Pat<(select (i32 (setle CPU16Regs:$a, CPU16Regs:$b)),
1560 CPU16Regs:$x, CPU16Regs:$y),
1561 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1562 CPU16Regs:$b, CPU16Regs:$a)>;
1566 // x = (a <= b)? x : y
1570 def : Mips16Pat<(select (i32 (setule CPU16Regs:$a, CPU16Regs:$b)),
1571 CPU16Regs:$x, CPU16Regs:$y),
1572 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1573 CPU16Regs:$b, CPU16Regs:$a)>;
1577 // x = (a == b)? x : y
1579 // if (a != b) x = y
1581 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, CPU16Regs:$b)),
1582 CPU16Regs:$x, CPU16Regs:$y),
1583 (SelTBteqZCmp CPU16Regs:$x, CPU16Regs:$y,
1584 CPU16Regs:$b, CPU16Regs:$a)>;
1588 // x = (a == 0)? x : y
1590 // if (a != 0) x = y
1592 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, 0)),
1593 CPU16Regs:$x, CPU16Regs:$y),
1594 (SelBeqZ CPU16Regs:$x, CPU16Regs:$y,
1600 // x = (a == k)? x : y
1602 // if (a != k) x = y
1604 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, immZExt16:$k)),
1605 CPU16Regs:$x, CPU16Regs:$y),
1606 (SelTBteqZCmpi CPU16Regs:$x, CPU16Regs:$y,
1607 CPU16Regs:$a, immZExt16:$k)>;
1612 // x = (a != b)? x : y
1614 // if (a == b) x = y
1617 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, CPU16Regs:$b)),
1618 CPU16Regs:$x, CPU16Regs:$y),
1619 (SelTBtneZCmp CPU16Regs:$x, CPU16Regs:$y,
1620 CPU16Regs:$b, CPU16Regs:$a)>;
1624 // x = (a != 0)? x : y
1626 // if (a == 0) x = y
1628 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, 0)),
1629 CPU16Regs:$x, CPU16Regs:$y),
1630 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1638 def : Mips16Pat<(select CPU16Regs:$a,
1639 CPU16Regs:$x, CPU16Regs:$y),
1640 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1646 // x = (a != k)? x : y
1648 // if (a == k) x = y
1650 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, immZExt16:$k)),
1651 CPU16Regs:$x, CPU16Regs:$y),
1652 (SelTBtneZCmpi CPU16Regs:$x, CPU16Regs:$y,
1653 CPU16Regs:$a, immZExt16:$k)>;
1656 // When writing C code to test setxx these patterns,
1657 // some will be transformed into
1658 // other things. So we test using C code but using -O3 and -O0
1663 <(seteq CPU16Regs:$lhs,CPU16Regs:$rhs),
1664 (SltiuCCRxImmX16 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs), 1)>;
1667 <(seteq CPU16Regs:$lhs, 0),
1668 (SltiuCCRxImmX16 CPU16Regs:$lhs, 1)>;
1676 <(setge CPU16Regs:$lhs, CPU16Regs:$rhs),
1677 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1681 // For constants, llvm transforms this to:
1682 // x > (k -1) and then reverses the operands to use setlt. So this pattern
1683 // is not used now by the compiler. (Presumably checking that k-1 does not
1684 // overflow). The compiler never uses this at a the current time, due to
1685 // other optimizations.
1688 // <(setge CPU16Regs:$lhs, immSExt16:$rhs),
1689 // (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, immSExt16:$rhs),
1690 // (LiRxImmX16 1))>;
1692 // This catches the x >= -32768 case by transforming it to x > -32769
1695 <(setgt CPU16Regs:$lhs, -32769),
1696 (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, -32768),
1705 <(setgt CPU16Regs:$lhs, CPU16Regs:$rhs),
1706 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1712 <(setle CPU16Regs:$lhs, CPU16Regs:$rhs),
1713 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImm16 1))>;
1718 def: SetCC_R16<setlt, SltCCRxRy16>;
1720 def: SetCC_I16<setlt, immSExt16, SltiCCRxImmX16>;
1726 <(setne CPU16Regs:$lhs,CPU16Regs:$rhs),
1727 (SltuCCRxRy16 (LiRxImmX16 0),
1728 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs))>;
1735 <(setuge CPU16Regs:$lhs, CPU16Regs:$rhs),
1736 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1739 // this pattern will never be used because the compiler will transform
1740 // x >= k to x > (k - 1) and then use SLT
1743 // <(setuge CPU16Regs:$lhs, immZExt16:$rhs),
1744 // (XorRxRxRy16 (SltiuCCRxImmX16 CPU16Regs:$lhs, immZExt16:$rhs),
1745 // (LiRxImmX16 1))>;
1751 <(setugt CPU16Regs:$lhs, CPU16Regs:$rhs),
1752 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1758 <(setule CPU16Regs:$lhs, CPU16Regs:$rhs),
1759 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImmX16 1))>;
1764 def: SetCC_R16<setult, SltuCCRxRy16>;
1766 def: SetCC_I16<setult, immSExt16, SltiuCCRxImmX16>;
1768 def: Mips16Pat<(add CPU16Regs:$hi, (MipsLo tglobaladdr:$lo)),
1769 (AddiuRxRxImmX16 CPU16Regs:$hi, tglobaladdr:$lo)>;
1773 def : Mips16Pat<(MipsHi tglobaladdr:$in),
1774 (SllX16 (LiRxImmX16 tglobaladdr:$in), 16)>;
1775 def : Mips16Pat<(MipsHi tjumptable:$in),
1776 (SllX16 (LiRxImmX16 tjumptable:$in), 16)>;
1777 def : Mips16Pat<(MipsHi tglobaltlsaddr:$in),
1778 (SllX16 (LiRxImmX16 tglobaltlsaddr:$in), 16)>;
1781 class Wrapper16Pat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1782 Mips16Pat<(MipsWrapper RC:$gp, node:$in),
1783 (ADDiuOp RC:$gp, node:$in)>;
1786 def : Wrapper16Pat<tglobaladdr, AddiuRxRxImmX16, CPU16Regs>;
1787 def : Wrapper16Pat<tglobaltlsaddr, AddiuRxRxImmX16, CPU16Regs>;
1789 def : Mips16Pat<(i32 (extloadi8 addr16:$src)),
1790 (LbuRxRyOffMemX16 addr16:$src)>;
1791 def : Mips16Pat<(i32 (extloadi16 addr16:$src)),
1792 (LhuRxRyOffMemX16 addr16:$src)>;