Home | History | Annotate | Download | only in ARM
      1 //===-- ARMInstrThumb2.td - Thumb2 support for ARM ---------*- tablegen -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file describes the Thumb2 instruction set.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 // IT block predicate field
     15 def it_pred_asmoperand : AsmOperandClass {
     16   let Name = "ITCondCode";
     17   let ParserMethod = "parseITCondCode";
     18 }
     19 def it_pred : Operand<i32> {
     20   let PrintMethod = "printMandatoryPredicateOperand";
     21   let ParserMatchClass = it_pred_asmoperand;
     22 }
     23 
     24 // IT block condition mask
     25 def it_mask_asmoperand : AsmOperandClass { let Name = "ITMask"; }
     26 def it_mask : Operand<i32> {
     27   let PrintMethod = "printThumbITMask";
     28   let ParserMatchClass = it_mask_asmoperand;
     29 }
     30 
     31 // t2_shift_imm: An integer that encodes a shift amount and the type of shift
     32 // (asr or lsl). The 6-bit immediate encodes as:
     33 //    {5}     0 ==> lsl
     34 //            1     asr
     35 //    {4-0}   imm5 shift amount.
     36 //            asr #32 not allowed
     37 def t2_shift_imm : Operand<i32> {
     38   let PrintMethod = "printShiftImmOperand";
     39   let ParserMatchClass = ShifterImmAsmOperand;
     40   let DecoderMethod = "DecodeT2ShifterImmOperand";
     41 }
     42 
     43 // Shifted operands. No register controlled shifts for Thumb2.
     44 // Note: We do not support rrx shifted operands yet.
     45 def t2_so_reg : Operand<i32>,    // reg imm
     46                 ComplexPattern<i32, 2, "SelectShiftImmShifterOperand",
     47                                [shl,srl,sra,rotr]> {
     48   let EncoderMethod = "getT2SORegOpValue";
     49   let PrintMethod = "printT2SOOperand";
     50   let DecoderMethod = "DecodeSORegImmOperand";
     51   let ParserMatchClass = ShiftedImmAsmOperand;
     52   let MIOperandInfo = (ops rGPR, i32imm);
     53 }
     54 
     55 // t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
     56 def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
     57   return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), SDLoc(N),
     58                                    MVT::i32);
     59 }]>;
     60 
     61 // t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
     62 def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
     63   return CurDAG->getTargetConstant(-((int)N->getZExtValue()), SDLoc(N),
     64                                    MVT::i32);
     65 }]>;
     66 
     67 // so_imm_notSext_XFORM - Return a so_imm value packed into the format
     68 // described for so_imm_notSext def below, with sign extension from 16
     69 // bits.
     70 def t2_so_imm_notSext16_XFORM : SDNodeXForm<imm, [{
     71   APInt apIntN = N->getAPIntValue();
     72   unsigned N16bitSignExt = apIntN.trunc(16).sext(32).getZExtValue();
     73   return CurDAG->getTargetConstant(~N16bitSignExt, SDLoc(N), MVT::i32);
     74 }]>;
     75 
     76 // t2_so_imm - Match a 32-bit immediate operand, which is an
     77 // 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
     78 // immediate splatted into multiple bytes of the word.
     79 def t2_so_imm_asmoperand : ImmAsmOperand { let Name = "T2SOImm"; }
     80 def t2_so_imm : Operand<i32>, ImmLeaf<i32, [{
     81     return ARM_AM::getT2SOImmVal(Imm) != -1;
     82   }]> {
     83   let ParserMatchClass = t2_so_imm_asmoperand;
     84   let EncoderMethod = "getT2SOImmOpValue";
     85   let DecoderMethod = "DecodeT2SOImm";
     86 }
     87 
     88 // t2_so_imm_not - Match an immediate that is a complement
     89 // of a t2_so_imm.
     90 // Note: this pattern doesn't require an encoder method and such, as it's
     91 // only used on aliases (Pat<> and InstAlias<>). The actual encoding
     92 // is handled by the destination instructions, which use t2_so_imm.
     93 def t2_so_imm_not_asmoperand : AsmOperandClass { let Name = "T2SOImmNot"; }
     94 def t2_so_imm_not : Operand<i32>, PatLeaf<(imm), [{
     95   return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
     96 }], t2_so_imm_not_XFORM> {
     97   let ParserMatchClass = t2_so_imm_not_asmoperand;
     98 }
     99 
    100 // t2_so_imm_notSext - match an immediate that is a complement of a t2_so_imm
    101 // if the upper 16 bits are zero.
    102 def t2_so_imm_notSext : Operand<i32>, PatLeaf<(imm), [{
    103     APInt apIntN = N->getAPIntValue();
    104     if (!apIntN.isIntN(16)) return false;
    105     unsigned N16bitSignExt = apIntN.trunc(16).sext(32).getZExtValue();
    106     return ARM_AM::getT2SOImmVal(~N16bitSignExt) != -1;
    107   }], t2_so_imm_notSext16_XFORM> {
    108   let ParserMatchClass = t2_so_imm_not_asmoperand;
    109 }
    110 
    111 // t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
    112 def t2_so_imm_neg_asmoperand : AsmOperandClass { let Name = "T2SOImmNeg"; }
    113 def t2_so_imm_neg : Operand<i32>, PatLeaf<(imm), [{
    114   int64_t Value = -(int)N->getZExtValue();
    115   return Value && ARM_AM::getT2SOImmVal(Value) != -1;
    116 }], t2_so_imm_neg_XFORM> {
    117   let ParserMatchClass = t2_so_imm_neg_asmoperand;
    118 }
    119 
    120 /// imm0_4095 predicate - True if the 32-bit immediate is in the range [0.4095].
    121 def imm0_4095_asmoperand: ImmAsmOperand { let Name = "Imm0_4095"; }
    122 def imm0_4095 : Operand<i32>, ImmLeaf<i32, [{
    123   return Imm >= 0 && Imm < 4096;
    124 }]> {
    125   let ParserMatchClass = imm0_4095_asmoperand;
    126 }
    127 
    128 def imm0_4095_neg_asmoperand: AsmOperandClass { let Name = "Imm0_4095Neg"; }
    129 def imm0_4095_neg : Operand<i32>, PatLeaf<(i32 imm), [{
    130  return (uint32_t)(-N->getZExtValue()) < 4096;
    131 }], imm_neg_XFORM> {
    132   let ParserMatchClass = imm0_4095_neg_asmoperand;
    133 }
    134 
    135 def imm1_255_neg : PatLeaf<(i32 imm), [{
    136   uint32_t Val = -N->getZExtValue();
    137   return (Val > 0 && Val < 255);
    138 }], imm_neg_XFORM>;
    139 
    140 def imm0_255_not : PatLeaf<(i32 imm), [{
    141   return (uint32_t)(~N->getZExtValue()) < 255;
    142 }], imm_comp_XFORM>;
    143 
    144 def lo5AllOne : PatLeaf<(i32 imm), [{
    145   // Returns true if all low 5-bits are 1.
    146   return (((uint32_t)N->getZExtValue()) & 0x1FUL) == 0x1FUL;
    147 }]>;
    148 
    149 // Define Thumb2 specific addressing modes.
    150 
    151 // t2addrmode_imm12  := reg + imm12
    152 def t2addrmode_imm12_asmoperand : AsmOperandClass {let Name="MemUImm12Offset";}
    153 def t2addrmode_imm12 : MemOperand,
    154                        ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
    155   let PrintMethod = "printAddrModeImm12Operand<false>";
    156   let EncoderMethod = "getAddrModeImm12OpValue";
    157   let DecoderMethod = "DecodeT2AddrModeImm12";
    158   let ParserMatchClass = t2addrmode_imm12_asmoperand;
    159   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
    160 }
    161 
    162 // t2ldrlabel  := imm12
    163 def t2ldrlabel : Operand<i32> {
    164   let EncoderMethod = "getAddrModeImm12OpValue";
    165   let PrintMethod = "printThumbLdrLabelOperand";
    166 }
    167 
    168 def t2ldr_pcrel_imm12_asmoperand : AsmOperandClass {let Name = "MemPCRelImm12";}
    169 def t2ldr_pcrel_imm12 : Operand<i32> {
    170   let ParserMatchClass = t2ldr_pcrel_imm12_asmoperand;
    171   // used for assembler pseudo instruction and maps to t2ldrlabel, so
    172   // doesn't need encoder or print methods of its own.
    173 }
    174 
    175 // ADR instruction labels.
    176 def t2adrlabel : Operand<i32> {
    177   let EncoderMethod = "getT2AdrLabelOpValue";
    178   let PrintMethod = "printAdrLabelOperand<0>";
    179 }
    180 
    181 // t2addrmode_posimm8  := reg + imm8
    182 def MemPosImm8OffsetAsmOperand : AsmOperandClass {let Name="MemPosImm8Offset";}
    183 def t2addrmode_posimm8 : MemOperand {
    184   let PrintMethod = "printT2AddrModeImm8Operand<false>";
    185   let EncoderMethod = "getT2AddrModeImm8OpValue";
    186   let DecoderMethod = "DecodeT2AddrModeImm8";
    187   let ParserMatchClass = MemPosImm8OffsetAsmOperand;
    188   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
    189 }
    190 
    191 // t2addrmode_negimm8  := reg - imm8
    192 def MemNegImm8OffsetAsmOperand : AsmOperandClass {let Name="MemNegImm8Offset";}
    193 def t2addrmode_negimm8 : MemOperand,
    194                       ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
    195   let PrintMethod = "printT2AddrModeImm8Operand<false>";
    196   let EncoderMethod = "getT2AddrModeImm8OpValue";
    197   let DecoderMethod = "DecodeT2AddrModeImm8";
    198   let ParserMatchClass = MemNegImm8OffsetAsmOperand;
    199   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
    200 }
    201 
    202 // t2addrmode_imm8  := reg +/- imm8
    203 def MemImm8OffsetAsmOperand : AsmOperandClass { let Name = "MemImm8Offset"; }
    204 class T2AddrMode_Imm8 : MemOperand,
    205                         ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
    206   let EncoderMethod = "getT2AddrModeImm8OpValue";
    207   let DecoderMethod = "DecodeT2AddrModeImm8";
    208   let ParserMatchClass = MemImm8OffsetAsmOperand;
    209   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
    210 }
    211 
    212 def t2addrmode_imm8 : T2AddrMode_Imm8 {
    213   let PrintMethod = "printT2AddrModeImm8Operand<false>";
    214 }
    215 
    216 def t2addrmode_imm8_pre : T2AddrMode_Imm8 {
    217   let PrintMethod = "printT2AddrModeImm8Operand<true>";
    218 }
    219 
    220 def t2am_imm8_offset : MemOperand,
    221                        ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset",
    222                                       [], [SDNPWantRoot]> {
    223   let PrintMethod = "printT2AddrModeImm8OffsetOperand";
    224   let EncoderMethod = "getT2AddrModeImm8OffsetOpValue";
    225   let DecoderMethod = "DecodeT2Imm8";
    226 }
    227 
    228 // t2addrmode_imm8s4  := reg +/- (imm8 << 2)
    229 def MemImm8s4OffsetAsmOperand : AsmOperandClass {let Name = "MemImm8s4Offset";}
    230 class T2AddrMode_Imm8s4 : MemOperand {
    231   let EncoderMethod = "getT2AddrModeImm8s4OpValue";
    232   let DecoderMethod = "DecodeT2AddrModeImm8s4";
    233   let ParserMatchClass = MemImm8s4OffsetAsmOperand;
    234   let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
    235 }
    236 
    237 def t2addrmode_imm8s4 : T2AddrMode_Imm8s4 {
    238   let PrintMethod = "printT2AddrModeImm8s4Operand<false>";
    239 }
    240 
    241 def t2addrmode_imm8s4_pre : T2AddrMode_Imm8s4 {
    242   let PrintMethod = "printT2AddrModeImm8s4Operand<true>";
    243 }
    244 
    245 def t2am_imm8s4_offset_asmoperand : AsmOperandClass { let Name = "Imm8s4"; }
    246 def t2am_imm8s4_offset : MemOperand {
    247   let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
    248   let EncoderMethod = "getT2Imm8s4OpValue";
    249   let DecoderMethod = "DecodeT2Imm8S4";
    250 }
    251 
    252 // t2addrmode_imm0_1020s4  := reg + (imm8 << 2)
    253 def MemImm0_1020s4OffsetAsmOperand : AsmOperandClass {
    254   let Name = "MemImm0_1020s4Offset";
    255 }
    256 def t2addrmode_imm0_1020s4 : MemOperand,
    257                          ComplexPattern<i32, 2, "SelectT2AddrModeExclusive"> {
    258   let PrintMethod = "printT2AddrModeImm0_1020s4Operand";
    259   let EncoderMethod = "getT2AddrModeImm0_1020s4OpValue";
    260   let DecoderMethod = "DecodeT2AddrModeImm0_1020s4";
    261   let ParserMatchClass = MemImm0_1020s4OffsetAsmOperand;
    262   let MIOperandInfo = (ops GPRnopc:$base, i32imm:$offsimm);
    263 }
    264 
    265 // t2addrmode_so_reg  := reg + (reg << imm2)
    266 def t2addrmode_so_reg_asmoperand : AsmOperandClass {let Name="T2MemRegOffset";}
    267 def t2addrmode_so_reg : MemOperand,
    268                         ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
    269   let PrintMethod = "printT2AddrModeSoRegOperand";
    270   let EncoderMethod = "getT2AddrModeSORegOpValue";
    271   let DecoderMethod = "DecodeT2AddrModeSOReg";
    272   let ParserMatchClass = t2addrmode_so_reg_asmoperand;
    273   let MIOperandInfo = (ops GPR:$base, rGPR:$offsreg, i32imm:$offsimm);
    274 }
    275 
    276 // Addresses for the TBB/TBH instructions.
    277 def addrmode_tbb_asmoperand : AsmOperandClass { let Name = "MemTBB"; }
    278 def addrmode_tbb : MemOperand {
    279   let PrintMethod = "printAddrModeTBB";
    280   let ParserMatchClass = addrmode_tbb_asmoperand;
    281   let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
    282 }
    283 def addrmode_tbh_asmoperand : AsmOperandClass { let Name = "MemTBH"; }
    284 def addrmode_tbh : MemOperand {
    285   let PrintMethod = "printAddrModeTBH";
    286   let ParserMatchClass = addrmode_tbh_asmoperand;
    287   let MIOperandInfo = (ops GPR:$Rn, rGPR:$Rm);
    288 }
    289 
    290 //===----------------------------------------------------------------------===//
    291 // Multiclass helpers...
    292 //
    293 
    294 
    295 class T2OneRegImm<dag oops, dag iops, InstrItinClass itin,
    296            string opc, string asm, list<dag> pattern>
    297   : T2I<oops, iops, itin, opc, asm, pattern> {
    298   bits<4> Rd;
    299   bits<12> imm;
    300 
    301   let Inst{11-8}  = Rd;
    302   let Inst{26}    = imm{11};
    303   let Inst{14-12} = imm{10-8};
    304   let Inst{7-0}   = imm{7-0};
    305 }
    306 
    307 
    308 class T2sOneRegImm<dag oops, dag iops, InstrItinClass itin,
    309            string opc, string asm, list<dag> pattern>
    310   : T2sI<oops, iops, itin, opc, asm, pattern> {
    311   bits<4> Rd;
    312   bits<4> Rn;
    313   bits<12> imm;
    314 
    315   let Inst{11-8}  = Rd;
    316   let Inst{26}    = imm{11};
    317   let Inst{14-12} = imm{10-8};
    318   let Inst{7-0}   = imm{7-0};
    319 }
    320 
    321 class T2OneRegCmpImm<dag oops, dag iops, InstrItinClass itin,
    322            string opc, string asm, list<dag> pattern>
    323   : T2I<oops, iops, itin, opc, asm, pattern> {
    324   bits<4> Rn;
    325   bits<12> imm;
    326 
    327   let Inst{19-16}  = Rn;
    328   let Inst{26}    = imm{11};
    329   let Inst{14-12} = imm{10-8};
    330   let Inst{7-0}   = imm{7-0};
    331 }
    332 
    333 
    334 class T2OneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
    335            string opc, string asm, list<dag> pattern>
    336   : T2I<oops, iops, itin, opc, asm, pattern> {
    337   bits<4> Rd;
    338   bits<12> ShiftedRm;
    339 
    340   let Inst{11-8}  = Rd;
    341   let Inst{3-0}   = ShiftedRm{3-0};
    342   let Inst{5-4}   = ShiftedRm{6-5};
    343   let Inst{14-12} = ShiftedRm{11-9};
    344   let Inst{7-6}   = ShiftedRm{8-7};
    345 }
    346 
    347 class T2sOneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
    348            string opc, string asm, list<dag> pattern>
    349   : T2sI<oops, iops, itin, opc, asm, pattern> {
    350   bits<4> Rd;
    351   bits<12> ShiftedRm;
    352 
    353   let Inst{11-8}  = Rd;
    354   let Inst{3-0}   = ShiftedRm{3-0};
    355   let Inst{5-4}   = ShiftedRm{6-5};
    356   let Inst{14-12} = ShiftedRm{11-9};
    357   let Inst{7-6}   = ShiftedRm{8-7};
    358 }
    359 
    360 class T2OneRegCmpShiftedReg<dag oops, dag iops, InstrItinClass itin,
    361            string opc, string asm, list<dag> pattern>
    362   : T2I<oops, iops, itin, opc, asm, pattern> {
    363   bits<4> Rn;
    364   bits<12> ShiftedRm;
    365 
    366   let Inst{19-16} = Rn;
    367   let Inst{3-0}   = ShiftedRm{3-0};
    368   let Inst{5-4}   = ShiftedRm{6-5};
    369   let Inst{14-12} = ShiftedRm{11-9};
    370   let Inst{7-6}   = ShiftedRm{8-7};
    371 }
    372 
    373 class T2TwoReg<dag oops, dag iops, InstrItinClass itin,
    374            string opc, string asm, list<dag> pattern>
    375   : T2I<oops, iops, itin, opc, asm, pattern> {
    376   bits<4> Rd;
    377   bits<4> Rm;
    378 
    379   let Inst{11-8}  = Rd;
    380   let Inst{3-0}   = Rm;
    381 }
    382 
    383 class T2sTwoReg<dag oops, dag iops, InstrItinClass itin,
    384            string opc, string asm, list<dag> pattern>
    385   : T2sI<oops, iops, itin, opc, asm, pattern> {
    386   bits<4> Rd;
    387   bits<4> Rm;
    388 
    389   let Inst{11-8}  = Rd;
    390   let Inst{3-0}   = Rm;
    391 }
    392 
    393 class T2TwoRegCmp<dag oops, dag iops, InstrItinClass itin,
    394            string opc, string asm, list<dag> pattern>
    395   : T2I<oops, iops, itin, opc, asm, pattern> {
    396   bits<4> Rn;
    397   bits<4> Rm;
    398 
    399   let Inst{19-16} = Rn;
    400   let Inst{3-0}   = Rm;
    401 }
    402 
    403 
    404 class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin,
    405            string opc, string asm, list<dag> pattern>
    406   : T2I<oops, iops, itin, opc, asm, pattern> {
    407   bits<4> Rd;
    408   bits<4> Rn;
    409   bits<12> imm;
    410 
    411   let Inst{11-8}  = Rd;
    412   let Inst{19-16} = Rn;
    413   let Inst{26}    = imm{11};
    414   let Inst{14-12} = imm{10-8};
    415   let Inst{7-0}   = imm{7-0};
    416 }
    417 
    418 class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin,
    419            string opc, string asm, list<dag> pattern>
    420   : T2sI<oops, iops, itin, opc, asm, pattern> {
    421   bits<4> Rd;
    422   bits<4> Rn;
    423   bits<12> imm;
    424 
    425   let Inst{11-8}  = Rd;
    426   let Inst{19-16} = Rn;
    427   let Inst{26}    = imm{11};
    428   let Inst{14-12} = imm{10-8};
    429   let Inst{7-0}   = imm{7-0};
    430 }
    431 
    432 class T2TwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
    433            string opc, string asm, list<dag> pattern>
    434   : T2I<oops, iops, itin, opc, asm, pattern> {
    435   bits<4> Rd;
    436   bits<4> Rm;
    437   bits<5> imm;
    438 
    439   let Inst{11-8}  = Rd;
    440   let Inst{3-0}   = Rm;
    441   let Inst{14-12} = imm{4-2};
    442   let Inst{7-6}   = imm{1-0};
    443 }
    444 
    445 class T2sTwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
    446            string opc, string asm, list<dag> pattern>
    447   : T2sI<oops, iops, itin, opc, asm, pattern> {
    448   bits<4> Rd;
    449   bits<4> Rm;
    450   bits<5> imm;
    451 
    452   let Inst{11-8}  = Rd;
    453   let Inst{3-0}   = Rm;
    454   let Inst{14-12} = imm{4-2};
    455   let Inst{7-6}   = imm{1-0};
    456 }
    457 
    458 class T2ThreeReg<dag oops, dag iops, InstrItinClass itin,
    459            string opc, string asm, list<dag> pattern>
    460   : T2I<oops, iops, itin, opc, asm, pattern> {
    461   bits<4> Rd;
    462   bits<4> Rn;
    463   bits<4> Rm;
    464 
    465   let Inst{11-8}  = Rd;
    466   let Inst{19-16} = Rn;
    467   let Inst{3-0}   = Rm;
    468 }
    469 
    470 class T2ThreeRegNoP<dag oops, dag iops, InstrItinClass itin,
    471            string asm, list<dag> pattern>
    472   : T2XI<oops, iops, itin, asm, pattern> {
    473   bits<4> Rd;
    474   bits<4> Rn;
    475   bits<4> Rm;
    476 
    477   let Inst{11-8}  = Rd;
    478   let Inst{19-16} = Rn;
    479   let Inst{3-0}   = Rm;
    480 }
    481 
    482 class T2sThreeReg<dag oops, dag iops, InstrItinClass itin,
    483            string opc, string asm, list<dag> pattern>
    484   : T2sI<oops, iops, itin, opc, asm, pattern> {
    485   bits<4> Rd;
    486   bits<4> Rn;
    487   bits<4> Rm;
    488 
    489   let Inst{11-8}  = Rd;
    490   let Inst{19-16} = Rn;
    491   let Inst{3-0}   = Rm;
    492 }
    493 
    494 class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
    495            string opc, string asm, list<dag> pattern>
    496   : T2I<oops, iops, itin, opc, asm, pattern> {
    497   bits<4> Rd;
    498   bits<4> Rn;
    499   bits<12> ShiftedRm;
    500 
    501   let Inst{11-8}  = Rd;
    502   let Inst{19-16} = Rn;
    503   let Inst{3-0}   = ShiftedRm{3-0};
    504   let Inst{5-4}   = ShiftedRm{6-5};
    505   let Inst{14-12} = ShiftedRm{11-9};
    506   let Inst{7-6}   = ShiftedRm{8-7};
    507 }
    508 
    509 class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
    510            string opc, string asm, list<dag> pattern>
    511   : T2sI<oops, iops, itin, opc, asm, pattern> {
    512   bits<4> Rd;
    513   bits<4> Rn;
    514   bits<12> ShiftedRm;
    515 
    516   let Inst{11-8}  = Rd;
    517   let Inst{19-16} = Rn;
    518   let Inst{3-0}   = ShiftedRm{3-0};
    519   let Inst{5-4}   = ShiftedRm{6-5};
    520   let Inst{14-12} = ShiftedRm{11-9};
    521   let Inst{7-6}   = ShiftedRm{8-7};
    522 }
    523 
    524 class T2FourReg<dag oops, dag iops, InstrItinClass itin,
    525            string opc, string asm, list<dag> pattern>
    526   : T2I<oops, iops, itin, opc, asm, pattern> {
    527   bits<4> Rd;
    528   bits<4> Rn;
    529   bits<4> Rm;
    530   bits<4> Ra;
    531 
    532   let Inst{19-16} = Rn;
    533   let Inst{15-12} = Ra;
    534   let Inst{11-8}  = Rd;
    535   let Inst{3-0}   = Rm;
    536 }
    537 
    538 class T2MulLong<bits<3> opc22_20, bits<4> opc7_4,
    539                 dag oops, dag iops, InstrItinClass itin,
    540                 string opc, string asm, list<dag> pattern>
    541   : T2I<oops, iops, itin, opc, asm, pattern> {
    542   bits<4> RdLo;
    543   bits<4> RdHi;
    544   bits<4> Rn;
    545   bits<4> Rm;
    546 
    547   let Inst{31-23} = 0b111110111;
    548   let Inst{22-20} = opc22_20;
    549   let Inst{19-16} = Rn;
    550   let Inst{15-12} = RdLo;
    551   let Inst{11-8}  = RdHi;
    552   let Inst{7-4}   = opc7_4;
    553   let Inst{3-0}   = Rm;
    554 }
    555 class T2MlaLong<bits<3> opc22_20, bits<4> opc7_4,
    556                 dag oops, dag iops, InstrItinClass itin,
    557                 string opc, string asm, list<dag> pattern>
    558   : T2I<oops, iops, itin, opc, asm, pattern> {
    559   bits<4> RdLo;
    560   bits<4> RdHi;
    561   bits<4> Rn;
    562   bits<4> Rm;
    563 
    564   let Inst{31-23} = 0b111110111;
    565   let Inst{22-20} = opc22_20;
    566   let Inst{19-16} = Rn;
    567   let Inst{15-12} = RdLo;
    568   let Inst{11-8}  = RdHi;
    569   let Inst{7-4}   = opc7_4;
    570   let Inst{3-0}   = Rm;
    571 }
    572 
    573 
    574 /// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
    575 /// binary operation that produces a value. These are predicable and can be
    576 /// changed to modify CPSR.
    577 multiclass T2I_bin_irs<bits<4> opcod, string opc,
    578                      InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
    579                        PatFrag opnode, bit Commutable = 0,
    580                        string wide = ""> {
    581    // shifted imm
    582    def ri : T2sTwoRegImm<
    583                 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii,
    584                  opc, "\t$Rd, $Rn, $imm",
    585                  [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>,
    586                  Sched<[WriteALU, ReadALU]> {
    587      let Inst{31-27} = 0b11110;
    588      let Inst{25} = 0;
    589      let Inst{24-21} = opcod;
    590      let Inst{15} = 0;
    591    }
    592    // register
    593    def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir,
    594                  opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"),
    595                  [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
    596                  Sched<[WriteALU, ReadALU, ReadALU]> {
    597      let isCommutable = Commutable;
    598      let Inst{31-27} = 0b11101;
    599      let Inst{26-25} = 0b01;
    600      let Inst{24-21} = opcod;
    601      let Inst{14-12} = 0b000; // imm3
    602      let Inst{7-6} = 0b00; // imm2
    603      let Inst{5-4} = 0b00; // type
    604    }
    605    // shifted register
    606    def rs : T2sTwoRegShiftedReg<
    607                  (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
    608                  opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"),
    609                  [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>,
    610                  Sched<[WriteALUsi, ReadALU]>  {
    611      let Inst{31-27} = 0b11101;
    612      let Inst{26-25} = 0b01;
    613      let Inst{24-21} = opcod;
    614    }
    615   // Assembly aliases for optional destination operand when it's the same
    616   // as the source operand.
    617   def : t2InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
    618      (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn,
    619                                                     t2_so_imm:$imm, pred:$p,
    620                                                     cc_out:$s)>;
    621   def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $Rm"),
    622      (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn,
    623                                                     rGPR:$Rm, pred:$p,
    624                                                     cc_out:$s)>;
    625   def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $shift"),
    626      (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn,
    627                                                     t2_so_reg:$shift, pred:$p,
    628                                                     cc_out:$s)>;
    629 }
    630 
    631 /// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
    632 //  the ".w" suffix to indicate that they are wide.
    633 multiclass T2I_bin_w_irs<bits<4> opcod, string opc,
    634                      InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
    635                          PatFrag opnode, bit Commutable = 0> :
    636     T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, Commutable, ".w"> {
    637   // Assembler aliases w/ the ".w" suffix.
    638   def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rd, $Rn, $imm"),
    639      (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p,
    640                                     cc_out:$s)>;
    641   // Assembler aliases w/o the ".w" suffix.
    642   def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
    643      (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p,
    644                                     cc_out:$s)>;
    645   def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $shift"),
    646      (!cast<Instruction>(NAME#"rs") rGPR:$Rd, rGPR:$Rn, t2_so_reg:$shift,
    647                                     pred:$p, cc_out:$s)>;
    648 
    649   // and with the optional destination operand, too.
    650   def : t2InstAlias<!strconcat(opc, "${s}${p}.w", " $Rdn, $imm"),
    651      (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm,
    652                                     pred:$p, cc_out:$s)>;
    653   def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
    654      (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
    655                                     cc_out:$s)>;
    656   def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $shift"),
    657      (!cast<Instruction>(NAME#"rs") rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$shift,
    658                                     pred:$p, cc_out:$s)>;
    659 }
    660 
    661 /// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
    662 /// reversed.  The 'rr' form is only defined for the disassembler; for codegen
    663 /// it is equivalent to the T2I_bin_irs counterpart.
    664 multiclass T2I_rbin_irs<bits<4> opcod, string opc, PatFrag opnode> {
    665    // shifted imm
    666    def ri : T2sTwoRegImm<
    667                  (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
    668                  opc, ".w\t$Rd, $Rn, $imm",
    669                  [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]>,
    670                  Sched<[WriteALU, ReadALU]> {
    671      let Inst{31-27} = 0b11110;
    672      let Inst{25} = 0;
    673      let Inst{24-21} = opcod;
    674      let Inst{15} = 0;
    675    }
    676    // register
    677    def rr : T2sThreeReg<
    678                  (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
    679                  opc, "\t$Rd, $Rn, $Rm",
    680                  [/* For disassembly only; pattern left blank */]>,
    681                  Sched<[WriteALU, ReadALU, ReadALU]> {
    682      let Inst{31-27} = 0b11101;
    683      let Inst{26-25} = 0b01;
    684      let Inst{24-21} = opcod;
    685      let Inst{14-12} = 0b000; // imm3
    686      let Inst{7-6} = 0b00; // imm2
    687      let Inst{5-4} = 0b00; // type
    688    }
    689    // shifted register
    690    def rs : T2sTwoRegShiftedReg<
    691                  (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
    692                  IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm",
    693                  [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]>,
    694                  Sched<[WriteALUsi, ReadALU]> {
    695      let Inst{31-27} = 0b11101;
    696      let Inst{26-25} = 0b01;
    697      let Inst{24-21} = opcod;
    698    }
    699 }
    700 
    701 /// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
    702 /// instruction modifies the CPSR register.
    703 ///
    704 /// These opcodes will be converted to the real non-S opcodes by
    705 /// AdjustInstrPostInstrSelection after giving then an optional CPSR operand.
    706 let hasPostISelHook = 1, Defs = [CPSR] in {
    707 multiclass T2I_bin_s_irs<InstrItinClass iii, InstrItinClass iir,
    708                          InstrItinClass iis, PatFrag opnode,
    709                          bit Commutable = 0> {
    710    // shifted imm
    711    def ri : t2PseudoInst<(outs rGPR:$Rd),
    712                          (ins GPRnopc:$Rn, t2_so_imm:$imm, pred:$p),
    713                          4, iii,
    714                          [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
    715                                                 t2_so_imm:$imm))]>,
    716             Sched<[WriteALU, ReadALU]>;
    717    // register
    718    def rr : t2PseudoInst<(outs rGPR:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm, pred:$p),
    719                          4, iir,
    720                          [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
    721                                                 rGPR:$Rm))]>,
    722             Sched<[WriteALU, ReadALU, ReadALU]> {
    723      let isCommutable = Commutable;
    724    }
    725    // shifted register
    726    def rs : t2PseudoInst<(outs rGPR:$Rd),
    727                          (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
    728                          4, iis,
    729                          [(set rGPR:$Rd, CPSR, (opnode GPRnopc:$Rn,
    730                                                 t2_so_reg:$ShiftedRm))]>,
    731             Sched<[WriteALUsi, ReadALUsr]>;
    732 }
    733 }
    734 
    735 /// T2I_rbin_s_is -  Same as T2I_bin_s_irs, except selection DAG
    736 /// operands are reversed.
    737 let hasPostISelHook = 1, Defs = [CPSR] in {
    738 multiclass T2I_rbin_s_is<PatFrag opnode> {
    739    // shifted imm
    740    def ri : t2PseudoInst<(outs rGPR:$Rd),
    741                          (ins rGPR:$Rn, t2_so_imm:$imm, pred:$p),
    742                          4, IIC_iALUi,
    743                          [(set rGPR:$Rd, CPSR, (opnode t2_so_imm:$imm,
    744                                                 rGPR:$Rn))]>,
    745             Sched<[WriteALU, ReadALU]>;
    746    // shifted register
    747    def rs : t2PseudoInst<(outs rGPR:$Rd),
    748                          (ins rGPR:$Rn, t2_so_reg:$ShiftedRm, pred:$p),
    749                          4, IIC_iALUsi,
    750                          [(set rGPR:$Rd, CPSR, (opnode t2_so_reg:$ShiftedRm,
    751                                                 rGPR:$Rn))]>,
    752             Sched<[WriteALUsi, ReadALU]>;
    753 }
    754 }
    755 
    756 /// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
    757 /// patterns for a binary operation that produces a value.
    758 multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, PatFrag opnode,
    759                           bit Commutable = 0> {
    760    // shifted imm
    761    // The register-immediate version is re-materializable. This is useful
    762    // in particular for taking the address of a local.
    763    let isReMaterializable = 1 in {
    764    def ri : T2sTwoRegImm<
    765                (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iALUi,
    766                opc, ".w\t$Rd, $Rn, $imm",
    767                [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_imm:$imm))]>,
    768                Sched<[WriteALU, ReadALU]> {
    769      let Inst{31-27} = 0b11110;
    770      let Inst{25} = 0;
    771      let Inst{24} = 1;
    772      let Inst{23-21} = op23_21;
    773      let Inst{15} = 0;
    774    }
    775    }
    776    // 12-bit imm
    777    def ri12 : T2I<
    778                   (outs GPRnopc:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi,
    779                   !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
    780                   [(set GPRnopc:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]>,
    781                   Sched<[WriteALU, ReadALU]> {
    782      bits<4> Rd;
    783      bits<4> Rn;
    784      bits<12> imm;
    785      let Inst{31-27} = 0b11110;
    786      let Inst{26} = imm{11};
    787      let Inst{25-24} = 0b10;
    788      let Inst{23-21} = op23_21;
    789      let Inst{20} = 0; // The S bit.
    790      let Inst{19-16} = Rn;
    791      let Inst{15} = 0;
    792      let Inst{14-12} = imm{10-8};
    793      let Inst{11-8} = Rd;
    794      let Inst{7-0} = imm{7-0};
    795    }
    796    // register
    797    def rr : T2sThreeReg<(outs GPRnopc:$Rd), (ins GPRnopc:$Rn, rGPR:$Rm),
    798                  IIC_iALUr, opc, ".w\t$Rd, $Rn, $Rm",
    799                  [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, rGPR:$Rm))]>,
    800                  Sched<[WriteALU, ReadALU, ReadALU]> {
    801      let isCommutable = Commutable;
    802      let Inst{31-27} = 0b11101;
    803      let Inst{26-25} = 0b01;
    804      let Inst{24} = 1;
    805      let Inst{23-21} = op23_21;
    806      let Inst{14-12} = 0b000; // imm3
    807      let Inst{7-6} = 0b00; // imm2
    808      let Inst{5-4} = 0b00; // type
    809    }
    810    // shifted register
    811    def rs : T2sTwoRegShiftedReg<
    812                  (outs GPRnopc:$Rd), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm),
    813                  IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
    814               [(set GPRnopc:$Rd, (opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm))]>,
    815               Sched<[WriteALUsi, ReadALU]> {
    816      let Inst{31-27} = 0b11101;
    817      let Inst{26-25} = 0b01;
    818      let Inst{24} = 1;
    819      let Inst{23-21} = op23_21;
    820    }
    821 }
    822 
    823 /// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns
    824 /// for a binary operation that produces a value and use the carry
    825 /// bit. It's not predicable.
    826 let Defs = [CPSR], Uses = [CPSR] in {
    827 multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
    828                              bit Commutable = 0> {
    829    // shifted imm
    830    def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
    831                  IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
    832                [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_imm:$imm, CPSR))]>,
    833                  Requires<[IsThumb2]>, Sched<[WriteALU, ReadALU]> {
    834      let Inst{31-27} = 0b11110;
    835      let Inst{25} = 0;
    836      let Inst{24-21} = opcod;
    837      let Inst{15} = 0;
    838    }
    839    // register
    840    def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
    841                  opc, ".w\t$Rd, $Rn, $Rm",
    842                  [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, rGPR:$Rm, CPSR))]>,
    843                  Requires<[IsThumb2]>, Sched<[WriteALU, ReadALU, ReadALU]> {
    844      let isCommutable = Commutable;
    845      let Inst{31-27} = 0b11101;
    846      let Inst{26-25} = 0b01;
    847      let Inst{24-21} = opcod;
    848      let Inst{14-12} = 0b000; // imm3
    849      let Inst{7-6} = 0b00; // imm2
    850      let Inst{5-4} = 0b00; // type
    851    }
    852    // shifted register
    853    def rs : T2sTwoRegShiftedReg<
    854                  (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
    855                  IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
    856          [(set rGPR:$Rd, CPSR, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm, CPSR))]>,
    857                  Requires<[IsThumb2]>, Sched<[WriteALUsi, ReadALU]> {
    858      let Inst{31-27} = 0b11101;
    859      let Inst{26-25} = 0b01;
    860      let Inst{24-21} = opcod;
    861    }
    862 }
    863 }
    864 
    865 /// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
    866 //  rotate operation that produces a value.
    867 multiclass T2I_sh_ir<bits<2> opcod, string opc, Operand ty, PatFrag opnode> {
    868    // 5-bit imm
    869    def ri : T2sTwoRegShiftImm<
    870                  (outs rGPR:$Rd), (ins rGPR:$Rm, ty:$imm), IIC_iMOVsi,
    871                  opc, ".w\t$Rd, $Rm, $imm",
    872                  [(set rGPR:$Rd, (opnode rGPR:$Rm, (i32 ty:$imm)))]>,
    873                  Sched<[WriteALU]> {
    874      let Inst{31-27} = 0b11101;
    875      let Inst{26-21} = 0b010010;
    876      let Inst{19-16} = 0b1111; // Rn
    877      let Inst{5-4} = opcod;
    878    }
    879    // register
    880    def rr : T2sThreeReg<
    881                  (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMOVsr,
    882                  opc, ".w\t$Rd, $Rn, $Rm",
    883                  [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
    884                  Sched<[WriteALU]> {
    885      let Inst{31-27} = 0b11111;
    886      let Inst{26-23} = 0b0100;
    887      let Inst{22-21} = opcod;
    888      let Inst{15-12} = 0b1111;
    889      let Inst{7-4} = 0b0000;
    890    }
    891 
    892   // Optional destination register
    893   def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $imm"),
    894      (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p,
    895                                     cc_out:$s)>;
    896   def : t2InstAlias<!strconcat(opc, "${s}${p}", ".w $Rdn, $Rm"),
    897      (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
    898                                     cc_out:$s)>;
    899 
    900   // Assembler aliases w/o the ".w" suffix.
    901   def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $imm"),
    902      (!cast<Instruction>(NAME#"ri") rGPR:$Rd, rGPR:$Rn, ty:$imm, pred:$p,
    903                                     cc_out:$s)>;
    904   def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rd, $Rn, $Rm"),
    905      (!cast<Instruction>(NAME#"rr") rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p,
    906                                     cc_out:$s)>;
    907 
    908   // and with the optional destination operand, too.
    909   def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $imm"),
    910      (!cast<Instruction>(NAME#"ri") rGPR:$Rdn, rGPR:$Rdn, ty:$imm, pred:$p,
    911                                     cc_out:$s)>;
    912   def : t2InstAlias<!strconcat(opc, "${s}${p}", " $Rdn, $Rm"),
    913      (!cast<Instruction>(NAME#"rr") rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p,
    914                                     cc_out:$s)>;
    915 }
    916 
    917 /// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
    918 /// patterns. Similar to T2I_bin_irs except the instruction does not produce
    919 /// a explicit result, only implicitly set CPSR.
    920 multiclass T2I_cmp_irs<bits<4> opcod, string opc,
    921                      InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
    922                        PatFrag opnode> {
    923 let isCompare = 1, Defs = [CPSR] in {
    924    // shifted imm
    925    def ri : T2OneRegCmpImm<
    926                 (outs), (ins GPRnopc:$Rn, t2_so_imm:$imm), iii,
    927                 opc, ".w\t$Rn, $imm",
    928                 [(opnode GPRnopc:$Rn, t2_so_imm:$imm)]>, Sched<[WriteCMP]> {
    929      let Inst{31-27} = 0b11110;
    930      let Inst{25} = 0;
    931      let Inst{24-21} = opcod;
    932      let Inst{20} = 1; // The S bit.
    933      let Inst{15} = 0;
    934      let Inst{11-8} = 0b1111; // Rd
    935    }
    936    // register
    937    def rr : T2TwoRegCmp<
    938                 (outs), (ins GPRnopc:$Rn, rGPR:$Rm), iir,
    939                 opc, ".w\t$Rn, $Rm",
    940                 [(opnode GPRnopc:$Rn, rGPR:$Rm)]>, Sched<[WriteCMP]> {
    941      let Inst{31-27} = 0b11101;
    942      let Inst{26-25} = 0b01;
    943      let Inst{24-21} = opcod;
    944      let Inst{20} = 1; // The S bit.
    945      let Inst{14-12} = 0b000; // imm3
    946      let Inst{11-8} = 0b1111; // Rd
    947      let Inst{7-6} = 0b00; // imm2
    948      let Inst{5-4} = 0b00; // type
    949    }
    950    // shifted register
    951    def rs : T2OneRegCmpShiftedReg<
    952                 (outs), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm), iis,
    953                 opc, ".w\t$Rn, $ShiftedRm",
    954                 [(opnode GPRnopc:$Rn, t2_so_reg:$ShiftedRm)]>,
    955                 Sched<[WriteCMPsi]> {
    956      let Inst{31-27} = 0b11101;
    957      let Inst{26-25} = 0b01;
    958      let Inst{24-21} = opcod;
    959      let Inst{20} = 1; // The S bit.
    960      let Inst{11-8} = 0b1111; // Rd
    961    }
    962 }
    963 
    964   // Assembler aliases w/o the ".w" suffix.
    965   // No alias here for 'rr' version as not all instantiations of this
    966   // multiclass want one (CMP in particular, does not).
    967   def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $imm"),
    968      (!cast<Instruction>(NAME#"ri") GPRnopc:$Rn, t2_so_imm:$imm, pred:$p)>;
    969   def : t2InstAlias<!strconcat(opc, "${p}", " $Rn, $shift"),
    970      (!cast<Instruction>(NAME#"rs") GPRnopc:$Rn, t2_so_reg:$shift, pred:$p)>;
    971 }
    972 
    973 /// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
    974 multiclass T2I_ld<bit signed, bits<2> opcod, string opc,
    975                   InstrItinClass iii, InstrItinClass iis, RegisterClass target,
    976                   PatFrag opnode> {
    977   def i12 : T2Ii12<(outs target:$Rt), (ins t2addrmode_imm12:$addr), iii,
    978                    opc, ".w\t$Rt, $addr",
    979                    [(set target:$Rt, (opnode t2addrmode_imm12:$addr))]> {
    980     bits<4> Rt;
    981     bits<17> addr;
    982     let Inst{31-25} = 0b1111100;
    983     let Inst{24} = signed;
    984     let Inst{23} = 1;
    985     let Inst{22-21} = opcod;
    986     let Inst{20} = 1; // load
    987     let Inst{19-16} = addr{16-13}; // Rn
    988     let Inst{15-12} = Rt;
    989     let Inst{11-0}  = addr{11-0};  // imm
    990 
    991     let DecoderMethod = "DecodeT2LoadImm12";
    992   }
    993   def i8  : T2Ii8 <(outs target:$Rt), (ins t2addrmode_negimm8:$addr), iii,
    994                    opc, "\t$Rt, $addr",
    995                    [(set target:$Rt, (opnode t2addrmode_negimm8:$addr))]> {
    996     bits<4> Rt;
    997     bits<13> addr;
    998     let Inst{31-27} = 0b11111;
    999     let Inst{26-25} = 0b00;
   1000     let Inst{24} = signed;
   1001     let Inst{23} = 0;
   1002     let Inst{22-21} = opcod;
   1003     let Inst{20} = 1; // load
   1004     let Inst{19-16} = addr{12-9}; // Rn
   1005     let Inst{15-12} = Rt;
   1006     let Inst{11} = 1;
   1007     // Offset: index==TRUE, wback==FALSE
   1008     let Inst{10} = 1; // The P bit.
   1009     let Inst{9}     = addr{8};    // U
   1010     let Inst{8} = 0; // The W bit.
   1011     let Inst{7-0}   = addr{7-0};  // imm
   1012 
   1013     let DecoderMethod = "DecodeT2LoadImm8";
   1014   }
   1015   def s   : T2Iso <(outs target:$Rt), (ins t2addrmode_so_reg:$addr), iis,
   1016                    opc, ".w\t$Rt, $addr",
   1017                    [(set target:$Rt, (opnode t2addrmode_so_reg:$addr))]> {
   1018     let Inst{31-27} = 0b11111;
   1019     let Inst{26-25} = 0b00;
   1020     let Inst{24} = signed;
   1021     let Inst{23} = 0;
   1022     let Inst{22-21} = opcod;
   1023     let Inst{20} = 1; // load
   1024     let Inst{11-6} = 0b000000;
   1025 
   1026     bits<4> Rt;
   1027     let Inst{15-12} = Rt;
   1028 
   1029     bits<10> addr;
   1030     let Inst{19-16} = addr{9-6}; // Rn
   1031     let Inst{3-0}   = addr{5-2}; // Rm
   1032     let Inst{5-4}   = addr{1-0}; // imm
   1033 
   1034     let DecoderMethod = "DecodeT2LoadShift";
   1035   }
   1036 
   1037   // pci variant is very similar to i12, but supports negative offsets
   1038   // from the PC.
   1039   def pci : T2Ipc <(outs target:$Rt), (ins t2ldrlabel:$addr), iii,
   1040                    opc, ".w\t$Rt, $addr",
   1041                    [(set target:$Rt, (opnode (ARMWrapper tconstpool:$addr)))]> {
   1042     let isReMaterializable = 1;
   1043     let Inst{31-27} = 0b11111;
   1044     let Inst{26-25} = 0b00;
   1045     let Inst{24} = signed;
   1046     let Inst{22-21} = opcod;
   1047     let Inst{20} = 1; // load
   1048     let Inst{19-16} = 0b1111; // Rn
   1049 
   1050     bits<4> Rt;
   1051     let Inst{15-12} = Rt{3-0};
   1052 
   1053     bits<13> addr;
   1054     let Inst{23} = addr{12}; // add = (U == '1')
   1055     let Inst{11-0}  = addr{11-0};
   1056 
   1057     let DecoderMethod = "DecodeT2LoadLabel";
   1058   }
   1059 }
   1060 
   1061 /// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
   1062 multiclass T2I_st<bits<2> opcod, string opc,
   1063                   InstrItinClass iii, InstrItinClass iis, RegisterClass target,
   1064                   PatFrag opnode> {
   1065   def i12 : T2Ii12<(outs), (ins target:$Rt, t2addrmode_imm12:$addr), iii,
   1066                    opc, ".w\t$Rt, $addr",
   1067                    [(opnode target:$Rt, t2addrmode_imm12:$addr)]> {
   1068     let Inst{31-27} = 0b11111;
   1069     let Inst{26-23} = 0b0001;
   1070     let Inst{22-21} = opcod;
   1071     let Inst{20} = 0; // !load
   1072 
   1073     bits<4> Rt;
   1074     let Inst{15-12} = Rt;
   1075 
   1076     bits<17> addr;
   1077     let addr{12}    = 1;           // add = TRUE
   1078     let Inst{19-16} = addr{16-13}; // Rn
   1079     let Inst{23}    = addr{12};    // U
   1080     let Inst{11-0}  = addr{11-0};  // imm
   1081   }
   1082   def i8  : T2Ii8 <(outs), (ins target:$Rt, t2addrmode_negimm8:$addr), iii,
   1083                    opc, "\t$Rt, $addr",
   1084                    [(opnode target:$Rt, t2addrmode_negimm8:$addr)]> {
   1085     let Inst{31-27} = 0b11111;
   1086     let Inst{26-23} = 0b0000;
   1087     let Inst{22-21} = opcod;
   1088     let Inst{20} = 0; // !load
   1089     let Inst{11} = 1;
   1090     // Offset: index==TRUE, wback==FALSE
   1091     let Inst{10} = 1; // The P bit.
   1092     let Inst{8} = 0; // The W bit.
   1093 
   1094     bits<4> Rt;
   1095     let Inst{15-12} = Rt;
   1096 
   1097     bits<13> addr;
   1098     let Inst{19-16} = addr{12-9}; // Rn
   1099     let Inst{9}     = addr{8};    // U
   1100     let Inst{7-0}   = addr{7-0};  // imm
   1101   }
   1102   def s   : T2Iso <(outs), (ins target:$Rt, t2addrmode_so_reg:$addr), iis,
   1103                    opc, ".w\t$Rt, $addr",
   1104                    [(opnode target:$Rt, t2addrmode_so_reg:$addr)]> {
   1105     let Inst{31-27} = 0b11111;
   1106     let Inst{26-23} = 0b0000;
   1107     let Inst{22-21} = opcod;
   1108     let Inst{20} = 0; // !load
   1109     let Inst{11-6} = 0b000000;
   1110 
   1111     bits<4> Rt;
   1112     let Inst{15-12} = Rt;
   1113 
   1114     bits<10> addr;
   1115     let Inst{19-16}   = addr{9-6}; // Rn
   1116     let Inst{3-0} = addr{5-2}; // Rm
   1117     let Inst{5-4}   = addr{1-0}; // imm
   1118   }
   1119 }
   1120 
   1121 /// T2I_ext_rrot - A unary operation with two forms: one whose operand is a
   1122 /// register and one whose operand is a register rotated by 8/16/24.
   1123 class T2I_ext_rrot<bits<3> opcod, string opc, PatFrag opnode>
   1124   : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr,
   1125              opc, ".w\t$Rd, $Rm$rot",
   1126              [(set rGPR:$Rd, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>,
   1127              Requires<[IsThumb2]> {
   1128    let Inst{31-27} = 0b11111;
   1129    let Inst{26-23} = 0b0100;
   1130    let Inst{22-20} = opcod;
   1131    let Inst{19-16} = 0b1111; // Rn
   1132    let Inst{15-12} = 0b1111;
   1133    let Inst{7} = 1;
   1134 
   1135    bits<2> rot;
   1136    let Inst{5-4} = rot{1-0}; // rotate
   1137 }
   1138 
   1139 // UXTB16 - Requres T2ExtractPack, does not need the .w qualifier.
   1140 class T2I_ext_rrot_uxtb16<bits<3> opcod, string opc, PatFrag opnode>
   1141   : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot),
   1142              IIC_iEXTr, opc, "\t$Rd, $Rm$rot",
   1143             [(set rGPR:$Rd, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>,
   1144           Requires<[HasT2ExtractPack, IsThumb2]> {
   1145   bits<2> rot;
   1146   let Inst{31-27} = 0b11111;
   1147   let Inst{26-23} = 0b0100;
   1148   let Inst{22-20} = opcod;
   1149   let Inst{19-16} = 0b1111; // Rn
   1150   let Inst{15-12} = 0b1111;
   1151   let Inst{7} = 1;
   1152   let Inst{5-4} = rot;
   1153 }
   1154 
   1155 // SXTB16 - Requres T2ExtractPack, does not need the .w qualifier, no pattern
   1156 // supported yet.
   1157 class T2I_ext_rrot_sxtb16<bits<3> opcod, string opc>
   1158   : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr,
   1159              opc, "\t$Rd, $Rm$rot", []>,
   1160           Requires<[IsThumb2, HasT2ExtractPack]> {
   1161   bits<2> rot;
   1162   let Inst{31-27} = 0b11111;
   1163   let Inst{26-23} = 0b0100;
   1164   let Inst{22-20} = opcod;
   1165   let Inst{19-16} = 0b1111; // Rn
   1166   let Inst{15-12} = 0b1111;
   1167   let Inst{7} = 1;
   1168   let Inst{5-4} = rot;
   1169 }
   1170 
   1171 /// T2I_exta_rrot - A binary operation with two forms: one whose operand is a
   1172 /// register and one whose operand is a register rotated by 8/16/24.
   1173 class T2I_exta_rrot<bits<3> opcod, string opc, PatFrag opnode>
   1174   : T2ThreeReg<(outs rGPR:$Rd),
   1175                (ins rGPR:$Rn, rGPR:$Rm, rot_imm:$rot),
   1176                IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot",
   1177              [(set rGPR:$Rd, (opnode rGPR:$Rn, (rotr rGPR:$Rm,rot_imm:$rot)))]>,
   1178            Requires<[HasT2ExtractPack, IsThumb2]> {
   1179   bits<2> rot;
   1180   let Inst{31-27} = 0b11111;
   1181   let Inst{26-23} = 0b0100;
   1182   let Inst{22-20} = opcod;
   1183   let Inst{15-12} = 0b1111;
   1184   let Inst{7} = 1;
   1185   let Inst{5-4} = rot;
   1186 }
   1187 
   1188 class T2I_exta_rrot_np<bits<3> opcod, string opc>
   1189   : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm,rot_imm:$rot),
   1190                IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot", []>,
   1191                Requires<[HasT2ExtractPack, IsThumb2]> {
   1192   bits<2> rot;
   1193   let Inst{31-27} = 0b11111;
   1194   let Inst{26-23} = 0b0100;
   1195   let Inst{22-20} = opcod;
   1196   let Inst{15-12} = 0b1111;
   1197   let Inst{7} = 1;
   1198   let Inst{5-4} = rot;
   1199 }
   1200 
   1201 //===----------------------------------------------------------------------===//
   1202 // Instructions
   1203 //===----------------------------------------------------------------------===//
   1204 
   1205 //===----------------------------------------------------------------------===//
   1206 //  Miscellaneous Instructions.
   1207 //
   1208 
   1209 class T2PCOneRegImm<dag oops, dag iops, InstrItinClass itin,
   1210            string asm, list<dag> pattern>
   1211   : T2XI<oops, iops, itin, asm, pattern> {
   1212   bits<4> Rd;
   1213   bits<12> label;
   1214 
   1215   let Inst{11-8}  = Rd;
   1216   let Inst{26}    = label{11};
   1217   let Inst{14-12} = label{10-8};
   1218   let Inst{7-0}   = label{7-0};
   1219 }
   1220 
   1221 // LEApcrel - Load a pc-relative address into a register without offending the
   1222 // assembler.
   1223 def t2ADR : T2PCOneRegImm<(outs rGPR:$Rd),
   1224               (ins t2adrlabel:$addr, pred:$p),
   1225               IIC_iALUi, "adr{$p}.w\t$Rd, $addr", []>,
   1226               Sched<[WriteALU, ReadALU]> {
   1227   let Inst{31-27} = 0b11110;
   1228   let Inst{25-24} = 0b10;
   1229   // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
   1230   let Inst{22} = 0;
   1231   let Inst{20} = 0;
   1232   let Inst{19-16} = 0b1111; // Rn
   1233   let Inst{15} = 0;
   1234 
   1235   bits<4> Rd;
   1236   bits<13> addr;
   1237   let Inst{11-8} = Rd;
   1238   let Inst{23}    = addr{12};
   1239   let Inst{21}    = addr{12};
   1240   let Inst{26}    = addr{11};
   1241   let Inst{14-12} = addr{10-8};
   1242   let Inst{7-0}   = addr{7-0};
   1243 
   1244   let DecoderMethod = "DecodeT2Adr";
   1245 }
   1246 
   1247 let hasSideEffects = 0, isReMaterializable = 1 in
   1248 def t2LEApcrel   : t2PseudoInst<(outs rGPR:$Rd), (ins i32imm:$label, pred:$p),
   1249                                 4, IIC_iALUi, []>, Sched<[WriteALU, ReadALU]>;
   1250 let hasSideEffects = 1 in
   1251 def t2LEApcrelJT : t2PseudoInst<(outs rGPR:$Rd),
   1252                                 (ins i32imm:$label, pred:$p),
   1253                                 4, IIC_iALUi,
   1254                                 []>, Sched<[WriteALU, ReadALU]>;
   1255 
   1256 
   1257 //===----------------------------------------------------------------------===//
   1258 //  Load / store Instructions.
   1259 //
   1260 
   1261 // Load
   1262 let canFoldAsLoad = 1, isReMaterializable = 1  in
   1263 defm t2LDR   : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si, GPR,
   1264                       UnOpFrag<(load node:$Src)>>;
   1265 
   1266 // Loads with zero extension
   1267 defm t2LDRH  : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
   1268                       GPRnopc, UnOpFrag<(zextloadi16 node:$Src)>>;
   1269 defm t2LDRB  : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
   1270                       GPRnopc, UnOpFrag<(zextloadi8  node:$Src)>>;
   1271 
   1272 // Loads with sign extension
   1273 defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
   1274                       GPRnopc, UnOpFrag<(sextloadi16 node:$Src)>>;
   1275 defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
   1276                       GPRnopc, UnOpFrag<(sextloadi8  node:$Src)>>;
   1277 
   1278 let mayLoad = 1, hasSideEffects = 0, hasExtraDefRegAllocReq = 1 in {
   1279 // Load doubleword
   1280 def t2LDRDi8  : T2Ii8s4<1, 0, 1, (outs rGPR:$Rt, rGPR:$Rt2),
   1281                         (ins t2addrmode_imm8s4:$addr),
   1282                         IIC_iLoad_d_i, "ldrd", "\t$Rt, $Rt2, $addr", "", []>;
   1283 } // mayLoad = 1, hasSideEffects = 0, hasExtraDefRegAllocReq = 1
   1284 
   1285 // zextload i1 -> zextload i8
   1286 def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
   1287             (t2LDRBi12  t2addrmode_imm12:$addr)>;
   1288 def : T2Pat<(zextloadi1 t2addrmode_negimm8:$addr),
   1289             (t2LDRBi8   t2addrmode_negimm8:$addr)>;
   1290 def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
   1291             (t2LDRBs    t2addrmode_so_reg:$addr)>;
   1292 def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
   1293             (t2LDRBpci  tconstpool:$addr)>;
   1294 
   1295 // extload -> zextload
   1296 // FIXME: Reduce the number of patterns by legalizing extload to zextload
   1297 // earlier?
   1298 def : T2Pat<(extloadi1  t2addrmode_imm12:$addr),
   1299             (t2LDRBi12  t2addrmode_imm12:$addr)>;
   1300 def : T2Pat<(extloadi1  t2addrmode_negimm8:$addr),
   1301             (t2LDRBi8   t2addrmode_negimm8:$addr)>;
   1302 def : T2Pat<(extloadi1  t2addrmode_so_reg:$addr),
   1303             (t2LDRBs    t2addrmode_so_reg:$addr)>;
   1304 def : T2Pat<(extloadi1  (ARMWrapper tconstpool:$addr)),
   1305             (t2LDRBpci  tconstpool:$addr)>;
   1306 
   1307 def : T2Pat<(extloadi8  t2addrmode_imm12:$addr),
   1308             (t2LDRBi12  t2addrmode_imm12:$addr)>;
   1309 def : T2Pat<(extloadi8  t2addrmode_negimm8:$addr),
   1310             (t2LDRBi8   t2addrmode_negimm8:$addr)>;
   1311 def : T2Pat<(extloadi8  t2addrmode_so_reg:$addr),
   1312             (t2LDRBs    t2addrmode_so_reg:$addr)>;
   1313 def : T2Pat<(extloadi8  (ARMWrapper tconstpool:$addr)),
   1314             (t2LDRBpci  tconstpool:$addr)>;
   1315 
   1316 def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
   1317             (t2LDRHi12  t2addrmode_imm12:$addr)>;
   1318 def : T2Pat<(extloadi16 t2addrmode_negimm8:$addr),
   1319             (t2LDRHi8   t2addrmode_negimm8:$addr)>;
   1320 def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
   1321             (t2LDRHs    t2addrmode_so_reg:$addr)>;
   1322 def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
   1323             (t2LDRHpci  tconstpool:$addr)>;
   1324 
   1325 // FIXME: The destination register of the loads and stores can't be PC, but
   1326 //        can be SP. We need another regclass (similar to rGPR) to represent
   1327 //        that. Not a pressing issue since these are selected manually,
   1328 //        not via pattern.
   1329 
   1330 // Indexed loads
   1331 
   1332 let mayLoad = 1, hasSideEffects = 0 in {
   1333 def t2LDR_PRE  : T2Ipreldst<0, 0b10, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
   1334                             (ins t2addrmode_imm8_pre:$addr),
   1335                             AddrModeT2_i8, IndexModePre, IIC_iLoad_iu,
   1336                             "ldr", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>;
   1337 
   1338 def t2LDR_POST : T2Ipostldst<0, 0b10, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
   1339                           (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
   1340                           AddrModeT2_i8, IndexModePost, IIC_iLoad_iu,
   1341                           "ldr", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
   1342 
   1343 def t2LDRB_PRE : T2Ipreldst<0, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
   1344                             (ins t2addrmode_imm8_pre:$addr),
   1345                             AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
   1346                             "ldrb", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>;
   1347 
   1348 def t2LDRB_POST : T2Ipostldst<0, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
   1349                           (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
   1350                           AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
   1351                           "ldrb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
   1352 
   1353 def t2LDRH_PRE : T2Ipreldst<0, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
   1354                             (ins t2addrmode_imm8_pre:$addr),
   1355                             AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
   1356                             "ldrh", "\t$Rt, $addr!", "$addr.base = $Rn_wb", []>;
   1357 
   1358 def t2LDRH_POST : T2Ipostldst<0, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
   1359                           (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
   1360                           AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
   1361                           "ldrh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
   1362 
   1363 def t2LDRSB_PRE : T2Ipreldst<1, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
   1364                             (ins t2addrmode_imm8_pre:$addr),
   1365                             AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
   1366                             "ldrsb", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
   1367                             []>;
   1368 
   1369 def t2LDRSB_POST : T2Ipostldst<1, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
   1370                           (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
   1371                           AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
   1372                           "ldrsb", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
   1373 
   1374 def t2LDRSH_PRE : T2Ipreldst<1, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn_wb),
   1375                             (ins t2addrmode_imm8_pre:$addr),
   1376                             AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
   1377                             "ldrsh", "\t$Rt, $addr!", "$addr.base = $Rn_wb",
   1378                             []>;
   1379 
   1380 def t2LDRSH_POST : T2Ipostldst<1, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn_wb),
   1381                           (ins addr_offset_none:$Rn, t2am_imm8_offset:$offset),
   1382                           AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
   1383                           "ldrsh", "\t$Rt, $Rn$offset", "$Rn = $Rn_wb", []>;
   1384 } // mayLoad = 1, hasSideEffects = 0
   1385 
   1386 // LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110).
   1387 // Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4
   1388 class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii>
   1389   : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_posimm8:$addr), ii, opc,
   1390           "\t$Rt, $addr", []> {
   1391   bits<4> Rt;
   1392   bits<13> addr;
   1393   let Inst{31-27} = 0b11111;
   1394   let Inst{26-25} = 0b00;
   1395   let Inst{24} = signed;
   1396   let Inst{23} = 0;
   1397   let Inst{22-21} = type;
   1398   let Inst{20} = 1; // load
   1399   let Inst{19-16} = addr{12-9};
   1400   let Inst{15-12} = Rt;
   1401   let Inst{11} = 1;
   1402   let Inst{10-8} = 0b110; // PUW.
   1403   let Inst{7-0} = addr{7-0};
   1404 
   1405   let DecoderMethod = "DecodeT2LoadT";
   1406 }
   1407 
   1408 def t2LDRT   : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>;
   1409 def t2LDRBT  : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>;
   1410 def t2LDRHT  : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>;
   1411 def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>;
   1412 def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>;
   1413 
   1414 class T2Ildacq<bits<4> bits23_20, bits<2> bit54, dag oops, dag iops,
   1415                string opc, string asm, list<dag> pattern>
   1416   : Thumb2I<oops, iops, AddrModeNone, 4, NoItinerary,
   1417             opc, asm, "", pattern>, Requires<[IsThumb, HasV8]> {
   1418   bits<4> Rt;
   1419   bits<4> addr;
   1420 
   1421   let Inst{31-27} = 0b11101;
   1422   let Inst{26-24} = 0b000;
   1423   let Inst{23-20} = bits23_20;
   1424   let Inst{11-6} = 0b111110;
   1425   let Inst{5-4} = bit54;
   1426   let Inst{3-0} = 0b1111;
   1427 
   1428   // Encode instruction operands
   1429   let Inst{19-16} = addr;
   1430   let Inst{15-12} = Rt;
   1431 }
   1432 
   1433 def t2LDA : T2Ildacq<0b1101, 0b10, (outs rGPR:$Rt),
   1434                      (ins addr_offset_none:$addr), "lda", "\t$Rt, $addr", []>;
   1435 def t2LDAB : T2Ildacq<0b1101, 0b00, (outs rGPR:$Rt),
   1436                       (ins addr_offset_none:$addr), "ldab", "\t$Rt, $addr", []>;
   1437 def t2LDAH : T2Ildacq<0b1101, 0b01, (outs rGPR:$Rt),
   1438                       (ins addr_offset_none:$addr), "ldah", "\t$Rt, $addr", []>;
   1439 
   1440 // Store
   1441 defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si, GPR,
   1442                    BinOpFrag<(store node:$LHS, node:$RHS)>>;
   1443 defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si,
   1444                    rGPR, BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
   1445 defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si,
   1446                    rGPR, BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
   1447 
   1448 // Store doubleword
   1449 let mayStore = 1, hasSideEffects = 0, hasExtraSrcRegAllocReq = 1 in
   1450 def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs),
   1451                        (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4:$addr),
   1452                IIC_iStore_d_r, "strd", "\t$Rt, $Rt2, $addr", "", []>;
   1453 
   1454 // Indexed stores
   1455 
   1456 let mayStore = 1, hasSideEffects = 0 in {
   1457 def t2STR_PRE  : T2Ipreldst<0, 0b10, 0, 1, (outs GPRnopc:$Rn_wb),
   1458                             (ins GPRnopc:$Rt, t2addrmode_imm8_pre:$addr),
   1459                             AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
   1460                             "str", "\t$Rt, $addr!",
   1461                             "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>;
   1462 
   1463 def t2STRH_PRE  : T2Ipreldst<0, 0b01, 0, 1, (outs GPRnopc:$Rn_wb),
   1464                             (ins rGPR:$Rt, t2addrmode_imm8_pre:$addr),
   1465                             AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
   1466                         "strh", "\t$Rt, $addr!",
   1467                         "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>;
   1468 
   1469 def t2STRB_PRE  : T2Ipreldst<0, 0b00, 0, 1, (outs GPRnopc:$Rn_wb),
   1470                             (ins rGPR:$Rt, t2addrmode_imm8_pre:$addr),
   1471                             AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu,
   1472                         "strb", "\t$Rt, $addr!",
   1473                         "$addr.base = $Rn_wb,@earlyclobber $Rn_wb", []>;
   1474 } // mayStore = 1, hasSideEffects = 0
   1475 
   1476 def t2STR_POST : T2Ipostldst<0, 0b10, 0, 0, (outs GPRnopc:$Rn_wb),
   1477                             (ins GPRnopc:$Rt, addr_offset_none:$Rn,
   1478                                  t2am_imm8_offset:$offset),
   1479                             AddrModeT2_i8, IndexModePost, IIC_iStore_iu,
   1480                           "str", "\t$Rt, $Rn$offset",
   1481                           "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
   1482              [(set GPRnopc:$Rn_wb,
   1483                   (post_store GPRnopc:$Rt, addr_offset_none:$Rn,
   1484                               t2am_imm8_offset:$offset))]>;
   1485 
   1486 def t2STRH_POST : T2Ipostldst<0, 0b01, 0, 0, (outs GPRnopc:$Rn_wb),
   1487                             (ins rGPR:$Rt, addr_offset_none:$Rn,
   1488                                  t2am_imm8_offset:$offset),
   1489                             AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
   1490                          "strh", "\t$Rt, $Rn$offset",
   1491                          "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
   1492        [(set GPRnopc:$Rn_wb,
   1493              (post_truncsti16 rGPR:$Rt, addr_offset_none:$Rn,
   1494                               t2am_imm8_offset:$offset))]>;
   1495 
   1496 def t2STRB_POST : T2Ipostldst<0, 0b00, 0, 0, (outs GPRnopc:$Rn_wb),
   1497                             (ins rGPR:$Rt, addr_offset_none:$Rn,
   1498                                  t2am_imm8_offset:$offset),
   1499                             AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
   1500                          "strb", "\t$Rt, $Rn$offset",
   1501                          "$Rn = $Rn_wb,@earlyclobber $Rn_wb",
   1502         [(set GPRnopc:$Rn_wb,
   1503               (post_truncsti8 rGPR:$Rt, addr_offset_none:$Rn,
   1504                               t2am_imm8_offset:$offset))]>;
   1505 
   1506 // Pseudo-instructions for pattern matching the pre-indexed stores. We can't
   1507 // put the patterns on the instruction definitions directly as ISel wants
   1508 // the address base and offset to be separate operands, not a single
   1509 // complex operand like we represent the instructions themselves. The
   1510 // pseudos map between the two.
   1511 let usesCustomInserter = 1,
   1512     Constraints = "$Rn = $Rn_wb,@earlyclobber $Rn_wb" in {
   1513 def t2STR_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
   1514                (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
   1515                4, IIC_iStore_ru,
   1516       [(set GPRnopc:$Rn_wb,
   1517             (pre_store rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>;
   1518 def t2STRB_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
   1519                (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
   1520                4, IIC_iStore_ru,
   1521       [(set GPRnopc:$Rn_wb,
   1522             (pre_truncsti8 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>;
   1523 def t2STRH_preidx: t2PseudoInst<(outs GPRnopc:$Rn_wb),
   1524                (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset, pred:$p),
   1525                4, IIC_iStore_ru,
   1526       [(set GPRnopc:$Rn_wb,
   1527             (pre_truncsti16 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$offset))]>;
   1528 }
   1529 
   1530 // STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly
   1531 // only.
   1532 // Ref: A8.6.193 STR (immediate, Thumb) Encoding T4
   1533 class T2IstT<bits<2> type, string opc, InstrItinClass ii>
   1534   : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc,
   1535           "\t$Rt, $addr", []> {
   1536   let Inst{31-27} = 0b11111;
   1537   let Inst{26-25} = 0b00;
   1538   let Inst{24} = 0; // not signed
   1539   let Inst{23} = 0;
   1540   let Inst{22-21} = type;
   1541   let Inst{20} = 0; // store
   1542   let Inst{11} = 1;
   1543   let Inst{10-8} = 0b110; // PUW
   1544 
   1545   bits<4> Rt;
   1546   bits<13> addr;
   1547   let Inst{15-12} = Rt;
   1548   let Inst{19-16} = addr{12-9};
   1549   let Inst{7-0}   = addr{7-0};
   1550 }
   1551 
   1552 def t2STRT   : T2IstT<0b10, "strt", IIC_iStore_i>;
   1553 def t2STRBT  : T2IstT<0b00, "strbt", IIC_iStore_bh_i>;
   1554 def t2STRHT  : T2IstT<0b01, "strht", IIC_iStore_bh_i>;
   1555 
   1556 // ldrd / strd pre / post variants
   1557 
   1558 let mayLoad = 1 in
   1559 def t2LDRD_PRE  : T2Ii8s4<1, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
   1560                  (ins t2addrmode_imm8s4_pre:$addr), IIC_iLoad_d_ru,
   1561                  "ldrd", "\t$Rt, $Rt2, $addr!", "$addr.base = $wb", []> {
   1562   let DecoderMethod = "DecodeT2LDRDPreInstruction";
   1563 }
   1564 
   1565 let mayLoad = 1 in
   1566 def t2LDRD_POST : T2Ii8s4post<0, 1, 1, (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
   1567                  (ins addr_offset_none:$addr, t2am_imm8s4_offset:$imm),
   1568                  IIC_iLoad_d_ru, "ldrd", "\t$Rt, $Rt2, $addr$imm",
   1569                  "$addr.base = $wb", []>;
   1570 
   1571 let mayStore = 1 in
   1572 def t2STRD_PRE  : T2Ii8s4<1, 1, 0, (outs GPR:$wb),
   1573                  (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_imm8s4_pre:$addr),
   1574                  IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr!",
   1575                  "$addr.base = $wb", []> {
   1576   let DecoderMethod = "DecodeT2STRDPreInstruction";
   1577 }
   1578 
   1579 let mayStore = 1 in
   1580 def t2STRD_POST : T2Ii8s4post<0, 1, 0, (outs GPR:$wb),
   1581                  (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr,
   1582                       t2am_imm8s4_offset:$imm),
   1583                  IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, $addr$imm",
   1584                  "$addr.base = $wb", []>;
   1585 
   1586 class T2Istrrel<bits<2> bit54, dag oops, dag iops,
   1587                 string opc, string asm, list<dag> pattern>
   1588   : Thumb2I<oops, iops, AddrModeNone, 4, NoItinerary, opc,
   1589             asm, "", pattern>, Requires<[IsThumb, HasV8]> {
   1590   bits<4> Rt;
   1591   bits<4> addr;
   1592 
   1593   let Inst{31-27} = 0b11101;
   1594   let Inst{26-20} = 0b0001100;
   1595   let Inst{11-6} = 0b111110;
   1596   let Inst{5-4} = bit54;
   1597   let Inst{3-0} = 0b1111;
   1598 
   1599   // Encode instruction operands
   1600   let Inst{19-16} = addr;
   1601   let Inst{15-12} = Rt;
   1602 }
   1603 
   1604 def t2STL  : T2Istrrel<0b10, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
   1605                        "stl", "\t$Rt, $addr", []>;
   1606 def t2STLB : T2Istrrel<0b00, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
   1607                        "stlb", "\t$Rt, $addr", []>;
   1608 def t2STLH : T2Istrrel<0b01, (outs), (ins rGPR:$Rt, addr_offset_none:$addr),
   1609                        "stlh", "\t$Rt, $addr", []>;
   1610 
   1611 // T2Ipl (Preload Data/Instruction) signals the memory system of possible future
   1612 // data/instruction access.
   1613 // instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0),
   1614 // (prefetch 1) -> (preload 2),  (prefetch 2) -> (preload 1).
   1615 multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> {
   1616 
   1617   def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc,
   1618                 "\t$addr",
   1619               [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]>,
   1620               Sched<[WritePreLd]> {
   1621     let Inst{31-25} = 0b1111100;
   1622     let Inst{24} = instr;
   1623     let Inst{23} = 1;
   1624     let Inst{22} = 0;
   1625     let Inst{21} = write;
   1626     let Inst{20} = 1;
   1627     let Inst{15-12} = 0b1111;
   1628 
   1629     bits<17> addr;
   1630     let Inst{19-16} = addr{16-13}; // Rn
   1631     let Inst{11-0}  = addr{11-0};  // imm12
   1632 
   1633     let DecoderMethod = "DecodeT2LoadImm12";
   1634   }
   1635 
   1636   def i8 : T2Ii8<(outs), (ins t2addrmode_negimm8:$addr), IIC_Preload, opc,
   1637                 "\t$addr",
   1638             [(ARMPreload t2addrmode_negimm8:$addr, (i32 write), (i32 instr))]>,
   1639             Sched<[WritePreLd]> {
   1640     let Inst{31-25} = 0b1111100;
   1641     let Inst{24} = instr;
   1642     let Inst{23} = 0; // U = 0
   1643     let Inst{22} = 0;
   1644     let Inst{21} = write;
   1645     let Inst{20} = 1;
   1646     let Inst{15-12} = 0b1111;
   1647     let Inst{11-8} = 0b1100;
   1648 
   1649     bits<13> addr;
   1650     let Inst{19-16} = addr{12-9}; // Rn
   1651     let Inst{7-0}   = addr{7-0};  // imm8
   1652 
   1653     let DecoderMethod = "DecodeT2LoadImm8";
   1654   }
   1655 
   1656   def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc,
   1657                "\t$addr",
   1658              [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]>,
   1659              Sched<[WritePreLd]> {
   1660     let Inst{31-25} = 0b1111100;
   1661     let Inst{24} = instr;
   1662     let Inst{23} = 0; // add = TRUE for T1
   1663     let Inst{22} = 0;
   1664     let Inst{21} = write;
   1665     let Inst{20} = 1;
   1666     let Inst{15-12} = 0b1111;
   1667     let Inst{11-6} = 0b000000;
   1668 
   1669     bits<10> addr;
   1670     let Inst{19-16} = addr{9-6}; // Rn
   1671     let Inst{3-0}   = addr{5-2}; // Rm
   1672     let Inst{5-4}   = addr{1-0}; // imm2
   1673 
   1674     let DecoderMethod = "DecodeT2LoadShift";
   1675   }
   1676 }
   1677 
   1678 defm t2PLD    : T2Ipl<0, 0, "pld">,  Requires<[IsThumb2]>;
   1679 defm t2PLDW   : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>;
   1680 defm t2PLI    : T2Ipl<0, 1, "pli">,  Requires<[IsThumb2,HasV7]>;
   1681 
   1682 // pci variant is very similar to i12, but supports negative offsets
   1683 // from the PC. Only PLD and PLI have pci variants (not PLDW)
   1684 class T2Iplpci<bits<1> inst, string opc> : T2Iso<(outs), (ins t2ldrlabel:$addr),
   1685                IIC_Preload, opc, "\t$addr",
   1686                [(ARMPreload (ARMWrapper tconstpool:$addr),
   1687                 (i32 0), (i32 inst))]>, Sched<[WritePreLd]> {
   1688   let Inst{31-25} = 0b1111100;
   1689   let Inst{24} = inst;
   1690   let Inst{22-20} = 0b001;
   1691   let Inst{19-16} = 0b1111;
   1692   let Inst{15-12} = 0b1111;
   1693 
   1694   bits<13> addr;
   1695   let Inst{23}   = addr{12};   // add = (U == '1')
   1696   let Inst{11-0} = addr{11-0}; // imm12
   1697 
   1698   let DecoderMethod = "DecodeT2LoadLabel";
   1699 }
   1700 
   1701 def t2PLDpci : T2Iplpci<0, "pld">,  Requires<[IsThumb2]>;
   1702 def t2PLIpci : T2Iplpci<1, "pli">,  Requires<[IsThumb2,HasV7]>;
   1703 
   1704 //===----------------------------------------------------------------------===//
   1705 //  Load / store multiple Instructions.
   1706 //
   1707 
   1708 multiclass thumb2_ld_mult<string asm, InstrItinClass itin,
   1709                             InstrItinClass itin_upd, bit L_bit> {
   1710   def IA :
   1711     T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
   1712          itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
   1713     bits<4>  Rn;
   1714     bits<16> regs;
   1715 
   1716     let Inst{31-27} = 0b11101;
   1717     let Inst{26-25} = 0b00;
   1718     let Inst{24-23} = 0b01;     // Increment After
   1719     let Inst{22}    = 0;
   1720     let Inst{21}    = 0;        // No writeback
   1721     let Inst{20}    = L_bit;
   1722     let Inst{19-16} = Rn;
   1723     let Inst{15-0}  = regs;
   1724   }
   1725   def IA_UPD :
   1726     T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
   1727           itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
   1728     bits<4>  Rn;
   1729     bits<16> regs;
   1730 
   1731     let Inst{31-27} = 0b11101;
   1732     let Inst{26-25} = 0b00;
   1733     let Inst{24-23} = 0b01;     // Increment After
   1734     let Inst{22}    = 0;
   1735     let Inst{21}    = 1;        // Writeback
   1736     let Inst{20}    = L_bit;
   1737     let Inst{19-16} = Rn;
   1738     let Inst{15-0}  = regs;
   1739   }
   1740   def DB :
   1741     T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
   1742          itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
   1743     bits<4>  Rn;
   1744     bits<16> regs;
   1745 
   1746     let Inst{31-27} = 0b11101;
   1747     let Inst{26-25} = 0b00;
   1748     let Inst{24-23} = 0b10;     // Decrement Before
   1749     let Inst{22}    = 0;
   1750     let Inst{21}    = 0;        // No writeback
   1751     let Inst{20}    = L_bit;
   1752     let Inst{19-16} = Rn;
   1753     let Inst{15-0}  = regs;
   1754   }
   1755   def DB_UPD :
   1756     T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
   1757           itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
   1758     bits<4>  Rn;
   1759     bits<16> regs;
   1760 
   1761     let Inst{31-27} = 0b11101;
   1762     let Inst{26-25} = 0b00;
   1763     let Inst{24-23} = 0b10;     // Decrement Before
   1764     let Inst{22}    = 0;
   1765     let Inst{21}    = 1;        // Writeback
   1766     let Inst{20}    = L_bit;
   1767     let Inst{19-16} = Rn;
   1768     let Inst{15-0}  = regs;
   1769   }
   1770 }
   1771 
   1772 let hasSideEffects = 0 in {
   1773 
   1774 let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
   1775 defm t2LDM : thumb2_ld_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>;
   1776 
   1777 multiclass thumb2_st_mult<string asm, InstrItinClass itin,
   1778                             InstrItinClass itin_upd, bit L_bit> {
   1779   def IA :
   1780     T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
   1781          itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
   1782     bits<4>  Rn;
   1783     bits<16> regs;
   1784 
   1785     let Inst{31-27} = 0b11101;
   1786     let Inst{26-25} = 0b00;
   1787     let Inst{24-23} = 0b01;     // Increment After
   1788     let Inst{22}    = 0;
   1789     let Inst{21}    = 0;        // No writeback
   1790     let Inst{20}    = L_bit;
   1791     let Inst{19-16} = Rn;
   1792     let Inst{15}    = 0;
   1793     let Inst{14}    = regs{14};
   1794     let Inst{13}    = 0;
   1795     let Inst{12-0}  = regs{12-0};
   1796   }
   1797   def IA_UPD :
   1798     T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
   1799           itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
   1800     bits<4>  Rn;
   1801     bits<16> regs;
   1802 
   1803     let Inst{31-27} = 0b11101;
   1804     let Inst{26-25} = 0b00;
   1805     let Inst{24-23} = 0b01;     // Increment After
   1806     let Inst{22}    = 0;
   1807     let Inst{21}    = 1;        // Writeback
   1808     let Inst{20}    = L_bit;
   1809     let Inst{19-16} = Rn;
   1810     let Inst{15}    = 0;
   1811     let Inst{14}    = regs{14};
   1812     let Inst{13}    = 0;
   1813     let Inst{12-0}  = regs{12-0};
   1814   }
   1815   def DB :
   1816     T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
   1817          itin, !strconcat(asm, "db${p}\t$Rn, $regs"), []> {
   1818     bits<4>  Rn;
   1819     bits<16> regs;
   1820 
   1821     let Inst{31-27} = 0b11101;
   1822     let Inst{26-25} = 0b00;
   1823     let Inst{24-23} = 0b10;     // Decrement Before
   1824     let Inst{22}    = 0;
   1825     let Inst{21}    = 0;        // No writeback
   1826     let Inst{20}    = L_bit;
   1827     let Inst{19-16} = Rn;
   1828     let Inst{15}    = 0;
   1829     let Inst{14}    = regs{14};
   1830     let Inst{13}    = 0;
   1831     let Inst{12-0}  = regs{12-0};
   1832   }
   1833   def DB_UPD :
   1834     T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
   1835           itin_upd, !strconcat(asm, "db${p}\t$Rn!, $regs"), "$Rn = $wb", []> {
   1836     bits<4>  Rn;
   1837     bits<16> regs;
   1838 
   1839     let Inst{31-27} = 0b11101;
   1840     let Inst{26-25} = 0b00;
   1841     let Inst{24-23} = 0b10;     // Decrement Before
   1842     let Inst{22}    = 0;
   1843     let Inst{21}    = 1;        // Writeback
   1844     let Inst{20}    = L_bit;
   1845     let Inst{19-16} = Rn;
   1846     let Inst{15}    = 0;
   1847     let Inst{14}    = regs{14};
   1848     let Inst{13}    = 0;
   1849     let Inst{12-0}  = regs{12-0};
   1850   }
   1851 }
   1852 
   1853 
   1854 let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
   1855 defm t2STM : thumb2_st_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>;
   1856 
   1857 } // hasSideEffects
   1858 
   1859 
   1860 //===----------------------------------------------------------------------===//
   1861 //  Move Instructions.
   1862 //
   1863 
   1864 let hasSideEffects = 0 in
   1865 def t2MOVr : T2sTwoReg<(outs GPRnopc:$Rd), (ins GPR:$Rm), IIC_iMOVr,
   1866                    "mov", ".w\t$Rd, $Rm", []>, Sched<[WriteALU]> {
   1867   let Inst{31-27} = 0b11101;
   1868   let Inst{26-25} = 0b01;
   1869   let Inst{24-21} = 0b0010;
   1870   let Inst{19-16} = 0b1111; // Rn
   1871   let Inst{14-12} = 0b000;
   1872   let Inst{7-4} = 0b0000;
   1873 }
   1874 def : t2InstAlias<"mov${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPR:$Rm,
   1875                                                 pred:$p, zero_reg)>;
   1876 def : t2InstAlias<"movs${p}.w $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPR:$Rm,
   1877                                                  pred:$p, CPSR)>;
   1878 def : t2InstAlias<"movs${p} $Rd, $Rm", (t2MOVr GPRnopc:$Rd, GPR:$Rm,
   1879                                                pred:$p, CPSR)>;
   1880 
   1881 // AddedComplexity to ensure isel tries t2MOVi before t2MOVi16.
   1882 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1,
   1883     AddedComplexity = 1 in
   1884 def t2MOVi : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), IIC_iMOVi,
   1885                    "mov", ".w\t$Rd, $imm",
   1886                    [(set rGPR:$Rd, t2_so_imm:$imm)]>, Sched<[WriteALU]> {
   1887   let Inst{31-27} = 0b11110;
   1888   let Inst{25} = 0;
   1889   let Inst{24-21} = 0b0010;
   1890   let Inst{19-16} = 0b1111; // Rn
   1891   let Inst{15} = 0;
   1892 }
   1893 
   1894 // cc_out is handled as part of the explicit mnemonic in the parser for 'mov'.
   1895 // Use aliases to get that to play nice here.
   1896 def : t2InstAlias<"movs${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
   1897                                                 pred:$p, CPSR)>;
   1898 def : t2InstAlias<"movs${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
   1899                                                 pred:$p, CPSR)>;
   1900 
   1901 def : t2InstAlias<"mov${p}.w $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
   1902                                                  pred:$p, zero_reg)>;
   1903 def : t2InstAlias<"mov${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
   1904                                                pred:$p, zero_reg)>;
   1905 
   1906 let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
   1907 def t2MOVi16 : T2I<(outs rGPR:$Rd), (ins imm0_65535_expr:$imm), IIC_iMOVi,
   1908                    "movw", "\t$Rd, $imm",
   1909                    [(set rGPR:$Rd, imm0_65535:$imm)]>, Sched<[WriteALU]> {
   1910   let Inst{31-27} = 0b11110;
   1911   let Inst{25} = 1;
   1912   let Inst{24-21} = 0b0010;
   1913   let Inst{20} = 0; // The S bit.
   1914   let Inst{15} = 0;
   1915 
   1916   bits<4> Rd;
   1917   bits<16> imm;
   1918 
   1919   let Inst{11-8}  = Rd;
   1920   let Inst{19-16} = imm{15-12};
   1921   let Inst{26}    = imm{11};
   1922   let Inst{14-12} = imm{10-8};
   1923   let Inst{7-0}   = imm{7-0};
   1924   let DecoderMethod = "DecodeT2MOVTWInstruction";
   1925 }
   1926 
   1927 def : t2InstAlias<"mov${p} $Rd, $imm",
   1928                   (t2MOVi16 rGPR:$Rd, imm256_65535_expr:$imm, pred:$p)>;
   1929 
   1930 def t2MOVi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
   1931                                 (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
   1932 
   1933 let Constraints = "$src = $Rd" in {
   1934 def t2MOVTi16 : T2I<(outs rGPR:$Rd),
   1935                     (ins rGPR:$src, imm0_65535_expr:$imm), IIC_iMOVi,
   1936                     "movt", "\t$Rd, $imm",
   1937                     [(set rGPR:$Rd,
   1938                           (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]>,
   1939                           Sched<[WriteALU]> {
   1940   let Inst{31-27} = 0b11110;
   1941   let Inst{25} = 1;
   1942   let Inst{24-21} = 0b0110;
   1943   let Inst{20} = 0; // The S bit.
   1944   let Inst{15} = 0;
   1945 
   1946   bits<4> Rd;
   1947   bits<16> imm;
   1948 
   1949   let Inst{11-8}  = Rd;
   1950   let Inst{19-16} = imm{15-12};
   1951   let Inst{26}    = imm{11};
   1952   let Inst{14-12} = imm{10-8};
   1953   let Inst{7-0}   = imm{7-0};
   1954   let DecoderMethod = "DecodeT2MOVTWInstruction";
   1955 }
   1956 
   1957 def t2MOVTi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
   1958                      (ins rGPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>,
   1959                      Sched<[WriteALU]>;
   1960 } // Constraints
   1961 
   1962 def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>;
   1963 
   1964 //===----------------------------------------------------------------------===//
   1965 //  Extend Instructions.
   1966 //
   1967 
   1968 // Sign extenders
   1969 
   1970 def t2SXTB  : T2I_ext_rrot<0b100, "sxtb",
   1971                               UnOpFrag<(sext_inreg node:$Src, i8)>>;
   1972 def t2SXTH  : T2I_ext_rrot<0b000, "sxth",
   1973                               UnOpFrag<(sext_inreg node:$Src, i16)>>;
   1974 def t2SXTB16 : T2I_ext_rrot_sxtb16<0b010, "sxtb16">;
   1975 
   1976 def t2SXTAB : T2I_exta_rrot<0b100, "sxtab",
   1977                         BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
   1978 def t2SXTAH : T2I_exta_rrot<0b000, "sxtah",
   1979                         BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
   1980 def t2SXTAB16 : T2I_exta_rrot_np<0b010, "sxtab16">;
   1981 
   1982 // A simple right-shift can also be used in most cases (the exception is the
   1983 // SXTH operations with a rotate of 24: there the non-contiguous bits are
   1984 // relevant).
   1985 def : Pat<(add rGPR:$Rn, (sext_inreg (srl rGPR:$Rm, rot_imm:$rot), i8)),
   1986           (t2SXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>,
   1987       Requires<[HasT2ExtractPack, IsThumb2]>;
   1988 def : Pat<(add rGPR:$Rn, (sext_inreg (srl rGPR:$Rm, imm8_or_16:$rot), i16)),
   1989           (t2SXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>,
   1990       Requires<[HasT2ExtractPack, IsThumb2]>;
   1991 
   1992 // Zero extenders
   1993 
   1994 let AddedComplexity = 16 in {
   1995 def t2UXTB   : T2I_ext_rrot<0b101, "uxtb",
   1996                                UnOpFrag<(and node:$Src, 0x000000FF)>>;
   1997 def t2UXTH   : T2I_ext_rrot<0b001, "uxth",
   1998                                UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
   1999 def t2UXTB16 : T2I_ext_rrot_uxtb16<0b011, "uxtb16",
   2000                                UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
   2001 
   2002 // FIXME: This pattern incorrectly assumes the shl operator is a rotate.
   2003 //        The transformation should probably be done as a combiner action
   2004 //        instead so we can include a check for masking back in the upper
   2005 //        eight bits of the source into the lower eight bits of the result.
   2006 //def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF),
   2007 //            (t2UXTB16 rGPR:$Src, 3)>,
   2008 //          Requires<[HasT2ExtractPack, IsThumb2]>;
   2009 def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF),
   2010             (t2UXTB16 rGPR:$Src, 1)>,
   2011         Requires<[HasT2ExtractPack, IsThumb2]>;
   2012 
   2013 def t2UXTAB : T2I_exta_rrot<0b101, "uxtab",
   2014                            BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
   2015 def t2UXTAH : T2I_exta_rrot<0b001, "uxtah",
   2016                            BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
   2017 def t2UXTAB16 : T2I_exta_rrot_np<0b011, "uxtab16">;
   2018 
   2019 def : Pat<(add rGPR:$Rn, (and (srl rGPR:$Rm, rot_imm:$rot), 0xFF)),
   2020           (t2UXTAB rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>,
   2021       Requires<[HasT2ExtractPack, IsThumb2]>;
   2022 def : Pat<(add rGPR:$Rn, (and (srl rGPR:$Rm, imm8_or_16:$rot), 0xFFFF)),
   2023           (t2UXTAH rGPR:$Rn, rGPR:$Rm, rot_imm:$rot)>,
   2024       Requires<[HasT2ExtractPack, IsThumb2]>;
   2025 }
   2026 
   2027 
   2028 //===----------------------------------------------------------------------===//
   2029 //  Arithmetic Instructions.
   2030 //
   2031 
   2032 defm t2ADD  : T2I_bin_ii12rs<0b000, "add",
   2033                              BinOpFrag<(add  node:$LHS, node:$RHS)>, 1>;
   2034 defm t2SUB  : T2I_bin_ii12rs<0b101, "sub",
   2035                              BinOpFrag<(sub  node:$LHS, node:$RHS)>>;
   2036 
   2037 // ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
   2038 //
   2039 // Currently, t2ADDS/t2SUBS are pseudo opcodes that exist only in the
   2040 // selection DAG. They are "lowered" to real t2ADD/t2SUB opcodes by
   2041 // AdjustInstrPostInstrSelection where we determine whether or not to
   2042 // set the "s" bit based on CPSR liveness.
   2043 //
   2044 // FIXME: Eliminate t2ADDS/t2SUBS pseudo opcodes after adding tablegen
   2045 // support for an optional CPSR definition that corresponds to the DAG
   2046 // node's second value. We can then eliminate the implicit def of CPSR.
   2047 defm t2ADDS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi,
   2048                              BinOpFrag<(ARMaddc node:$LHS, node:$RHS)>, 1>;
   2049 defm t2SUBS : T2I_bin_s_irs <IIC_iALUi, IIC_iALUr, IIC_iALUsi,
   2050                              BinOpFrag<(ARMsubc node:$LHS, node:$RHS)>>;
   2051 
   2052 let hasPostISelHook = 1 in {
   2053 defm t2ADC  : T2I_adde_sube_irs<0b1010, "adc",
   2054               BinOpWithFlagFrag<(ARMadde node:$LHS, node:$RHS, node:$FLAG)>, 1>;
   2055 defm t2SBC  : T2I_adde_sube_irs<0b1011, "sbc",
   2056               BinOpWithFlagFrag<(ARMsube node:$LHS, node:$RHS, node:$FLAG)>>;
   2057 }
   2058 
   2059 // RSB
   2060 defm t2RSB  : T2I_rbin_irs  <0b1110, "rsb",
   2061                              BinOpFrag<(sub  node:$LHS, node:$RHS)>>;
   2062 
   2063 // FIXME: Eliminate them if we can write def : Pat patterns which defines
   2064 // CPSR and the implicit def of CPSR is not needed.
   2065 defm t2RSBS : T2I_rbin_s_is <BinOpFrag<(ARMsubc node:$LHS, node:$RHS)>>;
   2066 
   2067 // (sub X, imm) gets canonicalized to (add X, -imm).  Match this form.
   2068 // The assume-no-carry-in form uses the negation of the input since add/sub
   2069 // assume opposite meanings of the carry flag (i.e., carry == !borrow).
   2070 // See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
   2071 // details.
   2072 // The AddedComplexity preferences the first variant over the others since
   2073 // it can be shrunk to a 16-bit wide encoding, while the others cannot.
   2074 let AddedComplexity = 1 in
   2075 def : T2Pat<(add        GPR:$src, imm1_255_neg:$imm),
   2076             (t2SUBri    GPR:$src, imm1_255_neg:$imm)>;
   2077 def : T2Pat<(add        GPR:$src, t2_so_imm_neg:$imm),
   2078             (t2SUBri    GPR:$src, t2_so_imm_neg:$imm)>;
   2079 def : T2Pat<(add        GPR:$src, imm0_4095_neg:$imm),
   2080             (t2SUBri12  GPR:$src, imm0_4095_neg:$imm)>;
   2081 def : T2Pat<(add        GPR:$src, imm0_65535_neg:$imm),
   2082             (t2SUBrr    GPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>;
   2083 
   2084 let AddedComplexity = 1 in
   2085 def : T2Pat<(ARMaddc    rGPR:$src, imm1_255_neg:$imm),
   2086             (t2SUBSri   rGPR:$src, imm1_255_neg:$imm)>;
   2087 def : T2Pat<(ARMaddc    rGPR:$src, t2_so_imm_neg:$imm),
   2088             (t2SUBSri   rGPR:$src, t2_so_imm_neg:$imm)>;
   2089 def : T2Pat<(ARMaddc    rGPR:$src, imm0_65535_neg:$imm),
   2090             (t2SUBSrr   rGPR:$src, (t2MOVi16 (imm_neg_XFORM imm:$imm)))>;
   2091 // The with-carry-in form matches bitwise not instead of the negation.
   2092 // Effectively, the inverse interpretation of the carry flag already accounts
   2093 // for part of the negation.
   2094 let AddedComplexity = 1 in
   2095 def : T2Pat<(ARMadde    rGPR:$src, imm0_255_not:$imm, CPSR),
   2096             (t2SBCri    rGPR:$src, imm0_255_not:$imm)>;
   2097 def : T2Pat<(ARMadde    rGPR:$src, t2_so_imm_not:$imm, CPSR),
   2098             (t2SBCri    rGPR:$src, t2_so_imm_not:$imm)>;
   2099 def : T2Pat<(ARMadde    rGPR:$src, imm0_65535_neg:$imm, CPSR),
   2100             (t2SBCrr    rGPR:$src, (t2MOVi16 (imm_not_XFORM imm:$imm)))>;
   2101 
   2102 // Select Bytes -- for disassembly only
   2103 
   2104 def t2SEL : T2ThreeReg<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
   2105                 NoItinerary, "sel", "\t$Rd, $Rn, $Rm", []>,
   2106           Requires<[IsThumb2, HasDSP]> {
   2107   let Inst{31-27} = 0b11111;
   2108   let Inst{26-24} = 0b010;
   2109   let Inst{23} = 0b1;
   2110   let Inst{22-20} = 0b010;
   2111   let Inst{15-12} = 0b1111;
   2112   let Inst{7} = 0b1;
   2113   let Inst{6-4} = 0b000;
   2114 }
   2115 
   2116 // A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned)
   2117 // And Miscellaneous operations -- for disassembly only
   2118 class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc,
   2119               list<dag> pat = [/* For disassembly only; pattern left blank */],
   2120               dag iops = (ins rGPR:$Rn, rGPR:$Rm),
   2121               string asm = "\t$Rd, $Rn, $Rm">
   2122   : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, pat>,
   2123     Requires<[IsThumb2, HasDSP]> {
   2124   let Inst{31-27} = 0b11111;
   2125   let Inst{26-23} = 0b0101;
   2126   let Inst{22-20} = op22_20;
   2127   let Inst{15-12} = 0b1111;
   2128   let Inst{7-4} = op7_4;
   2129 
   2130   bits<4> Rd;
   2131   bits<4> Rn;
   2132   bits<4> Rm;
   2133 
   2134   let Inst{11-8}  = Rd;
   2135   let Inst{19-16} = Rn;
   2136   let Inst{3-0}   = Rm;
   2137 }
   2138 
   2139 // Saturating add/subtract -- for disassembly only
   2140 
   2141 def t2QADD    : T2I_pam<0b000, 0b1000, "qadd",
   2142                         [(set rGPR:$Rd, (int_arm_qadd rGPR:$Rn, rGPR:$Rm))],
   2143                         (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
   2144 def t2QADD16  : T2I_pam<0b001, 0b0001, "qadd16">;
   2145 def t2QADD8   : T2I_pam<0b000, 0b0001, "qadd8">;
   2146 def t2QASX    : T2I_pam<0b010, 0b0001, "qasx">;
   2147 def t2QDADD   : T2I_pam<0b000, 0b1001, "qdadd", [],
   2148                         (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
   2149 def t2QDSUB   : T2I_pam<0b000, 0b1011, "qdsub", [],
   2150                         (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
   2151 def t2QSAX    : T2I_pam<0b110, 0b0001, "qsax">;
   2152 def t2QSUB    : T2I_pam<0b000, 0b1010, "qsub",
   2153                         [(set rGPR:$Rd, (int_arm_qsub rGPR:$Rn, rGPR:$Rm))],
   2154                         (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
   2155 def t2QSUB16  : T2I_pam<0b101, 0b0001, "qsub16">;
   2156 def t2QSUB8   : T2I_pam<0b100, 0b0001, "qsub8">;
   2157 def t2UQADD16 : T2I_pam<0b001, 0b0101, "uqadd16">;
   2158 def t2UQADD8  : T2I_pam<0b000, 0b0101, "uqadd8">;
   2159 def t2UQASX   : T2I_pam<0b010, 0b0101, "uqasx">;
   2160 def t2UQSAX   : T2I_pam<0b110, 0b0101, "uqsax">;
   2161 def t2UQSUB16 : T2I_pam<0b101, 0b0101, "uqsub16">;
   2162 def t2UQSUB8  : T2I_pam<0b100, 0b0101, "uqsub8">;
   2163 
   2164 // Signed/Unsigned add/subtract -- for disassembly only
   2165 
   2166 def t2SASX    : T2I_pam<0b010, 0b0000, "sasx">;
   2167 def t2SADD16  : T2I_pam<0b001, 0b0000, "sadd16">;
   2168 def t2SADD8   : T2I_pam<0b000, 0b0000, "sadd8">;
   2169 def t2SSAX    : T2I_pam<0b110, 0b0000, "ssax">;
   2170 def t2SSUB16  : T2I_pam<0b101, 0b0000, "ssub16">;
   2171 def t2SSUB8   : T2I_pam<0b100, 0b0000, "ssub8">;
   2172 def t2UASX    : T2I_pam<0b010, 0b0100, "uasx">;
   2173 def t2UADD16  : T2I_pam<0b001, 0b0100, "uadd16">;
   2174 def t2UADD8   : T2I_pam<0b000, 0b0100, "uadd8">;
   2175 def t2USAX    : T2I_pam<0b110, 0b0100, "usax">;
   2176 def t2USUB16  : T2I_pam<0b101, 0b0100, "usub16">;
   2177 def t2USUB8   : T2I_pam<0b100, 0b0100, "usub8">;
   2178 
   2179 // Signed/Unsigned halving add/subtract -- for disassembly only
   2180 
   2181 def t2SHASX   : T2I_pam<0b010, 0b0010, "shasx">;
   2182 def t2SHADD16 : T2I_pam<0b001, 0b0010, "shadd16">;
   2183 def t2SHADD8  : T2I_pam<0b000, 0b0010, "shadd8">;
   2184 def t2SHSAX   : T2I_pam<0b110, 0b0010, "shsax">;
   2185 def t2SHSUB16 : T2I_pam<0b101, 0b0010, "shsub16">;
   2186 def t2SHSUB8  : T2I_pam<0b100, 0b0010, "shsub8">;
   2187 def t2UHASX   : T2I_pam<0b010, 0b0110, "uhasx">;
   2188 def t2UHADD16 : T2I_pam<0b001, 0b0110, "uhadd16">;
   2189 def t2UHADD8  : T2I_pam<0b000, 0b0110, "uhadd8">;
   2190 def t2UHSAX   : T2I_pam<0b110, 0b0110, "uhsax">;
   2191 def t2UHSUB16 : T2I_pam<0b101, 0b0110, "uhsub16">;
   2192 def t2UHSUB8  : T2I_pam<0b100, 0b0110, "uhsub8">;
   2193 
   2194 // Helper class for disassembly only
   2195 // A6.3.16 & A6.3.17
   2196 // T2Imac - Thumb2 multiply [accumulate, and absolute difference] instructions.
   2197 class T2ThreeReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
   2198   dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
   2199   : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
   2200   let Inst{31-27} = 0b11111;
   2201   let Inst{26-24} = 0b011;
   2202   let Inst{23}    = long;
   2203   let Inst{22-20} = op22_20;
   2204   let Inst{7-4}   = op7_4;
   2205 }
   2206 
   2207 class T2FourReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
   2208   dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
   2209   : T2FourReg<oops, iops, itin, opc, asm, pattern> {
   2210   let Inst{31-27} = 0b11111;
   2211   let Inst{26-24} = 0b011;
   2212   let Inst{23}    = long;
   2213   let Inst{22-20} = op22_20;
   2214   let Inst{7-4}   = op7_4;
   2215 }
   2216 
   2217 // Unsigned Sum of Absolute Differences [and Accumulate].
   2218 def t2USAD8   : T2ThreeReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
   2219                                            (ins rGPR:$Rn, rGPR:$Rm),
   2220                         NoItinerary, "usad8", "\t$Rd, $Rn, $Rm", []>,
   2221           Requires<[IsThumb2, HasDSP]> {
   2222   let Inst{15-12} = 0b1111;
   2223 }
   2224 def t2USADA8  : T2FourReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
   2225                        (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), NoItinerary,
   2226                         "usada8", "\t$Rd, $Rn, $Rm, $Ra", []>,
   2227           Requires<[IsThumb2, HasDSP]>;
   2228 
   2229 // Signed/Unsigned saturate.
   2230 class T2SatI<dag oops, dag iops, InstrItinClass itin,
   2231            string opc, string asm, list<dag> pattern>
   2232   : T2I<oops, iops, itin, opc, asm, pattern> {
   2233   bits<4> Rd;
   2234   bits<4> Rn;
   2235   bits<5> sat_imm;
   2236   bits<7> sh;
   2237 
   2238   let Inst{11-8}  = Rd;
   2239   let Inst{19-16} = Rn;
   2240   let Inst{4-0}   = sat_imm;
   2241   let Inst{21}    = sh{5};
   2242   let Inst{14-12} = sh{4-2};
   2243   let Inst{7-6}   = sh{1-0};
   2244 }
   2245 
   2246 def t2SSAT: T2SatI<
   2247               (outs rGPR:$Rd),
   2248               (ins imm1_32:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
   2249               NoItinerary, "ssat", "\t$Rd, $sat_imm, $Rn$sh", []> {
   2250   let Inst{31-27} = 0b11110;
   2251   let Inst{25-22} = 0b1100;
   2252   let Inst{20} = 0;
   2253   let Inst{15} = 0;
   2254   let Inst{5}  = 0;
   2255 }
   2256 
   2257 def t2SSAT16: T2SatI<
   2258                 (outs rGPR:$Rd), (ins imm1_16:$sat_imm, rGPR:$Rn), NoItinerary,
   2259                 "ssat16", "\t$Rd, $sat_imm, $Rn", []>,
   2260           Requires<[IsThumb2, HasDSP]> {
   2261   let Inst{31-27} = 0b11110;
   2262   let Inst{25-22} = 0b1100;
   2263   let Inst{20} = 0;
   2264   let Inst{15} = 0;
   2265   let Inst{21} = 1;        // sh = '1'
   2266   let Inst{14-12} = 0b000; // imm3 = '000'
   2267   let Inst{7-6} = 0b00;    // imm2 = '00'
   2268   let Inst{5-4} = 0b00;
   2269 }
   2270 
   2271 def t2USAT: T2SatI<
   2272                (outs rGPR:$Rd),
   2273                (ins imm0_31:$sat_imm, rGPR:$Rn, t2_shift_imm:$sh),
   2274                 NoItinerary, "usat", "\t$Rd, $sat_imm, $Rn$sh", []> {
   2275   let Inst{31-27} = 0b11110;
   2276   let Inst{25-22} = 0b1110;
   2277   let Inst{20} = 0;
   2278   let Inst{15} = 0;
   2279 }
   2280 
   2281 def t2USAT16: T2SatI<(outs rGPR:$Rd), (ins imm0_15:$sat_imm, rGPR:$Rn),
   2282                      NoItinerary,
   2283                      "usat16", "\t$Rd, $sat_imm, $Rn", []>,
   2284           Requires<[IsThumb2, HasDSP]> {
   2285   let Inst{31-22} = 0b1111001110;
   2286   let Inst{20} = 0;
   2287   let Inst{15} = 0;
   2288   let Inst{21} = 1;        // sh = '1'
   2289   let Inst{14-12} = 0b000; // imm3 = '000'
   2290   let Inst{7-6} = 0b00;    // imm2 = '00'
   2291   let Inst{5-4} = 0b00;
   2292 }
   2293 
   2294 def : T2Pat<(int_arm_ssat GPR:$a, imm1_32:$pos), (t2SSAT imm1_32:$pos, GPR:$a, 0)>;
   2295 def : T2Pat<(int_arm_usat GPR:$a, imm0_31:$pos), (t2USAT imm0_31:$pos, GPR:$a, 0)>;
   2296 
   2297 //===----------------------------------------------------------------------===//
   2298 //  Shift and rotate Instructions.
   2299 //
   2300 
   2301 defm t2LSL  : T2I_sh_ir<0b00, "lsl", imm0_31,
   2302                         BinOpFrag<(shl  node:$LHS, node:$RHS)>>;
   2303 defm t2LSR  : T2I_sh_ir<0b01, "lsr", imm_sr,
   2304                         BinOpFrag<(srl  node:$LHS, node:$RHS)>>;
   2305 defm t2ASR  : T2I_sh_ir<0b10, "asr", imm_sr,
   2306                         BinOpFrag<(sra  node:$LHS, node:$RHS)>>;
   2307 defm t2ROR  : T2I_sh_ir<0b11, "ror", imm0_31,
   2308                         BinOpFrag<(rotr node:$LHS, node:$RHS)>>;
   2309 
   2310 // (rotr x, (and y, 0x...1f)) ==> (ROR x, y)
   2311 def : T2Pat<(rotr rGPR:$lhs, (and rGPR:$rhs, lo5AllOne)),
   2312             (t2RORrr rGPR:$lhs, rGPR:$rhs)>;
   2313 
   2314 let Uses = [CPSR] in {
   2315 def t2RRX : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
   2316                    "rrx", "\t$Rd, $Rm",
   2317                    [(set rGPR:$Rd, (ARMrrx rGPR:$Rm))]>, Sched<[WriteALU]> {
   2318   let Inst{31-27} = 0b11101;
   2319   let Inst{26-25} = 0b01;
   2320   let Inst{24-21} = 0b0010;
   2321   let Inst{19-16} = 0b1111; // Rn
   2322   let Inst{14-12} = 0b000;
   2323   let Inst{7-4} = 0b0011;
   2324 }
   2325 }
   2326 
   2327 let isCodeGenOnly = 1, Defs = [CPSR] in {
   2328 def t2MOVsrl_flag : T2TwoRegShiftImm<
   2329                         (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
   2330                         "lsrs", ".w\t$Rd, $Rm, #1",
   2331                         [(set rGPR:$Rd, (ARMsrl_flag rGPR:$Rm))]>,
   2332                         Sched<[WriteALU]> {
   2333   let Inst{31-27} = 0b11101;
   2334   let Inst{26-25} = 0b01;
   2335   let Inst{24-21} = 0b0010;
   2336   let Inst{20} = 1; // The S bit.
   2337   let Inst{19-16} = 0b1111; // Rn
   2338   let Inst{5-4} = 0b01; // Shift type.
   2339   // Shift amount = Inst{14-12:7-6} = 1.
   2340   let Inst{14-12} = 0b000;
   2341   let Inst{7-6} = 0b01;
   2342 }
   2343 def t2MOVsra_flag : T2TwoRegShiftImm<
   2344                         (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
   2345                         "asrs", ".w\t$Rd, $Rm, #1",
   2346                         [(set rGPR:$Rd, (ARMsra_flag rGPR:$Rm))]>,
   2347                         Sched<[WriteALU]> {
   2348   let Inst{31-27} = 0b11101;
   2349   let Inst{26-25} = 0b01;
   2350   let Inst{24-21} = 0b0010;
   2351   let Inst{20} = 1; // The S bit.
   2352   let Inst{19-16} = 0b1111; // Rn
   2353   let Inst{5-4} = 0b10; // Shift type.
   2354   // Shift amount = Inst{14-12:7-6} = 1.
   2355   let Inst{14-12} = 0b000;
   2356   let Inst{7-6} = 0b01;
   2357 }
   2358 }
   2359 
   2360 //===----------------------------------------------------------------------===//
   2361 //  Bitwise Instructions.
   2362 //
   2363 
   2364 defm t2AND  : T2I_bin_w_irs<0b0000, "and",
   2365                             IIC_iBITi, IIC_iBITr, IIC_iBITsi,
   2366                             BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
   2367 defm t2ORR  : T2I_bin_w_irs<0b0010, "orr",
   2368                             IIC_iBITi, IIC_iBITr, IIC_iBITsi,
   2369                             BinOpFrag<(or  node:$LHS, node:$RHS)>, 1>;
   2370 defm t2EOR  : T2I_bin_w_irs<0b0100, "eor",
   2371                             IIC_iBITi, IIC_iBITr, IIC_iBITsi,
   2372                             BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
   2373 
   2374 defm t2BIC  : T2I_bin_w_irs<0b0001, "bic",
   2375                             IIC_iBITi, IIC_iBITr, IIC_iBITsi,
   2376                             BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
   2377 
   2378 class T2BitFI<dag oops, dag iops, InstrItinClass itin,
   2379               string opc, string asm, list<dag> pattern>
   2380     : T2I<oops, iops, itin, opc, asm, pattern> {
   2381   bits<4> Rd;
   2382   bits<5> msb;
   2383   bits<5> lsb;
   2384 
   2385   let Inst{11-8}  = Rd;
   2386   let Inst{4-0}   = msb{4-0};
   2387   let Inst{14-12} = lsb{4-2};
   2388   let Inst{7-6}   = lsb{1-0};
   2389 }
   2390 
   2391 class T2TwoRegBitFI<dag oops, dag iops, InstrItinClass itin,
   2392               string opc, string asm, list<dag> pattern>
   2393     : T2BitFI<oops, iops, itin, opc, asm, pattern> {
   2394   bits<4> Rn;
   2395 
   2396   let Inst{19-16} = Rn;
   2397 }
   2398 
   2399 let Constraints = "$src = $Rd" in
   2400 def t2BFC : T2BitFI<(outs rGPR:$Rd), (ins rGPR:$src, bf_inv_mask_imm:$imm),
   2401                 IIC_iUNAsi, "bfc", "\t$Rd, $imm",
   2402                 [(set rGPR:$Rd, (and rGPR:$src, bf_inv_mask_imm:$imm))]> {
   2403   let Inst{31-27} = 0b11110;
   2404   let Inst{26} = 0; // should be 0.
   2405   let Inst{25} = 1;
   2406   let Inst{24-20} = 0b10110;
   2407   let Inst{19-16} = 0b1111; // Rn
   2408   let Inst{15} = 0;
   2409   let Inst{5} = 0; // should be 0.
   2410 
   2411   bits<10> imm;
   2412   let msb{4-0} = imm{9-5};
   2413   let lsb{4-0} = imm{4-0};
   2414 }
   2415 
   2416 def t2SBFX: T2TwoRegBitFI<
   2417                 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
   2418                  IIC_iUNAsi, "sbfx", "\t$Rd, $Rn, $lsb, $msb", []> {
   2419   let Inst{31-27} = 0b11110;
   2420   let Inst{25} = 1;
   2421   let Inst{24-20} = 0b10100;
   2422   let Inst{15} = 0;
   2423 }
   2424 
   2425 def t2UBFX: T2TwoRegBitFI<
   2426                 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
   2427                  IIC_iUNAsi, "ubfx", "\t$Rd, $Rn, $lsb, $msb", []> {
   2428   let Inst{31-27} = 0b11110;
   2429   let Inst{25} = 1;
   2430   let Inst{24-20} = 0b11100;
   2431   let Inst{15} = 0;
   2432 }
   2433 
   2434 // A8.8.247  UDF - Undefined (Encoding T2)
   2435 def t2UDF : T2XI<(outs), (ins imm0_65535:$imm16), IIC_Br, "udf.w\t$imm16",
   2436                  [(int_arm_undefined imm0_65535:$imm16)]> {
   2437   bits<16> imm16;
   2438   let Inst{31-29} = 0b111;
   2439   let Inst{28-27} = 0b10;
   2440   let Inst{26-20} = 0b1111111;
   2441   let Inst{19-16} = imm16{15-12};
   2442   let Inst{15} = 0b1;
   2443   let Inst{14-12} = 0b010;
   2444   let Inst{11-0} = imm16{11-0};
   2445 }
   2446 
   2447 // A8.6.18  BFI - Bitfield insert (Encoding T1)
   2448 let Constraints = "$src = $Rd" in {
   2449   def t2BFI : T2TwoRegBitFI<(outs rGPR:$Rd),
   2450                   (ins rGPR:$src, rGPR:$Rn, bf_inv_mask_imm:$imm),
   2451                   IIC_iBITi, "bfi", "\t$Rd, $Rn, $imm",
   2452                   [(set rGPR:$Rd, (ARMbfi rGPR:$src, rGPR:$Rn,
   2453                                    bf_inv_mask_imm:$imm))]> {
   2454     let Inst{31-27} = 0b11110;
   2455     let Inst{26} = 0; // should be 0.
   2456     let Inst{25} = 1;
   2457     let Inst{24-20} = 0b10110;
   2458     let Inst{15} = 0;
   2459     let Inst{5} = 0; // should be 0.
   2460 
   2461     bits<10> imm;
   2462     let msb{4-0} = imm{9-5};
   2463     let lsb{4-0} = imm{4-0};
   2464   }
   2465 }
   2466 
   2467 defm t2ORN  : T2I_bin_irs<0b0011, "orn",
   2468                           IIC_iBITi, IIC_iBITr, IIC_iBITsi,
   2469                           BinOpFrag<(or node:$LHS, (not node:$RHS))>, 0, "">;
   2470 
   2471 /// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
   2472 /// unary operation that produces a value. These are predicable and can be
   2473 /// changed to modify CPSR.
   2474 multiclass T2I_un_irs<bits<4> opcod, string opc,
   2475                      InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
   2476                       PatFrag opnode,
   2477                       bit Cheap = 0, bit ReMat = 0, bit MoveImm = 0> {
   2478    // shifted imm
   2479    def i : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), iii,
   2480                 opc, "\t$Rd, $imm",
   2481                 [(set rGPR:$Rd, (opnode t2_so_imm:$imm))]>, Sched<[WriteALU]> {
   2482      let isAsCheapAsAMove = Cheap;
   2483      let isReMaterializable = ReMat;
   2484      let isMoveImm = MoveImm;
   2485      let Inst{31-27} = 0b11110;
   2486      let Inst{25} = 0;
   2487      let Inst{24-21} = opcod;
   2488      let Inst{19-16} = 0b1111; // Rn
   2489      let Inst{15} = 0;
   2490    }
   2491    // register
   2492    def r : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), iir,
   2493                 opc, ".w\t$Rd, $Rm",
   2494                 [(set rGPR:$Rd, (opnode rGPR:$Rm))]>, Sched<[WriteALU]> {
   2495      let Inst{31-27} = 0b11101;
   2496      let Inst{26-25} = 0b01;
   2497      let Inst{24-21} = opcod;
   2498      let Inst{19-16} = 0b1111; // Rn
   2499      let Inst{14-12} = 0b000; // imm3
   2500      let Inst{7-6} = 0b00; // imm2
   2501      let Inst{5-4} = 0b00; // type
   2502    }
   2503    // shifted register
   2504    def s : T2sOneRegShiftedReg<(outs rGPR:$Rd), (ins t2_so_reg:$ShiftedRm), iis,
   2505                 opc, ".w\t$Rd, $ShiftedRm",
   2506                 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm))]>,
   2507                 Sched<[WriteALU]> {
   2508      let Inst{31-27} = 0b11101;
   2509      let Inst{26-25} = 0b01;
   2510      let Inst{24-21} = opcod;
   2511      let Inst{19-16} = 0b1111; // Rn
   2512    }
   2513 }
   2514 
   2515 // Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
   2516 let AddedComplexity = 1 in
   2517 defm t2MVN  : T2I_un_irs <0b0011, "mvn",
   2518                           IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi,
   2519                           UnOpFrag<(not node:$Src)>, 1, 1, 1>;
   2520 
   2521 let AddedComplexity = 1 in
   2522 def : T2Pat<(and     rGPR:$src, t2_so_imm_not:$imm),
   2523             (t2BICri rGPR:$src, t2_so_imm_not:$imm)>;
   2524 
   2525 // top16Zero - answer true if the upper 16 bits of $src are 0, false otherwise
   2526 def top16Zero: PatLeaf<(i32 rGPR:$src), [{
   2527   return CurDAG->MaskedValueIsZero(SDValue(N,0), APInt::getHighBitsSet(32, 16));
   2528   }]>;
   2529 
   2530 // so_imm_notSext is needed instead of so_imm_not, as the value of imm
   2531 // will match the extended, not the original bitWidth for $src.
   2532 def : T2Pat<(and top16Zero:$src, t2_so_imm_notSext:$imm),
   2533             (t2BICri rGPR:$src, t2_so_imm_notSext:$imm)>;
   2534 
   2535 
   2536 // FIXME: Disable this pattern on Darwin to workaround an assembler bug.
   2537 def : T2Pat<(or      rGPR:$src, t2_so_imm_not:$imm),
   2538             (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>,
   2539             Requires<[IsThumb2]>;
   2540 
   2541 def : T2Pat<(t2_so_imm_not:$src),
   2542             (t2MVNi t2_so_imm_not:$src)>;
   2543 
   2544 //===----------------------------------------------------------------------===//
   2545 //  Multiply Instructions.
   2546 //
   2547 let isCommutable = 1 in
   2548 def t2MUL: T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
   2549                 "mul", "\t$Rd, $Rn, $Rm",
   2550                 [(set rGPR:$Rd, (mul rGPR:$Rn, rGPR:$Rm))]> {
   2551   let Inst{31-27} = 0b11111;
   2552   let Inst{26-23} = 0b0110;
   2553   let Inst{22-20} = 0b000;
   2554   let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
   2555   let Inst{7-4} = 0b0000; // Multiply
   2556 }
   2557 
   2558 def t2MLA: T2FourReg<
   2559                 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
   2560                 "mla", "\t$Rd, $Rn, $Rm, $Ra",
   2561                 [(set rGPR:$Rd, (add (mul rGPR:$Rn, rGPR:$Rm), rGPR:$Ra))]>,
   2562            Requires<[IsThumb2, UseMulOps]> {
   2563   let Inst{31-27} = 0b11111;
   2564   let Inst{26-23} = 0b0110;
   2565   let Inst{22-20} = 0b000;
   2566   let Inst{7-4} = 0b0000; // Multiply
   2567 }
   2568 
   2569 def t2MLS: T2FourReg<
   2570                 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
   2571                 "mls", "\t$Rd, $Rn, $Rm, $Ra",
   2572                 [(set rGPR:$Rd, (sub rGPR:$Ra, (mul rGPR:$Rn, rGPR:$Rm)))]>,
   2573            Requires<[IsThumb2, UseMulOps]> {
   2574   let Inst{31-27} = 0b11111;
   2575   let Inst{26-23} = 0b0110;
   2576   let Inst{22-20} = 0b000;
   2577   let Inst{7-4} = 0b0001; // Multiply and Subtract
   2578 }
   2579 
   2580 // Extra precision multiplies with low / high results
   2581 let hasSideEffects = 0 in {
   2582 let isCommutable = 1 in {
   2583 def t2SMULL : T2MulLong<0b000, 0b0000,
   2584                   (outs rGPR:$RdLo, rGPR:$RdHi),
   2585                   (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
   2586                    "smull", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
   2587 
   2588 def t2UMULL : T2MulLong<0b010, 0b0000,
   2589                   (outs rGPR:$RdLo, rGPR:$RdHi),
   2590                   (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
   2591                    "umull", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
   2592 } // isCommutable
   2593 
   2594 // Multiply + accumulate
   2595 def t2SMLAL : T2MlaLong<0b100, 0b0000,
   2596                   (outs rGPR:$RdLo, rGPR:$RdHi),
   2597                   (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi), IIC_iMAC64,
   2598                   "smlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
   2599                   RegConstraint<"$RLo = $RdLo, $RHi = $RdHi">;
   2600 
   2601 def t2UMLAL : T2MlaLong<0b110, 0b0000,
   2602                   (outs rGPR:$RdLo, rGPR:$RdHi),
   2603                   (ins rGPR:$Rn, rGPR:$Rm, rGPR:$RLo, rGPR:$RHi), IIC_iMAC64,
   2604                   "umlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
   2605                   RegConstraint<"$RLo = $RdLo, $RHi = $RdHi">;
   2606 
   2607 def t2UMAAL : T2MulLong<0b110, 0b0110,
   2608                   (outs rGPR:$RdLo, rGPR:$RdHi),
   2609                   (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
   2610                   "umaal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
   2611           Requires<[IsThumb2, HasDSP]>;
   2612 } // hasSideEffects
   2613 
   2614 // Rounding variants of the below included for disassembly only
   2615 
   2616 // Most significant word multiply
   2617 def t2SMMUL : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
   2618                   "smmul", "\t$Rd, $Rn, $Rm",
   2619                   [(set rGPR:$Rd, (mulhs rGPR:$Rn, rGPR:$Rm))]>,
   2620           Requires<[IsThumb2, HasDSP]> {
   2621   let Inst{31-27} = 0b11111;
   2622   let Inst{26-23} = 0b0110;
   2623   let Inst{22-20} = 0b101;
   2624   let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
   2625   let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
   2626 }
   2627 
   2628 def t2SMMULR : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
   2629                   "smmulr", "\t$Rd, $Rn, $Rm", []>,
   2630           Requires<[IsThumb2, HasDSP]> {
   2631   let Inst{31-27} = 0b11111;
   2632   let Inst{26-23} = 0b0110;
   2633   let Inst{22-20} = 0b101;
   2634   let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
   2635   let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
   2636 }
   2637 
   2638 def t2SMMLA : T2FourReg<
   2639         (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
   2640                 "smmla", "\t$Rd, $Rn, $Rm, $Ra",
   2641                 [(set rGPR:$Rd, (add (mulhs rGPR:$Rm, rGPR:$Rn), rGPR:$Ra))]>,
   2642               Requires<[IsThumb2, HasDSP, UseMulOps]> {
   2643   let Inst{31-27} = 0b11111;
   2644   let Inst{26-23} = 0b0110;
   2645   let Inst{22-20} = 0b101;
   2646   let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
   2647 }
   2648 
   2649 def t2SMMLAR: T2FourReg<
   2650         (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
   2651                   "smmlar", "\t$Rd, $Rn, $Rm, $Ra", []>,
   2652           Requires<[IsThumb2, HasDSP]> {
   2653   let Inst{31-27} = 0b11111;
   2654   let Inst{26-23} = 0b0110;
   2655   let Inst{22-20} = 0b101;
   2656   let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
   2657 }
   2658 
   2659 def t2SMMLS: T2FourReg<
   2660         (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
   2661                 "smmls", "\t$Rd, $Rn, $Rm, $Ra",
   2662                 [(set rGPR:$Rd, (sub rGPR:$Ra, (mulhs rGPR:$Rn, rGPR:$Rm)))]>,
   2663              Requires<[IsThumb2, HasDSP, UseMulOps]> {
   2664   let Inst{31-27} = 0b11111;
   2665   let Inst{26-23} = 0b0110;
   2666   let Inst{22-20} = 0b110;
   2667   let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
   2668 }
   2669 
   2670 def t2SMMLSR:T2FourReg<
   2671         (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
   2672                 "smmlsr", "\t$Rd, $Rn, $Rm, $Ra", []>,
   2673           Requires<[IsThumb2, HasDSP]> {
   2674   let Inst{31-27} = 0b11111;
   2675   let Inst{26-23} = 0b0110;
   2676   let Inst{22-20} = 0b110;
   2677   let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
   2678 }
   2679 
   2680 multiclass T2I_smul<string opc, PatFrag opnode> {
   2681   def BB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
   2682               !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm",
   2683               [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16),
   2684                                       (sext_inreg rGPR:$Rm, i16)))]>,
   2685           Requires<[IsThumb2, HasDSP]> {
   2686     let Inst{31-27} = 0b11111;
   2687     let Inst{26-23} = 0b0110;
   2688     let Inst{22-20} = 0b001;
   2689     let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
   2690     let Inst{7-6} = 0b00;
   2691     let Inst{5-4} = 0b00;
   2692   }
   2693 
   2694   def BT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
   2695               !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm",
   2696               [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16),
   2697                                       (sra rGPR:$Rm, (i32 16))))]>,
   2698           Requires<[IsThumb2, HasDSP]> {
   2699     let Inst{31-27} = 0b11111;
   2700     let Inst{26-23} = 0b0110;
   2701     let Inst{22-20} = 0b001;
   2702     let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
   2703     let Inst{7-6} = 0b00;
   2704     let Inst{5-4} = 0b01;
   2705   }
   2706 
   2707   def TB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
   2708               !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm",
   2709               [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)),
   2710                                       (sext_inreg rGPR:$Rm, i16)))]>,
   2711           Requires<[IsThumb2, HasDSP]> {
   2712     let Inst{31-27} = 0b11111;
   2713     let Inst{26-23} = 0b0110;
   2714     let Inst{22-20} = 0b001;
   2715     let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
   2716     let Inst{7-6} = 0b00;
   2717     let Inst{5-4} = 0b10;
   2718   }
   2719 
   2720   def TT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
   2721               !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm",
   2722               [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)),
   2723                                       (sra rGPR:$Rm, (i32 16))))]>,
   2724           Requires<[IsThumb2, HasDSP]> {
   2725     let Inst{31-27} = 0b11111;
   2726     let Inst{26-23} = 0b0110;
   2727     let Inst{22-20} = 0b001;
   2728     let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
   2729     let Inst{7-6} = 0b00;
   2730     let Inst{5-4} = 0b11;
   2731   }
   2732 
   2733   def WB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
   2734               !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm",
   2735               []>,
   2736           Requires<[IsThumb2, HasDSP]> {
   2737     let Inst{31-27} = 0b11111;
   2738     let Inst{26-23} = 0b0110;
   2739     let Inst{22-20} = 0b011;
   2740     let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
   2741     let Inst{7-6} = 0b00;
   2742     let Inst{5-4} = 0b00;
   2743   }
   2744 
   2745   def WT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
   2746               !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm",
   2747               []>,
   2748           Requires<[IsThumb2, HasDSP]> {
   2749     let Inst{31-27} = 0b11111;
   2750     let Inst{26-23} = 0b0110;
   2751     let Inst{22-20} = 0b011;
   2752     let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
   2753     let Inst{7-6} = 0b00;
   2754     let Inst{5-4} = 0b01;
   2755   }
   2756 }
   2757 
   2758 
   2759 multiclass T2I_smla<string opc, PatFrag opnode> {
   2760   def BB : T2FourReg<
   2761         (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
   2762               !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm, $Ra",
   2763               [(set rGPR:$Rd, (add rGPR:$Ra,
   2764                                (opnode (sext_inreg rGPR:$Rn, i16),
   2765                                        (sext_inreg rGPR:$Rm, i16))))]>,
   2766            Requires<[IsThumb2, HasDSP, UseMulOps]> {
   2767     let Inst{31-27} = 0b11111;
   2768     let Inst{26-23} = 0b0110;
   2769     let Inst{22-20} = 0b001;
   2770     let Inst{7-6} = 0b00;
   2771     let Inst{5-4} = 0b00;
   2772   }
   2773 
   2774   def BT : T2FourReg<
   2775        (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
   2776              !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm, $Ra",
   2777              [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sext_inreg rGPR:$Rn, i16),
   2778                                                  (sra rGPR:$Rm, (i32 16)))))]>,
   2779            Requires<[IsThumb2, HasDSP, UseMulOps]> {
   2780     let Inst{31-27} = 0b11111;
   2781     let Inst{26-23} = 0b0110;
   2782     let Inst{22-20} = 0b001;
   2783     let Inst{7-6} = 0b00;
   2784     let Inst{5-4} = 0b01;
   2785   }
   2786 
   2787   def TB : T2FourReg<
   2788         (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
   2789               !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm, $Ra",
   2790               [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)),
   2791                                                (sext_inreg rGPR:$Rm, i16))))]>,
   2792            Requires<[IsThumb2, HasDSP, UseMulOps]> {
   2793     let Inst{31-27} = 0b11111;
   2794     let Inst{26-23} = 0b0110;
   2795     let Inst{22-20} = 0b001;
   2796     let Inst{7-6} = 0b00;
   2797     let Inst{5-4} = 0b10;
   2798   }
   2799 
   2800   def TT : T2FourReg<
   2801         (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
   2802               !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm, $Ra",
   2803              [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)),
   2804                                                  (sra rGPR:$Rm, (i32 16)))))]>,
   2805            Requires<[IsThumb2, HasDSP, UseMulOps]> {
   2806     let Inst{31-27} = 0b11111;
   2807     let Inst{26-23} = 0b0110;
   2808     let Inst{22-20} = 0b001;
   2809     let Inst{7-6} = 0b00;
   2810     let Inst{5-4} = 0b11;
   2811   }
   2812 
   2813   def WB : T2FourReg<
   2814         (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
   2815               !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm, $Ra",
   2816               []>,
   2817            Requires<[IsThumb2, HasDSP, UseMulOps]> {
   2818     let Inst{31-27} = 0b11111;
   2819     let Inst{26-23} = 0b0110;
   2820     let Inst{22-20} = 0b011;
   2821     let Inst{7-6} = 0b00;
   2822     let Inst{5-4} = 0b00;
   2823   }
   2824 
   2825   def WT : T2FourReg<
   2826         (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
   2827               !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm, $Ra",
   2828               []>,
   2829            Requires<[IsThumb2, HasDSP, UseMulOps]> {
   2830     let Inst{31-27} = 0b11111;
   2831     let Inst{26-23} = 0b0110;
   2832     let Inst{22-20} = 0b011;
   2833     let Inst{7-6} = 0b00;
   2834     let Inst{5-4} = 0b01;
   2835   }
   2836 }
   2837 
   2838 defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
   2839 defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
   2840 
   2841 // Halfword multiple accumulate long: SMLAL<x><y>
   2842 def t2SMLALBB : T2FourReg_mac<1, 0b100, 0b1000, (outs rGPR:$Ra,rGPR:$Rd),
   2843          (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbb", "\t$Ra, $Rd, $Rn, $Rm",
   2844            [/* For disassembly only; pattern left blank */]>,
   2845           Requires<[IsThumb2, HasDSP]>;
   2846 def t2SMLALBT : T2FourReg_mac<1, 0b100, 0b1001, (outs rGPR:$Ra,rGPR:$Rd),
   2847          (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbt", "\t$Ra, $Rd, $Rn, $Rm",
   2848            [/* For disassembly only; pattern left blank */]>,
   2849           Requires<[IsThumb2, HasDSP]>;
   2850 def t2SMLALTB : T2FourReg_mac<1, 0b100, 0b1010, (outs rGPR:$Ra,rGPR:$Rd),
   2851          (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltb", "\t$Ra, $Rd, $Rn, $Rm",
   2852            [/* For disassembly only; pattern left blank */]>,
   2853           Requires<[IsThumb2, HasDSP]>;
   2854 def t2SMLALTT : T2FourReg_mac<1, 0b100, 0b1011, (outs rGPR:$Ra,rGPR:$Rd),
   2855          (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltt", "\t$Ra, $Rd, $Rn, $Rm",
   2856            [/* For disassembly only; pattern left blank */]>,
   2857           Requires<[IsThumb2, HasDSP]>;
   2858 
   2859 // Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
   2860 def t2SMUAD: T2ThreeReg_mac<
   2861             0, 0b010, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
   2862             IIC_iMAC32, "smuad", "\t$Rd, $Rn, $Rm", []>,
   2863           Requires<[IsThumb2, HasDSP]> {
   2864   let Inst{15-12} = 0b1111;
   2865 }
   2866 def t2SMUADX:T2ThreeReg_mac<
   2867             0, 0b010, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
   2868             IIC_iMAC32, "smuadx", "\t$Rd, $Rn, $Rm", []>,
   2869           Requires<[IsThumb2, HasDSP]> {
   2870   let Inst{15-12} = 0b1111;
   2871 }
   2872 def t2SMUSD: T2ThreeReg_mac<
   2873             0, 0b100, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
   2874             IIC_iMAC32, "smusd", "\t$Rd, $Rn, $Rm", []>,
   2875           Requires<[IsThumb2, HasDSP]> {
   2876   let Inst{15-12} = 0b1111;
   2877 }
   2878 def t2SMUSDX:T2ThreeReg_mac<
   2879             0, 0b100, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
   2880             IIC_iMAC32, "smusdx", "\t$Rd, $Rn, $Rm", []>,
   2881           Requires<[IsThumb2, HasDSP]> {
   2882   let Inst{15-12} = 0b1111;
   2883 }
   2884 def t2SMLAD   : T2FourReg_mac<
   2885             0, 0b010, 0b0000, (outs rGPR:$Rd),
   2886             (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlad",
   2887             "\t$Rd, $Rn, $Rm, $Ra", []>,
   2888           Requires<[IsThumb2, HasDSP]>;
   2889 def t2SMLADX  : T2FourReg_mac<
   2890             0, 0b010, 0b0001, (outs rGPR:$Rd),
   2891             (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smladx",
   2892             "\t$Rd, $Rn, $Rm, $Ra", []>,
   2893           Requires<[IsThumb2, HasDSP]>;
   2894 def t2SMLSD   : T2FourReg_mac<0, 0b100, 0b0000, (outs rGPR:$Rd),
   2895             (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsd",
   2896             "\t$Rd, $Rn, $Rm, $Ra", []>,
   2897           Requires<[IsThumb2, HasDSP]>;
   2898 def t2SMLSDX  : T2FourReg_mac<0, 0b100, 0b0001, (outs rGPR:$Rd),
   2899             (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsdx",
   2900             "\t$Rd, $Rn, $Rm, $Ra", []>,
   2901           Requires<[IsThumb2, HasDSP]>;
   2902 def t2SMLALD  : T2FourReg_mac<1, 0b100, 0b1100, (outs rGPR:$Ra,rGPR:$Rd),
   2903                         (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64, "smlald",
   2904                         "\t$Ra, $Rd, $Rn, $Rm", []>,
   2905           Requires<[IsThumb2, HasDSP]>;
   2906 def t2SMLALDX : T2FourReg_mac<1, 0b100, 0b1101, (outs rGPR:$Ra,rGPR:$Rd),
   2907                         (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaldx",
   2908                         "\t$Ra, $Rd, $Rn, $Rm", []>,
   2909           Requires<[IsThumb2, HasDSP]>;
   2910 def t2SMLSLD  : T2FourReg_mac<1, 0b101, 0b1100, (outs rGPR:$Ra,rGPR:$Rd),
   2911                         (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlsld",
   2912                         "\t$Ra, $Rd, $Rn, $Rm", []>,
   2913           Requires<[IsThumb2, HasDSP]>;
   2914 def t2SMLSLDX : T2FourReg_mac<1, 0b101, 0b1101, (outs rGPR:$Ra,rGPR:$Rd),
   2915                         (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlsldx",
   2916                         "\t$Ra, $Rd, $Rn, $Rm", []>,
   2917           Requires<[IsThumb2, HasDSP]>;
   2918 
   2919 //===----------------------------------------------------------------------===//
   2920 //  Division Instructions.
   2921 //  Signed and unsigned division on v7-M
   2922 //
   2923 def t2SDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
   2924                  "sdiv", "\t$Rd, $Rn, $Rm",
   2925                  [(set rGPR:$Rd, (sdiv rGPR:$Rn, rGPR:$Rm))]>,
   2926                  Requires<[HasDivide, IsThumb2]> {
   2927   let Inst{31-27} = 0b11111;
   2928   let Inst{26-21} = 0b011100;
   2929   let Inst{20} = 0b1;
   2930   let Inst{15-12} = 0b1111;
   2931   let Inst{7-4} = 0b1111;
   2932 }
   2933 
   2934 def t2UDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iDIV,
   2935                  "udiv", "\t$Rd, $Rn, $Rm",
   2936                  [(set rGPR:$Rd, (udiv rGPR:$Rn, rGPR:$Rm))]>,
   2937                  Requires<[HasDivide, IsThumb2]> {
   2938   let Inst{31-27} = 0b11111;
   2939   let Inst{26-21} = 0b011101;
   2940   let Inst{20} = 0b1;
   2941   let Inst{15-12} = 0b1111;
   2942   let Inst{7-4} = 0b1111;
   2943 }
   2944 
   2945 //===----------------------------------------------------------------------===//
   2946 //  Misc. Arithmetic Instructions.
   2947 //
   2948 
   2949 class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops,
   2950       InstrItinClass itin, string opc, string asm, list<dag> pattern>
   2951   : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
   2952   let Inst{31-27} = 0b11111;
   2953   let Inst{26-22} = 0b01010;
   2954   let Inst{21-20} = op1;
   2955   let Inst{15-12} = 0b1111;
   2956   let Inst{7-6} = 0b10;
   2957   let Inst{5-4} = op2;
   2958   let Rn{3-0} = Rm;
   2959 }
   2960 
   2961 def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
   2962                     "clz", "\t$Rd, $Rm", [(set rGPR:$Rd, (ctlz rGPR:$Rm))]>,
   2963                     Sched<[WriteALU]>;
   2964 
   2965 def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
   2966                       "rbit", "\t$Rd, $Rm",
   2967                       [(set rGPR:$Rd, (bitreverse rGPR:$Rm))]>,
   2968                       Sched<[WriteALU]>;
   2969 
   2970 def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
   2971                  "rev", ".w\t$Rd, $Rm", [(set rGPR:$Rd, (bswap rGPR:$Rm))]>,
   2972                  Sched<[WriteALU]>;
   2973 
   2974 def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
   2975                        "rev16", ".w\t$Rd, $Rm",
   2976                 [(set rGPR:$Rd, (rotr (bswap rGPR:$Rm), (i32 16)))]>,
   2977                 Sched<[WriteALU]>;
   2978 
   2979 def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
   2980                        "revsh", ".w\t$Rd, $Rm",
   2981                  [(set rGPR:$Rd, (sra (bswap rGPR:$Rm), (i32 16)))]>,
   2982                  Sched<[WriteALU]>;
   2983 
   2984 def : T2Pat<(or (sra (shl rGPR:$Rm, (i32 24)), (i32 16)),
   2985                 (and (srl rGPR:$Rm, (i32 8)), 0xFF)),
   2986             (t2REVSH rGPR:$Rm)>;
   2987 
   2988 def t2PKHBT : T2ThreeReg<
   2989             (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_lsl_amt:$sh),
   2990                   IIC_iBITsi, "pkhbt", "\t$Rd, $Rn, $Rm$sh",
   2991                   [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF),
   2992                                       (and (shl rGPR:$Rm, pkh_lsl_amt:$sh),
   2993                                            0xFFFF0000)))]>,
   2994                   Requires<[HasT2ExtractPack, IsThumb2]>,
   2995                   Sched<[WriteALUsi, ReadALU]> {
   2996   let Inst{31-27} = 0b11101;
   2997   let Inst{26-25} = 0b01;
   2998   let Inst{24-20} = 0b01100;
   2999   let Inst{5} = 0; // BT form
   3000   let Inst{4} = 0;
   3001 
   3002   bits<5> sh;
   3003   let Inst{14-12} = sh{4-2};
   3004   let Inst{7-6}   = sh{1-0};
   3005 }
   3006 
   3007 // Alternate cases for PKHBT where identities eliminate some nodes.
   3008 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)),
   3009             (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>,
   3010             Requires<[HasT2ExtractPack, IsThumb2]>;
   3011 def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)),
   3012             (t2PKHBT rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
   3013             Requires<[HasT2ExtractPack, IsThumb2]>;
   3014 
   3015 // Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
   3016 // will match the pattern below.
   3017 def t2PKHTB : T2ThreeReg<
   3018                   (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, pkh_asr_amt:$sh),
   3019                   IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm$sh",
   3020                   [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF0000),
   3021                                        (and (sra rGPR:$Rm, pkh_asr_amt:$sh),
   3022                                             0xFFFF)))]>,
   3023                   Requires<[HasT2ExtractPack, IsThumb2]>,
   3024                   Sched<[WriteALUsi, ReadALU]> {
   3025   let Inst{31-27} = 0b11101;
   3026   let Inst{26-25} = 0b01;
   3027   let Inst{24-20} = 0b01100;
   3028   let Inst{5} = 1; // TB form
   3029   let Inst{4} = 0;
   3030 
   3031   bits<5> sh;
   3032   let Inst{14-12} = sh{4-2};
   3033   let Inst{7-6}   = sh{1-0};
   3034 }
   3035 
   3036 // Alternate cases for PKHTB where identities eliminate some nodes.  Note that
   3037 // a shift amount of 0 is *not legal* here, it is PKHBT instead.
   3038 // We also can not replace a srl (17..31) by an arithmetic shift we would use in
   3039 // pkhtb src1, src2, asr (17..31).
   3040 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16:$sh)),
   3041             (t2PKHTB rGPR:$src1, rGPR:$src2, imm16:$sh)>,
   3042             Requires<[HasT2ExtractPack, IsThumb2]>;
   3043 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (sra rGPR:$src2, imm16_31:$sh)),
   3044             (t2PKHTB rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
   3045             Requires<[HasT2ExtractPack, IsThumb2]>;
   3046 def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000),
   3047                 (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)),
   3048             (t2PKHTB rGPR:$src1, rGPR:$src2, imm1_15:$sh)>,
   3049             Requires<[HasT2ExtractPack, IsThumb2]>;
   3050 
   3051 //===----------------------------------------------------------------------===//
   3052 // CRC32 Instructions
   3053 //
   3054 // Polynomials:
   3055 // + CRC32{B,H,W}       0x04C11DB7
   3056 // + CRC32C{B,H,W}      0x1EDC6F41
   3057 //
   3058 
   3059 class T2I_crc32<bit C, bits<2> sz, string suffix, SDPatternOperator builtin>
   3060   : T2ThreeRegNoP<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), NoItinerary,
   3061                !strconcat("crc32", suffix, "\t$Rd, $Rn, $Rm"),
   3062                [(set rGPR:$Rd, (builtin rGPR:$Rn, rGPR:$Rm))]>,
   3063                Requires<[IsThumb2, HasV8, HasCRC]> {
   3064   let Inst{31-27} = 0b11111;
   3065   let Inst{26-21} = 0b010110;
   3066   let Inst{20}    = C;
   3067   let Inst{15-12} = 0b1111;
   3068   let Inst{7-6}   = 0b10;
   3069   let Inst{5-4}   = sz;
   3070 }
   3071 
   3072 def t2CRC32B  : T2I_crc32<0, 0b00, "b", int_arm_crc32b>;
   3073 def t2CRC32CB : T2I_crc32<1, 0b00, "cb", int_arm_crc32cb>;
   3074 def t2CRC32H  : T2I_crc32<0, 0b01, "h", int_arm_crc32h>;
   3075 def t2CRC32CH : T2I_crc32<1, 0b01, "ch", int_arm_crc32ch>;
   3076 def t2CRC32W  : T2I_crc32<0, 0b10, "w", int_arm_crc32w>;
   3077 def t2CRC32CW : T2I_crc32<1, 0b10, "cw", int_arm_crc32cw>;
   3078 
   3079 //===----------------------------------------------------------------------===//
   3080 //  Comparison Instructions...
   3081 //
   3082 defm t2CMP  : T2I_cmp_irs<0b1101, "cmp",
   3083                           IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
   3084                           BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
   3085 
   3086 def : T2Pat<(ARMcmpZ  GPRnopc:$lhs, t2_so_imm:$imm),
   3087             (t2CMPri  GPRnopc:$lhs, t2_so_imm:$imm)>;
   3088 def : T2Pat<(ARMcmpZ  GPRnopc:$lhs, rGPR:$rhs),
   3089             (t2CMPrr  GPRnopc:$lhs, rGPR:$rhs)>;
   3090 def : T2Pat<(ARMcmpZ  GPRnopc:$lhs, t2_so_reg:$rhs),
   3091             (t2CMPrs  GPRnopc:$lhs, t2_so_reg:$rhs)>;
   3092 
   3093 let isCompare = 1, Defs = [CPSR] in {
   3094    // shifted imm
   3095    def t2CMNri : T2OneRegCmpImm<
   3096                 (outs), (ins GPRnopc:$Rn, t2_so_imm:$imm), IIC_iCMPi,
   3097                 "cmn", ".w\t$Rn, $imm",
   3098                 [(ARMcmn GPRnopc:$Rn, (ineg t2_so_imm:$imm))]>,
   3099                 Sched<[WriteCMP, ReadALU]> {
   3100      let Inst{31-27} = 0b11110;
   3101      let Inst{25} = 0;
   3102      let Inst{24-21} = 0b1000;
   3103      let Inst{20} = 1; // The S bit.
   3104      let Inst{15} = 0;
   3105      let Inst{11-8} = 0b1111; // Rd
   3106    }
   3107    // register
   3108    def t2CMNzrr : T2TwoRegCmp<
   3109                 (outs), (ins GPRnopc:$Rn, rGPR:$Rm), IIC_iCMPr,
   3110                 "cmn", ".w\t$Rn, $Rm",
   3111                 [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
   3112                   GPRnopc:$Rn, rGPR:$Rm)]>, Sched<[WriteCMP, ReadALU, ReadALU]> {
   3113      let Inst{31-27} = 0b11101;
   3114      let Inst{26-25} = 0b01;
   3115      let Inst{24-21} = 0b1000;
   3116      let Inst{20} = 1; // The S bit.
   3117      let Inst{14-12} = 0b000; // imm3
   3118      let Inst{11-8} = 0b1111; // Rd
   3119      let Inst{7-6} = 0b00; // imm2
   3120      let Inst{5-4} = 0b00; // type
   3121    }
   3122    // shifted register
   3123    def t2CMNzrs : T2OneRegCmpShiftedReg<
   3124                 (outs), (ins GPRnopc:$Rn, t2_so_reg:$ShiftedRm), IIC_iCMPsi,
   3125                 "cmn", ".w\t$Rn, $ShiftedRm",
   3126                 [(BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>
   3127                   GPRnopc:$Rn, t2_so_reg:$ShiftedRm)]>,
   3128                   Sched<[WriteCMPsi, ReadALU, ReadALU]> {
   3129      let Inst{31-27} = 0b11101;
   3130      let Inst{26-25} = 0b01;
   3131      let Inst{24-21} = 0b1000;
   3132      let Inst{20} = 1; // The S bit.
   3133      let Inst{11-8} = 0b1111; // Rd
   3134    }
   3135 }
   3136 
   3137 // Assembler aliases w/o the ".w" suffix.
   3138 // No alias here for 'rr' version as not all instantiations of this multiclass
   3139 // want one (CMP in particular, does not).
   3140 def : t2InstAlias<"cmn${p} $Rn, $imm",
   3141    (t2CMNri GPRnopc:$Rn, t2_so_imm:$imm, pred:$p)>;
   3142 def : t2InstAlias<"cmn${p} $Rn, $shift",
   3143    (t2CMNzrs GPRnopc:$Rn, t2_so_reg:$shift, pred:$p)>;
   3144 
   3145 def : T2Pat<(ARMcmp  GPR:$src, t2_so_imm_neg:$imm),
   3146             (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
   3147 
   3148 def : T2Pat<(ARMcmpZ GPRnopc:$src, t2_so_imm_neg:$imm),
   3149             (t2CMNri GPRnopc:$src, t2_so_imm_neg:$imm)>;
   3150 
   3151 defm t2TST  : T2I_cmp_irs<0b0000, "tst",
   3152                           IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
   3153                          BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>>;
   3154 defm t2TEQ  : T2I_cmp_irs<0b0100, "teq",
   3155                           IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
   3156                          BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>>;
   3157 
   3158 // Conditional moves
   3159 let hasSideEffects = 0 in {
   3160 
   3161 let isCommutable = 1, isSelect = 1 in
   3162 def t2MOVCCr : t2PseudoInst<(outs rGPR:$Rd),
   3163                             (ins rGPR:$false, rGPR:$Rm, cmovpred:$p),
   3164                             4, IIC_iCMOVr,
   3165                             [(set rGPR:$Rd, (ARMcmov rGPR:$false, rGPR:$Rm,
   3166                                                      cmovpred:$p))]>,
   3167                RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
   3168 
   3169 let isMoveImm = 1 in
   3170 def t2MOVCCi
   3171     : t2PseudoInst<(outs rGPR:$Rd),
   3172                    (ins rGPR:$false, t2_so_imm:$imm, cmovpred:$p),
   3173                    4, IIC_iCMOVi,
   3174                    [(set rGPR:$Rd, (ARMcmov rGPR:$false,t2_so_imm:$imm,
   3175                                             cmovpred:$p))]>,
   3176       RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
   3177 
   3178 let isCodeGenOnly = 1 in {
   3179 let isMoveImm = 1 in
   3180 def t2MOVCCi16
   3181     : t2PseudoInst<(outs rGPR:$Rd),
   3182                    (ins  rGPR:$false, imm0_65535_expr:$imm, cmovpred:$p),
   3183                    4, IIC_iCMOVi,
   3184                    [(set rGPR:$Rd, (ARMcmov rGPR:$false, imm0_65535:$imm,
   3185                                             cmovpred:$p))]>,
   3186       RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
   3187 
   3188 let isMoveImm = 1 in
   3189 def t2MVNCCi
   3190     : t2PseudoInst<(outs rGPR:$Rd),
   3191                    (ins rGPR:$false, t2_so_imm:$imm, cmovpred:$p),
   3192                    4, IIC_iCMOVi,
   3193                    [(set rGPR:$Rd,
   3194                          (ARMcmov rGPR:$false, t2_so_imm_not:$imm,
   3195                                   cmovpred:$p))]>,
   3196       RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
   3197 
   3198 class MOVCCShPseudo<SDPatternOperator opnode, Operand ty>
   3199     : t2PseudoInst<(outs rGPR:$Rd),
   3200                    (ins rGPR:$false, rGPR:$Rm, i32imm:$imm, cmovpred:$p),
   3201                    4, IIC_iCMOVsi,
   3202                    [(set rGPR:$Rd, (ARMcmov rGPR:$false,
   3203                                             (opnode rGPR:$Rm, (i32 ty:$imm)),
   3204                                             cmovpred:$p))]>,
   3205       RegConstraint<"$false = $Rd">, Sched<[WriteALU]>;
   3206 
   3207 def t2MOVCClsl : MOVCCShPseudo<shl,  imm0_31>;
   3208 def t2MOVCClsr : MOVCCShPseudo<srl,  imm_sr>;
   3209 def t2MOVCCasr : MOVCCShPseudo<sra,  imm_sr>;
   3210 def t2MOVCCror : MOVCCShPseudo<rotr, imm0_31>;
   3211 
   3212 let isMoveImm = 1 in
   3213 def t2MOVCCi32imm
   3214     : t2PseudoInst<(outs rGPR:$dst),
   3215                    (ins rGPR:$false, i32imm:$src, cmovpred:$p),
   3216                    8, IIC_iCMOVix2,
   3217                    [(set rGPR:$dst, (ARMcmov rGPR:$false, imm:$src,
   3218                                              cmovpred:$p))]>,
   3219       RegConstraint<"$false = $dst">;
   3220 } // isCodeGenOnly = 1
   3221 
   3222 } // hasSideEffects
   3223 
   3224 //===----------------------------------------------------------------------===//
   3225 // Atomic operations intrinsics
   3226 //
   3227 
   3228 // memory barriers protect the atomic sequences
   3229 let hasSideEffects = 1 in {
   3230 def t2DMB : T2I<(outs), (ins memb_opt:$opt), NoItinerary,
   3231                 "dmb", "\t$opt", [(int_arm_dmb (i32 imm0_15:$opt))]>,
   3232                 Requires<[IsThumb, HasDB]> {
   3233   bits<4> opt;
   3234   let Inst{31-4} = 0xf3bf8f5;
   3235   let Inst{3-0} = opt;
   3236 }
   3237 
   3238 def t2DSB : T2I<(outs), (ins memb_opt:$opt), NoItinerary,
   3239                 "dsb", "\t$opt", [(int_arm_dsb (i32 imm0_15:$opt))]>,
   3240                 Requires<[IsThumb, HasDB]> {
   3241   bits<4> opt;
   3242   let Inst{31-4} = 0xf3bf8f4;
   3243   let Inst{3-0} = opt;
   3244 }
   3245 
   3246 def t2ISB : T2I<(outs), (ins instsyncb_opt:$opt), NoItinerary,
   3247                 "isb", "\t$opt", [(int_arm_isb (i32 imm0_15:$opt))]>,
   3248                 Requires<[IsThumb, HasDB]> {
   3249   bits<4> opt;
   3250   let Inst{31-4} = 0xf3bf8f6;
   3251   let Inst{3-0} = opt;
   3252 }
   3253 }
   3254 
   3255 class T2I_ldrex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz,
   3256                 InstrItinClass itin, string opc, string asm, string cstr,
   3257                 list<dag> pattern, bits<4> rt2 = 0b1111>
   3258   : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
   3259   let Inst{31-27} = 0b11101;
   3260   let Inst{26-20} = 0b0001101;
   3261   let Inst{11-8} = rt2;
   3262   let Inst{7-4} = opcod;
   3263   let Inst{3-0} = 0b1111;
   3264 
   3265   bits<4> addr;
   3266   bits<4> Rt;
   3267   let Inst{19-16} = addr;
   3268   let Inst{15-12} = Rt;
   3269 }
   3270 class T2I_strex<bits<4> opcod, dag oops, dag iops, AddrMode am, int sz,
   3271                 InstrItinClass itin, string opc, string asm, string cstr,
   3272                 list<dag> pattern, bits<4> rt2 = 0b1111>
   3273   : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
   3274   let Inst{31-27} = 0b11101;
   3275   let Inst{26-20} = 0b0001100;
   3276   let Inst{11-8} = rt2;
   3277   let Inst{7-4} = opcod;
   3278 
   3279   bits<4> Rd;
   3280   bits<4> addr;
   3281   bits<4> Rt;
   3282   let Inst{3-0}  = Rd;
   3283   let Inst{19-16} = addr;
   3284   let Inst{15-12} = Rt;
   3285 }
   3286 
   3287 let mayLoad = 1 in {
   3288 def t2LDREXB : T2I_ldrex<0b0100, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
   3289                          AddrModeNone, 4, NoItinerary,
   3290                          "ldrexb", "\t$Rt, $addr", "",
   3291                          [(set rGPR:$Rt, (ldrex_1 addr_offset_none:$addr))]>;
   3292 def t2LDREXH : T2I_ldrex<0b0101, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
   3293                          AddrModeNone, 4, NoItinerary,
   3294                          "ldrexh", "\t$Rt, $addr", "",
   3295                          [(set rGPR:$Rt, (ldrex_2 addr_offset_none:$addr))]>;
   3296 def t2LDREX  : Thumb2I<(outs rGPR:$Rt), (ins t2addrmode_imm0_1020s4:$addr),
   3297                        AddrModeNone, 4, NoItinerary,
   3298                        "ldrex", "\t$Rt, $addr", "",
   3299                      [(set rGPR:$Rt, (ldrex_4 t2addrmode_imm0_1020s4:$addr))]> {
   3300   bits<4> Rt;
   3301   bits<12> addr;
   3302   let Inst{31-27} = 0b11101;
   3303   let Inst{26-20} = 0b0000101;
   3304   let Inst{19-16} = addr{11-8};
   3305   let Inst{15-12} = Rt;
   3306   let Inst{11-8} = 0b1111;
   3307   let Inst{7-0} = addr{7-0};
   3308 }
   3309 let hasExtraDefRegAllocReq = 1 in
   3310 def t2LDREXD : T2I_ldrex<0b0111, (outs rGPR:$Rt, rGPR:$Rt2),
   3311                          (ins addr_offset_none:$addr),
   3312                          AddrModeNone, 4, NoItinerary,
   3313                          "ldrexd", "\t$Rt, $Rt2, $addr", "",
   3314                          [], {?, ?, ?, ?}>,
   3315                Requires<[IsThumb2, IsNotMClass]> {
   3316   bits<4> Rt2;
   3317   let Inst{11-8} = Rt2;
   3318 }
   3319 def t2LDAEXB : T2I_ldrex<0b1100, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
   3320                          AddrModeNone, 4, NoItinerary,
   3321                          "ldaexb", "\t$Rt, $addr", "",
   3322                          [(set rGPR:$Rt, (ldaex_1 addr_offset_none:$addr))]>,
   3323                Requires<[IsThumb, HasV8]>;
   3324 def t2LDAEXH : T2I_ldrex<0b1101, (outs rGPR:$Rt), (ins addr_offset_none:$addr),
   3325                          AddrModeNone, 4, NoItinerary,
   3326                          "ldaexh", "\t$Rt, $addr", "",
   3327                          [(set rGPR:$Rt, (ldaex_2 addr_offset_none:$addr))]>,
   3328                Requires<[IsThumb, HasV8]>;
   3329 def t2LDAEX  : Thumb2I<(outs rGPR:$Rt), (ins addr_offset_none:$addr),
   3330                        AddrModeNone, 4, NoItinerary,
   3331                        "ldaex", "\t$Rt, $addr", "",
   3332                          [(set rGPR:$Rt, (ldaex_4 addr_offset_none:$addr))]>,
   3333                Requires<[IsThumb, HasV8]> {
   3334   bits<4> Rt;
   3335   bits<4> addr;
   3336   let Inst{31-27} = 0b11101;
   3337   let Inst{26-20} = 0b0001101;
   3338   let Inst{19-16} = addr;
   3339   let Inst{15-12} = Rt;
   3340   let Inst{11-8} = 0b1111;
   3341   let Inst{7-0} = 0b11101111;
   3342 }
   3343 let hasExtraDefRegAllocReq = 1 in
   3344 def t2LDAEXD : T2I_ldrex<0b1111, (outs rGPR:$Rt, rGPR:$Rt2),
   3345                          (ins addr_offset_none:$addr),
   3346                          AddrModeNone, 4, NoItinerary,
   3347                          "ldaexd", "\t$Rt, $Rt2, $addr", "",
   3348                          [], {?, ?, ?, ?}>, Requires<[IsThumb, HasV8]> {
   3349   bits<4> Rt2;
   3350   let Inst{11-8} = Rt2;
   3351 
   3352   let Inst{7} = 1;
   3353 }
   3354 }
   3355 
   3356 let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
   3357 def t2STREXB : T2I_strex<0b0100, (outs rGPR:$Rd),
   3358                          (ins rGPR:$Rt, addr_offset_none:$addr),
   3359                          AddrModeNone, 4, NoItinerary,
   3360                          "strexb", "\t$Rd, $Rt, $addr", "",
   3361                          [(set rGPR:$Rd,
   3362                                (strex_1 rGPR:$Rt, addr_offset_none:$addr))]>;
   3363 def t2STREXH : T2I_strex<0b0101, (outs rGPR:$Rd),
   3364                          (ins rGPR:$Rt, addr_offset_none:$addr),
   3365                          AddrModeNone, 4, NoItinerary,
   3366                          "strexh", "\t$Rd, $Rt, $addr", "",
   3367                          [(set rGPR:$Rd,
   3368                                (strex_2 rGPR:$Rt, addr_offset_none:$addr))]>;
   3369 
   3370 def t2STREX  : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
   3371                              t2addrmode_imm0_1020s4:$addr),
   3372                   AddrModeNone, 4, NoItinerary,
   3373                   "strex", "\t$Rd, $Rt, $addr", "",
   3374                   [(set rGPR:$Rd,
   3375                         (strex_4 rGPR:$Rt, t2addrmode_imm0_1020s4:$addr))]> {
   3376   bits<4> Rd;
   3377   bits<4> Rt;
   3378   bits<12> addr;
   3379   let Inst{31-27} = 0b11101;
   3380   let Inst{26-20} = 0b0000100;
   3381   let Inst{19-16} = addr{11-8};
   3382   let Inst{15-12} = Rt;
   3383   let Inst{11-8}  = Rd;
   3384   let Inst{7-0} = addr{7-0};
   3385 }
   3386 let hasExtraSrcRegAllocReq = 1 in
   3387 def t2STREXD : T2I_strex<0b0111, (outs rGPR:$Rd),
   3388                          (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
   3389                          AddrModeNone, 4, NoItinerary,
   3390                          "strexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
   3391                          {?, ?, ?, ?}>,
   3392                Requires<[IsThumb2, IsNotMClass]> {
   3393   bits<4> Rt2;
   3394   let Inst{11-8} = Rt2;
   3395 }
   3396 def t2STLEXB : T2I_strex<0b1100, (outs rGPR:$Rd),
   3397                          (ins rGPR:$Rt, addr_offset_none:$addr),
   3398                          AddrModeNone, 4, NoItinerary,
   3399                          "stlexb", "\t$Rd, $Rt, $addr", "",
   3400                          [(set rGPR:$Rd,
   3401                                (stlex_1 rGPR:$Rt, addr_offset_none:$addr))]>,
   3402                          Requires<[IsThumb, HasV8]>;
   3403 
   3404 def t2STLEXH : T2I_strex<0b1101, (outs rGPR:$Rd),
   3405                          (ins rGPR:$Rt, addr_offset_none:$addr),
   3406                          AddrModeNone, 4, NoItinerary,
   3407                          "stlexh", "\t$Rd, $Rt, $addr", "",
   3408                          [(set rGPR:$Rd,
   3409                                (stlex_2 rGPR:$Rt, addr_offset_none:$addr))]>,
   3410                          Requires<[IsThumb, HasV8]>;
   3411 
   3412 def t2STLEX  : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt,
   3413                              addr_offset_none:$addr),
   3414                   AddrModeNone, 4, NoItinerary,
   3415                   "stlex", "\t$Rd, $Rt, $addr", "",
   3416                   [(set rGPR:$Rd,
   3417                         (stlex_4 rGPR:$Rt, addr_offset_none:$addr))]>,
   3418                   Requires<[IsThumb, HasV8]> {
   3419   bits<4> Rd;
   3420   bits<4> Rt;
   3421   bits<4> addr;
   3422   let Inst{31-27} = 0b11101;
   3423   let Inst{26-20} = 0b0001100;
   3424   let Inst{19-16} = addr;
   3425   let Inst{15-12} = Rt;
   3426   let Inst{11-4}  = 0b11111110;
   3427   let Inst{3-0}   = Rd;
   3428 }
   3429 let hasExtraSrcRegAllocReq = 1 in
   3430 def t2STLEXD : T2I_strex<0b1111, (outs rGPR:$Rd),
   3431                          (ins rGPR:$Rt, rGPR:$Rt2, addr_offset_none:$addr),
   3432                          AddrModeNone, 4, NoItinerary,
   3433                          "stlexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
   3434                          {?, ?, ?, ?}>, Requires<[IsThumb, HasV8]> {
   3435   bits<4> Rt2;
   3436   let Inst{11-8} = Rt2;
   3437 }
   3438 }
   3439 
   3440 def t2CLREX : T2I<(outs), (ins), NoItinerary, "clrex", "", [(int_arm_clrex)]>,
   3441             Requires<[IsThumb2, HasV7]>  {
   3442   let Inst{31-16} = 0xf3bf;
   3443   let Inst{15-14} = 0b10;
   3444   let Inst{13} = 0;
   3445   let Inst{12} = 0;
   3446   let Inst{11-8} = 0b1111;
   3447   let Inst{7-4} = 0b0010;
   3448   let Inst{3-0} = 0b1111;
   3449 }
   3450 
   3451 def : T2Pat<(and (ldrex_1 addr_offset_none:$addr), 0xff),
   3452             (t2LDREXB addr_offset_none:$addr)>;
   3453 def : T2Pat<(and (ldrex_2 addr_offset_none:$addr), 0xffff),
   3454             (t2LDREXH addr_offset_none:$addr)>;
   3455 def : T2Pat<(strex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr),
   3456             (t2STREXB GPR:$Rt, addr_offset_none:$addr)>;
   3457 def : T2Pat<(strex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr),
   3458             (t2STREXH GPR:$Rt, addr_offset_none:$addr)>;
   3459 
   3460 def : T2Pat<(and (ldaex_1 addr_offset_none:$addr), 0xff),
   3461             (t2LDAEXB addr_offset_none:$addr)>;
   3462 def : T2Pat<(and (ldaex_2 addr_offset_none:$addr), 0xffff),
   3463             (t2LDAEXH addr_offset_none:$addr)>;
   3464 def : T2Pat<(stlex_1 (and GPR:$Rt, 0xff), addr_offset_none:$addr),
   3465             (t2STLEXB GPR:$Rt, addr_offset_none:$addr)>;
   3466 def : T2Pat<(stlex_2 (and GPR:$Rt, 0xffff), addr_offset_none:$addr),
   3467             (t2STLEXH GPR:$Rt, addr_offset_none:$addr)>;
   3468 
   3469 //===----------------------------------------------------------------------===//
   3470 // SJLJ Exception handling intrinsics
   3471 //   eh_sjlj_setjmp() is an instruction sequence to store the return
   3472 //   address and save #0 in R0 for the non-longjmp case.
   3473 //   Since by its nature we may be coming from some other function to get
   3474 //   here, and we're using the stack frame for the containing function to
   3475 //   save/restore registers, we can't keep anything live in regs across
   3476 //   the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
   3477 //   when we get here from a longjmp(). We force everything out of registers
   3478 //   except for our own input by listing the relevant registers in Defs. By
   3479 //   doing so, we also cause the prologue/epilogue code to actively preserve
   3480 //   all of the callee-saved resgisters, which is exactly what we want.
   3481 //   $val is a scratch register for our use.
   3482 let Defs =
   3483   [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7,  R8,  R9,  R10, R11, R12, LR, CPSR,
   3484     Q0, Q1, Q2, Q3, Q8, Q9, Q10, Q11, Q12, Q13, Q14, Q15],
   3485   hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
   3486   usesCustomInserter = 1 in {
   3487   def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
   3488                                AddrModeNone, 0, NoItinerary, "", "",
   3489                           [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
   3490                              Requires<[IsThumb2, HasVFP2]>;
   3491 }
   3492 
   3493 let Defs =
   3494   [ R0,  R1,  R2,  R3,  R4,  R5,  R6,  R7,  R8,  R9,  R10, R11, R12, LR, CPSR ],
   3495   hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1,
   3496   usesCustomInserter = 1 in {
   3497   def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
   3498                                AddrModeNone, 0, NoItinerary, "", "",
   3499                           [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
   3500                                   Requires<[IsThumb2, NoVFP]>;
   3501 }
   3502 
   3503 
   3504 //===----------------------------------------------------------------------===//
   3505 // Control-Flow Instructions
   3506 //
   3507 
   3508 // FIXME: remove when we have a way to marking a MI with these properties.
   3509 // FIXME: Should pc be an implicit operand like PICADD, etc?
   3510 let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
   3511     hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
   3512 def t2LDMIA_RET: t2PseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
   3513                                                    reglist:$regs, variable_ops),
   3514                               4, IIC_iLoad_mBr, [],
   3515             (t2LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>,
   3516                          RegConstraint<"$Rn = $wb">;
   3517 
   3518 let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
   3519 let isPredicable = 1 in
   3520 def t2B   : T2I<(outs), (ins uncondbrtarget:$target), IIC_Br,
   3521                  "b", ".w\t$target",
   3522                  [(br bb:$target)]>, Sched<[WriteBr]> {
   3523   let Inst{31-27} = 0b11110;
   3524   let Inst{15-14} = 0b10;
   3525   let Inst{12} = 1;
   3526 
   3527   bits<24> target;
   3528   let Inst{26} = target{23};
   3529   let Inst{13} = target{22};
   3530   let Inst{11} = target{21};
   3531   let Inst{25-16} = target{20-11};
   3532   let Inst{10-0} = target{10-0};
   3533   let DecoderMethod = "DecodeT2BInstruction";
   3534   let AsmMatchConverter = "cvtThumbBranches";
   3535 }
   3536 
   3537 let Size = 4, isNotDuplicable = 1, isIndirectBranch = 1 in {
   3538 def t2BR_JT : t2PseudoInst<(outs),
   3539           (ins GPR:$target, GPR:$index, i32imm:$jt),
   3540            0, IIC_Br,
   3541           [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt)]>,
   3542           Sched<[WriteBr]>;
   3543 
   3544 // FIXME: Add a case that can be predicated.
   3545 def t2TBB_JT : t2PseudoInst<(outs),
   3546         (ins GPR:$base, GPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
   3547         Sched<[WriteBr]>;
   3548 
   3549 def t2TBH_JT : t2PseudoInst<(outs),
   3550         (ins GPR:$base, GPR:$index, i32imm:$jt, i32imm:$pclbl), 0, IIC_Br, []>,
   3551         Sched<[WriteBr]>;
   3552 
   3553 def t2TBB : T2I<(outs), (ins addrmode_tbb:$addr), IIC_Br,
   3554                     "tbb", "\t$addr", []>, Sched<[WriteBrTbl]> {
   3555   bits<4> Rn;
   3556   bits<4> Rm;
   3557   let Inst{31-20} = 0b111010001101;
   3558   let Inst{19-16} = Rn;
   3559   let Inst{15-5} = 0b11110000000;
   3560   let Inst{4} = 0; // B form
   3561   let Inst{3-0} = Rm;
   3562 
   3563   let DecoderMethod = "DecodeThumbTableBranch";
   3564 }
   3565 
   3566 def t2TBH : T2I<(outs), (ins addrmode_tbh:$addr), IIC_Br,
   3567                    "tbh", "\t$addr", []>, Sched<[WriteBrTbl]> {
   3568   bits<4> Rn;
   3569   bits<4> Rm;
   3570   let Inst{31-20} = 0b111010001101;
   3571   let Inst{19-16} = Rn;
   3572   let Inst{15-5} = 0b11110000000;
   3573   let Inst{4} = 1; // H form
   3574   let Inst{3-0} = Rm;
   3575 
   3576   let DecoderMethod = "DecodeThumbTableBranch";
   3577 }
   3578 } // isNotDuplicable, isIndirectBranch
   3579 
   3580 } // isBranch, isTerminator, isBarrier
   3581 
   3582 // FIXME: should be able to write a pattern for ARMBrcond, but can't use
   3583 // a two-value operand where a dag node expects ", "two operands. :(
   3584 let isBranch = 1, isTerminator = 1 in
   3585 def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
   3586                 "b", ".w\t$target",
   3587                 [/*(ARMbrcond bb:$target, imm:$cc)*/]>, Sched<[WriteBr]> {
   3588   let Inst{31-27} = 0b11110;
   3589   let Inst{15-14} = 0b10;
   3590   let Inst{12} = 0;
   3591 
   3592   bits<4> p;
   3593   let Inst{25-22} = p;
   3594 
   3595   bits<21> target;
   3596   let Inst{26} = target{20};
   3597   let Inst{11} = target{19};
   3598   let Inst{13} = target{18};
   3599   let Inst{21-16} = target{17-12};
   3600   let Inst{10-0} = target{11-1};
   3601 
   3602   let DecoderMethod = "DecodeThumb2BCCInstruction";
   3603   let AsmMatchConverter = "cvtThumbBranches";
   3604 }
   3605 
   3606 // Tail calls. The MachO version of thumb tail calls uses a t2 branch, so
   3607 // it goes here.
   3608 let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
   3609   // IOS version.
   3610   let Uses = [SP] in
   3611   def tTAILJMPd: tPseudoExpand<(outs),
   3612                    (ins uncondbrtarget:$dst, pred:$p),
   3613                    4, IIC_Br, [],
   3614                    (t2B uncondbrtarget:$dst, pred:$p)>,
   3615                  Requires<[IsThumb2, IsMachO]>, Sched<[WriteBr]>;
   3616 }
   3617 
   3618 // IT block
   3619 let Defs = [ITSTATE] in
   3620 def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
   3621                     AddrModeNone, 2,  IIC_iALUx,
   3622                     "it$mask\t$cc", "", []>,
   3623            ComplexDeprecationPredicate<"IT"> {
   3624   // 16-bit instruction.
   3625   let Inst{31-16} = 0x0000;
   3626   let Inst{15-8} = 0b10111111;
   3627 
   3628   bits<4> cc;
   3629   bits<4> mask;
   3630   let Inst{7-4} = cc;
   3631   let Inst{3-0} = mask;
   3632 
   3633   let DecoderMethod = "DecodeIT";
   3634 }
   3635 
   3636 // Branch and Exchange Jazelle -- for disassembly only
   3637 // Rm = Inst{19-16}
   3638 def t2BXJ : T2I<(outs), (ins GPRnopc:$func), NoItinerary, "bxj", "\t$func", []>,
   3639     Sched<[WriteBr]>, Requires<[IsThumb2, IsNotMClass]> {
   3640   bits<4> func;
   3641   let Inst{31-27} = 0b11110;
   3642   let Inst{26} = 0;
   3643   let Inst{25-20} = 0b111100;
   3644   let Inst{19-16} = func;
   3645   let Inst{15-0} = 0b1000111100000000;
   3646 }
   3647 
   3648 // Compare and branch on zero / non-zero
   3649 let isBranch = 1, isTerminator = 1 in {
   3650   def tCBZ  : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
   3651                   "cbz\t$Rn, $target", []>,
   3652               T1Misc<{0,0,?,1,?,?,?}>,
   3653               Requires<[IsThumb2]>, Sched<[WriteBr]> {
   3654     // A8.6.27
   3655     bits<6> target;
   3656     bits<3> Rn;
   3657     let Inst{9}   = target{5};
   3658     let Inst{7-3} = target{4-0};
   3659     let Inst{2-0} = Rn;
   3660   }
   3661 
   3662   def tCBNZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
   3663                   "cbnz\t$Rn, $target", []>,
   3664               T1Misc<{1,0,?,1,?,?,?}>,
   3665               Requires<[IsThumb2]>, Sched<[WriteBr]> {
   3666     // A8.6.27
   3667     bits<6> target;
   3668     bits<3> Rn;
   3669     let Inst{9}   = target{5};
   3670     let Inst{7-3} = target{4-0};
   3671     let Inst{2-0} = Rn;
   3672   }
   3673 }
   3674 
   3675 
   3676 // Change Processor State is a system instruction.
   3677 // FIXME: Since the asm parser has currently no clean way to handle optional
   3678 // operands, create 3 versions of the same instruction. Once there's a clean
   3679 // framework to represent optional operands, change this behavior.
   3680 class t2CPS<dag iops, string asm_op> : T2XI<(outs), iops, NoItinerary,
   3681             !strconcat("cps", asm_op), []>,
   3682           Requires<[IsThumb2, IsNotMClass]> {
   3683   bits<2> imod;
   3684   bits<3> iflags;
   3685   bits<5> mode;
   3686   bit M;
   3687 
   3688   let Inst{31-11} = 0b111100111010111110000;
   3689   let Inst{10-9}  = imod;
   3690   let Inst{8}     = M;
   3691   let Inst{7-5}   = iflags;
   3692   let Inst{4-0}   = mode;
   3693   let DecoderMethod = "DecodeT2CPSInstruction";
   3694 }
   3695 
   3696 let M = 1 in
   3697   def t2CPS3p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags, i32imm:$mode),
   3698                       "$imod\t$iflags, $mode">;
   3699 let mode = 0, M = 0 in
   3700   def t2CPS2p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags),
   3701                       "$imod.w\t$iflags">;
   3702 let imod = 0, iflags = 0, M = 1 in
   3703   def t2CPS1p : t2CPS<(ins imm0_31:$mode), "\t$mode">;
   3704 
   3705 def : t2InstAlias<"cps$imod.w $iflags, $mode",
   3706                    (t2CPS3p imod_op:$imod, iflags_op:$iflags, i32imm:$mode), 0>;
   3707 def : t2InstAlias<"cps.w $mode", (t2CPS1p imm0_31:$mode), 0>;
   3708 
   3709 // A6.3.4 Branches and miscellaneous control
   3710 // Table A6-14 Change Processor State, and hint instructions
   3711 def t2HINT : T2I<(outs), (ins imm0_239:$imm), NoItinerary, "hint", ".w\t$imm",
   3712                   [(int_arm_hint imm0_239:$imm)]> {
   3713   bits<8> imm;
   3714   let Inst{31-3} = 0b11110011101011111000000000000;
   3715   let Inst{7-0} = imm;
   3716 }
   3717 
   3718 def : t2InstAlias<"hint$p $imm", (t2HINT imm0_239:$imm, pred:$p)>;
   3719 def : t2InstAlias<"nop$p.w", (t2HINT 0, pred:$p)>;
   3720 def : t2InstAlias<"yield$p.w", (t2HINT 1, pred:$p)>;
   3721 def : t2InstAlias<"wfe$p.w", (t2HINT 2, pred:$p)>;
   3722 def : t2InstAlias<"wfi$p.w", (t2HINT 3, pred:$p)>;
   3723 def : t2InstAlias<"sev$p.w", (t2HINT 4, pred:$p)>;
   3724 def : t2InstAlias<"sevl$p.w", (t2HINT 5, pred:$p)> {
   3725   let Predicates = [IsThumb2, HasV8];
   3726 }
   3727 
   3728 def t2DBG : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "dbg", "\t$opt",
   3729                 [(int_arm_dbg imm0_15:$opt)]> {
   3730   bits<4> opt;
   3731   let Inst{31-20} = 0b111100111010;
   3732   let Inst{19-16} = 0b1111;
   3733   let Inst{15-8} = 0b10000000;
   3734   let Inst{7-4} = 0b1111;
   3735   let Inst{3-0} = opt;
   3736 }
   3737 
   3738 // Secure Monitor Call is a system instruction.
   3739 // Option = Inst{19-16}
   3740 def t2SMC : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt",
   3741                 []>, Requires<[IsThumb2, HasTrustZone]> {
   3742   let Inst{31-27} = 0b11110;
   3743   let Inst{26-20} = 0b1111111;
   3744   let Inst{15-12} = 0b1000;
   3745 
   3746   bits<4> opt;
   3747   let Inst{19-16} = opt;
   3748 }
   3749 
   3750 class T2DCPS<bits<2> opt, string opc>
   3751   : T2I<(outs), (ins), NoItinerary, opc, "", []>, Requires<[IsThumb2, HasV8]> {
   3752   let Inst{31-27} = 0b11110;
   3753   let Inst{26-20} = 0b1111000;
   3754   let Inst{19-16} = 0b1111;
   3755   let Inst{15-12} = 0b1000;
   3756   let Inst{11-2} = 0b0000000000;
   3757   let Inst{1-0} = opt;
   3758 }
   3759 
   3760 def t2DCPS1 : T2DCPS<0b01, "dcps1">;
   3761 def t2DCPS2 : T2DCPS<0b10, "dcps2">;
   3762 def t2DCPS3 : T2DCPS<0b11, "dcps3">;
   3763 
   3764 class T2SRS<bits<2> Op, bit W, dag oops, dag iops, InstrItinClass itin,
   3765             string opc, string asm, list<dag> pattern>
   3766   : T2I<oops, iops, itin, opc, asm, pattern>,
   3767     Requires<[IsThumb2,IsNotMClass]> {
   3768   bits<5> mode;
   3769   let Inst{31-25} = 0b1110100;
   3770   let Inst{24-23} = Op;
   3771   let Inst{22} = 0;
   3772   let Inst{21} = W;
   3773   let Inst{20-16} = 0b01101;
   3774   let Inst{15-5} = 0b11000000000;
   3775   let Inst{4-0} = mode{4-0};
   3776 }
   3777 
   3778 // Store Return State is a system instruction.
   3779 def t2SRSDB_UPD : T2SRS<0b00, 1, (outs), (ins imm0_31:$mode), NoItinerary,
   3780                         "srsdb", "\tsp!, $mode", []>;
   3781 def t2SRSDB  : T2SRS<0b00, 0, (outs), (ins imm0_31:$mode), NoItinerary,
   3782                      "srsdb","\tsp, $mode", []>;
   3783 def t2SRSIA_UPD : T2SRS<0b11, 1, (outs), (ins imm0_31:$mode), NoItinerary,
   3784                         "srsia","\tsp!, $mode", []>;
   3785 def t2SRSIA  : T2SRS<0b11, 0, (outs), (ins imm0_31:$mode), NoItinerary,
   3786                      "srsia","\tsp, $mode", []>;
   3787 
   3788 
   3789 def : t2InstAlias<"srsdb${p} $mode", (t2SRSDB imm0_31:$mode, pred:$p)>;
   3790 def : t2InstAlias<"srsdb${p} $mode!", (t2SRSDB_UPD imm0_31:$mode, pred:$p)>;
   3791 
   3792 def : t2InstAlias<"srsia${p} $mode", (t2SRSIA imm0_31:$mode, pred:$p)>;
   3793 def : t2InstAlias<"srsia${p} $mode!", (t2SRSIA_UPD imm0_31:$mode, pred:$p)>;
   3794 
   3795 // Return From Exception is a system instruction.
   3796 class T2RFE<bits<12> op31_20, dag oops, dag iops, InstrItinClass itin,
   3797           string opc, string asm, list<dag> pattern>
   3798   : T2I<oops, iops, itin, opc, asm, pattern>,
   3799     Requires<[IsThumb2,IsNotMClass]> {
   3800   let Inst{31-20} = op31_20{11-0};
   3801 
   3802   bits<4> Rn;
   3803   let Inst{19-16} = Rn;
   3804   let Inst{15-0} = 0xc000;
   3805 }
   3806 
   3807 def t2RFEDBW : T2RFE<0b111010000011,
   3808                    (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn!",
   3809                    [/* For disassembly only; pattern left blank */]>;
   3810 def t2RFEDB  : T2RFE<0b111010000001,
   3811                    (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn",
   3812                    [/* For disassembly only; pattern left blank */]>;
   3813 def t2RFEIAW : T2RFE<0b111010011011,
   3814                    (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn!",
   3815                    [/* For disassembly only; pattern left blank */]>;
   3816 def t2RFEIA  : T2RFE<0b111010011001,
   3817                    (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn",
   3818                    [/* For disassembly only; pattern left blank */]>;
   3819 
   3820 // B9.3.19 SUBS PC, LR, #imm (Thumb2) system instruction.
   3821 // Exception return instruction is "subs pc, lr, #imm".
   3822 let isReturn = 1, isBarrier = 1, isTerminator = 1, Defs = [PC] in
   3823 def t2SUBS_PC_LR : T2I <(outs), (ins imm0_255:$imm), NoItinerary,
   3824                         "subs", "\tpc, lr, $imm",
   3825                         [(ARMintretflag imm0_255:$imm)]>,
   3826                    Requires<[IsThumb2,IsNotMClass]> {
   3827   let Inst{31-8} = 0b111100111101111010001111;
   3828 
   3829   bits<8> imm;
   3830   let Inst{7-0} = imm;
   3831 }
   3832 
   3833 // Hypervisor Call is a system instruction.
   3834 let isCall = 1 in {
   3835 def t2HVC : T2XI <(outs), (ins imm0_65535:$imm16), IIC_Br, "hvc.w\t$imm16", []>,
   3836       Requires<[IsThumb2, HasVirtualization]>, Sched<[WriteBr]> {
   3837     bits<16> imm16;
   3838     let Inst{31-20} = 0b111101111110;
   3839     let Inst{19-16} = imm16{15-12};
   3840     let Inst{15-12} = 0b1000;
   3841     let Inst{11-0} = imm16{11-0};
   3842 }
   3843 }
   3844 
   3845 // Alias for HVC without the ".w" optional width specifier
   3846 def : t2InstAlias<"hvc\t$imm16", (t2HVC imm0_65535:$imm16)>;
   3847 
   3848 // ERET - Return from exception in Hypervisor mode.
   3849 // B9.3.3, B9.3.20: ERET is an alias for "SUBS PC, LR, #0" in an implementation that
   3850 // includes virtualization extensions.
   3851 def t2ERET : InstAlias<"eret${p}", (t2SUBS_PC_LR 0, pred:$p)>,
   3852              Requires<[IsThumb2, HasVirtualization]>;
   3853 
   3854 //===----------------------------------------------------------------------===//
   3855 // Non-Instruction Patterns
   3856 //
   3857 
   3858 // 32-bit immediate using movw + movt.
   3859 // This is a single pseudo instruction to make it re-materializable.
   3860 // FIXME: Remove this when we can do generalized remat.
   3861 let isReMaterializable = 1, isMoveImm = 1 in
   3862 def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
   3863                             [(set rGPR:$dst, (i32 imm:$src))]>,
   3864                             Requires<[IsThumb, UseMovt]>;
   3865 
   3866 // Pseudo instruction that combines movw + movt + add pc (if pic).
   3867 // It also makes it possible to rematerialize the instructions.
   3868 // FIXME: Remove this when we can do generalized remat and when machine licm
   3869 // can properly the instructions.
   3870 let isReMaterializable = 1 in {
   3871 def t2MOV_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
   3872                                 IIC_iMOVix2addpc,
   3873                           [(set rGPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
   3874                           Requires<[IsThumb2, UseMovt]>;
   3875 
   3876 }
   3877 
   3878 // ConstantPool, GlobalAddress, and JumpTable
   3879 def : T2Pat<(ARMWrapper  tconstpool  :$dst), (t2LEApcrel tconstpool  :$dst)>;
   3880 def : T2Pat<(ARMWrapper  tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
   3881            Requires<[IsThumb2, UseMovt]>;
   3882 
   3883 def : T2Pat<(ARMWrapperJT tjumptable:$dst),
   3884             (t2LEApcrelJT tjumptable:$dst)>;
   3885 
   3886 // Pseudo instruction that combines ldr from constpool and add pc. This should
   3887 // be expanded into two instructions late to allow if-conversion and
   3888 // scheduling.
   3889 let canFoldAsLoad = 1, isReMaterializable = 1 in
   3890 def t2LDRpci_pic : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr, pclabel:$cp),
   3891                    IIC_iLoadiALU,
   3892               [(set rGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
   3893                                            imm:$cp))]>,
   3894                Requires<[IsThumb2]>;
   3895 
   3896 // Pseudo isntruction that combines movs + predicated rsbmi
   3897 // to implement integer ABS
   3898 let usesCustomInserter = 1, Defs = [CPSR] in {
   3899 def t2ABS : PseudoInst<(outs rGPR:$dst), (ins rGPR:$src),
   3900                        NoItinerary, []>, Requires<[IsThumb2]>;
   3901 }
   3902 
   3903 //===----------------------------------------------------------------------===//
   3904 // Coprocessor load/store -- for disassembly only
   3905 //
   3906 class T2CI<bits<4> op31_28, dag oops, dag iops, string opc, string asm>
   3907   : T2I<oops, iops, NoItinerary, opc, asm, []> {
   3908   let Inst{31-28} = op31_28;
   3909   let Inst{27-25} = 0b110;
   3910 }
   3911 
   3912 multiclass t2LdStCop<bits<4> op31_28, bit load, bit Dbit, string asm> {
   3913   def _OFFSET : T2CI<op31_28,
   3914                      (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5:$addr),
   3915                      asm, "\t$cop, $CRd, $addr"> {
   3916     bits<13> addr;
   3917     bits<4> cop;
   3918     bits<4> CRd;
   3919     let Inst{24} = 1; // P = 1
   3920     let Inst{23} = addr{8};
   3921     let Inst{22} = Dbit;
   3922     let Inst{21} = 0; // W = 0
   3923     let Inst{20} = load;
   3924     let Inst{19-16} = addr{12-9};
   3925     let Inst{15-12} = CRd;
   3926     let Inst{11-8} = cop;
   3927     let Inst{7-0} = addr{7-0};
   3928     let DecoderMethod = "DecodeCopMemInstruction";
   3929   }
   3930   def _PRE : T2CI<op31_28,
   3931                   (outs), (ins p_imm:$cop, c_imm:$CRd, addrmode5_pre:$addr),
   3932                   asm, "\t$cop, $CRd, $addr!"> {
   3933     bits<13> addr;
   3934     bits<4> cop;
   3935     bits<4> CRd;
   3936     let Inst{24} = 1; // P = 1
   3937     let Inst{23} = addr{8};
   3938     let Inst{22} = Dbit;
   3939     let Inst{21} = 1; // W = 1
   3940     let Inst{20} = load;
   3941     let Inst{19-16} = addr{12-9};
   3942     let Inst{15-12} = CRd;
   3943     let Inst{11-8} = cop;
   3944     let Inst{7-0} = addr{7-0};
   3945     let DecoderMethod = "DecodeCopMemInstruction";
   3946   }
   3947   def _POST: T2CI<op31_28,
   3948                   (outs), (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
   3949                                postidx_imm8s4:$offset),
   3950                  asm, "\t$cop, $CRd, $addr, $offset"> {
   3951     bits<9> offset;
   3952     bits<4> addr;
   3953     bits<4> cop;
   3954     bits<4> CRd;
   3955     let Inst{24} = 0; // P = 0
   3956     let Inst{23} = offset{8};
   3957     let Inst{22} = Dbit;
   3958     let Inst{21} = 1; // W = 1
   3959     let Inst{20} = load;
   3960     let Inst{19-16} = addr;
   3961     let Inst{15-12} = CRd;
   3962     let Inst{11-8} = cop;
   3963     let Inst{7-0} = offset{7-0};
   3964     let DecoderMethod = "DecodeCopMemInstruction";
   3965   }
   3966   def _OPTION : T2CI<op31_28, (outs),
   3967                      (ins p_imm:$cop, c_imm:$CRd, addr_offset_none:$addr,
   3968                           coproc_option_imm:$option),
   3969       asm, "\t$cop, $CRd, $addr, $option"> {
   3970     bits<8> option;
   3971     bits<4> addr;
   3972     bits<4> cop;
   3973     bits<4> CRd;
   3974     let Inst{24} = 0; // P = 0
   3975     let Inst{23} = 1; // U = 1
   3976     let Inst{22} = Dbit;
   3977     let Inst{21} = 0; // W = 0
   3978     let Inst{20} = load;
   3979     let Inst{19-16} = addr;
   3980     let Inst{15-12} = CRd;
   3981     let Inst{11-8} = cop;
   3982     let Inst{7-0} = option;
   3983     let DecoderMethod = "DecodeCopMemInstruction";
   3984   }
   3985 }
   3986 
   3987 defm t2LDC   : t2LdStCop<0b1110, 1, 0, "ldc">;
   3988 defm t2LDCL  : t2LdStCop<0b1110, 1, 1, "ldcl">;
   3989 defm t2STC   : t2LdStCop<0b1110, 0, 0, "stc">;
   3990 defm t2STCL  : t2LdStCop<0b1110, 0, 1, "stcl">;
   3991 defm t2LDC2  : t2LdStCop<0b1111, 1, 0, "ldc2">, Requires<[PreV8,IsThumb2]>;
   3992 defm t2LDC2L : t2LdStCop<0b1111, 1, 1, "ldc2l">, Requires<[PreV8,IsThumb2]>;
   3993 defm t2STC2  : t2LdStCop<0b1111, 0, 0, "stc2">, Requires<[PreV8,IsThumb2]>;
   3994 defm t2STC2L : t2LdStCop<0b1111, 0, 1, "stc2l">, Requires<[PreV8,IsThumb2]>;
   3995 
   3996 
   3997 //===----------------------------------------------------------------------===//
   3998 // Move between special register and ARM core register -- for disassembly only
   3999 //
   4000 // Move to ARM core register from Special Register
   4001 
   4002 // A/R class MRS.
   4003 //
   4004 // A/R class can only move from CPSR or SPSR.
   4005 def t2MRS_AR : T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, apsr",
   4006                   []>, Requires<[IsThumb2,IsNotMClass]> {
   4007   bits<4> Rd;
   4008   let Inst{31-12} = 0b11110011111011111000;
   4009   let Inst{11-8} = Rd;
   4010   let Inst{7-0} = 0b00000000;
   4011 }
   4012 
   4013 def : t2InstAlias<"mrs${p} $Rd, cpsr", (t2MRS_AR GPR:$Rd, pred:$p)>;
   4014 
   4015 def t2MRSsys_AR: T2I<(outs GPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, spsr",
   4016                    []>, Requires<[IsThumb2,IsNotMClass]> {
   4017   bits<4> Rd;
   4018   let Inst{31-12} = 0b11110011111111111000;
   4019   let Inst{11-8} = Rd;
   4020   let Inst{7-0} = 0b00000000;
   4021 }
   4022 
   4023 def t2MRSbanked : T2I<(outs rGPR:$Rd), (ins banked_reg:$banked),
   4024                       NoItinerary, "mrs", "\t$Rd, $banked", []>,
   4025                   Requires<[IsThumb, HasVirtualization]> {
   4026   bits<6> banked;
   4027   bits<4> Rd;
   4028 
   4029   let Inst{31-21} = 0b11110011111;
   4030   let Inst{20} = banked{5}; // R bit
   4031   let Inst{19-16} = banked{3-0};
   4032   let Inst{15-12} = 0b1000;
   4033   let Inst{11-8} = Rd;
   4034   let Inst{7-5} = 0b001;
   4035   let Inst{4} = banked{4};
   4036   let Inst{3-0} = 0b0000;
   4037 }
   4038 
   4039 
   4040 // M class MRS.
   4041 //
   4042 // This MRS has a mask field in bits 7-0 and can take more values than
   4043 // the A/R class (a full msr_mask).
   4044 def t2MRS_M : T2I<(outs rGPR:$Rd), (ins msr_mask:$SYSm), NoItinerary,
   4045                   "mrs", "\t$Rd, $SYSm", []>,
   4046               Requires<[IsThumb,IsMClass]> {
   4047   bits<4> Rd;
   4048   bits<8> SYSm;
   4049   let Inst{31-12} = 0b11110011111011111000;
   4050   let Inst{11-8} = Rd;
   4051   let Inst{7-0} = SYSm;
   4052 
   4053   let Unpredictable{20-16} = 0b11111;
   4054   let Unpredictable{13} = 0b1;
   4055 }
   4056 
   4057 
   4058 // Move from ARM core register to Special Register
   4059 //
   4060 // A/R class MSR.
   4061 //
   4062 // No need to have both system and application versions, the encodings are the
   4063 // same and the assembly parser has no way to distinguish between them. The mask
   4064 // operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
   4065 // the mask with the fields to be accessed in the special register.
   4066 def t2MSR_AR : T2I<(outs), (ins msr_mask:$mask, rGPR:$Rn),
   4067                    NoItinerary, "msr", "\t$mask, $Rn", []>,
   4068                Requires<[IsThumb2,IsNotMClass]> {
   4069   bits<5> mask;
   4070   bits<4> Rn;
   4071   let Inst{31-21} = 0b11110011100;
   4072   let Inst{20}    = mask{4}; // R Bit
   4073   let Inst{19-16} = Rn;
   4074   let Inst{15-12} = 0b1000;
   4075   let Inst{11-8}  = mask{3-0};
   4076   let Inst{7-0}   = 0;
   4077 }
   4078 
   4079 // However, the MSR (banked register) system instruction (ARMv7VE) *does* have a
   4080 // separate encoding (distinguished by bit 5.
   4081 def t2MSRbanked : T2I<(outs), (ins banked_reg:$banked, rGPR:$Rn),
   4082                       NoItinerary, "msr", "\t$banked, $Rn", []>,
   4083                   Requires<[IsThumb, HasVirtualization]> {
   4084   bits<6> banked;
   4085   bits<4> Rn;
   4086 
   4087   let Inst{31-21} = 0b11110011100;
   4088   let Inst{20} = banked{5}; // R bit
   4089   let Inst{19-16} = Rn;
   4090   let Inst{15-12} = 0b1000;
   4091   let Inst{11-8} = banked{3-0};
   4092   let Inst{7-5} = 0b001;
   4093   let Inst{4} = banked{4};
   4094   let Inst{3-0} = 0b0000;
   4095 }
   4096 
   4097 
   4098 // M class MSR.
   4099 //
   4100 // Move from ARM core register to Special Register
   4101 def t2MSR_M : T2I<(outs), (ins msr_mask:$SYSm, rGPR:$Rn),
   4102                   NoItinerary, "msr", "\t$SYSm, $Rn", []>,
   4103               Requires<[IsThumb,IsMClass]> {
   4104   bits<12> SYSm;
   4105   bits<4> Rn;
   4106   let Inst{31-21} = 0b11110011100;
   4107   let Inst{20}    = 0b0;
   4108   let Inst{19-16} = Rn;
   4109   let Inst{15-12} = 0b1000;
   4110   let Inst{11-10} = SYSm{11-10};
   4111   let Inst{9-8}   = 0b00;
   4112   let Inst{7-0}   = SYSm{7-0};
   4113 
   4114   let Unpredictable{20} = 0b1;
   4115   let Unpredictable{13} = 0b1;
   4116   let Unpredictable{9-8} = 0b11;
   4117 }
   4118 
   4119 
   4120 //===----------------------------------------------------------------------===//
   4121 // Move between coprocessor and ARM core register
   4122 //
   4123 
   4124 class t2MovRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
   4125                   list<dag> pattern>
   4126   : T2Cop<Op, oops, iops, opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2",
   4127           pattern> {
   4128   let Inst{27-24} = 0b1110;
   4129   let Inst{20} = direction;
   4130   let Inst{4} = 1;
   4131 
   4132   bits<4> Rt;
   4133   bits<4> cop;
   4134   bits<3> opc1;
   4135   bits<3> opc2;
   4136   bits<4> CRm;
   4137   bits<4> CRn;
   4138 
   4139   let Inst{15-12} = Rt;
   4140   let Inst{11-8}  = cop;
   4141   let Inst{23-21} = opc1;
   4142   let Inst{7-5}   = opc2;
   4143   let Inst{3-0}   = CRm;
   4144   let Inst{19-16} = CRn;
   4145 }
   4146 
   4147 class t2MovRRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
   4148                    list<dag> pattern = []>
   4149   : T2Cop<Op, oops, iops, opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm", pattern> {
   4150   let Inst{27-24} = 0b1100;
   4151   let Inst{23-21} = 0b010;
   4152   let Inst{20} = direction;
   4153 
   4154   bits<4> Rt;
   4155   bits<4> Rt2;
   4156   bits<4> cop;
   4157   bits<4> opc1;
   4158   bits<4> CRm;
   4159 
   4160   let Inst{15-12} = Rt;
   4161   let Inst{19-16} = Rt2;
   4162   let Inst{11-8}  = cop;
   4163   let Inst{7-4}   = opc1;
   4164   let Inst{3-0}   = CRm;
   4165 }
   4166 
   4167 /* from ARM core register to coprocessor */
   4168 def t2MCR : t2MovRCopro<0b1110, "mcr", 0,
   4169            (outs),
   4170            (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
   4171                 c_imm:$CRm, imm0_7:$opc2),
   4172            [(int_arm_mcr imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
   4173                          imm:$CRm, imm:$opc2)]>,
   4174            ComplexDeprecationPredicate<"MCR">;
   4175 def : t2InstAlias<"mcr${p} $cop, $opc1, $Rt, $CRn, $CRm",
   4176                   (t2MCR p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
   4177                          c_imm:$CRm, 0, pred:$p)>;
   4178 def t2MCR2 : t2MovRCopro<0b1111, "mcr2", 0,
   4179              (outs), (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
   4180                           c_imm:$CRm, imm0_7:$opc2),
   4181              [(int_arm_mcr2 imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
   4182                             imm:$CRm, imm:$opc2)]> {
   4183   let Predicates = [IsThumb2, PreV8];
   4184 }
   4185 def : t2InstAlias<"mcr2${p} $cop, $opc1, $Rt, $CRn, $CRm",
   4186                   (t2MCR2 p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
   4187                           c_imm:$CRm, 0, pred:$p)>;
   4188 
   4189 /* from coprocessor to ARM core register */
   4190 def t2MRC : t2MovRCopro<0b1110, "mrc", 1,
   4191              (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
   4192                                   c_imm:$CRm, imm0_7:$opc2), []>;
   4193 def : t2InstAlias<"mrc${p} $cop, $opc1, $Rt, $CRn, $CRm",
   4194                   (t2MRC GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
   4195                          c_imm:$CRm, 0, pred:$p)>;
   4196 
   4197 def t2MRC2 : t2MovRCopro<0b1111, "mrc2", 1,
   4198              (outs GPRwithAPSR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
   4199                                   c_imm:$CRm, imm0_7:$opc2), []> {
   4200   let Predicates = [IsThumb2, PreV8];
   4201 }
   4202 def : t2InstAlias<"mrc2${p} $cop, $opc1, $Rt, $CRn, $CRm",
   4203                   (t2MRC2 GPRwithAPSR:$Rt, p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
   4204                           c_imm:$CRm, 0, pred:$p)>;
   4205 
   4206 def : T2v6Pat<(int_arm_mrc  imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
   4207               (t2MRC imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
   4208 
   4209 def : T2v6Pat<(int_arm_mrc2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
   4210               (t2MRC2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
   4211 
   4212 
   4213 /* from ARM core register to coprocessor */
   4214 def t2MCRR : t2MovRRCopro<0b1110, "mcrr", 0, (outs),
   4215                          (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2,
   4216                          c_imm:$CRm),
   4217                         [(int_arm_mcrr imm:$cop, imm:$opc1, GPR:$Rt, GPR:$Rt2,
   4218                                        imm:$CRm)]>;
   4219 def t2MCRR2 : t2MovRRCopro<0b1111, "mcrr2", 0, (outs),
   4220                           (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2,
   4221                            c_imm:$CRm),
   4222                           [(int_arm_mcrr2 imm:$cop, imm:$opc1, GPR:$Rt,
   4223                                           GPR:$Rt2, imm:$CRm)]> {
   4224   let Predicates = [IsThumb2, PreV8];
   4225 }
   4226 
   4227 /* from coprocessor to ARM core register */
   4228 def t2MRRC : t2MovRRCopro<0b1110, "mrrc", 1, (outs GPR:$Rt, GPR:$Rt2),
   4229                           (ins p_imm:$cop, imm0_15:$opc1, c_imm:$CRm)>;
   4230 
   4231 def t2MRRC2 : t2MovRRCopro<0b1111, "mrrc2", 1, (outs GPR:$Rt, GPR:$Rt2),
   4232                            (ins p_imm:$cop, imm0_15:$opc1, c_imm:$CRm)> {
   4233   let Predicates = [IsThumb2, PreV8];
   4234 }
   4235 
   4236 //===----------------------------------------------------------------------===//
   4237 // Other Coprocessor Instructions.
   4238 //
   4239 
   4240 def t2CDP : T2Cop<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
   4241                  c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
   4242                  "cdp", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
   4243                  [(int_arm_cdp imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
   4244                                imm:$CRm, imm:$opc2)]> {
   4245   let Inst{27-24} = 0b1110;
   4246 
   4247   bits<4> opc1;
   4248   bits<4> CRn;
   4249   bits<4> CRd;
   4250   bits<4> cop;
   4251   bits<3> opc2;
   4252   bits<4> CRm;
   4253 
   4254   let Inst{3-0}   = CRm;
   4255   let Inst{4}     = 0;
   4256   let Inst{7-5}   = opc2;
   4257   let Inst{11-8}  = cop;
   4258   let Inst{15-12} = CRd;
   4259   let Inst{19-16} = CRn;
   4260   let Inst{23-20} = opc1;
   4261 
   4262   let Predicates = [IsThumb2, PreV8];
   4263 }
   4264 
   4265 def t2CDP2 : T2Cop<0b1111, (outs), (ins p_imm:$cop, imm0_15:$opc1,
   4266                    c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
   4267                    "cdp2", "\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
   4268                    [(int_arm_cdp2 imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
   4269                                   imm:$CRm, imm:$opc2)]> {
   4270   let Inst{27-24} = 0b1110;
   4271 
   4272   bits<4> opc1;
   4273   bits<4> CRn;
   4274   bits<4> CRd;
   4275   bits<4> cop;
   4276   bits<3> opc2;
   4277   bits<4> CRm;
   4278 
   4279   let Inst{3-0}   = CRm;
   4280   let Inst{4}     = 0;
   4281   let Inst{7-5}   = opc2;
   4282   let Inst{11-8}  = cop;
   4283   let Inst{15-12} = CRd;
   4284   let Inst{19-16} = CRn;
   4285   let Inst{23-20} = opc1;
   4286 
   4287   let Predicates = [IsThumb2, PreV8];
   4288 }
   4289 
   4290 
   4291 
   4292 //===----------------------------------------------------------------------===//
   4293 // ARMv8.1 Privilege Access Never extension
   4294 //
   4295 // SETPAN #imm1
   4296 
   4297 def t2SETPAN : T1I<(outs), (ins imm0_1:$imm), NoItinerary, "setpan\t$imm", []>,
   4298                T1Misc<0b0110000>, Requires<[IsThumb2, HasV8, HasV8_1a]> {
   4299   bits<1> imm;
   4300 
   4301   let Inst{4} = 0b1;
   4302   let Inst{3} = imm;
   4303   let Inst{2-0} = 0b000;
   4304 
   4305   let Unpredictable{4} = 0b1;
   4306   let Unpredictable{2-0} = 0b111;
   4307 }
   4308 
   4309 //===----------------------------------------------------------------------===//
   4310 // Non-Instruction Patterns
   4311 //
   4312 
   4313 // SXT/UXT with no rotate
   4314 let AddedComplexity = 16 in {
   4315 def : T2Pat<(and rGPR:$Rm, 0x000000FF), (t2UXTB rGPR:$Rm, 0)>,
   4316            Requires<[IsThumb2]>;
   4317 def : T2Pat<(and rGPR:$Rm, 0x0000FFFF), (t2UXTH rGPR:$Rm, 0)>,
   4318            Requires<[IsThumb2]>;
   4319 def : T2Pat<(and rGPR:$Rm, 0x00FF00FF), (t2UXTB16 rGPR:$Rm, 0)>,
   4320            Requires<[HasT2ExtractPack, IsThumb2]>;
   4321 def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0x00FF)),
   4322             (t2UXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
   4323            Requires<[HasT2ExtractPack, IsThumb2]>;
   4324 def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0xFFFF)),
   4325             (t2UXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
   4326            Requires<[HasT2ExtractPack, IsThumb2]>;
   4327 }
   4328 
   4329 def : T2Pat<(sext_inreg rGPR:$Src, i8),  (t2SXTB rGPR:$Src, 0)>,
   4330            Requires<[IsThumb2]>;
   4331 def : T2Pat<(sext_inreg rGPR:$Src, i16), (t2SXTH rGPR:$Src, 0)>,
   4332            Requires<[IsThumb2]>;
   4333 def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i8)),
   4334             (t2SXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
   4335            Requires<[HasT2ExtractPack, IsThumb2]>;
   4336 def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i16)),
   4337             (t2SXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
   4338            Requires<[HasT2ExtractPack, IsThumb2]>;
   4339 
   4340 // Atomic load/store patterns
   4341 def : T2Pat<(atomic_load_8   t2addrmode_imm12:$addr),
   4342             (t2LDRBi12  t2addrmode_imm12:$addr)>;
   4343 def : T2Pat<(atomic_load_8   t2addrmode_negimm8:$addr),
   4344             (t2LDRBi8   t2addrmode_negimm8:$addr)>;
   4345 def : T2Pat<(atomic_load_8   t2addrmode_so_reg:$addr),
   4346             (t2LDRBs    t2addrmode_so_reg:$addr)>;
   4347 def : T2Pat<(atomic_load_16  t2addrmode_imm12:$addr),
   4348             (t2LDRHi12  t2addrmode_imm12:$addr)>;
   4349 def : T2Pat<(atomic_load_16  t2addrmode_negimm8:$addr),
   4350             (t2LDRHi8   t2addrmode_negimm8:$addr)>;
   4351 def : T2Pat<(atomic_load_16  t2addrmode_so_reg:$addr),
   4352             (t2LDRHs    t2addrmode_so_reg:$addr)>;
   4353 def : T2Pat<(atomic_load_32  t2addrmode_imm12:$addr),
   4354             (t2LDRi12   t2addrmode_imm12:$addr)>;
   4355 def : T2Pat<(atomic_load_32  t2addrmode_negimm8:$addr),
   4356             (t2LDRi8    t2addrmode_negimm8:$addr)>;
   4357 def : T2Pat<(atomic_load_32  t2addrmode_so_reg:$addr),
   4358             (t2LDRs     t2addrmode_so_reg:$addr)>;
   4359 def : T2Pat<(atomic_store_8  t2addrmode_imm12:$addr, GPR:$val),
   4360             (t2STRBi12  GPR:$val, t2addrmode_imm12:$addr)>;
   4361 def : T2Pat<(atomic_store_8  t2addrmode_negimm8:$addr, GPR:$val),
   4362             (t2STRBi8   GPR:$val, t2addrmode_negimm8:$addr)>;
   4363 def : T2Pat<(atomic_store_8  t2addrmode_so_reg:$addr, GPR:$val),
   4364             (t2STRBs    GPR:$val, t2addrmode_so_reg:$addr)>;
   4365 def : T2Pat<(atomic_store_16 t2addrmode_imm12:$addr, GPR:$val),
   4366             (t2STRHi12  GPR:$val, t2addrmode_imm12:$addr)>;
   4367 def : T2Pat<(atomic_store_16 t2addrmode_negimm8:$addr, GPR:$val),
   4368             (t2STRHi8   GPR:$val, t2addrmode_negimm8:$addr)>;
   4369 def : T2Pat<(atomic_store_16 t2addrmode_so_reg:$addr, GPR:$val),
   4370             (t2STRHs    GPR:$val, t2addrmode_so_reg:$addr)>;
   4371 def : T2Pat<(atomic_store_32 t2addrmode_imm12:$addr, GPR:$val),
   4372             (t2STRi12   GPR:$val, t2addrmode_imm12:$addr)>;
   4373 def : T2Pat<(atomic_store_32 t2addrmode_negimm8:$addr, GPR:$val),
   4374             (t2STRi8    GPR:$val, t2addrmode_negimm8:$addr)>;
   4375 def : T2Pat<(atomic_store_32 t2addrmode_so_reg:$addr, GPR:$val),
   4376             (t2STRs     GPR:$val, t2addrmode_so_reg:$addr)>;
   4377 
   4378 let AddedComplexity = 8 in {
   4379   def : T2Pat<(atomic_load_acquire_8 addr_offset_none:$addr),  (t2LDAB addr_offset_none:$addr)>;
   4380   def : T2Pat<(atomic_load_acquire_16 addr_offset_none:$addr), (t2LDAH addr_offset_none:$addr)>;
   4381   def : T2Pat<(atomic_load_acquire_32 addr_offset_none:$addr), (t2LDA  addr_offset_none:$addr)>;
   4382   def : T2Pat<(atomic_store_release_8 addr_offset_none:$addr, GPR:$val),  (t2STLB GPR:$val, addr_offset_none:$addr)>;
   4383   def : T2Pat<(atomic_store_release_16 addr_offset_none:$addr, GPR:$val), (t2STLH GPR:$val, addr_offset_none:$addr)>;
   4384   def : T2Pat<(atomic_store_release_32 addr_offset_none:$addr, GPR:$val), (t2STL  GPR:$val, addr_offset_none:$addr)>;
   4385 }
   4386 
   4387 
   4388 //===----------------------------------------------------------------------===//
   4389 // Assembler aliases
   4390 //
   4391 
   4392 // Aliases for ADC without the ".w" optional width specifier.
   4393 def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $Rm",
   4394                   (t2ADCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
   4395 def : t2InstAlias<"adc${s}${p} $Rd, $Rn, $ShiftedRm",
   4396                   (t2ADCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
   4397                            pred:$p, cc_out:$s)>;
   4398 
   4399 // Aliases for SBC without the ".w" optional width specifier.
   4400 def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $Rm",
   4401                   (t2SBCrr rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
   4402 def : t2InstAlias<"sbc${s}${p} $Rd, $Rn, $ShiftedRm",
   4403                   (t2SBCrs rGPR:$Rd, rGPR:$Rn, t2_so_reg:$ShiftedRm,
   4404                            pred:$p, cc_out:$s)>;
   4405 
   4406 // Aliases for ADD without the ".w" optional width specifier.
   4407 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
   4408         (t2ADDri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p,
   4409          cc_out:$s)>;
   4410 def : t2InstAlias<"add${p} $Rd, $Rn, $imm",
   4411            (t2ADDri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
   4412 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $Rm",
   4413               (t2ADDrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
   4414 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $ShiftedRm",
   4415                   (t2ADDrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
   4416                            pred:$p, cc_out:$s)>;
   4417 // ... and with the destination and source register combined.
   4418 def : t2InstAlias<"add${s}${p} $Rdn, $imm",
   4419       (t2ADDri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
   4420 def : t2InstAlias<"add${p} $Rdn, $imm",
   4421            (t2ADDri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095:$imm, pred:$p)>;
   4422 def : t2InstAlias<"add${s}${p} $Rdn, $Rm",
   4423             (t2ADDrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
   4424 def : t2InstAlias<"add${s}${p} $Rdn, $ShiftedRm",
   4425                   (t2ADDrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
   4426                            pred:$p, cc_out:$s)>;
   4427 
   4428 // add w/ negative immediates is just a sub.
   4429 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
   4430         (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
   4431                  cc_out:$s)>;
   4432 def : t2InstAlias<"add${p} $Rd, $Rn, $imm",
   4433            (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
   4434 def : t2InstAlias<"add${s}${p} $Rdn, $imm",
   4435       (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm_neg:$imm, pred:$p,
   4436                cc_out:$s)>;
   4437 def : t2InstAlias<"add${p} $Rdn, $imm",
   4438            (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
   4439 
   4440 def : t2InstAlias<"add${s}${p}.w $Rd, $Rn, $imm",
   4441         (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm, pred:$p,
   4442                  cc_out:$s)>;
   4443 def : t2InstAlias<"addw${p} $Rd, $Rn, $imm",
   4444            (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095_neg:$imm, pred:$p)>;
   4445 def : t2InstAlias<"add${s}${p}.w $Rdn, $imm",
   4446       (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm_neg:$imm, pred:$p,
   4447                cc_out:$s)>;
   4448 def : t2InstAlias<"addw${p} $Rdn, $imm",
   4449            (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095_neg:$imm, pred:$p)>;
   4450 
   4451 
   4452 // Aliases for SUB without the ".w" optional width specifier.
   4453 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $imm",
   4454         (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
   4455 def : t2InstAlias<"sub${p} $Rd, $Rn, $imm",
   4456            (t2SUBri12 GPRnopc:$Rd, GPR:$Rn, imm0_4095:$imm, pred:$p)>;
   4457 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $Rm",
   4458               (t2SUBrr GPRnopc:$Rd, GPRnopc:$Rn, rGPR:$Rm, pred:$p, cc_out:$s)>;
   4459 def : t2InstAlias<"sub${s}${p} $Rd, $Rn, $ShiftedRm",
   4460                   (t2SUBrs GPRnopc:$Rd, GPRnopc:$Rn, t2_so_reg:$ShiftedRm,
   4461                            pred:$p, cc_out:$s)>;
   4462 // ... and with the destination and source register combined.
   4463 def : t2InstAlias<"sub${s}${p} $Rdn, $imm",
   4464       (t2SUBri GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
   4465 def : t2InstAlias<"sub${p} $Rdn, $imm",
   4466            (t2SUBri12 GPRnopc:$Rdn, GPRnopc:$Rdn, imm0_4095:$imm, pred:$p)>;
   4467 def : t2InstAlias<"sub${s}${p}.w $Rdn, $Rm",
   4468             (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
   4469 def : t2InstAlias<"sub${s}${p} $Rdn, $Rm",
   4470             (t2SUBrr GPRnopc:$Rdn, GPRnopc:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
   4471 def : t2InstAlias<"sub${s}${p} $Rdn, $ShiftedRm",
   4472                   (t2SUBrs GPRnopc:$Rdn, GPRnopc:$Rdn, t2_so_reg:$ShiftedRm,
   4473                            pred:$p, cc_out:$s)>;
   4474 
   4475 // Alias for compares without the ".w" optional width specifier.
   4476 def : t2InstAlias<"cmn${p} $Rn, $Rm",
   4477                   (t2CMNzrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
   4478 def : t2InstAlias<"teq${p} $Rn, $Rm",
   4479                   (t2TEQrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
   4480 def : t2InstAlias<"tst${p} $Rn, $Rm",
   4481                   (t2TSTrr GPRnopc:$Rn, rGPR:$Rm, pred:$p)>;
   4482 
   4483 // Memory barriers
   4484 def : InstAlias<"dmb${p}", (t2DMB 0xf, pred:$p)>, Requires<[HasDB]>;
   4485 def : InstAlias<"dsb${p}", (t2DSB 0xf, pred:$p)>, Requires<[HasDB]>;
   4486 def : InstAlias<"isb${p}", (t2ISB 0xf, pred:$p)>, Requires<[HasDB]>;
   4487 
   4488 // Alias for LDR, LDRB, LDRH, LDRSB, and LDRSH without the ".w" optional
   4489 // width specifier.
   4490 def : t2InstAlias<"ldr${p} $Rt, $addr",
   4491                   (t2LDRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
   4492 def : t2InstAlias<"ldrb${p} $Rt, $addr",
   4493                   (t2LDRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
   4494 def : t2InstAlias<"ldrh${p} $Rt, $addr",
   4495                   (t2LDRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
   4496 def : t2InstAlias<"ldrsb${p} $Rt, $addr",
   4497                   (t2LDRSBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
   4498 def : t2InstAlias<"ldrsh${p} $Rt, $addr",
   4499                   (t2LDRSHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
   4500 
   4501 def : t2InstAlias<"ldr${p} $Rt, $addr",
   4502                   (t2LDRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
   4503 def : t2InstAlias<"ldrb${p} $Rt, $addr",
   4504                   (t2LDRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
   4505 def : t2InstAlias<"ldrh${p} $Rt, $addr",
   4506                   (t2LDRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
   4507 def : t2InstAlias<"ldrsb${p} $Rt, $addr",
   4508                   (t2LDRSBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
   4509 def : t2InstAlias<"ldrsh${p} $Rt, $addr",
   4510                   (t2LDRSHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
   4511 
   4512 def : t2InstAlias<"ldr${p} $Rt, $addr",
   4513                   (t2LDRpci GPRnopc:$Rt, t2ldrlabel:$addr, pred:$p)>;
   4514 def : t2InstAlias<"ldrb${p} $Rt, $addr",
   4515                   (t2LDRBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
   4516 def : t2InstAlias<"ldrh${p} $Rt, $addr",
   4517                   (t2LDRHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
   4518 def : t2InstAlias<"ldrsb${p} $Rt, $addr",
   4519                   (t2LDRSBpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
   4520 def : t2InstAlias<"ldrsh${p} $Rt, $addr",
   4521                   (t2LDRSHpci rGPR:$Rt, t2ldrlabel:$addr, pred:$p)>;
   4522 
   4523 // Alias for MVN with(out) the ".w" optional width specifier.
   4524 def : t2InstAlias<"mvn${s}${p}.w $Rd, $imm",
   4525            (t2MVNi rGPR:$Rd, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
   4526 def : t2InstAlias<"mvn${s}${p} $Rd, $Rm",
   4527            (t2MVNr rGPR:$Rd, rGPR:$Rm, pred:$p, cc_out:$s)>;
   4528 def : t2InstAlias<"mvn${s}${p} $Rd, $ShiftedRm",
   4529            (t2MVNs rGPR:$Rd, t2_so_reg:$ShiftedRm, pred:$p, cc_out:$s)>;
   4530 
   4531 // PKHBT/PKHTB with default shift amount. PKHTB is equivalent to PKHBT when the
   4532 // shift amount is zero (i.e., unspecified).
   4533 def : InstAlias<"pkhbt${p} $Rd, $Rn, $Rm",
   4534                 (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>,
   4535             Requires<[HasT2ExtractPack, IsThumb2]>;
   4536 def : InstAlias<"pkhtb${p} $Rd, $Rn, $Rm",
   4537                 (t2PKHBT rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>,
   4538             Requires<[HasT2ExtractPack, IsThumb2]>;
   4539 
   4540 // PUSH/POP aliases for STM/LDM
   4541 def : t2InstAlias<"push${p}.w $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
   4542 def : t2InstAlias<"push${p} $regs", (t2STMDB_UPD SP, pred:$p, reglist:$regs)>;
   4543 def : t2InstAlias<"pop${p}.w $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
   4544 def : t2InstAlias<"pop${p} $regs", (t2LDMIA_UPD SP, pred:$p, reglist:$regs)>;
   4545 
   4546 // STMIA/STMIA_UPD aliases w/o the optional .w suffix
   4547 def : t2InstAlias<"stm${p} $Rn, $regs",
   4548                   (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
   4549 def : t2InstAlias<"stm${p} $Rn!, $regs",
   4550                   (t2STMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
   4551 
   4552 // LDMIA/LDMIA_UPD aliases w/o the optional .w suffix
   4553 def : t2InstAlias<"ldm${p} $Rn, $regs",
   4554                   (t2LDMIA GPR:$Rn, pred:$p, reglist:$regs)>;
   4555 def : t2InstAlias<"ldm${p} $Rn!, $regs",
   4556                   (t2LDMIA_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
   4557 
   4558 // STMDB/STMDB_UPD aliases w/ the optional .w suffix
   4559 def : t2InstAlias<"stmdb${p}.w $Rn, $regs",
   4560                   (t2STMDB GPR:$Rn, pred:$p, reglist:$regs)>;
   4561 def : t2InstAlias<"stmdb${p}.w $Rn!, $regs",
   4562                   (t2STMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
   4563 
   4564 // LDMDB/LDMDB_UPD aliases w/ the optional .w suffix
   4565 def : t2InstAlias<"ldmdb${p}.w $Rn, $regs",
   4566                   (t2LDMDB GPR:$Rn, pred:$p, reglist:$regs)>;
   4567 def : t2InstAlias<"ldmdb${p}.w $Rn!, $regs",
   4568                   (t2LDMDB_UPD GPR:$Rn, pred:$p, reglist:$regs)>;
   4569 
   4570 // Alias for REV/REV16/REVSH without the ".w" optional width specifier.
   4571 def : t2InstAlias<"rev${p} $Rd, $Rm", (t2REV rGPR:$Rd, rGPR:$Rm, pred:$p)>;
   4572 def : t2InstAlias<"rev16${p} $Rd, $Rm", (t2REV16 rGPR:$Rd, rGPR:$Rm, pred:$p)>;
   4573 def : t2InstAlias<"revsh${p} $Rd, $Rm", (t2REVSH rGPR:$Rd, rGPR:$Rm, pred:$p)>;
   4574 
   4575 
   4576 // Alias for RSB without the ".w" optional width specifier, and with optional
   4577 // implied destination register.
   4578 def : t2InstAlias<"rsb${s}${p} $Rd, $Rn, $imm",
   4579            (t2RSBri rGPR:$Rd, rGPR:$Rn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
   4580 def : t2InstAlias<"rsb${s}${p} $Rdn, $imm",
   4581            (t2RSBri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm:$imm, pred:$p, cc_out:$s)>;
   4582 def : t2InstAlias<"rsb${s}${p} $Rdn, $Rm",
   4583            (t2RSBrr rGPR:$Rdn, rGPR:$Rdn, rGPR:$Rm, pred:$p, cc_out:$s)>;
   4584 def : t2InstAlias<"rsb${s}${p} $Rdn, $ShiftedRm",
   4585            (t2RSBrs rGPR:$Rdn, rGPR:$Rdn, t2_so_reg:$ShiftedRm, pred:$p,
   4586                     cc_out:$s)>;
   4587 
   4588 // SSAT/USAT optional shift operand.
   4589 def : t2InstAlias<"ssat${p} $Rd, $sat_imm, $Rn",
   4590                   (t2SSAT rGPR:$Rd, imm1_32:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
   4591 def : t2InstAlias<"usat${p} $Rd, $sat_imm, $Rn",
   4592                   (t2USAT rGPR:$Rd, imm0_31:$sat_imm, rGPR:$Rn, 0, pred:$p)>;
   4593 
   4594 // STM w/o the .w suffix.
   4595 def : t2InstAlias<"stm${p} $Rn, $regs",
   4596                   (t2STMIA GPR:$Rn, pred:$p, reglist:$regs)>;
   4597 
   4598 // Alias for STR, STRB, and STRH without the ".w" optional
   4599 // width specifier.
   4600 def : t2InstAlias<"str${p} $Rt, $addr",
   4601                   (t2STRi12 GPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
   4602 def : t2InstAlias<"strb${p} $Rt, $addr",
   4603                   (t2STRBi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
   4604 def : t2InstAlias<"strh${p} $Rt, $addr",
   4605                   (t2STRHi12 rGPR:$Rt, t2addrmode_imm12:$addr, pred:$p)>;
   4606 
   4607 def : t2InstAlias<"str${p} $Rt, $addr",
   4608                   (t2STRs GPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
   4609 def : t2InstAlias<"strb${p} $Rt, $addr",
   4610                   (t2STRBs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
   4611 def : t2InstAlias<"strh${p} $Rt, $addr",
   4612                   (t2STRHs rGPR:$Rt, t2addrmode_so_reg:$addr, pred:$p)>;
   4613 
   4614 // Extend instruction optional rotate operand.
   4615 def : InstAlias<"sxtab${p} $Rd, $Rn, $Rm",
   4616               (t2SXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>,
   4617               Requires<[HasT2ExtractPack, IsThumb2]>;
   4618 def : InstAlias<"sxtah${p} $Rd, $Rn, $Rm",
   4619               (t2SXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>,
   4620               Requires<[HasT2ExtractPack, IsThumb2]>;
   4621 def : InstAlias<"sxtab16${p} $Rd, $Rn, $Rm",
   4622               (t2SXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>,
   4623               Requires<[HasT2ExtractPack, IsThumb2]>;
   4624 def : InstAlias<"sxtb16${p} $Rd, $Rm",
   4625               (t2SXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>,
   4626               Requires<[HasT2ExtractPack, IsThumb2]>;
   4627 
   4628 def : t2InstAlias<"sxtb${p} $Rd, $Rm",
   4629                 (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
   4630 def : t2InstAlias<"sxth${p} $Rd, $Rm",
   4631                 (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
   4632 def : t2InstAlias<"sxtb${p}.w $Rd, $Rm",
   4633                 (t2SXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
   4634 def : t2InstAlias<"sxth${p}.w $Rd, $Rm",
   4635                 (t2SXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
   4636 
   4637 def : InstAlias<"uxtab${p} $Rd, $Rn, $Rm",
   4638               (t2UXTAB rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>,
   4639               Requires<[HasT2ExtractPack, IsThumb2]>;
   4640 def : InstAlias<"uxtah${p} $Rd, $Rn, $Rm",
   4641               (t2UXTAH rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>,
   4642               Requires<[HasT2ExtractPack, IsThumb2]>;
   4643 def : InstAlias<"uxtab16${p} $Rd, $Rn, $Rm",
   4644               (t2UXTAB16 rGPR:$Rd, rGPR:$Rn, rGPR:$Rm, 0, pred:$p)>,
   4645               Requires<[HasT2ExtractPack, IsThumb2]>;
   4646 def : InstAlias<"uxtb16${p} $Rd, $Rm",
   4647               (t2UXTB16 rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>,
   4648               Requires<[HasT2ExtractPack, IsThumb2]>;
   4649 
   4650 def : t2InstAlias<"uxtb${p} $Rd, $Rm",
   4651                 (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
   4652 def : t2InstAlias<"uxth${p} $Rd, $Rm",
   4653                 (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
   4654 def : t2InstAlias<"uxtb${p}.w $Rd, $Rm",
   4655                 (t2UXTB rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
   4656 def : t2InstAlias<"uxth${p}.w $Rd, $Rm",
   4657                 (t2UXTH rGPR:$Rd, rGPR:$Rm, 0, pred:$p)>;
   4658 
   4659 // Extend instruction w/o the ".w" optional width specifier.
   4660 def : t2InstAlias<"uxtb${p} $Rd, $Rm$rot",
   4661                   (t2UXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
   4662 def : InstAlias<"uxtb16${p} $Rd, $Rm$rot",
   4663                 (t2UXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>,
   4664                 Requires<[HasT2ExtractPack, IsThumb2]>;
   4665 def : t2InstAlias<"uxth${p} $Rd, $Rm$rot",
   4666                   (t2UXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
   4667 
   4668 def : t2InstAlias<"sxtb${p} $Rd, $Rm$rot",
   4669                   (t2SXTB rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
   4670 def : InstAlias<"sxtb16${p} $Rd, $Rm$rot",
   4671                 (t2SXTB16 rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>,
   4672                 Requires<[HasT2ExtractPack, IsThumb2]>;
   4673 def : t2InstAlias<"sxth${p} $Rd, $Rm$rot",
   4674                   (t2SXTH rGPR:$Rd, rGPR:$Rm, rot_imm:$rot, pred:$p)>;
   4675 
   4676 
   4677 // "mov Rd, t2_so_imm_not" can be handled via "mvn" in assembly, just like
   4678 // for isel.
   4679 def : t2InstAlias<"mov${p} $Rd, $imm",
   4680                   (t2MVNi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, zero_reg)>;
   4681 def : t2InstAlias<"mvn${p} $Rd, $imm",
   4682                   (t2MOVi rGPR:$Rd, t2_so_imm_not:$imm, pred:$p, zero_reg)>;
   4683 // Same for AND <--> BIC
   4684 def : t2InstAlias<"bic${s}${p} $Rd, $Rn, $imm",
   4685                   (t2ANDri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
   4686                            pred:$p, cc_out:$s)>;
   4687 def : t2InstAlias<"bic${s}${p} $Rdn, $imm",
   4688                   (t2ANDri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
   4689                            pred:$p, cc_out:$s)>;
   4690 def : t2InstAlias<"and${s}${p} $Rd, $Rn, $imm",
   4691                   (t2BICri rGPR:$Rd, rGPR:$Rn, t2_so_imm_not:$imm,
   4692                            pred:$p, cc_out:$s)>;
   4693 def : t2InstAlias<"and${s}${p} $Rdn, $imm",
   4694                   (t2BICri rGPR:$Rdn, rGPR:$Rdn, t2_so_imm_not:$imm,
   4695                            pred:$p, cc_out:$s)>;
   4696 // Likewise, "add Rd, t2_so_imm_neg" -> sub
   4697 def : t2InstAlias<"add${s}${p} $Rd, $Rn, $imm",
   4698                   (t2SUBri GPRnopc:$Rd, GPRnopc:$Rn, t2_so_imm_neg:$imm,
   4699                            pred:$p, cc_out:$s)>;
   4700 def : t2InstAlias<"add${s}${p} $Rd, $imm",
   4701                   (t2SUBri GPRnopc:$Rd, GPRnopc:$Rd, t2_so_imm_neg:$imm,
   4702                            pred:$p, cc_out:$s)>;
   4703 // Same for CMP <--> CMN via t2_so_imm_neg
   4704 def : t2InstAlias<"cmp${p} $Rd, $imm",
   4705                   (t2CMNri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
   4706 def : t2InstAlias<"cmn${p} $Rd, $imm",
   4707                   (t2CMPri rGPR:$Rd, t2_so_imm_neg:$imm, pred:$p)>;
   4708 
   4709 
   4710 // Wide 'mul' encoding can be specified with only two operands.
   4711 def : t2InstAlias<"mul${p} $Rn, $Rm",
   4712                   (t2MUL rGPR:$Rn, rGPR:$Rm, rGPR:$Rn, pred:$p)>;
   4713 
   4714 // "neg" is and alias for "rsb rd, rn, #0"
   4715 def : t2InstAlias<"neg${s}${p} $Rd, $Rm",
   4716                   (t2RSBri rGPR:$Rd, rGPR:$Rm, 0, pred:$p, cc_out:$s)>;
   4717 
   4718 // MOV so_reg assembler pseudos. InstAlias isn't expressive enough for
   4719 // these, unfortunately.
   4720 def t2MOVsi: t2AsmPseudo<"mov${p} $Rd, $shift",
   4721                          (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
   4722 def t2MOVSsi: t2AsmPseudo<"movs${p} $Rd, $shift",
   4723                           (ins rGPR:$Rd, t2_so_reg:$shift, pred:$p)>;
   4724 
   4725 def t2MOVsr: t2AsmPseudo<"mov${p} $Rd, $shift",
   4726                          (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
   4727 def t2MOVSsr: t2AsmPseudo<"movs${p} $Rd, $shift",
   4728                           (ins rGPR:$Rd, so_reg_reg:$shift, pred:$p)>;
   4729 
   4730 // ADR w/o the .w suffix
   4731 def : t2InstAlias<"adr${p} $Rd, $addr",
   4732                   (t2ADR rGPR:$Rd, t2adrlabel:$addr, pred:$p)>;
   4733 
   4734 // LDR(literal) w/ alternate [pc, #imm] syntax.
   4735 def t2LDRpcrel   : t2AsmPseudo<"ldr${p} $Rt, $addr",
   4736                          (ins GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
   4737 def t2LDRBpcrel  : t2AsmPseudo<"ldrb${p} $Rt, $addr",
   4738                          (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
   4739 def t2LDRHpcrel  : t2AsmPseudo<"ldrh${p} $Rt, $addr",
   4740                          (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
   4741 def t2LDRSBpcrel  : t2AsmPseudo<"ldrsb${p} $Rt, $addr",
   4742                          (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
   4743 def t2LDRSHpcrel  : t2AsmPseudo<"ldrsh${p} $Rt, $addr",
   4744                          (ins GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
   4745     // Version w/ the .w suffix.
   4746 def : t2InstAlias<"ldr${p}.w $Rt, $addr",
   4747                   (t2LDRpcrel GPR:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p), 0>;
   4748 def : t2InstAlias<"ldrb${p}.w $Rt, $addr",
   4749                   (t2LDRBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
   4750 def : t2InstAlias<"ldrh${p}.w $Rt, $addr",
   4751                   (t2LDRHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
   4752 def : t2InstAlias<"ldrsb${p}.w $Rt, $addr",
   4753                   (t2LDRSBpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
   4754 def : t2InstAlias<"ldrsh${p}.w $Rt, $addr",
   4755                   (t2LDRSHpcrel GPRnopc:$Rt, t2ldr_pcrel_imm12:$addr, pred:$p)>;
   4756 
   4757 def : t2InstAlias<"add${p} $Rd, pc, $imm",
   4758                   (t2ADR rGPR:$Rd, imm0_4095:$imm, pred:$p)>;
   4759 
   4760 // PLD/PLDW/PLI with alternate literal form.
   4761 def : t2InstAlias<"pld${p} $addr",
   4762                   (t2PLDpci t2ldr_pcrel_imm12:$addr, pred:$p)>;
   4763 def : InstAlias<"pli${p} $addr",
   4764                  (t2PLIpci  t2ldr_pcrel_imm12:$addr, pred:$p)>,
   4765       Requires<[IsThumb2,HasV7]>;
   4766