blob: 5729182deafb438772c9d1f3e9e7ccef053ceeaf [file] [log] [blame]
Akira Hatanaka7d7ee0c2011-09-24 01:40:18 +00001//===- Mips64InstrInfo.td - Mips64 Instruction Information -*- 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 Mips64 instructions.
11//
12//===----------------------------------------------------------------------===//
Akira Hatanakac1179672011-09-28 17:50:27 +000013
14//===----------------------------------------------------------------------===//
Akira Hatanaka7769a772011-09-30 02:08:54 +000015// Mips Operand, Complex Patterns and Transformations Definitions.
16//===----------------------------------------------------------------------===//
17
Akira Hatanaka2a232d82011-12-19 19:44:09 +000018// shamt must fit in 6 bits.
19def immZExt6 : ImmLeaf<i32, [{return Imm == (Imm & 0x3f);}]>;
Akira Hatanaka61e256a2011-09-30 03:18:46 +000020
Kai Nacke6da86e82014-04-04 16:21:59 +000021// Node immediate fits as 10-bit sign extended on target immediate.
22// e.g. seqi, snei
23def immSExt10_64 : PatLeaf<(i64 imm),
24 [{ return isInt<10>(N->getSExtValue()); }]>;
25
Daniel Sanders0fa60412014-06-12 13:39:06 +000026def immZExt16_64 : PatLeaf<(i64 imm),
Simon Dardis5676d062016-04-22 13:19:22 +000027 [{ return isUInt<16>(N->getZExtValue()); }]>;
Daniel Sanders0fa60412014-06-12 13:39:06 +000028
Kai Nacke63072f82015-01-20 16:10:51 +000029def immZExt5_64 : ImmLeaf<i64, [{ return Imm == (Imm & 0x1f); }]>;
30
31// Transformation function: get log2 of low 32 bits of immediate
32def Log2LO : SDNodeXForm<imm, [{
33 return getImm(N, Log2_64((unsigned) N->getZExtValue()));
34}]>;
35
36// Transformation function: get log2 of high 32 bits of immediate
37def Log2HI : SDNodeXForm<imm, [{
38 return getImm(N, Log2_64((unsigned) (N->getZExtValue() >> 32)));
39}]>;
40
41// Predicate: True if immediate is a power of 2 and fits 32 bits
42def PowerOf2LO : PatLeaf<(imm), [{
43 if (N->getValueType(0) == MVT::i64) {
44 uint64_t Imm = N->getZExtValue();
45 return isPowerOf2_64(Imm) && (Imm & 0xffffffff) == Imm;
46 }
47 else
48 return false;
49}]>;
50
51// Predicate: True if immediate is a power of 2 and exceeds 32 bits
52def PowerOf2HI : PatLeaf<(imm), [{
53 if (N->getValueType(0) == MVT::i64) {
54 uint64_t Imm = N->getZExtValue();
55 return isPowerOf2_64(Imm) && (Imm & 0xffffffff00000000) == Imm;
56 }
57 else
58 return false;
59}]>;
60
Strahinja Petrovic89df7972017-08-30 11:25:38 +000061def PowerOf2LO_i32 : PatLeaf<(imm), [{
62 if (N->getValueType(0) == MVT::i32) {
63 uint64_t Imm = N->getZExtValue();
64 return isPowerOf2_32(Imm) && isUInt<32>(Imm);
65 }
66 else
67 return false;
68}]>;
69
Vasileios Kalintiris3751d412016-04-13 15:07:45 +000070def assertzext_lt_i32 : PatFrag<(ops node:$src), (assertzext node:$src), [{
71 return cast<VTSDNode>(N->getOperand(1))->getVT().bitsLT(MVT::i32);
72}]>;
73
Akira Hatanaka7769a772011-09-30 02:08:54 +000074//===----------------------------------------------------------------------===//
Akira Hatanaka36036412011-09-29 20:37:56 +000075// Instructions specific format
76//===----------------------------------------------------------------------===//
Akira Hatanaka6781fc12013-08-20 21:08:22 +000077let usesCustomInserter = 1 in {
78 def ATOMIC_LOAD_ADD_I64 : Atomic2Ops<atomic_load_add_64, GPR64>;
79 def ATOMIC_LOAD_SUB_I64 : Atomic2Ops<atomic_load_sub_64, GPR64>;
80 def ATOMIC_LOAD_AND_I64 : Atomic2Ops<atomic_load_and_64, GPR64>;
81 def ATOMIC_LOAD_OR_I64 : Atomic2Ops<atomic_load_or_64, GPR64>;
82 def ATOMIC_LOAD_XOR_I64 : Atomic2Ops<atomic_load_xor_64, GPR64>;
83 def ATOMIC_LOAD_NAND_I64 : Atomic2Ops<atomic_load_nand_64, GPR64>;
84 def ATOMIC_SWAP_I64 : Atomic2Ops<atomic_swap_64, GPR64>;
85 def ATOMIC_CMP_SWAP_I64 : AtomicCmpSwap<atomic_cmp_swap_64, GPR64>;
Akira Hatanaka21cbc252011-11-11 04:14:30 +000086}
87
Aleksandar Beserminji3239ba82018-07-05 09:27:05 +000088def ATOMIC_LOAD_ADD_I64_POSTRA : Atomic2OpsPostRA<GPR64>;
89def ATOMIC_LOAD_SUB_I64_POSTRA : Atomic2OpsPostRA<GPR64>;
90def ATOMIC_LOAD_AND_I64_POSTRA : Atomic2OpsPostRA<GPR64>;
91def ATOMIC_LOAD_OR_I64_POSTRA : Atomic2OpsPostRA<GPR64>;
92def ATOMIC_LOAD_XOR_I64_POSTRA : Atomic2OpsPostRA<GPR64>;
93def ATOMIC_LOAD_NAND_I64_POSTRA : Atomic2OpsPostRA<GPR64>;
94
95def ATOMIC_SWAP_I64_POSTRA : Atomic2OpsPostRA<GPR64>;
96
97def ATOMIC_CMP_SWAP_I64_POSTRA : AtomicCmpSwapPostRA<GPR64>;
98
Akira Hatanaka42543192013-04-30 23:22:09 +000099/// Pseudo instructions for loading and storing accumulator registers.
Simon Dardise661e522016-06-14 09:35:29 +0000100let isPseudo = 1, isCodeGenOnly = 1, hasNoSchedulingInfo = 1 in {
Akira Hatanaka6781fc12013-08-20 21:08:22 +0000101 def LOAD_ACC128 : Load<"", ACC128>;
102 def STORE_ACC128 : Store<"", ACC128>;
Akira Hatanakac8d85022013-03-30 00:54:52 +0000103}
104
Akira Hatanaka36036412011-09-29 20:37:56 +0000105//===----------------------------------------------------------------------===//
106// Instruction definition
107//===----------------------------------------------------------------------===//
Akira Hatanaka71928e62012-04-17 18:03:21 +0000108let DecoderNamespace = "Mips64" in {
Akira Hatanaka7769a772011-09-30 02:08:54 +0000109/// Arithmetic Instructions (ALU Immediate)
Simon Dardise661e522016-06-14 09:35:29 +0000110def DADDi : ArithLogicI<"daddi", simm16_64, GPR64Opnd, II_DADDI>,
111 ADDI_FM<0x18>, ISA_MIPS3_NOT_32R6_64R6;
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000112let AdditionalPredicates = [NotInMicroMips] in {
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000113 def DADDiu : ArithLogicI<"daddiu", simm16_64, GPR64Opnd, II_DADDIU,
114 immSExt16, add>,
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000115 ADDI_FM<0x19>, IsAsCheapAsAMove, ISA_MIPS3;
116}
Akira Hatanakac7e39982013-08-06 23:01:10 +0000117
118let isCodeGenOnly = 1 in {
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000119def SLTi64 : SetCC_I<"slti", setlt, simm16_64, immSExt16, GPR64Opnd>,
Simon Dardis1d6254f2018-06-08 10:55:34 +0000120 SLTI_FM<0xa>, GPR_64;
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000121def SLTiu64 : SetCC_I<"sltiu", setult, simm16_64, immSExt16, GPR64Opnd>,
Simon Dardis1d6254f2018-06-08 10:55:34 +0000122 SLTI_FM<0xb>, GPR_64;
Daniel Sanders306ef072014-01-16 15:57:05 +0000123def ANDi64 : ArithLogicI<"andi", uimm16_64, GPR64Opnd, II_AND, immZExt16, and>,
Simon Dardis1d6254f2018-06-08 10:55:34 +0000124 ADDI_FM<0xc>, GPR_64;
Daniel Sanders306ef072014-01-16 15:57:05 +0000125def ORi64 : ArithLogicI<"ori", uimm16_64, GPR64Opnd, II_OR, immZExt16, or>,
Simon Dardis1d6254f2018-06-08 10:55:34 +0000126 ADDI_FM<0xd>, GPR_64;
Daniel Sanders306ef072014-01-16 15:57:05 +0000127def XORi64 : ArithLogicI<"xori", uimm16_64, GPR64Opnd, II_XOR, immZExt16, xor>,
Simon Dardis1d6254f2018-06-08 10:55:34 +0000128 ADDI_FM<0xe>, GPR_64;
129def LUi64 : LoadUpper<"lui", GPR64Opnd, uimm16_64_relaxed>, LUI_FM, GPR_64;
Akira Hatanakac7e39982013-08-06 23:01:10 +0000130}
Akira Hatanaka7769a772011-09-30 02:08:54 +0000131
Akira Hatanaka36036412011-09-29 20:37:56 +0000132/// Arithmetic Instructions (3-Operand, R-Type)
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000133let AdditionalPredicates = [NotInMicroMips] in {
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000134 def DADD : ArithLogicR<"dadd", GPR64Opnd, 1, II_DADD>, ADD_FM<0, 0x2c>,
Zlatko Buljande0bbe62016-04-27 11:31:44 +0000135 ISA_MIPS3;
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000136 def DADDu : ArithLogicR<"daddu", GPR64Opnd, 1, II_DADDU, add>,
137 ADD_FM<0, 0x2d>, ISA_MIPS3;
138 def DSUBu : ArithLogicR<"dsubu", GPR64Opnd, 0, II_DSUBU, sub>,
139 ADD_FM<0, 0x2f>, ISA_MIPS3;
140 def DSUB : ArithLogicR<"dsub", GPR64Opnd, 0, II_DSUB>, ADD_FM<0, 0x2e>,
Zlatko Buljande0bbe62016-04-27 11:31:44 +0000141 ISA_MIPS3;
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000142}
Akira Hatanakae2a39e72013-08-06 22:35:29 +0000143
144let isCodeGenOnly = 1 in {
Simon Dardis1d6254f2018-06-08 10:55:34 +0000145def SLT64 : SetCC_R<"slt", setlt, GPR64Opnd>, ADD_FM<0, 0x2a>, GPR_64;
146def SLTu64 : SetCC_R<"sltu", setult, GPR64Opnd>, ADD_FM<0, 0x2b>, GPR_64;
147def AND64 : ArithLogicR<"and", GPR64Opnd, 1, II_AND, and>, ADD_FM<0, 0x24>,
148 GPR_64;
149def OR64 : ArithLogicR<"or", GPR64Opnd, 1, II_OR, or>, ADD_FM<0, 0x25>,
150 GPR_64;
151def XOR64 : ArithLogicR<"xor", GPR64Opnd, 1, II_XOR, xor>, ADD_FM<0, 0x26>,
152 GPR_64;
153def NOR64 : LogicNOR<"nor", GPR64Opnd>, ADD_FM<0, 0x27>, GPR_64;
Akira Hatanakae2a39e72013-08-06 22:35:29 +0000154}
Akira Hatanaka61e256a2011-09-30 03:18:46 +0000155
156/// Shift Instructions
Hrvoje Vargaaeb1fe82016-05-11 11:17:04 +0000157let AdditionalPredicates = [NotInMicroMips] in {
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000158 def DSLL : shift_rotate_imm<"dsll", uimm6, GPR64Opnd, II_DSLL, shl,
159 immZExt6>,
Hrvoje Vargaf1e0a032016-06-16 07:06:25 +0000160 SRA_FM<0x38, 0>, ISA_MIPS3;
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000161 def DSRL : shift_rotate_imm<"dsrl", uimm6, GPR64Opnd, II_DSRL, srl,
162 immZExt6>,
Daniel Sandersf2056be2014-05-09 13:02:27 +0000163 SRA_FM<0x3a, 0>, ISA_MIPS3;
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000164 def DSRA : shift_rotate_imm<"dsra", uimm6, GPR64Opnd, II_DSRA, sra,
165 immZExt6>,
Daniel Sandersf2056be2014-05-09 13:02:27 +0000166 SRA_FM<0x3b, 0>, ISA_MIPS3;
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000167 def DSLLV : shift_rotate_reg<"dsllv", GPR64Opnd, II_DSLLV, shl>,
Hrvoje Vargaf1e0a032016-06-16 07:06:25 +0000168 SRLV_FM<0x14, 0>, ISA_MIPS3;
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000169 def DSRAV : shift_rotate_reg<"dsrav", GPR64Opnd, II_DSRAV, sra>,
Hrvoje Vargaaeb1fe82016-05-11 11:17:04 +0000170 SRLV_FM<0x17, 0>, ISA_MIPS3;
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000171 def DSRLV : shift_rotate_reg<"dsrlv", GPR64Opnd, II_DSRLV, srl>,
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000172 SRLV_FM<0x16, 0>, ISA_MIPS3;
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000173 def DSLL32 : shift_rotate_imm<"dsll32", uimm5, GPR64Opnd, II_DSLL32>,
Hrvoje Vargaaeb1fe82016-05-11 11:17:04 +0000174 SRA_FM<0x3c, 0>, ISA_MIPS3;
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000175 def DSRL32 : shift_rotate_imm<"dsrl32", uimm5, GPR64Opnd, II_DSRL32>,
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000176 SRA_FM<0x3e, 0>, ISA_MIPS3;
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000177 def DSRA32 : shift_rotate_imm<"dsra32", uimm5, GPR64Opnd, II_DSRA32>,
Hrvoje Vargaaeb1fe82016-05-11 11:17:04 +0000178 SRA_FM<0x3f, 0>, ISA_MIPS3;
Akira Hatanakac7e39982013-08-06 23:01:10 +0000179
Akira Hatanaka7ba8a8d2011-09-30 18:51:46 +0000180// Rotate Instructions
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000181 def DROTR : shift_rotate_imm<"drotr", uimm6, GPR64Opnd, II_DROTR, rotr,
182 immZExt6>,
Hrvoje Vargaf1e0a032016-06-16 07:06:25 +0000183 SRA_FM<0x3a, 1>, ISA_MIPS64R2;
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000184 def DROTRV : shift_rotate_reg<"drotrv", GPR64Opnd, II_DROTRV, rotr>,
Hrvoje Vargaf1e0a032016-06-16 07:06:25 +0000185 SRLV_FM<0x16, 1>, ISA_MIPS64R2;
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000186 def DROTR32 : shift_rotate_imm<"drotr32", uimm5, GPR64Opnd, II_DROTR32>,
Hrvoje Vargaf1e0a032016-06-16 07:06:25 +0000187 SRA_FM<0x3e, 1>, ISA_MIPS64R2;
188}
Akira Hatanaka7ba8a8d2011-09-30 18:51:46 +0000189
Akira Hatanakabe68f3c2011-10-11 00:27:28 +0000190/// Load and Store Instructions
Jia Liuf54f60f2012-02-28 07:46:26 +0000191/// aligned
Akira Hatanakac7e39982013-08-06 23:01:10 +0000192let isCodeGenOnly = 1 in {
Simon Dardis1d6254f2018-06-08 10:55:34 +0000193def LB64 : Load<"lb", GPR64Opnd, sextloadi8, II_LB>, LW_FM<0x20>, GPR_64;
194def LBu64 : Load<"lbu", GPR64Opnd, zextloadi8, II_LBU>, LW_FM<0x24>, GPR_64;
195def LH64 : Load<"lh", GPR64Opnd, sextloadi16, II_LH>, LW_FM<0x21>, GPR_64;
196def LHu64 : Load<"lhu", GPR64Opnd, zextloadi16, II_LHU>, LW_FM<0x25>, GPR_64;
197def LW64 : Load<"lw", GPR64Opnd, sextloadi32, II_LW>, LW_FM<0x23>, GPR_64;
198def SB64 : Store<"sb", GPR64Opnd, truncstorei8, II_SB>, LW_FM<0x28>, GPR_64;
199def SH64 : Store<"sh", GPR64Opnd, truncstorei16, II_SH>, LW_FM<0x29>,
200 GPR_64;
201def SW64 : Store<"sw", GPR64Opnd, truncstorei32, II_SW>, LW_FM<0x2b>,
202 GPR_64;
Akira Hatanakac7e39982013-08-06 23:01:10 +0000203}
204
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000205let AdditionalPredicates = [NotInMicroMips] in {
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000206 def LWu : MMRel, Load<"lwu", GPR64Opnd, zextloadi32, II_LWU>,
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000207 LW_FM<0x27>, ISA_MIPS3;
Simon Atanasyan05db2792018-05-10 16:01:36 +0000208 def LD : LoadMemory<"ld", GPR64Opnd, mem_simmptr, load, II_LD>,
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000209 LW_FM<0x37>, ISA_MIPS3;
Simon Atanasyan05db2792018-05-10 16:01:36 +0000210 def SD : StoreMemory<"sd", GPR64Opnd, mem_simmptr, store, II_SD>,
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000211 LW_FM<0x3f>, ISA_MIPS3;
212}
213
214
Akira Hatanakabe68f3c2011-10-11 00:27:28 +0000215
Akira Hatanakaf11571d2012-06-02 00:04:19 +0000216/// load/store left/right
Akira Hatanakac7e39982013-08-06 23:01:10 +0000217let isCodeGenOnly = 1 in {
Simon Dardis1d6254f2018-06-08 10:55:34 +0000218def LWL64 : LoadLeftRight<"lwl", MipsLWL, GPR64Opnd, II_LWL>, LW_FM<0x22>,
219 GPR_64;
220def LWR64 : LoadLeftRight<"lwr", MipsLWR, GPR64Opnd, II_LWR>, LW_FM<0x26>,
221 GPR_64;
222def SWL64 : StoreLeftRight<"swl", MipsSWL, GPR64Opnd, II_SWL>, LW_FM<0x2a>,
223 GPR_64;
224def SWR64 : StoreLeftRight<"swr", MipsSWR, GPR64Opnd, II_SWR>, LW_FM<0x2e>,
225 GPR_64;
Akira Hatanakac7e39982013-08-06 23:01:10 +0000226}
Jack Carter873c7242013-01-12 01:03:14 +0000227
Daniel Sandersf2056be2014-05-09 13:02:27 +0000228def LDL : LoadLeftRight<"ldl", MipsLDL, GPR64Opnd, II_LDL>, LW_FM<0x1a>,
Daniel Sandersac272632014-05-23 13:18:02 +0000229 ISA_MIPS3_NOT_32R6_64R6;
Daniel Sandersf2056be2014-05-09 13:02:27 +0000230def LDR : LoadLeftRight<"ldr", MipsLDR, GPR64Opnd, II_LDR>, LW_FM<0x1b>,
Daniel Sandersac272632014-05-23 13:18:02 +0000231 ISA_MIPS3_NOT_32R6_64R6;
Daniel Sandersf2056be2014-05-09 13:02:27 +0000232def SDL : StoreLeftRight<"sdl", MipsSDL, GPR64Opnd, II_SDL>, LW_FM<0x2c>,
Daniel Sandersac272632014-05-23 13:18:02 +0000233 ISA_MIPS3_NOT_32R6_64R6;
Daniel Sandersf2056be2014-05-09 13:02:27 +0000234def SDR : StoreLeftRight<"sdr", MipsSDR, GPR64Opnd, II_SDR>, LW_FM<0x2d>,
Daniel Sandersac272632014-05-23 13:18:02 +0000235 ISA_MIPS3_NOT_32R6_64R6;
Akira Hatanakaf11571d2012-06-02 00:04:19 +0000236
Akira Hatanaka21cbc252011-11-11 04:14:30 +0000237/// Load-linked, Store-conditional
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000238let AdditionalPredicates = [NotInMicroMips] in {
Simon Atanasyan05db2792018-05-10 16:01:36 +0000239 def LLD : LLBase<"lld", GPR64Opnd, mem_simmptr>, LW_FM<0x34>,
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000240 ISA_MIPS3_NOT_32R6_64R6;
241}
Daniel Sanders6a803f62014-06-16 13:13:03 +0000242def SCD : SCBase<"scd", GPR64Opnd>, LW_FM<0x3c>, ISA_MIPS3_NOT_32R6_64R6;
Akira Hatanaka21cbc252011-11-11 04:14:30 +0000243
Simon Dardis4fbf76f2016-06-14 11:29:28 +0000244let AdditionalPredicates = [NotInMicroMips],
245 DecoderNamespace = "Mips32_64_PTR64" in {
246def LL64 : LLBase<"ll", GPR32Opnd>, LW_FM<0x30>, PTR_64,
247 ISA_MIPS2_NOT_32R6_64R6;
248def SC64 : SCBase<"sc", GPR32Opnd>, LW_FM<0x38>, PTR_64,
249 ISA_MIPS2_NOT_32R6_64R6;
Simon Dardis57f4ae42016-08-04 09:17:07 +0000250def JR64 : IndirectBranch<"jr", GPR64Opnd>, MTLO_FM<8>, PTR_64;
Simon Dardis4fbf76f2016-06-14 11:29:28 +0000251}
252
Simon Dardis57f4ae42016-08-04 09:17:07 +0000253def JALR64 : JumpLinkReg<"jalr", GPR64Opnd>, JALR_FM;
254
Akira Hatanaka4b6ac982011-10-11 18:49:17 +0000255/// Jump and Branch Instructions
Akira Hatanakac7e39982013-08-06 23:01:10 +0000256let isCodeGenOnly = 1 in {
Simon Dardis1d6254f2018-06-08 10:55:34 +0000257 def BEQ64 : CBranch<"beq", brtarget, seteq, GPR64Opnd>, BEQ_FM<4>,
258 GPR_64;
259 def BNE64 : CBranch<"bne", brtarget, setne, GPR64Opnd>, BEQ_FM<5>,
260 GPR_64;
261 def BGEZ64 : CBranchZero<"bgez", brtarget, setge, GPR64Opnd>, BGEZ_FM<1, 1>,
262 GPR_64;
263 def BGTZ64 : CBranchZero<"bgtz", brtarget, setgt, GPR64Opnd>, BGEZ_FM<7, 0>,
264 GPR_64;
265 def BLEZ64 : CBranchZero<"blez", brtarget, setle, GPR64Opnd>, BGEZ_FM<6, 0>,
266 GPR_64;
267 def BLTZ64 : CBranchZero<"bltz", brtarget, setlt, GPR64Opnd>, BGEZ_FM<1, 0>,
268 GPR_64;
Simon Dardis7bc8ad52018-02-21 00:06:53 +0000269 let AdditionalPredicates = [NoIndirectJumpGuards] in
270 def JALR64Pseudo : JumpLinkRegPseudo<GPR64Opnd, JALR, RA, GPR32Opnd>;
271}
272let AdditionalPredicates = [NotInMicroMips],
273 DecoderNamespace = "Mips64" in {
274 def JR_HB64 : JR_HB_DESC<GPR64Opnd>, JR_HB_ENC, ISA_MIPS32_NOT_32R6_64R6;
275 def JALR_HB64 : JALR_HB_DESC<GPR64Opnd>, JALR_HB_ENC, ISA_MIPS32R2;
276}
277def PseudoReturn64 : PseudoReturnBase<GPR64Opnd>;
278
279let AdditionalPredicates = [NotInMips16Mode, NotInMicroMips,
280 NoIndirectJumpGuards] in {
281 def TAILCALLREG64 : TailCallReg<JR64, GPR64Opnd>, ISA_MIPS3_NOT_32R6_64R6,
282 PTR_64;
283 def PseudoIndirectBranch64 : PseudoIndirectBranchBase<JR64, GPR64Opnd>,
284 ISA_MIPS3_NOT_32R6_64R6;
Akira Hatanaka34a32c02013-08-06 22:20:40 +0000285}
286
Simon Dardis7bc8ad52018-02-21 00:06:53 +0000287let AdditionalPredicates = [NotInMips16Mode, NotInMicroMips,
288 UseIndirectJumpsHazard] in {
289 def TAILCALLREGHB64 : TailCallReg<JR_HB64, GPR64Opnd>,
290 ISA_MIPS32R2_NOT_32R6_64R6, PTR_64;
291 def PseudoIndirectHazardBranch64 : PseudoIndirectBranchBase<JR_HB64,
292 GPR64Opnd>,
293 ISA_MIPS32R2_NOT_32R6_64R6;
294}
Daniel Sanders338513b2014-07-09 10:16:07 +0000295
Akira Hatanakaa279d9b2011-10-03 20:01:11 +0000296/// Multiply and Divide Instructions.
Zlatko Buljan31c9ebe2016-05-06 08:24:14 +0000297let AdditionalPredicates = [NotInMicroMips] in {
298 def DMULT : Mult<"dmult", II_DMULT, GPR64Opnd, [HI0_64, LO0_64]>,
299 MULT_FM<0, 0x1c>, ISA_MIPS3_NOT_32R6_64R6;
300 def DMULTu : Mult<"dmultu", II_DMULTU, GPR64Opnd, [HI0_64, LO0_64]>,
301 MULT_FM<0, 0x1d>, ISA_MIPS3_NOT_32R6_64R6;
302}
Akira Hatanaka00fcf2e2013-08-08 21:54:26 +0000303def PseudoDMULT : MultDivPseudo<DMULT, ACC128, GPR64Opnd, MipsMult,
Daniel Sanders308181e2014-06-12 10:44:10 +0000304 II_DMULT>, ISA_MIPS3_NOT_32R6_64R6;
Akira Hatanaka00fcf2e2013-08-08 21:54:26 +0000305def PseudoDMULTu : MultDivPseudo<DMULTu, ACC128, GPR64Opnd, MipsMultu,
Daniel Sanders308181e2014-06-12 10:44:10 +0000306 II_DMULTU>, ISA_MIPS3_NOT_32R6_64R6;
Zlatko Buljan58d6a952016-04-13 08:02:26 +0000307let AdditionalPredicates = [NotInMicroMips] in {
308 def DSDIV : Div<"ddiv", II_DDIV, GPR64Opnd, [HI0_64, LO0_64]>,
309 MULT_FM<0, 0x1e>, ISA_MIPS3_NOT_32R6_64R6;
310 def DUDIV : Div<"ddivu", II_DDIVU, GPR64Opnd, [HI0_64, LO0_64]>,
311 MULT_FM<0, 0x1f>, ISA_MIPS3_NOT_32R6_64R6;
312}
Akira Hatanaka00fcf2e2013-08-08 21:54:26 +0000313def PseudoDSDIV : MultDivPseudo<DSDIV, ACC128, GPR64Opnd, MipsDivRem,
Daniel Sanders308181e2014-06-12 10:44:10 +0000314 II_DDIV, 0, 1, 1>, ISA_MIPS3_NOT_32R6_64R6;
Akira Hatanaka00fcf2e2013-08-08 21:54:26 +0000315def PseudoDUDIV : MultDivPseudo<DUDIV, ACC128, GPR64Opnd, MipsDivRemU,
Daniel Sanders308181e2014-06-12 10:44:10 +0000316 II_DDIVU, 0, 1, 1>, ISA_MIPS3_NOT_32R6_64R6;
Akira Hatanakaa279d9b2011-10-03 20:01:11 +0000317
Akira Hatanakac7e39982013-08-06 23:01:10 +0000318let isCodeGenOnly = 1 in {
Daniel Sanders308181e2014-06-12 10:44:10 +0000319def MTHI64 : MoveToLOHI<"mthi", GPR64Opnd, [HI0_64]>, MTLO_FM<0x11>,
320 ISA_MIPS3_NOT_32R6_64R6;
321def MTLO64 : MoveToLOHI<"mtlo", GPR64Opnd, [LO0_64]>, MTLO_FM<0x13>,
322 ISA_MIPS3_NOT_32R6_64R6;
323def MFHI64 : MoveFromLOHI<"mfhi", GPR64Opnd, AC0_64>, MFLO_FM<0x10>,
324 ISA_MIPS3_NOT_32R6_64R6;
325def MFLO64 : MoveFromLOHI<"mflo", GPR64Opnd, AC0_64>, MFLO_FM<0x12>,
326 ISA_MIPS3_NOT_32R6_64R6;
327def PseudoMFHI64 : PseudoMFLOHI<GPR64, ACC128, MipsMFHI>,
328 ISA_MIPS3_NOT_32R6_64R6;
329def PseudoMFLO64 : PseudoMFLOHI<GPR64, ACC128, MipsMFLO>,
330 ISA_MIPS3_NOT_32R6_64R6;
331def PseudoMTLOHI64 : PseudoMTLOHI<ACC128, GPR64>, ISA_MIPS3_NOT_32R6_64R6;
Akira Hatanakacdcc7452011-10-03 19:28:44 +0000332
Akira Hatanaka9f7ec152012-01-24 21:41:09 +0000333/// Sign Ext In Register Instructions.
Daniel Sandersfcea8102014-05-12 12:28:15 +0000334def SEB64 : SignExtInReg<"seb", i8, GPR64Opnd, II_SEB>, SEB_FM<0x10, 0x20>,
335 ISA_MIPS32R2;
336def SEH64 : SignExtInReg<"seh", i16, GPR64Opnd, II_SEH>, SEB_FM<0x18, 0x20>,
337 ISA_MIPS32R2;
Akira Hatanakac7e39982013-08-06 23:01:10 +0000338}
Akira Hatanaka9f7ec152012-01-24 21:41:09 +0000339
Akira Hatanaka48a72ca2011-10-03 21:16:50 +0000340/// Count Leading
Hrvoje Vargaf1e0a032016-06-16 07:06:25 +0000341let AdditionalPredicates = [NotInMicroMips] in {
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000342 def DCLZ : CountLeading0<"dclz", GPR64Opnd, II_DCLZ>, CLO_FM<0x24>,
343 ISA_MIPS64_NOT_64R6;
344 def DCLO : CountLeading1<"dclo", GPR64Opnd, II_DCLO>, CLO_FM<0x25>,
345 ISA_MIPS64_NOT_64R6;
Akira Hatanaka48a72ca2011-10-03 21:16:50 +0000346
Akira Hatanaka4706ac92011-12-20 23:56:43 +0000347/// Double Word Swap Bytes/HalfWords
Simon Dardisf1148202016-08-24 13:00:47 +0000348 def DSBH : SubwordSwap<"dsbh", GPR64Opnd, II_DSBH>, SEB_FM<2, 0x24>,
349 ISA_MIPS64R2;
350 def DSHD : SubwordSwap<"dshd", GPR64Opnd, II_DSHD>, SEB_FM<5, 0x24>,
351 ISA_MIPS64R2;
Simon Dardisee67dcb2018-06-01 10:07:10 +0000352
Simon Dardis1d6254f2018-06-08 10:55:34 +0000353 def LEA_ADDiu64 : EffectiveAddress<"daddiu", GPR64Opnd>, LW_FM<0x19>,
354 GPR_64;
Hrvoje Vargaaeb1fe82016-05-11 11:17:04 +0000355}
Akira Hatanaka4706ac92011-12-20 23:56:43 +0000356
Akira Hatanakac7e39982013-08-06 23:01:10 +0000357let isCodeGenOnly = 1 in
Simon Dardis1d6254f2018-06-08 10:55:34 +0000358def RDHWR64 : ReadHardware<GPR64Opnd, HWRegsOpnd>, RDHWR_FM, GPR_64;
Akira Hatanaka4350c182011-12-07 23:31:26 +0000359
Zoran Jovanovic366783e2015-08-12 12:45:16 +0000360let AdditionalPredicates = [NotInMicroMips] in {
Simon Dardis55e44672017-09-14 17:27:53 +0000361 // The 'pos + size' constraints for code generation are enforced by the
362 // code that lowers into MipsISD::Ext.
363 // For assembly parsing, we alias dextu and dextm to dext, and match by
364 // operand were possible then check the 'pos + size' in MipsAsmParser.
365 // We override the generated decoder to enforce that dext always comes out
366 // for dextm and dextu like binutils.
367 let DecoderMethod = "DecodeDEXT" in {
368 def DEXT : ExtBase<"dext", GPR64Opnd, uimm5_report_uimm6,
369 uimm5_plus1_report_uimm6, immZExt5, immZExt5Plus1,
370 MipsExt>, EXT_FM<3>, ISA_MIPS64R2;
371 def DEXTM : ExtBase<"dextm", GPR64Opnd, uimm5, uimm5_plus33, immZExt5,
372 immZExt5Plus33, MipsExt>, EXT_FM<1>, ISA_MIPS64R2;
373 def DEXTU : ExtBase<"dextu", GPR64Opnd, uimm5_plus32, uimm5_plus1,
374 immZExt5Plus32, immZExt5Plus1, MipsExt>, EXT_FM<2>,
375 ISA_MIPS64R2;
376 }
Simon Dardis6f83ae32017-09-14 15:17:50 +0000377 // The 'pos + size' constraints for code generation are enforced by the
378 // code that lowers into MipsISD::Ins.
379 // For assembly parsing, we alias dinsu and dinsm to dins, and match by
380 // operand were possible then check the 'pos + size' in MipsAsmParser.
381 // We override the generated decoder to enforce that dins always comes out
382 // for dinsm and dinsu like binutils.
383 let DecoderMethod = "DecodeDINS" in {
384 def DINS : InsBase<"dins", GPR64Opnd, uimm6, uimm5_inssize_plus1,
Simon Dardisd3b9f612017-11-03 15:35:13 +0000385 immZExt5, immZExt5Plus1>, EXT_FM<7>,
Simon Dardis6f83ae32017-09-14 15:17:50 +0000386 ISA_MIPS64R2;
387 def DINSU : InsBase<"dinsu", GPR64Opnd, uimm5_plus32, uimm5_inssize_plus1,
Simon Dardisd3b9f612017-11-03 15:35:13 +0000388 immZExt5Plus32, immZExt5Plus1>,
Simon Dardis6f83ae32017-09-14 15:17:50 +0000389 EXT_FM<6>, ISA_MIPS64R2;
390 def DINSM : InsBase<"dinsm", GPR64Opnd, uimm5, uimm_range_2_64,
Simon Dardisd3b9f612017-11-03 15:35:13 +0000391 immZExt5, immZExtRange2To64>,
Simon Dardis6f83ae32017-09-14 15:17:50 +0000392 EXT_FM<5>, ISA_MIPS64R2;
393 }
Zoran Jovanovic366783e2015-08-12 12:45:16 +0000394}
Akira Hatanaka31213532013-09-07 00:02:02 +0000395
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000396let isCodeGenOnly = 1, AdditionalPredicates = [NotInMicroMips] in {
397 def DEXT64_32 : InstSE<(outs GPR64Opnd:$rt),
398 (ins GPR32Opnd:$rs, uimm5_report_uimm6:$pos,
399 uimm5_plus1:$size),
400 "dext $rt, $rs, $pos, $size", [], II_EXT, FrmR, "dext">,
401 EXT_FM<3>, ISA_MIPS64R2;
402}
403
Jack Carterf4946cf2012-08-07 00:35:22 +0000404let isCodeGenOnly = 1, rs = 0, shamt = 0 in {
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000405 def DSLL64_32 : FR<0x00, 0x3c, (outs GPR64:$rd), (ins GPR32:$rt),
Simon Dardis1d6254f2018-06-08 10:55:34 +0000406 "dsll\t$rd, $rt, 32", [], II_DSLL>, GPR_64;
Petar Jovanovicc0510002018-05-23 15:28:28 +0000407 let isMoveReg = 1 in {
408 def SLL64_32 : FR<0x0, 0x00, (outs GPR64:$rd), (ins GPR32:$rt),
Simon Dardis1d6254f2018-06-08 10:55:34 +0000409 "sll\t$rd, $rt, 0", [], II_SLL>, GPR_64;
Petar Jovanovicc0510002018-05-23 15:28:28 +0000410 def SLL64_64 : FR<0x0, 0x00, (outs GPR64:$rd), (ins GPR64:$rt),
Simon Dardis1d6254f2018-06-08 10:55:34 +0000411 "sll\t$rd, $rt, 0", [], II_SLL>, GPR_64;
Petar Jovanovicc0510002018-05-23 15:28:28 +0000412 }
Jack Carterf4946cf2012-08-07 00:35:22 +0000413}
Kai Nacke93fe5e82014-03-20 11:51:58 +0000414
Sasa Stankovice41db2f2014-05-27 18:53:06 +0000415// We need the following pseudo instruction to avoid offset calculation for
Sasa Stankovic7b061a42014-04-30 15:06:25 +0000416// long branches. See the comment in file MipsLongBranch.cpp for detailed
417// explanation.
418
Stefan Maksimovic8d7c3512018-11-05 14:37:41 +0000419// Expands to: lui $dst, %highest/%higher/%hi/%lo($tgt)
420def LONG_BRANCH_LUi2Op_64 : PseudoSE<(outs GPR64Opnd:$dst),
421 (ins brtarget:$tgt), []>, GPR_64;
422// Expands to: addiu $dst, %highest/%higher/%hi/%lo($tgt)
423def LONG_BRANCH_DADDiu2Op : PseudoSE<(outs GPR64Opnd:$dst),
424 (ins GPR64Opnd:$src, brtarget:$tgt), []>, GPR_64;
425
Sasa Stankovic7b061a42014-04-30 15:06:25 +0000426// Expands to: daddiu $dst, $src, %PART($tgt - $baltgt)
Sasa Stankovice41db2f2014-05-27 18:53:06 +0000427// where %PART may be %hi or %lo, depending on the relocation kind
Sasa Stankovic7b061a42014-04-30 15:06:25 +0000428// that $tgt is annotated with.
429def LONG_BRANCH_DADDiu : PseudoSE<(outs GPR64Opnd:$dst),
Simon Dardis1d6254f2018-06-08 10:55:34 +0000430 (ins GPR64Opnd:$src, brtarget:$tgt, brtarget:$baltgt), []>, GPR_64;
Sasa Stankovic7b061a42014-04-30 15:06:25 +0000431
Kai Nacke3adf9b82015-05-28 16:23:16 +0000432// Cavium Octeon cnMIPS instructions
433let DecoderNamespace = "CnMips",
Daniel Sandersf6921302016-03-24 11:40:48 +0000434 // FIXME: The lack of HasStdEnc is probably a bug
435 EncodingPredicates = []<Predicate> in {
Kai Nacke93fe5e82014-03-20 11:51:58 +0000436
437class Count1s<string opstr, RegisterOperand RO>:
438 InstSE<(outs RO:$rd), (ins RO:$rs), !strconcat(opstr, "\t$rd, $rs"),
Kai Nacke13673ac2014-04-02 18:40:43 +0000439 [(set RO:$rd, (ctpop RO:$rs))], II_POP, FrmR, opstr> {
440 let TwoOperandAliasConstraint = "$rd = $rs";
441}
442
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000443class ExtsCins<string opstr, InstrItinClass itin, RegisterOperand RO,
444 PatFrag PosImm, SDPatternOperator Op = null_frag>:
445 InstSE<(outs RO:$rt), (ins RO:$rs, uimm5:$pos, uimm5:$lenm1),
446 !strconcat(opstr, "\t$rt, $rs, $pos, $lenm1"),
447 [(set RO:$rt, (Op RO:$rs, PosImm:$pos, imm:$lenm1))],
Simon Dardisf1148202016-08-24 13:00:47 +0000448 itin, FrmR, opstr> {
Kai Nacke13673ac2014-04-02 18:40:43 +0000449 let TwoOperandAliasConstraint = "$rt = $rs";
450}
Kai Nacke93fe5e82014-03-20 11:51:58 +0000451
452class SetCC64_R<string opstr, PatFrag cond_op> :
453 InstSE<(outs GPR64Opnd:$rd), (ins GPR64Opnd:$rs, GPR64Opnd:$rt),
454 !strconcat(opstr, "\t$rd, $rs, $rt"),
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000455 [(set GPR64Opnd:$rd, (zext (cond_op GPR64Opnd:$rs,
456 GPR64Opnd:$rt)))],
Kai Nacke13673ac2014-04-02 18:40:43 +0000457 II_SEQ_SNE, FrmR, opstr> {
458 let TwoOperandAliasConstraint = "$rd = $rs";
459}
Kai Nacke93fe5e82014-03-20 11:51:58 +0000460
Kai Nacke6da86e82014-04-04 16:21:59 +0000461class SetCC64_I<string opstr, PatFrag cond_op>:
462 InstSE<(outs GPR64Opnd:$rt), (ins GPR64Opnd:$rs, simm10_64:$imm10),
463 !strconcat(opstr, "\t$rt, $rs, $imm10"),
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000464 [(set GPR64Opnd:$rt, (zext (cond_op GPR64Opnd:$rs,
465 immSExt10_64:$imm10)))],
Kai Nacke6da86e82014-04-04 16:21:59 +0000466 II_SEQI_SNEI, FrmI, opstr> {
467 let TwoOperandAliasConstraint = "$rt = $rs";
468}
469
Kai Nacke63072f82015-01-20 16:10:51 +0000470class CBranchBitNum<string opstr, DAGOperand opnd, PatFrag cond_op,
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000471 RegisterOperand RO, Operand ImmOp, bits<64> shift = 1> :
472 InstSE<(outs), (ins RO:$rs, ImmOp:$p, opnd:$offset),
Kai Nacke63072f82015-01-20 16:10:51 +0000473 !strconcat(opstr, "\t$rs, $p, $offset"),
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000474 [(brcond (i32 (cond_op (and RO:$rs, (shl shift, immZExt5_64:$p)), 0)),
Daniel Sanders86cce702015-09-22 13:36:28 +0000475 bb:$offset)], II_BBIT, FrmI, opstr> {
Kai Nacke63072f82015-01-20 16:10:51 +0000476 let isBranch = 1;
477 let isTerminator = 1;
478 let hasDelaySlot = 1;
479 let Defs = [AT];
480}
481
Simon Dardisf1148202016-08-24 13:00:47 +0000482class MFC2OP<string asmstr, RegisterOperand RO, InstrItinClass itin> :
Kai Nacke3adf9b82015-05-28 16:23:16 +0000483 InstSE<(outs RO:$rt, uimm16:$imm16), (ins),
Simon Dardisf1148202016-08-24 13:00:47 +0000484 !strconcat(asmstr, "\t$rt, $imm16"), [], itin, FrmFR>;
Kai Nacke3adf9b82015-05-28 16:23:16 +0000485
Kai Nacke93fe5e82014-03-20 11:51:58 +0000486// Unsigned Byte Add
Kai Nacke13673ac2014-04-02 18:40:43 +0000487def BADDu : ArithLogicR<"baddu", GPR64Opnd, 1, II_BADDU>,
Daniel Sandersf6921302016-03-24 11:40:48 +0000488 ADD_FM<0x1c, 0x28>, ASE_CNMIPS {
489 let Pattern = [(set GPR64Opnd:$rd,
490 (and (add GPR64Opnd:$rs, GPR64Opnd:$rt), 255))];
491}
Kai Nacke93fe5e82014-03-20 11:51:58 +0000492
Kai Nacke63072f82015-01-20 16:10:51 +0000493// Branch on Bit Clear /+32
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000494def BBIT0 : CBranchBitNum<"bbit0", brtarget, seteq, GPR64Opnd,
Daniel Sandersf6921302016-03-24 11:40:48 +0000495 uimm5_64_report_uimm6>, BBIT_FM<0x32>, ASE_CNMIPS;
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000496def BBIT032: CBranchBitNum<"bbit032", brtarget, seteq, GPR64Opnd, uimm5_64,
Daniel Sandersf6921302016-03-24 11:40:48 +0000497 0x100000000>, BBIT_FM<0x36>, ASE_CNMIPS;
Kai Nacke63072f82015-01-20 16:10:51 +0000498
499// Branch on Bit Set /+32
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000500def BBIT1 : CBranchBitNum<"bbit1", brtarget, setne, GPR64Opnd,
Daniel Sandersf6921302016-03-24 11:40:48 +0000501 uimm5_64_report_uimm6>, BBIT_FM<0x3a>, ASE_CNMIPS;
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000502def BBIT132: CBranchBitNum<"bbit132", brtarget, setne, GPR64Opnd, uimm5_64,
Daniel Sandersf6921302016-03-24 11:40:48 +0000503 0x100000000>, BBIT_FM<0x3e>, ASE_CNMIPS;
Kai Nacke63072f82015-01-20 16:10:51 +0000504
Kai Nacke93fe5e82014-03-20 11:51:58 +0000505// Multiply Doubleword to GPR
Kai Nacke93fe5e82014-03-20 11:51:58 +0000506def DMUL : ArithLogicR<"dmul", GPR64Opnd, 1, II_DMUL, mul>,
Daniel Sandersf6921302016-03-24 11:40:48 +0000507 ADD_FM<0x1c, 0x03>, ASE_CNMIPS {
508 let Defs = [HI0, LO0, P0, P1, P2];
509}
Kai Nacke93fe5e82014-03-20 11:51:58 +0000510
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000511let AdditionalPredicates = [NotInMicroMips] in {
512 // Extract a signed bit field /+32
513 def EXTS : ExtsCins<"exts", II_EXT, GPR64Opnd, immZExt5>, EXTS_FM<0x3a>,
514 ASE_MIPS64_CNMIPS;
515 def EXTS32: ExtsCins<"exts32", II_EXT, GPR64Opnd, immZExt5Plus32>,
516 EXTS_FM<0x3b>, ASE_MIPS64_CNMIPS;
Kai Nacke13673ac2014-04-02 18:40:43 +0000517
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000518 // Clear and insert a bit field /+32
519 def CINS : ExtsCins<"cins", II_INS, GPR64Opnd, immZExt5, MipsCIns>,
520 EXTS_FM<0x32>, ASE_MIPS64_CNMIPS;
521 def CINS32: ExtsCins<"cins32", II_INS, GPR64Opnd, immZExt5Plus32, MipsCIns>,
522 EXTS_FM<0x33>, ASE_MIPS64_CNMIPS;
523 let isCodeGenOnly = 1 in {
524 def CINS_i32 : ExtsCins<"cins", II_INS, GPR32Opnd, immZExt5, MipsCIns>,
525 EXTS_FM<0x32>, ASE_MIPS64_CNMIPS;
526 def CINS64_32 :InstSE<(outs GPR64Opnd:$rt),
527 (ins GPR32Opnd:$rs, uimm5:$pos, uimm5:$lenm1),
528 "cins\t$rt, $rs, $pos, $lenm1", [], II_INS, FrmR,
529 "cins">,
530 EXTS_FM<0x32>, ASE_MIPS64_CNMIPS;
531 }
532}
Kai Nacke13673ac2014-04-02 18:40:43 +0000533
Kai Nackeaf47f602014-04-01 18:35:26 +0000534// Move to multiplier/product register
Daniel Sandersf6921302016-03-24 11:40:48 +0000535def MTM0 : MoveToLOHI<"mtm0", GPR64Opnd, [MPL0, P0, P1, P2]>, MTMR_FM<0x08>,
536 ASE_CNMIPS;
537def MTM1 : MoveToLOHI<"mtm1", GPR64Opnd, [MPL1, P0, P1, P2]>, MTMR_FM<0x0c>,
538 ASE_CNMIPS;
539def MTM2 : MoveToLOHI<"mtm2", GPR64Opnd, [MPL2, P0, P1, P2]>, MTMR_FM<0x0d>,
540 ASE_CNMIPS;
541def MTP0 : MoveToLOHI<"mtp0", GPR64Opnd, [P0]>, MTMR_FM<0x09>, ASE_CNMIPS;
542def MTP1 : MoveToLOHI<"mtp1", GPR64Opnd, [P1]>, MTMR_FM<0x0a>, ASE_CNMIPS;
543def MTP2 : MoveToLOHI<"mtp2", GPR64Opnd, [P2]>, MTMR_FM<0x0b>, ASE_CNMIPS;
Kai Nackeaf47f602014-04-01 18:35:26 +0000544
Kai Nacke93fe5e82014-03-20 11:51:58 +0000545// Count Ones in a Word/Doubleword
Daniel Sandersf6921302016-03-24 11:40:48 +0000546def POP : Count1s<"pop", GPR32Opnd>, POP_FM<0x2c>, ASE_CNMIPS;
547def DPOP : Count1s<"dpop", GPR64Opnd>, POP_FM<0x2d>, ASE_CNMIPS;
Kai Nacke93fe5e82014-03-20 11:51:58 +0000548
549// Set on equal/not equal
Daniel Sandersf6921302016-03-24 11:40:48 +0000550def SEQ : SetCC64_R<"seq", seteq>, SEQ_FM<0x2a>, ASE_CNMIPS;
551def SEQi : SetCC64_I<"seqi", seteq>, SEQI_FM<0x2e>, ASE_CNMIPS;
552def SNE : SetCC64_R<"sne", setne>, SEQ_FM<0x2b>, ASE_CNMIPS;
553def SNEi : SetCC64_I<"snei", setne>, SEQI_FM<0x2f>, ASE_CNMIPS;
Kai Nacke6da86e82014-04-04 16:21:59 +0000554
Matheus Almeida583a13c2014-04-24 16:31:10 +0000555// 192-bit x 64-bit Unsigned Multiply and Add
Daniel Sandersf6921302016-03-24 11:40:48 +0000556def V3MULU: ArithLogicR<"v3mulu", GPR64Opnd, 0, II_DMUL>, ADD_FM<0x1c, 0x11>,
557 ASE_CNMIPS {
558 let Defs = [P0, P1, P2];
559}
Kai Nacke6da86e82014-04-04 16:21:59 +0000560
561// 64-bit Unsigned Multiply and Add Move
Daniel Sandersf6921302016-03-24 11:40:48 +0000562def VMM0 : ArithLogicR<"vmm0", GPR64Opnd, 0, II_DMUL>, ADD_FM<0x1c, 0x10>,
563 ASE_CNMIPS {
564 let Defs = [MPL0, P0, P1, P2];
565}
Kai Nacke6da86e82014-04-04 16:21:59 +0000566
567// 64-bit Unsigned Multiply and Add
Daniel Sandersf6921302016-03-24 11:40:48 +0000568def VMULU : ArithLogicR<"vmulu", GPR64Opnd, 0, II_DMUL>, ADD_FM<0x1c, 0x0f>,
569 ASE_CNMIPS {
570 let Defs = [MPL1, MPL2, P0, P1, P2];
571}
Kai Nacke6da86e82014-04-04 16:21:59 +0000572
Kai Nacke3adf9b82015-05-28 16:23:16 +0000573// Move between CPU and coprocessor registers
Simon Dardisf1148202016-08-24 13:00:47 +0000574def DMFC2_OCTEON : MFC2OP<"dmfc2", GPR64Opnd, II_DMFC2>, MFC2OP_FM<0x12, 1>,
575 ASE_CNMIPS;
576def DMTC2_OCTEON : MFC2OP<"dmtc2", GPR64Opnd, II_DMTC2>, MFC2OP_FM<0x12, 5>,
577 ASE_CNMIPS;
Kai Nacke93fe5e82014-03-20 11:51:58 +0000578}
579
Akira Hatanaka71928e62012-04-17 18:03:21 +0000580}
Kai Nacke13673ac2014-04-02 18:40:43 +0000581
Toma Tabacua90f1442015-02-24 11:52:19 +0000582/// Move between CPU and coprocessor registers
583let DecoderNamespace = "Mips64", Predicates = [HasMips64] in {
Petar Jovanovicd4349f32018-04-27 09:12:08 +0000584def DMFC0 : MFC3OP<"dmfc0", GPR64Opnd, COP0Opnd, II_DMFC0>,
585 MFC3OP_FM<0x10, 1, 0>, ISA_MIPS3;
586def DMTC0 : MTC3OP<"dmtc0", COP0Opnd, GPR64Opnd, II_DMTC0>,
587 MFC3OP_FM<0x10, 5, 0>, ISA_MIPS3;
588def DMFC2 : MFC3OP<"dmfc2", GPR64Opnd, COP2Opnd, II_DMFC2>,
589 MFC3OP_FM<0x12, 1, 0>, ISA_MIPS3;
590def DMTC2 : MTC3OP<"dmtc2", COP2Opnd, GPR64Opnd, II_DMTC2>,
591 MFC3OP_FM<0x12, 5, 0>, ISA_MIPS3;
Toma Tabacua90f1442015-02-24 11:52:19 +0000592}
593
Petar Jovanovicd4349f32018-04-27 09:12:08 +0000594/// Move between CPU and guest coprocessor registers (Virtualization ASE)
595let DecoderNamespace = "Mips64" in {
596 def DMFGC0 : MFC3OP<"dmfgc0", GPR64Opnd, COP0Opnd, II_DMFGC0>,
597 MFC3OP_FM<0x10, 3, 1>, ISA_MIPS64R5, ASE_VIRT;
598 def DMTGC0 : MTC3OP<"dmtgc0", COP0Opnd, GPR64Opnd, II_DMTGC0>,
599 MFC3OP_FM<0x10, 3, 3>, ISA_MIPS64R5, ASE_VIRT;
600}
Simon Dardis7bc8ad52018-02-21 00:06:53 +0000601
602let AdditionalPredicates = [UseIndirectJumpsHazard] in
603 def JALRHB64Pseudo : JumpLinkRegPseudo<GPR64Opnd, JALR_HB64, RA_64>;
604
Akira Hatanaka7ba8a8d2011-09-30 18:51:46 +0000605//===----------------------------------------------------------------------===//
606// Arbitrary patterns that map to one or more instructions
607//===----------------------------------------------------------------------===//
608
Simon Dardis61897522016-07-25 09:57:28 +0000609// Materialize i64 constants.
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000610defm : MaterializeImms<i64, ZERO_64, DADDiu, LUi64, ORi64>, ISA_MIPS3, GPR_64;
Simon Dardis61897522016-07-25 09:57:28 +0000611
612def : MipsPat<(i64 immZExt32Low16Zero:$imm),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000613 (DSLL (ORi64 ZERO_64, (HI16 imm:$imm)), 16)>, ISA_MIPS3, GPR_64;
Simon Dardis61897522016-07-25 09:57:28 +0000614
615def : MipsPat<(i64 immZExt32:$imm),
616 (ORi64 (DSLL (ORi64 ZERO_64, (HI16 imm:$imm)), 16),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000617 (LO16 imm:$imm))>, ISA_MIPS3, GPR_64;
Simon Dardis61897522016-07-25 09:57:28 +0000618
Akira Hatanakaf93b3f42011-11-14 19:06:14 +0000619// extended loads
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000620def : MipsPat<(i64 (extloadi1 addr:$src)), (LB64 addr:$src)>, ISA_MIPS3,
621 GPR_64;
622def : MipsPat<(i64 (extloadi8 addr:$src)), (LB64 addr:$src)>, ISA_MIPS3,
623 GPR_64;
624def : MipsPat<(i64 (extloadi16 addr:$src)), (LH64 addr:$src)>, ISA_MIPS3,
625 GPR_64;
626def : MipsPat<(i64 (extloadi32 addr:$src)), (LW64 addr:$src)>, ISA_MIPS3,
627 GPR_64;
Akira Hatanaka09b23eb2011-10-11 00:55:05 +0000628
629// hi/lo relocs
Simon Dardisca74dd72017-01-27 11:36:52 +0000630let AdditionalPredicates = [NotInMicroMips] in
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000631defm : MipsHiLoRelocs<LUi64, DADDiu, ZERO_64, GPR64Opnd>, ISA_MIPS3, GPR_64,
632 SYM_32;
Akira Hatanaka7b8547c2011-11-16 22:39:56 +0000633
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000634def : MipsPat<(MipsGotHi tglobaladdr:$in), (LUi64 tglobaladdr:$in)>, ISA_MIPS3,
635 GPR_64;
636def : MipsPat<(MipsGotHi texternalsym:$in), (LUi64 texternalsym:$in)>,
637 ISA_MIPS3, GPR_64;
Akira Hatanaka7b8547c2011-11-16 22:39:56 +0000638
Simon Atanasyan28ded4e2018-07-24 13:47:52 +0000639def : MipsPat<(MipsTlsHi tglobaltlsaddr:$in), (LUi64 tglobaltlsaddr:$in)>,
640 ISA_MIPS3, GPR_64;
641
Aleksandar Beserminjid6dada12017-12-11 11:21:40 +0000642// highest/higher/hi/lo relocs
643let AdditionalPredicates = [NotInMicroMips] in {
Simon Dardisca74dd72017-01-27 11:36:52 +0000644 def : MipsPat<(MipsJmpLink (i64 texternalsym:$dst)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000645 (JAL texternalsym:$dst)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000646 def : MipsPat<(MipsHighest (i64 tglobaladdr:$in)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000647 (LUi64 tglobaladdr:$in)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000648 def : MipsPat<(MipsHighest (i64 tblockaddress:$in)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000649 (LUi64 tblockaddress:$in)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000650 def : MipsPat<(MipsHighest (i64 tjumptable:$in)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000651 (LUi64 tjumptable:$in)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000652 def : MipsPat<(MipsHighest (i64 tconstpool:$in)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000653 (LUi64 tconstpool:$in)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000654 def : MipsPat<(MipsHighest (i64 texternalsym:$in)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000655 (LUi64 texternalsym:$in)>, ISA_MIPS3, GPR_64, SYM_64;
Akira Hatanakaf75add62011-10-11 18:53:46 +0000656
Simon Dardisca74dd72017-01-27 11:36:52 +0000657 def : MipsPat<(MipsHigher (i64 tglobaladdr:$in)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000658 (DADDiu ZERO_64, tglobaladdr:$in)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000659 def : MipsPat<(MipsHigher (i64 tblockaddress:$in)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000660 (DADDiu ZERO_64, tblockaddress:$in)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000661 def : MipsPat<(MipsHigher (i64 tjumptable:$in)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000662 (DADDiu ZERO_64, tjumptable:$in)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000663 def : MipsPat<(MipsHigher (i64 tconstpool:$in)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000664 (DADDiu ZERO_64, tconstpool:$in)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000665 def : MipsPat<(MipsHigher (i64 texternalsym:$in)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000666 (DADDiu ZERO_64, texternalsym:$in)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000667
668 def : MipsPat<(add GPR64:$hi, (MipsHigher (i64 tglobaladdr:$lo))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000669 (DADDiu GPR64:$hi, tglobaladdr:$lo)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000670 def : MipsPat<(add GPR64:$hi, (MipsHigher (i64 tblockaddress:$lo))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000671 (DADDiu GPR64:$hi, tblockaddress:$lo)>, ISA_MIPS3, GPR_64,
672 SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000673 def : MipsPat<(add GPR64:$hi, (MipsHigher (i64 tjumptable:$lo))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000674 (DADDiu GPR64:$hi, tjumptable:$lo)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000675 def : MipsPat<(add GPR64:$hi, (MipsHigher (i64 tconstpool:$lo))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000676 (DADDiu GPR64:$hi, tconstpool:$lo)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000677
678 def : MipsPat<(add GPR64:$hi, (MipsHi (i64 tglobaladdr:$lo))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000679 (DADDiu GPR64:$hi, tglobaladdr:$lo)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000680 def : MipsPat<(add GPR64:$hi, (MipsHi (i64 tblockaddress:$lo))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000681 (DADDiu GPR64:$hi, tblockaddress:$lo)>, ISA_MIPS3, GPR_64,
682 SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000683 def : MipsPat<(add GPR64:$hi, (MipsHi (i64 tjumptable:$lo))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000684 (DADDiu GPR64:$hi, tjumptable:$lo)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000685 def : MipsPat<(add GPR64:$hi, (MipsHi (i64 tconstpool:$lo))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000686 (DADDiu GPR64:$hi, tconstpool:$lo)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000687
688 def : MipsPat<(add GPR64:$hi, (MipsLo (i64 tglobaladdr:$lo))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000689 (DADDiu GPR64:$hi, tglobaladdr:$lo)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000690 def : MipsPat<(add GPR64:$hi, (MipsLo (i64 tblockaddress:$lo))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000691 (DADDiu GPR64:$hi, tblockaddress:$lo)>, ISA_MIPS3, GPR_64,
692 SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000693 def : MipsPat<(add GPR64:$hi, (MipsLo (i64 tjumptable:$lo))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000694 (DADDiu GPR64:$hi, tjumptable:$lo)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000695 def : MipsPat<(add GPR64:$hi, (MipsLo (i64 tconstpool:$lo))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000696 (DADDiu GPR64:$hi, tconstpool:$lo)>, ISA_MIPS3, GPR_64, SYM_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000697 def : MipsPat<(add GPR64:$hi, (MipsLo (i64 tglobaltlsaddr:$lo))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000698 (DADDiu GPR64:$hi, tglobaltlsaddr:$lo)>, ISA_MIPS3, GPR_64,
699 SYM_64;
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000700}
Akira Hatanakab2e05cb2011-12-07 22:11:43 +0000701
Simon Dardisae5b53e2017-08-11 14:36:05 +0000702// gp_rel relocs
703def : MipsPat<(add GPR64:$gp, (MipsGPRel tglobaladdr:$in)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000704 (DADDiu GPR64:$gp, tglobaladdr:$in)>, ISA_MIPS3, ABI_N64;
Simon Dardisae5b53e2017-08-11 14:36:05 +0000705def : MipsPat<(add GPR64:$gp, (MipsGPRel tconstpool:$in)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000706 (DADDiu GPR64:$gp, tconstpool:$in)>, ISA_MIPS3, ABI_N64;
Simon Dardisae5b53e2017-08-11 14:36:05 +0000707
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000708def : WrapperPat<tglobaladdr, DADDiu, GPR64>, ISA_MIPS3, GPR_64;
709def : WrapperPat<tconstpool, DADDiu, GPR64>, ISA_MIPS3, GPR_64;
710def : WrapperPat<texternalsym, DADDiu, GPR64>, ISA_MIPS3, GPR_64;
711def : WrapperPat<tblockaddress, DADDiu, GPR64>, ISA_MIPS3, GPR_64;
712def : WrapperPat<tjumptable, DADDiu, GPR64>, ISA_MIPS3, GPR_64;
713def : WrapperPat<tglobaltlsaddr, DADDiu, GPR64>, ISA_MIPS3, GPR_64;
Simon Dardisca74dd72017-01-27 11:36:52 +0000714
715
Hrvoje Varga2db00ce2016-07-22 07:18:33 +0000716defm : BrcondPats<GPR64, BEQ64, BEQ, BNE64, SLT64, SLTu64, SLTi64, SLTiu64,
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000717 ZERO_64>, ISA_MIPS3, GPR_64;
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000718def : MipsPat<(brcond (i32 (setlt i64:$lhs, 1)), bb:$dst),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000719 (BLEZ64 i64:$lhs, bb:$dst)>, ISA_MIPS3, GPR_64;
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000720def : MipsPat<(brcond (i32 (setgt i64:$lhs, -1)), bb:$dst),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000721 (BGEZ64 i64:$lhs, bb:$dst)>, ISA_MIPS3, GPR_64;
Akira Hatanaka68710312013-05-21 17:13:47 +0000722
Akira Hatanakaf75add62011-10-11 18:53:46 +0000723// setcc patterns
Hrvoje Varga2db00ce2016-07-22 07:18:33 +0000724let AdditionalPredicates = [NotInMicroMips] in {
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000725 defm : SeteqPats<GPR64, SLTiu64, XOR64, SLTu64, ZERO_64>, ISA_MIPS3, GPR_64;
726 defm : SetlePats<GPR64, XORi, SLT64, SLTu64>, ISA_MIPS3, GPR_64;
727 defm : SetgtPats<GPR64, SLT64, SLTu64>, ISA_MIPS3, GPR_64;
728 defm : SetgePats<GPR64, XORi, SLT64, SLTu64>, ISA_MIPS3, GPR_64;
729 defm : SetgeImmPats<GPR64, XORi, SLTi64, SLTiu64>, ISA_MIPS3, GPR_64;
Hrvoje Varga2db00ce2016-07-22 07:18:33 +0000730}
Akira Hatanakad5c13292011-11-07 18:57:41 +0000731// truncate
Daniel Sandersc43cda82014-11-07 16:54:21 +0000732def : MipsPat<(trunc (assertsext GPR64:$src)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000733 (EXTRACT_SUBREG GPR64:$src, sub_32)>, ISA_MIPS3, GPR_64;
Vasileios Kalintiris3751d412016-04-13 15:07:45 +0000734// The forward compatibility strategy employed by MIPS requires us to treat
735// values as being sign extended to an infinite number of bits. This allows
736// existing software to run without modification on any future MIPS
737// implementation (e.g. 128-bit, or 1024-bit). Being compatible with this
738// strategy requires that truncation acts as a sign-extension for values being
739// fed into instructions operating on 32-bit values. Such instructions have
740// undefined results if this is not true.
741// For our case, this means that we can't issue an extract_subreg for nodes
742// such as (trunc:i32 (assertzext:i64 X, i32)), because the sign-bit of the
743// lower subreg would not be replicated into the upper half.
744def : MipsPat<(trunc (assertzext_lt_i32 GPR64:$src)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000745 (EXTRACT_SUBREG GPR64:$src, sub_32)>, ISA_MIPS3, GPR_64;
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000746def : MipsPat<(i32 (trunc GPR64:$src)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000747 (SLL (EXTRACT_SUBREG GPR64:$src, sub_32), 0)>, ISA_MIPS3, GPR_64;
Jia Liuf54f60f2012-02-28 07:46:26 +0000748
Vasileios Kalintiris32177d62015-04-21 10:49:03 +0000749// variable shift instructions patterns
750def : MipsPat<(shl GPR64:$rt, (i32 (trunc GPR64:$rs))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000751 (DSLLV GPR64:$rt, (EXTRACT_SUBREG GPR64:$rs, sub_32))>,
752 ISA_MIPS3, GPR_64;
Vasileios Kalintiris32177d62015-04-21 10:49:03 +0000753def : MipsPat<(srl GPR64:$rt, (i32 (trunc GPR64:$rs))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000754 (DSRLV GPR64:$rt, (EXTRACT_SUBREG GPR64:$rs, sub_32))>,
755 ISA_MIPS3, GPR_64;
Vasileios Kalintiris32177d62015-04-21 10:49:03 +0000756def : MipsPat<(sra GPR64:$rt, (i32 (trunc GPR64:$rs))),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000757 (DSRAV GPR64:$rt, (EXTRACT_SUBREG GPR64:$rs, sub_32))>,
758 ISA_MIPS3, GPR_64;
759def : MipsPat<(rotr GPR64:$rt, (i32 (trunc GPR64:$rs))),
760 (DROTRV GPR64:$rt, (EXTRACT_SUBREG GPR64:$rs, sub_32))>,
761 ISA_MIPS3, GPR_64;
Vasileios Kalintiris32177d62015-04-21 10:49:03 +0000762
Akira Hatanakaae378af2011-12-07 23:14:41 +0000763// 32-to-64-bit extension
Vasileios Kalintiris29620ac2016-02-29 15:58:12 +0000764def : MipsPat<(i64 (anyext GPR32:$src)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000765 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), GPR32:$src, sub_32)>,
766 ISA_MIPS3, GPR_64;
767def : MipsPat<(i64 (zext GPR32:$src)), (DSRL (DSLL64_32 GPR32:$src), 32)>,
768 ISA_MIPS3, GPR_64;
769def : MipsPat<(i64 (sext GPR32:$src)), (SLL64_32 GPR32:$src)>, ISA_MIPS3,
770 GPR_64;
Akira Hatanaka4e210692011-12-20 22:06:20 +0000771
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000772let AdditionalPredicates = [NotInMicroMips] in {
773 def : MipsPat<(i64 (zext GPR32:$src)), (DEXT64_32 GPR32:$src, 0, 32)>,
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000774 ISA_MIPS64R2, GPR_64;
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000775 def : MipsPat<(i64 (zext (i32 (shl GPR32:$rt, immZExt5:$imm)))),
776 (CINS64_32 GPR32:$rt, imm:$imm, (immZExt5To31 imm:$imm))>,
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000777 ISA_MIPS64R2, GPR_64, ASE_MIPS64_CNMIPS;
Petar Jovanovicb71386a2017-03-15 13:10:08 +0000778}
779
Akira Hatanaka494fdf12011-12-20 22:40:40 +0000780// Sign extend in register
Akira Hatanaka13e6ccf2013-08-06 23:08:38 +0000781def : MipsPat<(i64 (sext_inreg GPR64:$src, i32)),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000782 (SLL64_64 GPR64:$src)>, ISA_MIPS3, GPR_64;
Akira Hatanaka494fdf12011-12-20 22:40:40 +0000783
Akira Hatanakad8ab16b2012-06-14 21:03:23 +0000784// bswap MipsPattern
Simon Dardisfce722e2018-04-24 10:19:29 +0000785def : MipsPat<(bswap GPR64:$rt), (DSHD (DSBH GPR64:$rt))>, ISA_MIPS64R2;
David Chisnall37051252012-10-09 16:27:43 +0000786
Vasileios Kalintirisef96a8e2015-01-26 12:33:22 +0000787// Carry pattern
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000788let AdditionalPredicates = [NotInMicroMips] in {
Zlatko Buljande0bbe62016-04-27 11:31:44 +0000789 def : MipsPat<(subc GPR64:$lhs, GPR64:$rhs),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000790 (DSUBu GPR64:$lhs, GPR64:$rhs)>, ISA_MIPS3, GPR_64;
Vasileios Kalintirisef96a8e2015-01-26 12:33:22 +0000791 def : MipsPat<(addc GPR64:$lhs, GPR64:$rhs),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000792 (DADDu GPR64:$lhs, GPR64:$rhs)>, ISA_MIPS3, ASE_NOT_DSP, GPR_64;
Vasileios Kalintirisef96a8e2015-01-26 12:33:22 +0000793 def : MipsPat<(addc GPR64:$lhs, immSExt16:$imm),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000794 (DADDiu GPR64:$lhs, imm:$imm)>, ISA_MIPS3, ASE_NOT_DSP, GPR_64;
Vasileios Kalintirisef96a8e2015-01-26 12:33:22 +0000795}
796
Kai Nacke63072f82015-01-20 16:10:51 +0000797// Octeon bbit0/bbit1 MipsPattern
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000798def : MipsPat<(brcond (i32 (seteq (and i64:$lhs, PowerOf2LO:$mask), 0)), bb:$dst),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000799 (BBIT0 i64:$lhs, (Log2LO PowerOf2LO:$mask), bb:$dst)>,
800 ISA_MIPS64R2, ASE_MIPS64_CNMIPS;
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000801def : MipsPat<(brcond (i32 (seteq (and i64:$lhs, PowerOf2HI:$mask), 0)), bb:$dst),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000802 (BBIT032 i64:$lhs, (Log2HI PowerOf2HI:$mask), bb:$dst)>,
803 ISA_MIPS64R2, ASE_MIPS64_CNMIPS;
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000804def : MipsPat<(brcond (i32 (setne (and i64:$lhs, PowerOf2LO:$mask), 0)), bb:$dst),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000805 (BBIT1 i64:$lhs, (Log2LO PowerOf2LO:$mask), bb:$dst)>,
806 ISA_MIPS64R2, ASE_MIPS64_CNMIPS;
Vasileios Kalintiris36901dd2016-03-01 20:25:43 +0000807def : MipsPat<(brcond (i32 (setne (and i64:$lhs, PowerOf2HI:$mask), 0)), bb:$dst),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000808 (BBIT132 i64:$lhs, (Log2HI PowerOf2HI:$mask), bb:$dst)>,
809 ISA_MIPS64R2, ASE_MIPS64_CNMIPS;
Strahinja Petrovic89df7972017-08-30 11:25:38 +0000810def : MipsPat<(brcond (i32 (seteq (and i32:$lhs, PowerOf2LO_i32:$mask), 0)), bb:$dst),
811 (BBIT0 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), i32:$lhs, sub_32),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000812 (Log2LO PowerOf2LO_i32:$mask), bb:$dst)>, ISA_MIPS64R2,
813 ASE_MIPS64_CNMIPS;
Strahinja Petrovic89df7972017-08-30 11:25:38 +0000814def : MipsPat<(brcond (i32 (setne (and i32:$lhs, PowerOf2LO_i32:$mask), 0)), bb:$dst),
815 (BBIT1 (INSERT_SUBREG (i64 (IMPLICIT_DEF)), i32:$lhs, sub_32),
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000816 (Log2LO PowerOf2LO_i32:$mask), bb:$dst)>, ISA_MIPS64R2,
817 ASE_MIPS64_CNMIPS;
Kai Nacke63072f82015-01-20 16:10:51 +0000818
Vasileios Kalintirisb04672c2015-11-06 12:07:20 +0000819// Atomic load patterns.
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000820def : MipsPat<(atomic_load_8 addr:$a), (LB64 addr:$a)>, ISA_MIPS3, GPR_64;
821def : MipsPat<(atomic_load_16 addr:$a), (LH64 addr:$a)>, ISA_MIPS3, GPR_64;
822def : MipsPat<(atomic_load_32 addr:$a), (LW64 addr:$a)>, ISA_MIPS3, GPR_64;
823def : MipsPat<(atomic_load_64 addr:$a), (LD addr:$a)>, ISA_MIPS3, GPR_64;
Vasileios Kalintirisb04672c2015-11-06 12:07:20 +0000824
825// Atomic store patterns.
Simon Atanasyan738a6e42018-07-16 13:52:41 +0000826def : MipsPat<(atomic_store_8 addr:$a, GPR64:$v), (SB64 GPR64:$v, addr:$a)>,
827 ISA_MIPS3, GPR_64;
828def : MipsPat<(atomic_store_16 addr:$a, GPR64:$v), (SH64 GPR64:$v, addr:$a)>,
829 ISA_MIPS3, GPR_64;
830def : MipsPat<(atomic_store_32 addr:$a, GPR64:$v), (SW64 GPR64:$v, addr:$a)>,
831 ISA_MIPS3, GPR_64;
832def : MipsPat<(atomic_store_64 addr:$a, GPR64:$v), (SD GPR64:$v, addr:$a)>,
833 ISA_MIPS3, GPR_64;
Vasileios Kalintirisb04672c2015-11-06 12:07:20 +0000834
Stefan Maksimovic4a612d42018-07-26 10:59:35 +0000835// Patterns used for matching away redundant sign extensions.
836// MIPS32 arithmetic instructions sign extend their result implicitly.
837def : MipsPat<(i64 (sext (i32 (add GPR32:$src, immSExt16:$imm16)))),
838 (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
839 (ADDiu GPR32:$src, immSExt16:$imm16), sub_32)>;
840def : MipsPat<(i64 (sext (i32 (add GPR32:$src, GPR32:$src2)))),
841 (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
842 (ADDu GPR32:$src, GPR32:$src2), sub_32)>;
843def : MipsPat<(i64 (sext (i32 (sub GPR32:$src, GPR32:$src2)))),
844 (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
845 (SUBu GPR32:$src, GPR32:$src2), sub_32)>;
846def : MipsPat<(i64 (sext (i32 (mul GPR32:$src, GPR32:$src2)))),
847 (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
Stefan Maksimovic90e7ff82018-09-25 06:27:49 +0000848 (MUL GPR32:$src, GPR32:$src2), sub_32)>, ISA_MIPS3_NOT_32R6_64R6;
Stefan Maksimovic4a612d42018-07-26 10:59:35 +0000849def : MipsPat<(i64 (sext (i32 (MipsMFHI ACC64:$src)))),
850 (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
851 (PseudoMFHI ACC64:$src), sub_32)>;
852def : MipsPat<(i64 (sext (i32 (MipsMFLO ACC64:$src)))),
853 (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
854 (PseudoMFLO ACC64:$src), sub_32)>;
855def : MipsPat<(i64 (sext (i32 (shl GPR32:$src, immZExt5:$imm5)))),
856 (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
857 (SLL GPR32:$src, immZExt5:$imm5), sub_32)>;
858def : MipsPat<(i64 (sext (i32 (shl GPR32:$src, GPR32:$src2)))),
859 (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
860 (SLLV GPR32:$src, GPR32:$src2), sub_32)>;
861def : MipsPat<(i64 (sext (i32 (srl GPR32:$src, immZExt5:$imm5)))),
862 (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
863 (SRL GPR32:$src, immZExt5:$imm5), sub_32)>;
864def : MipsPat<(i64 (sext (i32 (srl GPR32:$src, GPR32:$src2)))),
865 (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
866 (SRLV GPR32:$src, GPR32:$src2), sub_32)>;
867def : MipsPat<(i64 (sext (i32 (sra GPR32:$src, immZExt5:$imm5)))),
868 (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
869 (SRA GPR32:$src, immZExt5:$imm5), sub_32)>;
870def : MipsPat<(i64 (sext (i32 (sra GPR32:$src, GPR32:$src2)))),
871 (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
872 (SRAV GPR32:$src, GPR32:$src2), sub_32)>;
873
David Chisnall37051252012-10-09 16:27:43 +0000874//===----------------------------------------------------------------------===//
875// Instruction aliases
876//===----------------------------------------------------------------------===//
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000877let AdditionalPredicates = [NotInMicroMips] in {
878 def : MipsInstAlias<"move $dst, $src",
879 (OR64 GPR64Opnd:$dst, GPR64Opnd:$src, ZERO_64), 1>,
880 GPR_64;
881 def : MipsInstAlias<"move $dst, $src",
882 (DADDu GPR64Opnd:$dst, GPR64Opnd:$src, ZERO_64), 1>,
883 GPR_64;
884 def : MipsInstAlias<"dadd $rs, $rt, $imm",
885 (DADDi GPR64Opnd:$rs, GPR64Opnd:$rt, simm16_64:$imm),
886 0>, ISA_MIPS3_NOT_32R6_64R6;
887 def : MipsInstAlias<"dadd $rs, $imm",
888 (DADDi GPR64Opnd:$rs, GPR64Opnd:$rs, simm16_64:$imm),
889 0>, ISA_MIPS3_NOT_32R6_64R6;
890 def : MipsInstAlias<"daddu $rs, $rt, $imm",
891 (DADDiu GPR64Opnd:$rs, GPR64Opnd:$rt, simm16_64:$imm),
892 0>, ISA_MIPS3;
893 def : MipsInstAlias<"daddu $rs, $imm",
894 (DADDiu GPR64Opnd:$rs, GPR64Opnd:$rs, simm16_64:$imm),
895 0>, ISA_MIPS3;
Simon Dardisaa208812017-02-24 14:34:32 +0000896
897 defm : OneOrTwoOperandMacroImmediateAlias<"and", ANDi64, GPR64Opnd, imm64>,
Simon Dardisfdc05262018-04-19 09:45:04 +0000898 ISA_MIPS3, GPR_64;
Simon Dardisaa208812017-02-24 14:34:32 +0000899
900 defm : OneOrTwoOperandMacroImmediateAlias<"or", ORi64, GPR64Opnd, imm64>,
Simon Dardisfdc05262018-04-19 09:45:04 +0000901 ISA_MIPS3, GPR_64;
Simon Dardisaa208812017-02-24 14:34:32 +0000902
903 defm : OneOrTwoOperandMacroImmediateAlias<"xor", XORi64, GPR64Opnd, imm64>,
Simon Dardisfdc05262018-04-19 09:45:04 +0000904 ISA_MIPS3, GPR_64;
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000905}
Zlatko Buljande0bbe62016-04-27 11:31:44 +0000906let AdditionalPredicates = [NotInMicroMips] in {
907 def : MipsInstAlias<"dneg $rt, $rs",
908 (DSUB GPR64Opnd:$rt, ZERO_64, GPR64Opnd:$rs), 1>,
909 ISA_MIPS3;
910 def : MipsInstAlias<"dneg $rt",
Simon Dardis273fc262016-07-26 09:13:46 +0000911 (DSUB GPR64Opnd:$rt, ZERO_64, GPR64Opnd:$rt), 1>,
Zlatko Buljande0bbe62016-04-27 11:31:44 +0000912 ISA_MIPS3;
913 def : MipsInstAlias<"dnegu $rt, $rs",
914 (DSUBu GPR64Opnd:$rt, ZERO_64, GPR64Opnd:$rs), 1>,
915 ISA_MIPS3;
Simon Dardis273fc262016-07-26 09:13:46 +0000916 def : MipsInstAlias<"dnegu $rt",
917 (DSUBu GPR64Opnd:$rt, ZERO_64, GPR64Opnd:$rt), 1>,
918 ISA_MIPS3;
Zlatko Buljande0bbe62016-04-27 11:31:44 +0000919}
Daniel Sanderse8982362014-06-13 12:49:06 +0000920def : MipsInstAlias<"dsubi $rs, $rt, $imm",
921 (DADDi GPR64Opnd:$rs, GPR64Opnd:$rt,
922 InvertedImOperand64:$imm),
923 0>, ISA_MIPS3_NOT_32R6_64R6;
924def : MipsInstAlias<"dsubi $rs, $imm",
925 (DADDi GPR64Opnd:$rs, GPR64Opnd:$rs,
926 InvertedImOperand64:$imm),
927 0>, ISA_MIPS3_NOT_32R6_64R6;
928def : MipsInstAlias<"dsub $rs, $rt, $imm",
929 (DADDi GPR64Opnd:$rs, GPR64Opnd:$rt,
930 InvertedImOperand64:$imm),
931 0>, ISA_MIPS3_NOT_32R6_64R6;
Daniel Sanders7d290b02014-05-08 16:12:31 +0000932def : MipsInstAlias<"dsub $rs, $imm",
933 (DADDi GPR64Opnd:$rs, GPR64Opnd:$rs,
934 InvertedImOperand64:$imm),
Daniel Sanderse8982362014-06-13 12:49:06 +0000935 0>, ISA_MIPS3_NOT_32R6_64R6;
Zlatko Buljan53a037f2016-04-08 07:27:26 +0000936let AdditionalPredicates = [NotInMicroMips] in {
937 def : MipsInstAlias<"dsubu $rt, $rs, $imm",
938 (DADDiu GPR64Opnd:$rt, GPR64Opnd:$rs,
939 InvertedImOperand64:$imm), 0>, ISA_MIPS3;
940 def : MipsInstAlias<"dsubu $rs, $imm",
941 (DADDiu GPR64Opnd:$rs, GPR64Opnd:$rs,
942 InvertedImOperand64:$imm), 0>, ISA_MIPS3;
943}
Daniel Sanders52bdd652014-05-09 09:24:49 +0000944def : MipsInstAlias<"dsra $rd, $rt, $rs",
Daniel Sandersf2056be2014-05-09 13:02:27 +0000945 (DSRAV GPR64Opnd:$rd, GPR64Opnd:$rt, GPR32Opnd:$rs), 0>,
946 ISA_MIPS3;
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000947let AdditionalPredicates = [NotInMicroMips] in {
Simon Dardis4155c8f2017-06-27 13:35:17 +0000948 def : MipsInstAlias<"dsll $rd, $rt, $rs",
949 (DSLLV GPR64Opnd:$rd, GPR64Opnd:$rt, GPR32Opnd:$rs), 0>,
950 ISA_MIPS3;
Hrvoje Varga24b975d2016-06-27 08:23:28 +0000951 def : MipsInstAlias<"dsrl $rd, $rt, $rs",
952 (DSRLV GPR64Opnd:$rd, GPR64Opnd:$rt, GPR32Opnd:$rs), 0>,
953 ISA_MIPS3;
Simon Dardis4155c8f2017-06-27 13:35:17 +0000954 def : MipsInstAlias<"dsrl $rd, $rt",
955 (DSRLV GPR64Opnd:$rd, GPR64Opnd:$rd, GPR32Opnd:$rt), 0>,
956 ISA_MIPS3;
957 def : MipsInstAlias<"dsll $rd, $rt",
958 (DSLLV GPR64Opnd:$rd, GPR64Opnd:$rd, GPR32Opnd:$rt), 0>,
959 ISA_MIPS3;
Simon Dardis6f83ae32017-09-14 15:17:50 +0000960 def : MipsInstAlias<"dins $rt, $rs, $pos, $size",
961 (DINSM GPR64Opnd:$rt, GPR64Opnd:$rs, uimm5:$pos,
962 uimm_range_2_64:$size), 0>, ISA_MIPS64R2;
963 def : MipsInstAlias<"dins $rt, $rs, $pos, $size",
964 (DINSU GPR64Opnd:$rt, GPR64Opnd:$rs, uimm5_plus32:$pos,
965 uimm5_plus1:$size), 0>, ISA_MIPS64R2;
Simon Dardis55e44672017-09-14 17:27:53 +0000966 def : MipsInstAlias<"dext $rt, $rs, $pos, $size",
967 (DEXTM GPR64Opnd:$rt, GPR64Opnd:$rs, uimm5:$pos,
968 uimm5_plus33:$size), 0>, ISA_MIPS64R2;
969 def : MipsInstAlias<"dext $rt, $rs, $pos, $size",
970 (DEXTU GPR64Opnd:$rt, GPR64Opnd:$rs, uimm5_plus32:$pos,
971 uimm5_plus1:$size), 0>, ISA_MIPS64R2;
Simon Dardis7bc8ad52018-02-21 00:06:53 +0000972 def : MipsInstAlias<"jalr.hb $rs", (JALR_HB64 RA_64, GPR64Opnd:$rs), 1>,
973 ISA_MIPS64;
David Chisnall6a00ab42012-10-11 10:21:34 +0000974// Two operand (implicit 0 selector) versions:
Hrvoje Varga2cb74ac2016-03-24 08:02:09 +0000975 def : MipsInstAlias<"dmtc0 $rt, $rd",
976 (DMTC0 COP0Opnd:$rd, GPR64Opnd:$rt, 0), 0>;
Zlatko Buljan6221be82016-03-31 08:51:24 +0000977 def : MipsInstAlias<"dmfc0 $rt, $rd",
978 (DMFC0 GPR64Opnd:$rt, COP0Opnd:$rd, 0), 0>;
Petar Jovanovicd4349f32018-04-27 09:12:08 +0000979 def : MipsInstAlias<"dmfgc0 $rt, $rd",
980 (DMFGC0 GPR64Opnd:$rt, COP0Opnd:$rd, 0), 0>,
981 ISA_MIPS64R5, ASE_VIRT;
982 def : MipsInstAlias<"dmtgc0 $rt, $rd",
983 (DMTGC0 COP0Opnd:$rd, GPR64Opnd:$rt, 0), 0>,
984 ISA_MIPS64R5, ASE_VIRT;
Hrvoje Varga2cb74ac2016-03-24 08:02:09 +0000985}
Daniel Sandersa3134fa2015-06-27 15:39:19 +0000986def : MipsInstAlias<"dmfc2 $rt, $rd", (DMFC2 GPR64Opnd:$rt, COP2Opnd:$rd, 0), 0>;
987def : MipsInstAlias<"dmtc2 $rt, $rd", (DMTC2 COP2Opnd:$rd, GPR64Opnd:$rt, 0), 0>;
David Chisnall6a00ab42012-10-11 10:21:34 +0000988
Daniel Sandersf6921302016-03-24 11:40:48 +0000989def : MipsInstAlias<"synciobdma", (SYNC 0x2), 0>, ASE_MIPS64_CNMIPS;
990def : MipsInstAlias<"syncs", (SYNC 0x6), 0>, ASE_MIPS64_CNMIPS;
991def : MipsInstAlias<"syncw", (SYNC 0x4), 0>, ASE_MIPS64_CNMIPS;
992def : MipsInstAlias<"syncws", (SYNC 0x5), 0>, ASE_MIPS64_CNMIPS;
Toma Tabacua90f1442015-02-24 11:52:19 +0000993
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +0000994// cnMIPS Aliases.
995
996// bbit* with $p 32-63 converted to bbit*32 with $p 0-31
997def : MipsInstAlias<"bbit0 $rs, $p, $offset",
998 (BBIT032 GPR64Opnd:$rs, uimm5_plus32_normalize_64:$p,
999 brtarget:$offset), 0>,
1000 ASE_CNMIPS;
1001def : MipsInstAlias<"bbit1 $rs, $p, $offset",
1002 (BBIT132 GPR64Opnd:$rs, uimm5_plus32_normalize_64:$p,
1003 brtarget:$offset), 0>,
1004 ASE_CNMIPS;
1005
1006// exts with $pos 32-63 in converted to exts32 with $pos 0-31
1007def : MipsInstAlias<"exts $rt, $rs, $pos, $lenm1",
1008 (EXTS32 GPR64Opnd:$rt, GPR64Opnd:$rs,
1009 uimm5_plus32_normalize:$pos, uimm5:$lenm1), 0>,
Petar Jovanovicb71386a2017-03-15 13:10:08 +00001010 ASE_MIPS64_CNMIPS;
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +00001011def : MipsInstAlias<"exts $rt, $pos, $lenm1",
1012 (EXTS32 GPR64Opnd:$rt, GPR64Opnd:$rt,
1013 uimm5_plus32_normalize:$pos, uimm5:$lenm1), 0>,
Petar Jovanovicb71386a2017-03-15 13:10:08 +00001014 ASE_MIPS64_CNMIPS;
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +00001015
1016// cins with $pos 32-63 in converted to cins32 with $pos 0-31
1017def : MipsInstAlias<"cins $rt, $rs, $pos, $lenm1",
1018 (CINS32 GPR64Opnd:$rt, GPR64Opnd:$rs,
1019 uimm5_plus32_normalize:$pos, uimm5:$lenm1), 0>,
Petar Jovanovicb71386a2017-03-15 13:10:08 +00001020 ASE_MIPS64_CNMIPS;
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +00001021def : MipsInstAlias<"cins $rt, $pos, $lenm1",
1022 (CINS32 GPR64Opnd:$rt, GPR64Opnd:$rt,
1023 uimm5_plus32_normalize:$pos, uimm5:$lenm1), 0>,
Petar Jovanovicb71386a2017-03-15 13:10:08 +00001024 ASE_MIPS64_CNMIPS;
Daniel Sandersdaa4b6f2015-11-26 16:35:41 +00001025
Toma Tabacua90f1442015-02-24 11:52:19 +00001026//===----------------------------------------------------------------------===//
1027// Assembler Pseudo Instructions
1028//===----------------------------------------------------------------------===//
1029
Toma Tabacue1e3ffe2015-03-04 13:01:14 +00001030class LoadImmediate64<string instr_asm, Operand Od, RegisterOperand RO> :
Toma Tabacua90f1442015-02-24 11:52:19 +00001031 MipsAsmPseudoInst<(outs RO:$rt), (ins Od:$imm64),
1032 !strconcat(instr_asm, "\t$rt, $imm64")> ;
Toma Tabacue1e3ffe2015-03-04 13:01:14 +00001033def LoadImm64 : LoadImmediate64<"dli", imm64, GPR64Opnd>;
Daniel Sandersa39ef1c2015-08-17 10:11:55 +00001034
1035def LoadAddrReg64 : MipsAsmPseudoInst<(outs GPR64Opnd:$rt), (ins mem:$addr),
1036 "dla\t$rt, $addr">;
1037def LoadAddrImm64 : MipsAsmPseudoInst<(outs GPR64Opnd:$rt), (ins imm64:$imm64),
1038 "dla\t$rt, $imm64">;
Simon Dardis3c82a642017-02-08 16:25:05 +00001039
1040def DMULImmMacro : MipsAsmPseudoInst<(outs), (ins GPR64Opnd:$rs, GPR64Opnd:$rt,
1041 simm32_relaxed:$imm),
1042 "dmul\t$rs, $rt, $imm">,
1043 ISA_MIPS3_NOT_32R6_64R6;
1044def DMULOMacro : MipsAsmPseudoInst<(outs), (ins GPR64Opnd:$rs, GPR64Opnd:$rt,
1045 GPR64Opnd:$rd),
1046 "dmulo\t$rs, $rt, $rd">,
1047 ISA_MIPS3_NOT_32R6_64R6;
1048def DMULOUMacro : MipsAsmPseudoInst<(outs), (ins GPR64Opnd:$rs, GPR64Opnd:$rt,
1049 GPR64Opnd:$rd),
1050 "dmulou\t$rs, $rt, $rd">,
1051 ISA_MIPS3_NOT_32R6_64R6;
1052
1053def DMULMacro : MipsAsmPseudoInst<(outs), (ins GPR64Opnd:$rs, GPR64Opnd:$rt,
1054 GPR64Opnd:$rd),
1055 "dmul\t$rs, $rt, $rd"> {
1056 let InsnPredicates = [HasMips3, NotMips64r6, NotCnMips];
1057}
Simon Dardis509da1a2017-02-13 16:06:48 +00001058
1059let AdditionalPredicates = [NotInMicroMips] in {
1060 def DSDivMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd),
1061 (ins GPR64Opnd:$rs, GPR64Opnd:$rt),
1062 "ddiv\t$rd, $rs, $rt">,
1063 ISA_MIPS3_NOT_32R6_64R6;
1064 def DSDivIMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd),
1065 (ins GPR64Opnd:$rs, imm64:$imm),
1066 "ddiv\t$rd, $rs, $imm">,
1067 ISA_MIPS3_NOT_32R6_64R6;
1068 def DUDivMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd),
1069 (ins GPR64Opnd:$rs, GPR64Opnd:$rt),
1070 "ddivu\t$rd, $rs, $rt">,
1071 ISA_MIPS3_NOT_32R6_64R6;
1072 def DUDivIMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd),
1073 (ins GPR64Opnd:$rs, imm64:$imm),
1074 "ddivu\t$rd, $rs, $imm">,
1075 ISA_MIPS3_NOT_32R6_64R6;
1076
1077 // GAS expands 'div' and 'ddiv' differently when the destination
1078 // register is $zero and the instruction is in the two operand
1079 // form. 'ddiv' gets expanded, while 'div' is not expanded.
1080
1081 def : MipsInstAlias<"ddiv $rs, $rt", (DSDivMacro GPR64Opnd:$rs,
1082 GPR64Opnd:$rs,
1083 GPR64Opnd:$rt), 0>,
1084 ISA_MIPS3_NOT_32R6_64R6;
1085 def : MipsInstAlias<"ddiv $rd, $imm", (DSDivIMacro GPR64Opnd:$rd,
1086 GPR64Opnd:$rd,
1087 imm64:$imm), 0>,
1088 ISA_MIPS3_NOT_32R6_64R6;
1089
1090 // GAS expands 'divu' and 'ddivu' differently when the destination
1091 // register is $zero and the instruction is in the two operand
1092 // form. 'ddivu' gets expanded, while 'divu' is not expanded.
1093
1094 def : MipsInstAlias<"ddivu $rt, $rs", (DUDivMacro GPR64Opnd:$rt,
1095 GPR64Opnd:$rt,
1096 GPR64Opnd:$rs), 0>,
1097 ISA_MIPS3_NOT_32R6_64R6;
1098 def : MipsInstAlias<"ddivu $rd, $imm", (DUDivIMacro GPR64Opnd:$rd,
1099 GPR64Opnd:$rd,
1100 imm64:$imm), 0>,
1101 ISA_MIPS3_NOT_32R6_64R6;
Stefan Maksimovic0a239982018-07-09 13:06:44 +00001102 def DSRemMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd),
1103 (ins GPR64Opnd:$rs, GPR64Opnd:$rt),
1104 "drem\t$rd, $rs, $rt">,
1105 ISA_MIPS3_NOT_32R6_64R6;
1106 def DSRemIMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd),
1107 (ins GPR64Opnd:$rs, simm32_relaxed:$imm),
1108 "drem\t$rd, $rs, $imm">,
1109 ISA_MIPS3_NOT_32R6_64R6;
1110 def DURemMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd),
1111 (ins GPR64Opnd:$rs, GPR64Opnd:$rt),
1112 "dremu\t$rd, $rs, $rt">,
1113 ISA_MIPS3_NOT_32R6_64R6;
1114 def DURemIMacro : MipsAsmPseudoInst<(outs GPR64Opnd:$rd),
1115 (ins GPR64Opnd:$rs, simm32_relaxed:$imm),
1116 "dremu\t$rd, $rs, $imm">,
1117 ISA_MIPS3_NOT_32R6_64R6;
1118 def : MipsInstAlias<"drem $rt, $rs", (DSRemMacro GPR64Opnd:$rt,
1119 GPR64Opnd:$rt,
1120 GPR64Opnd:$rs), 0>,
1121 ISA_MIPS3_NOT_32R6_64R6;
1122 def : MipsInstAlias<"drem $rd, $imm", (DSRemIMacro GPR64Opnd:$rd,
1123 GPR64Opnd:$rd,
1124 simm32_relaxed:$imm), 0>,
1125 ISA_MIPS3_NOT_32R6_64R6;
1126 def : MipsInstAlias<"dremu $rt, $rs", (DURemMacro GPR64Opnd:$rt,
1127 GPR64Opnd:$rt,
1128 GPR64Opnd:$rs), 0>,
1129 ISA_MIPS3_NOT_32R6_64R6;
1130 def : MipsInstAlias<"dremu $rd, $imm", (DURemIMacro GPR64Opnd:$rd,
1131 GPR64Opnd:$rd,
1132 simm32_relaxed:$imm), 0>,
1133 ISA_MIPS3_NOT_32R6_64R6;
Simon Dardis509da1a2017-02-13 16:06:48 +00001134}
Simon Dardise3cceed2017-02-28 15:55:23 +00001135
1136def NORImm64 : NORIMM_DESC_BASE<GPR64Opnd, imm64>, GPR_64;
1137def : MipsInstAlias<"nor\t$rs, $imm", (NORImm64 GPR64Opnd:$rs, GPR64Opnd:$rs,
1138 imm64:$imm)>, GPR_64;
1139def SLTImm64 : MipsAsmPseudoInst<(outs GPR64Opnd:$rs),
1140 (ins GPR64Opnd:$rt, imm64:$imm),
1141 "slt\t$rs, $rt, $imm">, GPR_64;
1142def : MipsInstAlias<"slt\t$rs, $imm", (SLTImm64 GPR64Opnd:$rs, GPR64Opnd:$rs,
1143 imm64:$imm)>, GPR_64;
1144def SLTUImm64 : MipsAsmPseudoInst<(outs GPR64Opnd:$rs),
1145 (ins GPR64Opnd:$rt, imm64:$imm),
1146 "sltu\t$rs, $rt, $imm">, GPR_64;
1147def : MipsInstAlias<"sltu\t$rs, $imm", (SLTUImm64 GPR64Opnd:$rs, GPR64Opnd:$rs,
1148 imm64:$imm)>, GPR_64;
Simon Atanasyan32d8d1b2018-09-11 09:57:25 +00001149
1150def : MipsInstAlias<"rdhwr $rt, $rs",
1151 (RDHWR64 GPR64Opnd:$rt, HWRegsOpnd:$rs, 0), 1>, GPR_64;