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