xref: /netbsd-src/external/apache2/llvm/dist/llvm/lib/Target/MSP430/MSP430InstrInfo.td (revision 82d56013d7b633d116a93943de88e08335357a7c)
17330f729Sjoerg//===-- MSP430InstrInfo.td - MSP430 Instruction defs -------*- tablegen -*-===//
27330f729Sjoerg//
37330f729Sjoerg// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47330f729Sjoerg// See https://llvm.org/LICENSE.txt for license information.
57330f729Sjoerg// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67330f729Sjoerg//
77330f729Sjoerg//===----------------------------------------------------------------------===//
87330f729Sjoerg//
97330f729Sjoerg// This file describes the MSP430 instructions in TableGen format.
107330f729Sjoerg//
117330f729Sjoerg//===----------------------------------------------------------------------===//
127330f729Sjoerg
137330f729Sjoerginclude "MSP430InstrFormats.td"
147330f729Sjoerg
157330f729Sjoerg//===----------------------------------------------------------------------===//
167330f729Sjoerg// Type Constraints.
177330f729Sjoerg//===----------------------------------------------------------------------===//
187330f729Sjoergclass SDTCisI8<int OpNum> : SDTCisVT<OpNum, i8>;
197330f729Sjoergclass SDTCisI16<int OpNum> : SDTCisVT<OpNum, i16>;
207330f729Sjoerg
217330f729Sjoerg//===----------------------------------------------------------------------===//
227330f729Sjoerg// Type Profiles.
237330f729Sjoerg//===----------------------------------------------------------------------===//
247330f729Sjoergdef SDT_MSP430Call         : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>;
257330f729Sjoergdef SDT_MSP430CallSeqStart : SDCallSeqStart<[SDTCisVT<0, i16>,
267330f729Sjoerg                                             SDTCisVT<1, i16>]>;
277330f729Sjoergdef SDT_MSP430CallSeqEnd   : SDCallSeqEnd<[SDTCisVT<0, i16>, SDTCisVT<1, i16>]>;
287330f729Sjoergdef SDT_MSP430Wrapper      : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>,
297330f729Sjoerg                                                  SDTCisPtrTy<0>]>;
307330f729Sjoergdef SDT_MSP430Cmp          : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
317330f729Sjoergdef SDT_MSP430BrCC         : SDTypeProfile<0, 2, [SDTCisVT<0, OtherVT>,
327330f729Sjoerg                                                  SDTCisVT<1, i8>]>;
337330f729Sjoergdef SDT_MSP430SelectCC     : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>,
347330f729Sjoerg                                                  SDTCisSameAs<1, 2>,
357330f729Sjoerg                                                  SDTCisVT<3, i8>]>;
367330f729Sjoergdef SDT_MSP430DAdd         : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>,
377330f729Sjoerg                                                  SDTCisSameAs<0, 2>,
387330f729Sjoerg                                                  SDTCisInt<0>]>;
397330f729Sjoerg
407330f729Sjoerg//===----------------------------------------------------------------------===//
417330f729Sjoerg// MSP430 Specific Node Definitions.
427330f729Sjoerg//===----------------------------------------------------------------------===//
437330f729Sjoergdef MSP430retflag  : SDNode<"MSP430ISD::RET_FLAG", SDTNone,
447330f729Sjoerg                       [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
457330f729Sjoergdef MSP430retiflag : SDNode<"MSP430ISD::RETI_FLAG", SDTNone,
467330f729Sjoerg                       [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
477330f729Sjoerg
487330f729Sjoergdef MSP430rra     : SDNode<"MSP430ISD::RRA", SDTIntUnaryOp, []>;
497330f729Sjoergdef MSP430rla     : SDNode<"MSP430ISD::RLA", SDTIntUnaryOp, []>;
507330f729Sjoergdef MSP430rrc     : SDNode<"MSP430ISD::RRC", SDTIntUnaryOp, []>;
517330f729Sjoergdef MSP430rrcl    : SDNode<"MSP430ISD::RRCL", SDTIntUnaryOp, []>;
527330f729Sjoerg
537330f729Sjoergdef MSP430call    : SDNode<"MSP430ISD::CALL", SDT_MSP430Call,
547330f729Sjoerg                     [SDNPHasChain, SDNPOutGlue, SDNPOptInGlue, SDNPVariadic]>;
557330f729Sjoergdef MSP430callseq_start :
567330f729Sjoerg                 SDNode<"ISD::CALLSEQ_START", SDT_MSP430CallSeqStart,
577330f729Sjoerg                        [SDNPHasChain, SDNPOutGlue]>;
587330f729Sjoergdef MSP430callseq_end :
597330f729Sjoerg                 SDNode<"ISD::CALLSEQ_END",   SDT_MSP430CallSeqEnd,
607330f729Sjoerg                        [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
617330f729Sjoergdef MSP430Wrapper : SDNode<"MSP430ISD::Wrapper", SDT_MSP430Wrapper>;
627330f729Sjoergdef MSP430cmp     : SDNode<"MSP430ISD::CMP", SDT_MSP430Cmp, [SDNPOutGlue]>;
637330f729Sjoergdef MSP430brcc    : SDNode<"MSP430ISD::BR_CC", SDT_MSP430BrCC,
647330f729Sjoerg                            [SDNPHasChain, SDNPInGlue]>;
657330f729Sjoergdef MSP430selectcc: SDNode<"MSP430ISD::SELECT_CC", SDT_MSP430SelectCC,
667330f729Sjoerg                            [SDNPInGlue]>;
677330f729Sjoergdef MSP430dadd    : SDNode<"MSP430ISD::DADD", SDT_MSP430DAdd, []>;
687330f729Sjoerg
697330f729Sjoerg//===----------------------------------------------------------------------===//
707330f729Sjoerg// MSP430 Operand Definitions.
717330f729Sjoerg//===----------------------------------------------------------------------===//
727330f729Sjoerg
737330f729Sjoergdef MemAsmOperand : AsmOperandClass {
747330f729Sjoerg  let Name = "Mem";
757330f729Sjoerg}
767330f729Sjoerg
777330f729Sjoerg// Address operands
787330f729Sjoergdef memsrc : Operand<i16> {
797330f729Sjoerg  let PrintMethod = "printSrcMemOperand";
807330f729Sjoerg  let MIOperandInfo = (ops GR16, i16imm);
817330f729Sjoerg  let ParserMatchClass = MemAsmOperand;
827330f729Sjoerg  let EncoderMethod = "getMemOpValue";
837330f729Sjoerg  let DecoderMethod = "DecodeMemOperand";
847330f729Sjoerg}
857330f729Sjoerg
867330f729Sjoergdef memdst : Operand<i16> {
877330f729Sjoerg  let PrintMethod = "printSrcMemOperand";
887330f729Sjoerg  let MIOperandInfo = (ops GR16, i16imm);
897330f729Sjoerg  let ParserMatchClass = MemAsmOperand;
907330f729Sjoerg  let EncoderMethod = "getMemOpValue";
917330f729Sjoerg  let DecoderMethod = "DecodeMemOperand";
927330f729Sjoerg}
937330f729Sjoerg
947330f729Sjoergdef IndRegAsmOperand : AsmOperandClass {
957330f729Sjoerg  let Name = "IndReg";
967330f729Sjoerg  let RenderMethod = "addRegOperands";
977330f729Sjoerg}
987330f729Sjoerg
997330f729Sjoergdef indreg : Operand<i16> {
1007330f729Sjoerg  let PrintMethod = "printIndRegOperand";
1017330f729Sjoerg  let MIOperandInfo = (ops GR16);
1027330f729Sjoerg  let ParserMatchClass = IndRegAsmOperand;
1037330f729Sjoerg  let DecoderMethod = "DecodeGR16RegisterClass";
1047330f729Sjoerg}
1057330f729Sjoerg
1067330f729Sjoergdef PostIndRegAsmOperand : AsmOperandClass {
1077330f729Sjoerg  let Name = "PostIndReg";
1087330f729Sjoerg  let RenderMethod = "addRegOperands";
1097330f729Sjoerg}
1107330f729Sjoerg
1117330f729Sjoergdef postreg : Operand<i16> {
1127330f729Sjoerg  let PrintMethod = "printPostIndRegOperand";
1137330f729Sjoerg  let MIOperandInfo = (ops GR16);
1147330f729Sjoerg  let ParserMatchClass = PostIndRegAsmOperand;
1157330f729Sjoerg  let DecoderMethod = "DecodeGR16RegisterClass";
1167330f729Sjoerg}
1177330f729Sjoerg
1187330f729Sjoerg// Short jump targets have OtherVT type and are printed as pcrel imm values.
1197330f729Sjoergdef jmptarget : Operand<OtherVT> {
1207330f729Sjoerg  let PrintMethod = "printPCRelImmOperand";
1217330f729Sjoerg  let EncoderMethod = "getPCRelImmOpValue";
1227330f729Sjoerg}
1237330f729Sjoerg
1247330f729Sjoerg// Operand for printing out a condition code.
1257330f729Sjoergdef cc : Operand<i8> {
1267330f729Sjoerg  let PrintMethod = "printCCOperand";
1277330f729Sjoerg  let EncoderMethod = "getCCOpValue";
1287330f729Sjoerg}
1297330f729Sjoerg
1307330f729Sjoergdef CGImmAsmOperand : AsmOperandClass {
1317330f729Sjoerg  let Name = "CGImm";
1327330f729Sjoerg  let RenderMethod = "addImmOperands";
1337330f729Sjoerg}
1347330f729Sjoerg
1357330f729Sjoergdef cg8imm : Operand<i8>,
1367330f729Sjoerg             ImmLeaf<i8, [{return Imm == 0 || Imm == 1 || Imm == 2 ||
1377330f729Sjoerg                                  Imm == 4 || Imm == 8 || Imm == -1;}]> {
1387330f729Sjoerg  let ParserMatchClass = CGImmAsmOperand;
1397330f729Sjoerg  let EncoderMethod = "getCGImmOpValue";
1407330f729Sjoerg  let DecoderMethod = "DecodeCGImm";
1417330f729Sjoerg}
1427330f729Sjoerg
1437330f729Sjoergdef cg16imm : Operand<i16>,
1447330f729Sjoerg              ImmLeaf<i16, [{return Imm == 0 || Imm == 1 || Imm == 2 ||
1457330f729Sjoerg                                    Imm == 4 || Imm == 8 || Imm == -1;}]> {
1467330f729Sjoerg  let ParserMatchClass = CGImmAsmOperand;
1477330f729Sjoerg  let EncoderMethod = "getCGImmOpValue";
1487330f729Sjoerg  let DecoderMethod = "DecodeCGImm";
1497330f729Sjoerg}
1507330f729Sjoerg
1517330f729Sjoerg//===----------------------------------------------------------------------===//
1527330f729Sjoerg// MSP430 Complex Pattern Definitions.
1537330f729Sjoerg//===----------------------------------------------------------------------===//
1547330f729Sjoerg
1557330f729Sjoergdef addr : ComplexPattern<iPTR, 2, "SelectAddr", [], []>;
1567330f729Sjoerg
1577330f729Sjoerg//===----------------------------------------------------------------------===//
1587330f729Sjoerg// Pattern Fragments
1597330f729Sjoergdef zextloadi16i8 : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>;
1607330f729Sjoergdef  extloadi16i8 : PatFrag<(ops node:$ptr), (i16 ( extloadi8 node:$ptr))>;
1617330f729Sjoergdef bic : PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, (not node:$rhs))>;
1627330f729Sjoergdef and_su : PatFrag<(ops node:$lhs, node:$rhs), (and node:$lhs, node:$rhs), [{
1637330f729Sjoerg  return N->hasOneUse();
1647330f729Sjoerg}]>;
1657330f729Sjoerg//===----------------------------------------------------------------------===//
1667330f729Sjoerg// Instruction list..
1677330f729Sjoerg
1687330f729Sjoerg// ADJCALLSTACKDOWN/UP implicitly use/def SP because they may be expanded into
1697330f729Sjoerg// a stack adjustment and the codegen must know that they may modify the stack
1707330f729Sjoerg// pointer before prolog-epilog rewriting occurs.
1717330f729Sjoerg// Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
1727330f729Sjoerg// sub / add which can clobber SR.
1737330f729Sjoerglet isCodeGenOnly = 1, Defs = [SP, SR], Uses = [SP] in {
1747330f729Sjoergdef ADJCALLSTACKDOWN : Pseudo<(outs), (ins i16imm:$amt1, i16imm:$amt2),
1757330f729Sjoerg                              "#ADJCALLSTACKDOWN $amt1 $amt2",
1767330f729Sjoerg                              [(MSP430callseq_start timm:$amt1, timm:$amt2)]>;
1777330f729Sjoergdef ADJCALLSTACKUP   : Pseudo<(outs), (ins i16imm:$amt1, i16imm:$amt2),
1787330f729Sjoerg                              "#ADJCALLSTACKUP $amt1 $amt2",
1797330f729Sjoerg                              [(MSP430callseq_end timm:$amt1, timm:$amt2)]>;
1807330f729Sjoerg}
1817330f729Sjoerg
1827330f729Sjoerglet isCodeGenOnly = 1, Defs = [SR], Uses = [SP] in {
1837330f729Sjoergdef ADDframe : Pseudo<(outs GR16:$dst), (ins i16imm:$base, i16imm:$offset),
1847330f729Sjoerg                      "# ADDframe PSEUDO", []>;
1857330f729Sjoerg}
1867330f729Sjoerg
1877330f729Sjoerglet isCodeGenOnly = 1, usesCustomInserter = 1 in {
1887330f729Sjoerg  let Uses = [SR] in {
1897330f729Sjoerg  def Select8  : Pseudo<(outs GR8:$dst), (ins GR8:$src, GR8:$src2, i8imm:$cc),
1907330f729Sjoerg                        "# Select8 PSEUDO",
1917330f729Sjoerg                        [(set GR8:$dst,
1927330f729Sjoerg                          (MSP430selectcc GR8:$src, GR8:$src2, imm:$cc))]>;
1937330f729Sjoerg  def Select16 : Pseudo<(outs GR16:$dst), (ins GR16:$src, GR16:$src2, i8imm:$cc),
1947330f729Sjoerg                        "# Select16 PSEUDO",
1957330f729Sjoerg                        [(set GR16:$dst,
1967330f729Sjoerg                          (MSP430selectcc GR16:$src, GR16:$src2, imm:$cc))]>;
1977330f729Sjoerg  }
1987330f729Sjoerg  let Defs = [SR] in {
1997330f729Sjoerg  def Shl8     : Pseudo<(outs GR8:$dst), (ins GR8:$src, GR8:$cnt),
2007330f729Sjoerg                        "# Shl8 PSEUDO",
2017330f729Sjoerg                        [(set GR8:$dst, (shl GR8:$src, GR8:$cnt))]>;
2027330f729Sjoerg  def Shl16    : Pseudo<(outs GR16:$dst), (ins GR16:$src, GR8:$cnt),
2037330f729Sjoerg                        "# Shl16 PSEUDO",
2047330f729Sjoerg                        [(set GR16:$dst, (shl GR16:$src, GR8:$cnt))]>;
2057330f729Sjoerg  def Sra8     : Pseudo<(outs GR8:$dst), (ins GR8:$src, GR8:$cnt),
2067330f729Sjoerg                        "# Sra8 PSEUDO",
2077330f729Sjoerg                        [(set GR8:$dst, (sra GR8:$src, GR8:$cnt))]>;
2087330f729Sjoerg  def Sra16    : Pseudo<(outs GR16:$dst), (ins GR16:$src, GR8:$cnt),
2097330f729Sjoerg                        "# Sra16 PSEUDO",
2107330f729Sjoerg                        [(set GR16:$dst, (sra GR16:$src, GR8:$cnt))]>;
2117330f729Sjoerg  def Srl8     : Pseudo<(outs GR8:$dst), (ins GR8:$src, GR8:$cnt),
2127330f729Sjoerg                        "# Srl8 PSEUDO",
2137330f729Sjoerg                        [(set GR8:$dst, (srl GR8:$src, GR8:$cnt))]>;
2147330f729Sjoerg  def Srl16    : Pseudo<(outs GR16:$dst), (ins GR16:$src, GR8:$cnt),
2157330f729Sjoerg                        "# Srl16 PSEUDO",
2167330f729Sjoerg                        [(set GR16:$dst, (srl GR16:$src, GR8:$cnt))]>;
2177330f729Sjoerg  def Rrcl8    : Pseudo<(outs GR8:$dst), (ins GR8:$src), "",
2187330f729Sjoerg                        [(set GR8:$dst, (MSP430rrcl GR8:$src))]>;
2197330f729Sjoerg  def Rrcl16   : Pseudo<(outs GR16:$dst), (ins GR16:$src), "",
2207330f729Sjoerg                        [(set GR16:$dst, (MSP430rrcl GR16:$src))]>;
2217330f729Sjoerg  }
2227330f729Sjoerg}
2237330f729Sjoerg
2247330f729Sjoerg//===----------------------------------------------------------------------===//
2257330f729Sjoerg//  Control Flow Instructions...
2267330f729Sjoerg//
2277330f729Sjoerg
2287330f729Sjoerglet isReturn = 1, isTerminator = 1, isBarrier = 1 in {
2297330f729Sjoerg  def RET  : IForm16<0b0100, DstReg, SrcPostInc, 2,
2307330f729Sjoerg                     (outs), (ins), "ret",  [(MSP430retflag)]> {
2317330f729Sjoerg    let DecoderNamespace = "Delta";
2327330f729Sjoerg    let rs = 1;
2337330f729Sjoerg    let rd = 0;
2347330f729Sjoerg  }
2357330f729Sjoerg  def RETI : IIForm16<0b110, SrcReg, 2,
2367330f729Sjoerg                      (outs), (ins), "reti", [(MSP430retiflag)]> {
2377330f729Sjoerg    let rs = 0;
2387330f729Sjoerg  }
2397330f729Sjoerg}
2407330f729Sjoerg
2417330f729Sjoerglet isBranch = 1, isTerminator = 1 in {
2427330f729Sjoerg
2437330f729Sjoerg// FIXME: expand opcode & cond field for branches!
2447330f729Sjoerg
2457330f729Sjoerg// Direct branch
2467330f729Sjoerglet isBarrier = 1 in {
2477330f729Sjoerg  // Short branch
2487330f729Sjoerg  def JMP : CJForm<(outs), (ins jmptarget:$dst),
2497330f729Sjoerg                   "jmp\t$dst",
2507330f729Sjoerg                   [(br bb:$dst)]> {
2517330f729Sjoerg    let cond = 0b111;
2527330f729Sjoerg  }
2537330f729Sjoerg  let isIndirectBranch = 1, rd = 0 in {
2547330f729Sjoerg    // Long branches
2557330f729Sjoerg    def Bi  : I16ri<0b0100, (outs), (ins i16imm:$imm),
2567330f729Sjoerg                    "br\t$imm",
2577330f729Sjoerg                    [(brind tblockaddress:$imm)]>;
2587330f729Sjoerg    def Br  : I16rr<0b0100, (outs), (ins GR16:$rs),
2597330f729Sjoerg                    "br\t$rs",
2607330f729Sjoerg                    [(brind GR16:$rs)]>;
2617330f729Sjoerg    def Bm  : I16rm<0b0100, (outs), (ins memsrc:$src),
2627330f729Sjoerg                    "br\t$src",
2637330f729Sjoerg                    [(brind (load addr:$src))]>;
2647330f729Sjoerg  }
2657330f729Sjoerg}
2667330f729Sjoerg
2677330f729Sjoerg// Conditional branches
2687330f729Sjoerglet Uses = [SR] in
2697330f729Sjoerg  def JCC : CJForm<(outs), (ins jmptarget:$dst, cc:$cond),
2707330f729Sjoerg                   "j$cond\t$dst",
2717330f729Sjoerg                   [(MSP430brcc bb:$dst, imm:$cond)]>;
2727330f729Sjoerg} // isBranch, isTerminator
2737330f729Sjoerg
2747330f729Sjoerg//===----------------------------------------------------------------------===//
2757330f729Sjoerg//  Call Instructions...
2767330f729Sjoerg//
2777330f729Sjoerg// All calls clobber the non-callee saved registers. SPW is marked as
2787330f729Sjoerg// a use to prevent stack-pointer assignments that appear immediately
2797330f729Sjoerg// before calls from potentially appearing dead. Uses for argument
2807330f729Sjoerg// registers are added manually.
2817330f729Sjoerglet isCall = 1,
2827330f729Sjoerg    Defs = [R11, R12, R13, R14, R15, SR],
2837330f729Sjoerg    Uses = [SP] in {
2847330f729Sjoerg  def CALLi     : II16i<0b101,
2857330f729Sjoerg                        (outs), (ins i16imm:$imm),
2867330f729Sjoerg                        "call\t$imm", [(MSP430call imm:$imm)]>;
2877330f729Sjoerg  def CALLr     : II16r<0b101,
2887330f729Sjoerg                        (outs), (ins GR16:$rs),
2897330f729Sjoerg                        "call\t$rs", [(MSP430call GR16:$rs)]>;
2907330f729Sjoerg  def CALLm     : II16m<0b101,
2917330f729Sjoerg                        (outs), (ins memsrc:$src),
2927330f729Sjoerg                        "call\t$src", [(MSP430call (load addr:$src))]>;
2937330f729Sjoerg  def CALLn     : II16n<0b101, (outs), (ins indreg:$rs), "call\t$rs", []>;
2947330f729Sjoerg  def CALLp     : II16p<0b101, (outs), (ins postreg:$rs), "call\t$rs", []>;
2957330f729Sjoerg}
2967330f729Sjoerg
2977330f729Sjoerg//===----------------------------------------------------------------------===//
2987330f729Sjoerg//  Miscellaneous Instructions...
2997330f729Sjoerg//
3007330f729Sjoerglet Defs = [SP], Uses = [SP], hasSideEffects = 0 in {
3017330f729Sjoerglet mayLoad = 1 in
3027330f729Sjoergdef POP16r   : IForm16<0b0100, DstReg, SrcPostInc, 2,
3037330f729Sjoerg                       (outs GR16:$rd), (ins), "pop\t$rd", []> {
3047330f729Sjoerg  let DecoderNamespace = "Delta";
3057330f729Sjoerg  let rs = 1;
3067330f729Sjoerg}
3077330f729Sjoerg
3087330f729Sjoerglet mayStore = 1 in
3097330f729Sjoergdef PUSH8r :  II8r<0b100, (outs), (ins GR8:$rs), "push.b\t$rs", []>;
3107330f729Sjoergdef PUSH16r : II16r<0b100, (outs), (ins GR16:$rs), "push\t$rs", []>;
3117330f729Sjoergdef PUSH16c : II16c<0b100, (outs), (ins cg16imm:$imm), "push\t$imm", []>;
3127330f729Sjoergdef PUSH16i : II16i<0b100, (outs), (ins i16imm:$imm), "push\t$imm", []>;
3137330f729Sjoerg}
3147330f729Sjoerg
3157330f729Sjoerg//===----------------------------------------------------------------------===//
3167330f729Sjoerg// Move Instructions
3177330f729Sjoerg
3187330f729Sjoerglet hasSideEffects = 0 in {
3197330f729Sjoergdef MOV8rr  : I8rr<0b0100,
3207330f729Sjoerg                   (outs GR8:$rd), (ins GR8:$rs),
3217330f729Sjoerg                   "mov.b\t{$rs, $rd}",
3227330f729Sjoerg                   []>;
3237330f729Sjoergdef MOV16rr : I16rr<0b0100,
3247330f729Sjoerg                    (outs GR16:$rd), (ins GR16:$rs),
3257330f729Sjoerg                    "mov\t{$rs, $rd}",
3267330f729Sjoerg                    []>;
3277330f729Sjoerg}
3287330f729Sjoerg
3297330f729Sjoerglet isReMaterializable = 1, isAsCheapAsAMove = 1 in {
3307330f729Sjoergdef MOV8rc : I8rc<0b0100,
3317330f729Sjoerg                   (outs GR8:$rd), (ins cg8imm:$imm),
3327330f729Sjoerg                   "mov.b\t$imm, $rd",
3337330f729Sjoerg                   [(set GR8:$rd, cg8imm:$imm)]>;
3347330f729Sjoergdef MOV16rc : I16rc<0b0100,
3357330f729Sjoerg                    (outs GR16:$rd), (ins cg16imm:$imm),
3367330f729Sjoerg                    "mov\t$imm, $rd",
3377330f729Sjoerg                    [(set GR16:$rd, cg16imm:$imm)]>;
3387330f729Sjoergdef MOV8ri  : I8ri<0b0100,
3397330f729Sjoerg                   (outs GR8:$rd), (ins i8imm:$imm),
3407330f729Sjoerg                   "mov.b\t{$imm, $rd}",
3417330f729Sjoerg                   [(set GR8:$rd, imm:$imm)]>;
3427330f729Sjoergdef MOV16ri : I16ri<0b0100,
3437330f729Sjoerg                    (outs GR16:$rd), (ins i16imm:$imm),
3447330f729Sjoerg                    "mov\t{$imm, $rd}",
3457330f729Sjoerg                    [(set GR16:$rd, imm:$imm)]>;
3467330f729Sjoerg}
3477330f729Sjoerg
3487330f729Sjoerglet canFoldAsLoad = 1, isReMaterializable = 1 in {
3497330f729Sjoergdef MOV8rm  : I8rm<0b0100,
3507330f729Sjoerg                   (outs GR8:$rd), (ins memsrc:$src),
3517330f729Sjoerg                   "mov.b\t{$src, $rd}",
3527330f729Sjoerg                   [(set GR8:$rd, (load addr:$src))]>;
3537330f729Sjoergdef MOV16rm : I16rm<0b0100,
3547330f729Sjoerg                    (outs GR16:$rd), (ins memsrc:$src),
3557330f729Sjoerg                    "mov\t{$src, $rd}",
3567330f729Sjoerg                    [(set GR16:$rd, (load addr:$src))]>;
3577330f729Sjoergdef MOV8rn  : I8rn<0b0100,
3587330f729Sjoerg                   (outs GR8:$rd), (ins indreg:$rs),
3597330f729Sjoerg                   "mov.b\t{$rs, $rd}",
3607330f729Sjoerg                   [(set GR8:$rd, (load addr:$rs))]>;
3617330f729Sjoergdef MOV16rn : I16rn<0b0100,
3627330f729Sjoerg                    (outs GR16:$rd), (ins indreg:$rs),
3637330f729Sjoerg                    "mov\t{$rs, $rd}",
3647330f729Sjoerg                    [(set GR16:$rd, (load addr:$rs))]>;
3657330f729Sjoerg}
3667330f729Sjoerg
3677330f729Sjoerglet isCodeGenOnly = 1 in {
3687330f729Sjoergdef MOVZX16rr8 : I8rr<0b0100,
3697330f729Sjoerg                      (outs GR16:$rd), (ins GR8:$rs),
3707330f729Sjoerg                      "mov.b\t{$rs, $rd}",
3717330f729Sjoerg                      [(set GR16:$rd, (zext GR8:$rs))]>;
3727330f729Sjoergdef MOVZX16rm8 : I8rm<0b0100,
3737330f729Sjoerg                      (outs GR16:$rd), (ins memsrc:$src),
3747330f729Sjoerg                      "mov.b\t{$src, $rd}",
3757330f729Sjoerg                      [(set GR16:$rd, (zextloadi16i8 addr:$src))]>;
3767330f729Sjoerg}
3777330f729Sjoerg
3787330f729Sjoerglet mayLoad = 1, hasExtraDefRegAllocReq = 1, Constraints = "$rs = $wb" in {
3797330f729Sjoergdef MOV8rp  : I8rp<0b0100,
3807330f729Sjoerg                   (outs GR8:$rd, GR16:$wb), (ins postreg:$rs),
3817330f729Sjoerg                   "mov.b\t{$rs, $rd}", []>;
3827330f729Sjoergdef MOV16rp : I16rp<0b0100,
3837330f729Sjoerg                    (outs GR16:$rd, GR16:$wb), (ins postreg:$rs),
3847330f729Sjoerg                    "mov\t{$rs, $rd}", []>;
3857330f729Sjoerg}
3867330f729Sjoerg
3877330f729Sjoerg// Any instruction that defines a 8-bit result leaves the high half of the
3887330f729Sjoerg// register. Truncate can be lowered to EXTRACT_SUBREG, and CopyFromReg may
3897330f729Sjoerg// be copying from a truncate, but any other 8-bit operation will zero-extend
3907330f729Sjoerg// up to 16 bits.
3917330f729Sjoergdef def8 : PatLeaf<(i8 GR8:$src), [{
3927330f729Sjoerg  return N->getOpcode() != ISD::TRUNCATE &&
3937330f729Sjoerg         N->getOpcode() != TargetOpcode::EXTRACT_SUBREG &&
3947330f729Sjoerg         N->getOpcode() != ISD::CopyFromReg;
3957330f729Sjoerg}]>;
3967330f729Sjoerg
3977330f729Sjoerg// In the case of a 8-bit def that is known to implicitly zero-extend,
3987330f729Sjoerg// we can use a SUBREG_TO_REG.
3997330f729Sjoergdef : Pat<(i16 (zext def8:$src)),
4007330f729Sjoerg          (SUBREG_TO_REG (i16 0), GR8:$src, subreg_8bit)>;
4017330f729Sjoerg
4027330f729Sjoergdef MOV8mc  : I8mc<0b0100,
4037330f729Sjoerg                   (outs), (ins memdst:$dst, cg8imm:$imm),
4047330f729Sjoerg                   "mov.b\t{$imm, $dst}",
4057330f729Sjoerg                   [(store (i8 cg8imm:$imm), addr:$dst)]>;
4067330f729Sjoergdef MOV16mc : I16mc<0b0100,
4077330f729Sjoerg                    (outs), (ins memdst:$dst, cg16imm:$imm),
4087330f729Sjoerg                    "mov\t{$imm, $dst}",
4097330f729Sjoerg                    [(store (i16 cg16imm:$imm), addr:$dst)]>;
4107330f729Sjoerg
4117330f729Sjoergdef MOV8mi  : I8mi<0b0100,
4127330f729Sjoerg                   (outs), (ins memdst:$dst, i8imm:$imm),
4137330f729Sjoerg                   "mov.b\t{$imm, $dst}",
4147330f729Sjoerg                   [(store (i8 imm:$imm), addr:$dst)]>;
4157330f729Sjoergdef MOV16mi : I16mi<0b0100,
4167330f729Sjoerg                    (outs), (ins memdst:$dst, i16imm:$imm),
4177330f729Sjoerg                    "mov\t{$imm, $dst}",
4187330f729Sjoerg                    [(store (i16 imm:$imm), addr:$dst)]>;
4197330f729Sjoerg
4207330f729Sjoergdef MOV8mr  : I8mr<0b0100,
4217330f729Sjoerg                   (outs), (ins memdst:$dst, GR8:$rs),
4227330f729Sjoerg                   "mov.b\t{$rs, $dst}",
4237330f729Sjoerg                   [(store GR8:$rs, addr:$dst)]>;
4247330f729Sjoergdef MOV16mr : I16mr<0b0100,
4257330f729Sjoerg                    (outs), (ins memdst:$dst, GR16:$rs),
4267330f729Sjoerg                    "mov\t{$rs, $dst}",
4277330f729Sjoerg                    [(store GR16:$rs, addr:$dst)]>;
4287330f729Sjoerg
4297330f729Sjoergdef MOV8mm  : I8mm<0b0100,
4307330f729Sjoerg                   (outs), (ins memdst:$dst, memsrc:$src),
4317330f729Sjoerg                   "mov.b\t{$src, $dst}",
4327330f729Sjoerg                   [(store (i8 (load addr:$src)), addr:$dst)]>;
4337330f729Sjoergdef MOV16mm : I16mm<0b0100,
4347330f729Sjoerg                    (outs), (ins memdst:$dst, memsrc:$src),
4357330f729Sjoerg                    "mov\t{$src, $dst}",
4367330f729Sjoerg                    [(store (i16 (load addr:$src)), addr:$dst)]>;
4377330f729Sjoerg
4387330f729Sjoergdef MOV8mn  : I8mn<0b0100, (outs), (ins memdst:$dst, indreg:$rs),
4397330f729Sjoerg                   "mov.b\t{$rs, $dst}", []>;
4407330f729Sjoergdef MOV16mn : I16mn<0b0100, (outs), (ins memdst:$dst, indreg:$rs),
4417330f729Sjoerg                    "mov\t{$rs, $dst}", []>;
4427330f729Sjoerg
4437330f729Sjoerg//===----------------------------------------------------------------------===//
4447330f729Sjoerg// Arithmetic Instructions
4457330f729Sjoerg
446*82d56013Sjoergmulticlass Arith<bits<4> opcode, string asmstring, SDPatternOperator node,
4477330f729Sjoerg                 bit commutes, list<Register> uses> {
4487330f729Sjoerg  let Defs = [SR], Uses = uses in {
4497330f729Sjoerg  let Constraints = "$src2 = $rd" in {
4507330f729Sjoerg  let isCommutable = commutes in {
4517330f729Sjoerg  def 8rr : I8rr<opcode, (outs GR8:$rd), (ins GR8:$src2, GR8:$rs),
4527330f729Sjoerg                 !strconcat(asmstring, ".b\t$rs, $rd"),
4537330f729Sjoerg                 [(set GR8:$rd, (node GR8:$src2, GR8:$rs)),
4547330f729Sjoerg                  (implicit SR)]>;
4557330f729Sjoerg  def 16rr : I16rr<opcode, (outs GR16:$rd), (ins GR16:$src2, GR16:$rs),
4567330f729Sjoerg                   !strconcat(asmstring, "\t$rs, $rd"),
4577330f729Sjoerg                   [(set GR16:$rd, (node GR16:$src2, GR16:$rs)),
4587330f729Sjoerg                    (implicit SR)]>;
4597330f729Sjoerg  }
4607330f729Sjoerg  def 8rm : I8rm<opcode, (outs GR8:$rd), (ins GR8:$src2, memsrc:$src),
4617330f729Sjoerg                 !strconcat(asmstring, ".b\t$src, $rd"),
4627330f729Sjoerg                 [(set GR8:$rd, (node GR8:$src2, (load addr:$src))),
4637330f729Sjoerg                  (implicit SR)]>;
4647330f729Sjoerg  def 16rm : I16rm<opcode, (outs GR16:$rd), (ins GR16:$src2, memsrc:$src),
4657330f729Sjoerg                   !strconcat(asmstring, "\t$src, $rd"),
4667330f729Sjoerg                   [(set GR16:$rd, (node GR16:$src2, (load addr:$src))),
4677330f729Sjoerg                    (implicit SR)]>;
4687330f729Sjoerg  def 8rn : I8rn<opcode, (outs GR8:$rd), (ins GR8:$src2, indreg:$rs),
4697330f729Sjoerg                 !strconcat(asmstring, ".b\t$rs, $rd"), []>;
4707330f729Sjoerg  def 16rn : I16rn<opcode, (outs GR16:$rd), (ins GR16:$src2, indreg:$rs),
4717330f729Sjoerg                   !strconcat(asmstring, "\t$rs, $rd"), []>;
4727330f729Sjoerg  let mayLoad = 1,
4737330f729Sjoerg      hasExtraDefRegAllocReq = 1,
4747330f729Sjoerg      Constraints = "$rs = $wb, $src2 = $rd" in {
4757330f729Sjoerg  def 8rp : I8rp<opcode, (outs GR8:$rd, GR16:$wb), (ins GR8:$src2, postreg:$rs),
4767330f729Sjoerg                 !strconcat(asmstring, ".b\t$rs, $rd"), []>;
4777330f729Sjoerg  def 16rp : I16rp<opcode, (outs GR16:$rd, GR16:$wb), (ins GR16:$src2, postreg:$rs),
4787330f729Sjoerg                   !strconcat(asmstring, "\t$rs, $rd"), []>;
4797330f729Sjoerg  }
4807330f729Sjoerg  def 8rc : I8rc<opcode, (outs GR8:$rd), (ins GR8:$src2, cg8imm:$imm),
4817330f729Sjoerg                 !strconcat(asmstring, ".b\t$imm, $rd"),
4827330f729Sjoerg                 [(set GR8:$rd, (node GR8:$src2, cg8imm:$imm)),
4837330f729Sjoerg                  (implicit SR)]>;
4847330f729Sjoerg  def 16rc : I16rc<opcode, (outs GR16:$rd), (ins GR16:$src2, cg16imm:$imm),
4857330f729Sjoerg                 !strconcat(asmstring, "\t$imm, $rd"),
4867330f729Sjoerg                 [(set GR16:$rd, (node GR16:$src2, cg16imm:$imm)),
4877330f729Sjoerg                  (implicit SR)]>;
4887330f729Sjoerg  def 8ri : I8ri<opcode, (outs GR8:$rd), (ins GR8:$src2, i8imm:$imm),
4897330f729Sjoerg                 !strconcat(asmstring, ".b\t$imm, $rd"),
4907330f729Sjoerg                 [(set GR8:$rd, (node GR8:$src2, imm:$imm)),
4917330f729Sjoerg                  (implicit SR)]>;
4927330f729Sjoerg  def 16ri : I16ri<opcode, (outs GR16:$rd), (ins GR16:$src2, i16imm:$imm),
4937330f729Sjoerg                 !strconcat(asmstring, "\t$imm, $rd"),
4947330f729Sjoerg                 [(set GR16:$rd, (node GR16:$src2, imm:$imm)),
4957330f729Sjoerg                  (implicit SR)]>;
4967330f729Sjoerg  }
4977330f729Sjoerg  def 8mr : I8mr<opcode, (outs), (ins memdst:$dst, GR8:$rs),
4987330f729Sjoerg                 !strconcat(asmstring, ".b\t$rs, $dst"),
4997330f729Sjoerg                 [(store (node (load addr:$dst), GR8:$rs), addr:$dst),
5007330f729Sjoerg                  (implicit SR)]>;
5017330f729Sjoerg  def 16mr : I16mr<opcode, (outs), (ins memdst:$dst, GR16:$rs),
5027330f729Sjoerg                   !strconcat(asmstring, "\t$rs, $dst"),
5037330f729Sjoerg                   [(store (node (load addr:$dst), GR16:$rs), addr:$dst),
5047330f729Sjoerg                    (implicit SR)]>;
5057330f729Sjoerg  def 8mc : I8mc<opcode, (outs), (ins memdst:$dst, cg8imm:$imm),
5067330f729Sjoerg                 !strconcat(asmstring, ".b\t$imm, $dst"),
5077330f729Sjoerg                 [(store (node (load addr:$dst), (i8 cg8imm:$imm)), addr:$dst),
5087330f729Sjoerg                  (implicit SR)]>;
5097330f729Sjoerg  def 16mc : I16mc<opcode, (outs), (ins memdst:$dst, cg16imm:$imm),
5107330f729Sjoerg                   !strconcat(asmstring, "\t$imm, $dst"),
5117330f729Sjoerg                   [(store (node (load addr:$dst), (i16 cg16imm:$imm)), addr:$dst),
5127330f729Sjoerg                    (implicit SR)]>;
5137330f729Sjoerg  def 8mi : I8mi<opcode, (outs), (ins memdst:$dst, i8imm:$imm),
5147330f729Sjoerg                 !strconcat(asmstring, ".b\t$imm, $dst"),
5157330f729Sjoerg                 [(store (node (load addr:$dst), (i8 imm:$imm)), addr:$dst),
5167330f729Sjoerg                  (implicit SR)]>;
5177330f729Sjoerg  def 16mi : I16mi<opcode, (outs), (ins memdst:$dst, i16imm:$imm),
5187330f729Sjoerg                   !strconcat(asmstring, "\t$imm, $dst"),
5197330f729Sjoerg                   [(store (node (load addr:$dst), (i16 imm:$imm)), addr:$dst),
5207330f729Sjoerg                    (implicit SR)]>;
5217330f729Sjoerg  def 8mm : I8mm<opcode, (outs), (ins memdst:$dst, memsrc:$src),
5227330f729Sjoerg                 !strconcat(asmstring, ".b\t$src, $dst"),
5237330f729Sjoerg                 [(store (node (load addr:$dst),
5247330f729Sjoerg                               (i8 (load addr:$src))), addr:$dst),
5257330f729Sjoerg                  (implicit SR)]>;
5267330f729Sjoerg  def 16mm : I16mm<opcode, (outs), (ins memdst:$dst, memsrc:$src),
5277330f729Sjoerg                   !strconcat(asmstring, "\t$src, $dst"),
5287330f729Sjoerg                   [(store (node (load addr:$dst),
5297330f729Sjoerg                                 (i16 (load addr:$src))), addr:$dst),
5307330f729Sjoerg                    (implicit SR)]>;
5317330f729Sjoerg  def 8mn : I8mn<opcode, (outs), (ins memdst:$dst, indreg:$rs),
5327330f729Sjoerg                 !strconcat(asmstring, ".b\t$rs, $dst"), []>;
5337330f729Sjoerg  def 16mn : I16mn<opcode, (outs), (ins memdst:$dst, indreg:$rs),
5347330f729Sjoerg                   !strconcat(asmstring, "\t$rs, $dst"), []>;
5357330f729Sjoerg  def 8mp : I8mp<opcode, (outs), (ins memdst:$dst, postreg:$rs),
5367330f729Sjoerg                 !strconcat(asmstring, ".b\t$rs, $dst"), []>;
5377330f729Sjoerg  def 16mp : I16mp<opcode, (outs), (ins memdst:$dst, postreg:$rs),
5387330f729Sjoerg                   !strconcat(asmstring, "\t$rs, $dst"), []>;
5397330f729Sjoerg  }
5407330f729Sjoerg}
5417330f729Sjoerg
5427330f729Sjoergdefm ADD  : Arith<0b0101, "add",  add,  1, []>;
5437330f729Sjoergdefm ADDC : Arith<0b0110, "addc", adde, 1, [SR]>;
5447330f729Sjoergdefm AND  : Arith<0b1111, "and",  and,  1, []>;
5457330f729Sjoergdefm BIS  : Arith<0b1101, "bis",  or,   1, []>;
5467330f729Sjoergdefm BIC  : Arith<0b1100, "bic",  bic,  0, []>;
5477330f729Sjoergdefm XOR  : Arith<0b1110, "xor",  xor,  1, []>;
5487330f729Sjoergdefm SUB  : Arith<0b1000, "sub",  sub,  0, []>;
5497330f729Sjoergdefm SUBC : Arith<0b0111, "subc", sube, 0, [SR]>;
5507330f729Sjoergdefm DADD : Arith<0b1010, "dadd", MSP430dadd, 1, [SR]>;
5517330f729Sjoerg
5527330f729Sjoergdef ADC8r   : InstAlias<"adc.b\t$dst",  (ADDC8rc   GR8:$dst,     0)>;
5537330f729Sjoergdef ADC16r  : InstAlias<"adc\t$dst",    (ADDC16rc  GR16:$dst,    0)>;
5547330f729Sjoergdef ADC8m   : InstAlias<"adc.b\t$dst",  (ADDC8mc   memdst:$dst,  0)>;
5557330f729Sjoergdef ADC16m  : InstAlias<"adc\t$dst",    (ADDC16mc  memdst:$dst,  0)>;
5567330f729Sjoerg
5577330f729Sjoergdef DADC8r  : InstAlias<"dadc.b\t$dst", (DADD8rc   GR8:$dst,     0)>;
5587330f729Sjoergdef DADC16r : InstAlias<"dadc\t$dst",   (DADD16rc  GR16:$dst,    0)>;
5597330f729Sjoergdef DADC8m  : InstAlias<"dadc.b\t$dst", (DADD8mc   memdst:$dst,  0)>;
5607330f729Sjoergdef DADC16m : InstAlias<"dadc\t$dst",   (DADD16mc  memdst:$dst,  0)>;
5617330f729Sjoerg
5627330f729Sjoergdef DEC8r   : InstAlias<"dec.b\t$dst",  (SUB8rc    GR8:$dst,     1)>;
5637330f729Sjoergdef DEC16r  : InstAlias<"dec\t$dst",    (SUB16rc   GR16:$dst,    1)>;
5647330f729Sjoergdef DEC8m   : InstAlias<"dec.b\t$dst",  (SUB8mc    memdst:$dst,  1)>;
5657330f729Sjoergdef DEC16m  : InstAlias<"dec\t$dst",    (SUB16mc   memdst:$dst,  1)>;
5667330f729Sjoerg
5677330f729Sjoergdef DECD8r  : InstAlias<"decd.b\t$dst", (SUB8rc    GR8:$dst,     2)>;
5687330f729Sjoergdef DECD16r : InstAlias<"decd\t$dst",   (SUB16rc   GR16:$dst,    2)>;
5697330f729Sjoergdef DECD8m  : InstAlias<"decd.b\t$dst", (SUB8mc    memdst:$dst,  2)>;
5707330f729Sjoergdef DECD16m : InstAlias<"decd\t$dst",   (SUB16mc   memdst:$dst,  2)>;
5717330f729Sjoerg
5727330f729Sjoergdef INC8r   : InstAlias<"inc.b\t$dst",  (ADD8rc    GR8:$dst,     1)>;
5737330f729Sjoergdef INC16r  : InstAlias<"inc\t$dst",    (ADD16rc   GR16:$dst,    1)>;
5747330f729Sjoergdef INC8m   : InstAlias<"inc.b\t$dst",  (ADD8mc    memdst:$dst,  1)>;
5757330f729Sjoergdef INC16m  : InstAlias<"inc\t$dst",    (ADD16mc   memdst:$dst,  1)>;
5767330f729Sjoerg
5777330f729Sjoergdef INCD8r  : InstAlias<"incd.b\t$dst", (ADD8rc    GR8:$dst,     2)>;
5787330f729Sjoergdef INCD16r : InstAlias<"incd\t$dst",   (ADD16rc   GR16:$dst,    2)>;
5797330f729Sjoergdef INCD8m  : InstAlias<"incd.b\t$dst", (ADD8mc    memdst:$dst,  2)>;
5807330f729Sjoergdef INCD16m : InstAlias<"incd\t$dst",   (ADD16mc   memdst:$dst,  2)>;
5817330f729Sjoerg
5827330f729Sjoergdef SBC8r   : InstAlias<"sbc.b\t$dst",  (SUBC8rc   GR8:$dst,     0)>;
5837330f729Sjoergdef SBC16r  : InstAlias<"sbc\t$dst",    (SUBC16rc  GR16:$dst,    0)>;
5847330f729Sjoergdef SBC8m   : InstAlias<"sbc.b\t$dst",  (SUBC8mc   memdst:$dst,  0)>;
5857330f729Sjoergdef SBC16m  : InstAlias<"sbc\t$dst",    (SUBC16mc  memdst:$dst,  0)>;
5867330f729Sjoerg
5877330f729Sjoergdef INV8r   : InstAlias<"inv.b\t$dst",  (XOR8rc    GR8:$dst,    -1)>;
5887330f729Sjoergdef INV16r  : InstAlias<"inv\t$dst",    (XOR16rc   GR16:$dst,   -1)>;
5897330f729Sjoergdef INV8m   : InstAlias<"inv.b\t$dst",  (XOR8mc    memdst:$dst, -1)>;
5907330f729Sjoergdef INV16m  : InstAlias<"inv\t$dst",    (XOR16mc   memdst:$dst, -1)>;
5917330f729Sjoerg
5927330f729Sjoerg// printAliasInstr() doesn't check $dst operands are actually equal
5937330f729Sjoerg// for RLA and RLC aliases below, so disable printing aliases.
5947330f729Sjoerg
5957330f729Sjoergdef RLA8r   : InstAlias<"rla.b\t$dst",  (ADD8rr    GR8:$dst,     GR8:$dst),    0>;
5967330f729Sjoergdef RLA16r  : InstAlias<"rla\t$dst",    (ADD16rr   GR16:$dst,    GR16:$dst),   0>;
5977330f729Sjoergdef RLA8m   : InstAlias<"rla.b\t$dst",  (ADD8mm    memdst:$dst,  memdst:$dst), 0>;
5987330f729Sjoergdef RLA16m  : InstAlias<"rla\t$dst",    (ADD16mm   memdst:$dst,  memdst:$dst), 0>;
5997330f729Sjoerg
6007330f729Sjoergdef RLC8r   : InstAlias<"rlc.b\t$dst",  (ADDC8rr   GR8:$dst,     GR8:$dst),    0>;
6017330f729Sjoergdef RLC16r  : InstAlias<"rlc\t$dst",    (ADDC16rr  GR16:$dst,    GR16:$dst),   0>;
6027330f729Sjoergdef RLC8m   : InstAlias<"rlc.b\t$dst",  (ADDC8mm   memdst:$dst,  memdst:$dst), 0>;
6037330f729Sjoergdef RLC16m  : InstAlias<"rlc\t$dst",    (ADDC16mm  memdst:$dst,  memdst:$dst), 0>;
6047330f729Sjoerg
6057330f729Sjoergdef DINT : InstAlias<"dint", (BIC16rc SR, 8)>;
6067330f729Sjoergdef EINT : InstAlias<"eint", (BIS16rc SR, 8)>;
6077330f729Sjoerg
6087330f729Sjoergdef NOP  : InstAlias<"nop",  (MOV16rc CG, 0)>;
6097330f729Sjoerg
6107330f729Sjoergdef CLR8r   : InstAlias<"clr.b\t$dst",  (MOV8rc    GR8:$dst,     0)>;
6117330f729Sjoergdef CLR16r  : InstAlias<"clr\t$dst",    (MOV16rc   GR16:$dst,    0)>;
6127330f729Sjoergdef CLR8m   : InstAlias<"clr.b\t$dst",  (MOV8mc    memdst:$dst,  0)>;
6137330f729Sjoergdef CLR16m  : InstAlias<"clr\t$dst",    (MOV16mc   memdst:$dst,  0)>;
6147330f729Sjoerg
6157330f729Sjoergdef CLRC : InstAlias<"clrc", (BIC16rc SR, 1)>;
6167330f729Sjoergdef CLRN : InstAlias<"clrn", (BIC16rc SR, 4)>;
6177330f729Sjoergdef CLRZ : InstAlias<"clrz", (BIC16rc SR, 2)>;
6187330f729Sjoergdef SETC : InstAlias<"setc", (BIS16rc SR, 1)>;
6197330f729Sjoergdef SETN : InstAlias<"setn", (BIS16rc SR, 4)>;
6207330f729Sjoergdef SETZ : InstAlias<"setz", (BIS16rc SR, 2)>;
6217330f729Sjoerg
6227330f729Sjoergdef : Pat<(MSP430rla GR8:$dst),  (ADD8rr  $dst, $dst)>;
6237330f729Sjoergdef : Pat<(MSP430rla GR16:$dst), (ADD16rr $dst, $dst)>;
6247330f729Sjoerg
6257330f729Sjoerg// Format-II (Single Operand) Instruction
6267330f729Sjoerg// Register mode
6277330f729Sjoerglet Constraints = "$rs = $rd" in {
6287330f729Sjoerg
6297330f729Sjoerglet Defs = [SR] in {
6307330f729Sjoergdef RRA8r :   II8r<0b010,
6317330f729Sjoerg                   (outs GR8:$rd), (ins GR8:$rs),
6327330f729Sjoerg                   "rra.b\t$rd",
6337330f729Sjoerg                   [(set GR8:$rd, (MSP430rra GR8:$rs)),
6347330f729Sjoerg                    (implicit SR)]>;
6357330f729Sjoergdef RRA16r : II16r<0b010,
6367330f729Sjoerg                    (outs GR16:$rd), (ins GR16:$rs),
6377330f729Sjoerg                    "rra\t$rd",
6387330f729Sjoerg                    [(set GR16:$rd, (MSP430rra GR16:$rs)),
6397330f729Sjoerg                     (implicit SR)]>;
6407330f729Sjoerg
6417330f729Sjoerglet Uses = [SR] in {
6427330f729Sjoergdef RRC8r :   II8r<0b000,
6437330f729Sjoerg                   (outs GR8:$rd), (ins GR8:$rs),
6447330f729Sjoerg                   "rrc.b\t$rd",
6457330f729Sjoerg                   [(set GR8:$rd, (MSP430rrc GR8:$rs)),
6467330f729Sjoerg                    (implicit SR)]>;
6477330f729Sjoergdef RRC16r : II16r<0b000,
6487330f729Sjoerg                   (outs GR16:$rd), (ins GR16:$rs),
6497330f729Sjoerg                   "rrc\t$rd",
6507330f729Sjoerg                   [(set GR16:$rd, (MSP430rrc GR16:$rs)),
6517330f729Sjoerg                    (implicit SR)]>;
6527330f729Sjoerg} // Uses = [SR]
6537330f729Sjoerg
6547330f729Sjoergdef SEXT16r : II16r<0b011,
6557330f729Sjoerg                    (outs GR16:$rd), (ins GR16:$rs),
6567330f729Sjoerg                    "sxt\t$rd",
6577330f729Sjoerg                    [(set GR16:$rd, (sext_inreg GR16:$rs, i8)),
6587330f729Sjoerg                     (implicit SR)]>;
6597330f729Sjoerg
6607330f729Sjoerg} // Defs = [SR]
6617330f729Sjoerg
6627330f729Sjoerglet isCodeGenOnly = 1 in
6637330f729Sjoergdef ZEXT16r : I8rr<0b0100,
6647330f729Sjoerg                   (outs GR16:$rd), (ins GR16:$rs),
6657330f729Sjoerg                   "mov.b\t{$rs, $rd}",
6667330f729Sjoerg                   [(set GR16:$rd, (zext (trunc GR16:$rs)))]>;
6677330f729Sjoerg
6687330f729Sjoergdef SWPB16r : II16r<0b001,
6697330f729Sjoerg                    (outs GR16:$rd), (ins GR16:$rs),
6707330f729Sjoerg                    "swpb\t$rd",
6717330f729Sjoerg                    [(set GR16:$rd, (bswap GR16:$rs))]>;
6727330f729Sjoerg
6737330f729Sjoerg} // Constraints = "$src = $dst"
6747330f729Sjoerg
6757330f729Sjoerg// Indexed, indirect register and indirect autoincrement modes
6767330f729Sjoerglet Defs = [SR] in {
6777330f729Sjoergdef RRA8m  : II8m<0b010,
6787330f729Sjoerg                   (outs), (ins memsrc:$src),
6797330f729Sjoerg                   "rra.b\t$src",
6807330f729Sjoerg                   [(store (MSP430rra (i8 (load addr:$src))), addr:$src),
6817330f729Sjoerg                    (implicit SR)]>;
6827330f729Sjoergdef RRA16m : II16m<0b010,
6837330f729Sjoerg                   (outs), (ins memsrc:$src),
6847330f729Sjoerg                   "rra\t$src",
6857330f729Sjoerg                   [(store (MSP430rra (i16 (load addr:$src))), addr:$src),
6867330f729Sjoerg                    (implicit SR)]>;
6877330f729Sjoerg
6887330f729Sjoergdef RRA8n  : II8n<0b010, (outs), (ins indreg:$rs), "rra.b\t$rs", []>;
6897330f729Sjoergdef RRA16n : II16n<0b010, (outs), (ins indreg:$rs), "rra\t$rs", []>;
6907330f729Sjoergdef RRA8p  : II8p<0b010, (outs), (ins postreg:$rs), "rra.b\t$rs", []>;
6917330f729Sjoergdef RRA16p : II16p<0b010, (outs), (ins postreg:$rs), "rra\t$rs", []>;
6927330f729Sjoerg
6937330f729Sjoerglet Uses = [SR] in {
6947330f729Sjoergdef RRC8m  : II8m<0b000,
6957330f729Sjoerg                   (outs), (ins memsrc:$src),
6967330f729Sjoerg                   "rrc.b\t$src",
6977330f729Sjoerg                   [(store (MSP430rrc (i8 (load addr:$src))), addr:$src),
6987330f729Sjoerg                    (implicit SR)]>;
6997330f729Sjoergdef RRC16m : II16m<0b000,
7007330f729Sjoerg                   (outs), (ins memsrc:$src),
7017330f729Sjoerg                   "rrc\t$src",
7027330f729Sjoerg                   [(store (MSP430rrc (i16 (load addr:$src))), addr:$src),
7037330f729Sjoerg                    (implicit SR)]>;
7047330f729Sjoerg
7057330f729Sjoergdef RRC8n  : II8n<0b000, (outs), (ins indreg:$rs), "rrc.b\t$rs", []>;
7067330f729Sjoergdef RRC16n : II16n<0b000, (outs), (ins indreg:$rs), "rrc\t$rs", []>;
7077330f729Sjoergdef RRC8p  : II8p<0b000, (outs), (ins postreg:$rs), "rrc.b\t$rs", []>;
7087330f729Sjoergdef RRC16p : II16p<0b000, (outs), (ins postreg:$rs), "rrc\t$rs", []>;
7097330f729Sjoerg
7107330f729Sjoerg} // Uses = [SR]
7117330f729Sjoerg
7127330f729Sjoergdef SEXT16m : II16m<0b011,
7137330f729Sjoerg                    (outs), (ins memsrc:$src),
7147330f729Sjoerg                    "sxt\t$src",
7157330f729Sjoerg                    [(store (sext_inreg (extloadi16i8 addr:$src), i8),
7167330f729Sjoerg                             addr:$src),
7177330f729Sjoerg                     (implicit SR)]>;
7187330f729Sjoergdef SEXT16n : II16n<0b011, (outs), (ins indreg:$rs), "sxt\t$rs", []>;
7197330f729Sjoergdef SEXT16p : II16p<0b011, (outs), (ins postreg:$rs), "sxt\t$rs", []>;
7207330f729Sjoerg
7217330f729Sjoerg} // Defs = [SR]
7227330f729Sjoerg
7237330f729Sjoergdef SWPB16m : II16m<0b001,
7247330f729Sjoerg                   (outs), (ins memsrc:$src),
7257330f729Sjoerg                   "swpb\t$src",
7267330f729Sjoerg                   [(store (bswap (i16 (load addr:$src))), addr:$src)]>;
7277330f729Sjoergdef SWPB16n : II16n<0b001, (outs), (ins indreg:$rs), "swpb\t$rs", []>;
7287330f729Sjoergdef SWPB16p : II16p<0b001, (outs), (ins postreg:$rs), "swpb\t$rs", []>;
7297330f729Sjoerg
7307330f729Sjoerg// Integer comparisons
7317330f729Sjoerglet Defs = [SR] in {
7327330f729Sjoergdef CMP8rr  : I8rr<0b1001,
7337330f729Sjoerg                   (outs), (ins GR8:$rd, GR8:$rs),
7347330f729Sjoerg                   "cmp.b\t$rs, $rd",
7357330f729Sjoerg                   [(MSP430cmp GR8:$rd, GR8:$rs), (implicit SR)]>;
7367330f729Sjoergdef CMP16rr : I16rr<0b1001,
7377330f729Sjoerg                    (outs), (ins GR16:$rd, GR16:$rs),
7387330f729Sjoerg                    "cmp\t$rs, $rd",
7397330f729Sjoerg                    [(MSP430cmp GR16:$rd, GR16:$rs), (implicit SR)]>;
7407330f729Sjoerg
7417330f729Sjoergdef CMP8rc  : I8rc<0b1001,
7427330f729Sjoerg                   (outs), (ins GR8:$rd, cg8imm:$imm),
7437330f729Sjoerg                   "cmp.b\t$imm, $rd",
7447330f729Sjoerg                   [(MSP430cmp GR8:$rd, cg8imm:$imm), (implicit SR)]>;
7457330f729Sjoergdef CMP16rc : I16rc<0b1001,
7467330f729Sjoerg                    (outs), (ins GR16:$rd, cg16imm:$imm),
7477330f729Sjoerg                    "cmp\t$imm, $rd",
7487330f729Sjoerg                    [(MSP430cmp GR16:$rd, cg16imm:$imm), (implicit SR)]>;
7497330f729Sjoerg
7507330f729Sjoergdef CMP8ri  : I8ri<0b1001,
7517330f729Sjoerg                   (outs), (ins GR8:$rd, i8imm:$imm),
7527330f729Sjoerg                   "cmp.b\t$imm, $rd",
7537330f729Sjoerg                   [(MSP430cmp GR8:$rd, imm:$imm), (implicit SR)]>;
7547330f729Sjoergdef CMP16ri : I16ri<0b1001,
7557330f729Sjoerg                    (outs), (ins GR16:$rd, i16imm:$imm),
7567330f729Sjoerg                    "cmp\t$imm, $rd",
7577330f729Sjoerg                    [(MSP430cmp GR16:$rd, imm:$imm), (implicit SR)]>;
7587330f729Sjoerg
7597330f729Sjoergdef CMP8mc  : I8mc<0b1001,
7607330f729Sjoerg                   (outs), (ins memsrc:$dst, cg8imm:$imm),
7617330f729Sjoerg                   "cmp.b\t$imm, $dst",
7627330f729Sjoerg                   [(MSP430cmp (load addr:$dst), (i8 cg8imm:$imm)),
7637330f729Sjoerg                    (implicit SR)]>;
7647330f729Sjoergdef CMP16mc : I16mc<0b1001,
7657330f729Sjoerg                    (outs), (ins memsrc:$dst, cg16imm:$imm),
7667330f729Sjoerg                    "cmp\t$imm, $dst",
7677330f729Sjoerg                    [(MSP430cmp (load addr:$dst), (i16 cg16imm:$imm)),
7687330f729Sjoerg                     (implicit SR)]>;
7697330f729Sjoerg
7707330f729Sjoergdef CMP8mi  : I8mi<0b1001,
7717330f729Sjoerg                   (outs), (ins memsrc:$dst, i8imm:$imm),
7727330f729Sjoerg                   "cmp.b\t$imm, $dst",
7737330f729Sjoerg                   [(MSP430cmp (load addr:$dst),
7747330f729Sjoerg                               (i8 imm:$imm)), (implicit SR)]>;
7757330f729Sjoergdef CMP16mi : I16mi<0b1001,
7767330f729Sjoerg                    (outs), (ins memsrc:$dst, i16imm:$imm),
7777330f729Sjoerg                    "cmp\t$imm, $dst",
7787330f729Sjoerg                     [(MSP430cmp (load addr:$dst),
7797330f729Sjoerg                                 (i16 imm:$imm)), (implicit SR)]>;
7807330f729Sjoerg
7817330f729Sjoergdef CMP8rm  : I8rm<0b1001,
7827330f729Sjoerg                   (outs), (ins GR8:$rd, memsrc:$src),
7837330f729Sjoerg                   "cmp.b\t$src, $rd",
7847330f729Sjoerg                   [(MSP430cmp GR8:$rd, (load addr:$src)),
7857330f729Sjoerg                    (implicit SR)]>;
7867330f729Sjoergdef CMP16rm : I16rm<0b1001,
7877330f729Sjoerg                    (outs), (ins GR16:$rd, memsrc:$src),
7887330f729Sjoerg                    "cmp\t$src, $rd",
7897330f729Sjoerg                    [(MSP430cmp GR16:$rd, (load addr:$src)),
7907330f729Sjoerg                     (implicit SR)]>;
7917330f729Sjoerg
7927330f729Sjoergdef CMP8rn  : I8rn<0b1001,
7937330f729Sjoerg                   (outs), (ins GR8:$rd, indreg:$rs), "cmp.b\t$rs, $rd", []>;
7947330f729Sjoergdef CMP16rn : I16rn<0b1001,
7957330f729Sjoerg                    (outs), (ins GR16:$rd, indreg:$rs), "cmp\t$rs, $rd", []>;
7967330f729Sjoerg
7977330f729Sjoergdef CMP8rp  : I8rp<0b1001,
7987330f729Sjoerg                   (outs), (ins GR8:$rd, postreg:$rs), "cmp.b\t$rs, $rd", []>;
7997330f729Sjoergdef CMP16rp : I16rp<0b1001,
8007330f729Sjoerg                    (outs), (ins GR16:$rd, postreg:$rs), "cmp\t$rs, $rd", []>;
8017330f729Sjoerg
8027330f729Sjoergdef CMP8mr  : I8mr<0b1001,
8037330f729Sjoerg                   (outs), (ins memsrc:$dst, GR8:$rs),
8047330f729Sjoerg                   "cmp.b\t$rs, $dst",
8057330f729Sjoerg                   [(MSP430cmp (load addr:$dst), GR8:$rs),
8067330f729Sjoerg                    (implicit SR)]>;
8077330f729Sjoergdef CMP16mr : I16mr<0b1001,
8087330f729Sjoerg                    (outs), (ins memsrc:$dst, GR16:$rs),
8097330f729Sjoerg                    "cmp\t$rs, $dst",
8107330f729Sjoerg                    [(MSP430cmp (load addr:$dst), GR16:$rs),
8117330f729Sjoerg                     (implicit SR)]>;
8127330f729Sjoergdef CMP8mm  : I8mm<0b1001,
8137330f729Sjoerg                   (outs), (ins memdst:$dst, memsrc:$src),
8147330f729Sjoerg                   "cmp.b\t$src, $dst",
8157330f729Sjoerg                   [(MSP430cmp (load addr:$dst), (i8 (load addr:$src))),
8167330f729Sjoerg                    (implicit SR)]>;
8177330f729Sjoergdef CMP16mm : I16mm<0b1001, (outs), (ins memdst:$dst, memsrc:$src),
8187330f729Sjoerg                    "cmp\t$src, $dst",
8197330f729Sjoerg                    [(MSP430cmp (load addr:$dst), (i16 (load addr:$src))),
8207330f729Sjoerg                     (implicit SR)]>;
8217330f729Sjoerg
8227330f729Sjoergdef CMP8mn  : I8mn<0b1001, (outs), (ins memsrc:$dst, indreg:$rs),
8237330f729Sjoerg                   "cmp.b\t$rs, $dst", []>;
8247330f729Sjoergdef CMP16mn : I16mn<0b1001, (outs), (ins memsrc:$dst, indreg:$rs),
8257330f729Sjoerg                    "cmp\t$rs, $dst", []>;
8267330f729Sjoerg
8277330f729Sjoergdef CMP8mp  : I8mp<0b1001, (outs), (ins memsrc:$dst, postreg:$rs),
8287330f729Sjoerg                   "cmp.b\t$rs, $dst", []>;
8297330f729Sjoergdef CMP16mp : I16mp<0b1001, (outs), (ins memsrc:$dst, postreg:$rs),
8307330f729Sjoerg                    "cmp\t$rs, $dst", []>;
8317330f729Sjoerg
8327330f729Sjoerg// BIT TESTS, just sets condition codes
8337330f729Sjoerg// Note that the C condition is set differently than when using CMP.
8347330f729Sjoerglet isCommutable = 1 in {
8357330f729Sjoergdef BIT8rr  : I8rr<0b1011,
8367330f729Sjoerg                   (outs), (ins GR8:$rd, GR8:$rs),
8377330f729Sjoerg                   "bit.b\t$rs, $rd",
8387330f729Sjoerg                   [(MSP430cmp (and_su GR8:$rd, GR8:$rs), 0),
8397330f729Sjoerg                    (implicit SR)]>;
8407330f729Sjoergdef BIT16rr : I16rr<0b1011,
8417330f729Sjoerg                    (outs), (ins GR16:$rd, GR16:$rs),
8427330f729Sjoerg                    "bit\t$rs, $rd",
8437330f729Sjoerg                    [(MSP430cmp (and_su GR16:$rd, GR16:$rs), 0),
8447330f729Sjoerg                     (implicit SR)]>;
8457330f729Sjoerg}
8467330f729Sjoergdef BIT8rc  : I8rc<0b1011,
8477330f729Sjoerg                   (outs), (ins GR8:$rd, cg8imm:$imm),
8487330f729Sjoerg                   "bit.b\t$imm, $rd",
8497330f729Sjoerg                   [(MSP430cmp (and_su GR8:$rd, cg8imm:$imm), 0),
8507330f729Sjoerg                    (implicit SR)]>;
8517330f729Sjoergdef BIT16rc : I16rc<0b1011,
8527330f729Sjoerg                    (outs), (ins GR16:$rd, cg16imm:$imm),
8537330f729Sjoerg                    "bit\t$imm, $rd",
8547330f729Sjoerg                    [(MSP430cmp (and_su GR16:$rd, cg16imm:$imm), 0),
8557330f729Sjoerg                     (implicit SR)]>;
8567330f729Sjoerg
8577330f729Sjoergdef BIT8ri  : I8ri<0b1011,
8587330f729Sjoerg                   (outs), (ins GR8:$rd, i8imm:$imm),
8597330f729Sjoerg                   "bit.b\t$imm, $rd",
8607330f729Sjoerg                   [(MSP430cmp (and_su GR8:$rd, imm:$imm), 0),
8617330f729Sjoerg                    (implicit SR)]>;
8627330f729Sjoergdef BIT16ri : I16ri<0b1011,
8637330f729Sjoerg                    (outs), (ins GR16:$rd, i16imm:$imm),
8647330f729Sjoerg                    "bit\t$imm, $rd",
8657330f729Sjoerg                    [(MSP430cmp (and_su GR16:$rd, imm:$imm), 0),
8667330f729Sjoerg                     (implicit SR)]>;
8677330f729Sjoerg
8687330f729Sjoergdef BIT8rm  : I8rm<0b1011,
8697330f729Sjoerg                   (outs), (ins GR8:$rd, memdst:$src),
8707330f729Sjoerg                   "bit.b\t$src, $rd",
8717330f729Sjoerg                   [(MSP430cmp (and_su GR8:$rd,  (load addr:$src)), 0),
8727330f729Sjoerg                    (implicit SR)]>;
8737330f729Sjoergdef BIT16rm : I16rm<0b1011,
8747330f729Sjoerg                    (outs), (ins GR16:$rd, memdst:$src),
8757330f729Sjoerg                    "bit\t$src, $rd",
8767330f729Sjoerg                    [(MSP430cmp (and_su GR16:$rd,  (load addr:$src)), 0),
8777330f729Sjoerg                     (implicit SR)]>;
8787330f729Sjoerg
8797330f729Sjoergdef BIT8rn  : I8rn<0b1011, (outs), (ins GR8:$rd, indreg:$rs),
8807330f729Sjoerg                   "bit.b\t$rs, $rd", []>;
8817330f729Sjoergdef BIT16rn : I16rn<0b1011, (outs), (ins GR16:$rd, indreg:$rs),
8827330f729Sjoerg                    "bit\t$rs, $rd", []>;
8837330f729Sjoerg
8847330f729Sjoergdef BIT8rp  : I8rp<0b1011, (outs), (ins GR8:$rd, postreg:$rs),
8857330f729Sjoerg                   "bit.b\t$rs, $rd", []>;
8867330f729Sjoergdef BIT16rp : I16rp<0b1011, (outs), (ins GR16:$rd, postreg:$rs),
8877330f729Sjoerg                    "bit\t$rs, $rd", []>;
8887330f729Sjoerg
8897330f729Sjoergdef BIT8mr  : I8mr<0b1011,
8907330f729Sjoerg                  (outs), (ins memsrc:$dst, GR8:$rs),
8917330f729Sjoerg                  "bit.b\t$rs, $dst",
8927330f729Sjoerg                  [(MSP430cmp (and_su (load addr:$dst), GR8:$rs), 0),
8937330f729Sjoerg                   (implicit SR)]>;
8947330f729Sjoergdef BIT16mr : I16mr<0b1011,
8957330f729Sjoerg                    (outs), (ins memsrc:$dst, GR16:$rs),
8967330f729Sjoerg                    "bit\t$rs, $dst",
8977330f729Sjoerg                    [(MSP430cmp (and_su (load addr:$dst), GR16:$rs), 0),
8987330f729Sjoerg                     (implicit SR)]>;
8997330f729Sjoerg
9007330f729Sjoergdef BIT8mc  : I8mc<0b1011,
9017330f729Sjoerg                   (outs), (ins memsrc:$dst, cg8imm:$imm),
9027330f729Sjoerg                   "bit.b\t$imm, $dst",
9037330f729Sjoerg                   [(MSP430cmp (and_su (load addr:$dst), (i8 cg8imm:$imm)), 0),
9047330f729Sjoerg                    (implicit SR)]>;
9057330f729Sjoergdef BIT16mc : I16mc<0b1011,
9067330f729Sjoerg                    (outs), (ins memdst:$dst, cg16imm:$imm),
9077330f729Sjoerg                    "bit\t$imm, $dst",
9087330f729Sjoerg                    [(MSP430cmp (and_su (load addr:$dst), (i16 cg16imm:$imm)), 0),
9097330f729Sjoerg                     (implicit SR)]>;
9107330f729Sjoerg
9117330f729Sjoergdef BIT8mi  : I8mi<0b1011,
9127330f729Sjoerg                   (outs), (ins memsrc:$dst, i8imm:$imm),
9137330f729Sjoerg                   "bit.b\t$imm, $dst",
9147330f729Sjoerg                   [(MSP430cmp (and_su (load addr:$dst), (i8 imm:$imm)), 0),
9157330f729Sjoerg                    (implicit SR)]>;
9167330f729Sjoergdef BIT16mi : I16mi<0b1011,
9177330f729Sjoerg                    (outs), (ins memsrc:$dst, i16imm:$imm),
9187330f729Sjoerg                    "bit\t$imm, $dst",
9197330f729Sjoerg                    [(MSP430cmp (and_su (load addr:$dst), (i16 imm:$imm)), 0),
9207330f729Sjoerg                     (implicit SR)]>;
9217330f729Sjoerg
9227330f729Sjoergdef BIT8mm  : I8mm<0b1011,
9237330f729Sjoerg                   (outs), (ins memsrc:$dst, memsrc:$src),
9247330f729Sjoerg                   "bit.b\t$src, $dst",
9257330f729Sjoerg                   [(MSP430cmp (and_su (i8 (load addr:$dst)),
9267330f729Sjoerg                                       (load addr:$src)),
9277330f729Sjoerg                                 0),
9287330f729Sjoerg                      (implicit SR)]>;
9297330f729Sjoergdef BIT16mm : I16mm<0b1011,
9307330f729Sjoerg                    (outs), (ins memsrc:$dst, memsrc:$src),
9317330f729Sjoerg                    "bit\t$src, $dst",
9327330f729Sjoerg                    [(MSP430cmp (and_su (i16 (load addr:$dst)),
9337330f729Sjoerg                                        (load addr:$src)),
9347330f729Sjoerg                                 0),
9357330f729Sjoerg                     (implicit SR)]>;
9367330f729Sjoergdef BIT8mn  : I8mn<0b1011, (outs), (ins memsrc:$dst, indreg:$rs),
9377330f729Sjoerg                   "bit.b\t$rs, $dst", []>;
9387330f729Sjoergdef BIT16mn : I16mn<0b1011, (outs), (ins memsrc:$dst, indreg:$rs),
9397330f729Sjoerg                    "bit\t$rs, $dst", []>;
9407330f729Sjoerg
9417330f729Sjoergdef BIT8mp  : I8mp<0b1011, (outs), (ins memsrc:$dst, postreg:$rs),
9427330f729Sjoerg                   "bit.b\t$rs, $dst", []>;
9437330f729Sjoergdef BIT16mp : I16mp<0b1011, (outs), (ins memsrc:$dst, postreg:$rs),
9447330f729Sjoerg                    "bit\t$rs, $dst", []>;
9457330f729Sjoerg
9467330f729Sjoerg} // Defs = [SR]
9477330f729Sjoerg
9487330f729Sjoergdef TST8r   : InstAlias<"tst.b\t$dst",  (CMP8rc    GR8:$dst,     0)>;
9497330f729Sjoergdef TST16r  : InstAlias<"tst\t$dst",    (CMP16rc   GR16:$dst,    0)>;
9507330f729Sjoergdef TST8m   : InstAlias<"tst.b\t$dst",  (CMP8mc    memdst:$dst,  0)>;
9517330f729Sjoergdef TST16m  : InstAlias<"tst\t$dst",    (CMP16mc   memdst:$dst,  0)>;
9527330f729Sjoerg
9537330f729Sjoerg//===----------------------------------------------------------------------===//
9547330f729Sjoerg// Non-Instruction Patterns
9557330f729Sjoerg
9567330f729Sjoerg// extload
9577330f729Sjoergdef : Pat<(extloadi16i8 addr:$src), (MOVZX16rm8 addr:$src)>;
9587330f729Sjoerg
9597330f729Sjoerg// anyext
9607330f729Sjoergdef : Pat<(i16 (anyext GR8:$src)),
9617330f729Sjoerg          (SUBREG_TO_REG (i16 0), GR8:$src, subreg_8bit)>;
9627330f729Sjoerg
9637330f729Sjoerg// truncs
9647330f729Sjoergdef : Pat<(i8 (trunc GR16:$src)),
9657330f729Sjoerg          (EXTRACT_SUBREG GR16:$src, subreg_8bit)>;
9667330f729Sjoerg
9677330f729Sjoerg// GlobalAddress, ExternalSymbol
9687330f729Sjoergdef : Pat<(i16 (MSP430Wrapper tglobaladdr:$dst)), (MOV16ri tglobaladdr:$dst)>;
9697330f729Sjoergdef : Pat<(i16 (MSP430Wrapper texternalsym:$dst)), (MOV16ri texternalsym:$dst)>;
9707330f729Sjoergdef : Pat<(i16 (MSP430Wrapper tblockaddress:$dst)), (MOV16ri tblockaddress:$dst)>;
9717330f729Sjoerg
9727330f729Sjoergdef : Pat<(add GR16:$src, (MSP430Wrapper tglobaladdr :$src2)),
9737330f729Sjoerg          (ADD16ri GR16:$src, tglobaladdr:$src2)>;
9747330f729Sjoergdef : Pat<(add GR16:$src, (MSP430Wrapper texternalsym:$src2)),
9757330f729Sjoerg          (ADD16ri GR16:$src, texternalsym:$src2)>;
9767330f729Sjoergdef : Pat<(add GR16:$src, (MSP430Wrapper tblockaddress:$src2)),
9777330f729Sjoerg          (ADD16ri GR16:$src, tblockaddress:$src2)>;
9787330f729Sjoerg
9797330f729Sjoergdef : Pat<(store (i16 (MSP430Wrapper tglobaladdr:$src)), addr:$dst),
9807330f729Sjoerg          (MOV16mi addr:$dst, tglobaladdr:$src)>;
9817330f729Sjoergdef : Pat<(store (i16 (MSP430Wrapper texternalsym:$src)), addr:$dst),
9827330f729Sjoerg          (MOV16mi addr:$dst, texternalsym:$src)>;
9837330f729Sjoergdef : Pat<(store (i16 (MSP430Wrapper tblockaddress:$src)), addr:$dst),
9847330f729Sjoerg          (MOV16mi addr:$dst, tblockaddress:$src)>;
9857330f729Sjoerg
9867330f729Sjoerg// calls
9877330f729Sjoergdef : Pat<(MSP430call (i16 tglobaladdr:$dst)),
9887330f729Sjoerg          (CALLi tglobaladdr:$dst)>;
9897330f729Sjoergdef : Pat<(MSP430call (i16 texternalsym:$dst)),
9907330f729Sjoerg          (CALLi texternalsym:$dst)>;
9917330f729Sjoerg
9927330f729Sjoerg// add and sub always produce carry
9937330f729Sjoergdef : Pat<(addc GR16:$src, GR16:$src2),
9947330f729Sjoerg          (ADD16rr GR16:$src, GR16:$src2)>;
9957330f729Sjoergdef : Pat<(addc GR16:$src, (load addr:$src2)),
9967330f729Sjoerg          (ADD16rm GR16:$src, addr:$src2)>;
9977330f729Sjoergdef : Pat<(addc GR16:$src, imm:$src2),
9987330f729Sjoerg          (ADD16ri GR16:$src, imm:$src2)>;
9997330f729Sjoergdef : Pat<(store (addc (load addr:$dst), GR16:$src), addr:$dst),
10007330f729Sjoerg          (ADD16mr addr:$dst, GR16:$src)>;
10017330f729Sjoergdef : Pat<(store (addc (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
10027330f729Sjoerg          (ADD16mm addr:$dst, addr:$src)>;
10037330f729Sjoerg
10047330f729Sjoergdef : Pat<(addc GR8:$src, GR8:$src2),
10057330f729Sjoerg          (ADD8rr GR8:$src, GR8:$src2)>;
10067330f729Sjoergdef : Pat<(addc GR8:$src, (load addr:$src2)),
10077330f729Sjoerg          (ADD8rm GR8:$src, addr:$src2)>;
10087330f729Sjoergdef : Pat<(addc GR8:$src, imm:$src2),
10097330f729Sjoerg          (ADD8ri GR8:$src, imm:$src2)>;
10107330f729Sjoergdef : Pat<(store (addc (load addr:$dst), GR8:$src), addr:$dst),
10117330f729Sjoerg          (ADD8mr addr:$dst, GR8:$src)>;
10127330f729Sjoergdef : Pat<(store (addc (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
10137330f729Sjoerg          (ADD8mm addr:$dst, addr:$src)>;
10147330f729Sjoerg
10157330f729Sjoergdef : Pat<(subc GR16:$src, GR16:$src2),
10167330f729Sjoerg          (SUB16rr GR16:$src, GR16:$src2)>;
10177330f729Sjoergdef : Pat<(subc GR16:$src, (load addr:$src2)),
10187330f729Sjoerg          (SUB16rm GR16:$src, addr:$src2)>;
10197330f729Sjoergdef : Pat<(subc GR16:$src, imm:$src2),
10207330f729Sjoerg          (SUB16ri GR16:$src, imm:$src2)>;
10217330f729Sjoergdef : Pat<(store (subc (load addr:$dst), GR16:$src), addr:$dst),
10227330f729Sjoerg          (SUB16mr addr:$dst, GR16:$src)>;
10237330f729Sjoergdef : Pat<(store (subc (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
10247330f729Sjoerg          (SUB16mm addr:$dst, addr:$src)>;
10257330f729Sjoerg
10267330f729Sjoergdef : Pat<(subc GR8:$src, GR8:$src2),
10277330f729Sjoerg          (SUB8rr GR8:$src, GR8:$src2)>;
10287330f729Sjoergdef : Pat<(subc GR8:$src, (load addr:$src2)),
10297330f729Sjoerg          (SUB8rm GR8:$src, addr:$src2)>;
10307330f729Sjoergdef : Pat<(subc GR8:$src, imm:$src2),
10317330f729Sjoerg          (SUB8ri GR8:$src, imm:$src2)>;
10327330f729Sjoergdef : Pat<(store (subc (load addr:$dst), GR8:$src), addr:$dst),
10337330f729Sjoerg          (SUB8mr addr:$dst, GR8:$src)>;
10347330f729Sjoergdef : Pat<(store (subc (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
10357330f729Sjoerg          (SUB8mm addr:$dst, addr:$src)>;
10367330f729Sjoerg
10377330f729Sjoerg// peephole patterns
10387330f729Sjoergdef : Pat<(and GR16:$src, 255), (ZEXT16r GR16:$src)>;
10397330f729Sjoergdef : Pat<(MSP430cmp (trunc (and_su GR16:$src, GR16:$src2)), 0),
10407330f729Sjoerg          (BIT8rr (EXTRACT_SUBREG GR16:$src, subreg_8bit),
10417330f729Sjoerg                  (EXTRACT_SUBREG GR16:$src2, subreg_8bit))>;
1042