Home | History | Annotate | Download | only in Mips
      1 //===- Mips16InstrInfo.td - Target Description for Mips16  -*- tablegen -*-=//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file describes Mips16 instructions.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 //
     14 //
     15 // Mips Address
     16 //
     17 def addr16 :
     18   ComplexPattern<iPTR, 3, "selectAddr16", [frameindex], [SDNPWantParent]>;
     19 
     20 //
     21 // Address operand
     22 def mem16 : Operand<i32> {
     23   let PrintMethod = "printMemOperand";
     24   let MIOperandInfo = (ops CPU16Regs, simm16, CPU16Regs);
     25   let EncoderMethod = "getMemEncoding";
     26 }
     27 
     28 def mem16_ea : Operand<i32> {
     29   let PrintMethod = "printMemOperandEA";
     30   let MIOperandInfo = (ops CPU16Regs, simm16);
     31   let EncoderMethod = "getMemEncoding";
     32 }
     33 
     34 //
     35 //
     36 // I8 instruction format
     37 //
     38 
     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),
     42         [], itin>;
     43 
     44 
     45 class FI816_SP_ins<bits<3> _func, string asmstr,
     46                    InstrItinClass itin>:
     47   FI816_ins_base<_func, asmstr, "\t$$sp, $imm # 16 bit inst", itin>;
     48 
     49 //
     50 // RI instruction format
     51 //
     52 
     53 
     54 class FRI16_ins_base<bits<5> op, string asmstr, string asmstr2,
     55                      InstrItinClass itin>:
     56   FRI16<op, (outs CPU16Regs:$rx), (ins simm16:$imm),
     57         !strconcat(asmstr, asmstr2), [], itin>;
     58 
     59 class FRI16_ins<bits<5> op, string asmstr,
     60                 InstrItinClass itin>:
     61   FRI16_ins_base<op, asmstr, "\t$rx, $imm \t# 16 bit inst", itin>;
     62 
     63 class FRI16R_ins_base<bits<5> op, string asmstr, string asmstr2,
     64                      InstrItinClass itin>:
     65   FRI16<op, (outs), (ins CPU16Regs:$rx, simm16:$imm),
     66         !strconcat(asmstr, asmstr2), [], itin>;
     67 
     68 class FRI16R_ins<bits<5> op, string asmstr,
     69                 InstrItinClass itin>:
     70   FRI16R_ins_base<op, asmstr, "\t$rx, $imm \t# 16 bit inst", itin>;
     71 
     72 class F2RI16_ins<bits<5> _op, string asmstr,
     73                      InstrItinClass itin>:
     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";
     77 }
     78 
     79 class FRI16_B_ins<bits<5> _op, string asmstr,
     80                   InstrItinClass itin>:
     81   FRI16<_op, (outs), (ins  CPU16Regs:$rx, brtarget:$imm),
     82         !strconcat(asmstr, "\t$rx, $imm  # 16 bit inst"), [], itin>;
     83 //
     84 // Compare a register and immediate and place result in CC
     85 // Implicit use of T8
     86 //
     87 // EXT-CCRR Instruction format
     88 //
     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"), []> {
     92   let isCodeGenOnly=1;
     93   let usesCustomInserter = 1;
     94 }
     95 
     96 // JAL and JALX instruction format
     97 //
     98 class FJAL16_ins<bits<1> _X, string asmstr,
     99                  InstrItinClass itin>:
    100   FJAL16<_X, (outs), (ins simm20:$imm),
    101          !strconcat(asmstr, "\t$imm\n\tnop"),[],
    102          itin>  {
    103   let isCodeGenOnly=1;
    104 }
    105 //
    106 // EXT-I instruction format
    107 //
    108 class FEXT_I16_ins<bits<5> eop, string asmstr, InstrItinClass itin> :
    109   FEXT_I16<eop, (outs), (ins brtarget:$imm16),
    110            !strconcat(asmstr, "\t$imm16"),[], itin>;
    111 
    112 //
    113 // EXT-I8 instruction format
    114 //
    115 
    116 class FEXT_I816_ins_base<bits<3> _func, string asmstr,
    117                          string asmstr2, InstrItinClass itin>:
    118   FEXT_I816<_func, (outs), (ins simm16:$imm), !strconcat(asmstr, asmstr2),
    119             [], itin>;
    120 
    121 class FEXT_I816_ins<bits<3> _func, string asmstr,
    122                     InstrItinClass itin>:
    123   FEXT_I816_ins_base<_func, asmstr, "\t$imm", itin>;
    124 
    125 class FEXT_I816_SP_ins<bits<3> _func, string asmstr,
    126                        InstrItinClass itin>:
    127       FEXT_I816_ins_base<_func, asmstr, "\t$$sp, $imm", itin>;
    128 
    129 //
    130 // Assembler formats in alphabetical order.
    131 // Natural and pseudos are mixed together.
    132 //
    133 // Compare two registers and place result in CC
    134 // Implicit use of T8
    135 //
    136 // CC-RR Instruction format
    137 //
    138 class FCCRR16_ins<string asmstr> :
    139   MipsPseudo16<(outs CPU16Regs:$cc), (ins CPU16Regs:$rx, CPU16Regs:$ry),
    140                !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$cc, $$t8"), []> {
    141   let isCodeGenOnly=1;
    142   let usesCustomInserter = 1;
    143 }
    144 
    145 //
    146 // EXT-RI instruction format
    147 //
    148 
    149 class FEXT_RI16_ins_base<bits<5> _op, string asmstr, string asmstr2,
    150                          InstrItinClass itin>:
    151   FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins simm16:$imm),
    152                   !strconcat(asmstr, asmstr2), [], itin>;
    153 
    154 class FEXT_RI16_ins<bits<5> _op, string asmstr,
    155                     InstrItinClass itin>:
    156   FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
    157 
    158 class FEXT_RI16R_ins_base<bits<5> _op, string asmstr, string asmstr2,
    159                          InstrItinClass itin>:
    160   FEXT_RI16<_op, (outs ), (ins CPU16Regs:$rx, simm16:$imm),
    161                   !strconcat(asmstr, asmstr2), [], itin>;
    162 
    163 class FEXT_RI16R_ins<bits<5> _op, string asmstr,
    164                     InstrItinClass itin>:
    165   FEXT_RI16R_ins_base<_op, asmstr, "\t$rx, $imm", itin>;
    166 
    167 class FEXT_RI16_PC_ins<bits<5> _op, string asmstr, InstrItinClass itin>:
    168   FEXT_RI16_ins_base<_op, asmstr, "\t$rx, $$pc, $imm", itin>;
    169 
    170 class FEXT_RI16_B_ins<bits<5> _op, string asmstr,
    171                       InstrItinClass itin>:
    172   FEXT_RI16<_op, (outs), (ins  CPU16Regs:$rx, brtarget:$imm),
    173             !strconcat(asmstr, "\t$rx, $imm"), [], itin>;
    174 
    175 class FEXT_2RI16_ins<bits<5> _op, string asmstr,
    176                      InstrItinClass itin>:
    177   FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPU16Regs:$rx_, simm16:$imm),
    178             !strconcat(asmstr, "\t$rx, $imm"), [], itin> {
    179   let Constraints = "$rx_ = $rx";
    180 }
    181 
    182 
    183 // this has an explicit sp argument that we ignore to work around a problem
    184 // in the compiler
    185 class FEXT_RI16_SP_explicit_ins<bits<5> _op, string asmstr,
    186                                 InstrItinClass itin>:
    187   FEXT_RI16<_op, (outs CPU16Regs:$rx), (ins CPUSPReg:$ry, simm16:$imm),
    188             !strconcat(asmstr, "\t$rx, $imm ( $ry ); "), [], itin>;
    189 
    190 //
    191 // EXT-RRI instruction format
    192 //
    193 
    194 class FEXT_RRI16_mem_ins<bits<5> op, string asmstr, Operand MemOpnd,
    195                          InstrItinClass itin>:
    196   FEXT_RRI16<op, (outs CPU16Regs:$ry), (ins  MemOpnd:$addr),
    197              !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
    198 
    199 class FEXT_RRI16_mem2_ins<bits<5> op, string asmstr, Operand MemOpnd,
    200                           InstrItinClass itin>:
    201   FEXT_RRI16<op, (outs ), (ins  CPU16Regs:$ry, MemOpnd:$addr),
    202              !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
    203 
    204 //
    205 //
    206 // EXT-RRI-A instruction format
    207 //
    208 
    209 class FEXT_RRI_A16_mem_ins<bits<1> op, string asmstr, Operand MemOpnd,
    210                            InstrItinClass itin>:
    211   FEXT_RRI_A16<op, (outs CPU16Regs:$ry), (ins  MemOpnd:$addr),
    212                !strconcat(asmstr, "\t$ry, $addr"), [], itin>;
    213 
    214 //
    215 // EXT-SHIFT instruction format
    216 //
    217 class FEXT_SHIFT16_ins<bits<2> _f, string asmstr, InstrItinClass itin>:
    218   FEXT_SHIFT16<_f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry, shamt:$sa),
    219                !strconcat(asmstr, "\t$rx, $ry, $sa"), [], itin>;
    220 
    221 //
    222 // EXT-T8I8
    223 //
    224 class FEXT_T8I816_ins<string asmstr, string asmstr2>:
    225   MipsPseudo16<(outs),
    226                (ins CPU16Regs:$rx, CPU16Regs:$ry, brtarget:$imm),
    227                !strconcat(asmstr2, !strconcat("\t$rx, $ry\n\t",
    228                !strconcat(asmstr, "\t$imm"))),[]> {
    229   let isCodeGenOnly=1;
    230   let usesCustomInserter = 1;
    231 }
    232 
    233 //
    234 // EXT-T8I8I
    235 //
    236 class FEXT_T8I8I16_ins<string asmstr, string asmstr2>:
    237   MipsPseudo16<(outs),
    238                (ins CPU16Regs:$rx, simm16:$imm, brtarget:$targ),
    239                !strconcat(asmstr2, !strconcat("\t$rx, $imm\n\t",
    240                !strconcat(asmstr, "\t$targ"))), []> {
    241   let isCodeGenOnly=1;
    242   let usesCustomInserter = 1;
    243 }
    244 //
    245 
    246 
    247 //
    248 // I8_MOVR32 instruction format (used only by the MOVR32 instructio
    249 //
    250 class FI8_MOVR3216_ins<string asmstr, InstrItinClass itin>:
    251        FI8_MOVR3216<(outs CPU16Regs:$rz), (ins CPURegs:$r32),
    252        !strconcat(asmstr,  "\t$rz, $r32"), [], itin>;
    253 
    254 //
    255 // I8_MOV32R instruction format (used only by MOV32R instruction)
    256 //
    257 
    258 class FI8_MOV32R16_ins<string asmstr, InstrItinClass itin>:
    259   FI8_MOV32R16<(outs CPURegs:$r32), (ins CPU16Regs:$rz),
    260                !strconcat(asmstr,  "\t$r32, $rz"), [], itin>;
    261 
    262 //
    263 // This are pseudo formats for multiply
    264 // This first one can be changed to non pseudo now.
    265 //
    266 // MULT
    267 //
    268 class FMULT16_ins<string asmstr, InstrItinClass itin> :
    269   MipsPseudo16<(outs), (ins CPU16Regs:$rx, CPU16Regs:$ry),
    270                !strconcat(asmstr, "\t$rx, $ry"), []>;
    271 
    272 //
    273 // MULT-LO
    274 //
    275 class FMULT16_LO_ins<string asmstr, InstrItinClass itin> :
    276   MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
    277                !strconcat(asmstr, "\t$rx, $ry\n\tmflo\t$rz"), []> {
    278   let isCodeGenOnly=1;
    279 }
    280 
    281 //
    282 // RR-type instruction format
    283 //
    284 
    285 class FRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
    286   FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
    287         !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
    288 }
    289 
    290 class FRR16R_ins<bits<5> f, string asmstr, InstrItinClass itin> :
    291   FRR16<f, (outs), (ins  CPU16Regs:$rx, CPU16Regs:$ry),
    292         !strconcat(asmstr, "\t$rx, $ry"), [], itin> {
    293 }
    294 
    295 class FRRTR16_ins<string asmstr> :
    296   MipsPseudo16<(outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
    297                !strconcat(asmstr, "\t$rx, $ry\n\tmove\t$rz, $$t8"), []> ;
    298 
    299 //
    300 // maybe refactor but need a $zero as a dummy first parameter
    301 //
    302 class FRR16_div_ins<bits<5> f, string asmstr, InstrItinClass itin> :
    303   FRR16<f, (outs ), (ins CPU16Regs:$rx, CPU16Regs:$ry),
    304         !strconcat(asmstr, "\t$$zero, $rx, $ry"), [], itin> ;
    305 
    306 class FUnaryRR16_ins<bits<5> f, string asmstr, InstrItinClass itin> :
    307   FRR16<f, (outs CPU16Regs:$rx), (ins CPU16Regs:$ry),
    308         !strconcat(asmstr, "\t$rx, $ry"), [], itin> ;
    309 
    310 
    311 class FRR16_M_ins<bits<5> f, string asmstr,
    312                   InstrItinClass itin> :
    313   FRR16<f, (outs CPU16Regs:$rx), (ins),
    314         !strconcat(asmstr, "\t$rx"), [], itin>;
    315 
    316 class FRxRxRy16_ins<bits<5> f, string asmstr,
    317                     InstrItinClass itin> :
    318   FRR16<f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
    319             !strconcat(asmstr, "\t$rz, $ry"),
    320             [], itin> {
    321   let Constraints = "$rx = $rz";
    322 }
    323 
    324 let rx=0 in
    325 class FRR16_JALRC_RA_only_ins<bits<1> nd_, bits<1> l_,
    326                               string asmstr, InstrItinClass itin>:
    327   FRR16_JALRC<nd_, l_, 1, (outs), (ins), !strconcat(asmstr, "\t $$ra"),
    328               [], itin> ;
    329 
    330 
    331 class FRR16_JALRC_ins<bits<1> nd, bits<1> l, bits<1> ra,
    332                       string asmstr, InstrItinClass itin>:
    333   FRR16_JALRC<nd, l, ra, (outs), (ins CPU16Regs:$rx),
    334               !strconcat(asmstr, "\t $rx"), [], itin> ;
    335 
    336 //
    337 // RRR-type instruction format
    338 //
    339 
    340 class FRRR16_ins<bits<2> _f, string asmstr,  InstrItinClass itin> :
    341   FRRR16<_f, (outs CPU16Regs:$rz), (ins CPU16Regs:$rx, CPU16Regs:$ry),
    342          !strconcat(asmstr, "\t$rz, $rx, $ry"), [], itin>;
    343 
    344 //
    345 // These Sel patterns support the generation of conditional move
    346 // pseudo instructions.
    347 //
    348 // The nomenclature uses the components making up the pseudo and may
    349 // be a bit counter intuitive when compared with the end result we seek.
    350 // For example using a bqez in the example directly below results in the
    351 // conditional move being done if the tested register is not zero.
    352 // I considered in easier to check by keeping the pseudo consistent with
    353 // it's components but it could have been done differently.
    354 //
    355 // The simplest case is when can test and operand directly and do the
    356 // conditional move based on a simple mips16 conditional
    357 //  branch instruction.
    358 // for example:
    359 // if $op == beqz or bnez:
    360 //
    361 // $op1 $rt, .+4
    362 // move $rd, $rs
    363 //
    364 // if $op == beqz, then if $rt != 0, then the conditional assignment
    365 // $rd = $rs is done.
    366 
    367 // if $op == bnez, then if $rt == 0, then the conditional assignment
    368 // $rd = $rs is done.
    369 //
    370 // So this pseudo class only has one operand, i.e. op
    371 //
    372 class Sel<string op>:
    373   MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
    374                CPU16Regs:$rt),
    375                !strconcat(op, "\t$rt, .+4\n\t\n\tmove $rd, $rs"), []> {
    376   //let isCodeGenOnly=1;
    377   let Constraints = "$rd = $rd_";
    378   let usesCustomInserter = 1;
    379 }
    380 
    381 //
    382 // The next two instruction classes allow for an operand which tests
    383 // two operands and returns a value in register T8 and
    384 //then does a conditional branch based on the value of T8
    385 //
    386 
    387 // op2 can be cmpi or slti/sltiu
    388 // op1 can bteqz or btnez
    389 // the operands for op2 are a register and a signed constant
    390 //
    391 // $op2 $t, $imm  ;test register t and branch conditionally
    392 // $op1 .+4       ;op1 is a conditional branch
    393 // move $rd, $rs
    394 //
    395 //
    396 class SeliT<string op1, string op2>:
    397   MipsPseudo16<(outs CPU16Regs:$rd_), (ins CPU16Regs:$rd, CPU16Regs:$rs,
    398                                        CPU16Regs:$rl, simm16:$imm),
    399                !strconcat(op2,
    400                !strconcat("\t$rl, $imm\n\t",
    401                !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
    402   let isCodeGenOnly=1;
    403   let Constraints = "$rd = $rd_";
    404   let usesCustomInserter = 1;
    405 }
    406 
    407 //
    408 // op2 can be cmp or slt/sltu
    409 // op1 can be bteqz or btnez
    410 // the operands for op2 are two registers
    411 // op1 is a conditional branch
    412 //
    413 //
    414 // $op2 $rl, $rr  ;test registers rl,rr
    415 // $op1 .+4       ;op2 is a conditional branch
    416 // move $rd, $rs
    417 //
    418 //
    419 class SelT<string op1, string op2>:
    420   MipsPseudo16<(outs CPU16Regs:$rd_),
    421                (ins CPU16Regs:$rd, CPU16Regs:$rs,
    422                 CPU16Regs:$rl, CPU16Regs:$rr),
    423                !strconcat(op2,
    424                !strconcat("\t$rl, $rr\n\t",
    425                !strconcat(op1, "\t.+4\n\tmove $rd, $rs"))), []> {
    426   let isCodeGenOnly=1;
    427   let Constraints = "$rd = $rd_";
    428   let usesCustomInserter = 1;
    429 }
    430 
    431 //
    432 // 32 bit constant
    433 //
    434 def imm32: Operand<i32>;
    435 
    436 def Constant32:
    437   MipsPseudo16<(outs), (ins imm32:$imm), "\t.word $imm", []>;
    438 
    439 def LwConstant32:
    440   MipsPseudo16<(outs), (ins CPU16Regs:$rx, imm32:$imm),
    441     "lw\t$rx, 1f\n\tb\t2f\n\t.align\t2\n1: \t.word\t$imm\n2:", []>;
    442 
    443 
    444 //
    445 // Some general instruction class info
    446 //
    447 //
    448 
    449 class ArithLogic16Defs<bit isCom=0> {
    450   bits<5> shamt = 0;
    451   bit isCommutable = isCom;
    452   bit isReMaterializable = 1;
    453   bit neverHasSideEffects = 1;
    454 }
    455 
    456 class branch16 {
    457   bit isBranch = 1;
    458   bit isTerminator = 1;
    459   bit isBarrier = 1;
    460 }
    461 
    462 class cbranch16 {
    463   bit isBranch = 1;
    464   bit isTerminator = 1;
    465 }
    466 
    467 class MayLoad {
    468   bit mayLoad = 1;
    469 }
    470 
    471 class MayStore {
    472   bit mayStore = 1;
    473 }
    474 //
    475 
    476 
    477 // Format: ADDIU rx, immediate MIPS16e
    478 // Purpose: Add Immediate Unsigned Word (2-Operand, Extended)
    479 // To add a constant to a 32-bit integer.
    480 //
    481 def AddiuRxImmX16: FEXT_RI16_ins<0b01001, "addiu", IIAlu>;
    482 
    483 def AddiuRxRxImm16: F2RI16_ins<0b01001, "addiu", IIAlu>,
    484   ArithLogic16Defs<0> {
    485   let AddedComplexity = 5;
    486 }
    487 def AddiuRxRxImmX16: FEXT_2RI16_ins<0b01001, "addiu", IIAlu>,
    488   ArithLogic16Defs<0> {
    489   let isCodeGenOnly = 1;
    490 }
    491 
    492 def AddiuRxRyOffMemX16:
    493   FEXT_RRI_A16_mem_ins<0, "addiu", mem16_ea, IIAlu>;
    494 
    495 //
    496 
    497 // Format: ADDIU rx, pc, immediate MIPS16e
    498 // Purpose: Add Immediate Unsigned Word (3-Operand, PC-Relative, Extended)
    499 // To add a constant to the program counter.
    500 //
    501 def AddiuRxPcImmX16: FEXT_RI16_PC_ins<0b00001, "addiu", IIAlu>;
    502 
    503 //
    504 // Format: ADDIU sp, immediate MIPS16e
    505 // Purpose: Add Immediate Unsigned Word (2-Operand, SP-Relative, Extended)
    506 // To add a constant to the stack pointer.
    507 //
    508 def AddiuSpImm16
    509   : FI816_SP_ins<0b011, "addiu", IIAlu> {
    510   let Defs = [SP];
    511   let Uses = [SP];
    512   let AddedComplexity = 5;
    513 }
    514 
    515 def AddiuSpImmX16
    516   : FEXT_I816_SP_ins<0b011, "addiu", IIAlu> {
    517   let Defs = [SP];
    518   let Uses = [SP];
    519 }
    520 
    521 //
    522 // Format: ADDU rz, rx, ry MIPS16e
    523 // Purpose: Add Unsigned Word (3-Operand)
    524 // To add 32-bit integers.
    525 //
    526 
    527 def AdduRxRyRz16: FRRR16_ins<01, "addu", IIAlu>, ArithLogic16Defs<1>;
    528 
    529 //
    530 // Format: AND rx, ry MIPS16e
    531 // Purpose: AND
    532 // To do a bitwise logical AND.
    533 
    534 def AndRxRxRy16: FRxRxRy16_ins<0b01100, "and", IIAlu>, ArithLogic16Defs<1>;
    535 
    536 
    537 //
    538 // Format: BEQZ rx, offset MIPS16e
    539 // Purpose: Branch on Equal to Zero
    540 // To test a GPR then do a PC-relative conditional branch.
    541 //
    542 def BeqzRxImm16: FRI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
    543 
    544 
    545 //
    546 // Format: BEQZ rx, offset MIPS16e
    547 // Purpose: Branch on Equal to Zero (Extended)
    548 // To test a GPR then do a PC-relative conditional branch.
    549 //
    550 def BeqzRxImmX16: FEXT_RI16_B_ins<0b00100, "beqz", IIAlu>, cbranch16;
    551 
    552 // Format: B offset MIPS16e
    553 // Purpose: Unconditional Branch
    554 // To do an unconditional PC-relative branch.
    555 //
    556 def BimmX16: FEXT_I16_ins<0b00010, "b", IIAlu>, branch16;
    557 
    558 //
    559 // Format: BNEZ rx, offset MIPS16e
    560 // Purpose: Branch on Not Equal to Zero
    561 // To test a GPR then do a PC-relative conditional branch.
    562 //
    563 def BnezRxImm16: FRI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
    564 
    565 //
    566 // Format: BNEZ rx, offset MIPS16e
    567 // Purpose: Branch on Not Equal to Zero (Extended)
    568 // To test a GPR then do a PC-relative conditional branch.
    569 //
    570 def BnezRxImmX16: FEXT_RI16_B_ins<0b00101, "bnez", IIAlu>, cbranch16;
    571 
    572 //
    573 // Format: BTEQZ offset MIPS16e
    574 // Purpose: Branch on T Equal to Zero (Extended)
    575 // To test special register T then do a PC-relative conditional branch.
    576 //
    577 def BteqzX16: FEXT_I816_ins<0b000, "bteqz", IIAlu>, cbranch16 {
    578   let Uses = [T8];
    579 }
    580 
    581 def BteqzT8CmpX16: FEXT_T8I816_ins<"bteqz", "cmp">, cbranch16;
    582 
    583 def BteqzT8CmpiX16: FEXT_T8I8I16_ins<"bteqz", "cmpi">,
    584   cbranch16;
    585 
    586 def BteqzT8SltX16: FEXT_T8I816_ins<"bteqz", "slt">, cbranch16;
    587 
    588 def BteqzT8SltuX16: FEXT_T8I816_ins<"bteqz", "sltu">, cbranch16;
    589 
    590 def BteqzT8SltiX16: FEXT_T8I8I16_ins<"bteqz", "slti">, cbranch16;
    591 
    592 def BteqzT8SltiuX16: FEXT_T8I8I16_ins<"bteqz", "sltiu">,
    593   cbranch16;
    594 
    595 //
    596 // Format: BTNEZ offset MIPS16e
    597 // Purpose: Branch on T Not Equal to Zero (Extended)
    598 // To test special register T then do a PC-relative conditional branch.
    599 //
    600 def BtnezX16: FEXT_I816_ins<0b001, "btnez", IIAlu> ,cbranch16 {
    601   let Uses = [T8];
    602 }
    603 
    604 def BtnezT8CmpX16: FEXT_T8I816_ins<"btnez", "cmp">, cbranch16;
    605 
    606 def BtnezT8CmpiX16: FEXT_T8I8I16_ins<"btnez", "cmpi">, cbranch16;
    607 
    608 def BtnezT8SltX16: FEXT_T8I816_ins<"btnez", "slt">, cbranch16;
    609 
    610 def BtnezT8SltuX16: FEXT_T8I816_ins<"btnez", "sltu">, cbranch16;
    611 
    612 def BtnezT8SltiX16: FEXT_T8I8I16_ins<"btnez", "slti">, cbranch16;
    613 
    614 def BtnezT8SltiuX16: FEXT_T8I8I16_ins<"btnez", "sltiu">,
    615   cbranch16;
    616 
    617 //
    618 // Format: CMP rx, ry MIPS16e
    619 // Purpose: Compare
    620 // To compare the contents of two GPRs.
    621 //
    622 def CmpRxRy16: FRR16R_ins<0b01010, "cmp", IIAlu> {
    623   let Defs = [T8];
    624 }
    625 
    626 //
    627 // Format: CMPI rx, immediate MIPS16e
    628 // Purpose: Compare Immediate
    629 // To compare a constant with the contents of a GPR.
    630 //
    631 def CmpiRxImm16: FRI16R_ins<0b01110, "cmpi", IIAlu> {
    632   let Defs = [T8];
    633 }
    634 
    635 //
    636 // Format: CMPI rx, immediate MIPS16e
    637 // Purpose: Compare Immediate (Extended)
    638 // To compare a constant with the contents of a GPR.
    639 //
    640 def CmpiRxImmX16: FEXT_RI16R_ins<0b01110, "cmpi", IIAlu> {
    641   let Defs = [T8];
    642 }
    643 
    644 
    645 //
    646 // Format: DIV rx, ry MIPS16e
    647 // Purpose: Divide Word
    648 // To divide 32-bit signed integers.
    649 //
    650 def DivRxRy16: FRR16_div_ins<0b11010, "div", IIAlu> {
    651   let Defs = [HI, LO];
    652 }
    653 
    654 //
    655 // Format: DIVU rx, ry MIPS16e
    656 // Purpose: Divide Unsigned Word
    657 // To divide 32-bit unsigned integers.
    658 //
    659 def DivuRxRy16: FRR16_div_ins<0b11011, "divu", IIAlu> {
    660   let Defs = [HI, LO];
    661 }
    662 //
    663 // Format: JAL target MIPS16e
    664 // Purpose: Jump and Link
    665 // To execute a procedure call within the current 256 MB-aligned
    666 // region and preserve the current ISA.
    667 //
    668 
    669 def Jal16 : FJAL16_ins<0b0, "jal", IIAlu> {
    670   let isBranch = 1;
    671   let hasDelaySlot = 0;  // not true, but we add the nop for now
    672   let isTerminator=1;
    673   let isBarrier=1;
    674 }
    675 
    676 //
    677 // Format: JR ra MIPS16e
    678 // Purpose: Jump Register Through Register ra
    679 // To execute a branch to the instruction address in the return
    680 // address register.
    681 //
    682 
    683 def JrRa16: FRR16_JALRC_RA_only_ins<0, 0, "jr", IIAlu> {
    684   let isBranch = 1;
    685   let isIndirectBranch = 1;
    686   let hasDelaySlot = 1;
    687   let isTerminator=1;
    688   let isBarrier=1;
    689 }
    690 
    691 def JrcRa16: FRR16_JALRC_RA_only_ins<1, 1, "jrc", IIAlu> {
    692   let isBranch = 1;
    693   let isIndirectBranch = 1;
    694   let isTerminator=1;
    695   let isBarrier=1;
    696 }
    697 
    698 def JrcRx16: FRR16_JALRC_ins<1, 1, 0, "jrc", IIAlu> {
    699   let isBranch = 1;
    700   let isIndirectBranch = 1;
    701   let isTerminator=1;
    702   let isBarrier=1;
    703 }
    704 //
    705 // Format: LB ry, offset(rx) MIPS16e
    706 // Purpose: Load Byte (Extended)
    707 // To load a byte from memory as a signed value.
    708 //
    709 def LbRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lb", mem16, IILoad>, MayLoad{
    710   let isCodeGenOnly = 1;
    711 }
    712 
    713 //
    714 // Format: LBU ry, offset(rx) MIPS16e
    715 // Purpose: Load Byte Unsigned (Extended)
    716 // To load a byte from memory as a unsigned value.
    717 //
    718 def LbuRxRyOffMemX16:
    719   FEXT_RRI16_mem_ins<0b10100, "lbu", mem16, IILoad>, MayLoad {
    720   let isCodeGenOnly = 1;
    721 }
    722 
    723 //
    724 // Format: LH ry, offset(rx) MIPS16e
    725 // Purpose: Load Halfword signed (Extended)
    726 // To load a halfword from memory as a signed value.
    727 //
    728 def LhRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10100, "lh", mem16, IILoad>, MayLoad{
    729   let isCodeGenOnly = 1;
    730 }
    731 
    732 //
    733 // Format: LHU ry, offset(rx) MIPS16e
    734 // Purpose: Load Halfword unsigned (Extended)
    735 // To load a halfword from memory as an unsigned value.
    736 //
    737 def LhuRxRyOffMemX16:
    738   FEXT_RRI16_mem_ins<0b10100, "lhu", mem16, IILoad>, MayLoad {
    739   let isCodeGenOnly = 1;
    740 }
    741 
    742 //
    743 // Format: LI rx, immediate MIPS16e
    744 // Purpose: Load Immediate
    745 // To load a constant into a GPR.
    746 //
    747 def LiRxImm16: FRI16_ins<0b01101, "li", IIAlu>;
    748 
    749 //
    750 // Format: LI rx, immediate MIPS16e
    751 // Purpose: Load Immediate (Extended)
    752 // To load a constant into a GPR.
    753 //
    754 def LiRxImmX16: FEXT_RI16_ins<0b01101, "li", IIAlu>;
    755 
    756 //
    757 // Format: LW ry, offset(rx) MIPS16e
    758 // Purpose: Load Word (Extended)
    759 // To load a word from memory as a signed value.
    760 //
    761 def LwRxRyOffMemX16: FEXT_RRI16_mem_ins<0b10011, "lw", mem16, IILoad>, MayLoad{
    762   let isCodeGenOnly = 1;
    763 }
    764 
    765 // Format: LW rx, offset(sp) MIPS16e
    766 // Purpose: Load Word (SP-Relative, Extended)
    767 // To load an SP-relative word from memory as a signed value.
    768 //
    769 def LwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b10110, "lw", IILoad>, MayLoad{
    770   let Uses = [SP];
    771 }
    772 
    773 //
    774 // Format: MOVE r32, rz MIPS16e
    775 // Purpose: Move
    776 // To move the contents of a GPR to a GPR.
    777 //
    778 def Move32R16: FI8_MOV32R16_ins<"move", IIAlu>;
    779 
    780 //
    781 // Format: MOVE ry, r32 MIPS16e
    782 //Purpose: Move
    783 // To move the contents of a GPR to a GPR.
    784 //
    785 def MoveR3216: FI8_MOVR3216_ins<"move", IIAlu>;
    786 
    787 //
    788 // Format: MFHI rx MIPS16e
    789 // Purpose: Move From HI Register
    790 // To copy the special purpose HI register to a GPR.
    791 //
    792 def Mfhi16: FRR16_M_ins<0b10000, "mfhi", IIAlu> {
    793   let Uses = [HI];
    794   let neverHasSideEffects = 1;
    795 }
    796 
    797 //
    798 // Format: MFLO rx MIPS16e
    799 // Purpose: Move From LO Register
    800 // To copy the special purpose LO register to a GPR.
    801 //
    802 def Mflo16: FRR16_M_ins<0b10010, "mflo", IIAlu> {
    803   let Uses = [LO];
    804   let neverHasSideEffects = 1;
    805 }
    806 
    807 //
    808 // Pseudo Instruction for mult
    809 //
    810 def MultRxRy16:  FMULT16_ins<"mult",  IIAlu> {
    811   let isCommutable = 1;
    812   let neverHasSideEffects = 1;
    813   let Defs = [HI, LO];
    814 }
    815 
    816 def MultuRxRy16: FMULT16_ins<"multu", IIAlu> {
    817   let isCommutable = 1;
    818   let neverHasSideEffects = 1;
    819   let Defs = [HI, LO];
    820 }
    821 
    822 //
    823 // Format: MULT rx, ry MIPS16e
    824 // Purpose: Multiply Word
    825 // To multiply 32-bit signed integers.
    826 //
    827 def MultRxRyRz16: FMULT16_LO_ins<"mult", IIAlu> {
    828   let isCommutable = 1;
    829   let neverHasSideEffects = 1;
    830   let Defs = [HI, LO];
    831 }
    832 
    833 //
    834 // Format: MULTU rx, ry MIPS16e
    835 // Purpose: Multiply Unsigned Word
    836 // To multiply 32-bit unsigned integers.
    837 //
    838 def MultuRxRyRz16: FMULT16_LO_ins<"multu", IIAlu> {
    839   let isCommutable = 1;
    840   let neverHasSideEffects = 1;
    841   let Defs = [HI, LO];
    842 }
    843 
    844 //
    845 // Format: NEG rx, ry MIPS16e
    846 // Purpose: Negate
    847 // To negate an integer value.
    848 //
    849 def NegRxRy16: FUnaryRR16_ins<0b11101, "neg", IIAlu>;
    850 
    851 //
    852 // Format: NOT rx, ry MIPS16e
    853 // Purpose: Not
    854 // To complement an integer value
    855 //
    856 def NotRxRy16: FUnaryRR16_ins<0b01111, "not", IIAlu>;
    857 
    858 //
    859 // Format: OR rx, ry MIPS16e
    860 // Purpose: Or
    861 // To do a bitwise logical OR.
    862 //
    863 def OrRxRxRy16: FRxRxRy16_ins<0b01101, "or", IIAlu>, ArithLogic16Defs<1>;
    864 
    865 //
    866 // Format: RESTORE {ra,}{s0/s1/s0-1,}{framesize}
    867 // (All args are optional) MIPS16e
    868 // Purpose: Restore Registers and Deallocate Stack Frame
    869 // To deallocate a stack frame before exit from a subroutine,
    870 // restoring return address and static registers, and adjusting
    871 // stack
    872 //
    873 
    874 // fixed form for restoring RA and the frame
    875 // for direct object emitter, encoding needs to be adjusted for the
    876 // frame size
    877 //
    878 let ra=1, s=0,s0=1,s1=1 in
    879 def RestoreRaF16:
    880   FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
    881              "restore\t$$ra,  $$s0, $$s1, $frame_size", [], IILoad >, MayLoad {
    882   let isCodeGenOnly = 1;
    883   let Defs = [S0, S1, RA, SP];
    884   let Uses = [SP];
    885 }
    886 
    887 // Use Restore to increment SP since SP is not a Mip 16 register, this
    888 // is an easy way to do that which does not require a register.
    889 //
    890 let ra=0, s=0,s0=0,s1=0 in
    891 def RestoreIncSpF16:
    892   FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
    893              "restore\t$frame_size", [], IILoad >, MayLoad {
    894   let isCodeGenOnly = 1;
    895   let Defs = [SP];
    896   let Uses = [SP];
    897 }
    898 
    899 //
    900 // Format: SAVE {ra,}{s0/s1/s0-1,}{framesize} (All arguments are optional)
    901 // MIPS16e
    902 // Purpose: Save Registers and Set Up Stack Frame
    903 // To set up a stack frame on entry to a subroutine,
    904 // saving return address and static registers, and adjusting stack
    905 //
    906 let ra=1, s=1,s0=1,s1=1 in
    907 def SaveRaF16:
    908   FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
    909              "save\t$$ra, $$s0, $$s1, $frame_size", [], IIStore >, MayStore {
    910   let isCodeGenOnly = 1;
    911   let Uses = [RA, SP, S0, S1];
    912   let Defs = [SP];
    913 }
    914 
    915 //
    916 // Use Save to decrement the SP by a constant since SP is not
    917 // a Mips16 register.
    918 //
    919 let ra=0, s=0,s0=0,s1=0 in
    920 def SaveDecSpF16:
    921   FI8_SVRS16<0b1, (outs), (ins uimm16:$frame_size),
    922              "save\t$frame_size", [], IIStore >, MayStore {
    923   let isCodeGenOnly = 1;
    924   let Uses = [SP];
    925   let Defs = [SP];
    926 }
    927 //
    928 // Format: SB ry, offset(rx) MIPS16e
    929 // Purpose: Store Byte (Extended)
    930 // To store a byte to memory.
    931 //
    932 def SbRxRyOffMemX16:
    933   FEXT_RRI16_mem2_ins<0b11000, "sb", mem16, IIStore>, MayStore;
    934 
    935 //
    936 // The Sel(T) instructions are pseudos
    937 // T means that they use T8 implicitly.
    938 //
    939 //
    940 // Format: SelBeqZ rd, rs, rt
    941 // Purpose: if rt==0, do nothing
    942 //          else rs = rt
    943 //
    944 def SelBeqZ: Sel<"beqz">;
    945 
    946 //
    947 // Format:  SelTBteqZCmp rd, rs, rl, rr
    948 // Purpose: b = Cmp rl, rr.
    949 //          If b==0 then do nothing.
    950 //          if b!=0 then rd = rs
    951 //
    952 def SelTBteqZCmp: SelT<"bteqz", "cmp">;
    953 
    954 //
    955 // Format:  SelTBteqZCmpi rd, rs, rl, rr
    956 // Purpose: b = Cmpi rl, imm.
    957 //          If b==0 then do nothing.
    958 //          if b!=0 then rd = rs
    959 //
    960 def SelTBteqZCmpi: SeliT<"bteqz", "cmpi">;
    961 
    962 //
    963 // Format:  SelTBteqZSlt rd, rs, rl, rr
    964 // Purpose: b = Slt rl, rr.
    965 //          If b==0 then do nothing.
    966 //          if b!=0 then rd = rs
    967 //
    968 def SelTBteqZSlt: SelT<"bteqz", "slt">;
    969 
    970 //
    971 // Format:  SelTBteqZSlti rd, rs, rl, rr
    972 // Purpose: b = Slti rl, imm.
    973 //          If b==0 then do nothing.
    974 //          if b!=0 then rd = rs
    975 //
    976 def SelTBteqZSlti: SeliT<"bteqz", "slti">;
    977 
    978 //
    979 // Format:  SelTBteqZSltu rd, rs, rl, rr
    980 // Purpose: b = Sltu rl, rr.
    981 //          If b==0 then do nothing.
    982 //          if b!=0 then rd = rs
    983 //
    984 def SelTBteqZSltu: SelT<"bteqz", "sltu">;
    985 
    986 //
    987 // Format:  SelTBteqZSltiu rd, rs, rl, rr
    988 // Purpose: b = Sltiu rl, imm.
    989 //          If b==0 then do nothing.
    990 //          if b!=0 then rd = rs
    991 //
    992 def SelTBteqZSltiu: SeliT<"bteqz", "sltiu">;
    993 
    994 //
    995 // Format: SelBnez rd, rs, rt
    996 // Purpose: if rt!=0, do nothing
    997 //          else rs = rt
    998 //
    999 def SelBneZ: Sel<"bnez">;
   1000 
   1001 //
   1002 // Format:  SelTBtneZCmp rd, rs, rl, rr
   1003 // Purpose: b = Cmp rl, rr.
   1004 //          If b!=0 then do nothing.
   1005 //          if b0=0 then rd = rs
   1006 //
   1007 def SelTBtneZCmp: SelT<"btnez", "cmp">;
   1008 
   1009 //
   1010 // Format:  SelTBtnezCmpi rd, rs, rl, rr
   1011 // Purpose: b = Cmpi rl, imm.
   1012 //          If b!=0 then do nothing.
   1013 //          if b==0 then rd = rs
   1014 //
   1015 def SelTBtneZCmpi: SeliT<"btnez", "cmpi">;
   1016 
   1017 //
   1018 // Format:  SelTBtneZSlt rd, rs, rl, rr
   1019 // Purpose: b = Slt rl, rr.
   1020 //          If b!=0 then do nothing.
   1021 //          if b==0 then rd = rs
   1022 //
   1023 def SelTBtneZSlt: SelT<"btnez", "slt">;
   1024 
   1025 //
   1026 // Format:  SelTBtneZSlti rd, rs, rl, rr
   1027 // Purpose: b = Slti rl, imm.
   1028 //          If b!=0 then do nothing.
   1029 //          if b==0 then rd = rs
   1030 //
   1031 def SelTBtneZSlti: SeliT<"btnez", "slti">;
   1032 
   1033 //
   1034 // Format:  SelTBtneZSltu rd, rs, rl, rr
   1035 // Purpose: b = Sltu rl, rr.
   1036 //          If b!=0 then do nothing.
   1037 //          if b==0 then rd = rs
   1038 //
   1039 def SelTBtneZSltu: SelT<"btnez", "sltu">;
   1040 
   1041 //
   1042 // Format:  SelTBtneZSltiu rd, rs, rl, rr
   1043 // Purpose: b = Slti rl, imm.
   1044 //          If b!=0 then do nothing.
   1045 //          if b==0 then rd = rs
   1046 //
   1047 def SelTBtneZSltiu: SeliT<"btnez", "sltiu">;
   1048 //
   1049 //
   1050 // Format: SH ry, offset(rx) MIPS16e
   1051 // Purpose: Store Halfword (Extended)
   1052 // To store a halfword to memory.
   1053 //
   1054 def ShRxRyOffMemX16:
   1055   FEXT_RRI16_mem2_ins<0b11001, "sh", mem16, IIStore>, MayStore;
   1056 
   1057 //
   1058 // Format: SLL rx, ry, sa MIPS16e
   1059 // Purpose: Shift Word Left Logical (Extended)
   1060 // To execute a left-shift of a word by a fixed number of bits0 to 31 bits.
   1061 //
   1062 def SllX16: FEXT_SHIFT16_ins<0b00, "sll", IIAlu>;
   1063 
   1064 //
   1065 // Format: SLLV ry, rx MIPS16e
   1066 // Purpose: Shift Word Left Logical Variable
   1067 // To execute a left-shift of a word by a variable number of bits.
   1068 //
   1069 def SllvRxRy16 : FRxRxRy16_ins<0b00100, "sllv", IIAlu>;
   1070 
   1071 // Format: SLTI rx, immediate MIPS16e
   1072 // Purpose: Set on Less Than Immediate
   1073 // To record the result of a less-than comparison with a constant.
   1074 //
   1075 //
   1076 def SltiRxImm16: FRI16R_ins<0b01010, "slti", IIAlu> {
   1077   let Defs = [T8];
   1078 }
   1079 
   1080 //
   1081 // Format: SLTI rx, immediate MIPS16e
   1082 // Purpose: Set on Less Than Immediate (Extended)
   1083 // To record the result of a less-than comparison with a constant.
   1084 //
   1085 //
   1086 def SltiRxImmX16: FEXT_RI16R_ins<0b01010, "slti", IIAlu> {
   1087   let Defs = [T8];
   1088 }
   1089 
   1090 def SltiCCRxImmX16: FEXT_CCRXI16_ins<"slti">;
   1091 
   1092 // Format: SLTIU rx, immediate MIPS16e
   1093 // Purpose: Set on Less Than Immediate Unsigned
   1094 // To record the result of a less-than comparison with a constant.
   1095 //
   1096 //
   1097 def SltiuRxImm16: FRI16R_ins<0b01011, "sltiu", IIAlu> {
   1098   let Defs = [T8];
   1099 }
   1100 
   1101 //
   1102 // Format: SLTI rx, immediate MIPS16e
   1103 // Purpose: Set on Less Than Immediate Unsigned (Extended)
   1104 // To record the result of a less-than comparison with a constant.
   1105 //
   1106 //
   1107 def SltiuRxImmX16: FEXT_RI16R_ins<0b01011, "sltiu", IIAlu> {
   1108   let Defs = [T8];
   1109 }
   1110 //
   1111 // Format: SLTIU rx, immediate MIPS16e
   1112 // Purpose: Set on Less Than Immediate Unsigned (Extended)
   1113 // To record the result of a less-than comparison with a constant.
   1114 //
   1115 def SltiuCCRxImmX16: FEXT_CCRXI16_ins<"sltiu">;
   1116 
   1117 //
   1118 // Format: SLT rx, ry MIPS16e
   1119 // Purpose: Set on Less Than
   1120 // To record the result of a less-than comparison.
   1121 //
   1122 def SltRxRy16: FRR16R_ins<0b00010, "slt", IIAlu>{
   1123   let Defs = [T8];
   1124 }
   1125 
   1126 def SltCCRxRy16: FCCRR16_ins<"slt">;
   1127 
   1128 // Format: SLTU rx, ry MIPS16e
   1129 // Purpose: Set on Less Than Unsigned
   1130 // To record the result of an unsigned less-than comparison.
   1131 //
   1132 def SltuRxRy16: FRR16R_ins<0b00011, "sltu", IIAlu>{
   1133   let Defs = [T8];
   1134 }
   1135 
   1136 def SltuRxRyRz16: FRRTR16_ins<"sltu"> {
   1137   let isCodeGenOnly=1;
   1138   let Defs = [T8];
   1139 }
   1140 
   1141 
   1142 def SltuCCRxRy16: FCCRR16_ins<"sltu">;
   1143 //
   1144 // Format: SRAV ry, rx MIPS16e
   1145 // Purpose: Shift Word Right Arithmetic Variable
   1146 // To execute an arithmetic right-shift of a word by a variable
   1147 // number of bits.
   1148 //
   1149 def SravRxRy16: FRxRxRy16_ins<0b00111, "srav", IIAlu>;
   1150 
   1151 
   1152 //
   1153 // Format: SRA rx, ry, sa MIPS16e
   1154 // Purpose: Shift Word Right Arithmetic (Extended)
   1155 // To execute an arithmetic right-shift of a word by a fixed
   1156 // number of bits1 to 8 bits.
   1157 //
   1158 def SraX16: FEXT_SHIFT16_ins<0b11, "sra", IIAlu>;
   1159 
   1160 
   1161 //
   1162 // Format: SRLV ry, rx MIPS16e
   1163 // Purpose: Shift Word Right Logical Variable
   1164 // To execute a logical right-shift of a word by a variable
   1165 // number of bits.
   1166 //
   1167 def SrlvRxRy16: FRxRxRy16_ins<0b00110, "srlv", IIAlu>;
   1168 
   1169 
   1170 //
   1171 // Format: SRL rx, ry, sa MIPS16e
   1172 // Purpose: Shift Word Right Logical (Extended)
   1173 // To execute a logical right-shift of a word by a fixed
   1174 // number of bits1 to 31 bits.
   1175 //
   1176 def SrlX16: FEXT_SHIFT16_ins<0b10, "srl", IIAlu>;
   1177 
   1178 //
   1179 // Format: SUBU rz, rx, ry MIPS16e
   1180 // Purpose: Subtract Unsigned Word
   1181 // To subtract 32-bit integers
   1182 //
   1183 def SubuRxRyRz16: FRRR16_ins<0b11, "subu", IIAlu>, ArithLogic16Defs<0>;
   1184 
   1185 //
   1186 // Format: SW ry, offset(rx) MIPS16e
   1187 // Purpose: Store Word (Extended)
   1188 // To store a word to memory.
   1189 //
   1190 def SwRxRyOffMemX16:
   1191   FEXT_RRI16_mem2_ins<0b11011, "sw", mem16, IIStore>, MayStore;
   1192 
   1193 //
   1194 // Format: SW rx, offset(sp) MIPS16e
   1195 // Purpose: Store Word rx (SP-Relative)
   1196 // To store an SP-relative word to memory.
   1197 //
   1198 def SwRxSpImmX16: FEXT_RI16_SP_explicit_ins<0b11010, "sw", IIStore>, MayStore;
   1199 
   1200 //
   1201 //
   1202 // Format: XOR rx, ry MIPS16e
   1203 // Purpose: Xor
   1204 // To do a bitwise logical XOR.
   1205 //
   1206 def XorRxRxRy16: FRxRxRy16_ins<0b01110, "xor", IIAlu>, ArithLogic16Defs<1>;
   1207 
   1208 class Mips16Pat<dag pattern, dag result> : Pat<pattern, result> {
   1209   let Predicates = [InMips16Mode];
   1210 }
   1211 
   1212 // Unary Arith/Logic
   1213 //
   1214 class ArithLogicU_pat<PatFrag OpNode, Instruction I> :
   1215   Mips16Pat<(OpNode CPU16Regs:$r),
   1216             (I CPU16Regs:$r)>;
   1217 
   1218 def: ArithLogicU_pat<not, NotRxRy16>;
   1219 def: ArithLogicU_pat<ineg, NegRxRy16>;
   1220 
   1221 class ArithLogic16_pat<SDNode OpNode, Instruction I> :
   1222   Mips16Pat<(OpNode CPU16Regs:$l, CPU16Regs:$r),
   1223             (I CPU16Regs:$l, CPU16Regs:$r)>;
   1224 
   1225 def: ArithLogic16_pat<add, AdduRxRyRz16>;
   1226 def: ArithLogic16_pat<and, AndRxRxRy16>;
   1227 def: ArithLogic16_pat<mul, MultRxRyRz16>;
   1228 def: ArithLogic16_pat<or, OrRxRxRy16>;
   1229 def: ArithLogic16_pat<sub, SubuRxRyRz16>;
   1230 def: ArithLogic16_pat<xor, XorRxRxRy16>;
   1231 
   1232 // Arithmetic and logical instructions with 2 register operands.
   1233 
   1234 class ArithLogicI16_pat<SDNode OpNode, PatFrag imm_type, Instruction I> :
   1235   Mips16Pat<(OpNode CPU16Regs:$in, imm_type:$imm),
   1236             (I CPU16Regs:$in, imm_type:$imm)>;
   1237 
   1238 def: ArithLogicI16_pat<add, immSExt8, AddiuRxRxImm16>;
   1239 def: ArithLogicI16_pat<add, immSExt16, AddiuRxRxImmX16>;
   1240 def: ArithLogicI16_pat<shl, immZExt5, SllX16>;
   1241 def: ArithLogicI16_pat<srl, immZExt5, SrlX16>;
   1242 def: ArithLogicI16_pat<sra, immZExt5, SraX16>;
   1243 
   1244 class shift_rotate_reg16_pat<SDNode OpNode, Instruction I> :
   1245   Mips16Pat<(OpNode CPU16Regs:$r, CPU16Regs:$ra),
   1246             (I CPU16Regs:$r, CPU16Regs:$ra)>;
   1247 
   1248 def: shift_rotate_reg16_pat<shl, SllvRxRy16>;
   1249 def: shift_rotate_reg16_pat<sra, SravRxRy16>;
   1250 def: shift_rotate_reg16_pat<srl, SrlvRxRy16>;
   1251 
   1252 class LoadM16_pat<PatFrag OpNode, Instruction I> :
   1253   Mips16Pat<(OpNode addr16:$addr), (I addr16:$addr)>;
   1254 
   1255 def: LoadM16_pat<sextloadi8, LbRxRyOffMemX16>;
   1256 def: LoadM16_pat<zextloadi8, LbuRxRyOffMemX16>;
   1257 def: LoadM16_pat<sextloadi16, LhRxRyOffMemX16>;
   1258 def: LoadM16_pat<zextloadi16, LhuRxRyOffMemX16>;
   1259 def: LoadM16_pat<load, LwRxRyOffMemX16>;
   1260 
   1261 class StoreM16_pat<PatFrag OpNode, Instruction I> :
   1262   Mips16Pat<(OpNode CPU16Regs:$r, addr16:$addr),
   1263             (I CPU16Regs:$r, addr16:$addr)>;
   1264 
   1265 def: StoreM16_pat<truncstorei8, SbRxRyOffMemX16>;
   1266 def: StoreM16_pat<truncstorei16, ShRxRyOffMemX16>;
   1267 def: StoreM16_pat<store, SwRxRyOffMemX16>;
   1268 
   1269 // Unconditional branch
   1270 class UncondBranch16_pat<SDNode OpNode, Instruction I>:
   1271   Mips16Pat<(OpNode bb:$imm16), (I bb:$imm16)> {
   1272     let Predicates = [InMips16Mode];
   1273   }
   1274 
   1275 def : Mips16Pat<(MipsJmpLink (i32 tglobaladdr:$dst)),
   1276                 (Jal16 tglobaladdr:$dst)>;
   1277 
   1278 def : Mips16Pat<(MipsJmpLink (i32 texternalsym:$dst)),
   1279                 (Jal16 texternalsym:$dst)>;
   1280 
   1281 // Indirect branch
   1282 def: Mips16Pat<
   1283   (brind CPU16Regs:$rs),
   1284   (JrcRx16 CPU16Regs:$rs)>;
   1285 
   1286 // Jump and Link (Call)
   1287 let isCall=1, hasDelaySlot=0 in
   1288 def JumpLinkReg16:
   1289   FRR16_JALRC<0, 0, 0, (outs), (ins CPU16Regs:$rs),
   1290               "jalrc \t$rs", [(MipsJmpLink CPU16Regs:$rs)], IIBranch>;
   1291 
   1292 // Mips16 pseudos
   1293 let isReturn=1, isTerminator=1, hasDelaySlot=1, isBarrier=1, hasCtrlDep=1,
   1294   hasExtraSrcRegAllocReq = 1 in
   1295 def RetRA16 : MipsPseudo16<(outs), (ins), "", [(MipsRet)]>;
   1296 
   1297 
   1298 // setcc patterns
   1299 
   1300 class SetCC_R16<PatFrag cond_op, Instruction I>:
   1301   Mips16Pat<(cond_op CPU16Regs:$rx, CPU16Regs:$ry),
   1302             (I CPU16Regs:$rx, CPU16Regs:$ry)>;
   1303 
   1304 class SetCC_I16<PatFrag cond_op, PatLeaf imm_type, Instruction I>:
   1305   Mips16Pat<(cond_op CPU16Regs:$rx, imm_type:$imm16),
   1306             (I CPU16Regs:$rx, imm_type:$imm16)>;
   1307 
   1308 
   1309 def: Mips16Pat<(i32  addr16:$addr),
   1310                (AddiuRxRyOffMemX16  addr16:$addr)>;
   1311 
   1312 
   1313 // Large (>16 bit) immediate loads
   1314 def : Mips16Pat<(i32 imm:$imm),
   1315                 (OrRxRxRy16 (SllX16 (LiRxImmX16 (HI16 imm:$imm)), 16),
   1316                 (LiRxImmX16 (LO16 imm:$imm)))>;
   1317 
   1318 // Carry MipsPatterns
   1319 def : Mips16Pat<(subc CPU16Regs:$lhs, CPU16Regs:$rhs),
   1320                 (SubuRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
   1321 def : Mips16Pat<(addc CPU16Regs:$lhs, CPU16Regs:$rhs),
   1322                 (AdduRxRyRz16 CPU16Regs:$lhs, CPU16Regs:$rhs)>;
   1323 def : Mips16Pat<(addc  CPU16Regs:$src, immSExt16:$imm),
   1324                 (AddiuRxRxImmX16 CPU16Regs:$src, imm:$imm)>;
   1325 
   1326 //
   1327 // Some branch conditional patterns are not generated by llvm at this time.
   1328 // Some are for seemingly arbitrary reasons not used: i.e. with signed number
   1329 // comparison they are used and for unsigned a different pattern is used.
   1330 // I am pushing upstream from the full mips16 port and it seemed that I needed
   1331 // these earlier and the mips32 port has these but now I cannot create test
   1332 // cases that use these patterns. While I sort this all out I will leave these
   1333 // extra patterns commented out and if I can be sure they are really not used,
   1334 // I will delete the code. I don't want to check the code in uncommented without
   1335 // a valid test case. In some cases, the compiler is generating patterns with
   1336 // setcc instead and earlier I had implemented setcc first so may have masked
   1337 // the problem. The setcc variants are suboptimal for mips16 so I may wantto
   1338 // figure out how to enable the brcond patterns or else possibly new
   1339 // combinations of of brcond and setcc.
   1340 //
   1341 //
   1342 // bcond-seteq
   1343 //
   1344 def: Mips16Pat
   1345   <(brcond (i32 (seteq CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
   1346    (BteqzT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
   1347   >;
   1348 
   1349 
   1350 def: Mips16Pat
   1351   <(brcond (i32 (seteq CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
   1352    (BteqzT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm,  bb:$targ16)
   1353   >;
   1354 
   1355 def: Mips16Pat
   1356   <(brcond (i32 (seteq CPU16Regs:$rx, 0)), bb:$targ16),
   1357    (BeqzRxImmX16 CPU16Regs:$rx, bb:$targ16)
   1358   >;
   1359 
   1360 //
   1361 // bcond-setgt (do we need to have this pair of setlt, setgt??)
   1362 //
   1363 def: Mips16Pat
   1364   <(brcond (i32 (setgt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
   1365    (BtnezT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx,  bb:$imm16)
   1366   >;
   1367 
   1368 //
   1369 // bcond-setge
   1370 //
   1371 def: Mips16Pat
   1372   <(brcond (i32 (setge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
   1373    (BteqzT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
   1374   >;
   1375 
   1376 //
   1377 // never called because compiler transforms a >= k to a > (k-1)
   1378 def: Mips16Pat
   1379   <(brcond (i32 (setge CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
   1380    (BteqzT8SltiX16 CPU16Regs:$rx, immSExt16:$imm,  bb:$imm16)
   1381   >;
   1382 
   1383 //
   1384 // bcond-setlt
   1385 //
   1386 def: Mips16Pat
   1387   <(brcond (i32 (setlt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
   1388    (BtnezT8SltX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
   1389   >;
   1390 
   1391 def: Mips16Pat
   1392   <(brcond (i32 (setlt CPU16Regs:$rx, immSExt16:$imm)), bb:$imm16),
   1393    (BtnezT8SltiX16 CPU16Regs:$rx, immSExt16:$imm,  bb:$imm16)
   1394   >;
   1395 
   1396 //
   1397 // bcond-setle
   1398 //
   1399 def: Mips16Pat
   1400   <(brcond (i32 (setle CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
   1401    (BteqzT8SltX16 CPU16Regs:$ry, CPU16Regs:$rx,  bb:$imm16)
   1402   >;
   1403 
   1404 //
   1405 // bcond-setne
   1406 //
   1407 def: Mips16Pat
   1408   <(brcond (i32 (setne CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
   1409    (BtnezT8CmpX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
   1410   >;
   1411 
   1412 def: Mips16Pat
   1413   <(brcond (i32 (setne CPU16Regs:$rx, immZExt16:$imm)), bb:$targ16),
   1414    (BtnezT8CmpiX16 CPU16Regs:$rx, immSExt16:$imm,  bb:$targ16)
   1415   >;
   1416 
   1417 def: Mips16Pat
   1418   <(brcond (i32 (setne CPU16Regs:$rx, 0)), bb:$targ16),
   1419    (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
   1420   >;
   1421 
   1422 //
   1423 // This needs to be there but I forget which code will generate it
   1424 //
   1425 def: Mips16Pat
   1426   <(brcond CPU16Regs:$rx, bb:$targ16),
   1427    (BnezRxImmX16 CPU16Regs:$rx, bb:$targ16)
   1428   >;
   1429 
   1430 //
   1431 
   1432 //
   1433 // bcond-setugt
   1434 //
   1435 //def: Mips16Pat
   1436 //  <(brcond (i32 (setugt CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
   1437 //   (BtnezT8SltuX16 CPU16Regs:$ry, CPU16Regs:$rx,  bb:$imm16)
   1438 //  >;
   1439 
   1440 //
   1441 // bcond-setuge
   1442 //
   1443 //def: Mips16Pat
   1444 //  <(brcond (i32 (setuge CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
   1445 //   (BteqzT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
   1446 //  >;
   1447 
   1448 
   1449 //
   1450 // bcond-setult
   1451 //
   1452 //def: Mips16Pat
   1453 //  <(brcond (i32 (setult CPU16Regs:$rx, CPU16Regs:$ry)), bb:$imm16),
   1454 //   (BtnezT8SltuX16 CPU16Regs:$rx, CPU16Regs:$ry,  bb:$imm16)
   1455 //  >;
   1456 
   1457 def: UncondBranch16_pat<br, BimmX16>;
   1458 
   1459 // Small immediates
   1460 def: Mips16Pat<(i32 immSExt16:$in),
   1461                (AddiuRxRxImmX16 (Move32R16 ZERO), immSExt16:$in)>;
   1462 
   1463 def: Mips16Pat<(i32 immZExt16:$in), (LiRxImmX16 immZExt16:$in)>;
   1464 
   1465 //
   1466 // MipsDivRem
   1467 //
   1468 def: Mips16Pat
   1469   <(MipsDivRem CPU16Regs:$rx, CPU16Regs:$ry),
   1470    (DivRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
   1471 
   1472 //
   1473 // MipsDivRemU
   1474 //
   1475 def: Mips16Pat
   1476   <(MipsDivRemU CPU16Regs:$rx, CPU16Regs:$ry),
   1477    (DivuRxRy16 CPU16Regs:$rx, CPU16Regs:$ry)>;
   1478 
   1479 //  signed a,b
   1480 //  x = (a>=b)?x:y
   1481 //
   1482 //  if !(a < b) x = y
   1483 //
   1484 def : Mips16Pat<(select (i32 (setge CPU16Regs:$a, CPU16Regs:$b)),
   1485                  CPU16Regs:$x, CPU16Regs:$y),
   1486                 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
   1487                  CPU16Regs:$a, CPU16Regs:$b)>;
   1488 
   1489 //  signed a,b
   1490 //  x = (a>b)?x:y
   1491 //
   1492 //  if  (b < a) x = y
   1493 //
   1494 def : Mips16Pat<(select (i32 (setgt CPU16Regs:$a, CPU16Regs:$b)),
   1495                  CPU16Regs:$x, CPU16Regs:$y),
   1496                 (SelTBtneZSlt CPU16Regs:$x, CPU16Regs:$y,
   1497                  CPU16Regs:$b, CPU16Regs:$a)>;
   1498 
   1499 // unsigned a,b
   1500 // x = (a>=b)?x:y
   1501 //
   1502 // if !(a < b) x = y;
   1503 //
   1504 def : Mips16Pat<
   1505   (select (i32 (setuge CPU16Regs:$a, CPU16Regs:$b)),
   1506    CPU16Regs:$x, CPU16Regs:$y),
   1507   (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
   1508    CPU16Regs:$a, CPU16Regs:$b)>;
   1509 
   1510 //  unsigned a,b
   1511 //  x = (a>b)?x:y
   1512 //
   1513 //  if (b < a) x = y
   1514 //
   1515 def : Mips16Pat<(select (i32 (setugt CPU16Regs:$a, CPU16Regs:$b)),
   1516                  CPU16Regs:$x, CPU16Regs:$y),
   1517                 (SelTBtneZSltu CPU16Regs:$x, CPU16Regs:$y,
   1518                  CPU16Regs:$b, CPU16Regs:$a)>;
   1519 
   1520 // signed
   1521 // x = (a >= k)?x:y
   1522 // due to an llvm optimization, i don't think that this will ever
   1523 // be used. This is transformed into x = (a > k-1)?x:y
   1524 //
   1525 //
   1526 
   1527 //def : Mips16Pat<
   1528 //  (select (i32 (setge CPU16Regs:$lhs, immSExt16:$rhs)),
   1529 //   CPU16Regs:$T, CPU16Regs:$F),
   1530 //  (SelTBteqZSlti CPU16Regs:$T, CPU16Regs:$F,
   1531 //   CPU16Regs:$lhs, immSExt16:$rhs)>;
   1532 
   1533 //def : Mips16Pat<
   1534 //  (select (i32 (setuge CPU16Regs:$lhs, immSExt16:$rhs)),
   1535 //   CPU16Regs:$T, CPU16Regs:$F),
   1536 //  (SelTBteqZSltiu CPU16Regs:$T, CPU16Regs:$F,
   1537 //   CPU16Regs:$lhs, immSExt16:$rhs)>;
   1538 
   1539 // signed
   1540 // x = (a < k)?x:y
   1541 //
   1542 // if !(a < k) x = y;
   1543 //
   1544 def : Mips16Pat<
   1545   (select (i32 (setlt CPU16Regs:$a, immSExt16:$b)),
   1546    CPU16Regs:$x, CPU16Regs:$y),
   1547   (SelTBtneZSlti CPU16Regs:$x, CPU16Regs:$y,
   1548    CPU16Regs:$a, immSExt16:$b)>;
   1549 
   1550 
   1551 //
   1552 //
   1553 // signed
   1554 // x = (a <= b)? x : y
   1555 //
   1556 // if  (b < a) x = y
   1557 //
   1558 def : Mips16Pat<(select (i32 (setle CPU16Regs:$a, CPU16Regs:$b)),
   1559                  CPU16Regs:$x, CPU16Regs:$y),
   1560                 (SelTBteqZSlt CPU16Regs:$x, CPU16Regs:$y,
   1561                  CPU16Regs:$b, CPU16Regs:$a)>;
   1562 
   1563 //
   1564 // unnsigned
   1565 // x = (a <= b)? x : y
   1566 //
   1567 // if  (b < a) x = y
   1568 //
   1569 def : Mips16Pat<(select (i32 (setule CPU16Regs:$a, CPU16Regs:$b)),
   1570                  CPU16Regs:$x, CPU16Regs:$y),
   1571                 (SelTBteqZSltu CPU16Regs:$x, CPU16Regs:$y,
   1572                  CPU16Regs:$b, CPU16Regs:$a)>;
   1573 
   1574 //
   1575 // signed/unsigned
   1576 // x = (a == b)? x : y
   1577 //
   1578 // if (a != b) x = y
   1579 //
   1580 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, CPU16Regs:$b)),
   1581                  CPU16Regs:$x, CPU16Regs:$y),
   1582                 (SelTBteqZCmp CPU16Regs:$x, CPU16Regs:$y,
   1583                  CPU16Regs:$b, CPU16Regs:$a)>;
   1584 
   1585 //
   1586 // signed/unsigned
   1587 // x = (a == 0)? x : y
   1588 //
   1589 // if (a != 0) x = y
   1590 //
   1591 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, 0)),
   1592                  CPU16Regs:$x, CPU16Regs:$y),
   1593                 (SelBeqZ CPU16Regs:$x, CPU16Regs:$y,
   1594                  CPU16Regs:$a)>;
   1595 
   1596 
   1597 //
   1598 // signed/unsigned
   1599 // x = (a == k)? x : y
   1600 //
   1601 // if (a != k) x = y
   1602 //
   1603 def : Mips16Pat<(select (i32 (seteq CPU16Regs:$a, immZExt16:$k)),
   1604                  CPU16Regs:$x, CPU16Regs:$y),
   1605                 (SelTBteqZCmpi CPU16Regs:$x, CPU16Regs:$y,
   1606                  CPU16Regs:$a, immZExt16:$k)>;
   1607 
   1608 
   1609 //
   1610 // signed/unsigned
   1611 // x = (a != b)? x : y
   1612 //
   1613 // if (a == b) x = y
   1614 //
   1615 //
   1616 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, CPU16Regs:$b)),
   1617                  CPU16Regs:$x, CPU16Regs:$y),
   1618                 (SelTBtneZCmp CPU16Regs:$x, CPU16Regs:$y,
   1619                  CPU16Regs:$b, CPU16Regs:$a)>;
   1620 
   1621 //
   1622 // signed/unsigned
   1623 // x = (a != 0)? x : y
   1624 //
   1625 // if (a == 0) x = y
   1626 //
   1627 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, 0)),
   1628                  CPU16Regs:$x, CPU16Regs:$y),
   1629                 (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
   1630                  CPU16Regs:$a)>;
   1631 
   1632 // signed/unsigned
   1633 // x = (a)? x : y
   1634 //
   1635 // if (!a) x = y
   1636 //
   1637 def : Mips16Pat<(select  CPU16Regs:$a,
   1638                  CPU16Regs:$x, CPU16Regs:$y),
   1639       (SelBneZ CPU16Regs:$x, CPU16Regs:$y,
   1640        CPU16Regs:$a)>;
   1641 
   1642 
   1643 //
   1644 // signed/unsigned
   1645 // x = (a != k)? x : y
   1646 //
   1647 // if (a == k) x = y
   1648 //
   1649 def : Mips16Pat<(select (i32 (setne CPU16Regs:$a, immZExt16:$k)),
   1650                  CPU16Regs:$x, CPU16Regs:$y),
   1651                 (SelTBtneZCmpi CPU16Regs:$x, CPU16Regs:$y,
   1652                  CPU16Regs:$a, immZExt16:$k)>;
   1653 
   1654 //
   1655 // When writing C code to test setxx these patterns,
   1656 // some will be transformed into
   1657 // other things. So we test using C code but using -O3 and -O0
   1658 //
   1659 // seteq
   1660 //
   1661 def : Mips16Pat
   1662   <(seteq CPU16Regs:$lhs,CPU16Regs:$rhs),
   1663    (SltiuCCRxImmX16 (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs), 1)>;
   1664 
   1665 def : Mips16Pat
   1666   <(seteq CPU16Regs:$lhs, 0),
   1667    (SltiuCCRxImmX16 CPU16Regs:$lhs, 1)>;
   1668 
   1669 
   1670 //
   1671 // setge
   1672 //
   1673 
   1674 def: Mips16Pat
   1675   <(setge CPU16Regs:$lhs, CPU16Regs:$rhs),
   1676    (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
   1677    (LiRxImmX16 1))>;
   1678 
   1679 //
   1680 // For constants, llvm transforms this to:
   1681 // x > (k -1) and then reverses the operands to use setlt. So this pattern
   1682 // is not used now by the compiler. (Presumably checking that k-1 does not
   1683 // overflow). The compiler never uses this at a the current time, due to
   1684 // other optimizations.
   1685 //
   1686 //def: Mips16Pat
   1687 //  <(setge CPU16Regs:$lhs, immSExt16:$rhs),
   1688 //   (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, immSExt16:$rhs),
   1689 //   (LiRxImmX16 1))>;
   1690 
   1691 // This catches the x >= -32768 case by transforming it to  x > -32769
   1692 //
   1693 def: Mips16Pat
   1694   <(setgt CPU16Regs:$lhs, -32769),
   1695    (XorRxRxRy16 (SltiCCRxImmX16 CPU16Regs:$lhs, -32768),
   1696    (LiRxImmX16 1))>;
   1697 
   1698 //
   1699 // setgt
   1700 //
   1701 //
   1702 
   1703 def: Mips16Pat
   1704   <(setgt CPU16Regs:$lhs, CPU16Regs:$rhs),
   1705    (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
   1706 
   1707 //
   1708 // setle
   1709 //
   1710 def: Mips16Pat
   1711   <(setle CPU16Regs:$lhs, CPU16Regs:$rhs),
   1712    (XorRxRxRy16 (SltCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImm16 1))>;
   1713 
   1714 //
   1715 // setlt
   1716 //
   1717 def: SetCC_R16<setlt, SltCCRxRy16>;
   1718 
   1719 def: SetCC_I16<setlt, immSExt16, SltiCCRxImmX16>;
   1720 
   1721 //
   1722 // setne
   1723 //
   1724 def : Mips16Pat
   1725   <(setne CPU16Regs:$lhs,CPU16Regs:$rhs),
   1726    (SltuCCRxRy16 (LiRxImmX16 0),
   1727    (XorRxRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs))>;
   1728 
   1729 
   1730 //
   1731 // setuge
   1732 //
   1733 def: Mips16Pat
   1734   <(setuge CPU16Regs:$lhs, CPU16Regs:$rhs),
   1735    (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$lhs, CPU16Regs:$rhs),
   1736    (LiRxImmX16 1))>;
   1737 
   1738 // this pattern will never be used because the compiler will transform
   1739 // x >= k to x > (k - 1) and then use SLT
   1740 //
   1741 //def: Mips16Pat
   1742 //  <(setuge CPU16Regs:$lhs, immZExt16:$rhs),
   1743 //   (XorRxRxRy16 (SltiuCCRxImmX16 CPU16Regs:$lhs, immZExt16:$rhs),
   1744 //   (LiRxImmX16 1))>;
   1745 
   1746 //
   1747 // setugt
   1748 //
   1749 def: Mips16Pat
   1750   <(setugt CPU16Regs:$lhs, CPU16Regs:$rhs),
   1751    (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs)>;
   1752 
   1753 //
   1754 // setule
   1755 //
   1756 def: Mips16Pat
   1757   <(setule CPU16Regs:$lhs, CPU16Regs:$rhs),
   1758    (XorRxRxRy16 (SltuCCRxRy16 CPU16Regs:$rhs, CPU16Regs:$lhs), (LiRxImmX16 1))>;
   1759 
   1760 //
   1761 // setult
   1762 //
   1763 def: SetCC_R16<setult, SltuCCRxRy16>;
   1764 
   1765 def: SetCC_I16<setult, immSExt16, SltiuCCRxImmX16>;
   1766 
   1767 def: Mips16Pat<(add CPU16Regs:$hi, (MipsLo tglobaladdr:$lo)),
   1768                (AddiuRxRxImmX16 CPU16Regs:$hi, tglobaladdr:$lo)>;
   1769 
   1770 // hi/lo relocs
   1771 
   1772 def : Mips16Pat<(MipsHi tglobaladdr:$in),
   1773                 (SllX16 (LiRxImmX16 tglobaladdr:$in), 16)>;
   1774 def : Mips16Pat<(MipsHi tjumptable:$in),
   1775                 (SllX16 (LiRxImmX16 tjumptable:$in), 16)>;
   1776 def : Mips16Pat<(MipsHi tglobaltlsaddr:$in),
   1777                 (SllX16 (LiRxImmX16 tglobaltlsaddr:$in), 16)>;
   1778 
   1779 // wrapper_pic
   1780 class Wrapper16Pat<SDNode node, Instruction ADDiuOp, RegisterClass RC>:
   1781   Mips16Pat<(MipsWrapper RC:$gp, node:$in),
   1782             (ADDiuOp RC:$gp, node:$in)>;
   1783 
   1784 
   1785 def : Wrapper16Pat<tglobaladdr, AddiuRxRxImmX16, CPU16Regs>;
   1786 def : Wrapper16Pat<tglobaltlsaddr, AddiuRxRxImmX16, CPU16Regs>;
   1787 
   1788 def : Mips16Pat<(i32 (extloadi8   addr16:$src)),
   1789                 (LbuRxRyOffMemX16  addr16:$src)>;
   1790 def : Mips16Pat<(i32 (extloadi16  addr16:$src)),
   1791                 (LhuRxRyOffMemX16  addr16:$src)>;
   1792