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"), []> {
95 // JAL and JALX instruction format
97 class FJAL16_ins<bits<1> _X, string asmstr,
99 FJAL16<_X, (outs), (ins simm20:$imm),
100 !strconcat(asmstr, "\t$imm\n\tnop"),[],
105 // EXT-I instruction format
107 class FEXT_I16_ins<bits<5> eop, string asmstr, InstrItinClass itin> :
108 FEXT_I16<eop, (outs), (ins brtarget:$imm16),
109 !strconcat(asmstr, "\t$imm16"),[], itin>;
112 // EXT-I8 instruction format
115 class FEXT_I816_ins_base<bits<3> _func, string asmstr,
116 string asmstr2, InstrItinClass itin>:
117 FEXT_I816<_func, (outs), (ins simm16:$imm), !strconcat(asmstr, asmstr2),
120 class FEXT_I816_ins<bits<3> _func, string asmstr,
121 InstrItinClass itin>:
122 FEXT_I816_ins_base<_func, asmstr, "\t$imm", itin>;
124 class FEXT_I816_SP_ins<bits<3> _func, string asmstr,
125 InstrItinClass itin>:
126 FEXT_I816_ins_base<_func, asmstr, "\t$$sp, $imm", itin>;
129 // Assembler formats in alphabetical order.
130 // Natural and pseudos are mixed together.
132 // Compare two registers and place result in CC
133 // Implicit use of T8
135 // CC-RR Instruction format
137 class FCCRR16_ins<string asmstr> :
138 MipsPseudo16<(outs CPU16Regs:$cc), (ins CPU16Regs:$rx, CPU16Regs:$ry),
139 !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$cc, $$t8"), []> {
144 // EXT-RI instruction format
147 class FEXT_RI16_ins_base<bits<5> _op, string asmstr, string asmstr2,
148 InstrItinClass itin>:
149 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins simm16:$imm),
150 !strconcat(asmstr, asmstr2), [], itin>;
152 class FEXT_RI16_ins<bits<5> _op, string asmstr,
153 InstrItinClass itin>:
154 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
156 class FEXT_RI16R_ins_base<bits<5> _op, string asmstr, string asmstr2,
157 InstrItinClass itin>:
158 FEXT_RI16<_op, (outs ), (ins CPU16Regs:$rx, simm16:$imm),
159 !strconcat(asmstr, asmstr2), [], itin>;
161 class FEXT_RI16R_ins<bits<5> _op, string asmstr,
162 InstrItinClass itin>:
163 FEXT_RI16R_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
165 class FEXT_RI16_PC_ins<bits<5> _op, string asmstr, InstrItinClass itin>:
166 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $$pc, $imm", itin>;
168 class FEXT_RI16_B_ins<bits<5> _op, string asmstr,
169 InstrItinClass itin>:
170 FEXT_RI16<_op, (outs), (ins CPU16Regs:$rx, brtarget:$imm),
171 !strconcat(asmstr, "\t$rx, $imm"), [], itin>;
173 class FEXT_2RI16_ins<bits<5> _op, string asmstr,
174 InstrItinClass itin>:
175 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
176 !strconcat(asmstr, "\t$rx, $imm"), [], itin> {
177 let Constraints = "$rx_ = $rx";
181 // this has an explicit sp argument that we ignore to work around a problem
183 class FEXT_RI16_SP_explicit_ins<bits<5> _op, string asmstr,
184 InstrItinClass itin>:
185 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPUSPReg:$ry, simm16:$imm),
186 !strconcat(asmstr, "\t$rx, $imm ( $ry ); "), [], itin>;
189 // EXT-RRI instruction format
192 class FEXT_RRI16_mem_ins<bits<5> op, string asmstr, Operand MemOpnd,
193 InstrItinClass itin>:
194 FEXT_RRI16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
195 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
197 class FEXT_RRI16_mem2_ins<bits<5> op, string asmstr, Operand MemOpnd,
198 InstrItinClass itin>:
199 FEXT_RRI16<op, (outs ), (ins CPU16Regs:$ry, MemOpnd:$addr),
200 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
204 // EXT-RRI-A instruction format
207 class FEXT_RRI_A16_mem_ins<bits<1> op, string asmstr, Operand MemOpnd,
208 InstrItinClass itin>:
209 FEXT_RRI_A16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
210 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
213 // EXT-SHIFT instruction format
215 class FEXT_SHIFT16_ins<bits<2> _f, string asmstr, InstrItinClass itin>:
216 FEXT_SHIFT16<_f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry, shamt:$sa),
217 !strconcat(asmstr, "\t$rx, $ry, $sa"), [], itin>;
222 class FEXT_T8I816_ins<string asmstr, string asmstr2>:
224 (ins CPU16Regs:$rx, CPU16Regs:$ry, brtarget:$imm),
225 !strconcat(asmstr2, !strconcat("\t$rx, $ry\n\t",
226 !strconcat(asmstr, "\t$imm"))),[]> {
233 class FEXT_T8I8I16_ins<string asmstr, string asmstr2>:
235 (ins CPU16Regs:$rx, simm16:$imm, brtarget:$targ),
236 !strconcat(asmstr2, !strconcat("\t$rx, $imm\n\t",
237 !strconcat(asmstr, "\t$targ"))), []> {
244 // I8_MOVR32 instruction format (used only by the MOVR32 instructio
246 class FI8_MOVR3216_ins<string asmstr, InstrItinClass itin>:
247 FI8_MOVR3216<(outs CPU16Regs:$rz), (ins CPURegs:$r32),
248 !strconcat(asmstr, "\t$rz, $r32"), [], itin>;
251 // I8_MOV32R instruction format (used only by MOV32R instruction)
254 class FI8_MOV32R16_ins<string asmstr, InstrItinClass itin>:
255 FI8_MOV32R16<(outs CPURegs:$r32), (ins CPU16Regs:$rz),
256 !strconcat(asmstr, "\t$r32, $rz"), [], itin>;
259 // This are pseudo formats for multiply
260 // This first one can be changed to non pseudo now.
264 class FMULT16_ins<string asmstr, InstrItinClass itin> :
265 MipsPseudo16<(outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
266 !strconcat(asmstr, "\t$rx, $ry"), []>;
271 class FMULT16_LO_ins<string asmstr, InstrItinClass itin> :
272 MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
273 !strconcat(asmstr, "\t$rx, $ry\n\tmflo\t$rz"), []> {
278 // RR-type instruction format
281 class FRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
282 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
283 !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
286 class FRRTR16_ins<string asmstr> :
287 MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
288 !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$rz, $$t8"), []> ;
291 // maybe refactor but need a $zero as a dummy first parameter
293 class FRR16_div_ins<bits<5> f, string asmstr, InstrItinClass itin> :
294 FRR16<f, (outs ), (ins CPU16Regs:$rx, CPU16Regs:$ry),
295 !strconcat(asmstr, "\t$$zero, $rx, $ry"), [], itin> ;
297 class FUnaryRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
298 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
299 !strconcat(asmstr, "\t$rx, $ry"), [], itin> ;
302 class FRR16_M_ins<bits<5> f, string asmstr,
303 InstrItinClass itin> :
304 FRR16<f, (outs CPU16Regs:$rx), (ins),
305 !strconcat(asmstr, "\t$rx"), [], itin>;
307 class FRxRxRy16_ins<bits<5> f, string asmstr,
308 InstrItinClass itin> :
309 FRR16<f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
310 !strconcat(asmstr, "\t$rz, $ry"),
312 let Constraints = "$rx = $rz";
316 class FRR16_JALRC_RA_only_ins<bits<1> nd_, bits<1> l_,
317 string asmstr, InstrItinClass itin>:
318 FRR16_JALRC<nd_, l_, 1, (outs), (ins), !strconcat(asmstr, "\t $$ra"),
322 class FRR16_JALRC_ins<bits<1> nd, bits<1> l, bits<1> ra,
323 string asmstr, InstrItinClass itin>:
324 FRR16_JALRC<nd, l, ra, (outs), (ins CPU16Regs:$rx),
325 !strconcat(asmstr, "\t $rx"), [], itin> ;
328 // RRR-type instruction format
331 class FRRR16_ins<bits<2> _f, string asmstr, InstrItinClass itin> :
332 FRRR16<_f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
333 !strconcat(asmstr, "\t$rz, $rx, $ry"), [], itin>;
336 // These Sel patterns support the generation of conditional move
337 // pseudo instructions.
339 // The nomenclature uses the components making up the pseudo and may
340 // be a bit counter intuitive when compared with the end result we seek.
341 // For example using a bqez in the example directly below results in the
342 // conditional move being done if the tested register is not zero.
343 // I considered in easier to check by keeping the pseudo consistent with
344 // it's components but it could have been done differently.
346 // The simplest case is when can test and operand directly and do the
347 // conditional move based on a simple mips16 conditional
348 // branch instruction.
350 // if $op == beqz or bnez:
355 // if $op == beqz, then if $rt != 0, then the conditional assignment
356 // $rd = $rs is done.
358 // if $op == bnez, then if $rt == 0, then the conditional assignment
359 // $rd = $rs is done.
361 // So this pseudo class only has one operand, i.e. op
363 class Sel<string op>:
364 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
366 !strconcat(op, "\t$rt, .+4\n\t\n\tmove $rd, $rs"), []> {
367 //let isCodeGenOnly=1;
368 let Constraints = "$rd = $rd_";
369 let usesCustomInserter = 1;
373 // The next two instruction classes allow for an operand which tests
374 // two operands and returns a value in register T8 and
375 //then does a conditional branch based on the value of T8
378 // op2 can be cmpi or slti/sltiu
379 // op1 can bteqz or btnez
380 // the operands for op2 are a register and a signed constant
382 // $op2 $t, $imm ;test register t and branch conditionally
383 // $op1 .+4 ;op1 is a conditional branch
387 class SeliT<string op1, string op2>:
388 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
389 CPU16Regs:$rl, simm16:$imm),
391 !strconcat("\t$rl, $imm\n\t",
392 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
394 let Constraints = "$rd = $rd_";
395 let usesCustomInserter = 1;
399 // op2 can be cmp or slt/sltu
400 // op1 can be bteqz or btnez
401 // the operands for op2 are two registers
402 // op1 is a conditional branch
405 // $op2 $rl, $rr ;test registers rl,rr
406 // $op1 .+4 ;op2 is a conditional branch
410 class SelT<string op1, string op2>:
411 MipsPseudo16<(outs CPU16Regs:$rd_),
412 (ins CPU16Regs:$rd, CPU16Regs:$rs,
413 CPU16Regs:$rl, CPU16Regs:$rr),
415 !strconcat("\t$rl, $rr\n\t",
416 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
418 let Constraints = "$rd = $rd_";
424 def imm32: Operand<i32>;
427 MipsPseudo16<(outs), (ins imm32:$imm), "\t.word $imm", []>;
430 MipsPseudo16<(outs), (ins CPU16Regs:$rx, imm32:$imm),
431 "lw\t$rx, 1f\n\tb\t2f\n\t.align\t2\n1: \t.word\t$imm\n2:", []>;
435 // Some general instruction class info
439 class ArithLogic16Defs<bit isCom=0> {
441 bit isCommutable = isCom;
442 bit isReMaterializable = 1;
443 bit neverHasSideEffects = 1;
448 bit isTerminator = 1;
454 bit isTerminator = 1;
467 // Format: ADDIU rx, immediate MIPS16e
468 // Purpose: Add Immediate Unsigned Word (2-Operand, Extended)
469 // To add a constant to a 32-bit integer.
471 def AddiuRxImmX16: FEXT_RI16_ins<0b01001, "addiu", IIAlu>;
473 def AddiuRxRxImm16: F2RI16_ins<0b01001, "addiu", IIAlu>,
474 ArithLogic16Defs<0> {
475 let AddedComplexity = 5;
477 def AddiuRxRxImmX16: FEXT_2RI16_ins<0b01001, "addiu", IIAlu>,
478 ArithLogic16Defs<0> {
479 let isCodeGenOnly = 1;
482 def AddiuRxRyOffMemX16:
483 FEXT_RRI_A16_mem_ins<0, "addiu", mem16_ea, IIAlu>;
487 // Format: ADDIU rx, pc, immediate MIPS16e
488 // Purpose: Add Immediate Unsigned Word (3-Operand, PC-Relative, Extended)
489 // To add a constant to the program counter.
491 def AddiuRxPcImmX16: FEXT_RI16_PC_ins<0b00001, "addiu", IIAlu>;
494 // Format: ADDIU sp, immediate MIPS16e
495 // Purpose: Add Immediate Unsigned Word (2-Operand, SP-Relative, Extended)
496 // To add a constant to the stack pointer.
499 : FI816_SP_ins<0b011, "addiu", IIAlu> {
502 let AddedComplexity = 5;
506 : FEXT_I816_SP_ins<0b011, "addiu", IIAlu> {
512 // Format: ADDU rz, rx, ry MIPS16e
513 // Purpose: Add Unsigned Word (3-Operand)
514 // To add 32-bit integers.
517 def AdduRxRyRz16: FRRR16_ins<01, "addu", IIAlu>, ArithLogic16Defs<1>;
520 // Format: AND rx, ry MIPS16e
522 // To do a bitwise logical AND.
524 def AndRxRxRy16: FRxRxRy16_ins<0b01100, "and", IIAlu>, ArithLogic16Defs<1>;
528 // Format: BEQZ rx, offset MIPS16e
529 // Purpose: Branch on Equal to Zero
530 // To test a GPR then do a PC-relative conditional branch.
532 def BeqzRxImm16: FRI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
536 // Format: BEQZ rx, offset MIPS16e
537 // Purpose: Branch on Equal to Zero (Extended)
538 // To test a GPR then do a PC-relative conditional branch.
540 def BeqzRxImmX16: FEXT_RI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
542 // Format: B offset MIPS16e
543 // Purpose: Unconditional Branch
544 // To do an unconditional PC-relative branch.
546 def BimmX16: FEXT_I16_ins<0b00010, "b", IIAlu>, branch16;
549 // Format: BNEZ rx, offset MIPS16e
550 // Purpose: Branch on Not Equal to Zero
551 // To test a GPR then do a PC-relative conditional branch.
553 def BnezRxImm16: FRI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
556 // Format: BNEZ rx, offset MIPS16e
557 // Purpose: Branch on Not Equal to Zero (Extended)
558 // To test a GPR then do a PC-relative conditional branch.
560 def BnezRxImmX16: FEXT_RI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
563 // Format: BTEQZ offset MIPS16e
564 // Purpose: Branch on T Equal to Zero (Extended)
565 // To test special register T then do a PC-relative conditional branch.
567 def BteqzX16: FEXT_I816_ins<0b000, "bteqz", IIAlu>, cbranch16 {
571 def BteqzT8CmpX16: FEXT_T8I816_ins<"bteqz", "cmp">, cbranch16;
573 def BteqzT8CmpiX16: FEXT_T8I8I16_ins<"bteqz", "cmpi">,
576 def BteqzT8SltX16: FEXT_T8I816_ins<"bteqz", "slt">, cbranch16;
578 def BteqzT8SltuX16: FEXT_T8I816_ins<"bteqz", "sltu">, cbranch16;
580 def BteqzT8SltiX16: FEXT_T8I8I16_ins<"bteqz", "slti">, cbranch16;
582 def BteqzT8SltiuX16: FEXT_T8I8I16_ins<"bteqz", "sltiu">,
586 // Format: BTNEZ offset MIPS16e
587 // Purpose: Branch on T Not Equal to Zero (Extended)
588 // To test special register T then do a PC-relative conditional branch.
590 def BtnezX16: FEXT_I816_ins<0b001, "btnez", IIAlu> ,cbranch16 {
594 def BtnezT8CmpX16: FEXT_T8I816_ins<"btnez", "cmp">, cbranch16;
596 def BtnezT8CmpiX16: FEXT_T8I8I16_ins<"btnez", "cmpi">, cbranch16;
598 def BtnezT8SltX16: FEXT_T8I816_ins<"btnez", "slt">, cbranch16;
600 def BtnezT8SltuX16: FEXT_T8I816_ins<"btnez", "sltu">, cbranch16;
602 def BtnezT8SltiX16: FEXT_T8I8I16_ins<"btnez", "slti">, cbranch16;
604 def BtnezT8SltiuX16: FEXT_T8I8I16_ins<"btnez", "sltiu">,
608 // Format: CMP rx, ry MIPS16e
610 // To compare the contents of two GPRs.
612 def CmpRxRy16: FRR16_ins<0b01010, "cmp", IIAlu> {
617 // Format: CMPI rx, immediate MIPS16e
618 // Purpose: Compare Immediate
619 // To compare a constant with the contents of a GPR.
621 def CmpiRxImm16: FRI16_ins<0b01110, "cmpi", IIAlu> {
626 // Format: CMPI rx, immediate MIPS16e
627 // Purpose: Compare Immediate (Extended)
628 // To compare a constant with the contents of a GPR.
630 def CmpiRxImmX16: FEXT_RI16_ins<0b01110, "cmpi", IIAlu> {
636 // Format: DIV rx, ry MIPS16e
637 // Purpose: Divide Word
638 // To divide 32-bit signed integers.
640 def DivRxRy16: FRR16_div_ins<0b11010, "div", IIAlu> {
645 // Format: DIVU rx, ry MIPS16e
646 // Purpose: Divide Unsigned Word
647 // To divide 32-bit unsigned integers.
649 def DivuRxRy16: FRR16_div_ins<0b11011, "divu", IIAlu> {
653 // Format: JAL target MIPS16e
654 // Purpose: Jump and Link
655 // To execute a procedure call within the current 256 MB-aligned
656 // region and preserve the current ISA.
659 def Jal16 : FJAL16_ins<0b0, "jal", IIAlu> {
661 let hasDelaySlot = 0; // not true, but we add the nop for now
667 // Format: JR ra MIPS16e
668 // Purpose: Jump Register Through Register ra
669 // To execute a branch to the instruction address in the return
673 def JrRa16: FRR16_JALRC_RA_only_ins<0, 0, "jr", IIAlu> {
675 let isIndirectBranch = 1;
676 let hasDelaySlot = 1;
681 def JrcRa16: FRR16_JALRC_RA_only_ins<1, 1, "jrc", IIAlu> {
683 let isIndirectBranch = 1;
688 def JrcRx16: FRR16_JALRC_ins<1, 1, 0, "jrc", IIAlu> {
690 let isIndirectBranch = 1;
695 // Format: LB ry, offset(rx) MIPS16e
696 // Purpose: Load Byte (Extended)
697 // To load a byte from memory as a signed value.
699 def LbRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lb", mem16, IILoad>, MayLoad{
700 let isCodeGenOnly = 1;
704 // Format: LBU ry, offset(rx) MIPS16e
705 // Purpose: Load Byte Unsigned (Extended)
706 // To load a byte from memory as a unsigned value.
708 def LbuRxRyOffMemX16:
709 FEXT_RRI16_mem_ins<0b10100, "lbu", mem16, IILoad>, MayLoad {
710 let isCodeGenOnly = 1;
714 // Format: LH ry, offset(rx) MIPS16e
715 // Purpose: Load Halfword signed (Extended)
716 // To load a halfword from memory as a signed value.
718 def LhRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10100, "lh", mem16, IILoad>, MayLoad{
719 let isCodeGenOnly = 1;
723 // Format: LHU ry, offset(rx) MIPS16e
724 // Purpose: Load Halfword unsigned (Extended)
725 // To load a halfword from memory as an unsigned value.
727 def LhuRxRyOffMemX16:
728 FEXT_RRI16_mem_ins<0b10100, "lhu", mem16, IILoad>, MayLoad {
729 let isCodeGenOnly = 1;
733 // Format: LI rx, immediate MIPS16e
734 // Purpose: Load Immediate
735 // To load a constant into a GPR.
737 def LiRxImm16: FRI16_ins<0b01101, "li", IIAlu>;
740 // Format: LI rx, immediate MIPS16e
741 // Purpose: Load Immediate (Extended)
742 // To load a constant into a GPR.
744 def LiRxImmX16: FEXT_RI16_ins<0b01101, "li", IIAlu>;
747 // Format: LW ry, offset(rx) MIPS16e
748 // Purpose: Load Word (Extended)
749 // To load a word from memory as a signed value.
751 def LwRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lw", mem16, IILoad>, MayLoad{
752 let isCodeGenOnly = 1;
755 // Format: LW rx, offset(sp) MIPS16e
756 // Purpose: Load Word (SP-Relative, Extended)
757 // To load an SP-relative word from memory as a signed value.
759 def LwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b10110, "lw", IILoad>, MayLoad{
764 // Format: MOVE r32, rz MIPS16e
766 // To move the contents of a GPR to a GPR.
768 def Move32R16: FI8_MOV32R16_ins<"move", IIAlu>;
771 // Format: MOVE ry, r32 MIPS16e
773 // To move the contents of a GPR to a GPR.
775 def MoveR3216: FI8_MOVR3216_ins<"move", IIAlu>;
778 // Format: MFHI rx MIPS16e
779 // Purpose: Move From HI Register
780 // To copy the special purpose HI register to a GPR.
782 def Mfhi16: FRR16_M_ins<0b10000, "mfhi", IIAlu> {
784 let neverHasSideEffects = 1;
788 // Format: MFLO rx MIPS16e
789 // Purpose: Move From LO Register
790 // To copy the special purpose LO register to a GPR.
792 def Mflo16: FRR16_M_ins<0b10010, "mflo", IIAlu> {
794 let neverHasSideEffects = 1;
798 // Pseudo Instruction for mult
800 def MultRxRy16: FMULT16_ins<"mult", IIAlu> {
801 let isCommutable = 1;
802 let neverHasSideEffects = 1;
806 def MultuRxRy16: FMULT16_ins<"multu", IIAlu> {
807 let isCommutable = 1;
808 let neverHasSideEffects = 1;
813 // Format: MULT rx, ry MIPS16e
814 // Purpose: Multiply Word
815 // To multiply 32-bit signed integers.
817 def MultRxRyRz16: FMULT16_LO_ins<"mult", IIAlu> {
818 let isCommutable = 1;
819 let neverHasSideEffects = 1;
824 // Format: MULTU rx, ry MIPS16e
825 // Purpose: Multiply Unsigned Word
826 // To multiply 32-bit unsigned integers.
828 def MultuRxRyRz16: FMULT16_LO_ins<"multu", IIAlu> {
829 let isCommutable = 1;
830 let neverHasSideEffects = 1;
835 // Format: NEG rx, ry MIPS16e
837 // To negate an integer value.
839 def NegRxRy16: FUnaryRR16_ins<0b11101, "neg", IIAlu>;
842 // Format: NOT rx, ry MIPS16e
844 // To complement an integer value
846 def NotRxRy16: FUnaryRR16_ins<0b01111, "not", IIAlu>;
849 // Format: OR rx, ry MIPS16e
851 // To do a bitwise logical OR.
853 def OrRxRxRy16: FRxRxRy16_ins<0b01101, "or", IIAlu>, ArithLogic16Defs<1>;
856 // Format: RESTORE {ra,}{s0/s1/s0-1,}{framesize}
857 // (All args are optional) MIPS16e
858 // Purpose: Restore Registers and Deallocate Stack Frame
859 // To deallocate a stack frame before exit from a subroutine,
860 // restoring return address and static registers, and adjusting
864 // fixed form for restoring RA and the frame
865 // for direct object emitter, encoding needs to be adjusted for the
868 let ra=1, s=0,s0=1,s1=1 in
870 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
871 "restore\t$$ra, $$s0, $$s1, $frame_size", [], IILoad >, MayLoad {
872 let isCodeGenOnly = 1;
873 let Defs = [S0, S1, RA, SP];
877 // Use Restore to increment SP since SP is not a Mip 16 register, this
878 // is an easy way to do that which does not require a register.
880 let ra=0, s=0,s0=0,s1=0 in
882 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
883 "restore\t$frame_size", [], IILoad >, MayLoad {
884 let isCodeGenOnly = 1;
890 // Format: SAVE {ra,}{s0/s1/s0-1,}{framesize} (All arguments are optional)
892 // Purpose: Save Registers and Set Up Stack Frame
893 // To set up a stack frame on entry to a subroutine,
894 // saving return address and static registers, and adjusting stack
896 let ra=1, s=1,s0=1,s1=1 in
898 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
899 "save\t$$ra, $$s0, $$s1, $frame_size", [], IIStore >, MayStore {
900 let isCodeGenOnly = 1;
901 let Uses = [RA, SP, S0, S1];
906 // Use Save to decrement the SP by a constant since SP is not
907 // a Mips16 register.
909 let ra=0, s=0,s0=0,s1=0 in
911 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
912 "save\t$frame_size", [], IIStore >, MayStore {
913 let isCodeGenOnly = 1;
918 // Format: SB ry, offset(rx) MIPS16e
919 // Purpose: Store Byte (Extended)
920 // To store a byte to memory.
923 FEXT_RRI16_mem2_ins<0b11000, "sb", mem16, IIStore>, MayStore;
926 // The Sel(T) instructions are pseudos
927 // T means that they use T8 implicitly.
930 // Format: SelBeqZ rd, rs, rt
931 // Purpose: if rt==0, do nothing
934 def SelBeqZ: Sel<"beqz">;
937 // Format: SelTBteqZCmp rd, rs, rl, rr
938 // Purpose: b = Cmp rl, rr.
939 // If b==0 then do nothing.
940 // if b!=0 then rd = rs
942 def SelTBteqZCmp: SelT<"bteqz", "cmp">;
945 // Format: SelTBteqZCmpi rd, rs, rl, rr
946 // Purpose: b = Cmpi rl, imm.
947 // If b==0 then do nothing.
948 // if b!=0 then rd = rs
950 def SelTBteqZCmpi: SeliT<"bteqz", "cmpi">;
953 // Format: SelTBteqZSlt rd, rs, rl, rr
954 // Purpose: b = Slt rl, rr.
955 // If b==0 then do nothing.
956 // if b!=0 then rd = rs
958 def SelTBteqZSlt: SelT<"bteqz", "slt">;
961 // Format: SelTBteqZSlti rd, rs, rl, rr
962 // Purpose: b = Slti rl, imm.
963 // If b==0 then do nothing.
964 // if b!=0 then rd = rs
966 def SelTBteqZSlti: SeliT<"bteqz", "slti">;
969 // Format: SelTBteqZSltu rd, rs, rl, rr
970 // Purpose: b = Sltu rl, rr.
971 // If b==0 then do nothing.
972 // if b!=0 then rd = rs
974 def SelTBteqZSltu: SelT<"bteqz", "sltu">;
977 // Format: SelTBteqZSltiu rd, rs, rl, rr
978 // Purpose: b = Sltiu rl, imm.
979 // If b==0 then do nothing.
980 // if b!=0 then rd = rs
982 def SelTBteqZSltiu: SeliT<"bteqz", "sltiu">;
985 // Format: SelBnez rd, rs, rt
986 // Purpose: if rt!=0, do nothing
989 def SelBneZ: Sel<"bnez">;
992 // Format: SelTBtneZCmp rd, rs, rl, rr
993 // Purpose: b = Cmp rl, rr.
994 // If b!=0 then do nothing.
995 // if b0=0 then rd = rs
997 def SelTBtneZCmp: SelT<"btnez", "cmp">;
1000 // Format: SelTBtnezCmpi rd, rs, rl, rr
1001 // Purpose: b = Cmpi rl, imm.
1002 // If b!=0 then do nothing.
1003 // if b==0 then rd = rs
1005 def SelTBtneZCmpi: SeliT<"btnez", "cmpi">;
1008 // Format: SelTBtneZSlt rd, rs, rl, rr
1009 // Purpose: b = Slt rl, rr.
1010 // If b!=0 then do nothing.
1011 // if b==0 then rd = rs
1013 def SelTBtneZSlt: SelT<"btnez", "slt">;
1016 // Format: SelTBtneZSlti rd, rs, rl, rr
1017 // Purpose: b = Slti rl, imm.
1018 // If b!=0 then do nothing.
1019 // if b==0 then rd = rs
1021 def SelTBtneZSlti: SeliT<"btnez", "slti">;
1024 // Format: SelTBtneZSltu rd, rs, rl, rr
1025 // Purpose: b = Sltu rl, rr.
1026 // If b!=0 then do nothing.
1027 // if b==0 then rd = rs
1029 def SelTBtneZSltu: SelT<"btnez", "sltu">;
1032 // Format: SelTBtneZSltiu rd, rs, rl, rr
1033 // Purpose: b = Slti rl, imm.
1034 // If b!=0 then do nothing.
1035 // if b==0 then rd = rs
1037 def SelTBtneZSltiu: SeliT<"btnez", "sltiu">;
1040 // Format: SH ry, offset(rx) MIPS16e
1041 // Purpose: Store Halfword (Extended)
1042 // To store a halfword to memory.
1044 def ShRxRyOffMemX16:
1045 FEXT_RRI16_mem2_ins<0b11001, "sh", mem16, IIStore>, MayStore;
1048 // Format: SLL rx, ry, sa MIPS16e
1049 // Purpose: Shift Word Left Logical (Extended)
1050 // To execute a left-shift of a word by a fixed number of bits—0 to 31 bits.
1052 def SllX16: FEXT_SHIFT16_ins<0b00, "sll", IIAlu>;
1055 // Format: SLLV ry, rx MIPS16e
1056 // Purpose: Shift Word Left Logical Variable
1057 // To execute a left-shift of a word by a variable number of bits.
1059 def SllvRxRy16 : FRxRxRy16_ins<0b00100, "sllv", IIAlu>;
1061 // Format: SLTI rx, immediate MIPS16e
1062 // Purpose: Set on Less Than Immediate
1063 // To record the result of a less-than comparison with a constant.
1066 def SltiRxImm16: FRI16R_ins<0b01010, "slti", IIAlu> {
1071 // Format: SLTI rx, immediate MIPS16e
1072 // Purpose: Set on Less Than Immediate (Extended)
1073 // To record the result of a less-than comparison with a constant.
1076 def SltiRxImmX16: FEXT_RI16R_ins<0b01010, "slti", IIAlu> {
1080 def SltiCCRxImmX16: FEXT_CCRXI16_ins<"slti">;
1082 // Format: SLTIU rx, immediate MIPS16e
1083 // Purpose: Set on Less Than Immediate Unsigned
1084 // To record the result of a less-than comparison with a constant.
1087 def SltiuRxImm16: FRI16R_ins<0b01011, "sltiu", IIAlu> {
1092 // Format: SLTI rx, immediate MIPS16e
1093 // Purpose: Set on Less Than Immediate Unsigned (Extended)
1094 // To record the result of a less-than comparison with a constant.
1097 def SltiuRxImmX16: FEXT_RI16R_ins<0b01011, "sltiu", IIAlu> {
1101 // Format: SLTIU rx, immediate MIPS16e
1102 // Purpose: Set on Less Than Immediate Unsigned (Extended)
1103 // To record the result of a less-than comparison with a constant.
1105 def SltiuCCRxImmX16: FEXT_CCRXI16_ins<"sltiu">;
1108 // Format: SLT rx, ry MIPS16e
1109 // Purpose: Set on Less Than
1110 // To record the result of a less-than comparison.
1112 def SltRxRy16: FRR16_ins<0b00010, "slt", IIAlu>{
1116 def SltCCRxRy16: FCCRR16_ins<"slt">;
1118 // Format: SLTU rx, ry MIPS16e
1119 // Purpose: Set on Less Than Unsigned
1120 // To record the result of an unsigned less-than comparison.
1122 def SltuRxRy16: FRR16_ins<0b00011, "sltu", IIAlu>{
1126 def SltuRxRyRz16: FRRTR16_ins<"sltu"> {
1127 let isCodeGenOnly=1;
1132 def SltuCCRxRy16: FCCRR16_ins<"sltu">;
1134 // Format: SRAV ry, rx MIPS16e
1135 // Purpose: Shift Word Right Arithmetic Variable
1136 // To execute an arithmetic right-shift of a word by a variable
1139 def SravRxRy16: FRxRxRy16_ins<0b00111, "srav", IIAlu>;
1143 // Format: SRA rx, ry, sa MIPS16e
1144 // Purpose: Shift Word Right Arithmetic (Extended)
1145 // To execute an arithmetic right-shift of a word by a fixed
1146 // number of bits—1 to 8 bits.
1148 def SraX16: FEXT_SHIFT16_ins<0b11, "sra", IIAlu>;
1152 // Format: SRLV ry, rx MIPS16e
1153 // Purpose: Shift Word Right Logical Variable
1154 // To execute a logical right-shift of a word by a variable
1157 def SrlvRxRy16: FRxRxRy16_ins<0b00110, "srlv", IIAlu>;
1161 // Format: SRL rx, ry, sa MIPS16e
1162 // Purpose: Shift Word Right Logical (Extended)
1163 // To execute a logical right-shift of a word by a fixed
1164 // number of bits—1 to 31 bits.
1166 def SrlX16: FEXT_SHIFT16_ins<0b10, "srl", IIAlu>;
1169 // Format: SUBU rz, rx, ry MIPS16e
1170 // Purpose: Subtract Unsigned Word
1171 // To subtract 32-bit integers
1173 def SubuRxRyRz16: FRRR16_ins<0b11, "subu", IIAlu>, ArithLogic16Defs<0>;
1176 // Format: SW ry, offset(rx) MIPS16e
1177 // Purpose: Store Word (Extended)
1178 // To store a word to memory.
1180 def SwRxRyOffMemX16:
1181 FEXT_RRI16_mem2_ins<0b11011, "sw", mem16, IIStore>, MayStore;
1184 // Format: SW rx, offset(sp) MIPS16e
1185 // Purpose: Store Word rx (SP-Relative)
1186 // To store an SP-relative word to memory.
1188 def SwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b11010, "sw", IIStore>, MayStore;
1192 // Format: XOR rx, ry MIPS16e
1194 // To do a bitwise logical XOR.
1196 def XorRxRxRy16: FRxRxRy16_ins<0b01110, "xor", IIAlu>, ArithLogic16Defs<1>;
1198 class Mips16Pat<dag pattern, dag result> : Pat<pattern, result> {
1199 let Predicates = [InMips16Mode];
1202 // Unary Arith/Logic
1204 class ArithLogicU_pat<PatFrag OpNode, Instruction I> :
1205 Mips16Pat<(OpNode CPU16Regs:$r),
1208 def: ArithLogicU_pat<not, NotRxRy16>;
1209 def: ArithLogicU_pat<ineg, NegRxRy16>;
1211 class ArithLogic16_pat<SDNode OpNode, Instruction I> :
1212 Mips16Pat<(OpNode CPU16Regs:$l, CPU16Regs:$r),
1213 (I CPU16Regs:$l, CPU16Regs:$r)>;
1215 def: ArithLogic16_pat<add, AdduRxRyRz16>;
1216 def: ArithLogic16_pat<and, AndRxRxRy16>;
1217 def: ArithLogic16_pat<mul, MultRxRyRz16>;
1218 def: ArithLogic16_pat<or, OrRxRxRy16>;
1219 def: ArithLogic16_pat<sub, SubuRxRyRz16>;
1220 def: ArithLogic16_pat<xor, XorRxRxRy16>;
1222 // Arithmetic and logical instructions with 2 register operands.
1224 class ArithLogicI16_pat<SDNode OpNode, PatFrag imm_type, Instruction I> :
1225 Mips16Pat<(OpNode CPU16Regs:$in, imm_type:$imm),
1226 (I CPU16Regs:$in, imm_type:$imm)>;
1228 def: ArithLogicI16_pat<add, immSExt8, AddiuRxRxImm16>;
1229 def: ArithLogicI16_pat<add, immSExt16, AddiuRxRxImmX16>;
1230 def: ArithLogicI16_pat<shl, immZExt5, SllX16>;
1231 def: ArithLogicI16_pat<srl, immZExt5, SrlX16>;
1232 def: ArithLogicI16_pat<sra, immZExt5, SraX16>;
1234 class shift_rotate_reg16_pat<SDNode OpNode, Instruction I> :
1235 Mips16Pat<(OpNode CPU16Regs:$r, CPU16Regs:$ra),
1236 (I CPU16Regs:$r, CPU16Regs:$ra)>;
1238 def: shift_rotate_reg16_pat<shl, SllvRxRy16>;
1239 def: shift_rotate_reg16_pat<sra, SravRxRy16>;
1240 def: shift_rotate_reg16_pat<srl, SrlvRxRy16>;
1242 class LoadM16_pat<PatFrag OpNode, Instruction I> :
1243 Mips16Pat<(OpNode addr16:$addr), (I addr16:$addr)>;
1245 def: LoadM16_pat<sextloadi8, LbRxRyOffMemX16>;
1246 def: LoadM16_pat<zextloadi8, LbuRxRyOffMemX16>;
1247 def: LoadM16_pat<sextloadi16, LhRxRyOffMemX16>;
1248 def: LoadM16_pat<zextloadi16, LhuRxRyOffMemX16>;
1249 def: LoadM16_pat<load, LwRxRyOffMemX16>;
1251 class StoreM16_pat<PatFrag OpNode, Instruction I> :
1252 Mips16Pat<(OpNode CPU16Regs:$r, addr16:$addr),
1253 (I CPU16Regs:$r, addr16:$addr)>;
1255 def: StoreM16_pat<truncstorei8, SbRxRyOffMemX16>;
1256 def: StoreM16_pat<truncstorei16, ShRxRyOffMemX16>;
1257 def: StoreM16_pat<store, SwRxRyOffMemX16>;
1259 // Unconditional branch
1260 class UncondBranch16_pat<SDNode OpNode, Instruction I>:
1261 Mips16Pat<(OpNode bb:$imm16), (I bb:$imm16)> {
1262 let Predicates = [InMips16Mode];
1265 def : Mips16Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
1266 (Jal16 tglobaladdr:$dst)>;
1268 def : Mips16Pat<(MipsJmpLink (i32 texternalsym:$dst)),
1269 (Jal16 texternalsym:$dst)>;
1273 (brind CPU16Regs:$rs),
1274 (JrcRx16 CPU16Regs:$rs)>;
1276 // Jump and Link (Call)
1277 let isCall=1, hasDelaySlot=0 in
1279 FRR16_JALRC<0, 0, 0, (outs), (ins CPU16Regs:$rs),
1280 "jalrc \t$rs", [(MipsJmpLink CPU16Regs:$rs)], IIBranch>;
1283 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1,
1284 hasExtraSrcRegAllocReq = 1 in
1285 def RetRA16 : MipsPseudo16<(outs), (ins), "", [(MipsRet)]>;
1290 class SetCC_R16<PatFrag cond_op, Instruction I>:
1291 Mips16Pat<(cond_op CPU16Regs:$rx, CPU16Regs:$ry),
1292 (I CPU16Regs:$rx, CPU16Regs:$ry)>;
1294 class SetCC_I16<PatFrag cond_op, PatLeaf imm_type, Instruction I>:
1295 Mips16Pat<(cond_op CPU16Regs:$rx, imm_type:$imm16),
1296 (I CPU16Regs:$rx, imm_type:$imm16)>;
1299 def: Mips16Pat<(i32 addr16:$addr),
1300 (AddiuRxRyOffMemX16 addr16:$addr)>;
1303 // Large (>16 bit) immediate loads
1304 def : Mips16Pat<(i32 imm:$imm),
1305 (OrRxRxRy16 (SllX16 (LiRxImmX16 (HI16 imm:$imm)), 16),
1306 (LiRxImmX16 (LO16 imm:$imm)))>;
1308 // Carry MipsPatterns
1309 def : Mips16Pat<(subc CPU16Regs:$lhs, CPU16Regs:$rhs),
1310 (SubuRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1311 def : Mips16Pat<(addc CPU16Regs:$lhs, CPU16Regs:$rhs),
1312 (AdduRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1313 def : Mips16Pat<(addc CPU16Regs:$src, immSExt16:$imm),
1314 (AddiuRxRxImmX16 CPU16Regs:$src, imm:$imm)>;
1317 // Some branch conditional patterns are not generated by llvm at this time.
1318 // Some are for seemingly arbitrary reasons not used: i.e. with signed number
1319 // comparison they are used and for unsigned a different pattern is used.
1320 // I am pushing upstream from the full mips16 port and it seemed that I needed
1321 // these earlier and the mips32 port has these but now I cannot create test
1322 // cases that use these patterns. While I sort this all out I will leave these
1323 // extra patterns commented out and if I can be sure they are really not used,
1324 // I will delete the code. I don't want to check the code in uncommented without
1325 // a valid test case. In some cases, the compiler is generating patterns with
1326 // setcc instead and earlier I had implemented setcc first so may have masked
1327 // the problem. The setcc variants are suboptimal for mips16 so I may wantto
1328 // figure out how to enable the brcond patterns or else possibly new
1329 // combinations of of brcond and setcc.
1335 <(brcond (i32 (seteq CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1336 (BteqzT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1341 <(brcond (i32 (seteq CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1342 (BteqzT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1346 <(brcond (i32 (seteq CPU16Regs:$rx, 0)), bb:$targ16),
1347 (BeqzRxImmX16 CPU16Regs:$rx, bb:$targ16)
1351 // bcond-setgt (do we need to have this pair of setlt, setgt??)
1354 <(brcond (i32 (setgt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1355 (BtnezT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1362 <(brcond (i32 (setge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1363 (BteqzT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1367 // never called because compiler transforms a >= k to a > (k-1)
1369 <(brcond (i32 (setge CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1370 (BteqzT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1377 <(brcond (i32 (setlt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1378 (BtnezT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1382 <(brcond (i32 (setlt CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1383 (BtnezT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1390 <(brcond (i32 (setle CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1391 (BteqzT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1398 <(brcond (i32 (setne CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1399 (BtnezT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1403 <(brcond (i32 (setne CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1404 (BtnezT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1408 <(brcond (i32 (setne CPU16Regs:$rx, 0)), bb:$targ16),
1409 (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1413 // This needs to be there but I forget which code will generate it
1416 <(brcond CPU16Regs:$rx, bb:$targ16),
1417 (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1426 // <(brcond (i32 (setugt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1427 // (BtnezT8SltuX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1434 // <(brcond (i32 (setuge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1435 // (BteqzT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1443 // <(brcond (i32 (setult CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1444 // (BtnezT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1447 def: UncondBranch16_pat<br, BimmX16>;
1450 def: Mips16Pat<(i32 immSExt16:$in),
1451 (AddiuRxRxImmX16 (Move32R16 ZERO), immSExt16:$in)>;
1453 def: Mips16Pat<(i32 immZExt16:$in), (LiRxImmX16 immZExt16:$in)>;
1459 <(MipsDivRem CPU16Regs:$rx, CPU16Regs:$ry),
1460 (DivRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1466 <(MipsDivRemU CPU16Regs:$rx, CPU16Regs:$ry),
1467 (DivuRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1472 // if !(a < b) x = y
1474 def : Mips16Pat<(select (i32 (setge CPU16Regs:$a, CPU16Regs:$b)),
1475 CPU16Regs:$x, CPU16Regs:$y),
1476 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1477 CPU16Regs:$a, CPU16Regs:$b)>;
1484 def : Mips16Pat<(select (i32 (setgt CPU16Regs:$a, CPU16Regs:$b)),
1485 CPU16Regs:$x, CPU16Regs:$y),
1486 (SelTBtneZSlt CPU16Regs:$x, CPU16Regs:$y,
1487 CPU16Regs:$b, CPU16Regs:$a)>;
1492 // if !(a < b) x = y;
1495 (select (i32 (setuge CPU16Regs:$a, CPU16Regs:$b)),
1496 CPU16Regs:$x, CPU16Regs:$y),
1497 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1498 CPU16Regs:$a, CPU16Regs:$b)>;
1505 def : Mips16Pat<(select (i32 (setugt CPU16Regs:$a, CPU16Regs:$b)),
1506 CPU16Regs:$x, CPU16Regs:$y),
1507 (SelTBtneZSltu CPU16Regs:$x, CPU16Regs:$y,
1508 CPU16Regs:$b, CPU16Regs:$a)>;
1512 // due to an llvm optimization, i don't think that this will ever
1513 // be used. This is transformed into x = (a > k-1)?x:y
1518 // (select (i32 (setge CPU16Regs:$lhs, immSExt16:$rhs)),
1519 // CPU16Regs:$T, CPU16Regs:$F),
1520 // (SelTBteqZSlti CPU16Regs:$T, CPU16Regs:$F,
1521 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1524 // (select (i32 (setuge CPU16Regs:$lhs, immSExt16:$rhs)),
1525 // CPU16Regs:$T, CPU16Regs:$F),
1526 // (SelTBteqZSltiu CPU16Regs:$T, CPU16Regs:$F,
1527 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1532 // if !(a < k) x = y;
1535 (select (i32 (setlt CPU16Regs:$a, immSExt16:$b)),
1536 CPU16Regs:$x, CPU16Regs:$y),
1537 (SelTBtneZSlti CPU16Regs:$x, CPU16Regs:$y,
1538 CPU16Regs:$a, immSExt16:$b)>;
1544 // x = (a <= b)? x : y
1548 def : Mips16Pat<(select (i32 (setle CPU16Regs:$a, CPU16Regs:$b)),
1549 CPU16Regs:$x, CPU16Regs:$y),
1550 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1551 CPU16Regs:$b, CPU16Regs:$a)>;
1555 // x = (a <= b)? x : y
1559 def : Mips16Pat<(select (i32 (setule CPU16Regs:$a, CPU16Regs:$b)),
1560 CPU16Regs:$x, CPU16Regs:$y),
1561 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1562 CPU16Regs:$b, CPU16Regs:$a)>;
1566 // x = (a == b)? x : y
1568 // if (a != b) x = y
1570 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, CPU16Regs:$b)),
1571 CPU16Regs:$x, CPU16Regs:$y),
1572 (SelTBteqZCmp CPU16Regs:$x, CPU16Regs:$y,
1573 CPU16Regs:$b, CPU16Regs:$a)>;
1577 // x = (a == 0)? x : y
1579 // if (a != 0) x = y
1581 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, 0)),
1582 CPU16Regs:$x, CPU16Regs:$y),
1583 (SelBeqZ CPU16Regs:$x, CPU16Regs:$y,
1589 // x = (a == k)? x : y
1591 // if (a != k) x = y
1593 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, immZExt16:$k)),
1594 CPU16Regs:$x, CPU16Regs:$y),
1595 (SelTBteqZCmpi CPU16Regs:$x, CPU16Regs:$y,
1596 CPU16Regs:$a, immZExt16:$k)>;
1601 // x = (a != b)? x : y
1603 // if (a == b) x = y
1606 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, CPU16Regs:$b)),
1607 CPU16Regs:$x, CPU16Regs:$y),
1608 (SelTBtneZCmp CPU16Regs:$x, CPU16Regs:$y,
1609 CPU16Regs:$b, CPU16Regs:$a)>;
1613 // x = (a != 0)? x : y
1615 // if (a == 0) x = y
1617 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, 0)),
1618 CPU16Regs:$x, CPU16Regs:$y),
1619 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1627 def : Mips16Pat<(select CPU16Regs:$a,
1628 CPU16Regs:$x, CPU16Regs:$y),
1629 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1635 // x = (a != k)? x : y
1637 // if (a == k) x = y
1639 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, immZExt16:$k)),
1640 CPU16Regs:$x, CPU16Regs:$y),
1641 (SelTBtneZCmpi CPU16Regs:$x, CPU16Regs:$y,
1642 CPU16Regs:$a, immZExt16:$k)>;
1645 // When writing C code to test setxx these patterns,
1646 // some will be transformed into
1647 // other things. So we test using C code but using -O3 and -O0
1652 <(seteq CPU16Regs:$lhs,CPU16Regs:$rhs),
1653 (SltiuCCRxImmX16 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs), 1)>;
1656 <(seteq CPU16Regs:$lhs, 0),
1657 (SltiuCCRxImmX16 CPU16Regs:$lhs, 1)>;
1665 <(setge CPU16Regs:$lhs, CPU16Regs:$rhs),
1666 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1670 // For constants, llvm transforms this to:
1671 // x > (k -1) and then reverses the operands to use setlt. So this pattern
1672 // is not used now by the compiler. (Presumably checking that k-1 does not
1673 // overflow). The compiler never uses this at a the current time, due to
1674 // other optimizations.
1677 // <(setge CPU16Regs:$lhs, immSExt16:$rhs),
1678 // (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, immSExt16:$rhs),
1679 // (LiRxImmX16 1))>;
1681 // This catches the x >= -32768 case by transforming it to x > -32769
1684 <(setgt CPU16Regs:$lhs, -32769),
1685 (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, -32768),
1694 <(setgt CPU16Regs:$lhs, CPU16Regs:$rhs),
1695 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1701 <(setle CPU16Regs:$lhs, CPU16Regs:$rhs),
1702 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImm16 1))>;
1707 def: SetCC_R16<setlt, SltCCRxRy16>;
1709 def: SetCC_I16<setlt, immSExt16, SltiCCRxImmX16>;
1715 <(setne CPU16Regs:$lhs,CPU16Regs:$rhs),
1716 (SltuCCRxRy16 (LiRxImmX16 0),
1717 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs))>;
1724 <(setuge CPU16Regs:$lhs, CPU16Regs:$rhs),
1725 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1728 // this pattern will never be used because the compiler will transform
1729 // x >= k to x > (k - 1) and then use SLT
1732 // <(setuge CPU16Regs:$lhs, immZExt16:$rhs),
1733 // (XorRxRxRy16 (SltiuCCRxImmX16 CPU16Regs:$lhs, immZExt16:$rhs),
1734 // (LiRxImmX16 1))>;
1740 <(setugt CPU16Regs:$lhs, CPU16Regs:$rhs),
1741 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1747 <(setule CPU16Regs:$lhs, CPU16Regs:$rhs),
1748 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImmX16 1))>;
1753 def: SetCC_R16<setult, SltuCCRxRy16>;
1755 def: SetCC_I16<setult, immSExt16, SltiuCCRxImmX16>;
1757 def: Mips16Pat<(add CPU16Regs:$hi, (MipsLo tglobaladdr:$lo)),
1758 (AddiuRxRxImmX16 CPU16Regs:$hi, tglobaladdr:$lo)>;
1762 def : Mips16Pat<(MipsHi tglobaladdr:$in),
1763 (SllX16 (LiRxImmX16 tglobaladdr:$in), 16)>;
1764 def : Mips16Pat<(MipsHi tjumptable:$in),
1765 (SllX16 (LiRxImmX16 tjumptable:$in), 16)>;
1766 def : Mips16Pat<(MipsHi tglobaltlsaddr:$in),
1767 (SllX16 (LiRxImmX16 tglobaltlsaddr:$in), 16)>;
1770 class Wrapper16Pat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1771 Mips16Pat<(MipsWrapper RC:$gp, node:$in),
1772 (ADDiuOp RC:$gp, node:$in)>;
1775 def : Wrapper16Pat<tglobaladdr, AddiuRxRxImmX16, CPU16Regs>;
1776 def : Wrapper16Pat<tglobaltlsaddr, AddiuRxRxImmX16, CPU16Regs>;
1778 def : Mips16Pat<(i32 (extloadi8 addr16:$src)),
1779 (LbuRxRyOffMemX16 addr16:$src)>;
1780 def : Mips16Pat<(i32 (extloadi16 addr16:$src)),
1781 (LhuRxRyOffMemX16 addr16:$src)>;