[XCore] Remove '-' from back branch asm syntax.
[oota-llvm.git] / lib / Target / XCore / XCoreInstrInfo.td
1 //===-- XCoreInstrInfo.td - Target Description for XCore ---*- 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 the XCore instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 // Uses of CP, DP are not currently reflected in the patterns, since
15 // having a physical register as an operand prevents loop hoisting and
16 // since the value of these registers never changes during the life of the
17 // function.
18
19 //===----------------------------------------------------------------------===//
20 // Instruction format superclass.
21 //===----------------------------------------------------------------------===//
22
23 include "XCoreInstrFormats.td"
24
25 //===----------------------------------------------------------------------===//
26 // XCore specific DAG Nodes.
27 //
28
29 // Call
30 def SDT_XCoreBranchLink : SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
31 def XCoreBranchLink     : SDNode<"XCoreISD::BL",SDT_XCoreBranchLink,
32                             [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
33                              SDNPVariadic]>;
34
35 def XCoreRetsp : SDNode<"XCoreISD::RETSP", SDTBrind,
36                       [SDNPHasChain, SDNPOptInGlue, SDNPMayLoad, SDNPVariadic]>;
37
38 def SDT_XCoreBR_JT    : SDTypeProfile<0, 2,
39                                       [SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
40
41 def XCoreBR_JT : SDNode<"XCoreISD::BR_JT", SDT_XCoreBR_JT,
42                         [SDNPHasChain]>;
43
44 def XCoreBR_JT32 : SDNode<"XCoreISD::BR_JT32", SDT_XCoreBR_JT,
45                         [SDNPHasChain]>;
46
47 def SDT_XCoreAddress    : SDTypeProfile<1, 1,
48                             [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
49
50 def pcrelwrapper : SDNode<"XCoreISD::PCRelativeWrapper", SDT_XCoreAddress,
51                            []>;
52
53 def dprelwrapper : SDNode<"XCoreISD::DPRelativeWrapper", SDT_XCoreAddress,
54                            []>;
55
56 def cprelwrapper : SDNode<"XCoreISD::CPRelativeWrapper", SDT_XCoreAddress,
57                            []>;
58
59 def SDT_XCoreStwsp    : SDTypeProfile<0, 2, [SDTCisInt<1>]>;
60 def XCoreStwsp        : SDNode<"XCoreISD::STWSP", SDT_XCoreStwsp,
61                                [SDNPHasChain, SDNPMayStore]>;
62
63 // These are target-independent nodes, but have target-specific formats.
64 def SDT_XCoreCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
65 def SDT_XCoreCallSeqEnd   : SDCallSeqEnd<[ SDTCisVT<0, i32>,
66                                         SDTCisVT<1, i32> ]>;
67
68 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_XCoreCallSeqStart,
69                            [SDNPHasChain, SDNPOutGlue]>;
70 def callseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_XCoreCallSeqEnd,
71                            [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
72
73 //===----------------------------------------------------------------------===//
74 // Instruction Pattern Stuff
75 //===----------------------------------------------------------------------===//
76
77 def div4_xform : SDNodeXForm<imm, [{
78   // Transformation function: imm/4
79   assert(N->getZExtValue() % 4 == 0);
80   return getI32Imm(N->getZExtValue()/4);
81 }]>;
82
83 def msksize_xform : SDNodeXForm<imm, [{
84   // Transformation function: get the size of a mask
85   assert(isMask_32(N->getZExtValue()));
86   // look for the first non-zero bit
87   return getI32Imm(32 - CountLeadingZeros_32(N->getZExtValue()));
88 }]>;
89
90 def neg_xform : SDNodeXForm<imm, [{
91   // Transformation function: -imm
92   uint32_t value = N->getZExtValue();
93   return getI32Imm(-value);
94 }]>;
95
96 def bpwsub_xform : SDNodeXForm<imm, [{
97   // Transformation function: 32-imm
98   uint32_t value = N->getZExtValue();
99   return getI32Imm(32-value);
100 }]>;
101
102 def div4neg_xform : SDNodeXForm<imm, [{
103   // Transformation function: -imm/4
104   uint32_t value = N->getZExtValue();
105   assert(-value % 4 == 0);
106   return getI32Imm(-value/4);
107 }]>;
108
109 def immUs4Neg : PatLeaf<(imm), [{
110   uint32_t value = (uint32_t)N->getZExtValue();
111   return (-value)%4 == 0 && (-value)/4 <= 11;
112 }]>;
113
114 def immUs4 : PatLeaf<(imm), [{
115   uint32_t value = (uint32_t)N->getZExtValue();
116   return value%4 == 0 && value/4 <= 11;
117 }]>;
118
119 def immUsNeg : PatLeaf<(imm), [{
120   return -((uint32_t)N->getZExtValue()) <= 11;
121 }]>;
122
123 def immUs : PatLeaf<(imm), [{
124   return (uint32_t)N->getZExtValue() <= 11;
125 }]>;
126
127 def immU6 : PatLeaf<(imm), [{
128   return (uint32_t)N->getZExtValue() < (1 << 6);
129 }]>;
130
131 def immU10 : PatLeaf<(imm), [{
132   return (uint32_t)N->getZExtValue() < (1 << 10);
133 }]>;
134
135 def immU16 : PatLeaf<(imm), [{
136   return (uint32_t)N->getZExtValue() < (1 << 16);
137 }]>;
138
139 def immU20 : PatLeaf<(imm), [{
140   return (uint32_t)N->getZExtValue() < (1 << 20);
141 }]>;
142
143 def immMskBitp : PatLeaf<(imm), [{ return immMskBitp(N); }]>;
144
145 def immBitp : PatLeaf<(imm), [{
146   uint32_t value = (uint32_t)N->getZExtValue();
147   return (value >= 1 && value <= 8)
148           || value == 16
149           || value == 24
150           || value == 32;
151 }]>;
152
153 def immBpwSubBitp : PatLeaf<(imm), [{
154   uint32_t value = (uint32_t)N->getZExtValue();
155   return (value >= 24 && value <= 31)
156           || value == 16
157           || value == 8
158           || value == 0;
159 }]>;
160
161 def lda16f : PatFrag<(ops node:$addr, node:$offset),
162                      (add node:$addr, (shl node:$offset, 1))>;
163 def lda16b : PatFrag<(ops node:$addr, node:$offset),
164                      (sub node:$addr, (shl node:$offset, 1))>;
165 def ldawf : PatFrag<(ops node:$addr, node:$offset),
166                      (add node:$addr, (shl node:$offset, 2))>;
167 def ldawb : PatFrag<(ops node:$addr, node:$offset),
168                      (sub node:$addr, (shl node:$offset, 2))>;
169
170 // Instruction operand types
171 def calltarget  : Operand<i32>;
172 def brtarget : Operand<OtherVT>;
173 def brtarget_neg : Operand<OtherVT> {
174   let DecoderMethod = "DecodeNegImmOperand";
175 }
176
177 // Addressing modes
178 def ADDRspii : ComplexPattern<i32, 2, "SelectADDRspii", [add, frameindex], []>;
179
180 // Address operands
181 def MEMii : Operand<i32> {
182   let MIOperandInfo = (ops i32imm, i32imm);
183 }
184
185 // Jump tables.
186 def InlineJT : Operand<i32> {
187   let PrintMethod = "printInlineJT";
188 }
189
190 def InlineJT32 : Operand<i32> {
191   let PrintMethod = "printInlineJT32";
192 }
193
194 //===----------------------------------------------------------------------===//
195 // Instruction Class Templates
196 //===----------------------------------------------------------------------===//
197
198 // Three operand short
199
200 multiclass F3R_2RUS<bits<5> opc1, bits<5> opc2, string OpcStr, SDNode OpNode> {
201   def _3r: _F3R<opc1, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
202                 !strconcat(OpcStr, " $dst, $b, $c"),
203                 [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
204   def _2rus : _F2RUS<opc2, (outs GRRegs:$dst), (ins GRRegs:$b, i32imm:$c),
205                      !strconcat(OpcStr, " $dst, $b, $c"),
206                      [(set GRRegs:$dst, (OpNode GRRegs:$b, immUs:$c))]>;
207 }
208
209 multiclass F3R_2RUS_np<bits<5> opc1, bits<5> opc2, string OpcStr> {
210   def _3r: _F3R<opc1, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
211                 !strconcat(OpcStr, " $dst, $b, $c"), []>;
212   def _2rus : _F2RUS<opc2, (outs GRRegs:$dst), (ins GRRegs:$b, i32imm:$c),
213                      !strconcat(OpcStr, " $dst, $b, $c"), []>;
214 }
215
216 multiclass F3R_2RBITP<bits<5> opc1, bits<5> opc2, string OpcStr,
217                       SDNode OpNode> {
218   def _3r: _F3R<opc1, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
219                 !strconcat(OpcStr, " $dst, $b, $c"),
220                 [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
221   def _2rus : _F2RUSBitp<opc2, (outs GRRegs:$dst), (ins GRRegs:$b, i32imm:$c),
222                          !strconcat(OpcStr, " $dst, $b, $c"),
223                          [(set GRRegs:$dst, (OpNode GRRegs:$b, immBitp:$c))]>;
224 }
225
226 class F3R<bits<5> opc, string OpcStr, SDNode OpNode> :
227   _F3R<opc, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
228        !strconcat(OpcStr, " $dst, $b, $c"),
229        [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
230
231 class F3R_np<bits<5> opc, string OpcStr> :
232   _F3R<opc, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
233        !strconcat(OpcStr, " $dst, $b, $c"), []>;
234 // Three operand long
235
236 /// FL3R_L2RUS multiclass - Define a normal FL3R/FL2RUS pattern in one shot.
237 multiclass FL3R_L2RUS<bits<9> opc1, bits<9> opc2, string OpcStr,
238                       SDNode OpNode> {
239   def _l3r: _FL3R<opc1, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
240                   !strconcat(OpcStr, " $dst, $b, $c"),
241                   [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
242   def _l2rus : _FL2RUS<opc2, (outs GRRegs:$dst), (ins GRRegs:$b, i32imm:$c),
243                        !strconcat(OpcStr, " $dst, $b, $c"),
244                        [(set GRRegs:$dst, (OpNode GRRegs:$b, immUs:$c))]>;
245 }
246
247 /// FL3R_L2RUS multiclass - Define a normal FL3R/FL2RUS pattern in one shot.
248 multiclass FL3R_L2RBITP<bits<9> opc1, bits<9> opc2, string OpcStr,
249                         SDNode OpNode> {
250   def _l3r: _FL3R<opc1, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
251                   !strconcat(OpcStr, " $dst, $b, $c"),
252                   [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
253   def _l2rus : _FL2RUSBitp<opc2, (outs GRRegs:$dst), (ins GRRegs:$b, i32imm:$c),
254                            !strconcat(OpcStr, " $dst, $b, $c"),
255                            [(set GRRegs:$dst, (OpNode GRRegs:$b, immBitp:$c))]>;
256 }
257
258 class FL3R<bits<9> opc, string OpcStr, SDNode OpNode> :
259   _FL3R<opc, (outs GRRegs:$dst), (ins GRRegs:$b, GRRegs:$c),
260         !strconcat(OpcStr, " $dst, $b, $c"),
261         [(set GRRegs:$dst, (OpNode GRRegs:$b, GRRegs:$c))]>;
262
263 // Register - U6
264 // Operand register - U6
265 multiclass FRU6_LRU6_branch<bits<6> opc, string OpcStr> {
266   def _ru6: _FRU6<opc, (outs), (ins GRRegs:$a, brtarget:$b),
267                   !strconcat(OpcStr, " $a, $b"), []>;
268   def _lru6: _FLRU6<opc, (outs), (ins GRRegs:$a, brtarget:$b),
269                     !strconcat(OpcStr, " $a, $b"), []>;
270 }
271
272 multiclass FRU6_LRU6_backwards_branch<bits<6> opc, string OpcStr> {
273   def _ru6: _FRU6<opc, (outs), (ins GRRegs:$a, brtarget_neg:$b),
274                   !strconcat(OpcStr, " $a, $b"), []>;
275   def _lru6: _FLRU6<opc, (outs), (ins GRRegs:$a, brtarget_neg:$b),
276                     !strconcat(OpcStr, " $a, $b"), []>;
277 }
278
279 multiclass FRU6_LRU6_cp<bits<6> opc, string OpcStr> {
280   def _ru6: _FRU6<opc, (outs RRegs:$a), (ins i32imm:$b),
281                   !strconcat(OpcStr, " $a, cp[$b]"), []>;
282   def _lru6: _FLRU6<opc, (outs RRegs:$a), (ins i32imm:$b),
283                     !strconcat(OpcStr, " $a, cp[$b]"), []>;
284 }
285
286 // U6
287 multiclass FU6_LU6<bits<10> opc, string OpcStr, SDNode OpNode> {
288   def _u6: _FU6<opc, (outs), (ins i32imm:$a), !strconcat(OpcStr, " $a"),
289                 [(OpNode immU6:$a)]>;
290   def _lu6: _FLU6<opc, (outs), (ins i32imm:$a), !strconcat(OpcStr, " $a"),
291                   [(OpNode immU16:$a)]>;
292 }
293
294 multiclass FU6_LU6_int<bits<10> opc, string OpcStr, Intrinsic Int> {
295   def _u6: _FU6<opc, (outs), (ins i32imm:$a), !strconcat(OpcStr, " $a"),
296                 [(Int immU6:$a)]>;
297   def _lu6: _FLU6<opc, (outs), (ins i32imm:$a), !strconcat(OpcStr, " $a"),
298                   [(Int immU16:$a)]>;
299 }
300
301 multiclass FU6_LU6_np<bits<10> opc, string OpcStr> {
302   def _u6: _FU6<opc, (outs), (ins i32imm:$a), !strconcat(OpcStr, " $a"), []>;
303   def _lu6: _FLU6<opc, (outs), (ins i32imm:$a), !strconcat(OpcStr, " $a"), []>;
304 }
305
306 // Two operand short
307
308 class F2R_np<bits<6> opc, string OpcStr> :
309   _F2R<opc, (outs GRRegs:$dst), (ins GRRegs:$b),
310        !strconcat(OpcStr, " $dst, $b"), []>;
311
312 // Two operand long
313
314 //===----------------------------------------------------------------------===//
315 // Pseudo Instructions
316 //===----------------------------------------------------------------------===//
317
318 let Defs = [SP], Uses = [SP] in {
319 def ADJCALLSTACKDOWN : PseudoInstXCore<(outs), (ins i32imm:$amt),
320                                "# ADJCALLSTACKDOWN $amt",
321                                [(callseq_start timm:$amt)]>;
322 def ADJCALLSTACKUP : PseudoInstXCore<(outs), (ins i32imm:$amt1, i32imm:$amt2),
323                             "# ADJCALLSTACKUP $amt1",
324                             [(callseq_end timm:$amt1, timm:$amt2)]>;
325 }
326
327 def LDWFI : PseudoInstXCore<(outs GRRegs:$dst), (ins MEMii:$addr),
328                              "# LDWFI $dst, $addr",
329                              [(set GRRegs:$dst, (load ADDRspii:$addr))]>;
330
331 def LDAWFI : PseudoInstXCore<(outs GRRegs:$dst), (ins MEMii:$addr),
332                              "# LDAWFI $dst, $addr",
333                              [(set GRRegs:$dst, ADDRspii:$addr)]>;
334
335 def STWFI : PseudoInstXCore<(outs), (ins GRRegs:$src, MEMii:$addr),
336                             "# STWFI $src, $addr",
337                             [(store GRRegs:$src, ADDRspii:$addr)]>;
338
339 // SELECT_CC_* - Used to implement the SELECT_CC DAG operation.  Expanded after
340 // instruction selection into a branch sequence.
341 let usesCustomInserter = 1 in {
342   def SELECT_CC : PseudoInstXCore<(outs GRRegs:$dst),
343                               (ins GRRegs:$cond, GRRegs:$T, GRRegs:$F),
344                               "# SELECT_CC PSEUDO!",
345                               [(set GRRegs:$dst,
346                                  (select GRRegs:$cond, GRRegs:$T, GRRegs:$F))]>;
347 }
348
349 //===----------------------------------------------------------------------===//
350 // Instructions
351 //===----------------------------------------------------------------------===//
352
353 // Three operand short
354 defm ADD : F3R_2RUS<0b00010, 0b10010, "add", add>;
355 defm SUB : F3R_2RUS<0b00011, 0b10011, "sub", sub>;
356 let neverHasSideEffects = 1 in {
357 defm EQ : F3R_2RUS_np<0b00110, 0b10110, "eq">;
358 def LSS_3r : F3R_np<0b11000, "lss">;
359 def LSU_3r : F3R_np<0b11001, "lsu">;
360 }
361 def AND_3r : F3R<0b00111, "and", and>;
362 def OR_3r : F3R<0b01000, "or", or>;
363
364 let mayLoad=1 in {
365 def LDW_3r : _F3R<0b01001, (outs GRRegs:$dst),
366                   (ins GRRegs:$addr, GRRegs:$offset),
367                   "ldw $dst, $addr[$offset]", []>;
368
369 def LDW_2rus : _F2RUS<0b00001, (outs GRRegs:$dst),
370                       (ins GRRegs:$addr, i32imm:$offset),
371                       "ldw $dst, $addr[$offset]", []>;
372
373 def LD16S_3r :  _F3R<0b10000, (outs GRRegs:$dst),
374                      (ins GRRegs:$addr, GRRegs:$offset),
375                      "ld16s $dst, $addr[$offset]", []>;
376
377 def LD8U_3r :  _F3R<0b10001, (outs GRRegs:$dst),
378                     (ins GRRegs:$addr, GRRegs:$offset),
379                     "ld8u $dst, $addr[$offset]", []>;
380 }
381
382 let mayStore=1 in {
383 def STW_l3r : _FL3R<0b000001100, (outs),
384                     (ins GRRegs:$val, GRRegs:$addr, GRRegs:$offset),
385                     "stw $val, $addr[$offset]", []>;
386
387 def STW_2rus : _F2RUS<0b0000, (outs),
388                       (ins GRRegs:$val, GRRegs:$addr, i32imm:$offset),
389                       "stw $val, $addr[$offset]", []>;
390 }
391
392 defm SHL : F3R_2RBITP<0b00100, 0b10100, "shl", shl>;
393 defm SHR : F3R_2RBITP<0b00101, 0b10101, "shr", srl>;
394
395 // The first operand is treated as an immediate since it refers to a register
396 // number in another thread.
397 def TSETR_3r : _F3RImm<0b10111, (outs), (ins i32imm:$a, GRRegs:$b, GRRegs:$c),
398                        "set t[$c]:r$a, $b", []>;
399
400 // Three operand long
401 def LDAWF_l3r : _FL3R<0b000111100, (outs GRRegs:$dst),
402                       (ins GRRegs:$addr, GRRegs:$offset),
403                       "ldaw $dst, $addr[$offset]",
404                       [(set GRRegs:$dst,
405                          (ldawf GRRegs:$addr, GRRegs:$offset))]>;
406
407 let neverHasSideEffects = 1 in
408 def LDAWF_l2rus : _FL2RUS<0b100111100, (outs GRRegs:$dst),
409                           (ins GRRegs:$addr, i32imm:$offset),
410                           "ldaw $dst, $addr[$offset]", []>;
411
412 def LDAWB_l3r : _FL3R<0b001001100, (outs GRRegs:$dst),
413                       (ins GRRegs:$addr, GRRegs:$offset),
414                       "ldaw $dst, $addr[-$offset]",
415                       [(set GRRegs:$dst,
416                          (ldawb GRRegs:$addr, GRRegs:$offset))]>;
417
418 let neverHasSideEffects = 1 in
419 def LDAWB_l2rus : _FL2RUS<0b101001100, (outs GRRegs:$dst),
420                          (ins GRRegs:$addr, i32imm:$offset),
421                          "ldaw $dst, $addr[-$offset]", []>;
422
423 def LDA16F_l3r : _FL3R<0b001011100, (outs GRRegs:$dst),
424                        (ins GRRegs:$addr, GRRegs:$offset),
425                        "lda16 $dst, $addr[$offset]",
426                        [(set GRRegs:$dst,
427                           (lda16f GRRegs:$addr, GRRegs:$offset))]>;
428
429 def LDA16B_l3r : _FL3R<0b001101100, (outs GRRegs:$dst),
430                        (ins GRRegs:$addr, GRRegs:$offset),
431                        "lda16 $dst, $addr[-$offset]",
432                        [(set GRRegs:$dst,
433                           (lda16b GRRegs:$addr, GRRegs:$offset))]>;
434
435 def MUL_l3r : FL3R<0b001111100, "mul", mul>;
436 // Instructions which may trap are marked as side effecting.
437 let hasSideEffects = 1 in {
438 def DIVS_l3r : FL3R<0b010001100, "divs", sdiv>;
439 def DIVU_l3r : FL3R<0b010011100, "divu", udiv>;
440 def REMS_l3r : FL3R<0b110001100, "rems", srem>;
441 def REMU_l3r : FL3R<0b110011100, "remu", urem>;
442 }
443 def XOR_l3r : FL3R<0b000011100, "xor", xor>;
444 defm ASHR : FL3R_L2RBITP<0b000101100, 0b100101100, "ashr", sra>;
445
446 let Constraints = "$src1 = $dst" in
447 def CRC_l3r : _FL3RSrcDst<0b101011100, (outs GRRegs:$dst),
448                           (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3),
449                           "crc32 $dst, $src2, $src3",
450                           [(set GRRegs:$dst,
451                              (int_xcore_crc32 GRRegs:$src1, GRRegs:$src2,
452                                               GRRegs:$src3))]>;
453
454 let mayStore=1 in {
455 def ST16_l3r : _FL3R<0b100001100, (outs),
456                      (ins GRRegs:$val, GRRegs:$addr, GRRegs:$offset),
457                      "st16 $val, $addr[$offset]", []>;
458
459 def ST8_l3r : _FL3R<0b100011100, (outs),
460                     (ins GRRegs:$val, GRRegs:$addr, GRRegs:$offset),
461                     "st8 $val, $addr[$offset]", []>;
462 }
463
464 def INPW_l2rus : _FL2RUSBitp<0b100101110, (outs GRRegs:$a),
465                              (ins GRRegs:$b, i32imm:$c), "inpw $a, res[$b], $c",
466                              []>;
467
468 def OUTPW_l2rus : _FL2RUSBitp<0b100101101, (outs),
469                               (ins GRRegs:$a, GRRegs:$b, i32imm:$c),
470                               "outpw res[$b], $a, $c", []>;
471
472 // Four operand long
473 let Constraints = "$e = $a,$f = $b" in {
474 def MACCU_l4r : _FL4RSrcDstSrcDst<
475   0b000001, (outs GRRegs:$a, GRRegs:$b),
476   (ins GRRegs:$e, GRRegs:$f, GRRegs:$c, GRRegs:$d), "maccu $a, $b, $c, $d", []>;
477
478 def MACCS_l4r : _FL4RSrcDstSrcDst<
479   0b000010, (outs GRRegs:$a, GRRegs:$b),
480   (ins GRRegs:$e, GRRegs:$f, GRRegs:$c, GRRegs:$d), "maccs $a, $b, $c, $d", []>;
481 }
482
483 let Constraints = "$e = $b" in
484 def CRC8_l4r : _FL4RSrcDst<0b000000, (outs GRRegs:$a, GRRegs:$b),
485                            (ins GRRegs:$e, GRRegs:$c, GRRegs:$d),
486                            "crc8 $b, $a, $c, $d", []>;
487
488 // Five operand long
489
490 def LADD_l5r : _FL5R<0b000001, (outs GRRegs:$dst1, GRRegs:$dst2),
491                      (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3),
492                      "ladd $dst2, $dst1, $src1, $src2, $src3",
493                      []>;
494
495 def LSUB_l5r : _FL5R<0b000010, (outs GRRegs:$dst1, GRRegs:$dst2),
496                      (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3),
497                      "lsub $dst2, $dst1, $src1, $src2, $src3", []>;
498
499 def LDIVU_l5r : _FL5R<0b000000, (outs GRRegs:$dst1, GRRegs:$dst2),
500                       (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3),
501                       "ldivu $dst1, $dst2, $src3, $src1, $src2", []>;
502
503 // Six operand long
504
505 def LMUL_l6r : _FL6R<
506   0b00000, (outs GRRegs:$dst1, GRRegs:$dst2),
507   (ins GRRegs:$src1, GRRegs:$src2, GRRegs:$src3, GRRegs:$src4),
508   "lmul $dst1, $dst2, $src1, $src2, $src3, $src4", []>;
509
510 // Register - U6
511
512 //let Uses = [DP] in ...
513 let neverHasSideEffects = 1, isReMaterializable = 1 in
514 def LDAWDP_ru6: _FRU6<0b011000, (outs RRegs:$a), (ins i32imm:$b),
515                       "ldaw $a, dp[$b]", []>;
516
517 let isReMaterializable = 1 in                    
518 def LDAWDP_lru6: _FLRU6<0b011000, (outs RRegs:$a), (ins i32imm:$b),
519                         "ldaw $a, dp[$b]",
520                         [(set RRegs:$a, (dprelwrapper tglobaladdr:$b))]>;
521
522 let mayLoad=1 in
523 def LDWDP_ru6: _FRU6<0b010110, (outs RRegs:$a), (ins i32imm:$b),
524                      "ldw $a, dp[$b]", []>;
525
526 def LDWDP_lru6: _FLRU6<0b010110, (outs RRegs:$a), (ins i32imm:$b),
527                        "ldw $a, dp[$b]",
528                        [(set RRegs:$a, (load (dprelwrapper tglobaladdr:$b)))]>;
529
530 let mayStore=1 in
531 def STWDP_ru6 : _FRU6<0b010100, (outs), (ins RRegs:$a, i32imm:$b),
532                       "stw $a, dp[$b]", []>;
533
534 def STWDP_lru6 : _FLRU6<0b010100, (outs), (ins RRegs:$a, i32imm:$b),
535                         "stw $a, dp[$b]",
536                         [(store RRegs:$a, (dprelwrapper tglobaladdr:$b))]>;
537
538 //let Uses = [CP] in ..
539 let mayLoad = 1, isReMaterializable = 1, neverHasSideEffects = 1 in
540 defm LDWCP : FRU6_LRU6_cp<0b011011, "ldw">;
541
542 let Uses = [SP] in {
543 let mayStore=1 in {
544 def STWSP_ru6 : _FRU6<0b010101, (outs), (ins RRegs:$a, i32imm:$b),
545                       "stw $a, sp[$b]",
546                       [(XCoreStwsp RRegs:$a, immU6:$b)]>;
547
548 def STWSP_lru6 : _FLRU6<0b010101, (outs), (ins RRegs:$a, i32imm:$b),
549                         "stw $a, sp[$b]",
550                         [(XCoreStwsp RRegs:$a, immU16:$b)]>;
551 }
552
553 let mayLoad=1 in {
554 def LDWSP_ru6 : _FRU6<0b010111, (outs RRegs:$a), (ins i32imm:$b),
555                       "ldw $a, sp[$b]", []>;
556
557 def LDWSP_lru6 : _FLRU6<0b010111, (outs RRegs:$a), (ins i32imm:$b),
558                         "ldw $a, sp[$b]", []>;
559 }
560
561 let neverHasSideEffects = 1 in {
562 def LDAWSP_ru6 : _FRU6<0b011001, (outs RRegs:$a), (ins i32imm:$b),
563                        "ldaw $a, sp[$b]", []>;
564
565 def LDAWSP_lru6 : _FLRU6<0b011001, (outs RRegs:$a), (ins i32imm:$b),
566                          "ldaw $a, sp[$b]", []>;
567 }
568 }
569
570 let isReMaterializable = 1 in {
571 def LDC_ru6 : _FRU6<0b011010, (outs RRegs:$a), (ins i32imm:$b),
572                     "ldc $a, $b", [(set RRegs:$a, immU6:$b)]>;
573
574 def LDC_lru6 : _FLRU6<0b011010, (outs RRegs:$a), (ins i32imm:$b),
575                       "ldc $a, $b", [(set RRegs:$a, immU16:$b)]>;
576 }
577
578 def SETC_ru6 : _FRU6<0b111010, (outs), (ins GRRegs:$a, i32imm:$b),
579                      "setc res[$a], $b",
580                      [(int_xcore_setc GRRegs:$a, immU6:$b)]>;
581
582 def SETC_lru6 : _FLRU6<0b111010, (outs), (ins GRRegs:$a, i32imm:$b),
583                        "setc res[$a], $b",
584                        [(int_xcore_setc GRRegs:$a, immU16:$b)]>;
585
586 // Operand register - U6
587 let isBranch = 1, isTerminator = 1 in {
588 defm BRFT: FRU6_LRU6_branch<0b011100, "bt">;
589 defm BRBT: FRU6_LRU6_backwards_branch<0b011101, "bt">;
590 defm BRFF: FRU6_LRU6_branch<0b011110, "bf">;
591 defm BRBF: FRU6_LRU6_backwards_branch<0b011111, "bf">;
592 }
593
594 // U6
595 let Defs = [SP], Uses = [SP] in {
596 let neverHasSideEffects = 1 in
597 defm EXTSP : FU6_LU6_np<0b0111011110, "extsp">;
598
599 let mayStore = 1 in
600 defm ENTSP : FU6_LU6_np<0b0111011101, "entsp">;
601
602 let isReturn = 1, isTerminator = 1, mayLoad = 1, isBarrier = 1 in {
603 defm RETSP : FU6_LU6<0b0111011111, "retsp", XCoreRetsp>;
604 }
605 }
606
607 let neverHasSideEffects = 1 in
608 defm EXTDP : FU6_LU6_np<0b0111001110, "extdp">;
609
610 let Uses = [R11], isCall=1 in
611 defm BLAT : FU6_LU6_np<0b0111001101, "blat">;
612
613 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
614 def BRBU_u6 : _FU6<0b0111011100, (outs), (ins brtarget_neg:$a), "bu $a", []>;
615
616 def BRBU_lu6 : _FLU6<0b0111011100, (outs), (ins brtarget_neg:$a), "bu $a", []>;
617
618 def BRFU_u6 : _FU6<0b0111001100, (outs), (ins brtarget:$a), "bu $a", []>;
619
620 def BRFU_lu6 : _FLU6<0b0111001100, (outs), (ins brtarget:$a), "bu $a", []>;
621 }
622
623 //let Uses = [CP] in ...
624 let Defs = [R11], neverHasSideEffects = 1, isReMaterializable = 1 in
625 def LDAWCP_u6: _FU6<0b0111111101, (outs), (ins i32imm:$a), "ldaw r11, cp[$a]",
626                     []>;
627
628 let Defs = [R11], isReMaterializable = 1 in
629 def LDAWCP_lu6: _FLU6<0b0111111101, (outs), (ins i32imm:$a), "ldaw r11, cp[$a]",
630                       [(set R11, (cprelwrapper tglobaladdr:$a))]>;
631
632 let Defs = [R11] in
633 defm GETSR : FU6_LU6_np<0b0111111100, "getsr r11,">;
634
635 defm SETSR : FU6_LU6_int<0b0111101101, "setsr", int_xcore_setsr>;
636
637 defm CLRSR : FU6_LU6_int<0b0111101100, "clrsr", int_xcore_clrsr>;
638
639 // setsr may cause a branch if it is used to enable events. clrsr may
640 // branch if it is executed while events are enabled.
641 let isBranch=1, isIndirectBranch=1, isTerminator=1, isBarrier = 1,
642     isCodeGenOnly = 1 in {
643 defm SETSR_branch : FU6_LU6_np<0b0111101101, "setsr">;
644 defm CLRSR_branch : FU6_LU6_np<0b0111101100, "clrsr">;
645 }
646
647 defm KCALL : FU6_LU6_np<0b0111001111, "kcall">;
648
649 let Uses = [SP], Defs = [SP], mayStore = 1 in
650 defm KENTSP : FU6_LU6_np<0b0111101110, "kentsp">;
651
652 let Uses = [SP], Defs = [SP], mayLoad = 1 in
653 defm KRESTSP : FU6_LU6_np<0b0111101111, "krestsp">;
654
655 // U10
656
657 let Defs = [R11], isReMaterializable = 1, neverHasSideEffects = 1 in
658 def LDAPF_u10 : _FU10<0b110110, (outs), (ins i32imm:$a), "ldap r11, $a", []>;
659
660 let Defs = [R11], isReMaterializable = 1 in
661 def LDAPF_lu10 : _FLU10<0b110110, (outs), (ins i32imm:$a), "ldap r11, $a",
662                         [(set R11, (pcrelwrapper tglobaladdr:$a))]>;
663
664 let Defs = [R11], isReMaterializable = 1, isCodeGenOnly = 1 in
665 def LDAPF_lu10_ba : _FLU10<0b110110, (outs), (ins i32imm:$a), "ldap r11, $a",
666                            [(set R11, (pcrelwrapper tblockaddress:$a))]>;
667
668 let isCall=1,
669 // All calls clobber the link register and the non-callee-saved registers:
670 Defs = [R0, R1, R2, R3, R11, LR], Uses = [SP] in {
671 def BLACP_u10 : _FU10<0b111000, (outs), (ins i32imm:$a), "bla cp[$a]", []>;
672
673 def BLACP_lu10 : _FLU10<0b111000, (outs), (ins i32imm:$a), "bla cp[$a]", []>;
674
675 def BLRF_u10 : _FU10<0b110100, (outs), (ins calltarget:$a), "bl $a",
676                      [(XCoreBranchLink immU10:$a)]>;
677
678 def BLRF_lu10 : _FLU10<0b110100, (outs), (ins calltarget:$a), "bl $a",
679                        [(XCoreBranchLink immU20:$a)]>;
680 }
681
682 let Defs = [R11], mayLoad = 1, isReMaterializable = 1,
683     neverHasSideEffects = 1 in {
684 def LDWCP_u10 : _FU10<0b111001, (outs), (ins i32imm:$a), "ldw r11, cp[$a]", []>;
685
686 def LDWCP_lu10 : _FLU10<0b111001, (outs), (ins i32imm:$a), "ldw r11, cp[$a]",
687                         []>;
688 }
689
690 // Two operand short
691 def NOT : _F2R<0b100010, (outs GRRegs:$dst), (ins GRRegs:$b),
692                 "not $dst, $b", [(set GRRegs:$dst, (not GRRegs:$b))]>;
693
694 def NEG : _F2R<0b100100, (outs GRRegs:$dst), (ins GRRegs:$b),
695                 "neg $dst, $b", [(set GRRegs:$dst, (ineg GRRegs:$b))]>;
696
697 let Constraints = "$src1 = $dst" in {
698 def SEXT_rus :
699   _FRUSSrcDstBitp<0b001101, (outs GRRegs:$dst), (ins GRRegs:$src1, i32imm:$src2),
700                   "sext $dst, $src2",
701                   [(set GRRegs:$dst, (int_xcore_sext GRRegs:$src1,
702                                                      immBitp:$src2))]>;
703
704 def SEXT_2r :
705   _F2RSrcDst<0b001100, (outs GRRegs:$dst), (ins GRRegs:$src1, GRRegs:$src2),
706              "sext $dst, $src2",
707              [(set GRRegs:$dst, (int_xcore_sext GRRegs:$src1, GRRegs:$src2))]>;
708
709 def ZEXT_rus :
710   _FRUSSrcDstBitp<0b010001, (outs GRRegs:$dst), (ins GRRegs:$src1, i32imm:$src2),
711                   "zext $dst, $src2",
712                   [(set GRRegs:$dst, (int_xcore_zext GRRegs:$src1,
713                                                      immBitp:$src2))]>;
714
715 def ZEXT_2r :
716   _F2RSrcDst<0b010000, (outs GRRegs:$dst), (ins GRRegs:$src1, GRRegs:$src2),
717              "zext $dst, $src2",
718              [(set GRRegs:$dst, (int_xcore_zext GRRegs:$src1, GRRegs:$src2))]>;
719
720 def ANDNOT_2r :
721   _F2RSrcDst<0b001010, (outs GRRegs:$dst), (ins GRRegs:$src1, GRRegs:$src2),
722              "andnot $dst, $src2",
723              [(set GRRegs:$dst, (and GRRegs:$src1, (not GRRegs:$src2)))]>;
724 }
725
726 let isReMaterializable = 1, neverHasSideEffects = 1 in
727 def MKMSK_rus : _FRUSBitp<0b101001, (outs GRRegs:$dst), (ins i32imm:$size),
728                           "mkmsk $dst, $size", []>;
729
730 def MKMSK_2r : _F2R<0b101000, (outs GRRegs:$dst), (ins GRRegs:$size),
731                     "mkmsk $dst, $size",
732                     [(set GRRegs:$dst, (add (shl 1, GRRegs:$size), -1))]>;
733
734 def GETR_rus : _FRUS<0b100000, (outs GRRegs:$dst), (ins i32imm:$type),
735                      "getr $dst, $type",
736                      [(set GRRegs:$dst, (int_xcore_getr immUs:$type))]>;
737
738 def GETTS_2r : _F2R<0b001110, (outs GRRegs:$dst), (ins GRRegs:$r),
739                     "getts $dst, res[$r]",
740                     [(set GRRegs:$dst, (int_xcore_getts GRRegs:$r))]>;
741
742 def SETPT_2r : _FR2R<0b001111, (outs), (ins GRRegs:$r, GRRegs:$val),
743                      "setpt res[$r], $val",
744                      [(int_xcore_setpt GRRegs:$r, GRRegs:$val)]>;
745
746 def OUTCT_2r : _F2R<0b010010, (outs), (ins GRRegs:$r, GRRegs:$val),
747                     "outct res[$r], $val",
748                     [(int_xcore_outct GRRegs:$r, GRRegs:$val)]>;
749
750 def OUTCT_rus : _FRUS<0b010011, (outs), (ins GRRegs:$r, i32imm:$val),
751                        "outct res[$r], $val",
752                        [(int_xcore_outct GRRegs:$r, immUs:$val)]>;
753
754 def OUTT_2r : _FR2R<0b000011, (outs), (ins GRRegs:$r, GRRegs:$val),
755                     "outt res[$r], $val",
756                     [(int_xcore_outt GRRegs:$r, GRRegs:$val)]>;
757
758 def OUT_2r : _FR2R<0b101010, (outs), (ins GRRegs:$r, GRRegs:$val),
759                    "out res[$r], $val",
760                    [(int_xcore_out GRRegs:$r, GRRegs:$val)]>;
761
762 let Constraints = "$src = $dst" in
763 def OUTSHR_2r :
764   _F2RSrcDst<0b101011, (outs GRRegs:$dst), (ins GRRegs:$src, GRRegs:$r),
765              "outshr res[$r], $src",
766              [(set GRRegs:$dst, (int_xcore_outshr GRRegs:$r, GRRegs:$src))]>;
767
768 def INCT_2r : _F2R<0b100001, (outs GRRegs:$dst), (ins GRRegs:$r),
769                    "inct $dst, res[$r]",
770                    [(set GRRegs:$dst, (int_xcore_inct GRRegs:$r))]>;
771
772 def INT_2r : _F2R<0b100011, (outs GRRegs:$dst), (ins GRRegs:$r),
773                   "int $dst, res[$r]",
774                   [(set GRRegs:$dst, (int_xcore_int GRRegs:$r))]>;
775
776 def IN_2r : _F2R<0b101100, (outs GRRegs:$dst), (ins GRRegs:$r),
777                  "in $dst, res[$r]",
778                  [(set GRRegs:$dst, (int_xcore_in GRRegs:$r))]>;
779
780 let Constraints = "$src = $dst" in
781 def INSHR_2r :
782   _F2RSrcDst<0b101101, (outs GRRegs:$dst), (ins GRRegs:$src, GRRegs:$r),
783              "inshr $dst, res[$r]",
784              [(set GRRegs:$dst, (int_xcore_inshr GRRegs:$r, GRRegs:$src))]>;
785
786 def CHKCT_2r : _F2R<0b110010, (outs), (ins GRRegs:$r, GRRegs:$val),
787                     "chkct res[$r], $val",
788                     [(int_xcore_chkct GRRegs:$r, GRRegs:$val)]>;
789
790 def CHKCT_rus : _FRUSBitp<0b110011, (outs), (ins GRRegs:$r, i32imm:$val),
791                           "chkct res[$r], $val",
792                           [(int_xcore_chkct GRRegs:$r, immUs:$val)]>;
793
794 def TESTCT_2r : _F2R<0b101111, (outs GRRegs:$dst), (ins GRRegs:$src),
795                      "testct $dst, res[$src]",
796                      [(set GRRegs:$dst, (int_xcore_testct GRRegs:$src))]>;
797
798 def TESTWCT_2r : _F2R<0b110001, (outs GRRegs:$dst), (ins GRRegs:$src),
799                       "testwct $dst, res[$src]",
800                       [(set GRRegs:$dst, (int_xcore_testwct GRRegs:$src))]>;
801
802 def SETD_2r : _FR2R<0b000101, (outs), (ins GRRegs:$r, GRRegs:$val),
803                     "setd res[$r], $val",
804                     [(int_xcore_setd GRRegs:$r, GRRegs:$val)]>;
805
806 def SETPSC_2r : _FR2R<0b110000, (outs), (ins GRRegs:$src1, GRRegs:$src2),
807                       "setpsc res[$src1], $src2",
808                       [(int_xcore_setpsc GRRegs:$src1, GRRegs:$src2)]>;
809
810 def GETST_2r : _F2R<0b000001, (outs GRRegs:$dst), (ins GRRegs:$r),
811                     "getst $dst, res[$r]",
812                     [(set GRRegs:$dst, (int_xcore_getst GRRegs:$r))]>;
813
814 def INITSP_2r : _F2R<0b000100, (outs), (ins GRRegs:$src, GRRegs:$t),
815                      "init t[$t]:sp, $src",
816                      [(int_xcore_initsp GRRegs:$t, GRRegs:$src)]>;
817
818 def INITPC_2r : _F2R<0b000000, (outs), (ins GRRegs:$src, GRRegs:$t),
819                      "init t[$t]:pc, $src",
820                      [(int_xcore_initpc GRRegs:$t, GRRegs:$src)]>;
821
822 def INITCP_2r : _F2R<0b000110, (outs), (ins GRRegs:$src, GRRegs:$t),
823                      "init t[$t]:cp, $src",
824                      [(int_xcore_initcp GRRegs:$t, GRRegs:$src)]>;
825
826 def INITDP_2r : _F2R<0b000010, (outs), (ins GRRegs:$src, GRRegs:$t),
827                      "init t[$t]:dp, $src",
828                      [(int_xcore_initdp GRRegs:$t, GRRegs:$src)]>;
829
830 def PEEK_2r : _F2R<0b101110, (outs GRRegs:$dst), (ins GRRegs:$src),
831                     "peek $dst, res[$src]",
832                     [(set GRRegs:$dst, (int_xcore_peek GRRegs:$src))]>;
833
834 def ENDIN_2r : _F2R<0b100101, (outs GRRegs:$dst), (ins GRRegs:$src),
835                      "endin $dst, res[$src]",
836                      [(set GRRegs:$dst, (int_xcore_endin GRRegs:$src))]>;
837
838 def EEF_2r : _F2R<0b001011, (outs), (ins GRRegs:$a, GRRegs:$b),
839                   "eef $a, res[$b]", []>;
840
841 def EET_2r : _F2R<0b001001, (outs), (ins GRRegs:$a, GRRegs:$b),
842                   "eet $a, res[$b]", []>;
843
844 def TSETMR_2r : _F2RImm<0b000111, (outs), (ins i32imm:$a, GRRegs:$b),
845                         "tsetmr r$a, $b", []>;
846
847 // Two operand long
848 def BITREV_l2r : _FL2R<0b0000011000, (outs GRRegs:$dst), (ins GRRegs:$src),
849                        "bitrev $dst, $src",
850                        [(set GRRegs:$dst, (int_xcore_bitrev GRRegs:$src))]>;
851
852 def BYTEREV_l2r : _FL2R<0b0000011001, (outs GRRegs:$dst), (ins GRRegs:$src),
853                         "byterev $dst, $src",
854                         [(set GRRegs:$dst, (bswap GRRegs:$src))]>;
855
856 def CLZ_l2r : _FL2R<0b000111000, (outs GRRegs:$dst), (ins GRRegs:$src),
857                     "clz $dst, $src",
858                     [(set GRRegs:$dst, (ctlz GRRegs:$src))]>;
859
860 def GETD_l2r : _FL2R<0b0001111001, (outs GRRegs:$dst), (ins GRRegs:$src),
861                      "getd $dst, res[$src]", []>;
862
863 def GETN_l2r : _FL2R<0b0011011001, (outs GRRegs:$dst), (ins GRRegs:$src),
864                      "getn $dst, res[$src]", []>;
865
866 def SETC_l2r : _FL2R<0b0010111001, (outs), (ins GRRegs:$r, GRRegs:$val),
867                      "setc res[$r], $val",
868                      [(int_xcore_setc GRRegs:$r, GRRegs:$val)]>;
869
870 def SETTW_l2r : _FLR2R<0b0010011001, (outs), (ins GRRegs:$r, GRRegs:$val),
871                        "settw res[$r], $val",
872                        [(int_xcore_settw GRRegs:$r, GRRegs:$val)]>;
873
874 def GETPS_l2r : _FL2R<0b0001011001, (outs GRRegs:$dst), (ins GRRegs:$src),
875                       "get $dst, ps[$src]",
876                       [(set GRRegs:$dst, (int_xcore_getps GRRegs:$src))]>;
877
878 def SETPS_l2r : _FLR2R<0b0001111000, (outs), (ins GRRegs:$src1, GRRegs:$src2),
879                        "set ps[$src1], $src2",
880                        [(int_xcore_setps GRRegs:$src1, GRRegs:$src2)]>;
881
882 def INITLR_l2r : _FL2R<0b0001011000, (outs), (ins GRRegs:$src, GRRegs:$t),
883                        "init t[$t]:lr, $src",
884                        [(int_xcore_initlr GRRegs:$t, GRRegs:$src)]>;
885
886 def SETCLK_l2r : _FLR2R<0b0000111001, (outs), (ins GRRegs:$src1, GRRegs:$src2),
887                         "setclk res[$src1], $src2",
888                         [(int_xcore_setclk GRRegs:$src1, GRRegs:$src2)]>;
889
890 def SETN_l2r : _FLR2R<0b0011011000, (outs), (ins GRRegs:$src1, GRRegs:$src2),
891                       "setn res[$src1], $src2", []>;
892
893 def SETRDY_l2r : _FLR2R<0b0010111000, (outs), (ins GRRegs:$src1, GRRegs:$src2),
894                         "setrdy res[$src1], $src2",
895                         [(int_xcore_setrdy GRRegs:$src1, GRRegs:$src2)]>;
896
897 def TESTLCL_l2r : _FL2R<0b0010011000, (outs GRRegs:$dst), (ins GRRegs:$src),
898                         "testlcl $dst, res[$src]", []>;
899
900 // One operand short
901 def MSYNC_1r : _F1R<0b000111, (outs), (ins GRRegs:$a),
902                     "msync res[$a]",
903                     [(int_xcore_msync GRRegs:$a)]>;
904 def MJOIN_1r : _F1R<0b000101, (outs), (ins GRRegs:$a),
905                     "mjoin res[$a]",
906                     [(int_xcore_mjoin GRRegs:$a)]>;
907
908 let isBranch=1, isIndirectBranch=1, isTerminator=1, isBarrier = 1 in
909 def BAU_1r : _F1R<0b001001, (outs), (ins GRRegs:$a),
910                  "bau $a",
911                  [(brind GRRegs:$a)]>;
912
913 let isBranch=1, isIndirectBranch=1, isTerminator=1, isBarrier = 1 in
914 def BR_JT : PseudoInstXCore<(outs), (ins InlineJT:$t, GRRegs:$i),
915                             "bru $i\n$t",
916                             [(XCoreBR_JT tjumptable:$t, GRRegs:$i)]>;
917
918 let isBranch=1, isIndirectBranch=1, isTerminator=1, isBarrier = 1 in
919 def BR_JT32 : PseudoInstXCore<(outs), (ins InlineJT32:$t, GRRegs:$i),
920                               "bru $i\n$t",
921                               [(XCoreBR_JT32 tjumptable:$t, GRRegs:$i)]>;
922
923 let isBranch=1, isIndirectBranch=1, isTerminator=1, isBarrier = 1 in
924 def BRU_1r : _F1R<0b001010, (outs), (ins GRRegs:$a), "bru $a", []>;
925
926 let Defs=[SP], neverHasSideEffects=1 in
927 def SETSP_1r : _F1R<0b001011, (outs), (ins GRRegs:$a), "set sp, $a", []>;
928
929 let neverHasSideEffects=1 in
930 def SETDP_1r : _F1R<0b001100, (outs), (ins GRRegs:$a), "set dp, $a", []>;
931
932 let neverHasSideEffects=1 in
933 def SETCP_1r : _F1R<0b001101, (outs), (ins GRRegs:$a), "set cp, $a", []>;
934
935 let hasCtrlDep = 1 in 
936 def ECALLT_1r : _F1R<0b010011, (outs), (ins GRRegs:$a),
937                  "ecallt $a",
938                  []>;
939
940 let hasCtrlDep = 1 in 
941 def ECALLF_1r : _F1R<0b010010, (outs), (ins GRRegs:$a),
942                  "ecallf $a",
943                  []>;
944
945 let isCall=1, 
946 // All calls clobber the link register and the non-callee-saved registers:
947 Defs = [R0, R1, R2, R3, R11, LR], Uses = [SP] in {
948 def BLA_1r : _F1R<0b001000, (outs), (ins GRRegs:$a),
949                  "bla $a",
950                  [(XCoreBranchLink GRRegs:$a)]>;
951 }
952
953 def SYNCR_1r : _F1R<0b100001, (outs), (ins GRRegs:$a),
954                  "syncr res[$a]",
955                  [(int_xcore_syncr GRRegs:$a)]>;
956
957 def FREER_1r : _F1R<0b000100, (outs), (ins GRRegs:$a),
958                "freer res[$a]",
959                [(int_xcore_freer GRRegs:$a)]>;
960
961 let Uses=[R11] in {
962 def SETV_1r : _F1R<0b010001, (outs), (ins GRRegs:$a),
963                    "setv res[$a], r11",
964                    [(int_xcore_setv GRRegs:$a, R11)]>;
965
966 def SETEV_1r : _F1R<0b001111, (outs), (ins GRRegs:$a),
967                     "setev res[$a], r11",
968                     [(int_xcore_setev GRRegs:$a, R11)]>;
969 }
970
971 def DGETREG_1r : _F1R<0b001110, (outs GRRegs:$a), (ins), "dgetreg $a", []>;
972
973 def EDU_1r : _F1R<0b000000, (outs), (ins GRRegs:$a), "edu res[$a]", []>;
974
975 def EEU_1r : _F1R<0b000001, (outs), (ins GRRegs:$a),
976                "eeu res[$a]",
977                [(int_xcore_eeu GRRegs:$a)]>;
978
979 def KCALL_1r : _F1R<0b010000, (outs), (ins GRRegs:$a), "kcall $a", []>;
980
981 def WAITEF_1R : _F1R<0b000011, (outs), (ins GRRegs:$a), "waitef $a", []>;
982
983 def WAITET_1R : _F1R<0b000010, (outs), (ins GRRegs:$a), "waitet $a", []>;
984
985 def TSTART_1R : _F1R<0b000110, (outs), (ins GRRegs:$a), "start t[$a]", []>;
986
987 def CLRPT_1R : _F1R<0b100000, (outs), (ins GRRegs:$a), "clrpt res[$a]", []>;
988
989 // Zero operand short
990
991 def CLRE_0R : _F0R<0b0000001101, (outs), (ins), "clre", [(int_xcore_clre)]>;
992
993 def DCALL_0R : _F0R<0b0000011100, (outs), (ins), "dcall", []>;
994
995 let Defs = [SP], Uses = [SP] in
996 def DENTSP_0R : _F0R<0b0001001100, (outs), (ins), "dentsp", []>;
997
998 let Defs = [SP] in
999 def DRESTSP_0R : _F0R<0b0001001101, (outs), (ins), "drestsp", []>;
1000
1001 def DRET_0R : _F0R<0b0000011110, (outs), (ins), "dret", []>;
1002
1003 def FREET_0R : _F0R<0b0000001111, (outs), (ins), "freet", []>;
1004
1005 let Defs = [R11] in {
1006 def GETID_0R : _F0R<0b0001001110, (outs), (ins),
1007                     "get r11, id",
1008                     [(set R11, (int_xcore_getid))]>;
1009
1010 def GETED_0R : _F0R<0b0000111110, (outs), (ins),
1011                     "get r11, ed",
1012                     [(set R11, (int_xcore_geted))]>;
1013
1014 def GETET_0R : _F0R<0b0000111111, (outs), (ins),
1015                     "get r11, et",
1016                     [(set R11, (int_xcore_getet))]>;
1017
1018 def GETKEP_0R : _F0R<0b0001001111, (outs), (ins),
1019                      "get r11, kep", []>;
1020
1021 def GETKSP_0R : _F0R<0b0001011100, (outs), (ins),
1022                      "get r11, ksp", []>;
1023 }
1024
1025 let Defs = [SP] in
1026 def KRET_0R : _F0R<0b0000011101, (outs), (ins), "kret", []>;
1027
1028 let Uses = [SP], mayLoad = 1 in {
1029 def LDET_0R : _F0R<0b0001011110, (outs), (ins), "ldw et, sp[4]", []>;
1030
1031 def LDSED_0R : _F0R<0b0001011101, (outs), (ins), "ldw sed, sp[3]", []>;
1032
1033 def LDSPC_0R : _F0R<0b0000101100, (outs), (ins), "ldw spc, sp[1]", []>;
1034
1035 def LDSSR_0R : _F0R<0b0000101110, (outs), (ins), "ldw ssr, sp[2]", []>;
1036 }
1037
1038 let Uses=[R11] in
1039 def SETKEP_0R : _F0R<0b0000011111, (outs), (ins), "set kep, r11", []>;
1040
1041 def SSYNC_0r : _F0R<0b0000001110, (outs), (ins),
1042                     "ssync",
1043                     [(int_xcore_ssync)]>;
1044
1045 let Uses = [SP], mayStore = 1 in {
1046 def STET_0R : _F0R<0b0000111101, (outs), (ins), "stw et, sp[4]", []>;
1047
1048 def STSED_0R : _F0R<0b0000111100, (outs), (ins), "stw sed, sp[3]", []>;
1049
1050 def STSPC_0R : _F0R<0b0000101101, (outs), (ins), "stw spc, sp[1]", []>;
1051
1052 def STSSR_0R : _F0R<0b0000101111, (outs), (ins), "stw ssr, sp[2]", []>;
1053 }
1054
1055 let isBranch=1, isIndirectBranch=1, isTerminator=1, isBarrier = 1,
1056     hasSideEffects = 1 in
1057 def WAITEU_0R : _F0R<0b0000001100, (outs), (ins),
1058                      "waiteu",
1059                      [(brind (int_xcore_waitevent))]>;
1060
1061 //===----------------------------------------------------------------------===//
1062 // Non-Instruction Patterns
1063 //===----------------------------------------------------------------------===//
1064
1065 def : Pat<(XCoreBranchLink tglobaladdr:$addr), (BLRF_lu10 tglobaladdr:$addr)>;
1066 def : Pat<(XCoreBranchLink texternalsym:$addr), (BLRF_lu10 texternalsym:$addr)>;
1067
1068 /// sext_inreg
1069 def : Pat<(sext_inreg GRRegs:$b, i1), (SEXT_rus GRRegs:$b, 1)>;
1070 def : Pat<(sext_inreg GRRegs:$b, i8), (SEXT_rus GRRegs:$b, 8)>;
1071 def : Pat<(sext_inreg GRRegs:$b, i16), (SEXT_rus GRRegs:$b, 16)>;
1072
1073 /// loads
1074 def : Pat<(zextloadi8 (add GRRegs:$addr, GRRegs:$offset)),
1075           (LD8U_3r GRRegs:$addr, GRRegs:$offset)>;
1076 def : Pat<(zextloadi8 GRRegs:$addr), (LD8U_3r GRRegs:$addr, (LDC_ru6 0))>;
1077
1078 def : Pat<(sextloadi16 (lda16f GRRegs:$addr, GRRegs:$offset)),
1079           (LD16S_3r GRRegs:$addr, GRRegs:$offset)>;
1080 def : Pat<(sextloadi16 GRRegs:$addr), (LD16S_3r GRRegs:$addr, (LDC_ru6 0))>;
1081
1082 def : Pat<(load (ldawf GRRegs:$addr, GRRegs:$offset)),
1083           (LDW_3r GRRegs:$addr, GRRegs:$offset)>;
1084 def : Pat<(load (add GRRegs:$addr, immUs4:$offset)),
1085           (LDW_2rus GRRegs:$addr, (div4_xform immUs4:$offset))>;
1086 def : Pat<(load GRRegs:$addr), (LDW_2rus GRRegs:$addr, 0)>;
1087
1088 /// anyext
1089 def : Pat<(extloadi8 (add GRRegs:$addr, GRRegs:$offset)),
1090           (LD8U_3r GRRegs:$addr, GRRegs:$offset)>;
1091 def : Pat<(extloadi8 GRRegs:$addr), (LD8U_3r GRRegs:$addr, (LDC_ru6 0))>;
1092 def : Pat<(extloadi16 (lda16f GRRegs:$addr, GRRegs:$offset)),
1093           (LD16S_3r GRRegs:$addr, GRRegs:$offset)>;
1094 def : Pat<(extloadi16 GRRegs:$addr), (LD16S_3r GRRegs:$addr, (LDC_ru6 0))>;
1095
1096 /// stores
1097 def : Pat<(truncstorei8 GRRegs:$val, (add GRRegs:$addr, GRRegs:$offset)),
1098           (ST8_l3r GRRegs:$val, GRRegs:$addr, GRRegs:$offset)>;
1099 def : Pat<(truncstorei8 GRRegs:$val, GRRegs:$addr),
1100           (ST8_l3r GRRegs:$val, GRRegs:$addr, (LDC_ru6 0))>;
1101           
1102 def : Pat<(truncstorei16 GRRegs:$val, (lda16f GRRegs:$addr, GRRegs:$offset)),
1103           (ST16_l3r GRRegs:$val, GRRegs:$addr, GRRegs:$offset)>;
1104 def : Pat<(truncstorei16 GRRegs:$val, GRRegs:$addr),
1105           (ST16_l3r GRRegs:$val, GRRegs:$addr, (LDC_ru6 0))>;
1106
1107 def : Pat<(store GRRegs:$val, (ldawf GRRegs:$addr, GRRegs:$offset)),
1108           (STW_l3r GRRegs:$val, GRRegs:$addr, GRRegs:$offset)>;
1109 def : Pat<(store GRRegs:$val, (add GRRegs:$addr, immUs4:$offset)),
1110           (STW_2rus GRRegs:$val, GRRegs:$addr, (div4_xform immUs4:$offset))>;
1111 def : Pat<(store GRRegs:$val, GRRegs:$addr),
1112           (STW_2rus GRRegs:$val, GRRegs:$addr, 0)>;
1113
1114 /// cttz
1115 def : Pat<(cttz GRRegs:$src), (CLZ_l2r (BITREV_l2r GRRegs:$src))>;
1116
1117 /// trap
1118 def : Pat<(trap), (ECALLF_1r (LDC_ru6 0))>;
1119
1120 ///
1121 /// branch patterns
1122 ///
1123
1124 // unconditional branch
1125 def : Pat<(br bb:$addr), (BRFU_lu6 bb:$addr)>;
1126
1127 // direct match equal/notequal zero brcond
1128 def : Pat<(brcond (setne GRRegs:$lhs, 0), bb:$dst),
1129           (BRFT_lru6 GRRegs:$lhs, bb:$dst)>;
1130 def : Pat<(brcond (seteq GRRegs:$lhs, 0), bb:$dst),
1131           (BRFF_lru6 GRRegs:$lhs, bb:$dst)>;
1132
1133 def : Pat<(brcond (setle GRRegs:$lhs, GRRegs:$rhs), bb:$dst),
1134           (BRFF_lru6 (LSS_3r GRRegs:$rhs, GRRegs:$lhs), bb:$dst)>;
1135 def : Pat<(brcond (setule GRRegs:$lhs, GRRegs:$rhs), bb:$dst),
1136           (BRFF_lru6 (LSU_3r GRRegs:$rhs, GRRegs:$lhs), bb:$dst)>;
1137 def : Pat<(brcond (setge GRRegs:$lhs, GRRegs:$rhs), bb:$dst),
1138           (BRFF_lru6 (LSS_3r GRRegs:$lhs, GRRegs:$rhs), bb:$dst)>;
1139 def : Pat<(brcond (setuge GRRegs:$lhs, GRRegs:$rhs), bb:$dst),
1140           (BRFF_lru6 (LSU_3r GRRegs:$lhs, GRRegs:$rhs), bb:$dst)>;
1141 def : Pat<(brcond (setne GRRegs:$lhs, GRRegs:$rhs), bb:$dst),
1142           (BRFF_lru6 (EQ_3r GRRegs:$lhs, GRRegs:$rhs), bb:$dst)>;
1143 def : Pat<(brcond (setne GRRegs:$lhs, immUs:$rhs), bb:$dst),
1144           (BRFF_lru6 (EQ_2rus GRRegs:$lhs, immUs:$rhs), bb:$dst)>;
1145
1146 // generic brcond pattern
1147 def : Pat<(brcond GRRegs:$cond, bb:$addr), (BRFT_lru6 GRRegs:$cond, bb:$addr)>;
1148
1149
1150 ///
1151 /// Select patterns
1152 ///
1153
1154 // direct match equal/notequal zero select
1155 def : Pat<(select (setne GRRegs:$lhs, 0), GRRegs:$T, GRRegs:$F),
1156         (SELECT_CC GRRegs:$lhs, GRRegs:$T, GRRegs:$F)>;
1157
1158 def : Pat<(select (seteq GRRegs:$lhs, 0), GRRegs:$T, GRRegs:$F),
1159         (SELECT_CC GRRegs:$lhs, GRRegs:$F, GRRegs:$T)>;
1160
1161 def : Pat<(select (setle GRRegs:$lhs, GRRegs:$rhs), GRRegs:$T, GRRegs:$F),
1162           (SELECT_CC (LSS_3r GRRegs:$rhs, GRRegs:$lhs), GRRegs:$F, GRRegs:$T)>;
1163 def : Pat<(select (setule GRRegs:$lhs, GRRegs:$rhs), GRRegs:$T, GRRegs:$F),
1164           (SELECT_CC (LSU_3r GRRegs:$rhs, GRRegs:$lhs), GRRegs:$F, GRRegs:$T)>;
1165 def : Pat<(select (setge GRRegs:$lhs, GRRegs:$rhs), GRRegs:$T, GRRegs:$F),
1166           (SELECT_CC (LSS_3r GRRegs:$lhs, GRRegs:$rhs), GRRegs:$F, GRRegs:$T)>;
1167 def : Pat<(select (setuge GRRegs:$lhs, GRRegs:$rhs), GRRegs:$T, GRRegs:$F),
1168           (SELECT_CC (LSU_3r GRRegs:$lhs, GRRegs:$rhs), GRRegs:$F, GRRegs:$T)>;
1169 def : Pat<(select (setne GRRegs:$lhs, GRRegs:$rhs), GRRegs:$T, GRRegs:$F),
1170           (SELECT_CC (EQ_3r GRRegs:$lhs, GRRegs:$rhs), GRRegs:$F, GRRegs:$T)>;
1171 def : Pat<(select (setne GRRegs:$lhs, immUs:$rhs), GRRegs:$T, GRRegs:$F),
1172           (SELECT_CC (EQ_2rus GRRegs:$lhs, immUs:$rhs), GRRegs:$F, GRRegs:$T)>;
1173
1174 ///
1175 /// setcc patterns, only matched when none of the above brcond
1176 /// patterns match
1177 ///
1178
1179 // setcc 2 register operands
1180 def : Pat<(setle GRRegs:$lhs, GRRegs:$rhs),
1181           (EQ_2rus (LSS_3r GRRegs:$rhs, GRRegs:$lhs), 0)>;
1182 def : Pat<(setule GRRegs:$lhs, GRRegs:$rhs),
1183           (EQ_2rus (LSU_3r GRRegs:$rhs, GRRegs:$lhs), 0)>;
1184
1185 def : Pat<(setgt GRRegs:$lhs, GRRegs:$rhs),
1186           (LSS_3r GRRegs:$rhs, GRRegs:$lhs)>;
1187 def : Pat<(setugt GRRegs:$lhs, GRRegs:$rhs),
1188           (LSU_3r GRRegs:$rhs, GRRegs:$lhs)>;
1189
1190 def : Pat<(setge GRRegs:$lhs, GRRegs:$rhs),
1191           (EQ_2rus (LSS_3r GRRegs:$lhs, GRRegs:$rhs), 0)>;
1192 def : Pat<(setuge GRRegs:$lhs, GRRegs:$rhs),
1193           (EQ_2rus (LSU_3r GRRegs:$lhs, GRRegs:$rhs), 0)>;
1194
1195 def : Pat<(setlt GRRegs:$lhs, GRRegs:$rhs),
1196           (LSS_3r GRRegs:$lhs, GRRegs:$rhs)>;
1197 def : Pat<(setult GRRegs:$lhs, GRRegs:$rhs),
1198           (LSU_3r GRRegs:$lhs, GRRegs:$rhs)>;
1199
1200 def : Pat<(setne GRRegs:$lhs, GRRegs:$rhs),
1201           (EQ_2rus (EQ_3r GRRegs:$lhs, GRRegs:$rhs), 0)>;
1202
1203 def : Pat<(seteq GRRegs:$lhs, GRRegs:$rhs),
1204           (EQ_3r GRRegs:$lhs, GRRegs:$rhs)>;
1205
1206 // setcc reg/imm operands
1207 def : Pat<(seteq GRRegs:$lhs, immUs:$rhs),
1208           (EQ_2rus GRRegs:$lhs, immUs:$rhs)>;
1209 def : Pat<(setne GRRegs:$lhs, immUs:$rhs),
1210           (EQ_2rus (EQ_2rus GRRegs:$lhs, immUs:$rhs), 0)>;
1211
1212 // misc
1213 def : Pat<(add GRRegs:$addr, immUs4:$offset),
1214           (LDAWF_l2rus GRRegs:$addr, (div4_xform immUs4:$offset))>;
1215
1216 def : Pat<(sub GRRegs:$addr, immUs4:$offset),
1217           (LDAWB_l2rus GRRegs:$addr, (div4_xform immUs4:$offset))>;
1218
1219 def : Pat<(and GRRegs:$val, immMskBitp:$mask),
1220           (ZEXT_rus GRRegs:$val, (msksize_xform immMskBitp:$mask))>;
1221
1222 // (sub X, imm) gets canonicalized to (add X, -imm).  Match this form.
1223 def : Pat<(add GRRegs:$src1, immUsNeg:$src2),
1224           (SUB_2rus GRRegs:$src1, (neg_xform immUsNeg:$src2))>;
1225
1226 def : Pat<(add GRRegs:$src1, immUs4Neg:$src2),
1227           (LDAWB_l2rus GRRegs:$src1, (div4neg_xform immUs4Neg:$src2))>;
1228
1229 ///
1230 /// Some peepholes
1231 ///
1232
1233 def : Pat<(mul GRRegs:$src, 3),
1234           (LDA16F_l3r GRRegs:$src, GRRegs:$src)>;
1235
1236 def : Pat<(mul GRRegs:$src, 5),
1237           (LDAWF_l3r GRRegs:$src, GRRegs:$src)>;
1238
1239 def : Pat<(mul GRRegs:$src, -3),
1240           (LDAWB_l3r GRRegs:$src, GRRegs:$src)>;
1241
1242 // ashr X, 32 is equivalent to ashr X, 31 on the XCore.
1243 def : Pat<(sra GRRegs:$src, 31),
1244           (ASHR_l2rus GRRegs:$src, 32)>;
1245
1246 def : Pat<(brcond (setlt GRRegs:$lhs, 0), bb:$dst),
1247           (BRFT_lru6 (ASHR_l2rus GRRegs:$lhs, 32), bb:$dst)>;
1248
1249 // setge X, 0 is canonicalized to setgt X, -1
1250 def : Pat<(brcond (setgt GRRegs:$lhs, -1), bb:$dst),
1251           (BRFF_lru6 (ASHR_l2rus GRRegs:$lhs, 32), bb:$dst)>;
1252
1253 def : Pat<(select (setlt GRRegs:$lhs, 0), GRRegs:$T, GRRegs:$F),
1254           (SELECT_CC (ASHR_l2rus GRRegs:$lhs, 32), GRRegs:$T, GRRegs:$F)>;
1255
1256 def : Pat<(select (setgt GRRegs:$lhs, -1), GRRegs:$T, GRRegs:$F),
1257           (SELECT_CC (ASHR_l2rus GRRegs:$lhs, 32), GRRegs:$F, GRRegs:$T)>;
1258
1259 def : Pat<(setgt GRRegs:$lhs, -1),
1260           (EQ_2rus (ASHR_l2rus GRRegs:$lhs, 32), 0)>;
1261
1262 def : Pat<(sra (shl GRRegs:$src, immBpwSubBitp:$imm), immBpwSubBitp:$imm),
1263           (SEXT_rus GRRegs:$src, (bpwsub_xform immBpwSubBitp:$imm))>;