]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/MSP430/MSP430InstrInfo.td
Merge ^/head r317808 through r317970.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / MSP430 / MSP430InstrInfo.td
1 //===-- MSP430InstrInfo.td - MSP430 Instruction defs -------*- 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 MSP430 instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 include "MSP430InstrFormats.td"
15
16 //===----------------------------------------------------------------------===//
17 // Type Constraints.
18 //===----------------------------------------------------------------------===//
19 class SDTCisI8<int OpNum> : SDTCisVT<OpNum, i8>;
20 class SDTCisI16<int OpNum> : SDTCisVT<OpNum, i16>;
21
22 //===----------------------------------------------------------------------===//
23 // Type Profiles.
24 //===----------------------------------------------------------------------===//
25 def SDT_MSP430Call         : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>;
26 def SDT_MSP430CallSeqStart : SDCallSeqStart<[SDTCisVT<0, i16>]>;
27 def SDT_MSP430CallSeqEnd   : SDCallSeqEnd<[SDTCisVT<0, i16>, SDTCisVT<1, i16>]>;
28 def SDT_MSP430Wrapper      : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>,
29                                                   SDTCisPtrTy<0>]>;
30 def SDT_MSP430Cmp          : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
31 def SDT_MSP430BrCC         : SDTypeProfile<0, 2, [SDTCisVT<0, OtherVT>,
32                                                   SDTCisVT<1, i8>]>;
33 def SDT_MSP430SelectCC     : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>,
34                                                   SDTCisSameAs<1, 2>, 
35                                                   SDTCisVT<3, i8>]>;
36 def SDT_MSP430Shift        : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>,
37                                                   SDTCisI8<2>]>;
38
39 //===----------------------------------------------------------------------===//
40 // MSP430 Specific Node Definitions.
41 //===----------------------------------------------------------------------===//
42 def MSP430retflag  : SDNode<"MSP430ISD::RET_FLAG", SDTNone,
43                        [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
44 def MSP430retiflag : SDNode<"MSP430ISD::RETI_FLAG", SDTNone,
45                        [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
46
47 def MSP430rra     : SDNode<"MSP430ISD::RRA", SDTIntUnaryOp, []>;
48 def MSP430rla     : SDNode<"MSP430ISD::RLA", SDTIntUnaryOp, []>;
49 def MSP430rrc     : SDNode<"MSP430ISD::RRC", SDTIntUnaryOp, []>;
50
51 def MSP430call    : SDNode<"MSP430ISD::CALL", SDT_MSP430Call,
52                      [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, SDNPVariadic]>;
53 def MSP430callseq_start :
54                  SDNode<"ISD::CALLSEQ_START", SDT_MSP430CallSeqStart,
55                         [SDNPHasChain, SDNPOutGlue]>;
56 def MSP430callseq_end :
57                  SDNode<"ISD::CALLSEQ_END",   SDT_MSP430CallSeqEnd,
58                         [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
59 def MSP430Wrapper : SDNode<"MSP430ISD::Wrapper", SDT_MSP430Wrapper>;
60 def MSP430cmp     : SDNode<"MSP430ISD::CMP", SDT_MSP430Cmp, [SDNPOutGlue]>;
61 def MSP430brcc    : SDNode<"MSP430ISD::BR_CC", SDT_MSP430BrCC,
62                             [SDNPHasChain, SDNPInGlue]>;
63 def MSP430selectcc: SDNode<"MSP430ISD::SELECT_CC", SDT_MSP430SelectCC,
64                             [SDNPInGlue]>;
65 def MSP430shl     : SDNode<"MSP430ISD::SHL", SDT_MSP430Shift, []>;
66 def MSP430sra     : SDNode<"MSP430ISD::SRA", SDT_MSP430Shift, []>;
67 def MSP430srl     : SDNode<"MSP430ISD::SRL", SDT_MSP430Shift, []>;
68
69 //===----------------------------------------------------------------------===//
70 // MSP430 Operand Definitions.
71 //===----------------------------------------------------------------------===//
72
73 // Address operands
74 def memsrc : Operand<i16> {
75   let PrintMethod = "printSrcMemOperand";
76   let MIOperandInfo = (ops GR16, i16imm);
77 }
78
79 def memdst : Operand<i16> {
80   let PrintMethod = "printSrcMemOperand";
81   let MIOperandInfo = (ops GR16, i16imm);
82 }
83
84 // Short jump targets have OtherVT type and are printed as pcrel imm values.
85 def jmptarget : Operand<OtherVT> {
86   let PrintMethod = "printPCRelImmOperand";
87 }
88
89 // Operand for printing out a condition code.
90 def cc : Operand<i8> {
91   let PrintMethod = "printCCOperand";
92 }
93
94 //===----------------------------------------------------------------------===//
95 // MSP430 Complex Pattern Definitions.
96 //===----------------------------------------------------------------------===//
97
98 def addr : ComplexPattern<iPTR, 2, "SelectAddr", [], []>;
99
100 //===----------------------------------------------------------------------===//
101 // Pattern Fragments
102 def zextloadi16i8 : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>;
103 def  extloadi16i8 : PatFrag<(ops node:$ptr), (i16 ( extloadi8 node:$ptr))>;
104 def and_su : PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, node:$rhs), [{
105   return N->hasOneUse();
106 }]>;
107 //===----------------------------------------------------------------------===//
108 // Instruction list..
109
110 // ADJCALLSTACKDOWN/UP implicitly use/def SP because they may be expanded into
111 // a stack adjustment and the codegen must know that they may modify the stack
112 // pointer before prolog-epilog rewriting occurs.
113 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
114 // sub / add which can clobber SR.
115 let Defs = [SP, SR], Uses = [SP] in {
116 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i16imm:$amt),
117                               "#ADJCALLSTACKDOWN",
118                               [(MSP430callseq_start timm:$amt)]>;
119 def ADJCALLSTACKUP   : Pseudo<(outs), (ins i16imm:$amt1, i16imm:$amt2),
120                               "#ADJCALLSTACKUP",
121                               [(MSP430callseq_end timm:$amt1, timm:$amt2)]>;
122 }
123
124 let usesCustomInserter = 1 in {
125   let Uses = [SR] in {
126   def Select8  : Pseudo<(outs GR8:$dst), (ins GR8:$src, GR8:$src2, i8imm:$cc),
127                         "# Select8 PSEUDO",
128                         [(set GR8:$dst,
129                           (MSP430selectcc GR8:$src, GR8:$src2, imm:$cc))]>;
130   def Select16 : Pseudo<(outs GR16:$dst), (ins GR16:$src, GR16:$src2, i8imm:$cc),
131                         "# Select16 PSEUDO",
132                         [(set GR16:$dst,
133                           (MSP430selectcc GR16:$src, GR16:$src2, imm:$cc))]>;
134   }
135   let Defs = [SR] in {
136   def Shl8     : Pseudo<(outs GR8:$dst), (ins GR8:$src, GR8:$cnt),
137                         "# Shl8 PSEUDO",
138                         [(set GR8:$dst, (MSP430shl GR8:$src, GR8:$cnt))]>;
139   def Shl16    : Pseudo<(outs GR16:$dst), (ins GR16:$src, GR8:$cnt),
140                         "# Shl16 PSEUDO",
141                         [(set GR16:$dst, (MSP430shl GR16:$src, GR8:$cnt))]>;
142   def Sra8     : Pseudo<(outs GR8:$dst), (ins GR8:$src, GR8:$cnt),
143                         "# Sra8 PSEUDO",
144                         [(set GR8:$dst, (MSP430sra GR8:$src, GR8:$cnt))]>;
145   def Sra16    : Pseudo<(outs GR16:$dst), (ins GR16:$src, GR8:$cnt),
146                         "# Sra16 PSEUDO",
147                         [(set GR16:$dst, (MSP430sra GR16:$src, GR8:$cnt))]>;
148   def Srl8     : Pseudo<(outs GR8:$dst), (ins GR8:$src, GR8:$cnt),
149                         "# Srl8 PSEUDO",
150                         [(set GR8:$dst, (MSP430srl GR8:$src, GR8:$cnt))]>;
151   def Srl16    : Pseudo<(outs GR16:$dst), (ins GR16:$src, GR8:$cnt),
152                         "# Srl16 PSEUDO",
153                         [(set GR16:$dst, (MSP430srl GR16:$src, GR8:$cnt))]>;
154
155   }
156 }
157
158 let hasSideEffects = 0 in
159 def NOP : Pseudo<(outs), (ins), "nop", []>;
160
161 //===----------------------------------------------------------------------===//
162 //  Control Flow Instructions...
163 //
164
165 // FIXME: Provide proper encoding!
166 let isReturn = 1, isTerminator = 1, isBarrier = 1 in {
167   def RET  : IForm16<0x0, DstReg, SrcPostInc, Size2Bytes,
168                      (outs), (ins), "ret",  [(MSP430retflag)]>;
169   def RETI : II16r<0x0, (outs), (ins), "reti", [(MSP430retiflag)]>;
170 }
171
172 let isBranch = 1, isTerminator = 1 in {
173
174 // FIXME: expand opcode & cond field for branches!
175
176 // Direct branch
177 let isBarrier = 1 in {
178   // Short branch
179   def JMP : CJForm<0, 0, (outs), (ins jmptarget:$dst),
180                    "jmp\t$dst",
181                    [(br bb:$dst)]>;
182   let isIndirectBranch = 1 in {
183     // Long branches
184     def Bi  : I16ri<0, (outs), (ins i16imm:$brdst),
185                     "br\t$brdst",
186                     [(brind tblockaddress:$brdst)]>;
187     def Br  : I16rr<0, (outs), (ins GR16:$brdst),
188                     "br\t$brdst",
189                     [(brind GR16:$brdst)]>;
190     def Bm  : I16rm<0, (outs), (ins memsrc:$brdst),
191                     "br\t$brdst",
192                     [(brind (load addr:$brdst))]>;
193   }
194 }
195
196 // Conditional branches
197 let Uses = [SR] in
198   def JCC : CJForm<0, 0,
199                    (outs), (ins jmptarget:$dst, cc:$cc),
200                    "j$cc\t$dst",
201                    [(MSP430brcc bb:$dst, imm:$cc)]>;
202 } // isBranch, isTerminator
203
204 //===----------------------------------------------------------------------===//
205 //  Call Instructions...
206 //
207 let isCall = 1 in
208   // All calls clobber the non-callee saved registers. SPW is marked as
209   // a use to prevent stack-pointer assignments that appear immediately
210   // before calls from potentially appearing dead. Uses for argument
211   // registers are added manually.
212   let Defs = [R12, R13, R14, R15, SR],
213       Uses = [SP] in {
214     def CALLi     : II16i<0x0,
215                           (outs), (ins i16imm:$dst),
216                           "call\t$dst", [(MSP430call imm:$dst)]>;
217     def CALLr     : II16r<0x0,
218                           (outs), (ins GR16:$dst),
219                           "call\t$dst", [(MSP430call GR16:$dst)]>;
220     def CALLm     : II16m<0x0,
221                           (outs), (ins memsrc:$dst),
222                           "call\t${dst:mem}", [(MSP430call (load addr:$dst))]>;
223   }
224
225
226 //===----------------------------------------------------------------------===//
227 //  Miscellaneous Instructions...
228 //
229 let Defs = [SP], Uses = [SP], hasSideEffects=0 in {
230 let mayLoad = 1 in
231 def POP16r   : IForm16<0x0, DstReg, SrcPostInc, Size2Bytes,
232                        (outs GR16:$reg), (ins), "pop.w\t$reg", []>;
233
234 let mayStore = 1 in
235 def PUSH16r  : II16r<0x0,
236                      (outs), (ins GR16:$reg), "push.w\t$reg",[]>;
237 }
238
239 //===----------------------------------------------------------------------===//
240 // Move Instructions
241
242 // FIXME: Provide proper encoding!
243 let hasSideEffects = 0 in {
244 def MOV8rr  : I8rr<0x0,
245                    (outs GR8:$dst), (ins GR8:$src),
246                    "mov.b\t{$src, $dst}",
247                    []>;
248 def MOV16rr : I16rr<0x0,
249                     (outs GR16:$dst), (ins GR16:$src),
250                     "mov.w\t{$src, $dst}",
251                     []>;
252 }
253
254 // FIXME: Provide proper encoding!
255 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
256 def MOV8ri  : I8ri<0x0,
257                    (outs GR8:$dst), (ins i8imm:$src),
258                    "mov.b\t{$src, $dst}",
259                    [(set GR8:$dst, imm:$src)]>;
260 def MOV16ri : I16ri<0x0,
261                     (outs GR16:$dst), (ins i16imm:$src),
262                     "mov.w\t{$src, $dst}",
263                     [(set GR16:$dst, imm:$src)]>;
264 }
265
266 let canFoldAsLoad = 1, isReMaterializable = 1 in {
267 def MOV8rm  : I8rm<0x0,
268                    (outs GR8:$dst), (ins memsrc:$src),
269                    "mov.b\t{$src, $dst}",
270                    [(set GR8:$dst, (load addr:$src))]>;
271 def MOV16rm : I16rm<0x0,
272                     (outs GR16:$dst), (ins memsrc:$src),
273                     "mov.w\t{$src, $dst}",
274                     [(set GR16:$dst, (load addr:$src))]>;
275 }
276
277 def MOVZX16rr8 : I8rr<0x0,
278                       (outs GR16:$dst), (ins GR8:$src),
279                       "mov.b\t{$src, $dst}",
280                       [(set GR16:$dst, (zext GR8:$src))]>;
281 def MOVZX16rm8 : I8rm<0x0,
282                       (outs GR16:$dst), (ins memsrc:$src),
283                       "mov.b\t{$src, $dst}",
284                       [(set GR16:$dst, (zextloadi16i8 addr:$src))]>;
285
286 let mayLoad = 1, hasExtraDefRegAllocReq = 1, Constraints = "$base = $base_wb" in {
287 def MOV8rm_POST  : IForm8<0x0, DstReg, SrcPostInc, Size2Bytes,
288                          (outs GR8:$dst, GR16:$base_wb), (ins GR16:$base),
289                          "mov.b\t{@$base+, $dst}", []>;
290 def MOV16rm_POST : IForm16<0x0, DstReg, SrcPostInc, Size2Bytes,
291                            (outs GR16:$dst, GR16:$base_wb), (ins GR16:$base),
292                            "mov.w\t{@$base+, $dst}", []>;
293 }
294
295 // Any instruction that defines a 8-bit result leaves the high half of the
296 // register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
297 // be copying from a truncate, but any other 8-bit operation will zero-extend
298 // up to 16 bits.
299 def def8 : PatLeaf<(i8 GR8:$src), [{
300   return N->getOpcode() != ISD::TRUNCATE &&
301          N->getOpcode() != TargetOpcode::EXTRACT_SUBREG &&
302          N->getOpcode() != ISD::CopyFromReg;
303 }]>;
304
305 // In the case of a 8-bit def that is known to implicitly zero-extend,
306 // we can use a SUBREG_TO_REG.
307 def : Pat<(i16 (zext def8:$src)),
308           (SUBREG_TO_REG (i16 0), GR8:$src, subreg_8bit)>;
309
310 def MOV8mi  : I8mi<0x0,
311                    (outs), (ins memdst:$dst, i8imm:$src),
312                    "mov.b\t{$src, $dst}",
313                    [(store (i8 imm:$src), addr:$dst)]>;
314 def MOV16mi : I16mi<0x0,
315                     (outs), (ins memdst:$dst, i16imm:$src),
316                     "mov.w\t{$src, $dst}",
317                     [(store (i16 imm:$src), addr:$dst)]>;
318
319 def MOV8mr  : I8mr<0x0,
320                    (outs), (ins memdst:$dst, GR8:$src),
321                    "mov.b\t{$src, $dst}",
322                    [(store GR8:$src, addr:$dst)]>;
323 def MOV16mr : I16mr<0x0,
324                     (outs), (ins memdst:$dst, GR16:$src),
325                     "mov.w\t{$src, $dst}",
326                     [(store GR16:$src, addr:$dst)]>;
327
328 def MOV8mm  : I8mm<0x0,
329                    (outs), (ins memdst:$dst, memsrc:$src),
330                    "mov.b\t{$src, $dst}",
331                    [(store (i8 (load addr:$src)), addr:$dst)]>;
332 def MOV16mm : I16mm<0x0,
333                     (outs), (ins memdst:$dst, memsrc:$src),
334                     "mov.w\t{$src, $dst}",
335                     [(store (i16 (load addr:$src)), addr:$dst)]>;
336
337 //===----------------------------------------------------------------------===//
338 // Arithmetic Instructions
339
340 let Constraints = "$src = $dst" in {
341
342 let Defs = [SR] in {
343
344 let isCommutable = 1 in { // X = ADD Y, Z  == X = ADD Z, Y
345
346 def ADD8rr  : I8rr<0x0,
347                    (outs GR8:$dst), (ins GR8:$src, GR8:$src2),
348                    "add.b\t{$src2, $dst}",
349                    [(set GR8:$dst, (add GR8:$src, GR8:$src2)),
350                     (implicit SR)]>;
351 def ADD16rr : I16rr<0x0,
352                     (outs GR16:$dst), (ins GR16:$src, GR16:$src2),
353                     "add.w\t{$src2, $dst}",
354                     [(set GR16:$dst, (add GR16:$src, GR16:$src2)),
355                      (implicit SR)]>;
356 }
357
358 def ADD8rm  : I8rm<0x0,
359                    (outs GR8:$dst), (ins GR8:$src, memsrc:$src2),
360                    "add.b\t{$src2, $dst}",
361                    [(set GR8:$dst, (add GR8:$src, (load addr:$src2))),
362                     (implicit SR)]>;
363 def ADD16rm : I16rm<0x0,
364                     (outs GR16:$dst), (ins GR16:$src, memsrc:$src2),
365                     "add.w\t{$src2, $dst}",
366                     [(set GR16:$dst, (add GR16:$src, (load addr:$src2))),
367                      (implicit SR)]>;
368
369 let mayLoad = 1, hasExtraDefRegAllocReq = 1, 
370 Constraints = "$base = $base_wb, $src = $dst" in {
371 def ADD8rm_POST : IForm8<0x0, DstReg, SrcPostInc, Size2Bytes,
372                          (outs GR8:$dst, GR16:$base_wb),
373                          (ins GR8:$src, GR16:$base),
374                          "add.b\t{@$base+, $dst}", []>;
375 def ADD16rm_POST : IForm16<0x0, DstReg, SrcPostInc, Size2Bytes,
376                            (outs GR16:$dst, GR16:$base_wb),
377                            (ins GR16:$src, GR16:$base),
378                           "add.w\t{@$base+, $dst}", []>;
379 }
380
381
382 def ADD8ri  : I8ri<0x0,
383                    (outs GR8:$dst), (ins GR8:$src, i8imm:$src2),
384                    "add.b\t{$src2, $dst}",
385                    [(set GR8:$dst, (add GR8:$src, imm:$src2)),
386                     (implicit SR)]>;
387 def ADD16ri : I16ri<0x0,
388                     (outs GR16:$dst), (ins GR16:$src, i16imm:$src2),
389                     "add.w\t{$src2, $dst}",
390                     [(set GR16:$dst, (add GR16:$src, imm:$src2)),
391                      (implicit SR)]>;
392
393 let Constraints = "" in {
394 def ADD8mr  : I8mr<0x0,
395                    (outs), (ins memdst:$dst, GR8:$src),
396                    "add.b\t{$src, $dst}",
397                    [(store (add (load addr:$dst), GR8:$src), addr:$dst),
398                     (implicit SR)]>;
399 def ADD16mr : I16mr<0x0,
400                     (outs), (ins memdst:$dst, GR16:$src),
401                     "add.w\t{$src, $dst}",
402                     [(store (add (load addr:$dst), GR16:$src), addr:$dst),
403                      (implicit SR)]>;
404
405 def ADD8mi  : I8mi<0x0,
406                    (outs), (ins memdst:$dst, i8imm:$src),
407                    "add.b\t{$src, $dst}",
408                    [(store (add (load addr:$dst), (i8 imm:$src)), addr:$dst),
409                     (implicit SR)]>;
410 def ADD16mi : I16mi<0x0,
411                     (outs), (ins memdst:$dst, i16imm:$src),
412                     "add.w\t{$src, $dst}",
413                     [(store (add (load addr:$dst), (i16 imm:$src)), addr:$dst),
414                      (implicit SR)]>;
415
416 def ADD8mm  : I8mm<0x0,
417                    (outs), (ins memdst:$dst, memsrc:$src),
418                    "add.b\t{$src, $dst}",
419                    [(store (add (load addr:$dst), 
420                                 (i8 (load addr:$src))), addr:$dst),
421                     (implicit SR)]>;
422 def ADD16mm : I16mm<0x0,
423                     (outs), (ins memdst:$dst, memsrc:$src),
424                     "add.w\t{$src, $dst}",
425                     [(store (add (load addr:$dst), 
426                                   (i16 (load addr:$src))), addr:$dst),
427                      (implicit SR)]>;
428 }
429
430 let Uses = [SR] in {
431
432 let isCommutable = 1 in { // X = ADDC Y, Z  == X = ADDC Z, Y
433 def ADC8rr  : I8rr<0x0,
434                    (outs GR8:$dst), (ins GR8:$src, GR8:$src2),
435                    "addc.b\t{$src2, $dst}",
436                    [(set GR8:$dst, (adde GR8:$src, GR8:$src2)),
437                     (implicit SR)]>;
438 def ADC16rr : I16rr<0x0,
439                     (outs GR16:$dst), (ins GR16:$src, GR16:$src2),
440                     "addc.w\t{$src2, $dst}",
441                     [(set GR16:$dst, (adde GR16:$src, GR16:$src2)),
442                      (implicit SR)]>;
443 } // isCommutable
444
445 def ADC8ri  : I8ri<0x0,
446                    (outs GR8:$dst), (ins GR8:$src, i8imm:$src2),
447                    "addc.b\t{$src2, $dst}",
448                    [(set GR8:$dst, (adde GR8:$src, imm:$src2)),
449                     (implicit SR)]>;
450 def ADC16ri : I16ri<0x0,
451                     (outs GR16:$dst), (ins GR16:$src, i16imm:$src2),
452                     "addc.w\t{$src2, $dst}",
453                     [(set GR16:$dst, (adde GR16:$src, imm:$src2)),
454                      (implicit SR)]>;
455
456 def ADC8rm  : I8rm<0x0,
457                    (outs GR8:$dst), (ins GR8:$src, memsrc:$src2),
458                    "addc.b\t{$src2, $dst}",
459                    [(set GR8:$dst, (adde GR8:$src, (load addr:$src2))),
460                     (implicit SR)]>;
461 def ADC16rm : I16rm<0x0,
462                     (outs GR16:$dst), (ins GR16:$src, memsrc:$src2),
463                     "addc.w\t{$src2, $dst}",
464                     [(set GR16:$dst, (adde GR16:$src, (load addr:$src2))),
465                      (implicit SR)]>;
466
467 let Constraints = "" in {
468 def ADC8mr  : I8mr<0x0,
469                    (outs), (ins memdst:$dst, GR8:$src),
470                    "addc.b\t{$src, $dst}",
471                    [(store (adde (load addr:$dst), GR8:$src), addr:$dst),
472                     (implicit SR)]>;
473 def ADC16mr : I16mr<0x0,
474                     (outs), (ins memdst:$dst, GR16:$src),
475                     "addc.w\t{$src, $dst}",
476                     [(store (adde (load addr:$dst), GR16:$src), addr:$dst),
477                      (implicit SR)]>;
478
479 def ADC8mi  : I8mi<0x0,
480                    (outs), (ins memdst:$dst, i8imm:$src),
481                    "addc.b\t{$src, $dst}",
482                    [(store (adde (load addr:$dst), (i8 imm:$src)), addr:$dst),
483                     (implicit SR)]>;
484 def ADC16mi : I16mi<0x0,
485                     (outs), (ins memdst:$dst, i16imm:$src),
486                     "addc.w\t{$src, $dst}",
487                     [(store (adde (load addr:$dst), (i16 imm:$src)), addr:$dst),
488                      (implicit SR)]>;
489
490 def ADC8mm  : I8mm<0x0,
491                    (outs), (ins memdst:$dst, memsrc:$src),
492                    "addc.b\t{$src, $dst}",
493                    [(store (adde (load addr:$dst), 
494                                  (i8 (load addr:$src))), addr:$dst),
495                     (implicit SR)]>;
496 def ADC16mm : I8mm<0x0,
497                    (outs), (ins memdst:$dst, memsrc:$src),
498                    "addc.w\t{$src, $dst}",
499                    [(store (adde (load addr:$dst), 
500                                  (i16 (load addr:$src))), addr:$dst),
501                     (implicit SR)]>;
502 }
503
504 } // Uses = [SR]
505
506 let isCommutable = 1 in { // X = AND Y, Z  == X = AND Z, Y
507 def AND8rr  : I8rr<0x0,
508                    (outs GR8:$dst), (ins GR8:$src, GR8:$src2),
509                    "and.b\t{$src2, $dst}",
510                    [(set GR8:$dst, (and GR8:$src, GR8:$src2)),
511                     (implicit SR)]>;
512 def AND16rr : I16rr<0x0,
513                     (outs GR16:$dst), (ins GR16:$src, GR16:$src2),
514                     "and.w\t{$src2, $dst}",
515                     [(set GR16:$dst, (and GR16:$src, GR16:$src2)),
516                      (implicit SR)]>;
517 }
518
519 def AND8ri  : I8ri<0x0,
520                    (outs GR8:$dst), (ins GR8:$src, i8imm:$src2),
521                    "and.b\t{$src2, $dst}",
522                    [(set GR8:$dst, (and GR8:$src, imm:$src2)),
523                     (implicit SR)]>;
524 def AND16ri : I16ri<0x0,
525                     (outs GR16:$dst), (ins GR16:$src, i16imm:$src2),
526                     "and.w\t{$src2, $dst}",
527                     [(set GR16:$dst, (and GR16:$src, imm:$src2)),
528                      (implicit SR)]>;
529
530 def AND8rm  : I8rm<0x0,
531                    (outs GR8:$dst), (ins GR8:$src, memsrc:$src2),
532                    "and.b\t{$src2, $dst}",
533                    [(set GR8:$dst, (and GR8:$src, (load addr:$src2))),
534                     (implicit SR)]>;
535 def AND16rm : I16rm<0x0,
536                     (outs GR16:$dst), (ins GR16:$src, memsrc:$src2),
537                     "and.w\t{$src2, $dst}",
538                     [(set GR16:$dst, (and GR16:$src, (load addr:$src2))),
539                      (implicit SR)]>;
540
541 let mayLoad = 1, hasExtraDefRegAllocReq = 1, 
542 Constraints = "$base = $base_wb, $src = $dst" in {
543 def AND8rm_POST : IForm8<0x0, DstReg, SrcPostInc, Size2Bytes,
544                          (outs GR8:$dst, GR16:$base_wb),
545                          (ins GR8:$src, GR16:$base),
546                          "and.b\t{@$base+, $dst}", []>;
547 def AND16rm_POST : IForm16<0x0, DstReg, SrcPostInc, Size2Bytes,
548                            (outs GR16:$dst, GR16:$base_wb),
549                            (ins GR16:$src, GR16:$base),
550                            "and.w\t{@$base+, $dst}", []>;
551 }
552
553 let Constraints = "" in {
554 def AND8mr  : I8mr<0x0,
555                    (outs), (ins memdst:$dst, GR8:$src),
556                    "and.b\t{$src, $dst}",
557                    [(store (and (load addr:$dst), GR8:$src), addr:$dst),
558                     (implicit SR)]>;
559 def AND16mr : I16mr<0x0,
560                     (outs), (ins memdst:$dst, GR16:$src),
561                     "and.w\t{$src, $dst}",
562                     [(store (and (load addr:$dst), GR16:$src), addr:$dst),
563                      (implicit SR)]>;
564
565 def AND8mi  : I8mi<0x0,
566                    (outs), (ins memdst:$dst, i8imm:$src),
567                    "and.b\t{$src, $dst}",
568                    [(store (and (load addr:$dst), (i8 imm:$src)), addr:$dst),
569                     (implicit SR)]>;
570 def AND16mi : I16mi<0x0,
571                     (outs), (ins memdst:$dst, i16imm:$src),
572                     "and.w\t{$src, $dst}",
573                     [(store (and (load addr:$dst), (i16 imm:$src)), addr:$dst),
574                      (implicit SR)]>;
575
576 def AND8mm  : I8mm<0x0,
577                    (outs), (ins memdst:$dst, memsrc:$src),
578                    "and.b\t{$src, $dst}",
579                    [(store (and (load addr:$dst), 
580                                 (i8 (load addr:$src))), addr:$dst),
581                     (implicit SR)]>;
582 def AND16mm : I16mm<0x0,
583                     (outs), (ins memdst:$dst, memsrc:$src),
584                     "and.w\t{$src, $dst}",
585                     [(store (and (load addr:$dst), 
586                                  (i16 (load addr:$src))), addr:$dst),
587                      (implicit SR)]>;
588 }
589
590 let isCommutable = 1 in { // X = OR Y, Z  == X = OR Z, Y
591 def OR8rr  : I8rr<0x0,
592                   (outs GR8:$dst), (ins GR8:$src, GR8:$src2),
593                   "bis.b\t{$src2, $dst}",
594                   [(set GR8:$dst, (or GR8:$src, GR8:$src2))]>;
595 def OR16rr : I16rr<0x0,
596                    (outs GR16:$dst), (ins GR16:$src, GR16:$src2),
597                    "bis.w\t{$src2, $dst}",
598                    [(set GR16:$dst, (or GR16:$src, GR16:$src2))]>;
599 }
600
601 def OR8ri  : I8ri<0x0,
602                   (outs GR8:$dst), (ins GR8:$src, i8imm:$src2),
603                   "bis.b\t{$src2, $dst}",
604                   [(set GR8:$dst, (or GR8:$src, imm:$src2))]>;
605 def OR16ri : I16ri<0x0,
606                    (outs GR16:$dst), (ins GR16:$src, i16imm:$src2),
607                    "bis.w\t{$src2, $dst}",
608                    [(set GR16:$dst, (or GR16:$src, imm:$src2))]>;
609
610 def OR8rm  : I8rm<0x0,
611                   (outs GR8:$dst), (ins GR8:$src, memsrc:$src2),
612                   "bis.b\t{$src2, $dst}",
613                   [(set GR8:$dst, (or GR8:$src, (load addr:$src2)))]>;
614 def OR16rm : I16rm<0x0,
615                    (outs GR16:$dst), (ins GR16:$src, memsrc:$src2),
616                    "bis.w\t{$src2, $dst}",
617                    [(set GR16:$dst, (or GR16:$src, (load addr:$src2)))]>;
618
619 let mayLoad = 1, hasExtraDefRegAllocReq = 1, 
620 Constraints = "$base = $base_wb, $src = $dst" in {
621 def OR8rm_POST : IForm8<0x0, DstReg, SrcPostInc, Size2Bytes,
622                         (outs GR8:$dst, GR16:$base_wb),
623                         (ins GR8:$src, GR16:$base),
624                         "bis.b\t{@$base+, $dst}", []>;
625 def OR16rm_POST : IForm16<0x0, DstReg, SrcPostInc, Size2Bytes,
626                           (outs GR16:$dst, GR16:$base_wb),
627                           (ins GR16:$src, GR16:$base),
628                           "bis.w\t{@$base+, $dst}", []>;
629 }
630
631 let Constraints = "" in {
632 def OR8mr  : I8mr<0x0,
633                   (outs), (ins memdst:$dst, GR8:$src),
634                   "bis.b\t{$src, $dst}",
635                   [(store (or (load addr:$dst), GR8:$src), addr:$dst)]>;
636 def OR16mr : I16mr<0x0,
637                    (outs), (ins memdst:$dst, GR16:$src),
638                    "bis.w\t{$src, $dst}",
639                    [(store (or (load addr:$dst), GR16:$src), addr:$dst)]>;
640
641 def OR8mi  : I8mi<0x0, 
642                   (outs), (ins memdst:$dst, i8imm:$src),
643                   "bis.b\t{$src, $dst}",
644                   [(store (or (load addr:$dst), (i8 imm:$src)), addr:$dst)]>;
645 def OR16mi : I16mi<0x0,
646                    (outs), (ins memdst:$dst, i16imm:$src),
647                    "bis.w\t{$src, $dst}",
648                    [(store (or (load addr:$dst), (i16 imm:$src)), addr:$dst)]>;
649
650 def OR8mm  : I8mm<0x0,
651                   (outs), (ins memdst:$dst, memsrc:$src),
652                   "bis.b\t{$src, $dst}",
653                   [(store (or (i8 (load addr:$dst)),
654                               (i8 (load addr:$src))), addr:$dst)]>;
655 def OR16mm : I16mm<0x0,
656                    (outs), (ins memdst:$dst, memsrc:$src),
657                    "bis.w\t{$src, $dst}",
658                    [(store (or (i16 (load addr:$dst)),
659                                (i16 (load addr:$src))), addr:$dst)]>;
660 }
661
662 // bic does not modify condition codes
663 def BIC8rr :  I8rr<0x0,
664                    (outs GR8:$dst), (ins GR8:$src, GR8:$src2),
665                    "bic.b\t{$src2, $dst}",
666                    [(set GR8:$dst, (and GR8:$src, (not GR8:$src2)))]>;
667 def BIC16rr : I16rr<0x0,
668                     (outs GR16:$dst), (ins GR16:$src, GR16:$src2),
669                     "bic.w\t{$src2, $dst}",
670                     [(set GR16:$dst, (and GR16:$src, (not GR16:$src2)))]>;
671
672 def BIC8rm :  I8rm<0x0,
673                    (outs GR8:$dst), (ins GR8:$src, memsrc:$src2),
674                    "bic.b\t{$src2, $dst}",
675                     [(set GR8:$dst, (and GR8:$src, (not (i8 (load addr:$src2)))))]>;
676 def BIC16rm : I16rm<0x0,
677                     (outs GR16:$dst), (ins GR16:$src, memsrc:$src2),
678                     "bic.w\t{$src2, $dst}",
679                     [(set GR16:$dst, (and GR16:$src, (not (i16 (load addr:$src2)))))]>;
680
681 let Constraints = "" in {
682 def BIC8mr :  I8mr<0x0,
683                    (outs), (ins memdst:$dst, GR8:$src),
684                    "bic.b\t{$src, $dst}",
685                    [(store (and (load addr:$dst), (not GR8:$src)), addr:$dst)]>;
686 def BIC16mr : I16mr<0x0,
687                     (outs), (ins memdst:$dst, GR16:$src),
688                     "bic.w\t{$src, $dst}",
689                     [(store (and (load addr:$dst), (not GR16:$src)), addr:$dst)]>;
690
691 def BIC8mm :  I8mm<0x0,
692                    (outs), (ins memdst:$dst, memsrc:$src),
693                    "bic.b\t{$src, $dst}",
694                    [(store (and (load addr:$dst),
695                                 (not (i8 (load addr:$src)))), addr:$dst)]>;
696 def BIC16mm : I16mm<0x0,
697                     (outs), (ins memdst:$dst, memsrc:$src),
698                     "bic.w\t{$src, $dst}",
699                     [(store (and (load addr:$dst),
700                                  (not (i16 (load addr:$src)))), addr:$dst)]>;
701 }
702
703 let isCommutable = 1 in { // X = XOR Y, Z  == X = XOR Z, Y
704 def XOR8rr  : I8rr<0x0,
705                    (outs GR8:$dst), (ins GR8:$src, GR8:$src2),
706                    "xor.b\t{$src2, $dst}",
707                    [(set GR8:$dst, (xor GR8:$src, GR8:$src2)),
708                     (implicit SR)]>;
709 def XOR16rr : I16rr<0x0,
710                     (outs GR16:$dst), (ins GR16:$src, GR16:$src2),
711                     "xor.w\t{$src2, $dst}",
712                     [(set GR16:$dst, (xor GR16:$src, GR16:$src2)),
713                      (implicit SR)]>;
714 }
715
716 def XOR8ri  : I8ri<0x0,
717                    (outs GR8:$dst), (ins GR8:$src, i8imm:$src2),
718                    "xor.b\t{$src2, $dst}",
719                    [(set GR8:$dst, (xor GR8:$src, imm:$src2)),
720                     (implicit SR)]>;
721 def XOR16ri : I16ri<0x0,
722                     (outs GR16:$dst), (ins GR16:$src, i16imm:$src2),
723                     "xor.w\t{$src2, $dst}",
724                     [(set GR16:$dst, (xor GR16:$src, imm:$src2)),
725                      (implicit SR)]>;
726
727 def XOR8rm  : I8rm<0x0,
728                    (outs GR8:$dst), (ins GR8:$src, memsrc:$src2),
729                    "xor.b\t{$src2, $dst}",
730                    [(set GR8:$dst, (xor GR8:$src, (load addr:$src2))),
731                     (implicit SR)]>;
732 def XOR16rm : I16rm<0x0,
733                     (outs GR16:$dst), (ins GR16:$src, memsrc:$src2),
734                     "xor.w\t{$src2, $dst}",
735                     [(set GR16:$dst, (xor GR16:$src, (load addr:$src2))),
736                      (implicit SR)]>;
737
738 let mayLoad = 1, hasExtraDefRegAllocReq = 1, 
739 Constraints = "$base = $base_wb, $src = $dst" in {
740 def XOR8rm_POST : IForm8<0x0, DstReg, SrcPostInc, Size2Bytes,
741                          (outs GR8:$dst, GR16:$base_wb),
742                          (ins GR8:$src, GR16:$base),
743                          "xor.b\t{@$base+, $dst}", []>;
744 def XOR16rm_POST : IForm16<0x0, DstReg, SrcPostInc, Size2Bytes,
745                            (outs GR16:$dst, GR16:$base_wb),
746                            (ins GR16:$src, GR16:$base),
747                            "xor.w\t{@$base+, $dst}", []>;
748 }
749
750 let Constraints = "" in {
751 def XOR8mr  : I8mr<0x0,
752                    (outs), (ins memdst:$dst, GR8:$src),
753                    "xor.b\t{$src, $dst}",
754                    [(store (xor (load addr:$dst), GR8:$src), addr:$dst),
755                     (implicit SR)]>;
756 def XOR16mr : I16mr<0x0,
757                     (outs), (ins memdst:$dst, GR16:$src),
758                     "xor.w\t{$src, $dst}",
759                     [(store (xor (load addr:$dst), GR16:$src), addr:$dst),
760                      (implicit SR)]>;
761
762 def XOR8mi  : I8mi<0x0,
763                    (outs), (ins memdst:$dst, i8imm:$src),
764                    "xor.b\t{$src, $dst}",
765                    [(store (xor (load addr:$dst), (i8 imm:$src)), addr:$dst),
766                     (implicit SR)]>;
767 def XOR16mi : I16mi<0x0,
768                     (outs), (ins memdst:$dst, i16imm:$src),
769                     "xor.w\t{$src, $dst}",
770                     [(store (xor (load addr:$dst), (i16 imm:$src)), addr:$dst),
771                      (implicit SR)]>;
772
773 def XOR8mm  : I8mm<0x0,
774                    (outs), (ins memdst:$dst, memsrc:$src),
775                    "xor.b\t{$src, $dst}",
776                    [(store (xor (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
777                     (implicit SR)]>;
778 def XOR16mm : I16mm<0x0,
779                     (outs), (ins memdst:$dst, memsrc:$src),
780                     "xor.w\t{$src, $dst}",
781                     [(store (xor (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
782                      (implicit SR)]>;
783 }
784
785
786 def SUB8rr  : I8rr<0x0,
787                    (outs GR8:$dst), (ins GR8:$src, GR8:$src2),
788                    "sub.b\t{$src2, $dst}",
789                    [(set GR8:$dst, (sub GR8:$src, GR8:$src2)),
790                     (implicit SR)]>;
791 def SUB16rr : I16rr<0x0,
792                     (outs GR16:$dst), (ins GR16:$src, GR16:$src2),
793                     "sub.w\t{$src2, $dst}",
794                     [(set GR16:$dst, (sub GR16:$src, GR16:$src2)),
795                      (implicit SR)]>;
796
797 def SUB8ri  : I8ri<0x0,
798                    (outs GR8:$dst), (ins GR8:$src, i8imm:$src2),
799                    "sub.b\t{$src2, $dst}",
800                    [(set GR8:$dst, (sub GR8:$src, imm:$src2)),
801                     (implicit SR)]>;
802 def SUB16ri : I16ri<0x0,
803                     (outs GR16:$dst), (ins GR16:$src, i16imm:$src2),
804                     "sub.w\t{$src2, $dst}",
805                     [(set GR16:$dst, (sub GR16:$src, imm:$src2)),
806                      (implicit SR)]>;
807
808 def SUB8rm  : I8rm<0x0,
809                    (outs GR8:$dst), (ins GR8:$src, memsrc:$src2),
810                    "sub.b\t{$src2, $dst}",
811                    [(set GR8:$dst, (sub GR8:$src, (load addr:$src2))),
812                     (implicit SR)]>;
813 def SUB16rm : I16rm<0x0,
814                     (outs GR16:$dst), (ins GR16:$src, memsrc:$src2),
815                     "sub.w\t{$src2, $dst}",
816                     [(set GR16:$dst, (sub GR16:$src, (load addr:$src2))),
817                      (implicit SR)]>;
818
819 let mayLoad = 1, hasExtraDefRegAllocReq = 1, 
820 Constraints = "$base = $base_wb, $src = $dst" in {
821 def SUB8rm_POST : IForm8<0x0, DstReg, SrcPostInc, Size2Bytes,
822                          (outs GR8:$dst, GR16:$base_wb),
823                          (ins GR8:$src, GR16:$base),
824                          "sub.b\t{@$base+, $dst}", []>;
825 def SUB16rm_POST : IForm16<0x0, DstReg, SrcPostInc, Size2Bytes,
826                           (outs GR16:$dst, GR16:$base_wb),
827                           (ins GR16:$src, GR16:$base),
828                           "sub.w\t{@$base+, $dst}", []>;
829 }
830
831 let Constraints = "" in {
832 def SUB8mr  : I8mr<0x0,
833                    (outs), (ins memdst:$dst, GR8:$src),
834                    "sub.b\t{$src, $dst}",
835                    [(store (sub (load addr:$dst), GR8:$src), addr:$dst),
836                     (implicit SR)]>;
837 def SUB16mr : I16mr<0x0,
838                     (outs), (ins memdst:$dst, GR16:$src),
839                     "sub.w\t{$src, $dst}",
840                     [(store (sub (load addr:$dst), GR16:$src), addr:$dst),
841                      (implicit SR)]>;
842
843 def SUB8mi  : I8mi<0x0,
844                    (outs), (ins memdst:$dst, i8imm:$src),
845                    "sub.b\t{$src, $dst}",
846                    [(store (sub (load addr:$dst), (i8 imm:$src)), addr:$dst),
847                     (implicit SR)]>;
848 def SUB16mi : I16mi<0x0,
849                     (outs), (ins memdst:$dst, i16imm:$src),
850                     "sub.w\t{$src, $dst}",
851                     [(store (sub (load addr:$dst), (i16 imm:$src)), addr:$dst),
852                      (implicit SR)]>;
853
854 def SUB8mm  : I8mm<0x0,
855                    (outs), (ins memdst:$dst, memsrc:$src),
856                    "sub.b\t{$src, $dst}",
857                    [(store (sub (load addr:$dst), 
858                                 (i8 (load addr:$src))), addr:$dst),
859                     (implicit SR)]>;
860 def SUB16mm : I16mm<0x0,
861                     (outs), (ins memdst:$dst, memsrc:$src),
862                     "sub.w\t{$src, $dst}",
863                     [(store (sub (load addr:$dst), 
864                                  (i16 (load addr:$src))), addr:$dst),
865                      (implicit SR)]>;
866 }
867
868 let Uses = [SR] in {
869 def SBC8rr  : I8rr<0x0,
870                    (outs GR8:$dst), (ins GR8:$src, GR8:$src2),
871                    "subc.b\t{$src2, $dst}",
872                    [(set GR8:$dst, (sube GR8:$src, GR8:$src2)),
873                     (implicit SR)]>;
874 def SBC16rr : I16rr<0x0,
875                     (outs GR16:$dst), (ins GR16:$src, GR16:$src2),
876                     "subc.w\t{$src2, $dst}",
877                     [(set GR16:$dst, (sube GR16:$src, GR16:$src2)),
878                      (implicit SR)]>;
879
880 def SBC8ri  : I8ri<0x0,
881                    (outs GR8:$dst), (ins GR8:$src, i8imm:$src2),
882                    "subc.b\t{$src2, $dst}",
883                    [(set GR8:$dst, (sube GR8:$src, imm:$src2)),
884                     (implicit SR)]>;
885 def SBC16ri : I16ri<0x0,
886                     (outs GR16:$dst), (ins GR16:$src, i16imm:$src2),
887                     "subc.w\t{$src2, $dst}",
888                     [(set GR16:$dst, (sube GR16:$src, imm:$src2)),
889                      (implicit SR)]>;
890
891 def SBC8rm  : I8rm<0x0,
892                    (outs GR8:$dst), (ins GR8:$src, memsrc:$src2),
893                    "subc.b\t{$src2, $dst}",
894                    [(set GR8:$dst, (sube GR8:$src, (load addr:$src2))),
895                     (implicit SR)]>;
896 def SBC16rm : I16rm<0x0,
897                     (outs GR16:$dst), (ins GR16:$src, memsrc:$src2),
898                     "subc.w\t{$src2, $dst}",
899                     [(set GR16:$dst, (sube GR16:$src, (load addr:$src2))),
900                      (implicit SR)]>;
901
902 let Constraints = "" in {
903 def SBC8mr  : I8mr<0x0,
904                    (outs), (ins memdst:$dst, GR8:$src),
905                    "subc.b\t{$src, $dst}",
906                   [(store (sube (load addr:$dst), GR8:$src), addr:$dst),
907                    (implicit SR)]>;
908 def SBC16mr : I16mr<0x0,
909                     (outs), (ins memdst:$dst, GR16:$src),
910                     "subc.w\t{$src, $dst}",
911                     [(store (sube (load addr:$dst), GR16:$src), addr:$dst),
912                      (implicit SR)]>;
913
914 def SBC8mi  : I8mi<0x0,
915                    (outs), (ins memdst:$dst, i8imm:$src),
916                    "subc.b\t{$src, $dst}",
917                    [(store (sube (load addr:$dst), (i8 imm:$src)), addr:$dst),
918                     (implicit SR)]>;
919 def SBC16mi : I16mi<0x0,
920                     (outs), (ins memdst:$dst, i16imm:$src),
921                     "subc.w\t{$src, $dst}",
922                     [(store (sube (load addr:$dst), (i16 imm:$src)), addr:$dst),
923                      (implicit SR)]>;
924
925 def SBC8mm  : I8mm<0x0,
926                    (outs), (ins memdst:$dst, memsrc:$src),
927                    "subc.b\t{$src, $dst}",
928                    [(store (sube (load addr:$dst),
929                                  (i8 (load addr:$src))), addr:$dst),
930                     (implicit SR)]>;
931 def SBC16mm : I16mm<0x0,
932                     (outs), (ins memdst:$dst, memsrc:$src),
933                     "subc.w\t{$src, $dst}",
934                     [(store (sube (load addr:$dst),
935                             (i16 (load addr:$src))), addr:$dst),
936                      (implicit SR)]>;
937 }
938
939 } // Uses = [SR]
940
941 // FIXME: memory variant!
942 def SAR8r1  : II8r<0x0,
943                    (outs GR8:$dst), (ins GR8:$src),
944                    "rra.b\t$dst",
945                    [(set GR8:$dst, (MSP430rra GR8:$src)),
946                     (implicit SR)]>;
947 def SAR16r1 : II16r<0x0,
948                     (outs GR16:$dst), (ins GR16:$src),
949                     "rra.w\t$dst",
950                     [(set GR16:$dst, (MSP430rra GR16:$src)),
951                      (implicit SR)]>;
952
953 def SHL8r1  : I8rr<0x0,
954                    (outs GR8:$dst), (ins GR8:$src),
955                    "rla.b\t$dst",
956                    [(set GR8:$dst, (MSP430rla GR8:$src)),
957                     (implicit SR)]>;
958 def SHL16r1 : I16rr<0x0,
959                     (outs GR16:$dst), (ins GR16:$src),
960                     "rla.w\t$dst",
961                     [(set GR16:$dst, (MSP430rla GR16:$src)),
962                      (implicit SR)]>;
963
964 def SAR8r1c  : Pseudo<(outs GR8:$dst), (ins GR8:$src),
965                       "clrc\n\t"
966                       "rrc.b\t$dst",
967                       [(set GR8:$dst, (MSP430rrc GR8:$src)),
968                        (implicit SR)]>;
969 def SAR16r1c : Pseudo<(outs GR16:$dst), (ins GR16:$src),
970                       "clrc\n\t"
971                       "rrc.w\t$dst",
972                       [(set GR16:$dst, (MSP430rrc GR16:$src)),
973                        (implicit SR)]>;
974
975 // FIXME: Memory sext's ?
976 def SEXT16r : II16r<0x0,
977                     (outs GR16:$dst), (ins GR16:$src),
978                     "sxt\t$dst",
979                     [(set GR16:$dst, (sext_inreg GR16:$src, i8)),
980                      (implicit SR)]>;
981
982 } // Defs = [SR]
983
984 def ZEXT16r : I8rr<0x0,
985                    (outs GR16:$dst), (ins GR16:$src),
986                    "mov.b\t{$src, $dst}",
987                    [(set GR16:$dst, (zext (trunc GR16:$src)))]>;
988
989 // FIXME: Memory bitswaps?
990 def SWPB16r : II16r<0x0,
991                     (outs GR16:$dst), (ins GR16:$src),
992                     "swpb\t$dst",
993                     [(set GR16:$dst, (bswap GR16:$src))]>;
994
995 } // Constraints = "$src = $dst"
996
997 // Integer comparisons
998 let Defs = [SR] in {
999 def CMP8rr  : I8rr<0x0,
1000                    (outs), (ins GR8:$src, GR8:$src2),
1001                    "cmp.b\t{$src2, $src}",
1002                    [(MSP430cmp GR8:$src, GR8:$src2), (implicit SR)]>;
1003 def CMP16rr : I16rr<0x0,
1004                     (outs), (ins GR16:$src, GR16:$src2),
1005                     "cmp.w\t{$src2, $src}",
1006                     [(MSP430cmp GR16:$src, GR16:$src2), (implicit SR)]>;
1007
1008 def CMP8ri  : I8ri<0x0,
1009                    (outs), (ins GR8:$src, i8imm:$src2),
1010                    "cmp.b\t{$src2, $src}",
1011                    [(MSP430cmp GR8:$src, imm:$src2), (implicit SR)]>;
1012 def CMP16ri : I16ri<0x0,
1013                     (outs), (ins GR16:$src, i16imm:$src2),
1014                     "cmp.w\t{$src2, $src}",
1015                     [(MSP430cmp GR16:$src, imm:$src2), (implicit SR)]>;
1016
1017 def CMP8mi  : I8mi<0x0,
1018                    (outs), (ins memsrc:$src, i8imm:$src2),
1019                    "cmp.b\t{$src2, $src}",
1020                    [(MSP430cmp (load addr:$src),
1021                                (i8 imm:$src2)), (implicit SR)]>;
1022 def CMP16mi : I16mi<0x0,
1023                     (outs), (ins memsrc:$src, i16imm:$src2),
1024                     "cmp.w\t{$src2, $src}",
1025                      [(MSP430cmp (load addr:$src),
1026                                  (i16 imm:$src2)), (implicit SR)]>;
1027
1028 def CMP8rm  : I8rm<0x0,
1029                    (outs), (ins GR8:$src, memsrc:$src2),
1030                    "cmp.b\t{$src2, $src}",
1031                    [(MSP430cmp GR8:$src, (load addr:$src2)), 
1032                     (implicit SR)]>;
1033 def CMP16rm : I16rm<0x0,
1034                     (outs), (ins GR16:$src, memsrc:$src2),
1035                     "cmp.w\t{$src2, $src}",
1036                     [(MSP430cmp GR16:$src, (load addr:$src2)),
1037                      (implicit SR)]>;
1038
1039 def CMP8mr  : I8mr<0x0,
1040                    (outs), (ins memsrc:$src, GR8:$src2),
1041                    "cmp.b\t{$src2, $src}",
1042                    [(MSP430cmp (load addr:$src), GR8:$src2),
1043                     (implicit SR)]>;
1044 def CMP16mr : I16mr<0x0,
1045                     (outs), (ins memsrc:$src, GR16:$src2),
1046                     "cmp.w\t{$src2, $src}",
1047                     [(MSP430cmp (load addr:$src), GR16:$src2), 
1048                      (implicit SR)]>;
1049
1050
1051 // BIT TESTS, just sets condition codes
1052 // Note that the C condition is set differently than when using CMP.
1053 let isCommutable = 1 in {
1054 def BIT8rr  : I8rr<0x0,
1055                    (outs), (ins GR8:$src, GR8:$src2),
1056                    "bit.b\t{$src2, $src}",
1057                    [(MSP430cmp (and_su GR8:$src, GR8:$src2), 0),
1058                     (implicit SR)]>;
1059 def BIT16rr : I16rr<0x0,
1060                     (outs), (ins GR16:$src, GR16:$src2),
1061                     "bit.w\t{$src2, $src}",
1062                     [(MSP430cmp (and_su GR16:$src, GR16:$src2), 0),
1063                      (implicit SR)]>;
1064 }
1065 def BIT8ri  : I8ri<0x0,
1066                    (outs), (ins GR8:$src, i8imm:$src2),
1067                    "bit.b\t{$src2, $src}",
1068                    [(MSP430cmp (and_su GR8:$src, imm:$src2), 0),
1069                     (implicit SR)]>;
1070 def BIT16ri : I16ri<0x0,
1071                     (outs), (ins GR16:$src, i16imm:$src2),
1072                     "bit.w\t{$src2, $src}",
1073                     [(MSP430cmp (and_su GR16:$src, imm:$src2), 0),
1074                      (implicit SR)]>;
1075
1076 def BIT8rm  : I8rm<0x0,
1077                    (outs), (ins GR8:$src, memdst:$src2),
1078                    "bit.b\t{$src2, $src}",
1079                    [(MSP430cmp (and_su GR8:$src,  (load addr:$src2)), 0),
1080                     (implicit SR)]>;
1081 def BIT16rm : I16rm<0x0,
1082                     (outs), (ins GR16:$src, memdst:$src2),
1083                     "bit.w\t{$src2, $src}",
1084                     [(MSP430cmp (and_su GR16:$src,  (load addr:$src2)), 0),
1085                      (implicit SR)]>;
1086
1087 def BIT8mr  : I8mr<0x0,
1088                   (outs), (ins memsrc:$src, GR8:$src2),
1089                   "bit.b\t{$src2, $src}",
1090                   [(MSP430cmp (and_su (load addr:$src), GR8:$src2), 0),
1091                    (implicit SR)]>;
1092 def BIT16mr : I16mr<0x0,
1093                     (outs), (ins memsrc:$src, GR16:$src2),
1094                     "bit.w\t{$src2, $src}",
1095                     [(MSP430cmp (and_su (load addr:$src), GR16:$src2), 0),
1096                      (implicit SR)]>;
1097
1098 def BIT8mi  : I8mi<0x0,
1099                    (outs), (ins memsrc:$src, i8imm:$src2),
1100                    "bit.b\t{$src2, $src}",
1101                    [(MSP430cmp (and_su (load addr:$src), (i8 imm:$src2)), 0),
1102                     (implicit SR)]>;
1103 def BIT16mi : I16mi<0x0,
1104                     (outs), (ins memsrc:$src, i16imm:$src2),
1105                     "bit.w\t{$src2, $src}",
1106                     [(MSP430cmp (and_su (load addr:$src), (i16 imm:$src2)), 0),
1107                      (implicit SR)]>;
1108
1109 def BIT8mm  : I8mm<0x0,
1110                    (outs), (ins memsrc:$src, memsrc:$src2),
1111                    "bit.b\t{$src2, $src}",
1112                    [(MSP430cmp (and_su (i8 (load addr:$src)),
1113                                        (load addr:$src2)),
1114                                  0),
1115                       (implicit SR)]>;
1116 def BIT16mm : I16mm<0x0,
1117                     (outs), (ins memsrc:$src, memsrc:$src2),
1118                     "bit.w\t{$src2, $src}",
1119                     [(MSP430cmp (and_su (i16 (load addr:$src)),
1120                                         (load addr:$src2)),
1121                                  0),
1122                      (implicit SR)]>;
1123 } // Defs = [SR]
1124
1125 //===----------------------------------------------------------------------===//
1126 // Non-Instruction Patterns
1127
1128 // extload
1129 def : Pat<(extloadi16i8 addr:$src), (MOVZX16rm8 addr:$src)>;
1130
1131 // anyext
1132 def : Pat<(i16 (anyext GR8:$src)),
1133           (SUBREG_TO_REG (i16 0), GR8:$src, subreg_8bit)>;
1134
1135 // truncs
1136 def : Pat<(i8 (trunc GR16:$src)),
1137           (EXTRACT_SUBREG GR16:$src, subreg_8bit)>;
1138
1139 // GlobalAddress, ExternalSymbol
1140 def : Pat<(i16 (MSP430Wrapper tglobaladdr:$dst)), (MOV16ri tglobaladdr:$dst)>;
1141 def : Pat<(i16 (MSP430Wrapper texternalsym:$dst)), (MOV16ri texternalsym:$dst)>;
1142 def : Pat<(i16 (MSP430Wrapper tblockaddress:$dst)), (MOV16ri tblockaddress:$dst)>;
1143
1144 def : Pat<(add GR16:$src, (MSP430Wrapper tglobaladdr :$src2)),
1145           (ADD16ri GR16:$src, tglobaladdr:$src2)>;
1146 def : Pat<(add GR16:$src, (MSP430Wrapper texternalsym:$src2)),
1147           (ADD16ri GR16:$src, texternalsym:$src2)>;
1148 def : Pat<(add GR16:$src, (MSP430Wrapper tblockaddress:$src2)),
1149           (ADD16ri GR16:$src, tblockaddress:$src2)>;
1150
1151 def : Pat<(store (i16 (MSP430Wrapper tglobaladdr:$src)), addr:$dst),
1152           (MOV16mi addr:$dst, tglobaladdr:$src)>;
1153 def : Pat<(store (i16 (MSP430Wrapper texternalsym:$src)), addr:$dst),
1154           (MOV16mi addr:$dst, texternalsym:$src)>;
1155 def : Pat<(store (i16 (MSP430Wrapper tblockaddress:$src)), addr:$dst),
1156           (MOV16mi addr:$dst, tblockaddress:$src)>;
1157
1158 // calls
1159 def : Pat<(MSP430call (i16 tglobaladdr:$dst)),
1160           (CALLi tglobaladdr:$dst)>;
1161 def : Pat<(MSP430call (i16 texternalsym:$dst)),
1162           (CALLi texternalsym:$dst)>;
1163
1164 // add and sub always produce carry
1165 def : Pat<(addc GR16:$src, GR16:$src2),
1166           (ADD16rr GR16:$src, GR16:$src2)>;
1167 def : Pat<(addc GR16:$src, (load addr:$src2)),
1168           (ADD16rm GR16:$src, addr:$src2)>;
1169 def : Pat<(addc GR16:$src, imm:$src2),
1170           (ADD16ri GR16:$src, imm:$src2)>;
1171 def : Pat<(store (addc (load addr:$dst), GR16:$src), addr:$dst),
1172           (ADD16mr addr:$dst, GR16:$src)>;
1173 def : Pat<(store (addc (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
1174           (ADD16mm addr:$dst, addr:$src)>;
1175
1176 def : Pat<(addc GR8:$src, GR8:$src2),
1177           (ADD8rr GR8:$src, GR8:$src2)>;
1178 def : Pat<(addc GR8:$src, (load addr:$src2)),
1179           (ADD8rm GR8:$src, addr:$src2)>;
1180 def : Pat<(addc GR8:$src, imm:$src2),
1181           (ADD8ri GR8:$src, imm:$src2)>;
1182 def : Pat<(store (addc (load addr:$dst), GR8:$src), addr:$dst),
1183           (ADD8mr addr:$dst, GR8:$src)>;
1184 def : Pat<(store (addc (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
1185           (ADD8mm addr:$dst, addr:$src)>;
1186
1187 def : Pat<(subc GR16:$src, GR16:$src2),
1188           (SUB16rr GR16:$src, GR16:$src2)>;
1189 def : Pat<(subc GR16:$src, (load addr:$src2)),
1190           (SUB16rm GR16:$src, addr:$src2)>;
1191 def : Pat<(subc GR16:$src, imm:$src2),
1192           (SUB16ri GR16:$src, imm:$src2)>;
1193 def : Pat<(store (subc (load addr:$dst), GR16:$src), addr:$dst),
1194           (SUB16mr addr:$dst, GR16:$src)>;
1195 def : Pat<(store (subc (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
1196           (SUB16mm addr:$dst, addr:$src)>;
1197
1198 def : Pat<(subc GR8:$src, GR8:$src2),
1199           (SUB8rr GR8:$src, GR8:$src2)>;
1200 def : Pat<(subc GR8:$src, (load addr:$src2)),
1201           (SUB8rm GR8:$src, addr:$src2)>;
1202 def : Pat<(subc GR8:$src, imm:$src2),
1203           (SUB8ri GR8:$src, imm:$src2)>;
1204 def : Pat<(store (subc (load addr:$dst), GR8:$src), addr:$dst),
1205           (SUB8mr addr:$dst, GR8:$src)>;
1206 def : Pat<(store (subc (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
1207           (SUB8mm addr:$dst, addr:$src)>;
1208
1209 // peephole patterns
1210 def : Pat<(and GR16:$src, 255), (ZEXT16r GR16:$src)>;
1211 def : Pat<(MSP430cmp (trunc (and_su GR16:$src, GR16:$src2)), 0),
1212           (BIT8rr (EXTRACT_SUBREG GR16:$src, subreg_8bit),
1213                   (EXTRACT_SUBREG GR16:$src2, subreg_8bit))>;