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