blob: fb7453a912b30cb4a4fa2cca3ffb5070c96def73 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- ARMInstrThumb.td - Thumb support for ARM ---------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the Thumb instruction set.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
15// Thumb specific DAG Nodes.
16//
17
18def ARMtcall : SDNode<"ARMISD::tCALL", SDT_ARMcall,
19 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
20
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021def imm_neg_XFORM : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000022 return CurDAG->getTargetConstant(-(int)N->getZExtValue(), MVT::i32);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000023}]>;
24def imm_comp_XFORM : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000025 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000026}]>;
27
28
29/// imm0_7 predicate - True if the 32-bit immediate is in the range [0,7].
30def imm0_7 : PatLeaf<(i32 imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000031 return (uint32_t)N->getZExtValue() < 8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000032}]>;
33def imm0_7_neg : PatLeaf<(i32 imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000034 return (uint32_t)-N->getZExtValue() < 8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000035}], imm_neg_XFORM>;
36
37def imm0_255 : PatLeaf<(i32 imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000038 return (uint32_t)N->getZExtValue() < 256;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039}]>;
40def imm0_255_comp : PatLeaf<(i32 imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000041 return ~((uint32_t)N->getZExtValue()) < 256;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042}]>;
43
44def imm8_255 : PatLeaf<(i32 imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000045 return (uint32_t)N->getZExtValue() >= 8 && (uint32_t)N->getZExtValue() < 256;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046}]>;
47def imm8_255_neg : PatLeaf<(i32 imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000048 unsigned Val = -N->getZExtValue();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000049 return Val >= 8 && Val < 256;
50}], imm_neg_XFORM>;
51
52// Break imm's up into two pieces: an immediate + a left shift.
53// This uses thumb_immshifted to match and thumb_immshifted_val and
54// thumb_immshifted_shamt to get the val/shift pieces.
55def thumb_immshifted : PatLeaf<(imm), [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000056 return ARM_AM::isThumbImmShiftedVal((unsigned)N->getZExtValue());
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057}]>;
58
59def thumb_immshifted_val : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000060 unsigned V = ARM_AM::getThumbImmNonShiftedVal((unsigned)N->getZExtValue());
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061 return CurDAG->getTargetConstant(V, MVT::i32);
62}]>;
63
64def thumb_immshifted_shamt : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000065 unsigned V = ARM_AM::getThumbImmValShift((unsigned)N->getZExtValue());
Dan Gohmanf17a25c2007-07-18 16:29:46 +000066 return CurDAG->getTargetConstant(V, MVT::i32);
67}]>;
68
69// Define Thumb specific addressing modes.
70
71// t_addrmode_rr := reg + reg
72//
73def t_addrmode_rr : Operand<i32>,
74 ComplexPattern<i32, 2, "SelectThumbAddrModeRR", []> {
75 let PrintMethod = "printThumbAddrModeRROperand";
Jim Grosbach0e4e9742009-04-07 20:34:09 +000076 let MIOperandInfo = (ops tGPR:$base, tGPR:$offsreg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000077}
78
79// t_addrmode_s4 := reg + reg
80// reg + imm5 * 4
81//
82def t_addrmode_s4 : Operand<i32>,
83 ComplexPattern<i32, 3, "SelectThumbAddrModeS4", []> {
84 let PrintMethod = "printThumbAddrModeS4Operand";
Jim Grosbach0e4e9742009-04-07 20:34:09 +000085 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000086}
87
88// t_addrmode_s2 := reg + reg
89// reg + imm5 * 2
90//
91def t_addrmode_s2 : Operand<i32>,
92 ComplexPattern<i32, 3, "SelectThumbAddrModeS2", []> {
93 let PrintMethod = "printThumbAddrModeS2Operand";
Jim Grosbach0e4e9742009-04-07 20:34:09 +000094 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000095}
96
97// t_addrmode_s1 := reg + reg
98// reg + imm5
99//
100def t_addrmode_s1 : Operand<i32>,
101 ComplexPattern<i32, 3, "SelectThumbAddrModeS1", []> {
102 let PrintMethod = "printThumbAddrModeS1Operand";
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000103 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm, tGPR:$offsreg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000104}
105
106// t_addrmode_sp := sp + imm8 * 4
107//
108def t_addrmode_sp : Operand<i32>,
109 ComplexPattern<i32, 2, "SelectThumbAddrModeSP", []> {
110 let PrintMethod = "printThumbAddrModeSPOperand";
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000111 let MIOperandInfo = (ops tGPR:$base, i32imm:$offsimm);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000112}
113
114//===----------------------------------------------------------------------===//
115// Miscellaneous Instructions.
116//
117
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000118let Defs = [SP], Uses = [SP] in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000119def tADJCALLSTACKUP :
Bill Wendling22f8deb2007-11-13 00:44:25 +0000120PseudoInst<(outs), (ins i32imm:$amt1, i32imm:$amt2),
121 "@ tADJCALLSTACKUP $amt1",
David Goodwin4a897932009-07-08 23:10:31 +0000122 [(ARMcallseq_end imm:$amt1, imm:$amt2)]>, Requires<[IsThumb1Only]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000123
Jim Grosbach7ea52762009-03-27 23:06:27 +0000124def tADJCALLSTACKDOWN :
Evan Chengb783fa32007-07-19 01:14:50 +0000125PseudoInst<(outs), (ins i32imm:$amt),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000126 "@ tADJCALLSTACKDOWN $amt",
David Goodwin4a897932009-07-08 23:10:31 +0000127 [(ARMcallseq_start imm:$amt)]>, Requires<[IsThumb1Only]>;
Evan Cheng6e4d1d92007-09-11 19:55:27 +0000128}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000129
130let isNotDuplicable = 1 in
Evan Cheng41799702009-06-24 23:47:58 +0000131def tPICADD : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, pclabel:$cp),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000132 "$cp:\n\tadd $dst, pc",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000133 [(set tGPR:$dst, (ARMpic_add tGPR:$lhs, imm:$cp))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000134
Evan Chengae2ed1f2009-06-25 01:05:06 +0000135// PC relative add.
136def tADDrPCi : T1I<(outs tGPR:$dst), (ins i32imm:$rhs),
137 "add $dst, pc, $rhs * 4", []>;
138
139// ADD rd, sp, #imm8
140// FIXME: hard code sp?
141def tADDrSPi : T1I<(outs tGPR:$dst), (ins GPR:$sp, i32imm:$rhs),
142 "add $dst, $sp, $rhs * 4 @ addrspi", []>;
143
144// ADD sp, sp, #imm7
145// FIXME: hard code sp?
146def tADDspi : T1It<(outs GPR:$dst), (ins GPR:$lhs, i32imm:$rhs),
147 "add $dst, $rhs * 4", []>;
148
149// FIXME: Make use of the following?
150// ADD rm, sp, rm
151// ADD sp, rm
152
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000153//===----------------------------------------------------------------------===//
154// Control Flow Instructions.
155//
156
157let isReturn = 1, isTerminator = 1 in {
David Goodwin4a897932009-07-08 23:10:31 +0000158 def tBX_RET : T1I<(outs), (ins), "bx lr", [(ARMretflag)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000159 // Alternative return instruction used by vararg functions.
David Goodwin41afec22009-07-08 16:09:28 +0000160 def tBX_RET_vararg : T1I<(outs), (ins tGPR:$target), "bx $target", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000161}
162
163// FIXME: remove when we have a way to marking a MI with these properties.
Evan Cheng8610a3b2008-01-07 23:56:57 +0000164let isReturn = 1, isTerminator = 1 in
David Goodwin41afec22009-07-08 16:09:28 +0000165def tPOP_RET : T1I<(outs reglist:$dst1, variable_ops), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000166 "pop $dst1", []>;
167
Jim Grosbach7ea52762009-03-27 23:06:27 +0000168let isCall = 1,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000169 Defs = [R0, R1, R2, R3, LR,
170 D0, D1, D2, D3, D4, D5, D6, D7] in {
David Goodwin41afec22009-07-08 16:09:28 +0000171 def tBL : T1Ix2<(outs), (ins i32imm:$func, variable_ops),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000172 "bl ${func:call}",
173 [(ARMtcall tglobaladdr:$func)]>;
174 // ARMv5T and above
David Goodwin41afec22009-07-08 16:09:28 +0000175 def tBLXi : T1Ix2<(outs), (ins i32imm:$func, variable_ops),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000176 "blx ${func:call}",
177 [(ARMcall tglobaladdr:$func)]>, Requires<[HasV5T]>;
David Goodwin41afec22009-07-08 16:09:28 +0000178 def tBLXr : T1I<(outs), (ins tGPR:$func, variable_ops),
Evan Chengb783fa32007-07-19 01:14:50 +0000179 "blx $func",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000180 [(ARMtcall tGPR:$func)]>, Requires<[HasV5T]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000181 // ARMv4T
David Goodwin41afec22009-07-08 16:09:28 +0000182 def tBX : T1Ix2<(outs), (ins tGPR:$func, variable_ops),
Evan Chengb783fa32007-07-19 01:14:50 +0000183 "cpy lr, pc\n\tbx $func",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000184 [(ARMcall_nolink tGPR:$func)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000185}
186
Evan Cheng37e7c752007-07-21 00:34:19 +0000187let isBranch = 1, isTerminator = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000188 let isBarrier = 1 in {
189 let isPredicable = 1 in
David Goodwinf6154702009-06-30 18:04:13 +0000190 def tB : T1I<(outs), (ins brtarget:$target), "b $target",
191 [(br bb:$target)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000192
193 // Far jump
David Goodwinf6154702009-06-30 18:04:13 +0000194 def tBfar : T1Ix2<(outs), (ins brtarget:$target),
195 "bl $target\t@ far jump",[]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000196
David Goodwinf6154702009-06-30 18:04:13 +0000197 def tBR_JTr : T1JTI<(outs),
198 (ins tGPR:$target, jtblock_operand:$jt, i32imm:$id),
199 "cpy pc, $target \n\t.align\t2\n$jt",
200 [(ARMbrjt tGPR:$target, tjumptable:$jt, imm:$id)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000201 }
202}
203
204// FIXME: should be able to write a pattern for ARMBrcond, but can't use
Jim Grosbach7ea52762009-03-27 23:06:27 +0000205// a two-value operand where a dag node expects two operands. :(
Evan Cheng37e7c752007-07-21 00:34:19 +0000206let isBranch = 1, isTerminator = 1 in
David Goodwinf6154702009-06-30 18:04:13 +0000207 def tBcc : T1I<(outs), (ins brtarget:$target, pred:$cc), "b$cc $target",
Evan Chengb783fa32007-07-19 01:14:50 +0000208 [/*(ARMbrcond bb:$target, imm:$cc)*/]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000209
210//===----------------------------------------------------------------------===//
211// Load Store Instructions.
212//
213
Dan Gohman5574cc72008-12-03 18:15:48 +0000214let canFoldAsLoad = 1 in
Evan Cheng532cdc52009-06-29 07:51:04 +0000215def tLDR : T1I4<(outs tGPR:$dst), (ins t_addrmode_s4:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000216 "ldr $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000217 [(set tGPR:$dst, (load t_addrmode_s4:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000218
Evan Cheng532cdc52009-06-29 07:51:04 +0000219def tLDRB : T1I1<(outs tGPR:$dst), (ins t_addrmode_s1:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000220 "ldrb $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000221 [(set tGPR:$dst, (zextloadi8 t_addrmode_s1:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000222
Evan Cheng532cdc52009-06-29 07:51:04 +0000223def tLDRH : T1I2<(outs tGPR:$dst), (ins t_addrmode_s2:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224 "ldrh $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000225 [(set tGPR:$dst, (zextloadi16 t_addrmode_s2:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000226
Evan Cheng532cdc52009-06-29 07:51:04 +0000227def tLDRSB : T1I1<(outs tGPR:$dst), (ins t_addrmode_rr:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000228 "ldrsb $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000229 [(set tGPR:$dst, (sextloadi8 t_addrmode_rr:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000230
Evan Cheng532cdc52009-06-29 07:51:04 +0000231def tLDRSH : T1I2<(outs tGPR:$dst), (ins t_addrmode_rr:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000232 "ldrsh $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000233 [(set tGPR:$dst, (sextloadi16 t_addrmode_rr:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000234
Dan Gohman5574cc72008-12-03 18:15:48 +0000235let canFoldAsLoad = 1 in
Evan Cheng532cdc52009-06-29 07:51:04 +0000236def tLDRspi : T1Is<(outs tGPR:$dst), (ins t_addrmode_sp:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000237 "ldr $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000238 [(set tGPR:$dst, (load t_addrmode_sp:$addr))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000239
240// Special instruction for restore. It cannot clobber condition register
241// when it's expanded by eliminateCallFramePseudoInstr().
Dan Gohman5574cc72008-12-03 18:15:48 +0000242let canFoldAsLoad = 1, mayLoad = 1 in
Evan Cheng532cdc52009-06-29 07:51:04 +0000243def tRestore : T1Is<(outs tGPR:$dst), (ins t_addrmode_sp:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000244 "ldr $dst, $addr", []>;
245
246// Load tconstpool
Dan Gohman5574cc72008-12-03 18:15:48 +0000247let canFoldAsLoad = 1 in
Evan Cheng532cdc52009-06-29 07:51:04 +0000248def tLDRpci : T1Is<(outs tGPR:$dst), (ins i32imm:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000249 "ldr $dst, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000250 [(set tGPR:$dst, (load (ARMWrapper tconstpool:$addr)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000251
252// Special LDR for loads from non-pc-relative constpools.
Dan Gohman5574cc72008-12-03 18:15:48 +0000253let canFoldAsLoad = 1, mayLoad = 1, isReMaterializable = 1 in
Evan Cheng532cdc52009-06-29 07:51:04 +0000254def tLDRcp : T1Is<(outs tGPR:$dst), (ins i32imm:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000255 "ldr $dst, $addr", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000256
Evan Cheng532cdc52009-06-29 07:51:04 +0000257def tSTR : T1I4<(outs), (ins tGPR:$src, t_addrmode_s4:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000258 "str $src, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000259 [(store tGPR:$src, t_addrmode_s4:$addr)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000260
Evan Cheng532cdc52009-06-29 07:51:04 +0000261def tSTRB : T1I1<(outs), (ins tGPR:$src, t_addrmode_s1:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000262 "strb $src, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000263 [(truncstorei8 tGPR:$src, t_addrmode_s1:$addr)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000264
Evan Cheng532cdc52009-06-29 07:51:04 +0000265def tSTRH : T1I2<(outs), (ins tGPR:$src, t_addrmode_s2:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000266 "strh $src, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000267 [(truncstorei16 tGPR:$src, t_addrmode_s2:$addr)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000268
Evan Cheng532cdc52009-06-29 07:51:04 +0000269def tSTRspi : T1Is<(outs), (ins tGPR:$src, t_addrmode_sp:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000270 "str $src, $addr",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000271 [(store tGPR:$src, t_addrmode_sp:$addr)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000272
Chris Lattner6887b142008-01-06 08:36:04 +0000273let mayStore = 1 in {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000274// Special instruction for spill. It cannot clobber condition register
275// when it's expanded by eliminateCallFramePseudoInstr().
Evan Cheng532cdc52009-06-29 07:51:04 +0000276def tSpill : T1Is<(outs), (ins tGPR:$src, t_addrmode_sp:$addr),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000277 "str $src, $addr", []>;
278}
279
280//===----------------------------------------------------------------------===//
281// Load / store multiple Instructions.
282//
283
284// TODO: A7-44: LDMIA - load multiple
285
Chris Lattnerca4e0fe2008-01-10 05:12:37 +0000286let mayLoad = 1 in
David Goodwin41afec22009-07-08 16:09:28 +0000287def tPOP : T1I<(outs reglist:$dst1, variable_ops), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000288 "pop $dst1", []>;
289
Chris Lattner6887b142008-01-06 08:36:04 +0000290let mayStore = 1 in
David Goodwin41afec22009-07-08 16:09:28 +0000291def tPUSH : T1I<(outs), (ins reglist:$src1, variable_ops),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000292 "push $src1", []>;
293
294//===----------------------------------------------------------------------===//
295// Arithmetic Instructions.
296//
297
David Goodwin8768bff2009-06-25 22:49:55 +0000298// Add with carry register
299let isCommutable = 1, Defs = [CPSR], Uses = [CPSR] in
300def tADCS : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
301 "adc $dst, $rhs",
302 [(set tGPR:$dst, (adde tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000303
David Goodwin8768bff2009-06-25 22:49:55 +0000304// Add immediate
305let Defs = [CPSR] in {
Evan Cheng6fc534c2009-06-23 19:38:13 +0000306def tADDi3 : T1I<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000307 "add $dst, $lhs, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000308 [(set tGPR:$dst, (add tGPR:$lhs, imm0_7:$rhs))]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000309def tADDSi3 : T1I<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs),
310 "add $dst, $lhs, $rhs",
311 [(set tGPR:$dst, (addc tGPR:$lhs, imm0_7:$rhs))]>;
312}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000313
David Goodwin8768bff2009-06-25 22:49:55 +0000314let Defs = [CPSR] in {
Evan Cheng6fc534c2009-06-23 19:38:13 +0000315def tADDi8 : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000316 "add $dst, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000317 [(set tGPR:$dst, (add tGPR:$lhs, imm8_255:$rhs))]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000318def tADDSi8 : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs),
319 "add $dst, $rhs",
320 [(set tGPR:$dst, (addc tGPR:$lhs, imm8_255:$rhs))]>;
321}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000322
David Goodwin8768bff2009-06-25 22:49:55 +0000323// Add register
324let isCommutable = 1, Defs = [CPSR] in {
Evan Cheng6fc534c2009-06-23 19:38:13 +0000325def tADDrr : T1I<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000326 "add $dst, $lhs, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000327 [(set tGPR:$dst, (add tGPR:$lhs, tGPR:$rhs))]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000328def tADDSrr : T1I<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
329 "add $dst, $lhs, $rhs",
330 [(set tGPR:$dst, (addc tGPR:$lhs, tGPR:$rhs))]>;
331}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000332
Evan Chengd97d7142009-06-12 20:46:18 +0000333let neverHasSideEffects = 1 in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000334def tADDhirr : T1It<(outs tGPR:$dst), (ins GPR:$lhs, GPR:$rhs),
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000335 "add $dst, $rhs @ addhirr", []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000336
David Goodwin8768bff2009-06-25 22:49:55 +0000337// And register
338let isCommutable = 1, Defs = [CPSR] in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000339def tAND : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000340 "and $dst, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000341 [(set tGPR:$dst, (and tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342
David Goodwin8768bff2009-06-25 22:49:55 +0000343// ASR immediate
344let Defs = [CPSR] in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000345def tASRri : T1I<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000346 "asr $dst, $lhs, $rhs",
Bob Wilson74590a02009-06-22 22:08:29 +0000347 [(set tGPR:$dst, (sra tGPR:$lhs, (i32 imm:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000348
David Goodwin8768bff2009-06-25 22:49:55 +0000349// ASR register
350let Defs = [CPSR] in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000351def tASRrr : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352 "asr $dst, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000353 [(set tGPR:$dst, (sra tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000354
David Goodwin8768bff2009-06-25 22:49:55 +0000355// BIC register
356let Defs = [CPSR] in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000357def tBIC : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000358 "bic $dst, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000359 [(set tGPR:$dst, (and tGPR:$lhs, (not tGPR:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360
David Goodwin8768bff2009-06-25 22:49:55 +0000361// CMN register
362let Defs = [CPSR] in {
Evan Cheng6fc534c2009-06-23 19:38:13 +0000363def tCMN : T1I<(outs), (ins tGPR:$lhs, tGPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000364 "cmn $lhs, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000365 [(ARMcmp tGPR:$lhs, (ineg tGPR:$rhs))]>;
David Goodwin8bdcbb32009-06-29 15:33:01 +0000366def tCMNZ : T1I<(outs), (ins tGPR:$lhs, tGPR:$rhs),
367 "cmn $lhs, $rhs",
368 [(ARMcmpZ tGPR:$lhs, (ineg tGPR:$rhs))]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000369}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000370
David Goodwin8768bff2009-06-25 22:49:55 +0000371// CMP immediate
372let Defs = [CPSR] in {
373def tCMPi8 : T1I<(outs), (ins tGPR:$lhs, i32imm:$rhs),
374 "cmp $lhs, $rhs",
375 [(ARMcmp tGPR:$lhs, imm0_255:$rhs)]>;
David Goodwin8bdcbb32009-06-29 15:33:01 +0000376def tCMPZi8 : T1I<(outs), (ins tGPR:$lhs, i32imm:$rhs),
377 "cmp $lhs, $rhs",
378 [(ARMcmpZ tGPR:$lhs, imm0_255:$rhs)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000379
David Goodwin8768bff2009-06-25 22:49:55 +0000380}
381
382// CMP register
383let Defs = [CPSR] in {
384def tCMPr : T1I<(outs), (ins tGPR:$lhs, tGPR:$rhs),
385 "cmp $lhs, $rhs",
386 [(ARMcmp tGPR:$lhs, tGPR:$rhs)]>;
David Goodwin8bdcbb32009-06-29 15:33:01 +0000387def tCMPZr : T1I<(outs), (ins tGPR:$lhs, tGPR:$rhs),
388 "cmp $lhs, $rhs",
389 [(ARMcmpZ tGPR:$lhs, tGPR:$rhs)]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000390}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000391
392// TODO: A7-37: CMP(3) - cmp hi regs
393
David Goodwin8768bff2009-06-25 22:49:55 +0000394// XOR register
395let isCommutable = 1, Defs = [CPSR] in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000396def tEOR : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000397 "eor $dst, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000398 [(set tGPR:$dst, (xor tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000399
David Goodwin8768bff2009-06-25 22:49:55 +0000400// LSL immediate
401let Defs = [CPSR] in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000402def tLSLri : T1I<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000403 "lsl $dst, $lhs, $rhs",
Bob Wilson74590a02009-06-22 22:08:29 +0000404 [(set tGPR:$dst, (shl tGPR:$lhs, (i32 imm:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000405
David Goodwin8768bff2009-06-25 22:49:55 +0000406// LSL register
407let Defs = [CPSR] in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000408def tLSLrr : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000409 "lsl $dst, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000410 [(set tGPR:$dst, (shl tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000411
David Goodwin8768bff2009-06-25 22:49:55 +0000412// LSR immediate
413let Defs = [CPSR] in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000414def tLSRri : T1I<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000415 "lsr $dst, $lhs, $rhs",
Bob Wilson74590a02009-06-22 22:08:29 +0000416 [(set tGPR:$dst, (srl tGPR:$lhs, (i32 imm:$rhs)))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000417
David Goodwin8768bff2009-06-25 22:49:55 +0000418// LSR register
419let Defs = [CPSR] in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000420def tLSRrr : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000421 "lsr $dst, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000422 [(set tGPR:$dst, (srl tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000423
David Goodwin8768bff2009-06-25 22:49:55 +0000424// move register
425let Defs = [CPSR] in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000426def tMOVi8 : T1I<(outs tGPR:$dst), (ins i32imm:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000427 "mov $dst, $src",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000428 [(set tGPR:$dst, imm0_255:$src)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000429
430// TODO: A7-73: MOV(2) - mov setting flag.
431
432
433// Note: MOV(2) of two low regs updates the flags, so we emit this as 'cpy',
434// which is MOV(3). This also supports high registers.
Evan Chengd97d7142009-06-12 20:46:18 +0000435let neverHasSideEffects = 1 in {
Evan Cheng6fc534c2009-06-23 19:38:13 +0000436def tMOVr : T1I<(outs tGPR:$dst), (ins tGPR:$src),
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000437 "cpy $dst, $src", []>;
Evan Cheng6fc534c2009-06-23 19:38:13 +0000438def tMOVhir2lor : T1I<(outs tGPR:$dst), (ins GPR:$src),
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000439 "cpy $dst, $src\t@ hir2lor", []>;
Evan Cheng6fc534c2009-06-23 19:38:13 +0000440def tMOVlor2hir : T1I<(outs GPR:$dst), (ins tGPR:$src),
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000441 "cpy $dst, $src\t@ lor2hir", []>;
Evan Cheng6fc534c2009-06-23 19:38:13 +0000442def tMOVhir2hir : T1I<(outs GPR:$dst), (ins GPR:$src),
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000443 "cpy $dst, $src\t@ hir2hir", []>;
Evan Chengd97d7142009-06-12 20:46:18 +0000444} // neverHasSideEffects
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000445
David Goodwin8768bff2009-06-25 22:49:55 +0000446// multiply register
447let isCommutable = 1, Defs = [CPSR] in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000448def tMUL : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000449 "mul $dst, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000450 [(set tGPR:$dst, (mul tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000451
David Goodwin8768bff2009-06-25 22:49:55 +0000452// move inverse register
453let Defs = [CPSR] in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000454def tMVN : T1I<(outs tGPR:$dst), (ins tGPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000455 "mvn $dst, $src",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000456 [(set tGPR:$dst, (not tGPR:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000457
David Goodwin8768bff2009-06-25 22:49:55 +0000458// negate register
459let Defs = [CPSR] in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000460def tNEG : T1I<(outs tGPR:$dst), (ins tGPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000461 "neg $dst, $src",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000462 [(set tGPR:$dst, (ineg tGPR:$src))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000463
David Goodwin8768bff2009-06-25 22:49:55 +0000464// bitwise or register
465let isCommutable = 1, Defs = [CPSR] in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000466def tORR : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000467 "orr $dst, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000468 [(set tGPR:$dst, (or tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000469
David Goodwin8768bff2009-06-25 22:49:55 +0000470// swaps
Evan Cheng6fc534c2009-06-23 19:38:13 +0000471def tREV : T1I<(outs tGPR:$dst), (ins tGPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000472 "rev $dst, $src",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000473 [(set tGPR:$dst, (bswap tGPR:$src))]>,
David Goodwin4a897932009-07-08 23:10:31 +0000474 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000475
Evan Cheng6fc534c2009-06-23 19:38:13 +0000476def tREV16 : T1I<(outs tGPR:$dst), (ins tGPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000477 "rev16 $dst, $src",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000478 [(set tGPR:$dst,
Bob Wilson74590a02009-06-22 22:08:29 +0000479 (or (and (srl tGPR:$src, (i32 8)), 0xFF),
480 (or (and (shl tGPR:$src, (i32 8)), 0xFF00),
481 (or (and (srl tGPR:$src, (i32 8)), 0xFF0000),
482 (and (shl tGPR:$src, (i32 8)), 0xFF000000)))))]>,
David Goodwin4a897932009-07-08 23:10:31 +0000483 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000484
Evan Cheng6fc534c2009-06-23 19:38:13 +0000485def tREVSH : T1I<(outs tGPR:$dst), (ins tGPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000486 "revsh $dst, $src",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000487 [(set tGPR:$dst,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000488 (sext_inreg
Bob Wilson74590a02009-06-22 22:08:29 +0000489 (or (srl (and tGPR:$src, 0xFFFF), (i32 8)),
490 (shl tGPR:$src, (i32 8))), i16))]>,
David Goodwin4a897932009-07-08 23:10:31 +0000491 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000492
David Goodwin8768bff2009-06-25 22:49:55 +0000493// rotate right register
494let Defs = [CPSR] in
Evan Cheng6fc534c2009-06-23 19:38:13 +0000495def tROR : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000496 "ror $dst, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000497 [(set tGPR:$dst, (rotr tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000498
David Goodwin8768bff2009-06-25 22:49:55 +0000499// Subtract with carry register
500let Defs = [CPSR], Uses = [CPSR] in
501def tSBCS : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000502 "sbc $dst, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000503 [(set tGPR:$dst, (sube tGPR:$lhs, tGPR:$rhs))]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000504
David Goodwin8768bff2009-06-25 22:49:55 +0000505// Subtract immediate
506let Defs = [CPSR] in {
Evan Cheng6fc534c2009-06-23 19:38:13 +0000507def tSUBi3 : T1I<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000508 "sub $dst, $lhs, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000509 [(set tGPR:$dst, (add tGPR:$lhs, imm0_7_neg:$rhs))]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000510def tSUBSi3 : T1I<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs),
511 "sub $dst, $lhs, $rhs",
512 [(set tGPR:$dst, (addc tGPR:$lhs, imm0_7_neg:$rhs))]>;
513}
Jim Grosbach7ea52762009-03-27 23:06:27 +0000514
David Goodwin8768bff2009-06-25 22:49:55 +0000515let Defs = [CPSR] in {
Evan Cheng6fc534c2009-06-23 19:38:13 +0000516def tSUBi8 : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000517 "sub $dst, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000518 [(set tGPR:$dst, (add tGPR:$lhs, imm8_255_neg:$rhs))]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000519def tSUBSi8 : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs),
520 "sub $dst, $rhs",
521 [(set tGPR:$dst, (addc tGPR:$lhs, imm8_255_neg:$rhs))]>;
522}
Jim Grosbach7ea52762009-03-27 23:06:27 +0000523
David Goodwin8768bff2009-06-25 22:49:55 +0000524// subtract register
525let Defs = [CPSR] in {
Evan Cheng6fc534c2009-06-23 19:38:13 +0000526def tSUBrr : T1I<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000527 "sub $dst, $lhs, $rhs",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000528 [(set tGPR:$dst, (sub tGPR:$lhs, tGPR:$rhs))]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000529def tSUBSrr : T1I<(outs tGPR:$dst), (ins tGPR:$lhs, tGPR:$rhs),
530 "sub $dst, $lhs, $rhs",
531 [(set tGPR:$dst, (subc tGPR:$lhs, tGPR:$rhs))]>;
532}
533
534// TODO: A7-96: STMIA - store multiple.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000535
Evan Cheng6fc534c2009-06-23 19:38:13 +0000536def tSUBspi : T1It<(outs tGPR:$dst), (ins tGPR:$lhs, i32imm:$rhs),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000537 "sub $dst, $rhs * 4", []>;
538
David Goodwin8768bff2009-06-25 22:49:55 +0000539// sign-extend byte
Evan Cheng6fc534c2009-06-23 19:38:13 +0000540def tSXTB : T1I<(outs tGPR:$dst), (ins tGPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000541 "sxtb $dst, $src",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000542 [(set tGPR:$dst, (sext_inreg tGPR:$src, i8))]>,
David Goodwin4a897932009-07-08 23:10:31 +0000543 Requires<[IsThumb1Only, HasV6]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000544
545// sign-extend short
Evan Cheng6fc534c2009-06-23 19:38:13 +0000546def tSXTH : T1I<(outs tGPR:$dst), (ins tGPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547 "sxth $dst, $src",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000548 [(set tGPR:$dst, (sext_inreg tGPR:$src, i16))]>,
David Goodwin4a897932009-07-08 23:10:31 +0000549 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000550
David Goodwin8768bff2009-06-25 22:49:55 +0000551// test
Evan Cheng138f60e2009-06-26 00:19:07 +0000552let isCommutable = 1, Defs = [CPSR] in
David Goodwin8768bff2009-06-25 22:49:55 +0000553def tTST : T1I<(outs), (ins tGPR:$lhs, tGPR:$rhs),
554 "tst $lhs, $rhs",
David Goodwin8bdcbb32009-06-29 15:33:01 +0000555 [(ARMcmpZ (and tGPR:$lhs, tGPR:$rhs), 0)]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000556
David Goodwin8768bff2009-06-25 22:49:55 +0000557// zero-extend byte
Evan Cheng6fc534c2009-06-23 19:38:13 +0000558def tUXTB : T1I<(outs tGPR:$dst), (ins tGPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000559 "uxtb $dst, $src",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000560 [(set tGPR:$dst, (and tGPR:$src, 0xFF))]>,
David Goodwin4a897932009-07-08 23:10:31 +0000561 Requires<[IsThumb1Only, HasV6]>;
David Goodwin8768bff2009-06-25 22:49:55 +0000562
563// zero-extend short
Evan Cheng6fc534c2009-06-23 19:38:13 +0000564def tUXTH : T1I<(outs tGPR:$dst), (ins tGPR:$src),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000565 "uxth $dst, $src",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000566 [(set tGPR:$dst, (and tGPR:$src, 0xFFFF))]>,
David Goodwin4a897932009-07-08 23:10:31 +0000567 Requires<[IsThumb1Only, HasV6]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000568
569
570// Conditional move tMOVCCr - Used to implement the Thumb SELECT_CC DAG operation.
571// Expanded by the scheduler into a branch sequence.
572let usesCustomDAGSchedInserter = 1 in // Expanded by the scheduler.
573 def tMOVCCr :
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000574 PseudoInst<(outs tGPR:$dst), (ins tGPR:$false, tGPR:$true, pred:$cc),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000575 "@ tMOVCCr $cc",
Jim Grosbach0e4e9742009-04-07 20:34:09 +0000576 [/*(set tGPR:$dst, (ARMcmov tGPR:$false, tGPR:$true, imm:$cc))*/]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000577
578// tLEApcrel - Load a pc-relative address into a register without offending the
579// assembler.
David Goodwin41afec22009-07-08 16:09:28 +0000580def tLEApcrel : T1Ix2<(outs tGPR:$dst), (ins i32imm:$label),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000581 !strconcat(!strconcat(".set PCRELV${:uid}, ($label-(",
582 "${:private}PCRELL${:uid}+4))\n"),
583 !strconcat("\tmov $dst, #PCRELV${:uid}\n",
584 "${:private}PCRELL${:uid}:\n\tadd $dst, pc")),
585 []>;
586
David Goodwin41afec22009-07-08 16:09:28 +0000587def tLEApcrelJT : T1Ix2<(outs tGPR:$dst), (ins i32imm:$label, i32imm:$id),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000588 !strconcat(!strconcat(".set PCRELV${:uid}, (${label}_${id:no_hash}-(",
589 "${:private}PCRELL${:uid}+4))\n"),
590 !strconcat("\tmov $dst, #PCRELV${:uid}\n",
591 "${:private}PCRELL${:uid}:\n\tadd $dst, pc")),
592 []>;
593
594//===----------------------------------------------------------------------===//
595// TLS Instructions
596//
597
598// __aeabi_read_tp preserves the registers r1-r3.
599let isCall = 1,
600 Defs = [R0, LR] in {
David Goodwin41afec22009-07-08 16:09:28 +0000601 def tTPsoft : T1Ix2<(outs), (ins),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000602 "bl __aeabi_read_tp",
603 [(set R0, ARMthread_pointer)]>;
604}
605
606//===----------------------------------------------------------------------===//
607// Non-Instruction Patterns
608//
609
610// ConstantPool, GlobalAddress
Evan Cheng19bb7c72009-06-27 02:26:13 +0000611def : TPat<(ARMWrapper tglobaladdr :$dst), (tLEApcrel tglobaladdr :$dst)>;
612def : TPat<(ARMWrapper tconstpool :$dst), (tLEApcrel tconstpool :$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000613
614// JumpTable
Evan Cheng19bb7c72009-06-27 02:26:13 +0000615def : TPat<(ARMWrapperJT tjumptable:$dst, imm:$id),
616 (tLEApcrelJT tjumptable:$dst, imm:$id)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000617
618// Direct calls
Evan Cheng19bb7c72009-06-27 02:26:13 +0000619def : TPat<(ARMtcall texternalsym:$func), (tBL texternalsym:$func)>;
620def : Tv5Pat<(ARMcall texternalsym:$func), (tBLXi texternalsym:$func)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000621
622// Indirect calls to ARM routines
Evan Cheng19bb7c72009-06-27 02:26:13 +0000623def : Tv5Pat<(ARMcall tGPR:$dst), (tBLXr tGPR:$dst)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000624
625// zextload i1 -> zextload i8
Evan Cheng503be112009-06-30 02:15:48 +0000626def : T1Pat<(zextloadi1 t_addrmode_s1:$addr),
627 (tLDRB t_addrmode_s1:$addr)>;
Jim Grosbach7ea52762009-03-27 23:06:27 +0000628
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000629// extload -> zextload
Evan Cheng503be112009-06-30 02:15:48 +0000630def : T1Pat<(extloadi1 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
631def : T1Pat<(extloadi8 t_addrmode_s1:$addr), (tLDRB t_addrmode_s1:$addr)>;
632def : T1Pat<(extloadi16 t_addrmode_s2:$addr), (tLDRH t_addrmode_s2:$addr)>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000633
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000634// Large immediate handling.
635
636// Two piece imms.
Evan Cheng19bb7c72009-06-27 02:26:13 +0000637def : T1Pat<(i32 thumb_immshifted:$src),
638 (tLSLri (tMOVi8 (thumb_immshifted_val imm:$src)),
639 (thumb_immshifted_shamt imm:$src))>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000640
Evan Cheng19bb7c72009-06-27 02:26:13 +0000641def : T1Pat<(i32 imm0_255_comp:$src),
642 (tMVN (tMOVi8 (imm_comp_XFORM imm:$src)))>;