blob: b88f13685681e7aef2e54ebd9c4a2a4516a68658 [file] [log] [blame]
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00001//===-- ARMISelDAGToDAG.cpp - A dag to dag inst selector for ARM ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the ARM target.
11//
12//===----------------------------------------------------------------------===//
13
Dale Johannesen51e28e62010-06-03 21:09:53 +000014#define DEBUG_TYPE "arm-isel"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000015#include "ARM.h"
Evan Cheng48575f62010-12-05 22:04:16 +000016#include "ARMBaseInstrInfo.h"
Evan Chenge5ad88e2008-12-10 21:54:21 +000017#include "ARMAddressingModes.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000018#include "ARMTargetMachine.h"
Rafael Espindola84b19be2006-07-16 01:02:57 +000019#include "llvm/CallingConv.h"
Evan Chenga8e29892007-01-19 07:51:42 +000020#include "llvm/Constants.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000021#include "llvm/DerivedTypes.h"
22#include "llvm/Function.h"
23#include "llvm/Intrinsics.h"
Owen Anderson9adc0ab2009-07-14 23:09:55 +000024#include "llvm/LLVMContext.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000025#include "llvm/CodeGen/MachineFrameInfo.h"
26#include "llvm/CodeGen/MachineFunction.h"
27#include "llvm/CodeGen/MachineInstrBuilder.h"
28#include "llvm/CodeGen/SelectionDAG.h"
29#include "llvm/CodeGen/SelectionDAGISel.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000030#include "llvm/Target/TargetLowering.h"
Chris Lattner72939122007-05-03 00:32:00 +000031#include "llvm/Target/TargetOptions.h"
Evan Cheng94cc6d32010-05-04 20:39:49 +000032#include "llvm/Support/CommandLine.h"
Chris Lattner3d62d782008-02-03 05:43:57 +000033#include "llvm/Support/Compiler.h"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000034#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000035#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/raw_ostream.h"
37
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000038using namespace llvm;
39
Evan Chenga2c519b2010-07-30 23:33:54 +000040static cl::opt<bool>
41DisableShifterOp("disable-shifter-op", cl::Hidden,
42 cl::desc("Disable isel of shifter-op"),
43 cl::init(false));
44
Evan Cheng48575f62010-12-05 22:04:16 +000045static cl::opt<bool>
46CheckVMLxHazard("check-vmlx-hazard", cl::Hidden,
47 cl::desc("Check fp vmla / vmls hazard at isel time"),
48 cl::init(false));
49
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000050//===--------------------------------------------------------------------===//
51/// ARMDAGToDAGISel - ARM specific code to select ARM machine
52/// instructions for SelectionDAG operations.
53///
54namespace {
Jim Grosbach82891622010-09-29 19:03:54 +000055
56enum AddrMode2Type {
57 AM2_BASE, // Simple AM2 (+-imm12)
58 AM2_SHOP // Shifter-op AM2
59};
60
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000061class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000062 ARMBaseTargetMachine &TM;
Evan Cheng48575f62010-12-05 22:04:16 +000063 const ARMBaseInstrInfo *TII;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000064
Evan Chenga8e29892007-01-19 07:51:42 +000065 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
66 /// make the right decision when generating code for different targets.
67 const ARMSubtarget *Subtarget;
68
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000069public:
Bob Wilson522ce972009-09-28 14:30:20 +000070 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
71 CodeGenOpt::Level OptLevel)
72 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Cheng48575f62010-12-05 22:04:16 +000073 TII(static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo())),
74 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000075 }
76
Evan Chenga8e29892007-01-19 07:51:42 +000077 virtual const char *getPassName() const {
78 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000079 }
80
Bob Wilsonaf4a8912009-10-08 18:51:31 +000081 /// getI32Imm - Return a target constant of type i32 with the specified
82 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000083 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000084 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000085 }
86
Dan Gohmaneeb3a002010-01-05 01:24:18 +000087 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000088
Evan Cheng48575f62010-12-05 22:04:16 +000089
90 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Chengf40deed2010-10-27 23:41:30 +000091 bool isShifterOpProfitable(const SDValue &Shift,
92 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Chris Lattner52a261b2010-09-21 20:31:19 +000093 bool SelectShifterOperandReg(SDValue N, SDValue &A,
Evan Cheng055b0312009-06-29 07:51:04 +000094 SDValue &B, SDValue &C);
Evan Chengf40deed2010-10-27 23:41:30 +000095 bool SelectShiftShifterOperandReg(SDValue N, SDValue &A,
96 SDValue &B, SDValue &C);
Jim Grosbach3e556122010-10-26 22:37:02 +000097 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
98 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
99
Jim Grosbach82891622010-09-29 19:03:54 +0000100 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
101 SDValue &Offset, SDValue &Opc);
102 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
103 SDValue &Opc) {
104 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
105 }
106
107 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
108 SDValue &Opc) {
109 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
110 }
111
112 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
113 SDValue &Opc) {
114 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000115// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000116 // This always matches one way or another.
117 return true;
118 }
119
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000120 bool SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000121 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000122 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000123 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000124 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000125 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000126 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000127 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000128 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000129
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000130 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000131
Bill Wendlingf4caf692010-12-14 03:36:38 +0000132 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000133 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000134 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
135 unsigned Scale);
136 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
137 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
138 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
139 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
140 SDValue &OffImm);
141 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
142 SDValue &OffImm);
143 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
144 SDValue &OffImm);
145 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
146 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000147 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000148
Bill Wendlingf4caf692010-12-14 03:36:38 +0000149 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000150 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000151 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000152 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
153 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000154 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000155 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000156 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000157 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000158 SDValue &OffReg, SDValue &ShImm);
159
Evan Cheng875a6ac2010-11-12 22:42:47 +0000160 inline bool is_so_imm(unsigned Imm) const {
161 return ARM_AM::getSOImmVal(Imm) != -1;
162 }
163
164 inline bool is_so_imm_not(unsigned Imm) const {
165 return ARM_AM::getSOImmVal(~Imm) != -1;
166 }
167
168 inline bool is_t2_so_imm(unsigned Imm) const {
169 return ARM_AM::getT2SOImmVal(Imm) != -1;
170 }
171
172 inline bool is_t2_so_imm_not(unsigned Imm) const {
173 return ARM_AM::getT2SOImmVal(~Imm) != -1;
174 }
175
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000176 inline bool Pred_so_imm(SDNode *inN) const {
177 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000178 return is_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000179 }
180
181 inline bool Pred_t2_so_imm(SDNode *inN) const {
182 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000183 return is_t2_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000184 }
185
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000186 // Include the pieces autogenerated from the target description.
187#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000188
189private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000190 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
191 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000192 SDNode *SelectARMIndexedLoad(SDNode *N);
193 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000194
Bob Wilson621f1952010-03-23 05:25:43 +0000195 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
196 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000197 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000198 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000199 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000200 unsigned *QOpcodes0, unsigned *QOpcodes1);
201
Bob Wilson24f995d2009-10-14 18:32:29 +0000202 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000203 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000204 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000205 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000206 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000207 unsigned *QOpcodes0, unsigned *QOpcodes1);
208
Bob Wilson96493442009-10-14 16:46:45 +0000209 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000210 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000211 /// load/store of D registers and Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000212 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000213 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000214
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000215 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
216 /// should be 2, 3 or 4. The opcode array specifies the instructions used
217 /// for loading D registers. (Q registers are not supported.)
218 SDNode *SelectVLDDup(SDNode *N, unsigned NumVecs, unsigned *Opcodes);
219
Bob Wilson78dfbc32010-07-07 00:08:54 +0000220 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
221 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
222 /// generated to force the table registers to be consecutive.
223 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000224
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000225 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000226 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000227
Evan Cheng07ba9062009-11-19 21:45:22 +0000228 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000229 SDNode *SelectCMOVOp(SDNode *N);
230 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000231 ARMCC::CondCodes CCVal, SDValue CCR,
232 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000233 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000234 ARMCC::CondCodes CCVal, SDValue CCR,
235 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000236 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000237 ARMCC::CondCodes CCVal, SDValue CCR,
238 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000239 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000240 ARMCC::CondCodes CCVal, SDValue CCR,
241 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000242
Evan Chengde8aa4e2010-05-05 18:28:36 +0000243 SDNode *SelectConcatVector(SDNode *N);
244
Evan Chengaf4550f2009-07-02 01:23:32 +0000245 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
246 /// inline asm expressions.
247 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
248 char ConstraintCode,
249 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000250
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000251 // Form pairs of consecutive S, D, or Q registers.
252 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000253 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000254 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
255
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000256 // Form sequences of 4 consecutive S, D, or Q registers.
257 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000258 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000259 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000260
261 // Get the alignment operand for a NEON VLD or VST instruction.
262 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000263};
Evan Chenga8e29892007-01-19 07:51:42 +0000264}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000265
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000266/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
267/// operand. If so Imm will receive the 32-bit value.
268static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
269 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
270 Imm = cast<ConstantSDNode>(N)->getZExtValue();
271 return true;
272 }
273 return false;
274}
275
276// isInt32Immediate - This method tests to see if a constant operand.
277// If so Imm will receive the 32 bit value.
278static bool isInt32Immediate(SDValue N, unsigned &Imm) {
279 return isInt32Immediate(N.getNode(), Imm);
280}
281
282// isOpcWithIntImmediate - This method tests to see if the node is a specific
283// opcode and that it has a immediate integer right operand.
284// If so Imm will receive the 32 bit value.
285static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
286 return N->getOpcode() == Opc &&
287 isInt32Immediate(N->getOperand(1).getNode(), Imm);
288}
289
Evan Cheng48575f62010-12-05 22:04:16 +0000290/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
291/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
292/// least on current ARM implementations) which should be avoidded.
293bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
294 if (OptLevel == CodeGenOpt::None)
295 return true;
296
297 if (!CheckVMLxHazard)
298 return true;
299
300 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
301 return true;
302
303 if (!N->hasOneUse())
304 return false;
305
306 SDNode *Use = *N->use_begin();
307 if (Use->getOpcode() == ISD::CopyToReg)
308 return true;
309 if (Use->isMachineOpcode()) {
310 const TargetInstrDesc &TID = TII->get(Use->getMachineOpcode());
311 if (TID.mayStore())
312 return true;
313 unsigned Opcode = TID.getOpcode();
314 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
315 return true;
316 // vmlx feeding into another vmlx. We actually want to unfold
317 // the use later in the MLxExpansion pass. e.g.
318 // vmla
319 // vmla (stall 8 cycles)
320 //
321 // vmul (5 cycles)
322 // vadd (5 cycles)
323 // vmla
324 // This adds up to about 18 - 19 cycles.
325 //
326 // vmla
327 // vmul (stall 4 cycles)
328 // vadd adds up to about 14 cycles.
329 return TII->isFpMLxInstruction(Opcode);
330 }
331
332 return false;
333}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000334
Evan Chengf40deed2010-10-27 23:41:30 +0000335bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
336 ARM_AM::ShiftOpc ShOpcVal,
337 unsigned ShAmt) {
338 if (!Subtarget->isCortexA9())
339 return true;
340 if (Shift.hasOneUse())
341 return true;
342 // R << 2 is free.
343 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
344}
345
Chris Lattner52a261b2010-09-21 20:31:19 +0000346bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000347 SDValue &BaseReg,
348 SDValue &ShReg,
349 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000350 if (DisableShifterOp)
351 return false;
352
Evan Cheng055b0312009-06-29 07:51:04 +0000353 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
354
355 // Don't match base register only case. That is matched to a separate
356 // lower complexity pattern with explicit register operand.
357 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000358
Evan Cheng055b0312009-06-29 07:51:04 +0000359 BaseReg = N.getOperand(0);
360 unsigned ShImmVal = 0;
361 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000362 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000363 ShImmVal = RHS->getZExtValue() & 31;
364 } else {
365 ShReg = N.getOperand(1);
Evan Chengf40deed2010-10-27 23:41:30 +0000366 if (!isShifterOpProfitable(N, ShOpcVal, ShImmVal))
367 return false;
368 }
369 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
370 MVT::i32);
371 return true;
372}
373
374bool ARMDAGToDAGISel::SelectShiftShifterOperandReg(SDValue N,
375 SDValue &BaseReg,
376 SDValue &ShReg,
377 SDValue &Opc) {
378 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
379
380 // Don't match base register only case. That is matched to a separate
381 // lower complexity pattern with explicit register operand.
382 if (ShOpcVal == ARM_AM::no_shift) return false;
383
384 BaseReg = N.getOperand(0);
385 unsigned ShImmVal = 0;
386 // Do not check isShifterOpProfitable. This must return true.
387 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
388 ShReg = CurDAG->getRegister(0, MVT::i32);
389 ShImmVal = RHS->getZExtValue() & 31;
390 } else {
391 ShReg = N.getOperand(1);
Evan Cheng055b0312009-06-29 07:51:04 +0000392 }
393 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000394 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000395 return true;
396}
397
Jim Grosbach3e556122010-10-26 22:37:02 +0000398bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
399 SDValue &Base,
400 SDValue &OffImm) {
401 // Match simple R + imm12 operands.
402
403 // Base only.
404 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
405 if (N.getOpcode() == ISD::FrameIndex) {
406 // Match frame index...
407 int FI = cast<FrameIndexSDNode>(N)->getIndex();
408 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
409 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
410 return true;
411 } else if (N.getOpcode() == ARMISD::Wrapper &&
412 !(Subtarget->useMovt() &&
413 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
414 Base = N.getOperand(0);
415 } else
416 Base = N;
417 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
418 return true;
419 }
420
421 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
422 int RHSC = (int)RHS->getZExtValue();
423 if (N.getOpcode() == ISD::SUB)
424 RHSC = -RHSC;
425
426 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
427 Base = N.getOperand(0);
428 if (Base.getOpcode() == ISD::FrameIndex) {
429 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
430 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
431 }
432 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
433 return true;
434 }
435 }
436
437 // Base only.
438 Base = N;
439 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
440 return true;
441}
442
443
444
445bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
446 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000447 if (N.getOpcode() == ISD::MUL &&
448 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000449 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
450 // X * [3,5,9] -> X + X * [2,4,8] etc.
451 int RHSC = (int)RHS->getZExtValue();
452 if (RHSC & 1) {
453 RHSC = RHSC & ~1;
454 ARM_AM::AddrOpc AddSub = ARM_AM::add;
455 if (RHSC < 0) {
456 AddSub = ARM_AM::sub;
457 RHSC = - RHSC;
458 }
459 if (isPowerOf2_32(RHSC)) {
460 unsigned ShAmt = Log2_32(RHSC);
461 Base = Offset = N.getOperand(0);
462 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
463 ARM_AM::lsl),
464 MVT::i32);
465 return true;
466 }
467 }
468 }
469 }
470
471 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB)
472 return false;
473
474 // Leave simple R +/- imm12 operands for LDRi12
475 if (N.getOpcode() == ISD::ADD) {
476 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
477 int RHSC = (int)RHS->getZExtValue();
478 if ((RHSC >= 0 && RHSC < 0x1000) ||
479 (RHSC < 0 && RHSC > -0x1000)) // 12 bits.
480 return false;
481 }
482 }
483
Evan Chengf40deed2010-10-27 23:41:30 +0000484 if (Subtarget->isCortexA9() && !N.hasOneUse())
485 // Compute R +/- (R << N) and reuse it.
486 return false;
487
Jim Grosbach3e556122010-10-26 22:37:02 +0000488 // Otherwise this is R +/- [possibly shifted] R.
489 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
490 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
491 unsigned ShAmt = 0;
492
493 Base = N.getOperand(0);
494 Offset = N.getOperand(1);
495
496 if (ShOpcVal != ARM_AM::no_shift) {
497 // Check to see if the RHS of the shift is a constant, if not, we can't fold
498 // it.
499 if (ConstantSDNode *Sh =
500 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
501 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000502 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
503 Offset = N.getOperand(1).getOperand(0);
504 else {
505 ShAmt = 0;
506 ShOpcVal = ARM_AM::no_shift;
507 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000508 } else {
509 ShOpcVal = ARM_AM::no_shift;
510 }
511 }
512
513 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000514 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
515 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000516 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
517 if (ShOpcVal != ARM_AM::no_shift) {
518 // Check to see if the RHS of the shift is a constant, if not, we can't
519 // fold it.
520 if (ConstantSDNode *Sh =
521 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
522 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000523 if (!Subtarget->isCortexA9() ||
524 (N.hasOneUse() &&
525 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
526 Offset = N.getOperand(0).getOperand(0);
527 Base = N.getOperand(1);
528 } else {
529 ShAmt = 0;
530 ShOpcVal = ARM_AM::no_shift;
531 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000532 } else {
533 ShOpcVal = ARM_AM::no_shift;
534 }
535 }
536 }
537
538 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
539 MVT::i32);
540 return true;
541}
542
543
544
545
546//-----
547
Jim Grosbach82891622010-09-29 19:03:54 +0000548AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
549 SDValue &Base,
550 SDValue &Offset,
551 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000552 if (N.getOpcode() == ISD::MUL &&
553 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000554 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
555 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000556 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000557 if (RHSC & 1) {
558 RHSC = RHSC & ~1;
559 ARM_AM::AddrOpc AddSub = ARM_AM::add;
560 if (RHSC < 0) {
561 AddSub = ARM_AM::sub;
562 RHSC = - RHSC;
563 }
564 if (isPowerOf2_32(RHSC)) {
565 unsigned ShAmt = Log2_32(RHSC);
566 Base = Offset = N.getOperand(0);
567 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
568 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000569 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000570 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000571 }
572 }
573 }
574 }
575
Evan Chenga8e29892007-01-19 07:51:42 +0000576 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
577 Base = N;
578 if (N.getOpcode() == ISD::FrameIndex) {
579 int FI = cast<FrameIndexSDNode>(N)->getIndex();
580 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000581 } else if (N.getOpcode() == ARMISD::Wrapper &&
582 !(Subtarget->useMovt() &&
583 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000584 Base = N.getOperand(0);
585 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000586 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000587 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
588 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000589 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000590 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000591 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000592
Evan Chenga8e29892007-01-19 07:51:42 +0000593 // Match simple R +/- imm12 operands.
Jim Grosbachbe912322010-09-29 17:32:29 +0000594 if (N.getOpcode() == ISD::ADD) {
Evan Chenga8e29892007-01-19 07:51:42 +0000595 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000596 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000597 if ((RHSC >= 0 && RHSC < 0x1000) ||
598 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000599 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000600 if (Base.getOpcode() == ISD::FrameIndex) {
601 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
602 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
603 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000604 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000605
606 ARM_AM::AddrOpc AddSub = ARM_AM::add;
607 if (RHSC < 0) {
608 AddSub = ARM_AM::sub;
609 RHSC = - RHSC;
610 }
611 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000612 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000613 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000614 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000615 }
Evan Chenga8e29892007-01-19 07:51:42 +0000616 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000617 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000618
Evan Chengf40deed2010-10-27 23:41:30 +0000619 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
620 // Compute R +/- (R << N) and reuse it.
621 Base = N;
622 Offset = CurDAG->getRegister(0, MVT::i32);
623 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
624 ARM_AM::no_shift),
625 MVT::i32);
626 return AM2_BASE;
627 }
628
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000629 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000630 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
631 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
632 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000633
Evan Chenga8e29892007-01-19 07:51:42 +0000634 Base = N.getOperand(0);
635 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000636
Evan Chenga8e29892007-01-19 07:51:42 +0000637 if (ShOpcVal != ARM_AM::no_shift) {
638 // Check to see if the RHS of the shift is a constant, if not, we can't fold
639 // it.
640 if (ConstantSDNode *Sh =
641 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000642 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000643 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
644 Offset = N.getOperand(1).getOperand(0);
645 else {
646 ShAmt = 0;
647 ShOpcVal = ARM_AM::no_shift;
648 }
Evan Chenga8e29892007-01-19 07:51:42 +0000649 } else {
650 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000651 }
652 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000653
Evan Chenga8e29892007-01-19 07:51:42 +0000654 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000655 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
656 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chenga8e29892007-01-19 07:51:42 +0000657 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
658 if (ShOpcVal != ARM_AM::no_shift) {
659 // Check to see if the RHS of the shift is a constant, if not, we can't
660 // fold it.
661 if (ConstantSDNode *Sh =
662 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000663 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000664 if (!Subtarget->isCortexA9() ||
665 (N.hasOneUse() &&
666 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
667 Offset = N.getOperand(0).getOperand(0);
668 Base = N.getOperand(1);
669 } else {
670 ShAmt = 0;
671 ShOpcVal = ARM_AM::no_shift;
672 }
Evan Chenga8e29892007-01-19 07:51:42 +0000673 } else {
674 ShOpcVal = ARM_AM::no_shift;
675 }
676 }
677 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000678
Evan Chenga8e29892007-01-19 07:51:42 +0000679 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000680 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000681 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000682}
683
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000684bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000685 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000686 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000687 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
688 ? cast<LoadSDNode>(Op)->getAddressingMode()
689 : cast<StoreSDNode>(Op)->getAddressingMode();
690 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
691 ? ARM_AM::add : ARM_AM::sub;
692 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000693 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000694 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000695 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000696 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
697 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000698 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000699 return true;
700 }
701 }
702
703 Offset = N;
704 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
705 unsigned ShAmt = 0;
706 if (ShOpcVal != ARM_AM::no_shift) {
707 // Check to see if the RHS of the shift is a constant, if not, we can't fold
708 // it.
709 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000710 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000711 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
712 Offset = N.getOperand(0);
713 else {
714 ShAmt = 0;
715 ShOpcVal = ARM_AM::no_shift;
716 }
Evan Chenga8e29892007-01-19 07:51:42 +0000717 } else {
718 ShOpcVal = ARM_AM::no_shift;
719 }
720 }
721
722 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000723 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000724 return true;
725}
726
Evan Chenga8e29892007-01-19 07:51:42 +0000727
Chris Lattner52a261b2010-09-21 20:31:19 +0000728bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000729 SDValue &Base, SDValue &Offset,
730 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000731 if (N.getOpcode() == ISD::SUB) {
732 // X - C is canonicalize to X + -C, no need to handle it here.
733 Base = N.getOperand(0);
734 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000735 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000736 return true;
737 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000738
Evan Chenga8e29892007-01-19 07:51:42 +0000739 if (N.getOpcode() != ISD::ADD) {
740 Base = N;
741 if (N.getOpcode() == ISD::FrameIndex) {
742 int FI = cast<FrameIndexSDNode>(N)->getIndex();
743 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
744 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000745 Offset = CurDAG->getRegister(0, MVT::i32);
746 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000747 return true;
748 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000749
Evan Chenga8e29892007-01-19 07:51:42 +0000750 // If the RHS is +/- imm8, fold into addr mode.
751 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000752 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000753 if ((RHSC >= 0 && RHSC < 256) ||
754 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000755 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000756 if (Base.getOpcode() == ISD::FrameIndex) {
757 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
758 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
759 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000760 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000761
762 ARM_AM::AddrOpc AddSub = ARM_AM::add;
763 if (RHSC < 0) {
764 AddSub = ARM_AM::sub;
765 RHSC = - RHSC;
766 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000767 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000768 return true;
769 }
770 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000771
Evan Chenga8e29892007-01-19 07:51:42 +0000772 Base = N.getOperand(0);
773 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000774 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000775 return true;
776}
777
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000778bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000779 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000780 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000781 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
782 ? cast<LoadSDNode>(Op)->getAddressingMode()
783 : cast<StoreSDNode>(Op)->getAddressingMode();
784 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
785 ? ARM_AM::add : ARM_AM::sub;
786 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000787 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000788 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000789 Offset = CurDAG->getRegister(0, MVT::i32);
790 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000791 return true;
792 }
793 }
794
795 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000796 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000797 return true;
798}
799
Jim Grosbach3ab56582010-10-21 19:38:40 +0000800bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000801 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000802 if (N.getOpcode() != ISD::ADD) {
803 Base = N;
804 if (N.getOpcode() == ISD::FrameIndex) {
805 int FI = cast<FrameIndexSDNode>(N)->getIndex();
806 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000807 } else if (N.getOpcode() == ARMISD::Wrapper &&
808 !(Subtarget->useMovt() &&
809 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000810 Base = N.getOperand(0);
811 }
812 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000813 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000814 return true;
815 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000816
Evan Chenga8e29892007-01-19 07:51:42 +0000817 // If the RHS is +/- imm8, fold into addr mode.
818 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000819 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000820 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
821 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000822 if ((RHSC >= 0 && RHSC < 256) ||
823 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000824 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000825 if (Base.getOpcode() == ISD::FrameIndex) {
826 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
827 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
828 }
829
830 ARM_AM::AddrOpc AddSub = ARM_AM::add;
831 if (RHSC < 0) {
832 AddSub = ARM_AM::sub;
833 RHSC = - RHSC;
834 }
835 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000836 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000837 return true;
838 }
839 }
840 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000841
Evan Chenga8e29892007-01-19 07:51:42 +0000842 Base = N;
843 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000844 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000845 return true;
846}
847
Bob Wilson665814b2010-11-01 23:40:51 +0000848bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
849 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000850 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000851
852 unsigned Alignment = 0;
853 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
854 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
855 // The maximum alignment is equal to the memory size being referenced.
856 unsigned LSNAlign = LSN->getAlignment();
857 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
858 if (LSNAlign > MemSize && MemSize > 1)
859 Alignment = MemSize;
860 } else {
861 // All other uses of addrmode6 are for intrinsics. For now just record
862 // the raw alignment value; it will be refined later based on the legal
863 // alignment operands for the intrinsic.
864 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
865 }
866
867 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000868 return true;
869}
870
Chris Lattner52a261b2010-09-21 20:31:19 +0000871bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000872 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000873 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
874 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000875 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000876 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000877 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000878 return true;
879 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000880
Evan Chenga8e29892007-01-19 07:51:42 +0000881 return false;
882}
883
Bill Wendlingf4caf692010-12-14 03:36:38 +0000884
885//===----------------------------------------------------------------------===//
886// Thumb Addressing Modes
887//===----------------------------------------------------------------------===//
888
889
Chris Lattner52a261b2010-09-21 20:31:19 +0000890bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000891 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000892 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000893 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000894 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000895 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000896 return false;
897
898 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000899 return true;
900 }
901
Evan Chenga8e29892007-01-19 07:51:42 +0000902 Base = N.getOperand(0);
903 Offset = N.getOperand(1);
904 return true;
905}
906
Evan Cheng79d43262007-01-24 02:21:22 +0000907bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000908ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
909 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000910 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000911 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000912 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000913 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000914
Evan Cheng012f2d92007-01-24 08:53:17 +0000915 if (N.getOpcode() == ARMISD::Wrapper &&
916 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
917 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000918 }
919
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000920 if (N.getOpcode() != ISD::ADD)
921 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000922
Evan Chengad0e4652007-02-06 00:22:06 +0000923 // Thumb does not have [sp, r] address mode.
924 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
925 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
926 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000927 (RHSR && RHSR->getReg() == ARM::SP))
928 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000929
930 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
931 int RHSC = (int)RHS->getZExtValue();
932
933 if ((RHSC & (Scale - 1)) == 0) { // The constant is implicitly multiplied.
934 RHSC /= Scale;
935
936 if (RHSC >= 0 && RHSC < 32)
937 return false;
938 }
939 }
940
941 Base = N.getOperand(0);
942 Offset = N.getOperand(1);
943 return true;
944}
945
946bool
947ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
948 SDValue &Base,
949 SDValue &Offset) {
950 return SelectThumbAddrModeRI(N, Base, Offset, 1);
951}
952
953bool
954ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
955 SDValue &Base,
956 SDValue &Offset) {
957 return SelectThumbAddrModeRI(N, Base, Offset, 2);
958}
959
960bool
961ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
962 SDValue &Base,
963 SDValue &Offset) {
964 return SelectThumbAddrModeRI(N, Base, Offset, 4);
965}
966
967bool
968ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
969 SDValue &Base, SDValue &OffImm) {
970 if (Scale == 4) {
971 SDValue TmpBase, TmpOffImm;
972 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
973 return false; // We want to select tLDRspi / tSTRspi instead.
974
975 if (N.getOpcode() == ARMISD::Wrapper &&
976 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
977 return false; // We want to select tLDRpci instead.
978 }
979
980 if (N.getOpcode() != ISD::ADD) {
981 if (N.getOpcode() == ARMISD::Wrapper &&
982 !(Subtarget->useMovt() &&
983 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
984 Base = N.getOperand(0);
985 } else {
986 Base = N;
987 }
988
Owen Anderson825b72b2009-08-11 20:47:22 +0000989 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000990 return true;
991 }
992
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000993 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
994 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
995 if ((LHSR && LHSR->getReg() == ARM::SP) ||
996 (RHSR && RHSR->getReg() == ARM::SP)) {
997 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
998 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
999 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1000 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1001
1002 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1003 if (LHSC != 0 || RHSC != 0) return false;
1004
1005 Base = N;
1006 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1007 return true;
1008 }
1009
Evan Chenga8e29892007-01-19 07:51:42 +00001010 // If the RHS is + imm5 * scale, fold into addr mode.
1011 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001012 int RHSC = (int)RHS->getZExtValue();
Bill Wendlingf4caf692010-12-14 03:36:38 +00001013
1014 if ((RHSC & (Scale - 1)) == 0) { // The constant is implicitly multiplied.
Evan Chenga8e29892007-01-19 07:51:42 +00001015 RHSC /= Scale;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001016
Evan Chenga8e29892007-01-19 07:51:42 +00001017 if (RHSC >= 0 && RHSC < 32) {
1018 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001019 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001020 return true;
1021 }
1022 }
1023 }
1024
Evan Chengc38f2bc2007-01-23 22:59:13 +00001025 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001026 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001027 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001028}
1029
Bill Wendlingf4caf692010-12-14 03:36:38 +00001030bool
1031ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1032 SDValue &OffImm) {
1033 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001034}
1035
Bill Wendlingf4caf692010-12-14 03:36:38 +00001036bool
1037ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1038 SDValue &OffImm) {
1039 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001040}
1041
Bill Wendlingf4caf692010-12-14 03:36:38 +00001042bool
1043ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1044 SDValue &OffImm) {
1045 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001046}
1047
Chris Lattner52a261b2010-09-21 20:31:19 +00001048bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1049 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001050 if (N.getOpcode() == ISD::FrameIndex) {
1051 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1052 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001053 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001054 return true;
1055 }
Evan Cheng79d43262007-01-24 02:21:22 +00001056
Evan Chengad0e4652007-02-06 00:22:06 +00001057 if (N.getOpcode() != ISD::ADD)
1058 return false;
1059
1060 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001061 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1062 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001063 // If the RHS is + imm8 * scale, fold into addr mode.
1064 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001065 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +00001066 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
1067 RHSC >>= 2;
1068 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +00001069 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001070 if (Base.getOpcode() == ISD::FrameIndex) {
1071 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1072 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1073 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001074 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +00001075 return true;
1076 }
1077 }
1078 }
1079 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001080
Evan Chenga8e29892007-01-19 07:51:42 +00001081 return false;
1082}
1083
Bill Wendlingf4caf692010-12-14 03:36:38 +00001084
1085//===----------------------------------------------------------------------===//
1086// Thumb 2 Addressing Modes
1087//===----------------------------------------------------------------------===//
1088
1089
Chris Lattner52a261b2010-09-21 20:31:19 +00001090bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001091 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001092 if (DisableShifterOp)
1093 return false;
1094
Evan Cheng9cb9e672009-06-27 02:26:13 +00001095 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
1096
1097 // Don't match base register only case. That is matched to a separate
1098 // lower complexity pattern with explicit register operand.
1099 if (ShOpcVal == ARM_AM::no_shift) return false;
1100
1101 BaseReg = N.getOperand(0);
1102 unsigned ShImmVal = 0;
1103 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1104 ShImmVal = RHS->getZExtValue() & 31;
1105 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1106 return true;
1107 }
1108
1109 return false;
1110}
1111
Chris Lattner52a261b2010-09-21 20:31:19 +00001112bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001113 SDValue &Base, SDValue &OffImm) {
1114 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001115
Evan Cheng3a214252009-08-11 08:52:18 +00001116 // Base only.
1117 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001118 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +00001119 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +00001120 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1121 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001122 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001123 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001124 } else if (N.getOpcode() == ARMISD::Wrapper &&
1125 !(Subtarget->useMovt() &&
1126 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001127 Base = N.getOperand(0);
1128 if (Base.getOpcode() == ISD::TargetConstantPool)
1129 return false; // We want to select t2LDRpci instead.
1130 } else
1131 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001132 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001133 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001134 }
Evan Cheng055b0312009-06-29 07:51:04 +00001135
1136 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001137 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001138 // Let t2LDRi8 handle (R - imm8).
1139 return false;
1140
Evan Cheng055b0312009-06-29 07:51:04 +00001141 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001142 if (N.getOpcode() == ISD::SUB)
1143 RHSC = -RHSC;
1144
1145 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001146 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001147 if (Base.getOpcode() == ISD::FrameIndex) {
1148 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1149 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1150 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001151 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001152 return true;
1153 }
1154 }
1155
Evan Cheng3a214252009-08-11 08:52:18 +00001156 // Base only.
1157 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001158 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001159 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001160}
1161
Chris Lattner52a261b2010-09-21 20:31:19 +00001162bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001163 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001164 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +00001165 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +00001166 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1167 int RHSC = (int)RHS->getSExtValue();
1168 if (N.getOpcode() == ISD::SUB)
1169 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001170
Evan Cheng3a214252009-08-11 08:52:18 +00001171 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1172 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +00001173 if (Base.getOpcode() == ISD::FrameIndex) {
1174 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1175 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1176 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001177 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +00001178 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001179 }
Evan Cheng055b0312009-06-29 07:51:04 +00001180 }
1181 }
1182
1183 return false;
1184}
1185
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001186bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001187 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001188 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001189 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1190 ? cast<LoadSDNode>(Op)->getAddressingMode()
1191 : cast<StoreSDNode>(Op)->getAddressingMode();
1192 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
1193 int RHSC = (int)RHS->getZExtValue();
1194 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +00001195 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +00001196 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1197 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001198 return true;
1199 }
1200 }
1201
1202 return false;
1203}
1204
Chris Lattner52a261b2010-09-21 20:31:19 +00001205bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001206 SDValue &Base,
1207 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001208 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
1209 if (N.getOpcode() != ISD::ADD)
1210 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001211
Evan Cheng3a214252009-08-11 08:52:18 +00001212 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1213 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1214 int RHSC = (int)RHS->getZExtValue();
1215 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1216 return false;
1217 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001218 return false;
1219 }
1220
Evan Chengf40deed2010-10-27 23:41:30 +00001221 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1222 // Compute R + (R << [1,2,3]) and reuse it.
1223 Base = N;
1224 return false;
1225 }
1226
Evan Cheng055b0312009-06-29 07:51:04 +00001227 // Look for (R + R) or (R + (R << [1,2,3])).
1228 unsigned ShAmt = 0;
1229 Base = N.getOperand(0);
1230 OffReg = N.getOperand(1);
1231
1232 // Swap if it is ((R << c) + R).
1233 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1234 if (ShOpcVal != ARM_AM::lsl) {
1235 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1236 if (ShOpcVal == ARM_AM::lsl)
1237 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001238 }
1239
Evan Cheng055b0312009-06-29 07:51:04 +00001240 if (ShOpcVal == ARM_AM::lsl) {
1241 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1242 // it.
1243 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1244 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001245 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1246 OffReg = OffReg.getOperand(0);
1247 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001248 ShAmt = 0;
1249 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001250 }
Evan Cheng055b0312009-06-29 07:51:04 +00001251 } else {
1252 ShOpcVal = ARM_AM::no_shift;
1253 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001254 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001255
Owen Anderson825b72b2009-08-11 20:47:22 +00001256 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001257
1258 return true;
1259}
1260
1261//===--------------------------------------------------------------------===//
1262
Evan Chengee568cf2007-07-05 07:15:27 +00001263/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001264static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001265 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001266}
1267
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001268SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1269 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001270 ISD::MemIndexedMode AM = LD->getAddressingMode();
1271 if (AM == ISD::UNINDEXED)
1272 return NULL;
1273
Owen Andersone50ed302009-08-10 22:56:29 +00001274 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001275 SDValue Offset, AMOpc;
1276 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1277 unsigned Opcode = 0;
1278 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001279 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001280 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001281 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1282 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001283 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001284 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001285 Match = true;
1286 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1287 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1288 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001289 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001290 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001291 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001292 Match = true;
1293 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1294 }
1295 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001296 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001297 Match = true;
1298 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1299 }
1300 }
1301 }
1302
1303 if (Match) {
1304 SDValue Chain = LD->getChain();
1305 SDValue Base = LD->getBasePtr();
1306 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001307 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001308 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001309 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001310 }
1311
1312 return NULL;
1313}
1314
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001315SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1316 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001317 ISD::MemIndexedMode AM = LD->getAddressingMode();
1318 if (AM == ISD::UNINDEXED)
1319 return NULL;
1320
Owen Andersone50ed302009-08-10 22:56:29 +00001321 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001322 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001323 SDValue Offset;
1324 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1325 unsigned Opcode = 0;
1326 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001327 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001328 switch (LoadedVT.getSimpleVT().SimpleTy) {
1329 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001330 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1331 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001332 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001333 if (isSExtLd)
1334 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1335 else
1336 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001337 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001338 case MVT::i8:
1339 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001340 if (isSExtLd)
1341 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1342 else
1343 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001344 break;
1345 default:
1346 return NULL;
1347 }
1348 Match = true;
1349 }
1350
1351 if (Match) {
1352 SDValue Chain = LD->getChain();
1353 SDValue Base = LD->getBasePtr();
1354 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001355 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001356 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001357 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001358 }
1359
1360 return NULL;
1361}
1362
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001363/// PairSRegs - Form a D register from a pair of S registers.
1364///
1365SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1366 DebugLoc dl = V0.getNode()->getDebugLoc();
1367 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1368 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001369 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1370 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001371}
1372
Evan Cheng603afbf2010-05-10 17:34:18 +00001373/// PairDRegs - Form a quad register from a pair of D registers.
1374///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001375SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1376 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001377 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1378 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001379 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1380 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001381}
1382
Evan Cheng7f687192010-05-14 00:21:45 +00001383/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001384///
1385SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1386 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001387 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1388 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001389 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1390 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1391}
1392
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001393/// QuadSRegs - Form 4 consecutive S registers.
1394///
1395SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1396 SDValue V2, SDValue V3) {
1397 DebugLoc dl = V0.getNode()->getDebugLoc();
1398 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1399 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1400 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1401 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1402 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1403 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1404}
1405
Evan Cheng7f687192010-05-14 00:21:45 +00001406/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001407///
1408SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1409 SDValue V2, SDValue V3) {
1410 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001411 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1412 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1413 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1414 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001415 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1416 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1417}
1418
Evan Cheng8f6de382010-05-16 03:27:48 +00001419/// QuadQRegs - Form 4 consecutive Q registers.
1420///
1421SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1422 SDValue V2, SDValue V3) {
1423 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001424 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1425 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1426 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1427 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001428 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1429 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1430}
1431
Bob Wilson2a6e6162010-09-23 23:42:37 +00001432/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1433/// of a NEON VLD or VST instruction. The supported values depend on the
1434/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001435SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1436 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001437 unsigned NumRegs = NumVecs;
1438 if (!is64BitVector && NumVecs < 3)
1439 NumRegs *= 2;
1440
Bob Wilson665814b2010-11-01 23:40:51 +00001441 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001442 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001443 Alignment = 32;
1444 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1445 Alignment = 16;
1446 else if (Alignment >= 8)
1447 Alignment = 8;
1448 else
1449 Alignment = 0;
1450
1451 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001452}
1453
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001454SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001455 unsigned *DOpcodes, unsigned *QOpcodes0,
1456 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001457 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001458 DebugLoc dl = N->getDebugLoc();
1459
Bob Wilson226036e2010-03-20 22:13:40 +00001460 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001461 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001462 return NULL;
1463
1464 SDValue Chain = N->getOperand(0);
1465 EVT VT = N->getValueType(0);
1466 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001467 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001468
Bob Wilson3e36f132009-10-14 17:28:52 +00001469 unsigned OpcodeIndex;
1470 switch (VT.getSimpleVT().SimpleTy) {
1471 default: llvm_unreachable("unhandled vld type");
1472 // Double-register operations:
1473 case MVT::v8i8: OpcodeIndex = 0; break;
1474 case MVT::v4i16: OpcodeIndex = 1; break;
1475 case MVT::v2f32:
1476 case MVT::v2i32: OpcodeIndex = 2; break;
1477 case MVT::v1i64: OpcodeIndex = 3; break;
1478 // Quad-register operations:
1479 case MVT::v16i8: OpcodeIndex = 0; break;
1480 case MVT::v8i16: OpcodeIndex = 1; break;
1481 case MVT::v4f32:
1482 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001483 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001484 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001485 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001486 }
1487
Bob Wilsonf5721912010-09-03 18:16:02 +00001488 EVT ResTy;
1489 if (NumVecs == 1)
1490 ResTy = VT;
1491 else {
1492 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1493 if (!is64BitVector)
1494 ResTyElts *= 2;
1495 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1496 }
1497
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001498 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001499 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilsonf5721912010-09-03 18:16:02 +00001500 SDValue SuperReg;
Bob Wilson3e36f132009-10-14 17:28:52 +00001501 if (is64BitVector) {
1502 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001503 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonf5721912010-09-03 18:16:02 +00001504 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001505 if (NumVecs == 1)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001506 return VLd;
1507
Bob Wilsonf5721912010-09-03 18:16:02 +00001508 SuperReg = SDValue(VLd, 0);
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001509 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001510 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001511 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Bob Wilsonffde0802010-09-02 16:00:54 +00001512 dl, VT, SuperReg);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001513 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001514 }
Bob Wilsonf5721912010-09-03 18:16:02 +00001515 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
Evan Chenge9e2ba02010-05-10 21:26:24 +00001516 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001517 }
1518
Bob Wilson621f1952010-03-23 05:25:43 +00001519 if (NumVecs <= 2) {
1520 // Quad registers are directly supported for VLD1 and VLD2,
1521 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001522 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001523 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonffde0802010-09-02 16:00:54 +00001524 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001525 if (NumVecs == 1)
1526 return VLd;
1527
Bob Wilsonf5721912010-09-03 18:16:02 +00001528 SuperReg = SDValue(VLd, 0);
Bob Wilsonffde0802010-09-02 16:00:54 +00001529 Chain = SDValue(VLd, 1);
1530
Bob Wilson3e36f132009-10-14 17:28:52 +00001531 } else {
1532 // Otherwise, quad registers are loaded with two separate instructions,
1533 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001534 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001535
Bob Wilson24f995d2009-10-14 18:32:29 +00001536 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001537 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001538 SDValue ImplDef =
1539 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1540 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
1541 SDNode *VLdA =
1542 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsA, 7);
1543 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001544
Bob Wilson24f995d2009-10-14 18:32:29 +00001545 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001546 Opc = QOpcodes1[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001547 const SDValue OpsB[] = { SDValue(VLdA, 1), Align, Reg0, SDValue(VLdA, 0),
1548 Pred, Reg0, Chain };
1549 SDNode *VLdB =
1550 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsB, 7);
1551 SuperReg = SDValue(VLdB, 0);
1552 Chain = SDValue(VLdB, 2);
1553 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001554
Bob Wilsonf5721912010-09-03 18:16:02 +00001555 // Extract out the Q registers.
1556 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1557 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1558 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1559 dl, VT, SuperReg);
1560 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001561 }
1562 ReplaceUses(SDValue(N, NumVecs), Chain);
1563 return NULL;
1564}
1565
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001566SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001567 unsigned *DOpcodes, unsigned *QOpcodes0,
1568 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001569 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001570 DebugLoc dl = N->getDebugLoc();
1571
Bob Wilson226036e2010-03-20 22:13:40 +00001572 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001573 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001574 return NULL;
1575
1576 SDValue Chain = N->getOperand(0);
1577 EVT VT = N->getOperand(3).getValueType();
1578 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001579 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001580
Bob Wilson24f995d2009-10-14 18:32:29 +00001581 unsigned OpcodeIndex;
1582 switch (VT.getSimpleVT().SimpleTy) {
1583 default: llvm_unreachable("unhandled vst type");
1584 // Double-register operations:
1585 case MVT::v8i8: OpcodeIndex = 0; break;
1586 case MVT::v4i16: OpcodeIndex = 1; break;
1587 case MVT::v2f32:
1588 case MVT::v2i32: OpcodeIndex = 2; break;
1589 case MVT::v1i64: OpcodeIndex = 3; break;
1590 // Quad-register operations:
1591 case MVT::v16i8: OpcodeIndex = 0; break;
1592 case MVT::v8i16: OpcodeIndex = 1; break;
1593 case MVT::v4f32:
1594 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001595 case MVT::v2i64: OpcodeIndex = 3;
1596 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1597 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001598 }
1599
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001600 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001601 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001602
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001603 SmallVector<SDValue, 7> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001604 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001605 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001606
1607 if (is64BitVector) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001608 if (NumVecs == 1) {
1609 Ops.push_back(N->getOperand(3));
1610 } else {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001611 SDValue RegSeq;
1612 SDValue V0 = N->getOperand(0+3);
1613 SDValue V1 = N->getOperand(1+3);
1614
1615 // Form a REG_SEQUENCE to force register allocation.
1616 if (NumVecs == 2)
1617 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1618 else {
1619 SDValue V2 = N->getOperand(2+3);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001620 // If it's a vld3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001621 // an undef.
1622 SDValue V3 = (NumVecs == 3)
1623 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1624 : N->getOperand(3+3);
1625 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1626 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001627 Ops.push_back(RegSeq);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001628 }
Evan Chengac0869d2009-11-21 06:21:52 +00001629 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001630 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001631 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001632 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001633 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001634 }
1635
Bob Wilson11d98992010-03-23 06:20:33 +00001636 if (NumVecs <= 2) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001637 // Quad registers are directly supported for VST1 and VST2.
Bob Wilson24f995d2009-10-14 18:32:29 +00001638 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001639 if (NumVecs == 1) {
1640 Ops.push_back(N->getOperand(3));
1641 } else {
1642 // Form a QQ register.
Evan Cheng603afbf2010-05-10 17:34:18 +00001643 SDValue Q0 = N->getOperand(3);
1644 SDValue Q1 = N->getOperand(4);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001645 Ops.push_back(SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0));
Bob Wilson24f995d2009-10-14 18:32:29 +00001646 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001647 Ops.push_back(Pred);
1648 Ops.push_back(Reg0); // predicate register
1649 Ops.push_back(Chain);
1650 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001651 }
1652
1653 // Otherwise, quad registers are stored with two separate instructions,
1654 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001655
Bob Wilson07f6e802010-06-16 21:34:01 +00001656 // Form the QQQQ REG_SEQUENCE.
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001657 SDValue V0 = N->getOperand(0+3);
1658 SDValue V1 = N->getOperand(1+3);
1659 SDValue V2 = N->getOperand(2+3);
1660 SDValue V3 = (NumVecs == 3)
1661 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1662 : N->getOperand(3+3);
1663 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001664
1665 // Store the even D registers.
Bob Wilson07f6e802010-06-16 21:34:01 +00001666 Ops.push_back(Reg0); // post-access address offset
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001667 Ops.push_back(RegSeq);
Bob Wilson07f6e802010-06-16 21:34:01 +00001668 Ops.push_back(Pred);
1669 Ops.push_back(Reg0); // predicate register
1670 Ops.push_back(Chain);
1671 unsigned Opc = QOpcodes0[OpcodeIndex];
1672 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001673 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001674 Chain = SDValue(VStA, 1);
1675
1676 // Store the odd D registers.
1677 Ops[0] = SDValue(VStA, 0); // MemAddr
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001678 Ops[6] = Chain;
Bob Wilson07f6e802010-06-16 21:34:01 +00001679 Opc = QOpcodes1[OpcodeIndex];
1680 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001681 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001682 Chain = SDValue(VStB, 1);
1683 ReplaceUses(SDValue(N, 0), Chain);
1684 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001685}
1686
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001687SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001688 unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001689 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001690 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001691 DebugLoc dl = N->getDebugLoc();
1692
Bob Wilson226036e2010-03-20 22:13:40 +00001693 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001694 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001695 return NULL;
1696
1697 SDValue Chain = N->getOperand(0);
1698 unsigned Lane =
1699 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001700 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001701 bool is64BitVector = VT.is64BitVector();
1702
Bob Wilson665814b2010-11-01 23:40:51 +00001703 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001704 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001705 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001706 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1707 if (Alignment > NumBytes)
1708 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001709 if (Alignment < 8 && Alignment < NumBytes)
1710 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001711 // Alignment must be a power of two; make sure of that.
1712 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001713 if (Alignment == 1)
1714 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001715 }
Bob Wilson665814b2010-11-01 23:40:51 +00001716 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001717
Bob Wilsona7c397c2009-10-14 16:19:03 +00001718 unsigned OpcodeIndex;
1719 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001720 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001721 // Double-register operations:
1722 case MVT::v8i8: OpcodeIndex = 0; break;
1723 case MVT::v4i16: OpcodeIndex = 1; break;
1724 case MVT::v2f32:
1725 case MVT::v2i32: OpcodeIndex = 2; break;
1726 // Quad-register operations:
1727 case MVT::v8i16: OpcodeIndex = 0; break;
1728 case MVT::v4f32:
1729 case MVT::v4i32: OpcodeIndex = 1; break;
1730 }
1731
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001732 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001733 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001734
Bob Wilson8466fa12010-09-13 23:01:35 +00001735 SmallVector<SDValue, 7> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001736 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001737 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001738
Jim Grosbach3ab56582010-10-21 19:38:40 +00001739 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
Eric Christopher23da0b22010-09-14 08:31:25 +00001740 QOpcodes[OpcodeIndex]);
Bob Wilson07f6e802010-06-16 21:34:01 +00001741
Bob Wilson8466fa12010-09-13 23:01:35 +00001742 SDValue SuperReg;
1743 SDValue V0 = N->getOperand(0+3);
1744 SDValue V1 = N->getOperand(1+3);
1745 if (NumVecs == 2) {
1746 if (is64BitVector)
1747 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1748 else
1749 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001750 } else {
Bob Wilson8466fa12010-09-13 23:01:35 +00001751 SDValue V2 = N->getOperand(2+3);
1752 SDValue V3 = (NumVecs == 3)
1753 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1754 : N->getOperand(3+3);
1755 if (is64BitVector)
1756 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1757 else
1758 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001759 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001760 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001761 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001762 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001763 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001764 Ops.push_back(Chain);
1765
Bob Wilson96493442009-10-14 16:46:45 +00001766 if (!IsLoad)
Bob Wilson8466fa12010-09-13 23:01:35 +00001767 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 7);
Bob Wilson96493442009-10-14 16:46:45 +00001768
Bob Wilson8466fa12010-09-13 23:01:35 +00001769 EVT ResTy;
1770 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1771 if (!is64BitVector)
1772 ResTyElts *= 2;
1773 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001774
Bob Wilson8466fa12010-09-13 23:01:35 +00001775 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other,
1776 Ops.data(), 7);
1777 SuperReg = SDValue(VLdLn, 0);
1778 Chain = SDValue(VLdLn, 1);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001779
Bob Wilson8466fa12010-09-13 23:01:35 +00001780 // Extract the subregisters.
Bob Wilson07f6e802010-06-16 21:34:01 +00001781 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1782 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1783 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1784 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1785 ReplaceUses(SDValue(N, Vec),
Bob Wilson8466fa12010-09-13 23:01:35 +00001786 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1787 ReplaceUses(SDValue(N, NumVecs), Chain);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001788 return NULL;
1789}
1790
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001791SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, unsigned NumVecs,
1792 unsigned *Opcodes) {
1793 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1794 DebugLoc dl = N->getDebugLoc();
1795
1796 SDValue MemAddr, Align;
1797 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1798 return NULL;
1799
1800 SDValue Chain = N->getOperand(0);
1801 EVT VT = N->getValueType(0);
1802
1803 unsigned Alignment = 0;
1804 if (NumVecs != 3) {
1805 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1806 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1807 if (Alignment > NumBytes)
1808 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001809 if (Alignment < 8 && Alignment < NumBytes)
1810 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001811 // Alignment must be a power of two; make sure of that.
1812 Alignment = (Alignment & -Alignment);
1813 if (Alignment == 1)
1814 Alignment = 0;
1815 }
1816 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1817
1818 unsigned OpcodeIndex;
1819 switch (VT.getSimpleVT().SimpleTy) {
1820 default: llvm_unreachable("unhandled vld-dup type");
1821 case MVT::v8i8: OpcodeIndex = 0; break;
1822 case MVT::v4i16: OpcodeIndex = 1; break;
1823 case MVT::v2f32:
1824 case MVT::v2i32: OpcodeIndex = 2; break;
1825 }
1826
1827 SDValue Pred = getAL(CurDAG);
1828 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1829 SDValue SuperReg;
1830 unsigned Opc = Opcodes[OpcodeIndex];
1831 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
1832
1833 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1834 EVT ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1835 SDNode *VLdDup = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
1836 SuperReg = SDValue(VLdDup, 0);
1837 Chain = SDValue(VLdDup, 1);
1838
1839 // Extract the subregisters.
1840 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1841 unsigned SubIdx = ARM::dsub_0;
1842 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1843 ReplaceUses(SDValue(N, Vec),
1844 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1845 ReplaceUses(SDValue(N, NumVecs), Chain);
1846 return NULL;
1847}
1848
Bob Wilson78dfbc32010-07-07 00:08:54 +00001849SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1850 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001851 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1852 DebugLoc dl = N->getDebugLoc();
1853 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001854 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001855
1856 // Form a REG_SEQUENCE to force register allocation.
1857 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001858 SDValue V0 = N->getOperand(FirstTblReg + 0);
1859 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001860 if (NumVecs == 2)
1861 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1862 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001863 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001864 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001865 // an undef.
1866 SDValue V3 = (NumVecs == 3)
1867 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001868 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001869 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1870 }
1871
Bob Wilson78dfbc32010-07-07 00:08:54 +00001872 SmallVector<SDValue, 6> Ops;
1873 if (IsExt)
1874 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001875 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001876 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001877 Ops.push_back(getAL(CurDAG)); // predicate
1878 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001879 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001880}
1881
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001882SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001883 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001884 if (!Subtarget->hasV6T2Ops())
1885 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001886
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001887 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1888 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1889
1890
1891 // For unsigned extracts, check for a shift right and mask
1892 unsigned And_imm = 0;
1893 if (N->getOpcode() == ISD::AND) {
1894 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1895
1896 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1897 if (And_imm & (And_imm + 1))
1898 return NULL;
1899
1900 unsigned Srl_imm = 0;
1901 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1902 Srl_imm)) {
1903 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1904
1905 unsigned Width = CountTrailingOnes_32(And_imm);
1906 unsigned LSB = Srl_imm;
1907 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1908 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1909 CurDAG->getTargetConstant(LSB, MVT::i32),
1910 CurDAG->getTargetConstant(Width, MVT::i32),
1911 getAL(CurDAG), Reg0 };
1912 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1913 }
1914 }
1915 return NULL;
1916 }
1917
1918 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001919 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001920 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001921 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1922 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001923 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001924 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1925 unsigned Width = 32 - Srl_imm;
1926 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001927 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001928 return NULL;
1929 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001930 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001931 CurDAG->getTargetConstant(LSB, MVT::i32),
1932 CurDAG->getTargetConstant(Width, MVT::i32),
1933 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001934 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001935 }
1936 }
1937 return NULL;
1938}
1939
Evan Cheng9ef48352009-11-20 00:54:03 +00001940SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001941SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001942 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1943 SDValue CPTmp0;
1944 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001945 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001946 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1947 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1948 unsigned Opc = 0;
1949 switch (SOShOp) {
1950 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1951 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1952 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1953 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1954 default:
1955 llvm_unreachable("Unknown so_reg opcode!");
1956 break;
1957 }
1958 SDValue SOShImm =
1959 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1960 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1961 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001962 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001963 }
1964 return 0;
1965}
1966
1967SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001968SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001969 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1970 SDValue CPTmp0;
1971 SDValue CPTmp1;
1972 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00001973 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001974 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1975 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001976 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001977 }
1978 return 0;
1979}
1980
1981SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00001982SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00001983 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001984 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00001985 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00001986 return 0;
1987
Evan Cheng63f35442010-11-13 02:25:14 +00001988 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00001989 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00001990 if (is_t2_so_imm(TrueImm)) {
1991 Opc = ARM::t2MOVCCi;
1992 } else if (TrueImm <= 0xffff) {
1993 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00001994 } else if (is_t2_so_imm_not(TrueImm)) {
1995 TrueImm = ~TrueImm;
1996 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00001997 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00001998 // Large immediate.
1999 Opc = ARM::t2MOVCCi32imm;
2000 }
2001
2002 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002003 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002004 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2005 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002006 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002007 }
Evan Cheng63f35442010-11-13 02:25:14 +00002008
Evan Cheng9ef48352009-11-20 00:54:03 +00002009 return 0;
2010}
2011
2012SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002013SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002014 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002015 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2016 if (!T)
2017 return 0;
2018
Evan Cheng63f35442010-11-13 02:25:14 +00002019 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002020 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002021 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002022 if (isSoImm) {
2023 Opc = ARM::MOVCCi;
2024 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2025 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002026 } else if (is_so_imm_not(TrueImm)) {
2027 TrueImm = ~TrueImm;
2028 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002029 } else if (TrueVal.getNode()->hasOneUse() &&
2030 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002031 // Large immediate.
2032 Opc = ARM::MOVCCi32imm;
2033 }
2034
2035 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002036 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002037 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2038 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002039 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002040 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002041
Evan Cheng9ef48352009-11-20 00:54:03 +00002042 return 0;
2043}
2044
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002045SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2046 EVT VT = N->getValueType(0);
2047 SDValue FalseVal = N->getOperand(0);
2048 SDValue TrueVal = N->getOperand(1);
2049 SDValue CC = N->getOperand(2);
2050 SDValue CCR = N->getOperand(3);
2051 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002052 assert(CC.getOpcode() == ISD::Constant);
2053 assert(CCR.getOpcode() == ISD::Register);
2054 ARMCC::CondCodes CCVal =
2055 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002056
2057 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2058 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2059 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2060 // Pattern complexity = 18 cost = 1 size = 0
2061 SDValue CPTmp0;
2062 SDValue CPTmp1;
2063 SDValue CPTmp2;
2064 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002065 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002066 CCVal, CCR, InFlag);
2067 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002068 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002069 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2070 if (Res)
2071 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002072 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002073 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002074 CCVal, CCR, InFlag);
2075 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002076 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002077 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2078 if (Res)
2079 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002080 }
2081
2082 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002083 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002084 // (imm:i32):$cc)
2085 // Emits: (MOVCCi:i32 GPR:i32:$false,
2086 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2087 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002088 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002089 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002090 CCVal, CCR, InFlag);
2091 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002092 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002093 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2094 if (Res)
2095 return Res;
2096 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002097 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002098 CCVal, CCR, InFlag);
2099 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002100 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002101 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2102 if (Res)
2103 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002104 }
2105 }
2106
2107 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2108 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2109 // Pattern complexity = 6 cost = 1 size = 0
2110 //
2111 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2112 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2113 // Pattern complexity = 6 cost = 11 size = 0
2114 //
2115 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002116 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2117 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002118 unsigned Opc = 0;
2119 switch (VT.getSimpleVT().SimpleTy) {
2120 default: assert(false && "Illegal conditional move type!");
2121 break;
2122 case MVT::i32:
2123 Opc = Subtarget->isThumb()
2124 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2125 : ARM::MOVCCr;
2126 break;
2127 case MVT::f32:
2128 Opc = ARM::VMOVScc;
2129 break;
2130 case MVT::f64:
2131 Opc = ARM::VMOVDcc;
2132 break;
2133 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002134 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002135}
2136
Evan Chengde8aa4e2010-05-05 18:28:36 +00002137SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2138 // The only time a CONCAT_VECTORS operation can have legal types is when
2139 // two 64-bit vectors are concatenated to a 128-bit vector.
2140 EVT VT = N->getValueType(0);
2141 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2142 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002143 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002144}
2145
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002146SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002147 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002148
Dan Gohmane8be6c62008-07-17 19:10:17 +00002149 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002150 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002151
2152 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002153 default: break;
2154 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002155 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002156 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002157 if (Subtarget->hasThumb2())
2158 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2159 // be done with MOV + MOVT, at worst.
2160 UseCP = 0;
2161 else {
2162 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002163 UseCP = (Val > 255 && // MOV
2164 ~Val > 255 && // MOV + MVN
2165 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002166 } else
2167 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2168 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2169 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2170 }
2171
Evan Chenga8e29892007-01-19 07:51:42 +00002172 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002173 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002174 CurDAG->getTargetConstantPool(ConstantInt::get(
2175 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002176 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002177
2178 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002179 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002180 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002181 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002182 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002183 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002184 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002185 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002186 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002187 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002188 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002189 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002190 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002191 CurDAG->getEntryNode()
2192 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002193 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002194 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002195 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002196 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002197 return NULL;
2198 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002199
Evan Chenga8e29892007-01-19 07:51:42 +00002200 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002201 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002202 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002203 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002204 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002205 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002206 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002207 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002208 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2209 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002210 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002211 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2212 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002213 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2214 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2215 CurDAG->getRegister(0, MVT::i32) };
2216 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002217 }
Evan Chenga8e29892007-01-19 07:51:42 +00002218 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002219 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002220 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002221 return I;
2222 break;
2223 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002224 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002225 return I;
2226 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002227 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002228 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002229 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002230 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002231 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002232 if (!RHSV) break;
2233 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002234 unsigned ShImm = Log2_32(RHSV-1);
2235 if (ShImm >= 32)
2236 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002237 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002238 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002239 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2240 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002241 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002242 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002243 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002244 } else {
2245 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002246 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002247 }
Evan Chenga8e29892007-01-19 07:51:42 +00002248 }
2249 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002250 unsigned ShImm = Log2_32(RHSV+1);
2251 if (ShImm >= 32)
2252 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002253 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002254 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002255 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2256 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002257 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002258 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2259 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002260 } else {
2261 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002262 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002263 }
Evan Chenga8e29892007-01-19 07:51:42 +00002264 }
2265 }
2266 break;
Evan Cheng20956592009-10-21 08:15:52 +00002267 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002268 // Check for unsigned bitfield extract
2269 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2270 return I;
2271
Evan Cheng20956592009-10-21 08:15:52 +00002272 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2273 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2274 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2275 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2276 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002277 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002278 if (VT != MVT::i32)
2279 break;
2280 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2281 ? ARM::t2MOVTi16
2282 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2283 if (!Opc)
2284 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002285 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002286 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2287 if (!N1C)
2288 break;
2289 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2290 SDValue N2 = N0.getOperand(1);
2291 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2292 if (!N2C)
2293 break;
2294 unsigned N1CVal = N1C->getZExtValue();
2295 unsigned N2CVal = N2C->getZExtValue();
2296 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2297 (N1CVal & 0xffffU) == 0xffffU &&
2298 (N2CVal & 0xffffU) == 0x0U) {
2299 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2300 MVT::i32);
2301 SDValue Ops[] = { N0.getOperand(0), Imm16,
2302 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2303 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2304 }
2305 }
2306 break;
2307 }
Jim Grosbache5165492009-11-09 00:11:35 +00002308 case ARMISD::VMOVRRD:
2309 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002310 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002311 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002312 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002313 if (Subtarget->isThumb1Only())
2314 break;
2315 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002316 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002317 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2318 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002319 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002320 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002321 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002322 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2323 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002324 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2325 ARM::UMULL : ARM::UMULLv5,
2326 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002327 }
Evan Chengee568cf2007-07-05 07:15:27 +00002328 }
Dan Gohman525178c2007-10-08 18:33:35 +00002329 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002330 if (Subtarget->isThumb1Only())
2331 break;
2332 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002333 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002334 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002335 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002336 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002337 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002338 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2339 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002340 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2341 ARM::SMULL : ARM::SMULLv5,
2342 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002343 }
Evan Chengee568cf2007-07-05 07:15:27 +00002344 }
Evan Chenga8e29892007-01-19 07:51:42 +00002345 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002346 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002347 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002348 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002349 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002350 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002351 if (ResNode)
2352 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002353 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002354 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002355 }
Evan Chengee568cf2007-07-05 07:15:27 +00002356 case ARMISD::BRCOND: {
2357 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2358 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2359 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002360
Evan Chengee568cf2007-07-05 07:15:27 +00002361 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2362 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2363 // Pattern complexity = 6 cost = 1 size = 0
2364
David Goodwin5e47a9a2009-06-30 18:04:13 +00002365 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2366 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2367 // Pattern complexity = 6 cost = 1 size = 0
2368
Jim Grosbach764ab522009-08-11 15:33:49 +00002369 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002370 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002371 SDValue Chain = N->getOperand(0);
2372 SDValue N1 = N->getOperand(1);
2373 SDValue N2 = N->getOperand(2);
2374 SDValue N3 = N->getOperand(3);
2375 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002376 assert(N1.getOpcode() == ISD::BasicBlock);
2377 assert(N2.getOpcode() == ISD::Constant);
2378 assert(N3.getOpcode() == ISD::Register);
2379
Dan Gohman475871a2008-07-27 21:46:04 +00002380 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002381 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002382 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002383 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002384 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002385 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002386 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002387 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002388 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002389 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002390 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002391 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002392 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002393 return NULL;
2394 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002395 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002396 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002397 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002398 EVT VT = N->getValueType(0);
2399 SDValue N0 = N->getOperand(0);
2400 SDValue N1 = N->getOperand(1);
2401 SDValue N2 = N->getOperand(2);
2402 SDValue N3 = N->getOperand(3);
2403 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002404 assert(N2.getOpcode() == ISD::Constant);
2405 assert(N3.getOpcode() == ISD::Register);
2406
Dan Gohman475871a2008-07-27 21:46:04 +00002407 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002408 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002409 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002410 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002411 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002412 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002413 default: assert(false && "Illegal conditional move type!");
2414 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002415 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002416 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002417 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002418 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002419 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002420 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002421 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002422 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002423 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002424
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002425 case ARMISD::VZIP: {
2426 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002427 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002428 switch (VT.getSimpleVT().SimpleTy) {
2429 default: return NULL;
2430 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2431 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2432 case MVT::v2f32:
2433 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2434 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2435 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2436 case MVT::v4f32:
2437 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2438 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002439 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002440 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2441 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2442 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002443 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002444 case ARMISD::VUZP: {
2445 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002446 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002447 switch (VT.getSimpleVT().SimpleTy) {
2448 default: return NULL;
2449 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2450 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2451 case MVT::v2f32:
2452 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2453 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2454 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2455 case MVT::v4f32:
2456 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2457 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002458 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002459 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2460 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2461 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002462 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002463 case ARMISD::VTRN: {
2464 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002465 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002466 switch (VT.getSimpleVT().SimpleTy) {
2467 default: return NULL;
2468 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2469 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2470 case MVT::v2f32:
2471 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2472 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2473 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2474 case MVT::v4f32:
2475 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2476 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002477 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002478 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2479 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2480 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002481 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002482 case ARMISD::BUILD_VECTOR: {
2483 EVT VecVT = N->getValueType(0);
2484 EVT EltVT = VecVT.getVectorElementType();
2485 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002486 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002487 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2488 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2489 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002490 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002491 if (NumElts == 2)
2492 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2493 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2494 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2495 N->getOperand(2), N->getOperand(3));
2496 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002497
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002498 case ARMISD::VLD2DUP: {
2499 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2500 ARM::VLD2DUPd32Pseudo };
2501 return SelectVLDDup(N, 2, Opcodes);
2502 }
2503
Bob Wilson86c6d802010-11-29 19:35:29 +00002504 case ARMISD::VLD3DUP: {
2505 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2506 ARM::VLD3DUPd32Pseudo };
2507 return SelectVLDDup(N, 3, Opcodes);
2508 }
2509
Bob Wilson6c4c9822010-11-30 00:00:35 +00002510 case ARMISD::VLD4DUP: {
2511 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2512 ARM::VLD4DUPd32Pseudo };
2513 return SelectVLDDup(N, 4, Opcodes);
2514 }
2515
Bob Wilson31fb12f2009-08-26 17:39:53 +00002516 case ISD::INTRINSIC_VOID:
2517 case ISD::INTRINSIC_W_CHAIN: {
2518 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002519 switch (IntNo) {
2520 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002521 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002522
Bob Wilson621f1952010-03-23 05:25:43 +00002523 case Intrinsic::arm_neon_vld1: {
2524 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2525 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002526 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2527 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson621f1952010-03-23 05:25:43 +00002528 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2529 }
2530
Bob Wilson31fb12f2009-08-26 17:39:53 +00002531 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002532 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2533 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2534 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2535 ARM::VLD2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002536 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002537 }
2538
2539 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002540 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2541 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2542 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2543 ARM::VLD3q16Pseudo_UPD,
2544 ARM::VLD3q32Pseudo_UPD };
2545 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2546 ARM::VLD3q16oddPseudo_UPD,
2547 ARM::VLD3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002548 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002549 }
2550
2551 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002552 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2553 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2554 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2555 ARM::VLD4q16Pseudo_UPD,
2556 ARM::VLD4q32Pseudo_UPD };
2557 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2558 ARM::VLD4q16oddPseudo_UPD,
2559 ARM::VLD4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002560 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002561 }
2562
Bob Wilson243fcc52009-09-01 04:26:28 +00002563 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002564 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2565 ARM::VLD2LNd32Pseudo };
2566 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
2567 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002568 }
2569
2570 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002571 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2572 ARM::VLD3LNd32Pseudo };
2573 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
2574 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002575 }
2576
2577 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002578 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2579 ARM::VLD4LNd32Pseudo };
2580 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
2581 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002582 }
2583
Bob Wilson11d98992010-03-23 06:20:33 +00002584 case Intrinsic::arm_neon_vst1: {
2585 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2586 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002587 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2588 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson11d98992010-03-23 06:20:33 +00002589 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2590 }
2591
Bob Wilson31fb12f2009-08-26 17:39:53 +00002592 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002593 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2594 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2595 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2596 ARM::VST2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002597 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002598 }
2599
2600 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002601 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2602 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2603 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2604 ARM::VST3q16Pseudo_UPD,
2605 ARM::VST3q32Pseudo_UPD };
2606 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2607 ARM::VST3q16oddPseudo_UPD,
2608 ARM::VST3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002609 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002610 }
2611
2612 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002613 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002614 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002615 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2616 ARM::VST4q16Pseudo_UPD,
2617 ARM::VST4q32Pseudo_UPD };
2618 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2619 ARM::VST4q16oddPseudo_UPD,
2620 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002621 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002622 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002623
2624 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002625 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2626 ARM::VST2LNd32Pseudo };
2627 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
2628 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002629 }
2630
2631 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002632 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2633 ARM::VST3LNd32Pseudo };
2634 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
2635 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002636 }
2637
2638 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002639 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2640 ARM::VST4LNd32Pseudo };
2641 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
2642 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002643 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002644 }
Bob Wilson429009b2010-05-06 16:05:26 +00002645 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002646 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002647
Bob Wilsond491d6e2010-07-06 23:36:25 +00002648 case ISD::INTRINSIC_WO_CHAIN: {
2649 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2650 switch (IntNo) {
2651 default:
2652 break;
2653
2654 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002655 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002656 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002657 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002658 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002659 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002660
2661 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002662 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002663 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002664 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002665 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002666 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002667 }
2668 break;
2669 }
2670
Bob Wilson429009b2010-05-06 16:05:26 +00002671 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002672 return SelectConcatVector(N);
2673 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002674
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002675 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002676}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002677
Bob Wilson224c2442009-05-19 05:53:42 +00002678bool ARMDAGToDAGISel::
2679SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2680 std::vector<SDValue> &OutOps) {
2681 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002682 // Require the address to be in a register. That is safe for all ARM
2683 // variants and it is hard to do anything much smarter without knowing
2684 // how the operand is used.
2685 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002686 return false;
2687}
2688
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002689/// createARMISelDag - This pass converts a legalized DAG into a
2690/// ARM-specific DAG, ready for instruction scheduling.
2691///
Bob Wilson522ce972009-09-28 14:30:20 +00002692FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2693 CodeGenOpt::Level OptLevel) {
2694 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002695}