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 F2RI16_ins<bits<5> _op, string asmstr,
56 FRI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
57 !strconcat(asmstr, "\t$rx, $imm\t# 16 bit inst"), [], itin> {
58 let Constraints = "$rx_ = $rx";
62 // Compare a register and immediate and place result in CC
65 // EXT-CCRR Instruction format
67 class FEXT_CCRXI16_ins<string asmstr>:
68 MipsPseudo16<(outs CPU16Regs:$cc), (ins CPU16Regs:$rx, simm16:$imm),
69 !strconcat(asmstr, "\t$rx, $imm\n\tmove\t$cc, $$t8"), []> {
73 // JAL and JALX instruction format
75 class FJAL16_ins<bits<1> _X, string asmstr,
77 FJAL16<_X, (outs), (ins simm20:$imm),
78 !strconcat(asmstr, "\t$imm\n\tnop"),[],
83 // EXT-I instruction format
85 class FEXT_I16_ins<bits<5> eop, string asmstr, InstrItinClass itin> :
86 FEXT_I16<eop, (outs), (ins brtarget:$imm16),
87 !strconcat(asmstr, "\t$imm16"),[], itin>;
90 // EXT-I8 instruction format
93 class FEXT_I816_ins_base<bits<3> _func, string asmstr,
94 string asmstr2, InstrItinClass itin>:
95 FEXT_I816<_func, (outs), (ins simm16:$imm), !strconcat(asmstr, asmstr2),
98 class FEXT_I816_ins<bits<3> _func, string asmstr,
100 FEXT_I816_ins_base<_func, asmstr, "\t$imm", itin>;
102 class FEXT_I816_SP_ins<bits<3> _func, string asmstr,
103 InstrItinClass itin>:
104 FEXT_I816_ins_base<_func, asmstr, "\t$$sp, $imm", itin>;
107 // Assembler formats in alphabetical order.
108 // Natural and pseudos are mixed together.
110 // Compare two registers and place result in CC
111 // Implicit use of T8
113 // CC-RR Instruction format
115 class FCCRR16_ins<string asmstr> :
116 MipsPseudo16<(outs CPU16Regs:$cc), (ins CPU16Regs:$rx, CPU16Regs:$ry),
117 !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$cc, $$t8"), []> {
122 // EXT-RI instruction format
125 class FEXT_RI16_ins_base<bits<5> _op, string asmstr, string asmstr2,
126 InstrItinClass itin>:
127 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins simm16:$imm),
128 !strconcat(asmstr, asmstr2), [], itin>;
130 class FEXT_RI16_ins<bits<5> _op, string asmstr,
131 InstrItinClass itin>:
132 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
134 class FEXT_RI16_PC_ins<bits<5> _op, string asmstr, InstrItinClass itin>:
135 FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $$pc, $imm", itin>;
137 class FEXT_RI16_B_ins<bits<5> _op, string asmstr,
138 InstrItinClass itin>:
139 FEXT_RI16<_op, (outs), (ins CPU16Regs:$rx, brtarget:$imm),
140 !strconcat(asmstr, "\t$rx, $imm"), [], itin>;
142 class FEXT_2RI16_ins<bits<5> _op, string asmstr,
143 InstrItinClass itin>:
144 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
145 !strconcat(asmstr, "\t$rx, $imm"), [], itin> {
146 let Constraints = "$rx_ = $rx";
150 // this has an explicit sp argument that we ignore to work around a problem
152 class FEXT_RI16_SP_explicit_ins<bits<5> _op, string asmstr,
153 InstrItinClass itin>:
154 FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPUSPReg:$ry, simm16:$imm),
155 !strconcat(asmstr, "\t$rx, $imm ( $ry ); "), [], itin>;
158 // EXT-RRI instruction format
161 class FEXT_RRI16_mem_ins<bits<5> op, string asmstr, Operand MemOpnd,
162 InstrItinClass itin>:
163 FEXT_RRI16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
164 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
166 class FEXT_RRI16_mem2_ins<bits<5> op, string asmstr, Operand MemOpnd,
167 InstrItinClass itin>:
168 FEXT_RRI16<op, (outs ), (ins CPU16Regs:$ry, MemOpnd:$addr),
169 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
173 // EXT-RRI-A instruction format
176 class FEXT_RRI_A16_mem_ins<bits<1> op, string asmstr, Operand MemOpnd,
177 InstrItinClass itin>:
178 FEXT_RRI_A16<op, (outs CPU16Regs:$ry), (ins MemOpnd:$addr),
179 !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
182 // EXT-SHIFT instruction format
184 class FEXT_SHIFT16_ins<bits<2> _f, string asmstr, InstrItinClass itin>:
185 FEXT_SHIFT16<_f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry, shamt:$sa),
186 !strconcat(asmstr, "\t$rx, $ry, $sa"), [], itin>;
191 class FEXT_T8I816_ins<string asmstr, string asmstr2>:
193 (ins CPU16Regs:$rx, CPU16Regs:$ry, brtarget:$imm),
194 !strconcat(asmstr2, !strconcat("\t$rx, $ry\n\t",
195 !strconcat(asmstr, "\t$imm"))),[]> {
202 class FEXT_T8I8I16_ins<string asmstr, string asmstr2>:
204 (ins CPU16Regs:$rx, simm16:$imm, brtarget:$targ),
205 !strconcat(asmstr2, !strconcat("\t$rx, $imm\n\t",
206 !strconcat(asmstr, "\t$targ"))), []> {
213 // I8_MOVR32 instruction format (used only by the MOVR32 instructio
215 class FI8_MOVR3216_ins<string asmstr, InstrItinClass itin>:
216 FI8_MOVR3216<(outs CPU16Regs:$rz), (ins CPURegs:$r32),
217 !strconcat(asmstr, "\t$rz, $r32"), [], itin>;
220 // I8_MOV32R instruction format (used only by MOV32R instruction)
223 class FI8_MOV32R16_ins<string asmstr, InstrItinClass itin>:
224 FI8_MOV32R16<(outs CPURegs:$r32), (ins CPU16Regs:$rz),
225 !strconcat(asmstr, "\t$r32, $rz"), [], itin>;
228 // This are pseudo formats for multiply
229 // This first one can be changed to non pseudo now.
233 class FMULT16_ins<string asmstr, InstrItinClass itin> :
234 MipsPseudo16<(outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
235 !strconcat(asmstr, "\t$rx, $ry"), []>;
240 class FMULT16_LO_ins<string asmstr, InstrItinClass itin> :
241 MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
242 !strconcat(asmstr, "\t$rx, $ry\n\tmflo\t$rz"), []> {
247 // RR-type instruction format
250 class FRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
251 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
252 !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
255 class FRRTR16_ins<string asmstr> :
256 MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
257 !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$rz, $$t8"), []> ;
260 // maybe refactor but need a $zero as a dummy first parameter
262 class FRR16_div_ins<bits<5> f, string asmstr, InstrItinClass itin> :
263 FRR16<f, (outs ), (ins CPU16Regs:$rx, CPU16Regs:$ry),
264 !strconcat(asmstr, "\t$$zero, $rx, $ry"), [], itin> ;
266 class FUnaryRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
267 FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
268 !strconcat(asmstr, "\t$rx, $ry"), [], itin> ;
271 class FRR16_M_ins<bits<5> f, string asmstr,
272 InstrItinClass itin> :
273 FRR16<f, (outs CPU16Regs:$rx), (ins),
274 !strconcat(asmstr, "\t$rx"), [], itin>;
276 class FRxRxRy16_ins<bits<5> f, string asmstr,
277 InstrItinClass itin> :
278 FRR16<f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
279 !strconcat(asmstr, "\t$rz, $ry"),
281 let Constraints = "$rx = $rz";
285 class FRR16_JALRC_RA_only_ins<bits<1> nd_, bits<1> l_,
286 string asmstr, InstrItinClass itin>:
287 FRR16_JALRC<nd_, l_, 1, (outs), (ins), !strconcat(asmstr, "\t $$ra"),
291 class FRR16_JALRC_ins<bits<1> nd, bits<1> l, bits<1> ra,
292 string asmstr, InstrItinClass itin>:
293 FRR16_JALRC<nd, l, ra, (outs), (ins CPU16Regs:$rx),
294 !strconcat(asmstr, "\t $rx"), [], itin> ;
297 // RRR-type instruction format
300 class FRRR16_ins<bits<2> _f, string asmstr, InstrItinClass itin> :
301 FRRR16<_f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
302 !strconcat(asmstr, "\t$rz, $rx, $ry"), [], itin>;
305 // These Sel patterns support the generation of conditional move
306 // pseudo instructions.
308 // The nomenclature uses the components making up the pseudo and may
309 // be a bit counter intuitive when compared with the end result we seek.
310 // For example using a bqez in the example directly below results in the
311 // conditional move being done if the tested register is not zero.
312 // I considered in easier to check by keeping the pseudo consistent with
313 // it's components but it could have been done differently.
315 // The simplest case is when can test and operand directly and do the
316 // conditional move based on a simple mips16 conditional
317 // branch instruction.
319 // if $op == beqz or bnez:
324 // if $op == beqz, then if $rt != 0, then the conditional assignment
325 // $rd = $rs is done.
327 // if $op == bnez, then if $rt == 0, then the conditional assignment
328 // $rd = $rs is done.
330 // So this pseudo class only has one operand, i.e. op
332 class Sel<string op>:
333 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
335 !strconcat(op, "\t$rt, .+4\n\t\n\tmove $rd, $rs"), []> {
336 //let isCodeGenOnly=1;
337 let Constraints = "$rd = $rd_";
341 // The next two instruction classes allow for an operand which tests
342 // two operands and returns a value in register T8 and
343 //then does a conditional branch based on the value of T8
346 // op2 can be cmpi or slti/sltiu
347 // op1 can bteqz or btnez
348 // the operands for op2 are a register and a signed constant
350 // $op2 $t, $imm ;test register t and branch conditionally
351 // $op1 .+4 ;op1 is a conditional branch
355 class SeliT<string op1, string op2>:
356 MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
357 CPU16Regs:$rl, simm16:$imm),
359 !strconcat("\t$rl, $imm\n\t",
360 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
362 let Constraints = "$rd = $rd_";
366 // op2 can be cmp or slt/sltu
367 // op1 can be bteqz or btnez
368 // the operands for op2 are two registers
369 // op1 is a conditional branch
372 // $op2 $rl, $rr ;test registers rl,rr
373 // $op1 .+4 ;op2 is a conditional branch
377 class SelT<string op1, string op2>:
378 MipsPseudo16<(outs CPU16Regs:$rd_),
379 (ins CPU16Regs:$rd, CPU16Regs:$rs,
380 CPU16Regs:$rl, CPU16Regs:$rr),
382 !strconcat("\t$rl, $rr\n\t",
383 !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
385 let Constraints = "$rd = $rd_";
391 def imm32: Operand<i32>;
394 MipsPseudo16<(outs), (ins imm32:$imm), "\t.word $imm", []>;
397 MipsPseudo16<(outs), (ins CPU16Regs:$rx, imm32:$imm),
398 "lw\t$rx, 1f\n\tb\t2f\n\t.align\t2\n1: \t.word\t$imm\n2:", []>;
402 // Some general instruction class info
406 class ArithLogic16Defs<bit isCom=0> {
408 bit isCommutable = isCom;
409 bit isReMaterializable = 1;
410 bit neverHasSideEffects = 1;
415 bit isTerminator = 1;
421 bit isTerminator = 1;
434 // Format: ADDIU rx, immediate MIPS16e
435 // Purpose: Add Immediate Unsigned Word (2-Operand, Extended)
436 // To add a constant to a 32-bit integer.
438 def AddiuRxImmX16: FEXT_RI16_ins<0b01001, "addiu", IIAlu>;
440 def AddiuRxRxImm16: F2RI16_ins<0b01001, "addiu", IIAlu>,
441 ArithLogic16Defs<0> {
442 let AddedComplexity = 5;
444 def AddiuRxRxImmX16: FEXT_2RI16_ins<0b01001, "addiu", IIAlu>,
445 ArithLogic16Defs<0> {
446 let isCodeGenOnly = 1;
449 def AddiuRxRyOffMemX16:
450 FEXT_RRI_A16_mem_ins<0, "addiu", mem16_ea, IIAlu>;
454 // Format: ADDIU rx, pc, immediate MIPS16e
455 // Purpose: Add Immediate Unsigned Word (3-Operand, PC-Relative, Extended)
456 // To add a constant to the program counter.
458 def AddiuRxPcImmX16: FEXT_RI16_PC_ins<0b00001, "addiu", IIAlu>;
461 // Format: ADDIU sp, immediate MIPS16e
462 // Purpose: Add Immediate Unsigned Word (2-Operand, SP-Relative, Extended)
463 // To add a constant to the stack pointer.
466 : FI816_SP_ins<0b011, "addiu", IIAlu> {
469 let AddedComplexity = 5;
473 : FEXT_I816_SP_ins<0b011, "addiu", IIAlu> {
479 // Format: ADDU rz, rx, ry MIPS16e
480 // Purpose: Add Unsigned Word (3-Operand)
481 // To add 32-bit integers.
484 def AdduRxRyRz16: FRRR16_ins<01, "addu", IIAlu>, ArithLogic16Defs<1>;
487 // Format: AND rx, ry MIPS16e
489 // To do a bitwise logical AND.
491 def AndRxRxRy16: FRxRxRy16_ins<0b01100, "and", IIAlu>, ArithLogic16Defs<1>;
495 // Format: BEQZ rx, offset MIPS16e
496 // Purpose: Branch on Equal to Zero (Extended)
497 // To test a GPR then do a PC-relative conditional branch.
499 def BeqzRxImmX16: FEXT_RI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
501 // Format: B offset MIPS16e
502 // Purpose: Unconditional Branch
503 // To do an unconditional PC-relative branch.
505 def BimmX16: FEXT_I16_ins<0b00010, "b", IIAlu>, branch16;
508 // Format: BNEZ rx, offset MIPS16e
509 // Purpose: Branch on Not Equal to Zero (Extended)
510 // To test a GPR then do a PC-relative conditional branch.
512 def BnezRxImmX16: FEXT_RI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
515 // Format: BTEQZ offset MIPS16e
516 // Purpose: Branch on T Equal to Zero (Extended)
517 // To test special register T then do a PC-relative conditional branch.
519 def BteqzX16: FEXT_I816_ins<0b000, "bteqz", IIAlu>, cbranch16;
521 def BteqzT8CmpX16: FEXT_T8I816_ins<"bteqz", "cmp">, cbranch16;
523 def BteqzT8CmpiX16: FEXT_T8I8I16_ins<"bteqz", "cmpi">,
526 def BteqzT8SltX16: FEXT_T8I816_ins<"bteqz", "slt">, cbranch16;
528 def BteqzT8SltuX16: FEXT_T8I816_ins<"bteqz", "sltu">, cbranch16;
530 def BteqzT8SltiX16: FEXT_T8I8I16_ins<"bteqz", "slti">, cbranch16;
532 def BteqzT8SltiuX16: FEXT_T8I8I16_ins<"bteqz", "sltiu">,
536 // Format: BTNEZ offset MIPS16e
537 // Purpose: Branch on T Not Equal to Zero (Extended)
538 // To test special register T then do a PC-relative conditional branch.
540 def BtnezX16: FEXT_I816_ins<0b001, "btnez", IIAlu> ,cbranch16;
542 def BtnezT8CmpX16: FEXT_T8I816_ins<"btnez", "cmp">, cbranch16;
544 def BtnezT8CmpiX16: FEXT_T8I8I16_ins<"btnez", "cmpi">, cbranch16;
546 def BtnezT8SltX16: FEXT_T8I816_ins<"btnez", "slt">, cbranch16;
548 def BtnezT8SltuX16: FEXT_T8I816_ins<"btnez", "sltu">, cbranch16;
550 def BtnezT8SltiX16: FEXT_T8I8I16_ins<"btnez", "slti">, cbranch16;
552 def BtnezT8SltiuX16: FEXT_T8I8I16_ins<"btnez", "sltiu">,
556 // Format: DIV rx, ry MIPS16e
557 // Purpose: Divide Word
558 // To divide 32-bit signed integers.
560 def DivRxRy16: FRR16_div_ins<0b11010, "div", IIAlu> {
565 // Format: DIVU rx, ry MIPS16e
566 // Purpose: Divide Unsigned Word
567 // To divide 32-bit unsigned integers.
569 def DivuRxRy16: FRR16_div_ins<0b11011, "divu", IIAlu> {
573 // Format: JAL target MIPS16e
574 // Purpose: Jump and Link
575 // To execute a procedure call within the current 256 MB-aligned
576 // region and preserve the current ISA.
579 def Jal16 : FJAL16_ins<0b0, "jal", IIAlu> {
581 let hasDelaySlot = 0; // not true, but we add the nop for now
587 // Format: JR ra MIPS16e
588 // Purpose: Jump Register Through Register ra
589 // To execute a branch to the instruction address in the return
593 def JrRa16: FRR16_JALRC_RA_only_ins<0, 0, "jr", IIAlu> {
595 let isIndirectBranch = 1;
596 let hasDelaySlot = 1;
601 def JrcRa16: FRR16_JALRC_RA_only_ins<1, 1, "jrc", IIAlu> {
603 let isIndirectBranch = 1;
608 def JrcRx16: FRR16_JALRC_ins<1, 1, 0, "jrc", IIAlu> {
610 let isIndirectBranch = 1;
615 // Format: LB ry, offset(rx) MIPS16e
616 // Purpose: Load Byte (Extended)
617 // To load a byte from memory as a signed value.
619 def LbRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lb", mem16, IILoad>, MayLoad{
620 let isCodeGenOnly = 1;
624 // Format: LBU ry, offset(rx) MIPS16e
625 // Purpose: Load Byte Unsigned (Extended)
626 // To load a byte from memory as a unsigned value.
628 def LbuRxRyOffMemX16:
629 FEXT_RRI16_mem_ins<0b10100, "lbu", mem16, IILoad>, MayLoad {
630 let isCodeGenOnly = 1;
634 // Format: LH ry, offset(rx) MIPS16e
635 // Purpose: Load Halfword signed (Extended)
636 // To load a halfword from memory as a signed value.
638 def LhRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10100, "lh", mem16, IILoad>, MayLoad{
639 let isCodeGenOnly = 1;
643 // Format: LHU ry, offset(rx) MIPS16e
644 // Purpose: Load Halfword unsigned (Extended)
645 // To load a halfword from memory as an unsigned value.
647 def LhuRxRyOffMemX16:
648 FEXT_RRI16_mem_ins<0b10100, "lhu", mem16, IILoad>, MayLoad {
649 let isCodeGenOnly = 1;
653 // Format: LI rx, immediate MIPS16e
654 // Purpose: Load Immediate (Extended)
655 // To load a constant into a GPR.
657 def LiRxImmX16: FEXT_RI16_ins<0b01101, "li", IIAlu>;
660 // Format: LW ry, offset(rx) MIPS16e
661 // Purpose: Load Word (Extended)
662 // To load a word from memory as a signed value.
664 def LwRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lw", mem16, IILoad>, MayLoad{
665 let isCodeGenOnly = 1;
668 // Format: LW rx, offset(sp) MIPS16e
669 // Purpose: Load Word (SP-Relative, Extended)
670 // To load an SP-relative word from memory as a signed value.
672 def LwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b10110, "lw", IILoad>, MayLoad{
677 // Format: MOVE r32, rz MIPS16e
679 // To move the contents of a GPR to a GPR.
681 def Move32R16: FI8_MOV32R16_ins<"move", IIAlu>;
684 // Format: MOVE ry, r32 MIPS16e
686 // To move the contents of a GPR to a GPR.
688 def MoveR3216: FI8_MOVR3216_ins<"move", IIAlu>;
691 // Format: MFHI rx MIPS16e
692 // Purpose: Move From HI Register
693 // To copy the special purpose HI register to a GPR.
695 def Mfhi16: FRR16_M_ins<0b10000, "mfhi", IIAlu> {
697 let neverHasSideEffects = 1;
701 // Format: MFLO rx MIPS16e
702 // Purpose: Move From LO Register
703 // To copy the special purpose LO register to a GPR.
705 def Mflo16: FRR16_M_ins<0b10010, "mflo", IIAlu> {
707 let neverHasSideEffects = 1;
711 // Pseudo Instruction for mult
713 def MultRxRy16: FMULT16_ins<"mult", IIAlu> {
714 let isCommutable = 1;
715 let neverHasSideEffects = 1;
719 def MultuRxRy16: FMULT16_ins<"multu", IIAlu> {
720 let isCommutable = 1;
721 let neverHasSideEffects = 1;
726 // Format: MULT rx, ry MIPS16e
727 // Purpose: Multiply Word
728 // To multiply 32-bit signed integers.
730 def MultRxRyRz16: FMULT16_LO_ins<"mult", IIAlu> {
731 let isCommutable = 1;
732 let neverHasSideEffects = 1;
737 // Format: MULTU rx, ry MIPS16e
738 // Purpose: Multiply Unsigned Word
739 // To multiply 32-bit unsigned integers.
741 def MultuRxRyRz16: FMULT16_LO_ins<"multu", IIAlu> {
742 let isCommutable = 1;
743 let neverHasSideEffects = 1;
748 // Format: NEG rx, ry MIPS16e
750 // To negate an integer value.
752 def NegRxRy16: FUnaryRR16_ins<0b11101, "neg", IIAlu>;
755 // Format: NOT rx, ry MIPS16e
757 // To complement an integer value
759 def NotRxRy16: FUnaryRR16_ins<0b01111, "not", IIAlu>;
762 // Format: OR rx, ry MIPS16e
764 // To do a bitwise logical OR.
766 def OrRxRxRy16: FRxRxRy16_ins<0b01101, "or", IIAlu>, ArithLogic16Defs<1>;
769 // Format: RESTORE {ra,}{s0/s1/s0-1,}{framesize}
770 // (All args are optional) MIPS16e
771 // Purpose: Restore Registers and Deallocate Stack Frame
772 // To deallocate a stack frame before exit from a subroutine,
773 // restoring return address and static registers, and adjusting
777 // fixed form for restoring RA and the frame
778 // for direct object emitter, encoding needs to be adjusted for the
781 let ra=1, s=0,s0=1,s1=1 in
783 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
784 "restore\t$$ra, $$s0, $$s1, $frame_size", [], IILoad >, MayLoad {
785 let isCodeGenOnly = 1;
786 let Defs = [S0, S1, RA, SP];
790 // Use Restore to increment SP since SP is not a Mip 16 register, this
791 // is an easy way to do that which does not require a register.
793 let ra=0, s=0,s0=0,s1=0 in
795 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
796 "restore\t$frame_size", [], IILoad >, MayLoad {
797 let isCodeGenOnly = 1;
803 // Format: SAVE {ra,}{s0/s1/s0-1,}{framesize} (All arguments are optional)
805 // Purpose: Save Registers and Set Up Stack Frame
806 // To set up a stack frame on entry to a subroutine,
807 // saving return address and static registers, and adjusting stack
809 let ra=1, s=1,s0=1,s1=1 in
811 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
812 "save\t$$ra, $$s0, $$s1, $frame_size", [], IIStore >, MayStore {
813 let isCodeGenOnly = 1;
814 let Uses = [RA, SP, S0, S1];
819 // Use Save to decrement the SP by a constant since SP is not
820 // a Mips16 register.
822 let ra=0, s=0,s0=0,s1=0 in
824 FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
825 "save\t$frame_size", [], IIStore >, MayStore {
826 let isCodeGenOnly = 1;
831 // Format: SB ry, offset(rx) MIPS16e
832 // Purpose: Store Byte (Extended)
833 // To store a byte to memory.
836 FEXT_RRI16_mem2_ins<0b11000, "sb", mem16, IIStore>, MayStore;
839 // The Sel(T) instructions are pseudos
840 // T means that they use T8 implicitly.
843 // Format: SelBeqZ rd, rs, rt
844 // Purpose: if rt==0, do nothing
847 def SelBeqZ: Sel<"beqz">;
850 // Format: SelTBteqZCmp rd, rs, rl, rr
851 // Purpose: b = Cmp rl, rr.
852 // If b==0 then do nothing.
853 // if b!=0 then rd = rs
855 def SelTBteqZCmp: SelT<"bteqz", "cmp">;
858 // Format: SelTBteqZCmpi rd, rs, rl, rr
859 // Purpose: b = Cmpi rl, imm.
860 // If b==0 then do nothing.
861 // if b!=0 then rd = rs
863 def SelTBteqZCmpi: SeliT<"bteqz", "cmpi">;
866 // Format: SelTBteqZSlt rd, rs, rl, rr
867 // Purpose: b = Slt rl, rr.
868 // If b==0 then do nothing.
869 // if b!=0 then rd = rs
871 def SelTBteqZSlt: SelT<"bteqz", "slt">;
874 // Format: SelTBteqZSlti rd, rs, rl, rr
875 // Purpose: b = Slti rl, imm.
876 // If b==0 then do nothing.
877 // if b!=0 then rd = rs
879 def SelTBteqZSlti: SeliT<"bteqz", "slti">;
882 // Format: SelTBteqZSltu rd, rs, rl, rr
883 // Purpose: b = Sltu rl, rr.
884 // If b==0 then do nothing.
885 // if b!=0 then rd = rs
887 def SelTBteqZSltu: SelT<"bteqz", "sltu">;
890 // Format: SelTBteqZSltiu rd, rs, rl, rr
891 // Purpose: b = Sltiu rl, imm.
892 // If b==0 then do nothing.
893 // if b!=0 then rd = rs
895 def SelTBteqZSltiu: SeliT<"bteqz", "sltiu">;
898 // Format: SelBnez rd, rs, rt
899 // Purpose: if rt!=0, do nothing
902 def SelBneZ: Sel<"bnez">;
905 // Format: SelTBtneZCmp rd, rs, rl, rr
906 // Purpose: b = Cmp rl, rr.
907 // If b!=0 then do nothing.
908 // if b0=0 then rd = rs
910 def SelTBtneZCmp: SelT<"btnez", "cmp">;
913 // Format: SelTBtnezCmpi rd, rs, rl, rr
914 // Purpose: b = Cmpi rl, imm.
915 // If b!=0 then do nothing.
916 // if b==0 then rd = rs
918 def SelTBtneZCmpi: SeliT<"btnez", "cmpi">;
921 // Format: SelTBtneZSlt rd, rs, rl, rr
922 // Purpose: b = Slt rl, rr.
923 // If b!=0 then do nothing.
924 // if b==0 then rd = rs
926 def SelTBtneZSlt: SelT<"btnez", "slt">;
929 // Format: SelTBtneZSlti rd, rs, rl, rr
930 // Purpose: b = Slti rl, imm.
931 // If b!=0 then do nothing.
932 // if b==0 then rd = rs
934 def SelTBtneZSlti: SeliT<"btnez", "slti">;
937 // Format: SelTBtneZSltu rd, rs, rl, rr
938 // Purpose: b = Sltu rl, rr.
939 // If b!=0 then do nothing.
940 // if b==0 then rd = rs
942 def SelTBtneZSltu: SelT<"btnez", "sltu">;
945 // Format: SelTBtneZSltiu rd, rs, rl, rr
946 // Purpose: b = Slti rl, imm.
947 // If b!=0 then do nothing.
948 // if b==0 then rd = rs
950 def SelTBtneZSltiu: SeliT<"btnez", "sltiu">;
953 // Format: SH ry, offset(rx) MIPS16e
954 // Purpose: Store Halfword (Extended)
955 // To store a halfword to memory.
958 FEXT_RRI16_mem2_ins<0b11001, "sh", mem16, IIStore>, MayStore;
961 // Format: SLL rx, ry, sa MIPS16e
962 // Purpose: Shift Word Left Logical (Extended)
963 // To execute a left-shift of a word by a fixed number of bits—0 to 31 bits.
965 def SllX16: FEXT_SHIFT16_ins<0b00, "sll", IIAlu>;
968 // Format: SLLV ry, rx MIPS16e
969 // Purpose: Shift Word Left Logical Variable
970 // To execute a left-shift of a word by a variable number of bits.
972 def SllvRxRy16 : FRxRxRy16_ins<0b00100, "sllv", IIAlu>;
975 // Format: SLTI rx, immediate MIPS16e
976 // Purpose: Set on Less Than Immediate (Extended)
977 // To record the result of a less-than comparison with a constant.
979 def SltiCCRxImmX16: FEXT_CCRXI16_ins<"slti">;
982 // Format: SLTIU rx, immediate MIPS16e
983 // Purpose: Set on Less Than Immediate Unsigned (Extended)
984 // To record the result of a less-than comparison with a constant.
986 def SltiuCCRxImmX16: FEXT_CCRXI16_ins<"sltiu">;
989 // Format: SLT rx, ry MIPS16e
990 // Purpose: Set on Less Than
991 // To record the result of a less-than comparison.
993 def SltRxRy16: FRR16_ins<0b00010, "slt", IIAlu>;
995 def SltCCRxRy16: FCCRR16_ins<"slt">;
997 // Format: SLTU rx, ry MIPS16e
998 // Purpose: Set on Less Than Unsigned
999 // To record the result of an unsigned less-than comparison.
1001 def SltuRxRyRz16: FRRTR16_ins<"sltu"> {
1002 let isCodeGenOnly=1;
1006 def SltuCCRxRy16: FCCRR16_ins<"sltu">;
1008 // Format: SRAV ry, rx MIPS16e
1009 // Purpose: Shift Word Right Arithmetic Variable
1010 // To execute an arithmetic right-shift of a word by a variable
1013 def SravRxRy16: FRxRxRy16_ins<0b00111, "srav", IIAlu>;
1017 // Format: SRA rx, ry, sa MIPS16e
1018 // Purpose: Shift Word Right Arithmetic (Extended)
1019 // To execute an arithmetic right-shift of a word by a fixed
1020 // number of bits—1 to 8 bits.
1022 def SraX16: FEXT_SHIFT16_ins<0b11, "sra", IIAlu>;
1026 // Format: SRLV ry, rx MIPS16e
1027 // Purpose: Shift Word Right Logical Variable
1028 // To execute a logical right-shift of a word by a variable
1031 def SrlvRxRy16: FRxRxRy16_ins<0b00110, "srlv", IIAlu>;
1035 // Format: SRL rx, ry, sa MIPS16e
1036 // Purpose: Shift Word Right Logical (Extended)
1037 // To execute a logical right-shift of a word by a fixed
1038 // number of bits—1 to 31 bits.
1040 def SrlX16: FEXT_SHIFT16_ins<0b10, "srl", IIAlu>;
1043 // Format: SUBU rz, rx, ry MIPS16e
1044 // Purpose: Subtract Unsigned Word
1045 // To subtract 32-bit integers
1047 def SubuRxRyRz16: FRRR16_ins<0b11, "subu", IIAlu>, ArithLogic16Defs<0>;
1050 // Format: SW ry, offset(rx) MIPS16e
1051 // Purpose: Store Word (Extended)
1052 // To store a word to memory.
1054 def SwRxRyOffMemX16:
1055 FEXT_RRI16_mem2_ins<0b11011, "sw", mem16, IIStore>, MayStore;
1058 // Format: SW rx, offset(sp) MIPS16e
1059 // Purpose: Store Word rx (SP-Relative)
1060 // To store an SP-relative word to memory.
1062 def SwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b11010, "sw", IIStore>, MayStore;
1066 // Format: XOR rx, ry MIPS16e
1068 // To do a bitwise logical XOR.
1070 def XorRxRxRy16: FRxRxRy16_ins<0b01110, "xor", IIAlu>, ArithLogic16Defs<1>;
1072 class Mips16Pat<dag pattern, dag result> : Pat<pattern, result> {
1073 let Predicates = [InMips16Mode];
1076 // Unary Arith/Logic
1078 class ArithLogicU_pat<PatFrag OpNode, Instruction I> :
1079 Mips16Pat<(OpNode CPU16Regs:$r),
1082 def: ArithLogicU_pat<not, NotRxRy16>;
1083 def: ArithLogicU_pat<ineg, NegRxRy16>;
1085 class ArithLogic16_pat<SDNode OpNode, Instruction I> :
1086 Mips16Pat<(OpNode CPU16Regs:$l, CPU16Regs:$r),
1087 (I CPU16Regs:$l, CPU16Regs:$r)>;
1089 def: ArithLogic16_pat<add, AdduRxRyRz16>;
1090 def: ArithLogic16_pat<and, AndRxRxRy16>;
1091 def: ArithLogic16_pat<mul, MultRxRyRz16>;
1092 def: ArithLogic16_pat<or, OrRxRxRy16>;
1093 def: ArithLogic16_pat<sub, SubuRxRyRz16>;
1094 def: ArithLogic16_pat<xor, XorRxRxRy16>;
1096 // Arithmetic and logical instructions with 2 register operands.
1098 class ArithLogicI16_pat<SDNode OpNode, PatFrag imm_type, Instruction I> :
1099 Mips16Pat<(OpNode CPU16Regs:$in, imm_type:$imm),
1100 (I CPU16Regs:$in, imm_type:$imm)>;
1102 def: ArithLogicI16_pat<add, immSExt8, AddiuRxRxImm16>;
1103 def: ArithLogicI16_pat<add, immSExt16, AddiuRxRxImmX16>;
1104 def: ArithLogicI16_pat<shl, immZExt5, SllX16>;
1105 def: ArithLogicI16_pat<srl, immZExt5, SrlX16>;
1106 def: ArithLogicI16_pat<sra, immZExt5, SraX16>;
1108 class shift_rotate_reg16_pat<SDNode OpNode, Instruction I> :
1109 Mips16Pat<(OpNode CPU16Regs:$r, CPU16Regs:$ra),
1110 (I CPU16Regs:$r, CPU16Regs:$ra)>;
1112 def: shift_rotate_reg16_pat<shl, SllvRxRy16>;
1113 def: shift_rotate_reg16_pat<sra, SravRxRy16>;
1114 def: shift_rotate_reg16_pat<srl, SrlvRxRy16>;
1116 class LoadM16_pat<PatFrag OpNode, Instruction I> :
1117 Mips16Pat<(OpNode addr16:$addr), (I addr16:$addr)>;
1119 def: LoadM16_pat<sextloadi8, LbRxRyOffMemX16>;
1120 def: LoadM16_pat<zextloadi8, LbuRxRyOffMemX16>;
1121 def: LoadM16_pat<sextloadi16, LhRxRyOffMemX16>;
1122 def: LoadM16_pat<zextloadi16, LhuRxRyOffMemX16>;
1123 def: LoadM16_pat<load, LwRxRyOffMemX16>;
1125 class StoreM16_pat<PatFrag OpNode, Instruction I> :
1126 Mips16Pat<(OpNode CPU16Regs:$r, addr16:$addr),
1127 (I CPU16Regs:$r, addr16:$addr)>;
1129 def: StoreM16_pat<truncstorei8, SbRxRyOffMemX16>;
1130 def: StoreM16_pat<truncstorei16, ShRxRyOffMemX16>;
1131 def: StoreM16_pat<store, SwRxRyOffMemX16>;
1133 // Unconditional branch
1134 class UncondBranch16_pat<SDNode OpNode, Instruction I>:
1135 Mips16Pat<(OpNode bb:$imm16), (I bb:$imm16)> {
1136 let Predicates = [InMips16Mode];
1139 def : Mips16Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
1140 (Jal16 tglobaladdr:$dst)>;
1142 def : Mips16Pat<(MipsJmpLink (i32 texternalsym:$dst)),
1143 (Jal16 texternalsym:$dst)>;
1147 (brind CPU16Regs:$rs),
1148 (JrcRx16 CPU16Regs:$rs)>;
1150 // Jump and Link (Call)
1151 let isCall=1, hasDelaySlot=0 in
1153 FRR16_JALRC<0, 0, 0, (outs), (ins CPU16Regs:$rs),
1154 "jalrc \t$rs", [(MipsJmpLink CPU16Regs:$rs)], IIBranch>;
1157 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1,
1158 hasExtraSrcRegAllocReq = 1 in
1159 def RetRA16 : MipsPseudo16<(outs), (ins), "", [(MipsRet)]>;
1164 class SetCC_R16<PatFrag cond_op, Instruction I>:
1165 Mips16Pat<(cond_op CPU16Regs:$rx, CPU16Regs:$ry),
1166 (I CPU16Regs:$rx, CPU16Regs:$ry)>;
1168 class SetCC_I16<PatFrag cond_op, PatLeaf imm_type, Instruction I>:
1169 Mips16Pat<(cond_op CPU16Regs:$rx, imm_type:$imm16),
1170 (I CPU16Regs:$rx, imm_type:$imm16)>;
1173 def: Mips16Pat<(i32 addr16:$addr),
1174 (AddiuRxRyOffMemX16 addr16:$addr)>;
1177 // Large (>16 bit) immediate loads
1178 def : Mips16Pat<(i32 imm:$imm),
1179 (OrRxRxRy16 (SllX16 (LiRxImmX16 (HI16 imm:$imm)), 16),
1180 (LiRxImmX16 (LO16 imm:$imm)))>;
1182 // Carry MipsPatterns
1183 def : Mips16Pat<(subc CPU16Regs:$lhs, CPU16Regs:$rhs),
1184 (SubuRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1185 def : Mips16Pat<(addc CPU16Regs:$lhs, CPU16Regs:$rhs),
1186 (AdduRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
1187 def : Mips16Pat<(addc CPU16Regs:$src, immSExt16:$imm),
1188 (AddiuRxRxImmX16 CPU16Regs:$src, imm:$imm)>;
1191 // Some branch conditional patterns are not generated by llvm at this time.
1192 // Some are for seemingly arbitrary reasons not used: i.e. with signed number
1193 // comparison they are used and for unsigned a different pattern is used.
1194 // I am pushing upstream from the full mips16 port and it seemed that I needed
1195 // these earlier and the mips32 port has these but now I cannot create test
1196 // cases that use these patterns. While I sort this all out I will leave these
1197 // extra patterns commented out and if I can be sure they are really not used,
1198 // I will delete the code. I don't want to check the code in uncommented without
1199 // a valid test case. In some cases, the compiler is generating patterns with
1200 // setcc instead and earlier I had implemented setcc first so may have masked
1201 // the problem. The setcc variants are suboptimal for mips16 so I may wantto
1202 // figure out how to enable the brcond patterns or else possibly new
1203 // combinations of of brcond and setcc.
1209 <(brcond (i32 (seteq CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1210 (BteqzT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1215 <(brcond (i32 (seteq CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1216 (BteqzT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1220 <(brcond (i32 (seteq CPU16Regs:$rx, 0)), bb:$targ16),
1221 (BeqzRxImmX16 CPU16Regs:$rx, bb:$targ16)
1225 // bcond-setgt (do we need to have this pair of setlt, setgt??)
1228 <(brcond (i32 (setgt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1229 (BtnezT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1236 <(brcond (i32 (setge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1237 (BteqzT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1241 // never called because compiler transforms a >= k to a > (k-1)
1243 <(brcond (i32 (setge CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1244 (BteqzT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1251 <(brcond (i32 (setlt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1252 (BtnezT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1256 <(brcond (i32 (setlt CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
1257 (BtnezT8SltiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$imm16)
1264 <(brcond (i32 (setle CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1265 (BteqzT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1272 <(brcond (i32 (setne CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1273 (BtnezT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1277 <(brcond (i32 (setne CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
1278 (BtnezT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm, bb:$targ16)
1282 <(brcond (i32 (setne CPU16Regs:$rx, 0)), bb:$targ16),
1283 (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1287 // This needs to be there but I forget which code will generate it
1290 <(brcond CPU16Regs:$rx, bb:$targ16),
1291 (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
1300 // <(brcond (i32 (setugt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1301 // (BtnezT8SltuX16 CPU16Regs:$ry, CPU16Regs:$rx, bb:$imm16)
1308 // <(brcond (i32 (setuge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1309 // (BteqzT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1317 // <(brcond (i32 (setult CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
1318 // (BtnezT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry, bb:$imm16)
1321 def: UncondBranch16_pat<br, BimmX16>;
1324 def: Mips16Pat<(i32 immSExt16:$in),
1325 (AddiuRxRxImmX16 (Move32R16 ZERO), immSExt16:$in)>;
1327 def: Mips16Pat<(i32 immZExt16:$in), (LiRxImmX16 immZExt16:$in)>;
1333 <(MipsDivRem CPU16Regs:$rx, CPU16Regs:$ry),
1334 (DivRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1340 <(MipsDivRemU CPU16Regs:$rx, CPU16Regs:$ry),
1341 (DivuRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
1346 // if !(a < b) x = y
1348 def : Mips16Pat<(select (i32 (setge CPU16Regs:$a, CPU16Regs:$b)),
1349 CPU16Regs:$x, CPU16Regs:$y),
1350 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1351 CPU16Regs:$a, CPU16Regs:$b)>;
1358 def : Mips16Pat<(select (i32 (setgt CPU16Regs:$a, CPU16Regs:$b)),
1359 CPU16Regs:$x, CPU16Regs:$y),
1360 (SelTBtneZSlt CPU16Regs:$x, CPU16Regs:$y,
1361 CPU16Regs:$b, CPU16Regs:$a)>;
1366 // if !(a < b) x = y;
1369 (select (i32 (setuge CPU16Regs:$a, CPU16Regs:$b)),
1370 CPU16Regs:$x, CPU16Regs:$y),
1371 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1372 CPU16Regs:$a, CPU16Regs:$b)>;
1379 def : Mips16Pat<(select (i32 (setugt CPU16Regs:$a, CPU16Regs:$b)),
1380 CPU16Regs:$x, CPU16Regs:$y),
1381 (SelTBtneZSltu CPU16Regs:$x, CPU16Regs:$y,
1382 CPU16Regs:$b, CPU16Regs:$a)>;
1386 // due to an llvm optimization, i don't think that this will ever
1387 // be used. This is transformed into x = (a > k-1)?x:y
1392 // (select (i32 (setge CPU16Regs:$lhs, immSExt16:$rhs)),
1393 // CPU16Regs:$T, CPU16Regs:$F),
1394 // (SelTBteqZSlti CPU16Regs:$T, CPU16Regs:$F,
1395 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1398 // (select (i32 (setuge CPU16Regs:$lhs, immSExt16:$rhs)),
1399 // CPU16Regs:$T, CPU16Regs:$F),
1400 // (SelTBteqZSltiu CPU16Regs:$T, CPU16Regs:$F,
1401 // CPU16Regs:$lhs, immSExt16:$rhs)>;
1406 // if !(a < k) x = y;
1409 (select (i32 (setlt CPU16Regs:$a, immSExt16:$b)),
1410 CPU16Regs:$x, CPU16Regs:$y),
1411 (SelTBtneZSlti CPU16Regs:$x, CPU16Regs:$y,
1412 CPU16Regs:$a, immSExt16:$b)>;
1418 // x = (a <= b)? x : y
1422 def : Mips16Pat<(select (i32 (setle CPU16Regs:$a, CPU16Regs:$b)),
1423 CPU16Regs:$x, CPU16Regs:$y),
1424 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
1425 CPU16Regs:$b, CPU16Regs:$a)>;
1429 // x = (a <= b)? x : y
1433 def : Mips16Pat<(select (i32 (setule CPU16Regs:$a, CPU16Regs:$b)),
1434 CPU16Regs:$x, CPU16Regs:$y),
1435 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
1436 CPU16Regs:$b, CPU16Regs:$a)>;
1440 // x = (a == b)? x : y
1442 // if (a != b) x = y
1444 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, CPU16Regs:$b)),
1445 CPU16Regs:$x, CPU16Regs:$y),
1446 (SelTBteqZCmp CPU16Regs:$x, CPU16Regs:$y,
1447 CPU16Regs:$b, CPU16Regs:$a)>;
1451 // x = (a == 0)? x : y
1453 // if (a != 0) x = y
1455 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, 0)),
1456 CPU16Regs:$x, CPU16Regs:$y),
1457 (SelBeqZ CPU16Regs:$x, CPU16Regs:$y,
1463 // x = (a == k)? x : y
1465 // if (a != k) x = y
1467 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, immZExt16:$k)),
1468 CPU16Regs:$x, CPU16Regs:$y),
1469 (SelTBteqZCmpi CPU16Regs:$x, CPU16Regs:$y,
1470 CPU16Regs:$a, immZExt16:$k)>;
1475 // x = (a != b)? x : y
1477 // if (a == b) x = y
1480 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, CPU16Regs:$b)),
1481 CPU16Regs:$x, CPU16Regs:$y),
1482 (SelTBtneZCmp CPU16Regs:$x, CPU16Regs:$y,
1483 CPU16Regs:$b, CPU16Regs:$a)>;
1487 // x = (a != 0)? x : y
1489 // if (a == 0) x = y
1491 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, 0)),
1492 CPU16Regs:$x, CPU16Regs:$y),
1493 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1501 def : Mips16Pat<(select CPU16Regs:$a,
1502 CPU16Regs:$x, CPU16Regs:$y),
1503 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
1509 // x = (a != k)? x : y
1511 // if (a == k) x = y
1513 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, immZExt16:$k)),
1514 CPU16Regs:$x, CPU16Regs:$y),
1515 (SelTBtneZCmpi CPU16Regs:$x, CPU16Regs:$y,
1516 CPU16Regs:$a, immZExt16:$k)>;
1519 // When writing C code to test setxx these patterns,
1520 // some will be transformed into
1521 // other things. So we test using C code but using -O3 and -O0
1526 <(seteq CPU16Regs:$lhs,CPU16Regs:$rhs),
1527 (SltiuCCRxImmX16 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs), 1)>;
1530 <(seteq CPU16Regs:$lhs, 0),
1531 (SltiuCCRxImmX16 CPU16Regs:$lhs, 1)>;
1539 <(setge CPU16Regs:$lhs, CPU16Regs:$rhs),
1540 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1544 // For constants, llvm transforms this to:
1545 // x > (k -1) and then reverses the operands to use setlt. So this pattern
1546 // is not used now by the compiler. (Presumably checking that k-1 does not
1547 // overflow). The compiler never uses this at a the current time, due to
1548 // other optimizations.
1551 // <(setge CPU16Regs:$lhs, immSExt16:$rhs),
1552 // (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, immSExt16:$rhs),
1553 // (LiRxImmX16 1))>;
1555 // This catches the x >= -32768 case by transforming it to x > -32769
1558 <(setgt CPU16Regs:$lhs, -32769),
1559 (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, -32768),
1568 <(setgt CPU16Regs:$lhs, CPU16Regs:$rhs),
1569 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1575 <(setle CPU16Regs:$lhs, CPU16Regs:$rhs),
1576 (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImmX16 1))>;
1581 def: SetCC_R16<setlt, SltCCRxRy16>;
1583 def: SetCC_I16<setlt, immSExt16, SltiCCRxImmX16>;
1589 <(setne CPU16Regs:$lhs,CPU16Regs:$rhs),
1590 (SltuCCRxRy16 (LiRxImmX16 0),
1591 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs))>;
1598 <(setuge CPU16Regs:$lhs, CPU16Regs:$rhs),
1599 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
1602 // this pattern will never be used because the compiler will transform
1603 // x >= k to x > (k - 1) and then use SLT
1606 // <(setuge CPU16Regs:$lhs, immZExt16:$rhs),
1607 // (XorRxRxRy16 (SltiuCCRxImmX16 CPU16Regs:$lhs, immZExt16:$rhs),
1608 // (LiRxImmX16 1))>;
1614 <(setugt CPU16Regs:$lhs, CPU16Regs:$rhs),
1615 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
1621 <(setule CPU16Regs:$lhs, CPU16Regs:$rhs),
1622 (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImmX16 1))>;
1627 def: SetCC_R16<setult, SltuCCRxRy16>;
1629 def: SetCC_I16<setult, immSExt16, SltiuCCRxImmX16>;
1631 def: Mips16Pat<(add CPU16Regs:$hi, (MipsLo tglobaladdr:$lo)),
1632 (AddiuRxRxImmX16 CPU16Regs:$hi, tglobaladdr:$lo)>;
1636 def : Mips16Pat<(MipsHi tglobaladdr:$in),
1637 (SllX16 (LiRxImmX16 tglobaladdr:$in), 16)>;
1638 def : Mips16Pat<(MipsHi tjumptable:$in),
1639 (SllX16 (LiRxImmX16 tjumptable:$in), 16)>;
1640 def : Mips16Pat<(MipsHi tglobaltlsaddr:$in),
1641 (SllX16 (LiRxImmX16 tglobaltlsaddr:$in), 16)>;
1644 class Wrapper16Pat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
1645 Mips16Pat<(MipsWrapper RC:$gp, node:$in),
1646 (ADDiuOp RC:$gp, node:$in)>;
1649 def : Wrapper16Pat<tglobaladdr, AddiuRxRxImmX16, CPU16Regs>;
1650 def : Wrapper16Pat<tglobaltlsaddr, AddiuRxRxImmX16, CPU16Regs>;
1652 def : Mips16Pat<(i32 (extloadi8 addr16:$src)),
1653 (LbuRxRyOffMemX16 addr16:$src)>;
1654 def : Mips16Pat<(i32 (extloadi16 addr16:$src)),
1655 (LhuRxRyOffMemX16 addr16:$src)>;