1 //===-- CSKYInstrInfo16Instr.td - CSKY 16-bit Instruction --*- tablegen -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file describes the CSKY 16-bit instructions in TableGen format.
11 //===----------------------------------------------------------------------===//
13 //===----------------------------------------------------------------------===//
14 // CSKY specific DAG Nodes.
15 //===----------------------------------------------------------------------===//
17 // Target-dependent nodes.
18 def CSKY_NIE : SDNode<"CSKYISD::NIE", SDTNone,
19 [SDNPHasChain, SDNPOptInGlue]>;
20 def CSKY_NIR : SDNode<"CSKYISD::NIR", SDTNone,
21 [SDNPHasChain, SDNPOptInGlue]>;
23 //===----------------------------------------------------------------------===//
24 // Operand and SDNode transformation definitions.
25 //===----------------------------------------------------------------------===//
27 def br_symbol_16bit : Operand<OtherVT> {
29 "getBranchSymbolOpValue<CSKY::fixup_csky_pcrel_imm10_scale2>";
30 let ParserMatchClass = CSKYSymbol;
31 let DecoderMethod = "decodeSImmOperand<10, 1>";
32 let PrintMethod = "printCSKYSymbolOperand";
33 let OperandType = "OPERAND_PCREL";
36 def constpool_symbol_16bit : Operand<iPTR> {
37 let ParserMatchClass = Constpool;
39 "getConstpoolSymbolOpValue<CSKY::fixup_csky_pcrel_uimm7_scale4>";
40 let DecoderMethod = "decodeLRW16Imm8";
41 let PrintMethod = "printConstpool";
42 let OperandType = "OPERAND_PCREL";
45 //===----------------------------------------------------------------------===//
46 // Instruction Formats
47 //===----------------------------------------------------------------------===//
49 include "CSKYInstrFormats16Instr.td"
51 //===----------------------------------------------------------------------===//
52 // Instruction definitions.
53 //===----------------------------------------------------------------------===//
55 //===----------------------------------------------------------------------===//
56 // Basic ALU instructions.
57 //===----------------------------------------------------------------------===//
59 let isCommutable = 1, isAdd = 1 in
60 def ADDU16 : R16_XYZ<0, "addu16", add>;
61 let Pattern = [(set mGPR:$rz, (sub mGPR:$rx, mGPR:$ry))] in
62 def SUBU16 : R16_XYZ<1, "subu16", sub>;
64 let isCommutable = 1, isAdd = 1 in
65 def ADDC16 : R16_XZ_BINOP_C<0b1000, 0b01, "addc16">;
66 def SUBC16 : R16_XZ_BINOP_C<0b1000, 0b11, "subc16">;
68 let isCommutable = 1 in {
70 def ADDU16XZ : R16_XZ_BINOP<0b1000, 0b00, "addu16", BinOpFrag<(add node:$LHS, node:$RHS)>>;
71 def AND16 : R16_XZ_BINOP<0b1010, 0b00, "and16", BinOpFrag<(and node:$LHS, node:$RHS)>>;
72 def OR16 : R16_XZ_BINOP<0b1011, 0b00, "or16", BinOpFrag<(or node:$LHS, node:$RHS)>>;
73 def XOR16 : R16_XZ_BINOP<0b1011, 0b01, "xor16", BinOpFrag<(xor node:$LHS, node:$RHS)>>;
74 def NOR16 : R16_XZ_BINOP<0b1011, 0b10, "nor16", BinOpFrag<(not (or node:$LHS, node:$RHS))>>;
75 let isCodeGenOnly = 1 in
76 def NOT16 : R16_Z_UNOP<0b1011, 0b10, "not16">;
77 def MULT16 : R16_XZ_BINOP<0b1111, 0b00, "mult16", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
79 def SUBU16XZ : R16_XZ_BINOP<0b1000, 0b10, "subu16", BinOpFrag<(sub node:$LHS, node:$RHS)>>;
80 def ANDN16 : R16_XZ_BINOP<0b1010, 0b01, "andn16", BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
81 def LSL16 : R16_XZ_BINOP<0b1100, 0b00, "lsl16", BinOpFrag<(shl node:$LHS, node:$RHS)>>;
82 def LSR16 : R16_XZ_BINOP<0b1100, 0b01, "lsr16", BinOpFrag<(srl node:$LHS, node:$RHS)>>;
83 def ASR16 : R16_XZ_BINOP<0b1100, 0b10, "asr16", BinOpFrag<(sra node:$LHS, node:$RHS)>>;
84 def ROTL16 : R16_XZ_BINOP<0b1100, 0b11, "rotl16", BinOpFrag<(rotl node:$LHS, (and node:$RHS, 0x1f))>>;
86 def MULSH16 : R16_XZ_BINOP_NOPat<0b1111, 0b01, "mulsh16">;
88 def ZEXTB16 : R16_XZ_UNOP<0b1101, 0b00, "zextb16">;
89 def ZEXTH16 : R16_XZ_UNOP<0b1101, 0b01, "zexth16">;
90 def SEXTB16 : R16_XZ_UNOP<0b1101, 0b10, "sextb16">;
91 def SEXTH16 : R16_XZ_UNOP<0b1101, 0b11, "sexth16">;
93 let Constraints = "$rZ = $rz", isReMaterializable = 1, isAsCheapAsAMove = 1 in {
94 let isAdd = 1, Pattern = [(set mGPR:$rz, (add mGPR:$rZ, oimm8:$imm8))] in
95 def ADDI16 : I16_Z_8<0b100, (ins mGPR:$rZ, oimm8:$imm8), "addi16\t$rz, $imm8">;
96 let Pattern = [(set mGPR:$rz, (sub mGPR:$rZ, oimm8:$imm8))] in
97 def SUBI16 : I16_Z_8<0b101, (ins mGPR:$rZ, oimm8:$imm8), "subi16\t$rz, $imm8">;
100 def : Pat<(add GPR:$rs1, (oimm8_neg:$im)),
101 (SUBI16 GPR:$rs1, (imm_neg_XFORM oimm8_neg:$im))>;
104 def ADDI16ZSP : I16_Z_8<0b011, (ins GPRSP:$sp, uimm8_2:$imm8),
105 "addi16\t$rz, $sp, $imm8">;
108 def ADDI16SPSP : I16_SP_IMM7<0b000,"addi16">;
109 def SUBI16SPSP : I16_SP_IMM7<0b001,"subi16">;
111 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
112 def LSLI16 : I16_XZ_IMM5<0, "lsli16", shl>;
113 def LSRI16 : I16_XZ_IMM5<1, "lsri16", srl>;
114 def ASRI16 : I16_XZ_IMM5<2, "asri16", sra>;
118 def ADDI16XZ : I16_XZ_IMM3<0b10, "addi16", add>;
119 def SUBI16XZ : I16_XZ_IMM3<0b11, "subi16", sub>;
122 def NEG16 : CSKYPseudo<(outs mGPR:$rd), (ins mGPR:$rx), "neg16 $rd, $rx", []>;
125 def RSUBI16 : CSKYPseudo<(outs mGPR:$rd),
126 (ins mGPR:$rx, uimm8:$imm8), "rsubi16 $rd, $rx, $imm8", []>;
128 //===----------------------------------------------------------------------===//
129 // Load & Store instructions.
130 //===----------------------------------------------------------------------===//
132 def LD16B : I16_XZ_LDST<AddrMode16B, 0b000, "ld16.b",
133 (outs mGPR:$rz), (ins mGPR:$rx, uimm5:$imm)>;
134 def LD16H : I16_XZ_LDST<AddrMode16H, 0b001, "ld16.h",
135 (outs mGPR:$rz), (ins mGPR:$rx, uimm5_1:$imm)>;
136 def LD16W : I16_XZ_LDST<AddrMode16W, 0b010, "ld16.w",
137 (outs mGPR:$rz), (ins mGPR:$rx, uimm5_2:$imm)>;
138 def ST16B : I16_XZ_LDST<AddrMode16B, 0b100, "st16.b",
139 (outs), (ins mGPR:$rz, mGPR:$rx, uimm5:$imm)>;
140 def ST16H : I16_XZ_LDST<AddrMode16H, 0b101, "st16.h",
141 (outs), (ins mGPR:$rz, mGPR:$rx, uimm5_1:$imm)>;
142 def ST16W : I16_XZ_LDST<AddrMode16W, 0b110, "st16.w",
143 (outs), (ins mGPR:$rz, mGPR:$rx, uimm5_2:$imm)>;
145 def LD16WSP : I16_ZSP_LDST<AddrMode16W, 0b011, "ld16.w",
146 (outs mGPR:$rz), (ins GPRSP:$sp, uimm8_2:$addr)>;
147 def ST16WSP : I16_ZSP_LDST<AddrMode16W, 0b111, "st16.w",
148 (outs), (ins mGPR:$rz, GPRSP:$sp, uimm8_2:$addr)>;
150 //===----------------------------------------------------------------------===//
151 // Compare instructions.
152 //===----------------------------------------------------------------------===//
154 def CMPHS16 : R16_XY_CMP<0, "cmphs16">;
155 def CMPLT16 : R16_XY_CMP<1, "cmplt16">;
156 let isCommutable = 1 in
157 def CMPNE16 : R16_XY_CMP<2, "cmpne16">;
160 def CMPHSI16 : I16_X_CMP<0, "cmphsi16", oimm5>;
161 def CMPLTI16 : I16_X_CMP<1, "cmplti16", oimm5>;
162 def CMPLEI16 : CSKYPseudo<(outs CARRY:$ca), (ins mGPR:$rx, uimm5:$imm5),
163 "cmplei16\t$rx, $imm5", []>;
164 def CMPNEI16 : I16_X_CMP<2, "cmpnei16", uimm5>;
166 //===----------------------------------------------------------------------===//
167 // Data move instructions.
168 //===----------------------------------------------------------------------===//
171 def MOVI16 : I16_Z_8<0b110, (ins uimm8:$imm8), "movi16\t$rz, $imm8"> {
172 let isReMaterializable = 1;
173 let isAsCheapAsAMove = 1;
175 let Pattern = [(set mGPR:$rz, uimm8:$imm8)];
178 def MOV16 : CSKY16Inst<AddrModeNone, (outs sGPR:$rz), (ins sGPR:$rx),
179 "mov16\t$rz, $rx", []> {
182 let Inst{15,14} = 0b01;
183 let Inst{13 - 10} = 0b1011;
184 let Inst{9 - 6} = rz;
185 let Inst{5 - 2} = rx;
186 let Inst{1,0} = 0b11;
189 // MVC16 is not in "cskyv2 instructions reference manul"
190 def MVCV16 : CSKY16Inst<AddrModeNone,
191 (outs sGPR:$rz), (ins CARRY:$ca), "mvcv16\t$rz", []> {
193 let Inst{15,14} = 0b01;
194 let Inst{13 - 10} = 0b1001;
195 let Inst{9 - 6} = rz;
197 let Inst{1,0} = 0b11;
201 //===----------------------------------------------------------------------===//
202 // Branch and call instructions.
203 //===----------------------------------------------------------------------===//
205 let isBranch = 1, isTerminator = 1 in {
206 let isBarrier = 1, isPredicable = 1 in
207 def BR16 : J16<1, "br16", (ins br_symbol_16bit:$offset)>;
209 def BT16 : J16_B<2, "bt16">;
210 def BF16 : J16_B<3, "bf16">;
213 def JMP16 : R16_X_J<0b11100000, 0b00, "jmp16"> {
215 let isTerminator = 1;
217 let isIndirectBranch = 1;
218 let Pattern = [(brind sGPR:$rx)];
221 def JSR16 : R16_X_J<0b11101111, 0b01, "jsr16"> {
226 def RTS16 : CSKY16Inst<AddrModeNone, (outs), (ins), "rts16", [(CSKY_RET)]> {
227 let isTerminator = 1;
230 let Inst = 0b0111100000111100;
232 let isCodeGenOnly = 1;
235 def JMPIX16 : CSKY16Inst<AddrModeNone, (outs),
236 (ins mGPR:$rx, uimm2_jmpix:$indeximm2), "jmpix16\t$rx, $indeximm2", []> {
239 let Inst{15,14} = 0b00;
240 let Inst{13 - 11} = 0b111;
241 let Inst{10 - 8} = rx;
242 let Inst{7 - 2} = 0b111000;
243 let Inst{1,0} = indeximm2;
244 let Predicates = [HasJAVA];
248 //===----------------------------------------------------------------------===//
249 // Symbol address instructions.
250 //===----------------------------------------------------------------------===//
252 def LRW16 : CSKY16Inst<AddrModeNone, (outs mGPR:$rz),
253 (ins constpool_symbol_16bit:$label), "lrw16\t$rz, $label", []> {
256 let Inst{15 - 13} = 0b000;
257 let Inst{12} = label{7};
258 let Inst{11,10} = 0b00;
259 let Inst{9,8} = label{6,5};
260 let Inst{7 - 5} = rz;
261 let Inst{4 - 0} = label{4-0};
266 def LRW16_Gen : CSKY16Inst<AddrModeNone, (outs mGPR:$rz),
267 (ins bare_symbol:$src, constpool_symbol_16bit:$label),
268 "lrw16\t$rz, $label", []> {
271 let Inst{15 - 13} = 0b000;
272 let Inst{12} = label{7};
273 let Inst{11,10} = 0b00;
274 let Inst{9,8} = label{6,5};
275 let Inst{7 - 5} = rz;
276 let Inst{4 - 0} = label{4-0};
279 let isCodeGenOnly = 1;
283 //===----------------------------------------------------------------------===//
284 // Other operation instructions.
285 //===----------------------------------------------------------------------===//
287 def REVB16 : R16_XZ_UNOP<0b1110, 0b10, "revb16">;
288 def REVH16 : R16_XZ_UNOP<0b1110, 0b11, "revh16">;
290 let isCodeGenOnly = 1 in
291 def SETC16 : CSKY16Inst<AddrModeNone,
292 (outs CARRY:$ca), (ins), "setc16", []> {
293 let Inst{15, 14} = 0b01;
294 let Inst{13 - 10} = 0b1001;
301 let isCodeGenOnly = 1 in
302 def CLRC16 : CSKY16Inst<AddrModeNone,
303 (outs CARRY:$ca), (ins), "clrc16", []> {
304 let Inst{15, 14} = 0b01;
305 let Inst{13 - 10} = 0b1001;
312 let Constraints = "$rZ = $rz" in {
313 def BCLRI16 : I16_Z_5<0b100, (outs mGPR:$rz), (ins mGPR:$rZ, uimm5:$imm5),
315 def BSETI16 : I16_Z_5<0b101, (outs mGPR:$rz), (ins mGPR:$rZ, uimm5:$imm5),
319 let Predicates = [HasBTST16] in
320 def BTSTI16 : I16_Z_5<0b110, (outs CARRY:$ca), (ins mGPR:$rz, uimm5:$imm5),
323 def TST16 : CSKY16Inst<AddrModeNone, (outs CARRY:$ca), (ins sGPR:$rx, sGPR:$ry),
324 "tst16\t$rx, $ry", []> {
327 let Inst{15,14} = 0b01;
328 let Inst{13 - 10} = 0b1010;
329 let Inst{9 - 6} = ry;
330 let Inst{5 - 2} = rx;
331 let Inst{1,0} = 0b10;
335 def TSTNBZ16 : CSKY16Inst<AddrModeNone, (outs CARRY:$ca), (ins sGPR:$rx),
336 "tstnbz16\t$rx", []> {
338 let Inst{15,14} = 0b01;
339 let Inst{13 - 10} = 0b1010;
340 let Inst{9 - 6} = 0b0000;
341 let Inst{5 - 2} = rx;
342 let Inst{1,0} = 0b11;
346 //===----------------------------------------------------------------------===//
347 // Special instructions.
348 //===----------------------------------------------------------------------===//
350 def BKPT : CSKY16Inst<AddrModeNone, (outs), (ins), "bkpt", []> {
354 let mayStore = 1 in {
355 def BPUSHH : I16_BPushPop<0b00010100111, 0, (outs), (ins mGPR:$rz), "bpush.h $rz">;
356 def BPUSHW : I16_BPushPop<0b00010100111, 0b10, (outs), (ins mGPR:$rz), "bpush.w $rz">;
360 def BPOPH : I16_BPushPop<0b00010100101, 0, (outs mGPR:$rz), (ins), "bpop.h $rz">;
361 def BPOPW : I16_BPushPop<0b00010100101, 0b10, (outs mGPR:$rz), (ins), "bpop.w $rz">;
364 def NIE : CSKY16Inst<AddrModeNone, (outs), (ins), "nie", [(CSKY_NIE)]> {
365 let Inst = 0b0001010001100000;
368 let isBarrier = 1, isReturn = 1, isTerminator = 1 in
369 def NIR : CSKY16Inst<AddrModeNone, (outs), (ins), "nir", [(CSKY_NIR)]> {
370 let Inst = 0b0001010001100001;
373 def IPUSH16 : CSKY16Inst<AddrModeNone, (outs), (ins), "ipush16", []> {
374 let Inst{15- 5} = 0b00010100011;
375 let Inst{4-0} = 0b00010;
376 let Predicates = [iHasE1];
378 let Uses = [R14, R0, R1, R2, R3, R12, R13];
382 def IPOP16 : CSKY16Inst<AddrModeNone, (outs), (ins), "ipop16", []> {
383 let Inst{15- 5} = 0b00010100011;
384 let Inst{4-0} = 0b00011;
385 let Predicates = [iHasE1];
386 let Defs = [R14, R0, R1, R2, R3, R12, R13];
391 def PUSH16 : CSKY16Inst<AddrModeNone, (outs),
392 (ins reglist:$regs, variable_ops), "push16 $regs", []> {
395 let Inst{15- 5} = 0b00010100110;
396 let Inst{4-0} = regs;
397 let Predicates = [iHasE1];
403 def POP16 : CSKY16Inst<AddrModeNone, (outs),
404 (ins reglist:$regs, variable_ops), "pop16 $regs", []> {
407 let Inst{15- 5} = 0b00010100100;
408 let Inst{4-0} = regs;
409 let Predicates = [iHasE1];
415 //===----------------------------------------------------------------------===//
417 //===----------------------------------------------------------------------===//
419 let usesCustomInserter = 1 in {
420 def ISEL16 : CSKYPseudo<(outs sGPR:$dst),
421 (ins CARRY:$cond, sGPR:$src1, sGPR:$src2),
422 "!isel16\t$dst, $src1, src2",
423 [(set sGPR:$dst, (select CARRY:$cond, sGPR:$src1, sGPR:$src2))]>;
426 class JBranchPseudo<dag out, dag ins, string opstr> :
427 CSKYPseudo<out, ins, opstr, []> {
429 let isTerminator = 1;
430 let isIndirectBranch = 1;
436 def JBR16 : JBranchPseudo<(outs),
437 (ins br_symbol_16bit:$src1), "jbr16\t$src1">;
438 def JBT16 : JBranchPseudo<(outs),
439 (ins CARRY:$ca, br_symbol_16bit:$src1), "jbt16\t$src1">;
440 def JBF16 : JBranchPseudo<(outs),
441 (ins CARRY:$ca, br_symbol_16bit:$src1), "jbf16\t$src1">;
443 let mayLoad = 1, Size = 2, isCodeGenOnly = 0 in
444 def PseudoLRW16 : CSKYPseudo<(outs mGPR:$rz),
445 (ins bare_symbol:$src), "lrw16 $rz, $src", []>;
447 //===----------------------------------------------------------------------===//
448 // Instruction Patterns.
449 //===----------------------------------------------------------------------===//
451 def : Pat<(sext_inreg mGPR:$src, i1), (ASRI16 (LSLI16 mGPR:$src, 7), 7)>;
452 def : Pat<(sext_inreg sGPR:$src, i8), (SEXTB16 sGPR:$src)>;
453 def : Pat<(sext_inreg sGPR:$src, i16), (SEXTH16 sGPR:$src)>;
455 // Load & Store Patterns
457 defm : LdPat<extloadi8, uimm5, LD16B, i32>;
458 defm : LdPat<zextloadi8, uimm5, LD16B, i32>;
460 defm : LdPat<extloadi16, uimm5_1, LD16H, i32>;
461 defm : LdPat<zextloadi16, uimm5_1, LD16H, i32>;
463 defm : LdPat<load, uimm5_2, LD16W, i32>;
466 defm : StPat<truncstorei8, i32, uimm5, ST16B>;
467 defm : StPat<truncstorei16, i32, uimm5_1, ST16H>;
468 defm : StPat<store, i32, uimm5_2, ST16W>;
470 def : Pat<(CSKY_CALLReg sGPR:$src), (JSR16 sGPR:$src)>;
471 def : Pat<(CSKY_TAILReg sGPR:$src), (JMP16 sGPR:$src)>;
473 // Symbol address Patterns
474 def : Pat<(CSKY_LOAD_ADDR tglobaladdr, tconstpool:$src2), (LRW16 tconstpool:$src2)>;
475 def : Pat<(CSKY_LOAD_ADDR tblockaddress, tconstpool:$src2), (LRW16 tconstpool:$src2)>;
476 def : Pat<(CSKY_LOAD_ADDR tjumptable:$src1, tconstpool:$src2), (LRW16_Gen tjumptable:$src1, tconstpool:$src2)>;
477 def : Pat<(CSKY_LOAD_ADDR texternalsym, tconstpool:$src2), (LRW16 tconstpool:$src2)>;
478 def : Pat<(CSKY_LOAD_ADDR tconstpool:$src1, tconstpool:$src2), (LRW16_Gen tconstpool:$src1, tconstpool:$src2)>;
480 def : Pat<(i32 (load constpool:$src)), (LRW16 (to_tconstpool tconstpool:$src))>;
484 def : Pat<(brcond CARRY:$ca, bb:$offset),
485 (BT16 CARRY:$ca, bb:$offset)>;
487 def : Pat<(br bb:$offset), (BR16 bb:$offset)>;
489 multiclass BTF16Pat0<PatFrag cond0, PatFrag cond1, ImmLeaf imm_ty, Instruction inst> {
490 def : Pat<(brcond (i32 (cond0 mGPR:$rs1, imm_ty:$rs2)), bb:$offset),
491 (BT16 (inst mGPR:$rs1, imm_ty:$rs2), bb:$offset)>;
492 def : Pat<(brcond (i32 (cond1 mGPR:$rs1, imm_ty:$rs2)), bb:$offset),
493 (BF16 (inst mGPR:$rs1, imm_ty:$rs2), bb:$offset)>;
496 defm : BTF16Pat0<setne, seteq, uimm5, CMPNEI16>;
497 defm : BTF16Pat0<setuge, setult, oimm5, CMPHSI16>;
498 defm : BTF16Pat0<setlt, setge, oimm5, CMPLTI16>;
500 def : Pat<(brcond (i32 (setne sGPR:$rs1, sGPR:$rs2)), bb:$offset),
501 (BT16 (CMPNE16 sGPR:$rs1, sGPR:$rs2), bb:$offset)>;
502 def : Pat<(brcond (i32 (seteq sGPR:$rs1, sGPR:$rs2)), bb:$offset),
503 (BF16 (CMPNE16 sGPR:$rs1, sGPR:$rs2), bb:$offset)>;
505 multiclass BTF16Pat1<PatFrag cond0, PatFrag cond1, Instruction cmp,
507 def : Pat<(brcond (i32 (cond0 sGPR:$rs1, sGPR:$rs2)), bb:$offset),
508 (br (cmp sGPR:$rs1, sGPR:$rs2), bb:$offset)>;
509 def : Pat<(brcond (i32 (cond1 sGPR:$rs1, sGPR:$rs2)), bb:$offset),
510 (br (cmp sGPR:$rs2, sGPR:$rs1), bb:$offset)>;
513 defm : BTF16Pat1<setuge, setule, CMPHS16, BT16>;
514 defm : BTF16Pat1<setult, setugt, CMPHS16, BF16>;
515 defm : BTF16Pat1<setlt, setgt, CMPLT16, BT16>;
516 defm : BTF16Pat1<setge, setle, CMPLT16, BF16>;
519 def : Pat<(setne sGPR:$rs1, sGPR:$rs2),
520 (SUBU16XZ (MOVI16 1), (MVCV16 (CMPNE16 sGPR:$rs1, sGPR:$rs2)))>;
521 def : Pat<(seteq sGPR:$rs1, sGPR:$rs2),
522 (MVCV16 (CMPNE16 sGPR:$rs1, sGPR:$rs2))>;
523 def : Pat<(setuge sGPR:$rs1, sGPR:$rs2),
524 (SUBU16XZ (MOVI16 1), (MVCV16 (CMPHS16 sGPR:$rs1, sGPR:$rs2)))>;
525 def : Pat<(setule sGPR:$rs1, sGPR:$rs2),
526 (SUBU16XZ (MOVI16 1), (MVCV16 (CMPHS16 sGPR:$rs2, sGPR:$rs1)))>;
527 def : Pat<(setult sGPR:$rs1, sGPR:$rs2),
528 (MVCV16 (CMPHS16 sGPR:$rs1, sGPR:$rs2))>;
529 def : Pat<(setugt sGPR:$rs1, sGPR:$rs2),
530 (MVCV16 (CMPHS16 sGPR:$rs2, sGPR:$rs1))>;
531 def : Pat<(setlt sGPR:$rs1, sGPR:$rs2),
532 (SUBU16XZ (MOVI16 1), (MVCV16 (CMPLT16 sGPR:$rs1, sGPR:$rs2)))>;
533 def : Pat<(setgt sGPR:$rs1, sGPR:$rs2),
534 (SUBU16XZ (MOVI16 1), (MVCV16 (CMPLT16 sGPR:$rs2, sGPR:$rs1)))>;
535 def : Pat<(setge sGPR:$rs1, sGPR:$rs2),
536 (MVCV16 (CMPLT16 sGPR:$rs1, sGPR:$rs2))>;
537 def : Pat<(setle sGPR:$rs1, sGPR:$rs2),
538 (MVCV16 (CMPLT16 sGPR:$rs2, sGPR:$rs1))>;
541 def : Pat<(setne mGPR:$rs1, uimm5:$rs2),
542 (SUBU16XZ (MOVI16 1), (MVCV16 (CMPNEI16 mGPR:$rs1, uimm5:$rs2)))>;
543 def : Pat<(seteq mGPR:$rs1, uimm5:$rs2),
544 (MVCV16 (CMPNEI16 mGPR:$rs1, uimm5:$rs2))>;
545 def : Pat<(setuge mGPR:$rs1, oimm5:$rs2),
546 (SUBU16XZ (MOVI16 1), (MVCV16 (CMPHSI16 mGPR:$rs1, oimm5:$rs2)))>;
547 def : Pat<(setult mGPR:$rs1, oimm5:$rs2),
548 (MVCV16 (CMPHSI16 mGPR:$rs1, oimm5:$rs2))>;
549 def : Pat<(setlt mGPR:$rs1, oimm5:$rs2),
550 (SUBU16XZ (MOVI16 1), (MVCV16 (CMPLTI16 mGPR:$rs1, oimm5:$rs2)))>;
551 def : Pat<(setge mGPR:$rs1, oimm5:$rs2),
552 (MVCV16 (CMPLTI16 mGPR:$rs1, oimm5:$rs2))>;
554 def : Pat<(select CARRY:$ca, sGPR:$rx, sGPR:$false),
555 (ISEL16 CARRY:$ca, sGPR:$rx, sGPR:$false)>;
556 def : Pat<(select (and CARRY:$ca, 1), sGPR:$rx, sGPR:$false),
557 (ISEL16 CARRY:$ca, sGPR:$rx, sGPR:$false)>;
559 def : Pat<(rotl sGPR:$rs1, sGPR:$rs2),
560 (ROTL16 sGPR:$rs1, (AND16 sGPR:$rs2, (MOVI16 0x1f)))>;
563 // FIXME: This is a temporary treatment for the e801.
564 def : Pat<(i32 imm:$imm),
565 (OR16 (MOVI16 (uimm8SRL_0 imm:$imm)),
566 (OR16 (LSLI16 (MOVI16 (uimm8SRL_8 imm:$imm)), 8),
567 (OR16 (LSLI16 (MOVI16 (uimm8SRL_16 imm:$imm)), 16),
568 (LSLI16 (MOVI16 (uimm8SRL_24 imm:$imm)), 24))))>;
571 let Predicates = [iHasE2] in {
572 def : Pat<(bswap sGPR:$rx), (REVB16 sGPR:$rx)>;
575 //===----------------------------------------------------------------------===//
576 // Compress Instruction tablegen backend.
577 //===----------------------------------------------------------------------===//
579 def : CompressPat<(ADDU32 sGPR:$rd, sGPR:$rd, sGPR:$rs2),
580 (ADDU16XZ sGPR:$rd, sGPR:$rs2)>;
581 def : CompressPat<(ADDU32 sGPR:$rd, sGPR:$rs1, sGPR:$rd),
582 (ADDU16XZ sGPR:$rd, sGPR:$rs1)>;
583 def : CompressPat<(ADDU32 mGPR:$rd, mGPR:$rs1, mGPR:$rs2),
584 (ADDU16 mGPR:$rd, mGPR:$rs1, mGPR:$rs2)>;
585 def : CompressPat<(SUBU32 sGPR:$rd, sGPR:$rd, sGPR:$rs2),
586 (SUBU16XZ sGPR:$rd, sGPR:$rs2)>;
587 def : CompressPat<(SUBU32 mGPR:$rd, mGPR:$rs1, mGPR:$rs2),
588 (SUBU16 mGPR:$rd, mGPR:$rs1, mGPR:$rs2)>;
591 (ADDC32 sGPR:$rd, CARRY:$cout, sGPR:$rd, sGPR:$rs2, CARRY:$cout),
592 (ADDC16 sGPR:$rd, CARRY:$cout, sGPR:$rs2, CARRY:$cout)
595 (SUBC32 sGPR:$rd, CARRY:$cout, sGPR:$rd, sGPR:$rs2, CARRY:$cout),
596 (SUBC16 sGPR:$rd, CARRY:$cout, sGPR:$rs2, CARRY:$cout)
599 def : CompressPat<(ADDI32 mGPR:$rd, mGPR:$rs, oimm3:$imm),
600 (ADDI16XZ mGPR:$rd, mGPR:$rs, oimm3:$imm)>;
601 def : CompressPat<(SUBI32 mGPR:$rd, mGPR:$rs, oimm3:$imm),
602 (SUBI16XZ mGPR:$rd, mGPR:$rs, oimm3:$imm)>;
604 def : CompressPat<(ADDI32 mGPR:$rd, mGPR:$rd, oimm8:$imm),
605 (ADDI16 mGPR:$rd, oimm8:$imm)>;
606 def : CompressPat<(SUBI32 mGPR:$rd, mGPR:$rd, oimm8:$imm),
607 (SUBI16 mGPR:$rd, oimm8:$imm)>;
609 def : CompressPat<(ADDI32 GPRSP:$sp, GPRSP:$sp, uimm7_2:$imm),
610 (ADDI16SPSP GPRSP:$sp, GPRSP:$sp, uimm7_2:$imm)>;
611 def : CompressPat<(SUBI32 GPRSP:$sp, GPRSP:$sp, uimm7_2:$imm),
612 (SUBI16SPSP GPRSP:$sp, GPRSP:$sp, uimm7_2:$imm)>;
614 def : CompressPat<(ADDI32 mGPR:$rd, GPRSP:$sp, uimm8_2:$imm),
615 (ADDI16ZSP mGPR:$rd, GPRSP:$sp, uimm8_2:$imm)>;
617 def : CompressPat<(MULT32 sGPR:$rd, sGPR:$rd, sGPR:$rs2),
618 (MULT16 sGPR:$rd, sGPR:$rs2)>;
619 def : CompressPat<(MULT32 sGPR:$rd, sGPR:$rs1, sGPR:$rd),
620 (MULT16 sGPR:$rd, sGPR:$rs1)>;
621 def : CompressPat<(AND32 sGPR:$rd, sGPR:$rd, sGPR:$rs2),
622 (AND16 sGPR:$rd, sGPR:$rs2)>;
623 def : CompressPat<(AND32 sGPR:$rd, sGPR:$rs1, sGPR:$rd),
624 (AND16 sGPR:$rd, sGPR:$rs1)>;
625 def : CompressPat<(OR32 sGPR:$rd, sGPR:$rd, sGPR:$rs2),
626 (OR16 sGPR:$rd, sGPR:$rs2)>;
627 def : CompressPat<(OR32 sGPR:$rd, sGPR:$rs1, sGPR:$rd),
628 (OR16 sGPR:$rd, sGPR:$rs1)>;
629 def : CompressPat<(XOR32 sGPR:$rd, sGPR:$rd, sGPR:$rs2),
630 (XOR16 sGPR:$rd, sGPR:$rs2)>;
631 def : CompressPat<(XOR32 sGPR:$rd, sGPR:$rs1, sGPR:$rd),
632 (XOR16 sGPR:$rd, sGPR:$rs1)>;
634 def : CompressPat<(ANDN32 sGPR:$rd, sGPR:$rd, sGPR:$rs2),
635 (ANDN16 sGPR:$rd, sGPR:$rs2)>;
636 def : CompressPat<(NOR32 sGPR:$rd, sGPR:$rd, sGPR:$rs2),
637 (NOR16 sGPR:$rd, sGPR:$rs2)>;
638 def : CompressPat<(LSL32 sGPR:$rd, sGPR:$rd, sGPR:$rs2),
639 (LSL16 sGPR:$rd, sGPR:$rs2)>;
640 def : CompressPat<(LSR32 sGPR:$rd, sGPR:$rd, sGPR:$rs2),
641 (LSR16 sGPR:$rd, sGPR:$rs2)>;
642 def : CompressPat<(ASR32 sGPR:$rd, sGPR:$rd, sGPR:$rs2),
643 (ASR16 sGPR:$rd, sGPR:$rs2)>;
644 def : CompressPat<(ROTL32 sGPR:$rd, sGPR:$rd, sGPR:$rs2),
645 (ROTL16 sGPR:$rd, sGPR:$rs2)>;
647 def : CompressPat<(NOT32 sGPR:$rd, sGPR:$rd),
650 let Predicates = [iHas2E3] in
651 def : CompressPat<(REVB32 sGPR:$rd, sGPR:$rs),
652 (REVB16 sGPR:$rd, sGPR:$rs)>;
654 def : CompressPat<(LSLI32 mGPR:$rd, mGPR:$rs, uimm5:$imm),
655 (LSLI16 mGPR:$rd, mGPR:$rs, uimm5:$imm)>;
656 def : CompressPat<(LSRI32 mGPR:$rd, mGPR:$rs, uimm5:$imm),
657 (LSRI16 mGPR:$rd, mGPR:$rs, uimm5:$imm)>;
658 def : CompressPat<(ASRI32 mGPR:$rd, mGPR:$rs, uimm5:$imm),
659 (ASRI16 mGPR:$rd, mGPR:$rs, uimm5:$imm)>;
661 def : CompressPat<(CMPHS32 CARRY:$ca, sGPR:$rs1, sGPR:$rs2),
662 (CMPHS16 CARRY:$ca, sGPR:$rs1, sGPR:$rs2)>;
663 def : CompressPat<(CMPLT32 CARRY:$ca, sGPR:$rs1, sGPR:$rs2),
664 (CMPLT16 CARRY:$ca, sGPR:$rs1, sGPR:$rs2)>;
665 def : CompressPat<(CMPNE32 CARRY:$ca, sGPR:$rs1, sGPR:$rs2),
666 (CMPNE16 CARRY:$ca, sGPR:$rs1, sGPR:$rs2)>;
668 def : CompressPat<(CMPHSI32 CARRY:$ca, mGPR:$rs, oimm5:$imm),
669 (CMPHSI16 CARRY:$ca, mGPR:$rs, oimm5:$imm)>;
670 def : CompressPat<(CMPLTI32 CARRY:$ca, mGPR:$rs, oimm5:$imm),
671 (CMPLTI16 CARRY:$ca, mGPR:$rs, oimm5:$imm)>;
672 def : CompressPat<(CMPNEI32 CARRY:$ca, mGPR:$rs, uimm5:$imm),
673 (CMPNEI16 CARRY:$ca, mGPR:$rs, uimm5:$imm)>;
675 def : CompressPat<(JSR32 sGPR:$rd),
679 def : CompressPat<(MVCV32 sGPR:$rd, CARRY:$ca),
680 (MVCV16 sGPR:$rd, CARRY:$ca)>;
681 def : CompressPat<(MOV32 sGPR:$rd, sGPR:$ca),
682 (MOV16 sGPR:$rd, sGPR:$ca)>;
683 def : CompressPat<(MOVI32 mGPR:$rd, uimm8:$imm),
684 (MOVI16 mGPR:$rd, uimm8:$imm)>;
686 def : CompressPat<(LD32B mGPR:$rd, mGPR:$rs, uimm5:$imm),
687 (LD16B mGPR:$rd, mGPR:$rs, uimm5:$imm)>;
688 def : CompressPat<(LD32H mGPR:$rd, mGPR:$rs, uimm5_1:$imm),
689 (LD16H mGPR:$rd, mGPR:$rs, uimm5_1:$imm)>;
690 def : CompressPat<(LD32W mGPR:$rd, mGPR:$rs, uimm5_2:$imm),
691 (LD16W mGPR:$rd, mGPR:$rs, uimm5_2:$imm)>;
692 def : CompressPat<(LD32W mGPR:$rd, GPRSP:$sp, uimm8_2:$imm),
693 (LD16WSP mGPR:$rd, GPRSP:$sp, uimm8_2:$imm)>;
695 def : CompressPat<(ST32B mGPR:$rd, mGPR:$rs, uimm5:$imm),
696 (ST16B mGPR:$rd, mGPR:$rs, uimm5:$imm)>;
697 def : CompressPat<(ST32H mGPR:$rd, mGPR:$rs, uimm5_1:$imm),
698 (ST16H mGPR:$rd, mGPR:$rs, uimm5_1:$imm)>;
699 def : CompressPat<(ST32W mGPR:$rd, mGPR:$rs, uimm5_2:$imm),
700 (ST16W mGPR:$rd, mGPR:$rs, uimm5_2:$imm)>;
701 def : CompressPat<(ST32W mGPR:$rd, GPRSP:$sp, uimm8_2:$imm),
702 (ST16WSP mGPR:$rd, GPRSP:$sp, uimm8_2:$imm)>;
704 let Predicates = [HasBTST16] in
705 def : CompressPat<(BTSTI32 CARRY:$ca, mGPR:$rs, uimm5:$imm),
706 (BTSTI16 CARRY:$ca, mGPR:$rs, uimm5:$imm)>;
707 def : CompressPat<(BCLRI32 mGPR:$rd, mGPR:$rd, uimm5:$imm),
708 (BCLRI16 mGPR:$rd, uimm5:$imm)>;
709 def : CompressPat<(BSETI32 mGPR:$rd, mGPR:$rd, uimm5:$imm),
710 (BSETI16 mGPR:$rd, uimm5:$imm)>;
712 def : CompressPat<(ZEXTB32 sGPR:$rd, sGPR:$rs),
713 (ZEXTB16 sGPR:$rd, sGPR:$rs)>;
714 def : CompressPat<(ZEXTH32 sGPR:$rd, sGPR:$rs),
715 (ZEXTH16 sGPR:$rd, sGPR:$rs)>;
716 def : CompressPat<(SEXTB32 sGPR:$rd, sGPR:$rs),
717 (SEXTB16 sGPR:$rd, sGPR:$rs)>;
718 def : CompressPat<(SEXTH32 sGPR:$rd, sGPR:$rs),
719 (SEXTH16 sGPR:$rd, sGPR:$rs)>;