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