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";
35 // RI instruction format
39 class F2RI16_ins<bits<5> _op, string asmstr,
41 FRI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
42 !strconcat(asmstr, "\t$rx, $imm\t# 16 bit inst"), [], itin> {
43 let Constraints = "$rx_ = $rx";
47 // Compare a register and immediate and place result in CC
50 // EXT-CCRR Instruction format
52 class FEXT_CCRXI16_ins<bits<5> _op, string asmstr,
54 FEXT_RI16<_op, (outs CPU16Regs:$cc), (ins CPU16Regs:$rx, simm16:$imm),
55 !strconcat(asmstr, "\t$rx, $imm\n\tmove\t$cc, $$t8"), [], itin> {
59 // JAL and JALX instruction format
61 class FJAL16_ins<bits<1> _X, string asmstr,
63 FJAL16<_X, (outs), (ins simm20:$imm),
64 !strconcat(asmstr, "\t$imm\n\tnop"),[],
69 // EXT-I instruction format
71 class FEXT_I16_ins<bits<5> eop, string asmstr, InstrItinClass itin> :
72 FEXT_I16<eop, (outs), (ins brtarget:$imm16),
73 !strconcat(asmstr, "\t$imm16"),[], itin>;
76 // EXT-I8 instruction format
79 class FEXT_I816_ins_base<bits<3> _func, string asmstr,
80 string asmstr2, InstrItinClass itin>:
81 FEXT_I816<_func, (outs), (ins simm16:$imm), !strconcat(asmstr, asmstr2),
84 class FEXT_I816_ins<bits<3> _func, string asmstr,
86 FEXT_I816_ins_base<_func, asmstr, "\t$imm", itin>;
88 class FEXT_I816_SP_ins<bits<3> _func, string asmstr,
90 FEXT_I816_ins_base<_func, asmstr, "\t$$sp, $imm", itin>;
93 // Assembler formats in alphabetical order.
94 // Natural and pseudos are mixed together.
96 // Compare two registers and place result in CC
99 // CC-RR Instruction format
101 class FCCRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
102 FRR16<f, (outs CPU16Regs:$cc), (ins CPU16Regs:$rx, CPU16Regs:$ry),
103 !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$cc, $$t8"), [], itin> {
108 // EXT-RI instruction format
111 class FEXT_RI16_ins_base<bits<5> _op, string asmstr, string asmstr2,
112 InstrItinClass itin>:
113 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins simm16:$imm),
114 !strconcat(asmstr, asmstr2), [], itin>;
116 class FEXT_RI16_ins<bits<5> _op, string asmstr,
117 InstrItinClass itin>:
118 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
120 class FEXT_RI16_PC_ins<bits<5> _op, string asmstr, InstrItinClass itin>:
121 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $$pc, $imm", itin>;
123 class FEXT_RI16_B_ins<bits<5> _op, string asmstr,
124 InstrItinClass itin>:
125 FEXT_RI16<_op, (outs), (ins CPU16Regs:$rx, brtarget:$imm),
126 !strconcat(asmstr, "\t$rx, $imm"), [], itin>;
128 class FEXT_2RI16_ins<bits<5> _op, string asmstr,
129 InstrItinClass itin>:
130 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
131 !strconcat(asmstr, "\t$rx, $imm"), [], itin> {
132 let Constraints = "$rx_ = $rx";
136 // this has an explicit sp argument that we ignore to work around a problem
138 class FEXT_RI16_SP_explicit_ins<bits<5> _op, string asmstr,
139 InstrItinClass itin>:
140 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPUSPReg:$ry, simm16:$imm),
141 !strconcat(asmstr, "\t$rx, $imm ( $ry ); "), [], itin>;
144 // EXT-RRI instruction format
147 class FEXT_RRI16_mem_ins<bits<5> op, string asmstr, Operand MemOpnd,
148 InstrItinClass itin>:
149 FEXT_RRI16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
150 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
152 class FEXT_RRI16_mem2_ins<bits<5> op, string asmstr, Operand MemOpnd,
153 InstrItinClass itin>:
154 FEXT_RRI16<op, (outs ), (ins CPU16Regs:$ry, MemOpnd:$addr),
155 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
159 // EXT-RRI-A instruction format
162 class FEXT_RRI_A16_mem_ins<bits<1> op, string asmstr, Operand MemOpnd,
163 InstrItinClass itin>:
164 FEXT_RRI_A16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
165 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
168 // EXT-SHIFT instruction format
170 class FEXT_SHIFT16_ins<bits<2> _f, string asmstr, InstrItinClass itin>:
171 FEXT_SHIFT16<_f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry, shamt:$sa),
172 !strconcat(asmstr, "\t$rx, $ry, $sa"), [], itin>;
177 class FEXT_T8I816_ins<bits<3> _func, string asmstr, string asmstr2,
178 InstrItinClass itin>:
179 FEXT_I816<_func, (outs),
180 (ins CPU16Regs:$rx, CPU16Regs:$ry, brtarget:$imm),
181 !strconcat(asmstr2, !strconcat("\t$rx, $ry\n\t",
182 !strconcat(asmstr, "\t$imm"))),[], itin> {
189 class FEXT_T8I8I16_ins<bits<3> _func, string asmstr, string asmstr2,
190 InstrItinClass itin>:
191 FEXT_I816<_func, (outs),
192 (ins CPU16Regs:$rx, simm16:$imm, brtarget:$targ),
193 !strconcat(asmstr2, !strconcat("\t$rx, $imm\n\t",
194 !strconcat(asmstr, "\t$targ"))), [], itin> {
201 // I8_MOVR32 instruction format (used only by the MOVR32 instructio
203 class FI8_MOVR3216_ins<string asmstr, InstrItinClass itin>:
204 FI8_MOVR3216<(outs CPU16Regs:$rz), (ins CPURegs:$r32),
205 !strconcat(asmstr, "\t$rz, $r32"), [], itin>;
208 // I8_MOV32R instruction format (used only by MOV32R instruction)
211 class FI8_MOV32R16_ins<string asmstr, InstrItinClass itin>:
212 FI8_MOV32R16<(outs CPURegs:$r32), (ins CPU16Regs:$rz),
213 !strconcat(asmstr, "\t$r32, $rz"), [], itin>;
216 // This are pseudo formats for multiply
217 // This first one can be changed to non pseudo now.
221 class FMULT16_ins<string asmstr, InstrItinClass itin> :
222 MipsPseudo16<(outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
223 !strconcat(asmstr, "\t$rx, $ry"), []>;
228 class FMULT16_LO_ins<string asmstr, InstrItinClass itin> :
229 MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
230 !strconcat(asmstr, "\t$rx, $ry\n\tmflo\t$rz"), []> {
235 // RR-type instruction format
238 class FRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
239 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
240 !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
243 class FRRTR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
244 FRR16<f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
245 !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$rz, $$t8"), [], itin> ;
248 // maybe refactor but need a $zero as a dummy first parameter
250 class FRR16_div_ins<bits<5> f, string asmstr, InstrItinClass itin> :
251 FRR16<f, (outs ), (ins CPU16Regs:$rx, CPU16Regs:$ry),
252 !strconcat(asmstr, "\t$$zero, $rx, $ry"), [], itin> ;
254 class FUnaryRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
255 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
256 !strconcat(asmstr, "\t$rx, $ry"), [], itin> ;
259 class FRR16_M_ins<bits<5> f, string asmstr,
260 InstrItinClass itin> :
261 FRR16<f, (outs CPU16Regs:$rx), (ins),
262 !strconcat(asmstr, "\t$rx"), [], itin>;
264 class FRxRxRy16_ins<bits<5> f, string asmstr,
265 InstrItinClass itin> :
266 FRR16<f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
267 !strconcat(asmstr, "\t$rz, $ry"),
269 let Constraints = "$rx = $rz";
273 class FRR16_JALRC_RA_only_ins<bits<1> nd_, bits<1> l_,
274 string asmstr, InstrItinClass itin>:
275 FRR16_JALRC<nd_, l_, 1, (outs), (ins), !strconcat(asmstr, "\t $$ra"),
279 class FRR16_JALRC_ins<bits<1> nd, bits<1> l, bits<1> ra,
280 string asmstr, InstrItinClass itin>:
281 FRR16_JALRC<nd, l, ra, (outs), (ins CPU16Regs:$rx),
282 !strconcat(asmstr, "\t $rx"), [], itin> ;
285 // RRR-type instruction format
288 class FRRR16_ins<bits<2> _f, string asmstr, InstrItinClass itin> :
289 FRRR16<_f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
290 !strconcat(asmstr, "\t$rz, $rx, $ry"), [], itin>;
293 // These Sel patterns support the generation of conditional move
294 // pseudo instructions.
296 // The nomenclature uses the components making up the pseudo and may
297 // be a bit counter intuitive when compared with the end result we seek.
298 // For example using a bqez in the example directly below results in the
299 // conditional move being done if the tested register is not zero.
300 // I considered in easier to check by keeping the pseudo consistent with
301 // it's components but it could have been done differently.
303 // The simplest case is when can test and operand directly and do the
304 // conditional move based on a simple mips16 conditional
305 // branch instruction.
307 // if $op == beqz or bnez:
312 // if $op == beqz, then if $rt != 0, then the conditional assignment
313 // $rd = $rs is done.
315 // if $op == bnez, then if $rt == 0, then the conditional assignment
316 // $rd = $rs is done.
318 // So this pseudo class only has one operand, i.e. op
320 class Sel<bits<5> f1, string op, InstrItinClass itin>:
321 MipsInst16_32<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
323 !strconcat(op, "\t$rt, .+4\n\t\n\tmove $rd, $rs"), [], itin,
326 let Constraints = "$rd = $rd_";
330 // The next two instruction classes allow for an operand which tests
331 // two operands and returns a value in register T8 and
332 //then does a conditional branch based on the value of T8
335 // op2 can be cmpi or slti/sltiu
336 // op1 can bteqz or btnez
337 // the operands for op2 are a register and a signed constant
339 // $op2 $t, $imm ;test register t and branch conditionally
340 // $op1 .+4 ;op1 is a conditional branch
344 class SeliT<bits<5> f1, string op1, bits<5> f2, string op2,
345 InstrItinClass itin>:
346 MipsInst16_32<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
347 CPU16Regs:$rl, simm16:$imm),
349 !strconcat("\t$rl, $imm\n\t",
350 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), [], itin,
353 let Constraints = "$rd = $rd_";
357 // op2 can be cmp or slt/sltu
358 // op1 can be bteqz or btnez
359 // the operands for op2 are two registers
360 // op1 is a conditional branch
363 // $op2 $rl, $rr ;test registers rl,rr
364 // $op1 .+4 ;op2 is a conditional branch
368 class SelT<bits<5> f1, string op1, bits<5> f2, string op2,
369 InstrItinClass itin>:
370 MipsInst16_32<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
371 CPU16Regs:$rl, CPU16Regs:$rr),
373 !strconcat("\t$rl, $rr\n\t",
374 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), [], itin,
377 let Constraints = "$rd = $rd_";
383 def imm32: Operand<i32>;
386 MipsPseudo16<(outs), (ins imm32:$imm), "\t.word $imm", []>;
389 MipsPseudo16<(outs), (ins CPU16Regs:$rx, imm32:$imm),
390 "lw\t$rx, 1f\n\tb\t2f\n\t.align\t2\n1: \t.word\t$imm\n2:", []>;
394 // Some general instruction class info
398 class ArithLogic16Defs<bit isCom=0> {
400 bit isCommutable = isCom;
401 bit isReMaterializable = 1;
402 bit neverHasSideEffects = 1;
407 bit isTerminator = 1;
413 bit isTerminator = 1;
425 // Format: ADDIU rx, immediate MIPS16e
426 // Purpose: Add Immediate Unsigned Word (2-Operand, Extended)
427 // To add a constant to a 32-bit integer.
429 def AddiuRxImmX16: FEXT_RI16_ins<0b01001, "addiu", IIAlu>;
431 def AddiuRxRxImm16: F2RI16_ins<0b01001, "addiu", IIAlu>,
432 ArithLogic16Defs<0> {
433 let AddedComplexity = 5;
435 def AddiuRxRxImmX16: FEXT_2RI16_ins<0b01001, "addiu", IIAlu>,
438 def AddiuRxRyOffMemX16:
439 FEXT_RRI_A16_mem_ins<0, "addiu", mem16_ea, IIAlu>;
443 // Format: ADDIU rx, pc, immediate MIPS16e
444 // Purpose: Add Immediate Unsigned Word (3-Operand, PC-Relative, Extended)
445 // To add a constant to the program counter.
447 def AddiuRxPcImmX16: FEXT_RI16_PC_ins<0b00001, "addiu", IIAlu>;
450 // Format: ADDIU sp, immediate MIPS16e
451 // Purpose: Add Immediate Unsigned Word (2-Operand, SP-Relative, Extended)
452 // To add a constant to the stack pointer.
455 : FEXT_I816_SP_ins<0b011, "addiu", IIAlu> {
461 // Format: ADDU rz, rx, ry MIPS16e
462 // Purpose: Add Unsigned Word (3-Operand)
463 // To add 32-bit integers.
466 def AdduRxRyRz16: FRRR16_ins<01, "addu", IIAlu>, ArithLogic16Defs<1>;
469 // Format: AND rx, ry MIPS16e
471 // To do a bitwise logical AND.
473 def AndRxRxRy16: FRxRxRy16_ins<0b01100, "and", IIAlu>, ArithLogic16Defs<1>;
477 // Format: BEQZ rx, offset MIPS16e
478 // Purpose: Branch on Equal to Zero (Extended)
479 // To test a GPR then do a PC-relative conditional branch.
481 def BeqzRxImmX16: FEXT_RI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
483 // Format: B offset MIPS16e
484 // Purpose: Unconditional Branch
485 // To do an unconditional PC-relative branch.
487 def BimmX16: FEXT_I16_ins<0b00010, "b", IIAlu>, branch16;
490 // Format: BNEZ rx, offset MIPS16e
491 // Purpose: Branch on Not Equal to Zero (Extended)
492 // To test a GPR then do a PC-relative conditional branch.
494 def BnezRxImmX16: FEXT_RI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
497 // Format: BTEQZ offset MIPS16e
498 // Purpose: Branch on T Equal to Zero (Extended)
499 // To test special register T then do a PC-relative conditional branch.
501 def BteqzX16: FEXT_I816_ins<0b000, "bteqz", IIAlu>, cbranch16;
503 def BteqzT8CmpX16: FEXT_T8I816_ins<0b000, "bteqz", "cmp", IIAlu>, cbranch16;
505 def BteqzT8CmpiX16: FEXT_T8I8I16_ins<0b000, "bteqz", "cmpi", IIAlu>,
508 def BteqzT8SltX16: FEXT_T8I816_ins<0b000, "bteqz", "slt", IIAlu>, cbranch16;
510 def BteqzT8SltuX16: FEXT_T8I816_ins<0b000, "bteqz", "sltu", IIAlu>, cbranch16;
512 def BteqzT8SltiX16: FEXT_T8I8I16_ins<0b000, "bteqz", "slti", IIAlu>, cbranch16;
514 def BteqzT8SltiuX16: FEXT_T8I8I16_ins<0b000, "bteqz", "sltiu", IIAlu>,
518 // Format: BTNEZ offset MIPS16e
519 // Purpose: Branch on T Not Equal to Zero (Extended)
520 // To test special register T then do a PC-relative conditional branch.
522 def BtnezX16: FEXT_I816_ins<0b001, "btnez", IIAlu> ,cbranch16;
524 def BtnezT8CmpX16: FEXT_T8I816_ins<0b000, "btnez", "cmp", IIAlu>, cbranch16;
526 def BtnezT8CmpiX16: FEXT_T8I8I16_ins<0b000, "btnez", "cmpi", IIAlu>, cbranch16;
528 def BtnezT8SltX16: FEXT_T8I816_ins<0b000, "btnez", "slt", IIAlu>, cbranch16;
530 def BtnezT8SltuX16: FEXT_T8I816_ins<0b000, "btnez", "sltu", IIAlu>, cbranch16;
532 def BtnezT8SltiX16: FEXT_T8I8I16_ins<0b000, "btnez", "slti", IIAlu>, cbranch16;
534 def BtnezT8SltiuX16: FEXT_T8I8I16_ins<0b000, "btnez", "sltiu", IIAlu>,
538 // Format: DIV rx, ry MIPS16e
539 // Purpose: Divide Word
540 // To divide 32-bit signed integers.
542 def DivRxRy16: FRR16_div_ins<0b11010, "div", IIAlu> {
547 // Format: DIVU rx, ry MIPS16e
548 // Purpose: Divide Unsigned Word
549 // To divide 32-bit unsigned integers.
551 def DivuRxRy16: FRR16_div_ins<0b11011, "divu", IIAlu> {
555 // Format: JAL target MIPS16e
556 // Purpose: Jump and Link
557 // To execute a procedure call within the current 256 MB-aligned
558 // region and preserve the current ISA.
561 def Jal16 : FJAL16_ins<0b0, "jal", IIAlu> {
563 let hasDelaySlot = 0; // not true, but we add the nop for now
569 // Format: JR ra MIPS16e
570 // Purpose: Jump Register Through Register ra
571 // To execute a branch to the instruction address in the return
575 def JrRa16: FRR16_JALRC_RA_only_ins<0, 0, "jr", IIAlu> {
577 let isIndirectBranch = 1;
578 let hasDelaySlot = 1;
583 def JrcRa16: FRR16_JALRC_RA_only_ins<0, 0, "jrc", IIAlu> {
585 let isIndirectBranch = 1;
590 def JrcRx16: FRR16_JALRC_ins<1, 1, 0, "jrc", IIAlu> {
592 let isIndirectBranch = 1;
597 // Format: LB ry, offset(rx) MIPS16e
598 // Purpose: Load Byte (Extended)
599 // To load a byte from memory as a signed value.
601 def LbRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lb", mem16, IILoad>, MayLoad;
604 // Format: LBU ry, offset(rx) MIPS16e
605 // Purpose: Load Byte Unsigned (Extended)
606 // To load a byte from memory as a unsigned value.
608 def LbuRxRyOffMemX16:
609 FEXT_RRI16_mem_ins<0b10100, "lbu", mem16, IILoad>, MayLoad;
612 // Format: LH ry, offset(rx) MIPS16e
613 // Purpose: Load Halfword signed (Extended)
614 // To load a halfword from memory as a signed value.
616 def LhRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10100, "lh", mem16, IILoad>, MayLoad;
619 // Format: LHU ry, offset(rx) MIPS16e
620 // Purpose: Load Halfword unsigned (Extended)
621 // To load a halfword from memory as an unsigned value.
623 def LhuRxRyOffMemX16:
624 FEXT_RRI16_mem_ins<0b10100, "lhu", mem16, IILoad>, MayLoad;
627 // Format: LI rx, immediate MIPS16e
628 // Purpose: Load Immediate (Extended)
629 // To load a constant into a GPR.
631 def LiRxImmX16: FEXT_RI16_ins<0b01101, "li", IIAlu>;
634 // Format: LW ry, offset(rx) MIPS16e
635 // Purpose: Load Word (Extended)
636 // To load a word from memory as a signed value.
638 def LwRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lw", mem16, IILoad>, MayLoad;
640 // Format: LW rx, offset(sp) MIPS16e
641 // Purpose: Load Word (SP-Relative, Extended)
642 // To load an SP-relative word from memory as a signed value.
644 def LwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b10110, "lw", IILoad>, MayLoad{
649 // Format: MOVE r32, rz MIPS16e
651 // To move the contents of a GPR to a GPR.
653 def Move32R16: FI8_MOV32R16_ins<"move", IIAlu>;
656 // Format: MOVE ry, r32 MIPS16e
658 // To move the contents of a GPR to a GPR.
660 def MoveR3216: FI8_MOVR3216_ins<"move", IIAlu>;
663 // Format: MFHI rx MIPS16e
664 // Purpose: Move From HI Register
665 // To copy the special purpose HI register to a GPR.
667 def Mfhi16: FRR16_M_ins<0b10000, "mfhi", IIAlu> {
669 let neverHasSideEffects = 1;
673 // Format: MFLO rx MIPS16e
674 // Purpose: Move From LO Register
675 // To copy the special purpose LO register to a GPR.
677 def Mflo16: FRR16_M_ins<0b10010, "mflo", IIAlu> {
679 let neverHasSideEffects = 1;
683 // Pseudo Instruction for mult
685 def MultRxRy16: FMULT16_ins<"mult", IIAlu> {
686 let isCommutable = 1;
687 let neverHasSideEffects = 1;
691 def MultuRxRy16: FMULT16_ins<"multu", IIAlu> {
692 let isCommutable = 1;
693 let neverHasSideEffects = 1;
698 // Format: MULT rx, ry MIPS16e
699 // Purpose: Multiply Word
700 // To multiply 32-bit signed integers.
702 def MultRxRyRz16: FMULT16_LO_ins<"mult", IIAlu> {
703 let isCommutable = 1;
704 let neverHasSideEffects = 1;
709 // Format: MULTU rx, ry MIPS16e
710 // Purpose: Multiply Unsigned Word
711 // To multiply 32-bit unsigned integers.
713 def MultuRxRyRz16: FMULT16_LO_ins<"multu", IIAlu> {
714 let isCommutable = 1;
715 let neverHasSideEffects = 1;
720 // Format: NEG rx, ry MIPS16e
722 // To negate an integer value.
724 def NegRxRy16: FUnaryRR16_ins<0b11101, "neg", IIAlu>;
727 // Format: NOT rx, ry MIPS16e
729 // To complement an integer value
731 def NotRxRy16: FUnaryRR16_ins<0b01111, "not", IIAlu>;
734 // Format: OR rx, ry MIPS16e
736 // To do a bitwise logical OR.
738 def OrRxRxRy16: FRxRxRy16_ins<0b01101, "or", IIAlu>, ArithLogic16Defs<1>;
741 // Format: RESTORE {ra,}{s0/s1/s0-1,}{framesize}
742 // (All args are optional) MIPS16e
743 // Purpose: Restore Registers and Deallocate Stack Frame
744 // To deallocate a stack frame before exit from a subroutine,
745 // restoring return address and static registers, and adjusting
749 // fixed form for restoring RA and the frame
750 // for direct object emitter, encoding needs to be adjusted for the
753 let ra=1, s=0,s0=1,s1=1 in
755 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
756 "restore\t$$ra, $$s0, $$s1, $frame_size", [], IILoad >, MayLoad {
757 let isCodeGenOnly = 1;
758 let Defs = [S0, S1, RA, SP];
762 // Use Restore to increment SP since SP is not a Mip 16 register, this
763 // is an easy way to do that which does not require a register.
765 let ra=0, s=0,s0=0,s1=0 in
767 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
768 "restore\t$frame_size", [], IILoad >, MayLoad {
769 let isCodeGenOnly = 1;
775 // Format: SAVE {ra,}{s0/s1/s0-1,}{framesize} (All arguments are optional)
777 // Purpose: Save Registers and Set Up Stack Frame
778 // To set up a stack frame on entry to a subroutine,
779 // saving return address and static registers, and adjusting stack
781 let ra=1, s=1,s0=1,s1=1 in
783 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
784 "save\t$$ra, $$s0, $$s1, $frame_size", [], IIStore >, MayStore {
785 let isCodeGenOnly = 1;
786 let Uses = [RA, SP, S0, S1];
791 // Use Save to decrement the SP by a constant since SP is not
792 // a Mips16 register.
794 let ra=0, s=0,s0=0,s1=0 in
796 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
797 "save\t$frame_size", [], IIStore >, MayStore {
798 let isCodeGenOnly = 1;
803 // Format: SB ry, offset(rx) MIPS16e
804 // Purpose: Store Byte (Extended)
805 // To store a byte to memory.
808 FEXT_RRI16_mem2_ins<0b11000, "sb", mem16, IIStore>, MayStore;
811 // The Sel(T) instructions are pseudos
812 // T means that they use T8 implicitly.
815 // Format: SelBeqZ rd, rs, rt
816 // Purpose: if rt==0, do nothing
819 def SelBeqZ: Sel<0b00100, "beqz", IIAlu>;
822 // Format: SelTBteqZCmp rd, rs, rl, rr
823 // Purpose: b = Cmp rl, rr.
824 // If b==0 then do nothing.
825 // if b!=0 then rd = rs
827 def SelTBteqZCmp: SelT<0b000, "bteqz", 0b01010, "cmp", IIAlu>;
830 // Format: SelTBteqZCmpi rd, rs, rl, rr
831 // Purpose: b = Cmpi rl, imm.
832 // If b==0 then do nothing.
833 // if b!=0 then rd = rs
835 def SelTBteqZCmpi: SeliT<0b000, "bteqz", 0b01110, "cmpi", IIAlu>;
838 // Format: SelTBteqZSlt rd, rs, rl, rr
839 // Purpose: b = Slt rl, rr.
840 // If b==0 then do nothing.
841 // if b!=0 then rd = rs
843 def SelTBteqZSlt: SelT<0b000, "bteqz", 0b00010, "slt", IIAlu>;
846 // Format: SelTBteqZSlti rd, rs, rl, rr
847 // Purpose: b = Slti rl, imm.
848 // If b==0 then do nothing.
849 // if b!=0 then rd = rs
851 def SelTBteqZSlti: SeliT<0b000, "bteqz", 0b01010, "slti", IIAlu>;
854 // Format: SelTBteqZSltu rd, rs, rl, rr
855 // Purpose: b = Sltu rl, rr.
856 // If b==0 then do nothing.
857 // if b!=0 then rd = rs
859 def SelTBteqZSltu: SelT<0b000, "bteqz", 0b00011, "sltu", IIAlu>;
862 // Format: SelTBteqZSltiu rd, rs, rl, rr
863 // Purpose: b = Sltiu rl, imm.
864 // If b==0 then do nothing.
865 // if b!=0 then rd = rs
867 def SelTBteqZSltiu: SeliT<0b000, "bteqz", 0b01011, "sltiu", IIAlu>;
870 // Format: SelBnez rd, rs, rt
871 // Purpose: if rt!=0, do nothing
874 def SelBneZ: Sel<0b00101, "bnez", IIAlu>;
877 // Format: SelTBtneZCmp rd, rs, rl, rr
878 // Purpose: b = Cmp rl, rr.
879 // If b!=0 then do nothing.
880 // if b0=0 then rd = rs
882 def SelTBtneZCmp: SelT<0b001, "btnez", 0b01010, "cmp", IIAlu>;
885 // Format: SelTBtnezCmpi rd, rs, rl, rr
886 // Purpose: b = Cmpi rl, imm.
887 // If b!=0 then do nothing.
888 // if b==0 then rd = rs
890 def SelTBtneZCmpi: SeliT<0b000, "btnez", 0b01110, "cmpi", IIAlu>;
893 // Format: SelTBtneZSlt rd, rs, rl, rr
894 // Purpose: b = Slt rl, rr.
895 // If b!=0 then do nothing.
896 // if b==0 then rd = rs
898 def SelTBtneZSlt: SelT<0b001, "btnez", 0b00010, "slt", IIAlu>;
901 // Format: SelTBtneZSlti rd, rs, rl, rr
902 // Purpose: b = Slti rl, imm.
903 // If b!=0 then do nothing.
904 // if b==0 then rd = rs
906 def SelTBtneZSlti: SeliT<0b001, "btnez", 0b01010, "slti", IIAlu>;
909 // Format: SelTBtneZSltu rd, rs, rl, rr
910 // Purpose: b = Sltu rl, rr.
911 // If b!=0 then do nothing.
912 // if b==0 then rd = rs
914 def SelTBtneZSltu: SelT<0b001, "btnez", 0b00011, "sltu", IIAlu>;
917 // Format: SelTBtneZSltiu rd, rs, rl, rr
918 // Purpose: b = Slti rl, imm.
919 // If b!=0 then do nothing.
920 // if b==0 then rd = rs
922 def SelTBtneZSltiu: SeliT<0b001, "btnez", 0b01011, "sltiu", IIAlu>;
925 // Format: SH ry, offset(rx) MIPS16e
926 // Purpose: Store Halfword (Extended)
927 // To store a halfword to memory.
930 FEXT_RRI16_mem2_ins<0b11001, "sh", mem16, IIStore>, MayStore;
933 // Format: SLL rx, ry, sa MIPS16e
934 // Purpose: Shift Word Left Logical (Extended)
935 // To execute a left-shift of a word by a fixed number of bits—0 to 31 bits.
937 def SllX16: FEXT_SHIFT16_ins<0b00, "sll", IIAlu>;
940 // Format: SLLV ry, rx MIPS16e
941 // Purpose: Shift Word Left Logical Variable
942 // To execute a left-shift of a word by a variable number of bits.
944 def SllvRxRy16 : FRxRxRy16_ins<0b00100, "sllv", IIAlu>;
947 // Format: SLTI rx, immediate MIPS16e
948 // Purpose: Set on Less Than Immediate (Extended)
949 // To record the result of a less-than comparison with a constant.
951 def SltiCCRxImmX16: FEXT_CCRXI16_ins<0b01010, "slti", IIAlu>;
954 // Format: SLTIU rx, immediate MIPS16e
955 // Purpose: Set on Less Than Immediate Unsigned (Extended)
956 // To record the result of a less-than comparison with a constant.
958 def SltiuCCRxImmX16: FEXT_CCRXI16_ins<0b01011, "sltiu", IIAlu>;
961 // Format: SLT rx, ry MIPS16e
962 // Purpose: Set on Less Than
963 // To record the result of a less-than comparison.
965 def SltRxRy16: FRR16_ins<0b00010, "slt", IIAlu>;
967 def SltCCRxRy16: FCCRR16_ins<0b00010, "slt", IIAlu>;
969 // Format: SLTU rx, ry MIPS16e
970 // Purpose: Set on Less Than Unsigned
971 // To record the result of an unsigned less-than comparison.
973 def SltuRxRyRz16: FRRTR16_ins<0b00011, "sltu", IIAlu> {
978 def SltuCCRxRy16: FCCRR16_ins<0b00011, "sltu", IIAlu>;
980 // Format: SRAV ry, rx MIPS16e
981 // Purpose: Shift Word Right Arithmetic Variable
982 // To execute an arithmetic right-shift of a word by a variable
985 def SravRxRy16: FRxRxRy16_ins<0b00111, "srav", IIAlu>;
989 // Format: SRA rx, ry, sa MIPS16e
990 // Purpose: Shift Word Right Arithmetic (Extended)
991 // To execute an arithmetic right-shift of a word by a fixed
992 // number of bits—1 to 8 bits.
994 def SraX16: FEXT_SHIFT16_ins<0b11, "sra", IIAlu>;
998 // Format: SRLV ry, rx MIPS16e
999 // Purpose: Shift Word Right Logical Variable
1000 // To execute a logical right-shift of a word by a variable
1003 def SrlvRxRy16: FRxRxRy16_ins<0b00110, "srlv", IIAlu>;
1007 // Format: SRL rx, ry, sa MIPS16e
1008 // Purpose: Shift Word Right Logical (Extended)
1009 // To execute a logical right-shift of a word by a fixed
1010 // number of bits—1 to 31 bits.
1012 def SrlX16: FEXT_SHIFT16_ins<0b10, "srl", IIAlu>;
1015 // Format: SUBU rz, rx, ry MIPS16e
1016 // Purpose: Subtract Unsigned Word
1017 // To subtract 32-bit integers
1019 def SubuRxRyRz16: FRRR16_ins<0b11, "subu", IIAlu>, ArithLogic16Defs<0>;
1022 // Format: SW ry, offset(rx) MIPS16e
1023 // Purpose: Store Word (Extended)
1024 // To store a word to memory.
1026 def SwRxRyOffMemX16:
1027 FEXT_RRI16_mem2_ins<0b11011, "sw", mem16, IIStore>, MayStore;
1030 // Format: SW rx, offset(sp) MIPS16e
1031 // Purpose: Store Word rx (SP-Relative)
1032 // To store an SP-relative word to memory.
1034 def SwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b11010, "sw", IIStore>, MayStore;
1038 // Format: XOR rx, ry MIPS16e
1040 // To do a bitwise logical XOR.
1042 def XorRxRxRy16: FRxRxRy16_ins<0b01110, "xor", IIAlu>, ArithLogic16Defs<1>;
1044 class Mips16Pat<dag pattern, dag result> : Pat<pattern, result> {
1045 let Predicates = [InMips16Mode];
1048 // Unary Arith/Logic
1050 class ArithLogicU_pat<PatFrag OpNode, Instruction I> :
1051 Mips16Pat<(OpNode CPU16Regs:$r),
1054 def: ArithLogicU_pat<not, NotRxRy16>;
1055 def: ArithLogicU_pat<ineg, NegRxRy16>;
1057 class ArithLogic16_pat<SDNode OpNode, Instruction I> :
1058 Mips16Pat<(OpNode CPU16Regs:$l, CPU16Regs:$r),
1059 (I CPU16Regs:$l, CPU16Regs:$r)>;
1061 def: ArithLogic16_pat<add, AdduRxRyRz16>;
1062 def: ArithLogic16_pat<and, AndRxRxRy16>;
1063 def: ArithLogic16_pat<mul, MultRxRyRz16>;
1064 def: ArithLogic16_pat<or, OrRxRxRy16>;
1065 def: ArithLogic16_pat<sub, SubuRxRyRz16>;
1066 def: ArithLogic16_pat<xor, XorRxRxRy16>;
1068 // Arithmetic and logical instructions with 2 register operands.
1070 class ArithLogicI16_pat<SDNode OpNode, PatFrag imm_type, Instruction I> :
1071 Mips16Pat<(OpNode CPU16Regs:$in, imm_type:$imm),
1072 (I CPU16Regs:$in, imm_type:$imm)>;
1074 def: ArithLogicI16_pat<add, immSExt8, AddiuRxRxImm16>;
1075 def: ArithLogicI16_pat<add, immSExt16, AddiuRxRxImmX16>;
1076 def: ArithLogicI16_pat<shl, immZExt5, SllX16>;
1077 def: ArithLogicI16_pat<srl, immZExt5, SrlX16>;
1078 def: ArithLogicI16_pat<sra, immZExt5, SraX16>;
1080 class shift_rotate_reg16_pat<SDNode OpNode, Instruction I> :
1081 Mips16Pat<(OpNode CPU16Regs:$r, CPU16Regs:$ra),
1082 (I CPU16Regs:$r, CPU16Regs:$ra)>;
1084 def: shift_rotate_reg16_pat<shl, SllvRxRy16>;
1085 def: shift_rotate_reg16_pat<sra, SravRxRy16>;
1086 def: shift_rotate_reg16_pat<srl, SrlvRxRy16>;
1088 class LoadM16_pat<PatFrag OpNode, Instruction I> :
1089 Mips16Pat<(OpNode addr16:$addr), (I addr16:$addr)>;
1091 def: LoadM16_pat<sextloadi8, LbRxRyOffMemX16>;
1092 def: LoadM16_pat<zextloadi8, LbuRxRyOffMemX16>;
1093 def: LoadM16_pat<sextloadi16, LhRxRyOffMemX16>;
1094 def: LoadM16_pat<zextloadi16, LhuRxRyOffMemX16>;
1095 def: LoadM16_pat<load, LwRxRyOffMemX16>;
1097 class StoreM16_pat<PatFrag OpNode, Instruction I> :
1098 Mips16Pat<(OpNode CPU16Regs:$r, addr16:$addr),
1099 (I CPU16Regs:$r, addr16:$addr)>;
1101 def: StoreM16_pat<truncstorei8, SbRxRyOffMemX16>;
1102 def: StoreM16_pat<truncstorei16, ShRxRyOffMemX16>;
1103 def: StoreM16_pat<store, SwRxRyOffMemX16>;
1105 // Unconditional branch
1106 class UncondBranch16_pat<SDNode OpNode, Instruction I>:
1107 Mips16Pat<(OpNode bb:$imm16), (I bb:$imm16)> {
1108 let Predicates = [InMips16Mode];
1111 def : Mips16Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
1112 (Jal16 tglobaladdr:$dst)>;
1114 def : Mips16Pat<(MipsJmpLink (i32 texternalsym:$dst)),
1115 (Jal16 texternalsym:$dst)>;
1119 (brind CPU16Regs:$rs),
1120 (JrcRx16 CPU16Regs:$rs)>;
1122 // Jump and Link (Call)
1123 let isCall=1, hasDelaySlot=0 in
1125 FRR16_JALRC<0, 0, 0, (outs), (ins CPU16Regs:$rs),
1126 "jalrc \t$rs", [(MipsJmpLink CPU16Regs:$rs)], IIBranch>;
1129 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1,
1130 hasExtraSrcRegAllocReq = 1 in
1131 def RetRA16 : MipsPseudo16<(outs), (ins), "", [(MipsRet)]>;
1136 class SetCC_R16<PatFrag cond_op, Instruction I>:
1137 Mips16Pat<(cond_op CPU16Regs:$rx, CPU16Regs:$ry),
1138 (I CPU16Regs:$rx, CPU16Regs:$ry)>;
1140 class SetCC_I16<PatFrag cond_op, PatLeaf imm_type, Instruction I>:
1141 Mips16Pat<(cond_op CPU16Regs:$rx, imm_type:$imm16),
1142 (I CPU16Regs:$rx, imm_type:$imm16)>;
1145 def: Mips16Pat<(i32 addr16:$addr),
1146 (AddiuRxRyOffMemX16 addr16:$addr)>;
1149 // Large (>16 bit) immediate loads
1150 def : Mips16Pat<(i32 imm:$imm),
1151 (OrRxRxRy16 (SllX16 (LiRxImmX16 (HI16 imm:$imm)), 16),
1152 (LiRxImmX16 (LO16 imm:$imm)))>;
1154 // Carry MipsPatterns
1155 def : Mips16Pat<(subc CPU16Regs:$lhs, CPU16Regs:$rhs),
1156 (SubuRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1157 def : Mips16Pat<(addc CPU16Regs:$lhs, CPU16Regs:$rhs),
1158 (AdduRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1159 def : Mips16Pat<(addc CPU16Regs:$src, immSExt16:$imm),
1160 (AddiuRxRxImmX16 CPU16Regs:$src, imm:$imm)>;
1163 // Some branch conditional patterns are not generated by llvm at this time.
1164 // Some are for seemingly arbitrary reasons not used: i.e. with signed number
1165 // comparison they are used and for unsigned a different pattern is used.
1166 // I am pushing upstream from the full mips16 port and it seemed that I needed
1167 // these earlier and the mips32 port has these but now I cannot create test
1168 // cases that use these patterns. While I sort this all out I will leave these
1169 // extra patterns commented out and if I can be sure they are really not used,
1170 // I will delete the code. I don't want to check the code in uncommented without
1171 // a valid test case. In some cases, the compiler is generating patterns with
1172 // setcc instead and earlier I had implemented setcc first so may have masked
1173 // the problem. The setcc variants are suboptimal for mips16 so I may wantto
1174 // figure out how to enable the brcond patterns or else possibly new
1175 // combinations of of brcond and setcc.
1181 <(brcond (i32 (seteq CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1182 (BteqzT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1187 <(brcond (i32 (seteq CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1188 (BteqzT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1192 <(brcond (i32 (seteq CPU16Regs:$rx, 0)), bb:$targ16),
1193 (BeqzRxImmX16 CPU16Regs:$rx, bb:$targ16)
1197 // bcond-setgt (do we need to have this pair of setlt, setgt??)
1200 <(brcond (i32 (setgt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1201 (BtnezT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1208 <(brcond (i32 (setge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1209 (BteqzT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1213 // never called because compiler transforms a >= k to a > (k-1)
1215 <(brcond (i32 (setge CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1216 (BteqzT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1223 <(brcond (i32 (setlt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1224 (BtnezT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1228 <(brcond (i32 (setlt CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1229 (BtnezT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1236 <(brcond (i32 (setle CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1237 (BteqzT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1244 <(brcond (i32 (setne CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1245 (BtnezT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1249 <(brcond (i32 (setne CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1250 (BtnezT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1254 <(brcond (i32 (setne CPU16Regs:$rx, 0)), bb:$targ16),
1255 (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1259 // This needs to be there but I forget which code will generate it
1262 <(brcond CPU16Regs:$rx, bb:$targ16),
1263 (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1272 // <(brcond (i32 (setugt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1273 // (BtnezT8SltuX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1280 // <(brcond (i32 (setuge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1281 // (BteqzT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1289 // <(brcond (i32 (setult CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1290 // (BtnezT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1293 def: UncondBranch16_pat<br, BimmX16>;
1296 def: Mips16Pat<(i32 immSExt16:$in),
1297 (AddiuRxRxImmX16 (Move32R16 ZERO), immSExt16:$in)>;
1299 def: Mips16Pat<(i32 immZExt16:$in), (LiRxImmX16 immZExt16:$in)>;
1305 <(MipsDivRem CPU16Regs:$rx, CPU16Regs:$ry),
1306 (DivRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1312 <(MipsDivRemU CPU16Regs:$rx, CPU16Regs:$ry),
1313 (DivuRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1318 // if !(a < b) x = y
1320 def : Mips16Pat<(select (i32 (setge CPU16Regs:$a, CPU16Regs:$b)),
1321 CPU16Regs:$x, CPU16Regs:$y),
1322 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1323 CPU16Regs:$a, CPU16Regs:$b)>;
1330 def : Mips16Pat<(select (i32 (setgt CPU16Regs:$a, CPU16Regs:$b)),
1331 CPU16Regs:$x, CPU16Regs:$y),
1332 (SelTBtneZSlt CPU16Regs:$x, CPU16Regs:$y,
1333 CPU16Regs:$b, CPU16Regs:$a)>;
1338 // if !(a < b) x = y;
1341 (select (i32 (setuge CPU16Regs:$a, CPU16Regs:$b)),
1342 CPU16Regs:$x, CPU16Regs:$y),
1343 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1344 CPU16Regs:$a, CPU16Regs:$b)>;
1351 def : Mips16Pat<(select (i32 (setugt CPU16Regs:$a, CPU16Regs:$b)),
1352 CPU16Regs:$x, CPU16Regs:$y),
1353 (SelTBtneZSltu CPU16Regs:$x, CPU16Regs:$y,
1354 CPU16Regs:$b, CPU16Regs:$a)>;
1358 // due to an llvm optimization, i don't think that this will ever
1359 // be used. This is transformed into x = (a > k-1)?x:y
1364 // (select (i32 (setge CPU16Regs:$lhs, immSExt16:$rhs)),
1365 // CPU16Regs:$T, CPU16Regs:$F),
1366 // (SelTBteqZSlti CPU16Regs:$T, CPU16Regs:$F,
1367 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1370 // (select (i32 (setuge CPU16Regs:$lhs, immSExt16:$rhs)),
1371 // CPU16Regs:$T, CPU16Regs:$F),
1372 // (SelTBteqZSltiu CPU16Regs:$T, CPU16Regs:$F,
1373 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1378 // if !(a < k) x = y;
1381 (select (i32 (setlt CPU16Regs:$a, immSExt16:$b)),
1382 CPU16Regs:$x, CPU16Regs:$y),
1383 (SelTBtneZSlti CPU16Regs:$x, CPU16Regs:$y,
1384 CPU16Regs:$a, immSExt16:$b)>;
1390 // x = (a <= b)? x : y
1394 def : Mips16Pat<(select (i32 (setle CPU16Regs:$a, CPU16Regs:$b)),
1395 CPU16Regs:$x, CPU16Regs:$y),
1396 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1397 CPU16Regs:$b, CPU16Regs:$a)>;
1401 // x = (a <= b)? x : y
1405 def : Mips16Pat<(select (i32 (setule CPU16Regs:$a, CPU16Regs:$b)),
1406 CPU16Regs:$x, CPU16Regs:$y),
1407 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1408 CPU16Regs:$b, CPU16Regs:$a)>;
1412 // x = (a == b)? x : y
1414 // if (a != b) x = y
1416 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, CPU16Regs:$b)),
1417 CPU16Regs:$x, CPU16Regs:$y),
1418 (SelTBteqZCmp CPU16Regs:$x, CPU16Regs:$y,
1419 CPU16Regs:$b, CPU16Regs:$a)>;
1423 // x = (a == 0)? x : y
1425 // if (a != 0) x = y
1427 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, 0)),
1428 CPU16Regs:$x, CPU16Regs:$y),
1429 (SelBeqZ CPU16Regs:$x, CPU16Regs:$y,
1435 // x = (a == k)? x : y
1437 // if (a != k) x = y
1439 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, immZExt16:$k)),
1440 CPU16Regs:$x, CPU16Regs:$y),
1441 (SelTBteqZCmpi CPU16Regs:$x, CPU16Regs:$y,
1442 CPU16Regs:$a, immZExt16:$k)>;
1447 // x = (a != b)? x : y
1449 // if (a == b) x = y
1452 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, CPU16Regs:$b)),
1453 CPU16Regs:$x, CPU16Regs:$y),
1454 (SelTBtneZCmp CPU16Regs:$x, CPU16Regs:$y,
1455 CPU16Regs:$b, CPU16Regs:$a)>;
1459 // x = (a != 0)? x : y
1461 // if (a == 0) x = y
1463 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, 0)),
1464 CPU16Regs:$x, CPU16Regs:$y),
1465 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1473 def : Mips16Pat<(select CPU16Regs:$a,
1474 CPU16Regs:$x, CPU16Regs:$y),
1475 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1481 // x = (a != k)? x : y
1483 // if (a == k) x = y
1485 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, immZExt16:$k)),
1486 CPU16Regs:$x, CPU16Regs:$y),
1487 (SelTBtneZCmpi CPU16Regs:$x, CPU16Regs:$y,
1488 CPU16Regs:$a, immZExt16:$k)>;
1491 // When writing C code to test setxx these patterns,
1492 // some will be transformed into
1493 // other things. So we test using C code but using -O3 and -O0
1498 <(seteq CPU16Regs:$lhs,CPU16Regs:$rhs),
1499 (SltiuCCRxImmX16 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs), 1)>;
1502 <(seteq CPU16Regs:$lhs, 0),
1503 (SltiuCCRxImmX16 CPU16Regs:$lhs, 1)>;
1511 <(setge CPU16Regs:$lhs, CPU16Regs:$rhs),
1512 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1516 // For constants, llvm transforms this to:
1517 // x > (k -1) and then reverses the operands to use setlt. So this pattern
1518 // is not used now by the compiler. (Presumably checking that k-1 does not
1519 // overflow). The compiler never uses this at a the current time, due to
1520 // other optimizations.
1523 // <(setge CPU16Regs:$lhs, immSExt16:$rhs),
1524 // (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, immSExt16:$rhs),
1525 // (LiRxImmX16 1))>;
1527 // This catches the x >= -32768 case by transforming it to x > -32769
1530 <(setgt CPU16Regs:$lhs, -32769),
1531 (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, -32768),
1540 <(setgt CPU16Regs:$lhs, CPU16Regs:$rhs),
1541 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1547 <(setle CPU16Regs:$lhs, CPU16Regs:$rhs),
1548 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImmX16 1))>;
1553 def: SetCC_R16<setlt, SltCCRxRy16>;
1555 def: SetCC_I16<setlt, immSExt16, SltiCCRxImmX16>;
1561 <(setne CPU16Regs:$lhs,CPU16Regs:$rhs),
1562 (SltuCCRxRy16 (LiRxImmX16 0),
1563 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs))>;
1570 <(setuge CPU16Regs:$lhs, CPU16Regs:$rhs),
1571 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1574 // this pattern will never be used because the compiler will transform
1575 // x >= k to x > (k - 1) and then use SLT
1578 // <(setuge CPU16Regs:$lhs, immZExt16:$rhs),
1579 // (XorRxRxRy16 (SltiuCCRxImmX16 CPU16Regs:$lhs, immZExt16:$rhs),
1580 // (LiRxImmX16 1))>;
1586 <(setugt CPU16Regs:$lhs, CPU16Regs:$rhs),
1587 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1593 <(setule CPU16Regs:$lhs, CPU16Regs:$rhs),
1594 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImmX16 1))>;
1599 def: SetCC_R16<setult, SltuCCRxRy16>;
1601 def: SetCC_I16<setult, immSExt16, SltiuCCRxImmX16>;
1603 def: Mips16Pat<(add CPU16Regs:$hi, (MipsLo tglobaladdr:$lo)),
1604 (AddiuRxRxImmX16 CPU16Regs:$hi, tglobaladdr:$lo)>;
1608 def : Mips16Pat<(MipsHi tglobaladdr:$in),
1609 (SllX16 (LiRxImmX16 tglobaladdr:$in), 16)>;
1610 def : Mips16Pat<(MipsHi tjumptable:$in),
1611 (SllX16 (LiRxImmX16 tjumptable:$in), 16)>;
1612 def : Mips16Pat<(MipsHi tglobaltlsaddr:$in),
1613 (SllX16 (LiRxImmX16 tglobaltlsaddr:$in), 16)>;
1616 class Wrapper16Pat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1617 Mips16Pat<(MipsWrapper RC:$gp, node:$in),
1618 (ADDiuOp RC:$gp, node:$in)>;
1621 def : Wrapper16Pat<tglobaladdr, AddiuRxRxImmX16, CPU16Regs>;
1622 def : Wrapper16Pat<tglobaltlsaddr, AddiuRxRxImmX16, CPU16Regs>;
1624 def : Mips16Pat<(i32 (extloadi8 addr16:$src)),
1625 (LbuRxRyOffMemX16 addr16:$src)>;
1626 def : Mips16Pat<(i32 (extloadi16 addr16:$src)),
1627 (LhuRxRyOffMemX16 addr16:$src)>;