blob: 476fe6efac141ce95ecba767cf05c29ef6003391 [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
Chris Lattner52a261b2010-09-21 20:31:19 +0000130 bool SelectAddrModePC(SDValue N, SDValue &Offset,
Bob Wilson8b024a52009-07-01 23:16:05 +0000131 SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000132
Bill Wendlingf4caf692010-12-14 03:36:38 +0000133 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000134 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000135 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
136 unsigned Scale);
137 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
138 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
139 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
140 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
141 SDValue &OffImm);
142 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
143 SDValue &OffImm);
144 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
145 SDValue &OffImm);
146 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
147 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000148 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000149
Bill Wendlingf4caf692010-12-14 03:36:38 +0000150 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000151 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000152 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000153 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
154 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000155 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000156 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000157 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000158 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000159 SDValue &OffReg, SDValue &ShImm);
160
Evan Cheng875a6ac2010-11-12 22:42:47 +0000161 inline bool is_so_imm(unsigned Imm) const {
162 return ARM_AM::getSOImmVal(Imm) != -1;
163 }
164
165 inline bool is_so_imm_not(unsigned Imm) const {
166 return ARM_AM::getSOImmVal(~Imm) != -1;
167 }
168
169 inline bool is_t2_so_imm(unsigned Imm) const {
170 return ARM_AM::getT2SOImmVal(Imm) != -1;
171 }
172
173 inline bool is_t2_so_imm_not(unsigned Imm) const {
174 return ARM_AM::getT2SOImmVal(~Imm) != -1;
175 }
176
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000177 inline bool Pred_so_imm(SDNode *inN) const {
178 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000179 return is_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000180 }
181
182 inline bool Pred_t2_so_imm(SDNode *inN) const {
183 ConstantSDNode *N = cast<ConstantSDNode>(inN);
Evan Cheng875a6ac2010-11-12 22:42:47 +0000184 return is_t2_so_imm(N->getZExtValue());
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +0000185 }
186
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000187 // Include the pieces autogenerated from the target description.
188#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000189
190private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000191 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
192 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000193 SDNode *SelectARMIndexedLoad(SDNode *N);
194 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000195
Bob Wilson621f1952010-03-23 05:25:43 +0000196 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
197 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000198 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000199 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000200 SDNode *SelectVLD(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000201 unsigned *QOpcodes0, unsigned *QOpcodes1);
202
Bob Wilson24f995d2009-10-14 18:32:29 +0000203 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000204 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000205 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000206 /// For NumVecs <= 2, QOpcodes1 is not used.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000207 SDNode *SelectVST(SDNode *N, unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000208 unsigned *QOpcodes0, unsigned *QOpcodes1);
209
Bob Wilson96493442009-10-14 16:46:45 +0000210 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000211 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000212 /// load/store of D registers and Q registers.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000213 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000214 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000215
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000216 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
217 /// should be 2, 3 or 4. The opcode array specifies the instructions used
218 /// for loading D registers. (Q registers are not supported.)
219 SDNode *SelectVLDDup(SDNode *N, unsigned NumVecs, unsigned *Opcodes);
220
Bob Wilson78dfbc32010-07-07 00:08:54 +0000221 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
222 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
223 /// generated to force the table registers to be consecutive.
224 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000225
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000226 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000227 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000228
Evan Cheng07ba9062009-11-19 21:45:22 +0000229 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000230 SDNode *SelectCMOVOp(SDNode *N);
231 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000232 ARMCC::CondCodes CCVal, SDValue CCR,
233 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000234 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000235 ARMCC::CondCodes CCVal, SDValue CCR,
236 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000237 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000238 ARMCC::CondCodes CCVal, SDValue CCR,
239 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000240 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000241 ARMCC::CondCodes CCVal, SDValue CCR,
242 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000243
Evan Chengde8aa4e2010-05-05 18:28:36 +0000244 SDNode *SelectConcatVector(SDNode *N);
245
Evan Chengaf4550f2009-07-02 01:23:32 +0000246 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
247 /// inline asm expressions.
248 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
249 char ConstraintCode,
250 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000251
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000252 // Form pairs of consecutive S, D, or Q registers.
253 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000254 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000255 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
256
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000257 // Form sequences of 4 consecutive S, D, or Q registers.
258 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000259 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000260 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000261
262 // Get the alignment operand for a NEON VLD or VST instruction.
263 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000264};
Evan Chenga8e29892007-01-19 07:51:42 +0000265}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000266
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000267/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
268/// operand. If so Imm will receive the 32-bit value.
269static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
270 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
271 Imm = cast<ConstantSDNode>(N)->getZExtValue();
272 return true;
273 }
274 return false;
275}
276
277// isInt32Immediate - This method tests to see if a constant operand.
278// If so Imm will receive the 32 bit value.
279static bool isInt32Immediate(SDValue N, unsigned &Imm) {
280 return isInt32Immediate(N.getNode(), Imm);
281}
282
283// isOpcWithIntImmediate - This method tests to see if the node is a specific
284// opcode and that it has a immediate integer right operand.
285// If so Imm will receive the 32 bit value.
286static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
287 return N->getOpcode() == Opc &&
288 isInt32Immediate(N->getOperand(1).getNode(), Imm);
289}
290
Evan Cheng48575f62010-12-05 22:04:16 +0000291/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
292/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
293/// least on current ARM implementations) which should be avoidded.
294bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
295 if (OptLevel == CodeGenOpt::None)
296 return true;
297
298 if (!CheckVMLxHazard)
299 return true;
300
301 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
302 return true;
303
304 if (!N->hasOneUse())
305 return false;
306
307 SDNode *Use = *N->use_begin();
308 if (Use->getOpcode() == ISD::CopyToReg)
309 return true;
310 if (Use->isMachineOpcode()) {
311 const TargetInstrDesc &TID = TII->get(Use->getMachineOpcode());
312 if (TID.mayStore())
313 return true;
314 unsigned Opcode = TID.getOpcode();
315 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
316 return true;
317 // vmlx feeding into another vmlx. We actually want to unfold
318 // the use later in the MLxExpansion pass. e.g.
319 // vmla
320 // vmla (stall 8 cycles)
321 //
322 // vmul (5 cycles)
323 // vadd (5 cycles)
324 // vmla
325 // This adds up to about 18 - 19 cycles.
326 //
327 // vmla
328 // vmul (stall 4 cycles)
329 // vadd adds up to about 14 cycles.
330 return TII->isFpMLxInstruction(Opcode);
331 }
332
333 return false;
334}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000335
Evan Chengf40deed2010-10-27 23:41:30 +0000336bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
337 ARM_AM::ShiftOpc ShOpcVal,
338 unsigned ShAmt) {
339 if (!Subtarget->isCortexA9())
340 return true;
341 if (Shift.hasOneUse())
342 return true;
343 // R << 2 is free.
344 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
345}
346
Chris Lattner52a261b2010-09-21 20:31:19 +0000347bool ARMDAGToDAGISel::SelectShifterOperandReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000348 SDValue &BaseReg,
349 SDValue &ShReg,
350 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000351 if (DisableShifterOp)
352 return false;
353
Evan Cheng055b0312009-06-29 07:51:04 +0000354 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
355
356 // Don't match base register only case. That is matched to a separate
357 // lower complexity pattern with explicit register operand.
358 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000359
Evan Cheng055b0312009-06-29 07:51:04 +0000360 BaseReg = N.getOperand(0);
361 unsigned ShImmVal = 0;
362 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000363 ShReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000364 ShImmVal = RHS->getZExtValue() & 31;
365 } else {
366 ShReg = N.getOperand(1);
Evan Chengf40deed2010-10-27 23:41:30 +0000367 if (!isShifterOpProfitable(N, ShOpcVal, ShImmVal))
368 return false;
369 }
370 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
371 MVT::i32);
372 return true;
373}
374
375bool ARMDAGToDAGISel::SelectShiftShifterOperandReg(SDValue N,
376 SDValue &BaseReg,
377 SDValue &ShReg,
378 SDValue &Opc) {
379 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
380
381 // Don't match base register only case. That is matched to a separate
382 // lower complexity pattern with explicit register operand.
383 if (ShOpcVal == ARM_AM::no_shift) return false;
384
385 BaseReg = N.getOperand(0);
386 unsigned ShImmVal = 0;
387 // Do not check isShifterOpProfitable. This must return true.
388 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
389 ShReg = CurDAG->getRegister(0, MVT::i32);
390 ShImmVal = RHS->getZExtValue() & 31;
391 } else {
392 ShReg = N.getOperand(1);
Evan Cheng055b0312009-06-29 07:51:04 +0000393 }
394 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000395 MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +0000396 return true;
397}
398
Jim Grosbach3e556122010-10-26 22:37:02 +0000399bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
400 SDValue &Base,
401 SDValue &OffImm) {
402 // Match simple R + imm12 operands.
403
404 // Base only.
405 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
406 if (N.getOpcode() == ISD::FrameIndex) {
407 // Match frame index...
408 int FI = cast<FrameIndexSDNode>(N)->getIndex();
409 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
410 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
411 return true;
412 } else if (N.getOpcode() == ARMISD::Wrapper &&
413 !(Subtarget->useMovt() &&
414 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
415 Base = N.getOperand(0);
416 } else
417 Base = N;
418 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
419 return true;
420 }
421
422 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
423 int RHSC = (int)RHS->getZExtValue();
424 if (N.getOpcode() == ISD::SUB)
425 RHSC = -RHSC;
426
427 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
428 Base = N.getOperand(0);
429 if (Base.getOpcode() == ISD::FrameIndex) {
430 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
431 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
432 }
433 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
434 return true;
435 }
436 }
437
438 // Base only.
439 Base = N;
440 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
441 return true;
442}
443
444
445
446bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
447 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000448 if (N.getOpcode() == ISD::MUL &&
449 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000450 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
451 // X * [3,5,9] -> X + X * [2,4,8] etc.
452 int RHSC = (int)RHS->getZExtValue();
453 if (RHSC & 1) {
454 RHSC = RHSC & ~1;
455 ARM_AM::AddrOpc AddSub = ARM_AM::add;
456 if (RHSC < 0) {
457 AddSub = ARM_AM::sub;
458 RHSC = - RHSC;
459 }
460 if (isPowerOf2_32(RHSC)) {
461 unsigned ShAmt = Log2_32(RHSC);
462 Base = Offset = N.getOperand(0);
463 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
464 ARM_AM::lsl),
465 MVT::i32);
466 return true;
467 }
468 }
469 }
470 }
471
472 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB)
473 return false;
474
475 // Leave simple R +/- imm12 operands for LDRi12
476 if (N.getOpcode() == ISD::ADD) {
477 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
478 int RHSC = (int)RHS->getZExtValue();
479 if ((RHSC >= 0 && RHSC < 0x1000) ||
480 (RHSC < 0 && RHSC > -0x1000)) // 12 bits.
481 return false;
482 }
483 }
484
Evan Chengf40deed2010-10-27 23:41:30 +0000485 if (Subtarget->isCortexA9() && !N.hasOneUse())
486 // Compute R +/- (R << N) and reuse it.
487 return false;
488
Jim Grosbach3e556122010-10-26 22:37:02 +0000489 // Otherwise this is R +/- [possibly shifted] R.
490 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
491 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
492 unsigned ShAmt = 0;
493
494 Base = N.getOperand(0);
495 Offset = N.getOperand(1);
496
497 if (ShOpcVal != ARM_AM::no_shift) {
498 // Check to see if the RHS of the shift is a constant, if not, we can't fold
499 // it.
500 if (ConstantSDNode *Sh =
501 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
502 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000503 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
504 Offset = N.getOperand(1).getOperand(0);
505 else {
506 ShAmt = 0;
507 ShOpcVal = ARM_AM::no_shift;
508 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000509 } else {
510 ShOpcVal = ARM_AM::no_shift;
511 }
512 }
513
514 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000515 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
516 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000517 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
518 if (ShOpcVal != ARM_AM::no_shift) {
519 // Check to see if the RHS of the shift is a constant, if not, we can't
520 // fold it.
521 if (ConstantSDNode *Sh =
522 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
523 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000524 if (!Subtarget->isCortexA9() ||
525 (N.hasOneUse() &&
526 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
527 Offset = N.getOperand(0).getOperand(0);
528 Base = N.getOperand(1);
529 } else {
530 ShAmt = 0;
531 ShOpcVal = ARM_AM::no_shift;
532 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000533 } else {
534 ShOpcVal = ARM_AM::no_shift;
535 }
536 }
537 }
538
539 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
540 MVT::i32);
541 return true;
542}
543
544
545
546
547//-----
548
Jim Grosbach82891622010-09-29 19:03:54 +0000549AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
550 SDValue &Base,
551 SDValue &Offset,
552 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000553 if (N.getOpcode() == ISD::MUL &&
554 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000555 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
556 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000557 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000558 if (RHSC & 1) {
559 RHSC = RHSC & ~1;
560 ARM_AM::AddrOpc AddSub = ARM_AM::add;
561 if (RHSC < 0) {
562 AddSub = ARM_AM::sub;
563 RHSC = - RHSC;
564 }
565 if (isPowerOf2_32(RHSC)) {
566 unsigned ShAmt = Log2_32(RHSC);
567 Base = Offset = N.getOperand(0);
568 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
569 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000570 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000571 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000572 }
573 }
574 }
575 }
576
Evan Chenga8e29892007-01-19 07:51:42 +0000577 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
578 Base = N;
579 if (N.getOpcode() == ISD::FrameIndex) {
580 int FI = cast<FrameIndexSDNode>(N)->getIndex();
581 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000582 } else if (N.getOpcode() == ARMISD::Wrapper &&
583 !(Subtarget->useMovt() &&
584 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000585 Base = N.getOperand(0);
586 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000587 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000588 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
589 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000590 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000591 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000592 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000593
Evan Chenga8e29892007-01-19 07:51:42 +0000594 // Match simple R +/- imm12 operands.
Jim Grosbachbe912322010-09-29 17:32:29 +0000595 if (N.getOpcode() == ISD::ADD) {
Evan Chenga8e29892007-01-19 07:51:42 +0000596 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000597 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000598 if ((RHSC >= 0 && RHSC < 0x1000) ||
599 (RHSC < 0 && RHSC > -0x1000)) { // 12 bits.
Evan Chenga8e29892007-01-19 07:51:42 +0000600 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000601 if (Base.getOpcode() == ISD::FrameIndex) {
602 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
603 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
604 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000605 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000606
607 ARM_AM::AddrOpc AddSub = ARM_AM::add;
608 if (RHSC < 0) {
609 AddSub = ARM_AM::sub;
610 RHSC = - RHSC;
611 }
612 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
Evan Chenga8e29892007-01-19 07:51:42 +0000613 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000614 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000615 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000616 }
Evan Chenga8e29892007-01-19 07:51:42 +0000617 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000618 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000619
Evan Chengf40deed2010-10-27 23:41:30 +0000620 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
621 // Compute R +/- (R << N) and reuse it.
622 Base = N;
623 Offset = CurDAG->getRegister(0, MVT::i32);
624 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
625 ARM_AM::no_shift),
626 MVT::i32);
627 return AM2_BASE;
628 }
629
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000630 // Otherwise this is R +/- [possibly shifted] R.
Evan Chenga8e29892007-01-19 07:51:42 +0000631 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::ADD ? ARM_AM::add:ARM_AM::sub;
632 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(1));
633 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000634
Evan Chenga8e29892007-01-19 07:51:42 +0000635 Base = N.getOperand(0);
636 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000637
Evan Chenga8e29892007-01-19 07:51:42 +0000638 if (ShOpcVal != ARM_AM::no_shift) {
639 // Check to see if the RHS of the shift is a constant, if not, we can't fold
640 // it.
641 if (ConstantSDNode *Sh =
642 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000643 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000644 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
645 Offset = N.getOperand(1).getOperand(0);
646 else {
647 ShAmt = 0;
648 ShOpcVal = ARM_AM::no_shift;
649 }
Evan Chenga8e29892007-01-19 07:51:42 +0000650 } else {
651 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000652 }
653 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000654
Evan Chenga8e29892007-01-19 07:51:42 +0000655 // Try matching (R shl C) + (R).
Evan Chengf40deed2010-10-27 23:41:30 +0000656 if (N.getOpcode() == ISD::ADD && ShOpcVal == ARM_AM::no_shift &&
657 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chenga8e29892007-01-19 07:51:42 +0000658 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0));
659 if (ShOpcVal != ARM_AM::no_shift) {
660 // Check to see if the RHS of the shift is a constant, if not, we can't
661 // fold it.
662 if (ConstantSDNode *Sh =
663 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000664 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000665 if (!Subtarget->isCortexA9() ||
666 (N.hasOneUse() &&
667 isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt))) {
668 Offset = N.getOperand(0).getOperand(0);
669 Base = N.getOperand(1);
670 } else {
671 ShAmt = 0;
672 ShOpcVal = ARM_AM::no_shift;
673 }
Evan Chenga8e29892007-01-19 07:51:42 +0000674 } else {
675 ShOpcVal = ARM_AM::no_shift;
676 }
677 }
678 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000679
Evan Chenga8e29892007-01-19 07:51:42 +0000680 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000681 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000682 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000683}
684
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000685bool ARMDAGToDAGISel::SelectAddrMode2Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000686 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000687 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000688 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
689 ? cast<LoadSDNode>(Op)->getAddressingMode()
690 : cast<StoreSDNode>(Op)->getAddressingMode();
691 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
692 ? ARM_AM::add : ARM_AM::sub;
693 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000694 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000695 if (Val >= 0 && Val < 0x1000) { // 12 bits.
Owen Anderson825b72b2009-08-11 20:47:22 +0000696 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000697 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
698 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000699 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000700 return true;
701 }
702 }
703
704 Offset = N;
705 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
706 unsigned ShAmt = 0;
707 if (ShOpcVal != ARM_AM::no_shift) {
708 // Check to see if the RHS of the shift is a constant, if not, we can't fold
709 // it.
710 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000711 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000712 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
713 Offset = N.getOperand(0);
714 else {
715 ShAmt = 0;
716 ShOpcVal = ARM_AM::no_shift;
717 }
Evan Chenga8e29892007-01-19 07:51:42 +0000718 } else {
719 ShOpcVal = ARM_AM::no_shift;
720 }
721 }
722
723 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000724 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000725 return true;
726}
727
Evan Chenga8e29892007-01-19 07:51:42 +0000728
Chris Lattner52a261b2010-09-21 20:31:19 +0000729bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000730 SDValue &Base, SDValue &Offset,
731 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000732 if (N.getOpcode() == ISD::SUB) {
733 // X - C is canonicalize to X + -C, no need to handle it here.
734 Base = N.getOperand(0);
735 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000736 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000737 return true;
738 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000739
Evan Chenga8e29892007-01-19 07:51:42 +0000740 if (N.getOpcode() != ISD::ADD) {
741 Base = N;
742 if (N.getOpcode() == ISD::FrameIndex) {
743 int FI = cast<FrameIndexSDNode>(N)->getIndex();
744 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
745 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000746 Offset = CurDAG->getRegister(0, MVT::i32);
747 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000748 return true;
749 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000750
Evan Chenga8e29892007-01-19 07:51:42 +0000751 // If the RHS is +/- imm8, fold into addr mode.
752 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000753 int RHSC = (int)RHS->getZExtValue();
Evan Chenge966d642007-01-24 02:45:25 +0000754 if ((RHSC >= 0 && RHSC < 256) ||
755 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000756 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000757 if (Base.getOpcode() == ISD::FrameIndex) {
758 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
759 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
760 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000761 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenge966d642007-01-24 02:45:25 +0000762
763 ARM_AM::AddrOpc AddSub = ARM_AM::add;
764 if (RHSC < 0) {
765 AddSub = ARM_AM::sub;
766 RHSC = - RHSC;
767 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000768 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000769 return true;
770 }
771 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000772
Evan Chenga8e29892007-01-19 07:51:42 +0000773 Base = N.getOperand(0);
774 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000775 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000776 return true;
777}
778
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000779bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000780 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000781 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000782 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
783 ? cast<LoadSDNode>(Op)->getAddressingMode()
784 : cast<StoreSDNode>(Op)->getAddressingMode();
785 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
786 ? ARM_AM::add : ARM_AM::sub;
787 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N)) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000788 int Val = (int)C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000789 if (Val >= 0 && Val < 256) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000790 Offset = CurDAG->getRegister(0, MVT::i32);
791 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000792 return true;
793 }
794 }
795
796 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000797 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000798 return true;
799}
800
Jim Grosbach3ab56582010-10-21 19:38:40 +0000801bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000802 SDValue &Base, SDValue &Offset) {
Evan Chenga8e29892007-01-19 07:51:42 +0000803 if (N.getOpcode() != ISD::ADD) {
804 Base = N;
805 if (N.getOpcode() == ISD::FrameIndex) {
806 int FI = cast<FrameIndexSDNode>(N)->getIndex();
807 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000808 } else if (N.getOpcode() == ARMISD::Wrapper &&
809 !(Subtarget->useMovt() &&
810 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000811 Base = N.getOperand(0);
812 }
813 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000814 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000815 return true;
816 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000817
Evan Chenga8e29892007-01-19 07:51:42 +0000818 // If the RHS is +/- imm8, fold into addr mode.
819 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000820 int RHSC = (int)RHS->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +0000821 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied by 4.
822 RHSC >>= 2;
Evan Chenge966d642007-01-24 02:45:25 +0000823 if ((RHSC >= 0 && RHSC < 256) ||
824 (RHSC < 0 && RHSC > -256)) { // note -256 itself isn't allowed.
Evan Chenga8e29892007-01-19 07:51:42 +0000825 Base = N.getOperand(0);
Evan Chenge966d642007-01-24 02:45:25 +0000826 if (Base.getOpcode() == ISD::FrameIndex) {
827 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
828 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
829 }
830
831 ARM_AM::AddrOpc AddSub = ARM_AM::add;
832 if (RHSC < 0) {
833 AddSub = ARM_AM::sub;
834 RHSC = - RHSC;
835 }
836 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
Owen Anderson825b72b2009-08-11 20:47:22 +0000837 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000838 return true;
839 }
840 }
841 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000842
Evan Chenga8e29892007-01-19 07:51:42 +0000843 Base = N;
844 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000845 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000846 return true;
847}
848
Bob Wilson665814b2010-11-01 23:40:51 +0000849bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
850 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000851 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000852
853 unsigned Alignment = 0;
854 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
855 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
856 // The maximum alignment is equal to the memory size being referenced.
857 unsigned LSNAlign = LSN->getAlignment();
858 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
859 if (LSNAlign > MemSize && MemSize > 1)
860 Alignment = MemSize;
861 } else {
862 // All other uses of addrmode6 are for intrinsics. For now just record
863 // the raw alignment value; it will be refined later based on the legal
864 // alignment operands for the intrinsic.
865 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
866 }
867
868 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000869 return true;
870}
871
Chris Lattner52a261b2010-09-21 20:31:19 +0000872bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000873 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000874 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
875 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000876 SDValue N1 = N.getOperand(1);
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000877 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
Owen Anderson825b72b2009-08-11 20:47:22 +0000878 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000879 return true;
880 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000881
Evan Chenga8e29892007-01-19 07:51:42 +0000882 return false;
883}
884
Bill Wendlingf4caf692010-12-14 03:36:38 +0000885
886//===----------------------------------------------------------------------===//
887// Thumb Addressing Modes
888//===----------------------------------------------------------------------===//
889
890
Chris Lattner52a261b2010-09-21 20:31:19 +0000891bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000892 SDValue &Base, SDValue &Offset){
Dale Johannesenf5f5dce2009-02-06 19:16:40 +0000893 // FIXME dl should come from the parent load or store, not the address
Evan Chengc38f2bc2007-01-23 22:59:13 +0000894 if (N.getOpcode() != ISD::ADD) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000895 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000896 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000897 return false;
898
899 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000900 return true;
901 }
902
Evan Chenga8e29892007-01-19 07:51:42 +0000903 Base = N.getOperand(0);
904 Offset = N.getOperand(1);
905 return true;
906}
907
Evan Cheng79d43262007-01-24 02:21:22 +0000908bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000909ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
910 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000911 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000912 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000913 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000914 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000915
Evan Cheng012f2d92007-01-24 08:53:17 +0000916 if (N.getOpcode() == ARMISD::Wrapper &&
917 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
918 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000919 }
920
Bill Wendling7d1d8db2010-12-15 00:04:00 +0000921 if (N.getOpcode() != ISD::ADD) {
922 if (N.getOpcode() == ARMISD::Wrapper &&
923 (!Subtarget->useMovt() ||
924 N.getOperand(0).getOpcode() != ISD::TargetGlobalAddress))
925 Base = N.getOperand(0);
926 else
927 Base = N;
928
929 Offset = CurDAG->getRegister(0, MVT::i32);
930 return true;
931 }
Evan Chenga8e29892007-01-19 07:51:42 +0000932
Evan Chengad0e4652007-02-06 00:22:06 +0000933 // Thumb does not have [sp, r] address mode.
934 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
935 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
936 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendling7d1d8db2010-12-15 00:04:00 +0000937 (RHSR && RHSR->getReg() == ARM::SP)) {
938 Base = N;
939 Offset = CurDAG->getRegister(0, MVT::i32);
940 return true;
941 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000942
943 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
944 int RHSC = (int)RHS->getZExtValue();
945
946 if ((RHSC & (Scale - 1)) == 0) { // The constant is implicitly multiplied.
947 RHSC /= Scale;
948
949 if (RHSC >= 0 && RHSC < 32)
950 return false;
951 }
952 }
953
954 Base = N.getOperand(0);
955 Offset = N.getOperand(1);
956 return true;
957}
958
959bool
960ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
961 SDValue &Base,
962 SDValue &Offset) {
963 return SelectThumbAddrModeRI(N, Base, Offset, 1);
964}
965
966bool
967ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
968 SDValue &Base,
969 SDValue &Offset) {
970 return SelectThumbAddrModeRI(N, Base, Offset, 2);
971}
972
973bool
974ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
975 SDValue &Base,
976 SDValue &Offset) {
977 return SelectThumbAddrModeRI(N, Base, Offset, 4);
978}
979
980bool
981ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
982 SDValue &Base, SDValue &OffImm) {
983 if (Scale == 4) {
984 SDValue TmpBase, TmpOffImm;
985 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
986 return false; // We want to select tLDRspi / tSTRspi instead.
987
988 if (N.getOpcode() == ARMISD::Wrapper &&
989 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
990 return false; // We want to select tLDRpci instead.
991 }
992
993 if (N.getOpcode() != ISD::ADD) {
994 if (N.getOpcode() == ARMISD::Wrapper &&
995 !(Subtarget->useMovt() &&
996 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
997 Base = N.getOperand(0);
998 } else {
999 Base = N;
1000 }
1001
Owen Anderson825b72b2009-08-11 20:47:22 +00001002 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001003 return true;
1004 }
1005
Evan Chenga8e29892007-01-19 07:51:42 +00001006 // If the RHS is + imm5 * scale, fold into addr mode.
1007 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001008 int RHSC = (int)RHS->getZExtValue();
Bill Wendlingf4caf692010-12-14 03:36:38 +00001009
1010 if ((RHSC & (Scale - 1)) == 0) { // The constant is implicitly multiplied.
Evan Chenga8e29892007-01-19 07:51:42 +00001011 RHSC /= Scale;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001012
Evan Chenga8e29892007-01-19 07:51:42 +00001013 if (RHSC >= 0 && RHSC < 32) {
1014 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001015 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001016 return true;
1017 }
1018 }
1019 }
1020
Evan Chengc38f2bc2007-01-23 22:59:13 +00001021 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001022 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001023 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001024}
1025
Bill Wendlingf4caf692010-12-14 03:36:38 +00001026bool
1027ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1028 SDValue &OffImm) {
1029 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001030}
1031
Bill Wendlingf4caf692010-12-14 03:36:38 +00001032bool
1033ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1034 SDValue &OffImm) {
1035 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001036}
1037
Bill Wendlingf4caf692010-12-14 03:36:38 +00001038bool
1039ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1040 SDValue &OffImm) {
1041 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001042}
1043
Chris Lattner52a261b2010-09-21 20:31:19 +00001044bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1045 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001046 if (N.getOpcode() == ISD::FrameIndex) {
1047 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1048 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001049 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001050 return true;
1051 }
Evan Cheng79d43262007-01-24 02:21:22 +00001052
Evan Chengad0e4652007-02-06 00:22:06 +00001053 if (N.getOpcode() != ISD::ADD)
1054 return false;
1055
1056 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001057 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1058 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001059 // If the RHS is + imm8 * scale, fold into addr mode.
1060 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001061 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +00001062 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
1063 RHSC >>= 2;
1064 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +00001065 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001066 if (Base.getOpcode() == ISD::FrameIndex) {
1067 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1068 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1069 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001070 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +00001071 return true;
1072 }
1073 }
1074 }
1075 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001076
Evan Chenga8e29892007-01-19 07:51:42 +00001077 return false;
1078}
1079
Bill Wendlingf4caf692010-12-14 03:36:38 +00001080
1081//===----------------------------------------------------------------------===//
1082// Thumb 2 Addressing Modes
1083//===----------------------------------------------------------------------===//
1084
1085
Chris Lattner52a261b2010-09-21 20:31:19 +00001086bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001087 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001088 if (DisableShifterOp)
1089 return false;
1090
Evan Cheng9cb9e672009-06-27 02:26:13 +00001091 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
1092
1093 // Don't match base register only case. That is matched to a separate
1094 // lower complexity pattern with explicit register operand.
1095 if (ShOpcVal == ARM_AM::no_shift) return false;
1096
1097 BaseReg = N.getOperand(0);
1098 unsigned ShImmVal = 0;
1099 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1100 ShImmVal = RHS->getZExtValue() & 31;
1101 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1102 return true;
1103 }
1104
1105 return false;
1106}
1107
Chris Lattner52a261b2010-09-21 20:31:19 +00001108bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001109 SDValue &Base, SDValue &OffImm) {
1110 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001111
Evan Cheng3a214252009-08-11 08:52:18 +00001112 // Base only.
1113 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001114 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +00001115 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +00001116 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1117 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001118 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001119 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001120 } else if (N.getOpcode() == ARMISD::Wrapper &&
1121 !(Subtarget->useMovt() &&
1122 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001123 Base = N.getOperand(0);
1124 if (Base.getOpcode() == ISD::TargetConstantPool)
1125 return false; // We want to select t2LDRpci instead.
1126 } else
1127 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001128 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001129 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001130 }
Evan Cheng055b0312009-06-29 07:51:04 +00001131
1132 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001133 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001134 // Let t2LDRi8 handle (R - imm8).
1135 return false;
1136
Evan Cheng055b0312009-06-29 07:51:04 +00001137 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001138 if (N.getOpcode() == ISD::SUB)
1139 RHSC = -RHSC;
1140
1141 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001142 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001143 if (Base.getOpcode() == ISD::FrameIndex) {
1144 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1145 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1146 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001147 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001148 return true;
1149 }
1150 }
1151
Evan Cheng3a214252009-08-11 08:52:18 +00001152 // Base only.
1153 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001154 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001155 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001156}
1157
Chris Lattner52a261b2010-09-21 20:31:19 +00001158bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001159 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001160 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +00001161 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +00001162 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1163 int RHSC = (int)RHS->getSExtValue();
1164 if (N.getOpcode() == ISD::SUB)
1165 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001166
Evan Cheng3a214252009-08-11 08:52:18 +00001167 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1168 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +00001169 if (Base.getOpcode() == ISD::FrameIndex) {
1170 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1171 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1172 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001173 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +00001174 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001175 }
Evan Cheng055b0312009-06-29 07:51:04 +00001176 }
1177 }
1178
1179 return false;
1180}
1181
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001182bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001183 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001184 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001185 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1186 ? cast<LoadSDNode>(Op)->getAddressingMode()
1187 : cast<StoreSDNode>(Op)->getAddressingMode();
1188 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
1189 int RHSC = (int)RHS->getZExtValue();
1190 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +00001191 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +00001192 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1193 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001194 return true;
1195 }
1196 }
1197
1198 return false;
1199}
1200
Chris Lattner52a261b2010-09-21 20:31:19 +00001201bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001202 SDValue &Base,
1203 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001204 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
1205 if (N.getOpcode() != ISD::ADD)
1206 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001207
Evan Cheng3a214252009-08-11 08:52:18 +00001208 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1209 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1210 int RHSC = (int)RHS->getZExtValue();
1211 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1212 return false;
1213 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001214 return false;
1215 }
1216
Evan Chengf40deed2010-10-27 23:41:30 +00001217 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1218 // Compute R + (R << [1,2,3]) and reuse it.
1219 Base = N;
1220 return false;
1221 }
1222
Evan Cheng055b0312009-06-29 07:51:04 +00001223 // Look for (R + R) or (R + (R << [1,2,3])).
1224 unsigned ShAmt = 0;
1225 Base = N.getOperand(0);
1226 OffReg = N.getOperand(1);
1227
1228 // Swap if it is ((R << c) + R).
1229 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1230 if (ShOpcVal != ARM_AM::lsl) {
1231 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1232 if (ShOpcVal == ARM_AM::lsl)
1233 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001234 }
1235
Evan Cheng055b0312009-06-29 07:51:04 +00001236 if (ShOpcVal == ARM_AM::lsl) {
1237 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1238 // it.
1239 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1240 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001241 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1242 OffReg = OffReg.getOperand(0);
1243 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001244 ShAmt = 0;
1245 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001246 }
Evan Cheng055b0312009-06-29 07:51:04 +00001247 } else {
1248 ShOpcVal = ARM_AM::no_shift;
1249 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001250 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001251
Owen Anderson825b72b2009-08-11 20:47:22 +00001252 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001253
1254 return true;
1255}
1256
1257//===--------------------------------------------------------------------===//
1258
Evan Chengee568cf2007-07-05 07:15:27 +00001259/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001260static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001261 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001262}
1263
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001264SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1265 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001266 ISD::MemIndexedMode AM = LD->getAddressingMode();
1267 if (AM == ISD::UNINDEXED)
1268 return NULL;
1269
Owen Andersone50ed302009-08-10 22:56:29 +00001270 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001271 SDValue Offset, AMOpc;
1272 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1273 unsigned Opcode = 0;
1274 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001275 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001276 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001277 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1278 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001279 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001280 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001281 Match = true;
1282 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1283 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1284 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001285 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001286 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001287 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001288 Match = true;
1289 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1290 }
1291 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001292 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001293 Match = true;
1294 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1295 }
1296 }
1297 }
1298
1299 if (Match) {
1300 SDValue Chain = LD->getChain();
1301 SDValue Base = LD->getBasePtr();
1302 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001303 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001304 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001305 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001306 }
1307
1308 return NULL;
1309}
1310
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001311SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1312 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001313 ISD::MemIndexedMode AM = LD->getAddressingMode();
1314 if (AM == ISD::UNINDEXED)
1315 return NULL;
1316
Owen Andersone50ed302009-08-10 22:56:29 +00001317 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001318 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001319 SDValue Offset;
1320 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1321 unsigned Opcode = 0;
1322 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001323 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001324 switch (LoadedVT.getSimpleVT().SimpleTy) {
1325 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001326 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1327 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001328 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001329 if (isSExtLd)
1330 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1331 else
1332 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001333 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001334 case MVT::i8:
1335 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001336 if (isSExtLd)
1337 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1338 else
1339 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001340 break;
1341 default:
1342 return NULL;
1343 }
1344 Match = true;
1345 }
1346
1347 if (Match) {
1348 SDValue Chain = LD->getChain();
1349 SDValue Base = LD->getBasePtr();
1350 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001351 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001352 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001353 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001354 }
1355
1356 return NULL;
1357}
1358
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001359/// PairSRegs - Form a D register from a pair of S registers.
1360///
1361SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1362 DebugLoc dl = V0.getNode()->getDebugLoc();
1363 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1364 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001365 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1366 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001367}
1368
Evan Cheng603afbf2010-05-10 17:34:18 +00001369/// PairDRegs - Form a quad register from a pair of D registers.
1370///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001371SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1372 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001373 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1374 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001375 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1376 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001377}
1378
Evan Cheng7f687192010-05-14 00:21:45 +00001379/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001380///
1381SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1382 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001383 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1384 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001385 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1386 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1387}
1388
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001389/// QuadSRegs - Form 4 consecutive S registers.
1390///
1391SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1392 SDValue V2, SDValue V3) {
1393 DebugLoc dl = V0.getNode()->getDebugLoc();
1394 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1395 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1396 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1397 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1398 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1399 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1400}
1401
Evan Cheng7f687192010-05-14 00:21:45 +00001402/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001403///
1404SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1405 SDValue V2, SDValue V3) {
1406 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001407 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1408 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1409 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1410 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001411 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1412 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1413}
1414
Evan Cheng8f6de382010-05-16 03:27:48 +00001415/// QuadQRegs - Form 4 consecutive Q registers.
1416///
1417SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1418 SDValue V2, SDValue V3) {
1419 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001420 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1421 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1422 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1423 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001424 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1425 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1426}
1427
Bob Wilson2a6e6162010-09-23 23:42:37 +00001428/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1429/// of a NEON VLD or VST instruction. The supported values depend on the
1430/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001431SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1432 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001433 unsigned NumRegs = NumVecs;
1434 if (!is64BitVector && NumVecs < 3)
1435 NumRegs *= 2;
1436
Bob Wilson665814b2010-11-01 23:40:51 +00001437 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001438 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001439 Alignment = 32;
1440 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1441 Alignment = 16;
1442 else if (Alignment >= 8)
1443 Alignment = 8;
1444 else
1445 Alignment = 0;
1446
1447 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001448}
1449
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001450SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001451 unsigned *DOpcodes, unsigned *QOpcodes0,
1452 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001453 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001454 DebugLoc dl = N->getDebugLoc();
1455
Bob Wilson226036e2010-03-20 22:13:40 +00001456 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001457 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001458 return NULL;
1459
1460 SDValue Chain = N->getOperand(0);
1461 EVT VT = N->getValueType(0);
1462 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001463 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001464
Bob Wilson3e36f132009-10-14 17:28:52 +00001465 unsigned OpcodeIndex;
1466 switch (VT.getSimpleVT().SimpleTy) {
1467 default: llvm_unreachable("unhandled vld type");
1468 // Double-register operations:
1469 case MVT::v8i8: OpcodeIndex = 0; break;
1470 case MVT::v4i16: OpcodeIndex = 1; break;
1471 case MVT::v2f32:
1472 case MVT::v2i32: OpcodeIndex = 2; break;
1473 case MVT::v1i64: OpcodeIndex = 3; break;
1474 // Quad-register operations:
1475 case MVT::v16i8: OpcodeIndex = 0; break;
1476 case MVT::v8i16: OpcodeIndex = 1; break;
1477 case MVT::v4f32:
1478 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001479 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001480 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001481 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001482 }
1483
Bob Wilsonf5721912010-09-03 18:16:02 +00001484 EVT ResTy;
1485 if (NumVecs == 1)
1486 ResTy = VT;
1487 else {
1488 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1489 if (!is64BitVector)
1490 ResTyElts *= 2;
1491 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1492 }
1493
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001494 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001495 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilsonf5721912010-09-03 18:16:02 +00001496 SDValue SuperReg;
Bob Wilson3e36f132009-10-14 17:28:52 +00001497 if (is64BitVector) {
1498 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001499 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonf5721912010-09-03 18:16:02 +00001500 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001501 if (NumVecs == 1)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001502 return VLd;
1503
Bob Wilsonf5721912010-09-03 18:16:02 +00001504 SuperReg = SDValue(VLd, 0);
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001505 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001506 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001507 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Bob Wilsonffde0802010-09-02 16:00:54 +00001508 dl, VT, SuperReg);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001509 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001510 }
Bob Wilsonf5721912010-09-03 18:16:02 +00001511 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
Evan Chenge9e2ba02010-05-10 21:26:24 +00001512 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001513 }
1514
Bob Wilson621f1952010-03-23 05:25:43 +00001515 if (NumVecs <= 2) {
1516 // Quad registers are directly supported for VLD1 and VLD2,
1517 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001518 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001519 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonffde0802010-09-02 16:00:54 +00001520 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001521 if (NumVecs == 1)
1522 return VLd;
1523
Bob Wilsonf5721912010-09-03 18:16:02 +00001524 SuperReg = SDValue(VLd, 0);
Bob Wilsonffde0802010-09-02 16:00:54 +00001525 Chain = SDValue(VLd, 1);
1526
Bob Wilson3e36f132009-10-14 17:28:52 +00001527 } else {
1528 // Otherwise, quad registers are loaded with two separate instructions,
1529 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001530 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001531
Bob Wilson24f995d2009-10-14 18:32:29 +00001532 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001533 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001534 SDValue ImplDef =
1535 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1536 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
1537 SDNode *VLdA =
1538 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsA, 7);
1539 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001540
Bob Wilson24f995d2009-10-14 18:32:29 +00001541 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001542 Opc = QOpcodes1[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001543 const SDValue OpsB[] = { SDValue(VLdA, 1), Align, Reg0, SDValue(VLdA, 0),
1544 Pred, Reg0, Chain };
1545 SDNode *VLdB =
1546 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsB, 7);
1547 SuperReg = SDValue(VLdB, 0);
1548 Chain = SDValue(VLdB, 2);
1549 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001550
Bob Wilsonf5721912010-09-03 18:16:02 +00001551 // Extract out the Q registers.
1552 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1553 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1554 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1555 dl, VT, SuperReg);
1556 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001557 }
1558 ReplaceUses(SDValue(N, NumVecs), Chain);
1559 return NULL;
1560}
1561
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001562SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001563 unsigned *DOpcodes, unsigned *QOpcodes0,
1564 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001565 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001566 DebugLoc dl = N->getDebugLoc();
1567
Bob Wilson226036e2010-03-20 22:13:40 +00001568 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001569 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001570 return NULL;
1571
1572 SDValue Chain = N->getOperand(0);
1573 EVT VT = N->getOperand(3).getValueType();
1574 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001575 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001576
Bob Wilson24f995d2009-10-14 18:32:29 +00001577 unsigned OpcodeIndex;
1578 switch (VT.getSimpleVT().SimpleTy) {
1579 default: llvm_unreachable("unhandled vst type");
1580 // Double-register operations:
1581 case MVT::v8i8: OpcodeIndex = 0; break;
1582 case MVT::v4i16: OpcodeIndex = 1; break;
1583 case MVT::v2f32:
1584 case MVT::v2i32: OpcodeIndex = 2; break;
1585 case MVT::v1i64: OpcodeIndex = 3; break;
1586 // Quad-register operations:
1587 case MVT::v16i8: OpcodeIndex = 0; break;
1588 case MVT::v8i16: OpcodeIndex = 1; break;
1589 case MVT::v4f32:
1590 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001591 case MVT::v2i64: OpcodeIndex = 3;
1592 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1593 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001594 }
1595
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001596 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001597 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001598
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001599 SmallVector<SDValue, 7> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001600 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001601 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001602
1603 if (is64BitVector) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001604 if (NumVecs == 1) {
1605 Ops.push_back(N->getOperand(3));
1606 } else {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001607 SDValue RegSeq;
1608 SDValue V0 = N->getOperand(0+3);
1609 SDValue V1 = N->getOperand(1+3);
1610
1611 // Form a REG_SEQUENCE to force register allocation.
1612 if (NumVecs == 2)
1613 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1614 else {
1615 SDValue V2 = N->getOperand(2+3);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001616 // If it's a vld3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001617 // an undef.
1618 SDValue V3 = (NumVecs == 3)
1619 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1620 : N->getOperand(3+3);
1621 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1622 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001623 Ops.push_back(RegSeq);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001624 }
Evan Chengac0869d2009-11-21 06:21:52 +00001625 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001626 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001627 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001628 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001629 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001630 }
1631
Bob Wilson11d98992010-03-23 06:20:33 +00001632 if (NumVecs <= 2) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001633 // Quad registers are directly supported for VST1 and VST2.
Bob Wilson24f995d2009-10-14 18:32:29 +00001634 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001635 if (NumVecs == 1) {
1636 Ops.push_back(N->getOperand(3));
1637 } else {
1638 // Form a QQ register.
Evan Cheng603afbf2010-05-10 17:34:18 +00001639 SDValue Q0 = N->getOperand(3);
1640 SDValue Q1 = N->getOperand(4);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001641 Ops.push_back(SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0));
Bob Wilson24f995d2009-10-14 18:32:29 +00001642 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001643 Ops.push_back(Pred);
1644 Ops.push_back(Reg0); // predicate register
1645 Ops.push_back(Chain);
1646 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001647 }
1648
1649 // Otherwise, quad registers are stored with two separate instructions,
1650 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001651
Bob Wilson07f6e802010-06-16 21:34:01 +00001652 // Form the QQQQ REG_SEQUENCE.
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001653 SDValue V0 = N->getOperand(0+3);
1654 SDValue V1 = N->getOperand(1+3);
1655 SDValue V2 = N->getOperand(2+3);
1656 SDValue V3 = (NumVecs == 3)
1657 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1658 : N->getOperand(3+3);
1659 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001660
1661 // Store the even D registers.
Bob Wilson07f6e802010-06-16 21:34:01 +00001662 Ops.push_back(Reg0); // post-access address offset
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001663 Ops.push_back(RegSeq);
Bob Wilson07f6e802010-06-16 21:34:01 +00001664 Ops.push_back(Pred);
1665 Ops.push_back(Reg0); // predicate register
1666 Ops.push_back(Chain);
1667 unsigned Opc = QOpcodes0[OpcodeIndex];
1668 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001669 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001670 Chain = SDValue(VStA, 1);
1671
1672 // Store the odd D registers.
1673 Ops[0] = SDValue(VStA, 0); // MemAddr
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001674 Ops[6] = Chain;
Bob Wilson07f6e802010-06-16 21:34:01 +00001675 Opc = QOpcodes1[OpcodeIndex];
1676 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001677 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001678 Chain = SDValue(VStB, 1);
1679 ReplaceUses(SDValue(N, 0), Chain);
1680 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001681}
1682
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001683SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001684 unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001685 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001686 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001687 DebugLoc dl = N->getDebugLoc();
1688
Bob Wilson226036e2010-03-20 22:13:40 +00001689 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001690 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001691 return NULL;
1692
1693 SDValue Chain = N->getOperand(0);
1694 unsigned Lane =
1695 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001696 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001697 bool is64BitVector = VT.is64BitVector();
1698
Bob Wilson665814b2010-11-01 23:40:51 +00001699 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001700 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001701 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001702 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1703 if (Alignment > NumBytes)
1704 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001705 if (Alignment < 8 && Alignment < NumBytes)
1706 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001707 // Alignment must be a power of two; make sure of that.
1708 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001709 if (Alignment == 1)
1710 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001711 }
Bob Wilson665814b2010-11-01 23:40:51 +00001712 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001713
Bob Wilsona7c397c2009-10-14 16:19:03 +00001714 unsigned OpcodeIndex;
1715 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001716 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001717 // Double-register operations:
1718 case MVT::v8i8: OpcodeIndex = 0; break;
1719 case MVT::v4i16: OpcodeIndex = 1; break;
1720 case MVT::v2f32:
1721 case MVT::v2i32: OpcodeIndex = 2; break;
1722 // Quad-register operations:
1723 case MVT::v8i16: OpcodeIndex = 0; break;
1724 case MVT::v4f32:
1725 case MVT::v4i32: OpcodeIndex = 1; break;
1726 }
1727
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001728 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001729 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001730
Bob Wilson8466fa12010-09-13 23:01:35 +00001731 SmallVector<SDValue, 7> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001732 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001733 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001734
Jim Grosbach3ab56582010-10-21 19:38:40 +00001735 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
Eric Christopher23da0b22010-09-14 08:31:25 +00001736 QOpcodes[OpcodeIndex]);
Bob Wilson07f6e802010-06-16 21:34:01 +00001737
Bob Wilson8466fa12010-09-13 23:01:35 +00001738 SDValue SuperReg;
1739 SDValue V0 = N->getOperand(0+3);
1740 SDValue V1 = N->getOperand(1+3);
1741 if (NumVecs == 2) {
1742 if (is64BitVector)
1743 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1744 else
1745 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001746 } else {
Bob Wilson8466fa12010-09-13 23:01:35 +00001747 SDValue V2 = N->getOperand(2+3);
1748 SDValue V3 = (NumVecs == 3)
1749 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1750 : N->getOperand(3+3);
1751 if (is64BitVector)
1752 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1753 else
1754 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001755 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001756 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001757 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001758 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001759 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001760 Ops.push_back(Chain);
1761
Bob Wilson96493442009-10-14 16:46:45 +00001762 if (!IsLoad)
Bob Wilson8466fa12010-09-13 23:01:35 +00001763 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 7);
Bob Wilson96493442009-10-14 16:46:45 +00001764
Bob Wilson8466fa12010-09-13 23:01:35 +00001765 EVT ResTy;
1766 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1767 if (!is64BitVector)
1768 ResTyElts *= 2;
1769 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001770
Bob Wilson8466fa12010-09-13 23:01:35 +00001771 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other,
1772 Ops.data(), 7);
1773 SuperReg = SDValue(VLdLn, 0);
1774 Chain = SDValue(VLdLn, 1);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001775
Bob Wilson8466fa12010-09-13 23:01:35 +00001776 // Extract the subregisters.
Bob Wilson07f6e802010-06-16 21:34:01 +00001777 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1778 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1779 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1780 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1781 ReplaceUses(SDValue(N, Vec),
Bob Wilson8466fa12010-09-13 23:01:35 +00001782 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1783 ReplaceUses(SDValue(N, NumVecs), Chain);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001784 return NULL;
1785}
1786
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001787SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, unsigned NumVecs,
1788 unsigned *Opcodes) {
1789 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1790 DebugLoc dl = N->getDebugLoc();
1791
1792 SDValue MemAddr, Align;
1793 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1794 return NULL;
1795
1796 SDValue Chain = N->getOperand(0);
1797 EVT VT = N->getValueType(0);
1798
1799 unsigned Alignment = 0;
1800 if (NumVecs != 3) {
1801 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1802 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1803 if (Alignment > NumBytes)
1804 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001805 if (Alignment < 8 && Alignment < NumBytes)
1806 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001807 // Alignment must be a power of two; make sure of that.
1808 Alignment = (Alignment & -Alignment);
1809 if (Alignment == 1)
1810 Alignment = 0;
1811 }
1812 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1813
1814 unsigned OpcodeIndex;
1815 switch (VT.getSimpleVT().SimpleTy) {
1816 default: llvm_unreachable("unhandled vld-dup type");
1817 case MVT::v8i8: OpcodeIndex = 0; break;
1818 case MVT::v4i16: OpcodeIndex = 1; break;
1819 case MVT::v2f32:
1820 case MVT::v2i32: OpcodeIndex = 2; break;
1821 }
1822
1823 SDValue Pred = getAL(CurDAG);
1824 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1825 SDValue SuperReg;
1826 unsigned Opc = Opcodes[OpcodeIndex];
1827 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
1828
1829 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1830 EVT ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1831 SDNode *VLdDup = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
1832 SuperReg = SDValue(VLdDup, 0);
1833 Chain = SDValue(VLdDup, 1);
1834
1835 // Extract the subregisters.
1836 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1837 unsigned SubIdx = ARM::dsub_0;
1838 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1839 ReplaceUses(SDValue(N, Vec),
1840 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1841 ReplaceUses(SDValue(N, NumVecs), Chain);
1842 return NULL;
1843}
1844
Bob Wilson78dfbc32010-07-07 00:08:54 +00001845SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1846 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001847 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1848 DebugLoc dl = N->getDebugLoc();
1849 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001850 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001851
1852 // Form a REG_SEQUENCE to force register allocation.
1853 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001854 SDValue V0 = N->getOperand(FirstTblReg + 0);
1855 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001856 if (NumVecs == 2)
1857 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1858 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001859 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001860 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001861 // an undef.
1862 SDValue V3 = (NumVecs == 3)
1863 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001864 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001865 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1866 }
1867
Bob Wilson78dfbc32010-07-07 00:08:54 +00001868 SmallVector<SDValue, 6> Ops;
1869 if (IsExt)
1870 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001871 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001872 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001873 Ops.push_back(getAL(CurDAG)); // predicate
1874 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001875 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001876}
1877
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001878SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001879 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001880 if (!Subtarget->hasV6T2Ops())
1881 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001882
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001883 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1884 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1885
1886
1887 // For unsigned extracts, check for a shift right and mask
1888 unsigned And_imm = 0;
1889 if (N->getOpcode() == ISD::AND) {
1890 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1891
1892 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1893 if (And_imm & (And_imm + 1))
1894 return NULL;
1895
1896 unsigned Srl_imm = 0;
1897 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1898 Srl_imm)) {
1899 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1900
1901 unsigned Width = CountTrailingOnes_32(And_imm);
1902 unsigned LSB = Srl_imm;
1903 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1904 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1905 CurDAG->getTargetConstant(LSB, MVT::i32),
1906 CurDAG->getTargetConstant(Width, MVT::i32),
1907 getAL(CurDAG), Reg0 };
1908 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1909 }
1910 }
1911 return NULL;
1912 }
1913
1914 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001915 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001916 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001917 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1918 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001919 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001920 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1921 unsigned Width = 32 - Srl_imm;
1922 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001923 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001924 return NULL;
1925 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001926 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001927 CurDAG->getTargetConstant(LSB, MVT::i32),
1928 CurDAG->getTargetConstant(Width, MVT::i32),
1929 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001930 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001931 }
1932 }
1933 return NULL;
1934}
1935
Evan Cheng9ef48352009-11-20 00:54:03 +00001936SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001937SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001938 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1939 SDValue CPTmp0;
1940 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001941 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001942 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1943 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1944 unsigned Opc = 0;
1945 switch (SOShOp) {
1946 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1947 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1948 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1949 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1950 default:
1951 llvm_unreachable("Unknown so_reg opcode!");
1952 break;
1953 }
1954 SDValue SOShImm =
1955 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1956 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1957 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001958 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001959 }
1960 return 0;
1961}
1962
1963SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001964SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001965 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1966 SDValue CPTmp0;
1967 SDValue CPTmp1;
1968 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00001969 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001970 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1971 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001972 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001973 }
1974 return 0;
1975}
1976
1977SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00001978SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00001979 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001980 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00001981 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00001982 return 0;
1983
Evan Cheng63f35442010-11-13 02:25:14 +00001984 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00001985 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00001986 if (is_t2_so_imm(TrueImm)) {
1987 Opc = ARM::t2MOVCCi;
1988 } else if (TrueImm <= 0xffff) {
1989 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00001990 } else if (is_t2_so_imm_not(TrueImm)) {
1991 TrueImm = ~TrueImm;
1992 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00001993 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00001994 // Large immediate.
1995 Opc = ARM::t2MOVCCi32imm;
1996 }
1997
1998 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00001999 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002000 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2001 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002002 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002003 }
Evan Cheng63f35442010-11-13 02:25:14 +00002004
Evan Cheng9ef48352009-11-20 00:54:03 +00002005 return 0;
2006}
2007
2008SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002009SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002010 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002011 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2012 if (!T)
2013 return 0;
2014
Evan Cheng63f35442010-11-13 02:25:14 +00002015 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002016 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002017 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002018 if (isSoImm) {
2019 Opc = ARM::MOVCCi;
2020 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2021 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002022 } else if (is_so_imm_not(TrueImm)) {
2023 TrueImm = ~TrueImm;
2024 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002025 } else if (TrueVal.getNode()->hasOneUse() &&
2026 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002027 // Large immediate.
2028 Opc = ARM::MOVCCi32imm;
2029 }
2030
2031 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002032 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002033 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2034 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002035 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002036 }
Evan Cheng63f35442010-11-13 02:25:14 +00002037
Evan Cheng9ef48352009-11-20 00:54:03 +00002038 return 0;
2039}
2040
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002041SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2042 EVT VT = N->getValueType(0);
2043 SDValue FalseVal = N->getOperand(0);
2044 SDValue TrueVal = N->getOperand(1);
2045 SDValue CC = N->getOperand(2);
2046 SDValue CCR = N->getOperand(3);
2047 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002048 assert(CC.getOpcode() == ISD::Constant);
2049 assert(CCR.getOpcode() == ISD::Register);
2050 ARMCC::CondCodes CCVal =
2051 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002052
2053 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2054 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2055 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2056 // Pattern complexity = 18 cost = 1 size = 0
2057 SDValue CPTmp0;
2058 SDValue CPTmp1;
2059 SDValue CPTmp2;
2060 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002061 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002062 CCVal, CCR, InFlag);
2063 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002064 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002065 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2066 if (Res)
2067 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002068 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002069 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002070 CCVal, CCR, InFlag);
2071 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002072 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002073 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2074 if (Res)
2075 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002076 }
2077
2078 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002079 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002080 // (imm:i32):$cc)
2081 // Emits: (MOVCCi:i32 GPR:i32:$false,
2082 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2083 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002084 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002085 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002086 CCVal, CCR, InFlag);
2087 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002088 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002089 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2090 if (Res)
2091 return Res;
2092 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002093 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002094 CCVal, CCR, InFlag);
2095 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002096 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002097 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2098 if (Res)
2099 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002100 }
2101 }
2102
2103 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2104 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2105 // Pattern complexity = 6 cost = 1 size = 0
2106 //
2107 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2108 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2109 // Pattern complexity = 6 cost = 11 size = 0
2110 //
2111 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002112 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2113 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002114 unsigned Opc = 0;
2115 switch (VT.getSimpleVT().SimpleTy) {
2116 default: assert(false && "Illegal conditional move type!");
2117 break;
2118 case MVT::i32:
2119 Opc = Subtarget->isThumb()
2120 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2121 : ARM::MOVCCr;
2122 break;
2123 case MVT::f32:
2124 Opc = ARM::VMOVScc;
2125 break;
2126 case MVT::f64:
2127 Opc = ARM::VMOVDcc;
2128 break;
2129 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002130 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002131}
2132
Evan Chengde8aa4e2010-05-05 18:28:36 +00002133SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2134 // The only time a CONCAT_VECTORS operation can have legal types is when
2135 // two 64-bit vectors are concatenated to a 128-bit vector.
2136 EVT VT = N->getValueType(0);
2137 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2138 llvm_unreachable("unexpected CONCAT_VECTORS");
2139 DebugLoc dl = N->getDebugLoc();
2140 SDValue V0 = N->getOperand(0);
2141 SDValue V1 = N->getOperand(1);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00002142 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
2143 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Evan Chengde8aa4e2010-05-05 18:28:36 +00002144 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
2145 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
2146}
2147
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002148SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002149 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002150
Dan Gohmane8be6c62008-07-17 19:10:17 +00002151 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002152 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002153
2154 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002155 default: break;
2156 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002157 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002158 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002159 if (Subtarget->hasThumb2())
2160 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2161 // be done with MOV + MOVT, at worst.
2162 UseCP = 0;
2163 else {
2164 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002165 UseCP = (Val > 255 && // MOV
2166 ~Val > 255 && // MOV + MVN
2167 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002168 } else
2169 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2170 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2171 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2172 }
2173
Evan Chenga8e29892007-01-19 07:51:42 +00002174 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002175 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002176 CurDAG->getTargetConstantPool(ConstantInt::get(
2177 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002178 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002179
2180 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002181 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002182 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002183 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002184 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Dan Gohman602b0c82009-09-25 18:54:59 +00002185 ResNode = CurDAG->getMachineNode(ARM::tLDRcp, dl, MVT::i32, MVT::Other,
2186 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002187 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002188 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002189 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002190 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002191 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002192 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002193 CurDAG->getEntryNode()
2194 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002195 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002196 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002197 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002198 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002199 return NULL;
2200 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002201
Evan Chenga8e29892007-01-19 07:51:42 +00002202 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002203 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002204 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002205 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002206 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002207 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002208 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002209 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002210 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2211 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002212 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002213 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2214 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002215 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2216 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2217 CurDAG->getRegister(0, MVT::i32) };
2218 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002219 }
Evan Chenga8e29892007-01-19 07:51:42 +00002220 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002221 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002222 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002223 return I;
2224 break;
2225 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002226 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002227 return I;
2228 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002229 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002230 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002231 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002232 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002233 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002234 if (!RHSV) break;
2235 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002236 unsigned ShImm = Log2_32(RHSV-1);
2237 if (ShImm >= 32)
2238 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002239 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002240 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002241 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2242 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002243 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002244 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002245 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002246 } else {
2247 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002248 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002249 }
Evan Chenga8e29892007-01-19 07:51:42 +00002250 }
2251 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002252 unsigned ShImm = Log2_32(RHSV+1);
2253 if (ShImm >= 32)
2254 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002255 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002256 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002257 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2258 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002259 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002260 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2261 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002262 } else {
2263 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002264 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002265 }
Evan Chenga8e29892007-01-19 07:51:42 +00002266 }
2267 }
2268 break;
Evan Cheng20956592009-10-21 08:15:52 +00002269 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002270 // Check for unsigned bitfield extract
2271 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2272 return I;
2273
Evan Cheng20956592009-10-21 08:15:52 +00002274 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2275 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2276 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2277 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2278 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002279 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002280 if (VT != MVT::i32)
2281 break;
2282 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2283 ? ARM::t2MOVTi16
2284 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2285 if (!Opc)
2286 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002287 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002288 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2289 if (!N1C)
2290 break;
2291 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2292 SDValue N2 = N0.getOperand(1);
2293 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2294 if (!N2C)
2295 break;
2296 unsigned N1CVal = N1C->getZExtValue();
2297 unsigned N2CVal = N2C->getZExtValue();
2298 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2299 (N1CVal & 0xffffU) == 0xffffU &&
2300 (N2CVal & 0xffffU) == 0x0U) {
2301 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2302 MVT::i32);
2303 SDValue Ops[] = { N0.getOperand(0), Imm16,
2304 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2305 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2306 }
2307 }
2308 break;
2309 }
Jim Grosbache5165492009-11-09 00:11:35 +00002310 case ARMISD::VMOVRRD:
2311 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002312 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002313 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002314 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002315 if (Subtarget->isThumb1Only())
2316 break;
2317 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002318 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002319 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2320 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002321 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002322 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002323 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002324 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2325 CurDAG->getRegister(0, MVT::i32) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002326 return CurDAG->getMachineNode(ARM::UMULL, 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) };
Dan Gohman602b0c82009-09-25 18:54:59 +00002340 return CurDAG->getMachineNode(ARM::SMULL, dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002341 }
Evan Chengee568cf2007-07-05 07:15:27 +00002342 }
Evan Chenga8e29892007-01-19 07:51:42 +00002343 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002344 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002345 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002346 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002347 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002348 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002349 if (ResNode)
2350 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002351 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002352 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002353 }
Evan Chengee568cf2007-07-05 07:15:27 +00002354 case ARMISD::BRCOND: {
2355 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2356 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2357 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002358
Evan Chengee568cf2007-07-05 07:15:27 +00002359 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2360 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2361 // Pattern complexity = 6 cost = 1 size = 0
2362
David Goodwin5e47a9a2009-06-30 18:04:13 +00002363 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2364 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2365 // Pattern complexity = 6 cost = 1 size = 0
2366
Jim Grosbach764ab522009-08-11 15:33:49 +00002367 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002368 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002369 SDValue Chain = N->getOperand(0);
2370 SDValue N1 = N->getOperand(1);
2371 SDValue N2 = N->getOperand(2);
2372 SDValue N3 = N->getOperand(3);
2373 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002374 assert(N1.getOpcode() == ISD::BasicBlock);
2375 assert(N2.getOpcode() == ISD::Constant);
2376 assert(N3.getOpcode() == ISD::Register);
2377
Dan Gohman475871a2008-07-27 21:46:04 +00002378 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002379 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002380 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002381 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002382 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
2383 MVT::Flag, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002384 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002385 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002386 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002387 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002388 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002389 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002390 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002391 return NULL;
2392 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002393 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002394 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002395 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002396 EVT VT = N->getValueType(0);
2397 SDValue N0 = N->getOperand(0);
2398 SDValue N1 = N->getOperand(1);
2399 SDValue N2 = N->getOperand(2);
2400 SDValue N3 = N->getOperand(3);
2401 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002402 assert(N2.getOpcode() == ISD::Constant);
2403 assert(N3.getOpcode() == ISD::Register);
2404
Dan Gohman475871a2008-07-27 21:46:04 +00002405 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002406 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002407 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002408 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002409 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002410 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002411 default: assert(false && "Illegal conditional move type!");
2412 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002413 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002414 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002415 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002416 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002417 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002418 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002419 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002420 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002421 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002422
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002423 case ARMISD::VZIP: {
2424 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002425 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002426 switch (VT.getSimpleVT().SimpleTy) {
2427 default: return NULL;
2428 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2429 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2430 case MVT::v2f32:
2431 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2432 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2433 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2434 case MVT::v4f32:
2435 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2436 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002437 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002438 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2439 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2440 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002441 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002442 case ARMISD::VUZP: {
2443 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002444 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002445 switch (VT.getSimpleVT().SimpleTy) {
2446 default: return NULL;
2447 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2448 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2449 case MVT::v2f32:
2450 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2451 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2452 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2453 case MVT::v4f32:
2454 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2455 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002456 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002457 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2458 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2459 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002460 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002461 case ARMISD::VTRN: {
2462 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002463 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002464 switch (VT.getSimpleVT().SimpleTy) {
2465 default: return NULL;
2466 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2467 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2468 case MVT::v2f32:
2469 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2470 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2471 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2472 case MVT::v4f32:
2473 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2474 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002475 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002476 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2477 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2478 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002479 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002480 case ARMISD::BUILD_VECTOR: {
2481 EVT VecVT = N->getValueType(0);
2482 EVT EltVT = VecVT.getVectorElementType();
2483 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002484 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002485 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2486 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2487 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002488 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002489 if (NumElts == 2)
2490 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2491 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2492 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2493 N->getOperand(2), N->getOperand(3));
2494 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002495
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002496 case ARMISD::VLD2DUP: {
2497 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2498 ARM::VLD2DUPd32Pseudo };
2499 return SelectVLDDup(N, 2, Opcodes);
2500 }
2501
Bob Wilson86c6d802010-11-29 19:35:29 +00002502 case ARMISD::VLD3DUP: {
2503 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2504 ARM::VLD3DUPd32Pseudo };
2505 return SelectVLDDup(N, 3, Opcodes);
2506 }
2507
Bob Wilson6c4c9822010-11-30 00:00:35 +00002508 case ARMISD::VLD4DUP: {
2509 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2510 ARM::VLD4DUPd32Pseudo };
2511 return SelectVLDDup(N, 4, Opcodes);
2512 }
2513
Bob Wilson31fb12f2009-08-26 17:39:53 +00002514 case ISD::INTRINSIC_VOID:
2515 case ISD::INTRINSIC_W_CHAIN: {
2516 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002517 switch (IntNo) {
2518 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002519 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002520
Bob Wilson621f1952010-03-23 05:25:43 +00002521 case Intrinsic::arm_neon_vld1: {
2522 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2523 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002524 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2525 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson621f1952010-03-23 05:25:43 +00002526 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2527 }
2528
Bob Wilson31fb12f2009-08-26 17:39:53 +00002529 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002530 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2531 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2532 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2533 ARM::VLD2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002534 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002535 }
2536
2537 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002538 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2539 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2540 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2541 ARM::VLD3q16Pseudo_UPD,
2542 ARM::VLD3q32Pseudo_UPD };
2543 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2544 ARM::VLD3q16oddPseudo_UPD,
2545 ARM::VLD3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002546 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002547 }
2548
2549 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002550 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2551 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2552 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2553 ARM::VLD4q16Pseudo_UPD,
2554 ARM::VLD4q32Pseudo_UPD };
2555 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2556 ARM::VLD4q16oddPseudo_UPD,
2557 ARM::VLD4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002558 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002559 }
2560
Bob Wilson243fcc52009-09-01 04:26:28 +00002561 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002562 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2563 ARM::VLD2LNd32Pseudo };
2564 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
2565 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002566 }
2567
2568 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002569 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2570 ARM::VLD3LNd32Pseudo };
2571 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
2572 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002573 }
2574
2575 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002576 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2577 ARM::VLD4LNd32Pseudo };
2578 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
2579 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002580 }
2581
Bob Wilson11d98992010-03-23 06:20:33 +00002582 case Intrinsic::arm_neon_vst1: {
2583 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2584 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002585 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2586 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson11d98992010-03-23 06:20:33 +00002587 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2588 }
2589
Bob Wilson31fb12f2009-08-26 17:39:53 +00002590 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002591 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2592 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2593 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2594 ARM::VST2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002595 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002596 }
2597
2598 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002599 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2600 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2601 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2602 ARM::VST3q16Pseudo_UPD,
2603 ARM::VST3q32Pseudo_UPD };
2604 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2605 ARM::VST3q16oddPseudo_UPD,
2606 ARM::VST3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002607 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002608 }
2609
2610 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002611 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002612 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002613 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2614 ARM::VST4q16Pseudo_UPD,
2615 ARM::VST4q32Pseudo_UPD };
2616 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2617 ARM::VST4q16oddPseudo_UPD,
2618 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002619 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002620 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002621
2622 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002623 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2624 ARM::VST2LNd32Pseudo };
2625 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
2626 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002627 }
2628
2629 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002630 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2631 ARM::VST3LNd32Pseudo };
2632 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
2633 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002634 }
2635
2636 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002637 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2638 ARM::VST4LNd32Pseudo };
2639 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
2640 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002641 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002642 }
Bob Wilson429009b2010-05-06 16:05:26 +00002643 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002644 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002645
Bob Wilsond491d6e2010-07-06 23:36:25 +00002646 case ISD::INTRINSIC_WO_CHAIN: {
2647 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2648 switch (IntNo) {
2649 default:
2650 break;
2651
2652 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002653 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002654 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002655 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002656 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002657 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002658
2659 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002660 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002661 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002662 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002663 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002664 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002665 }
2666 break;
2667 }
2668
Bob Wilson429009b2010-05-06 16:05:26 +00002669 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002670 return SelectConcatVector(N);
2671 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002672
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002673 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002674}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002675
Bob Wilson224c2442009-05-19 05:53:42 +00002676bool ARMDAGToDAGISel::
2677SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2678 std::vector<SDValue> &OutOps) {
2679 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002680 // Require the address to be in a register. That is safe for all ARM
2681 // variants and it is hard to do anything much smarter without knowing
2682 // how the operand is used.
2683 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002684 return false;
2685}
2686
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002687/// createARMISelDag - This pass converts a legalized DAG into a
2688/// ARM-specific DAG, ready for instruction scheduling.
2689///
Bob Wilson522ce972009-09-28 14:30:20 +00002690FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2691 CodeGenOpt::Level OptLevel) {
2692 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002693}