blob: eb54ba518c5f363339c314254f0fe883e44eedf0 [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 Wendlingbc4224b2010-12-15 01:03:19 +0000921 if (N.getOpcode() != ISD::ADD)
922 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000923
Evan Chengad0e4652007-02-06 00:22:06 +0000924 // Thumb does not have [sp, r] address mode.
925 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
926 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
927 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000928 (RHSR && RHSR->getReg() == ARM::SP))
929 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +0000930
931 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
932 int RHSC = (int)RHS->getZExtValue();
933
934 if ((RHSC & (Scale - 1)) == 0) { // The constant is implicitly multiplied.
935 RHSC /= Scale;
936
937 if (RHSC >= 0 && RHSC < 32)
938 return false;
939 }
940 }
941
942 Base = N.getOperand(0);
943 Offset = N.getOperand(1);
944 return true;
945}
946
947bool
948ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
949 SDValue &Base,
950 SDValue &Offset) {
951 return SelectThumbAddrModeRI(N, Base, Offset, 1);
952}
953
954bool
955ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
956 SDValue &Base,
957 SDValue &Offset) {
958 return SelectThumbAddrModeRI(N, Base, Offset, 2);
959}
960
961bool
962ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
963 SDValue &Base,
964 SDValue &Offset) {
965 return SelectThumbAddrModeRI(N, Base, Offset, 4);
966}
967
968bool
969ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
970 SDValue &Base, SDValue &OffImm) {
971 if (Scale == 4) {
972 SDValue TmpBase, TmpOffImm;
973 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
974 return false; // We want to select tLDRspi / tSTRspi instead.
975
976 if (N.getOpcode() == ARMISD::Wrapper &&
977 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
978 return false; // We want to select tLDRpci instead.
979 }
980
981 if (N.getOpcode() != ISD::ADD) {
982 if (N.getOpcode() == ARMISD::Wrapper &&
983 !(Subtarget->useMovt() &&
984 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
985 Base = N.getOperand(0);
986 } else {
987 Base = N;
988 }
989
Owen Anderson825b72b2009-08-11 20:47:22 +0000990 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +0000991 return true;
992 }
993
Bill Wendlingbc4224b2010-12-15 01:03:19 +0000994 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
995 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
996 if ((LHSR && LHSR->getReg() == ARM::SP) ||
997 (RHSR && RHSR->getReg() == ARM::SP)) {
998 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
999 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1000 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1001 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1002
1003 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1004 if (LHSC != 0 || RHSC != 0) return false;
1005
1006 Base = N;
1007 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1008 return true;
1009 }
1010
Evan Chenga8e29892007-01-19 07:51:42 +00001011 // If the RHS is + imm5 * scale, fold into addr mode.
1012 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001013 int RHSC = (int)RHS->getZExtValue();
Bill Wendlingf4caf692010-12-14 03:36:38 +00001014
1015 if ((RHSC & (Scale - 1)) == 0) { // The constant is implicitly multiplied.
Evan Chenga8e29892007-01-19 07:51:42 +00001016 RHSC /= Scale;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001017
Evan Chenga8e29892007-01-19 07:51:42 +00001018 if (RHSC >= 0 && RHSC < 32) {
1019 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001020 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001021 return true;
1022 }
1023 }
1024 }
1025
Evan Chengc38f2bc2007-01-23 22:59:13 +00001026 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001027 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001028 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001029}
1030
Bill Wendlingf4caf692010-12-14 03:36:38 +00001031bool
1032ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1033 SDValue &OffImm) {
1034 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001035}
1036
Bill Wendlingf4caf692010-12-14 03:36:38 +00001037bool
1038ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1039 SDValue &OffImm) {
1040 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001041}
1042
Bill Wendlingf4caf692010-12-14 03:36:38 +00001043bool
1044ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1045 SDValue &OffImm) {
1046 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001047}
1048
Chris Lattner52a261b2010-09-21 20:31:19 +00001049bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1050 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001051 if (N.getOpcode() == ISD::FrameIndex) {
1052 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1053 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001054 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001055 return true;
1056 }
Evan Cheng79d43262007-01-24 02:21:22 +00001057
Evan Chengad0e4652007-02-06 00:22:06 +00001058 if (N.getOpcode() != ISD::ADD)
1059 return false;
1060
1061 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001062 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1063 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001064 // If the RHS is + imm8 * scale, fold into addr mode.
1065 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00001066 int RHSC = (int)RHS->getZExtValue();
Evan Cheng79d43262007-01-24 02:21:22 +00001067 if ((RHSC & 3) == 0) { // The constant is implicitly multiplied.
1068 RHSC >>= 2;
1069 if (RHSC >= 0 && RHSC < 256) {
Evan Chengad0e4652007-02-06 00:22:06 +00001070 Base = N.getOperand(0);
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001071 if (Base.getOpcode() == ISD::FrameIndex) {
1072 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1073 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1074 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001075 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng79d43262007-01-24 02:21:22 +00001076 return true;
1077 }
1078 }
1079 }
1080 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001081
Evan Chenga8e29892007-01-19 07:51:42 +00001082 return false;
1083}
1084
Bill Wendlingf4caf692010-12-14 03:36:38 +00001085
1086//===----------------------------------------------------------------------===//
1087// Thumb 2 Addressing Modes
1088//===----------------------------------------------------------------------===//
1089
1090
Chris Lattner52a261b2010-09-21 20:31:19 +00001091bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001092 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001093 if (DisableShifterOp)
1094 return false;
1095
Evan Cheng9cb9e672009-06-27 02:26:13 +00001096 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N);
1097
1098 // Don't match base register only case. That is matched to a separate
1099 // lower complexity pattern with explicit register operand.
1100 if (ShOpcVal == ARM_AM::no_shift) return false;
1101
1102 BaseReg = N.getOperand(0);
1103 unsigned ShImmVal = 0;
1104 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1105 ShImmVal = RHS->getZExtValue() & 31;
1106 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1107 return true;
1108 }
1109
1110 return false;
1111}
1112
Chris Lattner52a261b2010-09-21 20:31:19 +00001113bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001114 SDValue &Base, SDValue &OffImm) {
1115 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001116
Evan Cheng3a214252009-08-11 08:52:18 +00001117 // Base only.
1118 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001119 if (N.getOpcode() == ISD::FrameIndex) {
Evan Cheng3a214252009-08-11 08:52:18 +00001120 // Match frame index...
David Goodwin31e7eba2009-07-20 15:55:39 +00001121 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1122 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001123 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001124 return true;
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001125 } else if (N.getOpcode() == ARMISD::Wrapper &&
1126 !(Subtarget->useMovt() &&
1127 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001128 Base = N.getOperand(0);
1129 if (Base.getOpcode() == ISD::TargetConstantPool)
1130 return false; // We want to select t2LDRpci instead.
1131 } else
1132 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001133 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001134 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001135 }
Evan Cheng055b0312009-06-29 07:51:04 +00001136
1137 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001138 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001139 // Let t2LDRi8 handle (R - imm8).
1140 return false;
1141
Evan Cheng055b0312009-06-29 07:51:04 +00001142 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001143 if (N.getOpcode() == ISD::SUB)
1144 RHSC = -RHSC;
1145
1146 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001147 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001148 if (Base.getOpcode() == ISD::FrameIndex) {
1149 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1150 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1151 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001152 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001153 return true;
1154 }
1155 }
1156
Evan Cheng3a214252009-08-11 08:52:18 +00001157 // Base only.
1158 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001159 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001160 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001161}
1162
Chris Lattner52a261b2010-09-21 20:31:19 +00001163bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001164 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001165 // Match simple R - imm8 operands.
Evan Cheng3a214252009-08-11 08:52:18 +00001166 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::SUB) {
David Goodwin07337c02009-07-30 22:45:52 +00001167 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1168 int RHSC = (int)RHS->getSExtValue();
1169 if (N.getOpcode() == ISD::SUB)
1170 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001171
Evan Cheng3a214252009-08-11 08:52:18 +00001172 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1173 Base = N.getOperand(0);
David Goodwin07337c02009-07-30 22:45:52 +00001174 if (Base.getOpcode() == ISD::FrameIndex) {
1175 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1176 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1177 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001178 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
David Goodwin07337c02009-07-30 22:45:52 +00001179 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001180 }
Evan Cheng055b0312009-06-29 07:51:04 +00001181 }
1182 }
1183
1184 return false;
1185}
1186
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001187bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001188 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001189 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001190 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1191 ? cast<LoadSDNode>(Op)->getAddressingMode()
1192 : cast<StoreSDNode>(Op)->getAddressingMode();
1193 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N)) {
1194 int RHSC = (int)RHS->getZExtValue();
1195 if (RHSC >= 0 && RHSC < 0x100) { // 8 bits.
David Goodwin4cb73522009-07-14 21:29:29 +00001196 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
Owen Anderson825b72b2009-08-11 20:47:22 +00001197 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1198 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001199 return true;
1200 }
1201 }
1202
1203 return false;
1204}
1205
Chris Lattner52a261b2010-09-21 20:31:19 +00001206bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001207 SDValue &Base,
1208 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001209 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
1210 if (N.getOpcode() != ISD::ADD)
1211 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001212
Evan Cheng3a214252009-08-11 08:52:18 +00001213 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1214 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1215 int RHSC = (int)RHS->getZExtValue();
1216 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1217 return false;
1218 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001219 return false;
1220 }
1221
Evan Chengf40deed2010-10-27 23:41:30 +00001222 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
1223 // Compute R + (R << [1,2,3]) and reuse it.
1224 Base = N;
1225 return false;
1226 }
1227
Evan Cheng055b0312009-06-29 07:51:04 +00001228 // Look for (R + R) or (R + (R << [1,2,3])).
1229 unsigned ShAmt = 0;
1230 Base = N.getOperand(0);
1231 OffReg = N.getOperand(1);
1232
1233 // Swap if it is ((R << c) + R).
1234 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg);
1235 if (ShOpcVal != ARM_AM::lsl) {
1236 ShOpcVal = ARM_AM::getShiftOpcForNode(Base);
1237 if (ShOpcVal == ARM_AM::lsl)
1238 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001239 }
1240
Evan Cheng055b0312009-06-29 07:51:04 +00001241 if (ShOpcVal == ARM_AM::lsl) {
1242 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1243 // it.
1244 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1245 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001246 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1247 OffReg = OffReg.getOperand(0);
1248 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001249 ShAmt = 0;
1250 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001251 }
Evan Cheng055b0312009-06-29 07:51:04 +00001252 } else {
1253 ShOpcVal = ARM_AM::no_shift;
1254 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001255 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001256
Owen Anderson825b72b2009-08-11 20:47:22 +00001257 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001258
1259 return true;
1260}
1261
1262//===--------------------------------------------------------------------===//
1263
Evan Chengee568cf2007-07-05 07:15:27 +00001264/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001265static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001266 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001267}
1268
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001269SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1270 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001271 ISD::MemIndexedMode AM = LD->getAddressingMode();
1272 if (AM == ISD::UNINDEXED)
1273 return NULL;
1274
Owen Andersone50ed302009-08-10 22:56:29 +00001275 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001276 SDValue Offset, AMOpc;
1277 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1278 unsigned Opcode = 0;
1279 bool Match = false;
Owen Anderson825b72b2009-08-11 20:47:22 +00001280 if (LoadedVT == MVT::i32 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001281 SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001282 Opcode = isPre ? ARM::LDR_PRE : ARM::LDR_POST;
1283 Match = true;
Owen Anderson825b72b2009-08-11 20:47:22 +00001284 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001285 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001286 Match = true;
1287 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1288 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1289 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001290 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001291 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001292 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001293 Match = true;
1294 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1295 }
1296 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001297 if (SelectAddrMode2Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001298 Match = true;
1299 Opcode = isPre ? ARM::LDRB_PRE : ARM::LDRB_POST;
1300 }
1301 }
1302 }
1303
1304 if (Match) {
1305 SDValue Chain = LD->getChain();
1306 SDValue Base = LD->getBasePtr();
1307 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001308 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001309 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001310 MVT::Other, Ops, 6);
Evan Chengaf4550f2009-07-02 01:23:32 +00001311 }
1312
1313 return NULL;
1314}
1315
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001316SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1317 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001318 ISD::MemIndexedMode AM = LD->getAddressingMode();
1319 if (AM == ISD::UNINDEXED)
1320 return NULL;
1321
Owen Andersone50ed302009-08-10 22:56:29 +00001322 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001323 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001324 SDValue Offset;
1325 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1326 unsigned Opcode = 0;
1327 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001328 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001329 switch (LoadedVT.getSimpleVT().SimpleTy) {
1330 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001331 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1332 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001333 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001334 if (isSExtLd)
1335 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1336 else
1337 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001338 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001339 case MVT::i8:
1340 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001341 if (isSExtLd)
1342 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1343 else
1344 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001345 break;
1346 default:
1347 return NULL;
1348 }
1349 Match = true;
1350 }
1351
1352 if (Match) {
1353 SDValue Chain = LD->getChain();
1354 SDValue Base = LD->getBasePtr();
1355 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001356 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001357 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001358 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001359 }
1360
1361 return NULL;
1362}
1363
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001364/// PairSRegs - Form a D register from a pair of S registers.
1365///
1366SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1367 DebugLoc dl = V0.getNode()->getDebugLoc();
1368 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1369 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001370 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1371 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001372}
1373
Evan Cheng603afbf2010-05-10 17:34:18 +00001374/// PairDRegs - Form a quad register from a pair of D registers.
1375///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001376SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1377 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001378 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1379 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Bob Wilson07f6e802010-06-16 21:34:01 +00001380 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1381 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001382}
1383
Evan Cheng7f687192010-05-14 00:21:45 +00001384/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001385///
1386SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1387 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001388 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1389 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001390 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1 };
1391 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 4);
1392}
1393
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001394/// QuadSRegs - Form 4 consecutive S registers.
1395///
1396SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1397 SDValue V2, SDValue V3) {
1398 DebugLoc dl = V0.getNode()->getDebugLoc();
1399 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1400 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1401 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1402 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
1403 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1404 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1405}
1406
Evan Cheng7f687192010-05-14 00:21:45 +00001407/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001408///
1409SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1410 SDValue V2, SDValue V3) {
1411 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001412 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1413 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1414 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1415 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Evan Cheng603afbf2010-05-10 17:34:18 +00001416 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1417 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1418}
1419
Evan Cheng8f6de382010-05-16 03:27:48 +00001420/// QuadQRegs - Form 4 consecutive Q registers.
1421///
1422SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1423 SDValue V2, SDValue V3) {
1424 DebugLoc dl = V0.getNode()->getDebugLoc();
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001425 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1426 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1427 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1428 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Evan Cheng8f6de382010-05-16 03:27:48 +00001429 const SDValue Ops[] = { V0, SubReg0, V1, SubReg1, V2, SubReg2, V3, SubReg3 };
1430 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 8);
1431}
1432
Bob Wilson2a6e6162010-09-23 23:42:37 +00001433/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1434/// of a NEON VLD or VST instruction. The supported values depend on the
1435/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001436SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1437 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001438 unsigned NumRegs = NumVecs;
1439 if (!is64BitVector && NumVecs < 3)
1440 NumRegs *= 2;
1441
Bob Wilson665814b2010-11-01 23:40:51 +00001442 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001443 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001444 Alignment = 32;
1445 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1446 Alignment = 16;
1447 else if (Alignment >= 8)
1448 Alignment = 8;
1449 else
1450 Alignment = 0;
1451
1452 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001453}
1454
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001455SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001456 unsigned *DOpcodes, unsigned *QOpcodes0,
1457 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001458 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001459 DebugLoc dl = N->getDebugLoc();
1460
Bob Wilson226036e2010-03-20 22:13:40 +00001461 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001462 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001463 return NULL;
1464
1465 SDValue Chain = N->getOperand(0);
1466 EVT VT = N->getValueType(0);
1467 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001468 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001469
Bob Wilson3e36f132009-10-14 17:28:52 +00001470 unsigned OpcodeIndex;
1471 switch (VT.getSimpleVT().SimpleTy) {
1472 default: llvm_unreachable("unhandled vld type");
1473 // Double-register operations:
1474 case MVT::v8i8: OpcodeIndex = 0; break;
1475 case MVT::v4i16: OpcodeIndex = 1; break;
1476 case MVT::v2f32:
1477 case MVT::v2i32: OpcodeIndex = 2; break;
1478 case MVT::v1i64: OpcodeIndex = 3; break;
1479 // Quad-register operations:
1480 case MVT::v16i8: OpcodeIndex = 0; break;
1481 case MVT::v8i16: OpcodeIndex = 1; break;
1482 case MVT::v4f32:
1483 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001484 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001485 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001486 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001487 }
1488
Bob Wilsonf5721912010-09-03 18:16:02 +00001489 EVT ResTy;
1490 if (NumVecs == 1)
1491 ResTy = VT;
1492 else {
1493 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1494 if (!is64BitVector)
1495 ResTyElts *= 2;
1496 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1497 }
1498
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001499 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001500 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilsonf5721912010-09-03 18:16:02 +00001501 SDValue SuperReg;
Bob Wilson3e36f132009-10-14 17:28:52 +00001502 if (is64BitVector) {
1503 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001504 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonf5721912010-09-03 18:16:02 +00001505 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001506 if (NumVecs == 1)
Evan Chenge9e2ba02010-05-10 21:26:24 +00001507 return VLd;
1508
Bob Wilsonf5721912010-09-03 18:16:02 +00001509 SuperReg = SDValue(VLd, 0);
Jakob Stoklund Olesen7bb31e32010-05-24 17:13:28 +00001510 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
Evan Cheng5c6aba22010-05-14 18:54:59 +00001511 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001512 SDValue D = CurDAG->getTargetExtractSubreg(ARM::dsub_0+Vec,
Bob Wilsonffde0802010-09-02 16:00:54 +00001513 dl, VT, SuperReg);
Evan Cheng5c6aba22010-05-14 18:54:59 +00001514 ReplaceUses(SDValue(N, Vec), D);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001515 }
Bob Wilsonf5721912010-09-03 18:16:02 +00001516 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
Evan Chenge9e2ba02010-05-10 21:26:24 +00001517 return NULL;
Bob Wilson3e36f132009-10-14 17:28:52 +00001518 }
1519
Bob Wilson621f1952010-03-23 05:25:43 +00001520 if (NumVecs <= 2) {
1521 // Quad registers are directly supported for VLD1 and VLD2,
1522 // loading pairs of D regs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001523 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilson226036e2010-03-20 22:13:40 +00001524 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
Bob Wilsonffde0802010-09-02 16:00:54 +00001525 SDNode *VLd = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
Bob Wilsonffde0802010-09-02 16:00:54 +00001526 if (NumVecs == 1)
1527 return VLd;
1528
Bob Wilsonf5721912010-09-03 18:16:02 +00001529 SuperReg = SDValue(VLd, 0);
Bob Wilsonffde0802010-09-02 16:00:54 +00001530 Chain = SDValue(VLd, 1);
1531
Bob Wilson3e36f132009-10-14 17:28:52 +00001532 } else {
1533 // Otherwise, quad registers are loaded with two separate instructions,
1534 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001535 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001536
Bob Wilson24f995d2009-10-14 18:32:29 +00001537 // Load the even subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001538 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001539 SDValue ImplDef =
1540 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1541 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
1542 SDNode *VLdA =
1543 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsA, 7);
1544 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001545
Bob Wilson24f995d2009-10-14 18:32:29 +00001546 // Load the odd subregs.
Bob Wilson3e36f132009-10-14 17:28:52 +00001547 Opc = QOpcodes1[OpcodeIndex];
Bob Wilsonf5721912010-09-03 18:16:02 +00001548 const SDValue OpsB[] = { SDValue(VLdA, 1), Align, Reg0, SDValue(VLdA, 0),
1549 Pred, Reg0, Chain };
1550 SDNode *VLdB =
1551 CurDAG->getMachineNode(Opc, dl, ResTy, AddrTy, MVT::Other, OpsB, 7);
1552 SuperReg = SDValue(VLdB, 0);
1553 Chain = SDValue(VLdB, 2);
1554 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001555
Bob Wilsonf5721912010-09-03 18:16:02 +00001556 // Extract out the Q registers.
1557 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1558 for (unsigned Vec = 0; Vec < NumVecs; ++Vec) {
1559 SDValue Q = CurDAG->getTargetExtractSubreg(ARM::qsub_0+Vec,
1560 dl, VT, SuperReg);
1561 ReplaceUses(SDValue(N, Vec), Q);
Bob Wilson3e36f132009-10-14 17:28:52 +00001562 }
1563 ReplaceUses(SDValue(N, NumVecs), Chain);
1564 return NULL;
1565}
1566
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001567SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001568 unsigned *DOpcodes, unsigned *QOpcodes0,
1569 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001570 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001571 DebugLoc dl = N->getDebugLoc();
1572
Bob Wilson226036e2010-03-20 22:13:40 +00001573 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001574 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001575 return NULL;
1576
1577 SDValue Chain = N->getOperand(0);
1578 EVT VT = N->getOperand(3).getValueType();
1579 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001580 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001581
Bob Wilson24f995d2009-10-14 18:32:29 +00001582 unsigned OpcodeIndex;
1583 switch (VT.getSimpleVT().SimpleTy) {
1584 default: llvm_unreachable("unhandled vst type");
1585 // Double-register operations:
1586 case MVT::v8i8: OpcodeIndex = 0; break;
1587 case MVT::v4i16: OpcodeIndex = 1; break;
1588 case MVT::v2f32:
1589 case MVT::v2i32: OpcodeIndex = 2; break;
1590 case MVT::v1i64: OpcodeIndex = 3; break;
1591 // Quad-register operations:
1592 case MVT::v16i8: OpcodeIndex = 0; break;
1593 case MVT::v8i16: OpcodeIndex = 1; break;
1594 case MVT::v4f32:
1595 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001596 case MVT::v2i64: OpcodeIndex = 3;
1597 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1598 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001599 }
1600
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001601 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001602 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001603
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001604 SmallVector<SDValue, 7> Ops;
Bob Wilson24f995d2009-10-14 18:32:29 +00001605 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001606 Ops.push_back(Align);
Bob Wilson24f995d2009-10-14 18:32:29 +00001607
1608 if (is64BitVector) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001609 if (NumVecs == 1) {
1610 Ops.push_back(N->getOperand(3));
1611 } else {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001612 SDValue RegSeq;
1613 SDValue V0 = N->getOperand(0+3);
1614 SDValue V1 = N->getOperand(1+3);
1615
1616 // Form a REG_SEQUENCE to force register allocation.
1617 if (NumVecs == 2)
1618 RegSeq = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1619 else {
1620 SDValue V2 = N->getOperand(2+3);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001621 // If it's a vld3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001622 // an undef.
1623 SDValue V3 = (NumVecs == 3)
1624 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1625 : N->getOperand(3+3);
1626 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1627 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001628 Ops.push_back(RegSeq);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001629 }
Evan Chengac0869d2009-11-21 06:21:52 +00001630 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001631 Ops.push_back(Reg0); // predicate register
Bob Wilson24f995d2009-10-14 18:32:29 +00001632 Ops.push_back(Chain);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001633 unsigned Opc = DOpcodes[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001634 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001635 }
1636
Bob Wilson11d98992010-03-23 06:20:33 +00001637 if (NumVecs <= 2) {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001638 // Quad registers are directly supported for VST1 and VST2.
Bob Wilson24f995d2009-10-14 18:32:29 +00001639 unsigned Opc = QOpcodes0[OpcodeIndex];
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001640 if (NumVecs == 1) {
1641 Ops.push_back(N->getOperand(3));
1642 } else {
1643 // Form a QQ register.
Evan Cheng603afbf2010-05-10 17:34:18 +00001644 SDValue Q0 = N->getOperand(3);
1645 SDValue Q1 = N->getOperand(4);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001646 Ops.push_back(SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0));
Bob Wilson24f995d2009-10-14 18:32:29 +00001647 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001648 Ops.push_back(Pred);
1649 Ops.push_back(Reg0); // predicate register
1650 Ops.push_back(Chain);
1651 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 6);
Bob Wilson24f995d2009-10-14 18:32:29 +00001652 }
1653
1654 // Otherwise, quad registers are stored with two separate instructions,
1655 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001656
Bob Wilson07f6e802010-06-16 21:34:01 +00001657 // Form the QQQQ REG_SEQUENCE.
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001658 SDValue V0 = N->getOperand(0+3);
1659 SDValue V1 = N->getOperand(1+3);
1660 SDValue V2 = N->getOperand(2+3);
1661 SDValue V3 = (NumVecs == 3)
1662 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1663 : N->getOperand(3+3);
1664 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001665
1666 // Store the even D registers.
Bob Wilson07f6e802010-06-16 21:34:01 +00001667 Ops.push_back(Reg0); // post-access address offset
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001668 Ops.push_back(RegSeq);
Bob Wilson07f6e802010-06-16 21:34:01 +00001669 Ops.push_back(Pred);
1670 Ops.push_back(Reg0); // predicate register
1671 Ops.push_back(Chain);
1672 unsigned Opc = QOpcodes0[OpcodeIndex];
1673 SDNode *VStA = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001674 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001675 Chain = SDValue(VStA, 1);
1676
1677 // Store the odd D registers.
1678 Ops[0] = SDValue(VStA, 0); // MemAddr
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001679 Ops[6] = Chain;
Bob Wilson07f6e802010-06-16 21:34:01 +00001680 Opc = QOpcodes1[OpcodeIndex];
1681 SDNode *VStB = CurDAG->getMachineNode(Opc, dl, MemAddr.getValueType(),
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001682 MVT::Other, Ops.data(), 7);
Bob Wilson07f6e802010-06-16 21:34:01 +00001683 Chain = SDValue(VStB, 1);
1684 ReplaceUses(SDValue(N, 0), Chain);
1685 return NULL;
Bob Wilson24f995d2009-10-14 18:32:29 +00001686}
1687
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001688SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson96493442009-10-14 16:46:45 +00001689 unsigned NumVecs, unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001690 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001691 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001692 DebugLoc dl = N->getDebugLoc();
1693
Bob Wilson226036e2010-03-20 22:13:40 +00001694 SDValue MemAddr, Align;
Bob Wilson665814b2010-11-01 23:40:51 +00001695 if (!SelectAddrMode6(N, N->getOperand(2), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001696 return NULL;
1697
1698 SDValue Chain = N->getOperand(0);
1699 unsigned Lane =
1700 cast<ConstantSDNode>(N->getOperand(NumVecs+3))->getZExtValue();
Bob Wilson96493442009-10-14 16:46:45 +00001701 EVT VT = IsLoad ? N->getValueType(0) : N->getOperand(3).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001702 bool is64BitVector = VT.is64BitVector();
1703
Bob Wilson665814b2010-11-01 23:40:51 +00001704 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001705 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001706 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001707 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1708 if (Alignment > NumBytes)
1709 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001710 if (Alignment < 8 && Alignment < NumBytes)
1711 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001712 // Alignment must be a power of two; make sure of that.
1713 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001714 if (Alignment == 1)
1715 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001716 }
Bob Wilson665814b2010-11-01 23:40:51 +00001717 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001718
Bob Wilsona7c397c2009-10-14 16:19:03 +00001719 unsigned OpcodeIndex;
1720 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001721 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001722 // Double-register operations:
1723 case MVT::v8i8: OpcodeIndex = 0; break;
1724 case MVT::v4i16: OpcodeIndex = 1; break;
1725 case MVT::v2f32:
1726 case MVT::v2i32: OpcodeIndex = 2; break;
1727 // Quad-register operations:
1728 case MVT::v8i16: OpcodeIndex = 0; break;
1729 case MVT::v4f32:
1730 case MVT::v4i32: OpcodeIndex = 1; break;
1731 }
1732
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001733 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001734 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001735
Bob Wilson8466fa12010-09-13 23:01:35 +00001736 SmallVector<SDValue, 7> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001737 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001738 Ops.push_back(Align);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001739
Jim Grosbach3ab56582010-10-21 19:38:40 +00001740 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
Eric Christopher23da0b22010-09-14 08:31:25 +00001741 QOpcodes[OpcodeIndex]);
Bob Wilson07f6e802010-06-16 21:34:01 +00001742
Bob Wilson8466fa12010-09-13 23:01:35 +00001743 SDValue SuperReg;
1744 SDValue V0 = N->getOperand(0+3);
1745 SDValue V1 = N->getOperand(1+3);
1746 if (NumVecs == 2) {
1747 if (is64BitVector)
1748 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1749 else
1750 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001751 } else {
Bob Wilson8466fa12010-09-13 23:01:35 +00001752 SDValue V2 = N->getOperand(2+3);
1753 SDValue V3 = (NumVecs == 3)
1754 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
1755 : N->getOperand(3+3);
1756 if (is64BitVector)
1757 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1758 else
1759 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001760 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001761 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001762 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001763 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001764 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001765 Ops.push_back(Chain);
1766
Bob Wilson96493442009-10-14 16:46:45 +00001767 if (!IsLoad)
Bob Wilson8466fa12010-09-13 23:01:35 +00001768 return CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops.data(), 7);
Bob Wilson96493442009-10-14 16:46:45 +00001769
Bob Wilson8466fa12010-09-13 23:01:35 +00001770 EVT ResTy;
1771 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1772 if (!is64BitVector)
1773 ResTyElts *= 2;
1774 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001775
Bob Wilson8466fa12010-09-13 23:01:35 +00001776 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other,
1777 Ops.data(), 7);
1778 SuperReg = SDValue(VLdLn, 0);
1779 Chain = SDValue(VLdLn, 1);
Evan Cheng7092c2b2010-05-15 01:36:29 +00001780
Bob Wilson8466fa12010-09-13 23:01:35 +00001781 // Extract the subregisters.
Bob Wilson07f6e802010-06-16 21:34:01 +00001782 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1783 assert(ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1784 unsigned SubIdx = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
1785 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1786 ReplaceUses(SDValue(N, Vec),
Bob Wilson8466fa12010-09-13 23:01:35 +00001787 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1788 ReplaceUses(SDValue(N, NumVecs), Chain);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001789 return NULL;
1790}
1791
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001792SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, unsigned NumVecs,
1793 unsigned *Opcodes) {
1794 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
1795 DebugLoc dl = N->getDebugLoc();
1796
1797 SDValue MemAddr, Align;
1798 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
1799 return NULL;
1800
1801 SDValue Chain = N->getOperand(0);
1802 EVT VT = N->getValueType(0);
1803
1804 unsigned Alignment = 0;
1805 if (NumVecs != 3) {
1806 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
1807 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1808 if (Alignment > NumBytes)
1809 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001810 if (Alignment < 8 && Alignment < NumBytes)
1811 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001812 // Alignment must be a power of two; make sure of that.
1813 Alignment = (Alignment & -Alignment);
1814 if (Alignment == 1)
1815 Alignment = 0;
1816 }
1817 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
1818
1819 unsigned OpcodeIndex;
1820 switch (VT.getSimpleVT().SimpleTy) {
1821 default: llvm_unreachable("unhandled vld-dup type");
1822 case MVT::v8i8: OpcodeIndex = 0; break;
1823 case MVT::v4i16: OpcodeIndex = 1; break;
1824 case MVT::v2f32:
1825 case MVT::v2i32: OpcodeIndex = 2; break;
1826 }
1827
1828 SDValue Pred = getAL(CurDAG);
1829 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1830 SDValue SuperReg;
1831 unsigned Opc = Opcodes[OpcodeIndex];
1832 const SDValue Ops[] = { MemAddr, Align, Pred, Reg0, Chain };
1833
1834 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1835 EVT ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1836 SDNode *VLdDup = CurDAG->getMachineNode(Opc, dl, ResTy, MVT::Other, Ops, 5);
1837 SuperReg = SDValue(VLdDup, 0);
1838 Chain = SDValue(VLdDup, 1);
1839
1840 // Extract the subregisters.
1841 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
1842 unsigned SubIdx = ARM::dsub_0;
1843 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1844 ReplaceUses(SDValue(N, Vec),
1845 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
1846 ReplaceUses(SDValue(N, NumVecs), Chain);
1847 return NULL;
1848}
1849
Bob Wilson78dfbc32010-07-07 00:08:54 +00001850SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
1851 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001852 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
1853 DebugLoc dl = N->getDebugLoc();
1854 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001855 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00001856
1857 // Form a REG_SEQUENCE to force register allocation.
1858 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00001859 SDValue V0 = N->getOperand(FirstTblReg + 0);
1860 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001861 if (NumVecs == 2)
1862 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
1863 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00001864 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00001865 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00001866 // an undef.
1867 SDValue V3 = (NumVecs == 3)
1868 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00001869 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00001870 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1871 }
1872
Bob Wilson78dfbc32010-07-07 00:08:54 +00001873 SmallVector<SDValue, 6> Ops;
1874 if (IsExt)
1875 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00001876 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00001877 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00001878 Ops.push_back(getAL(CurDAG)); // predicate
1879 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00001880 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00001881}
1882
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001883SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001884 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001885 if (!Subtarget->hasV6T2Ops())
1886 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00001887
Jim Grosbach3a1287b2010-04-22 23:24:18 +00001888 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
1889 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
1890
1891
1892 // For unsigned extracts, check for a shift right and mask
1893 unsigned And_imm = 0;
1894 if (N->getOpcode() == ISD::AND) {
1895 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
1896
1897 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
1898 if (And_imm & (And_imm + 1))
1899 return NULL;
1900
1901 unsigned Srl_imm = 0;
1902 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
1903 Srl_imm)) {
1904 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1905
1906 unsigned Width = CountTrailingOnes_32(And_imm);
1907 unsigned LSB = Srl_imm;
1908 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
1909 SDValue Ops[] = { N->getOperand(0).getOperand(0),
1910 CurDAG->getTargetConstant(LSB, MVT::i32),
1911 CurDAG->getTargetConstant(Width, MVT::i32),
1912 getAL(CurDAG), Reg0 };
1913 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
1914 }
1915 }
1916 return NULL;
1917 }
1918
1919 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001920 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001921 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001922 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
1923 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001924 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001925 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
1926 unsigned Width = 32 - Srl_imm;
1927 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00001928 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001929 return NULL;
1930 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001931 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001932 CurDAG->getTargetConstant(LSB, MVT::i32),
1933 CurDAG->getTargetConstant(Width, MVT::i32),
1934 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001935 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001936 }
1937 }
1938 return NULL;
1939}
1940
Evan Cheng9ef48352009-11-20 00:54:03 +00001941SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001942SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001943 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1944 SDValue CPTmp0;
1945 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00001946 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001947 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
1948 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
1949 unsigned Opc = 0;
1950 switch (SOShOp) {
1951 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
1952 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
1953 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
1954 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
1955 default:
1956 llvm_unreachable("Unknown so_reg opcode!");
1957 break;
1958 }
1959 SDValue SOShImm =
1960 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
1961 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1962 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001963 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00001964 }
1965 return 0;
1966}
1967
1968SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001969SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00001970 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
1971 SDValue CPTmp0;
1972 SDValue CPTmp1;
1973 SDValue CPTmp2;
Chris Lattner52a261b2010-09-21 20:31:19 +00001974 if (SelectShifterOperandReg(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001975 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
1976 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001977 return CurDAG->SelectNodeTo(N, ARM::MOVCCs, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00001978 }
1979 return 0;
1980}
1981
1982SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00001983SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00001984 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00001985 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00001986 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00001987 return 0;
1988
Evan Cheng63f35442010-11-13 02:25:14 +00001989 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00001990 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00001991 if (is_t2_so_imm(TrueImm)) {
1992 Opc = ARM::t2MOVCCi;
1993 } else if (TrueImm <= 0xffff) {
1994 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00001995 } else if (is_t2_so_imm_not(TrueImm)) {
1996 TrueImm = ~TrueImm;
1997 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00001998 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00001999 // Large immediate.
2000 Opc = ARM::t2MOVCCi32imm;
2001 }
2002
2003 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002004 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002005 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2006 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002007 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002008 }
Evan Cheng63f35442010-11-13 02:25:14 +00002009
Evan Cheng9ef48352009-11-20 00:54:03 +00002010 return 0;
2011}
2012
2013SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002014SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002015 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002016 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2017 if (!T)
2018 return 0;
2019
Evan Cheng63f35442010-11-13 02:25:14 +00002020 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002021 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002022 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002023 if (isSoImm) {
2024 Opc = ARM::MOVCCi;
2025 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2026 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002027 } else if (is_so_imm_not(TrueImm)) {
2028 TrueImm = ~TrueImm;
2029 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002030 } else if (TrueVal.getNode()->hasOneUse() &&
2031 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002032 // Large immediate.
2033 Opc = ARM::MOVCCi32imm;
2034 }
2035
2036 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002037 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002038 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2039 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002040 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002041 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002042
Evan Cheng9ef48352009-11-20 00:54:03 +00002043 return 0;
2044}
2045
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002046SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2047 EVT VT = N->getValueType(0);
2048 SDValue FalseVal = N->getOperand(0);
2049 SDValue TrueVal = N->getOperand(1);
2050 SDValue CC = N->getOperand(2);
2051 SDValue CCR = N->getOperand(3);
2052 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002053 assert(CC.getOpcode() == ISD::Constant);
2054 assert(CCR.getOpcode() == ISD::Register);
2055 ARMCC::CondCodes CCVal =
2056 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002057
2058 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2059 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2060 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2061 // Pattern complexity = 18 cost = 1 size = 0
2062 SDValue CPTmp0;
2063 SDValue CPTmp1;
2064 SDValue CPTmp2;
2065 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002066 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002067 CCVal, CCR, InFlag);
2068 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002069 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002070 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2071 if (Res)
2072 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002073 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002074 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002075 CCVal, CCR, InFlag);
2076 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002077 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002078 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2079 if (Res)
2080 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002081 }
2082
2083 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002084 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002085 // (imm:i32):$cc)
2086 // Emits: (MOVCCi:i32 GPR:i32:$false,
2087 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2088 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002089 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002090 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002091 CCVal, CCR, InFlag);
2092 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002093 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002094 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2095 if (Res)
2096 return Res;
2097 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002098 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002099 CCVal, CCR, InFlag);
2100 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002101 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002102 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2103 if (Res)
2104 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002105 }
2106 }
2107
2108 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2109 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2110 // Pattern complexity = 6 cost = 1 size = 0
2111 //
2112 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2113 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2114 // Pattern complexity = 6 cost = 11 size = 0
2115 //
2116 // Also FCPYScc and FCPYDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002117 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2118 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002119 unsigned Opc = 0;
2120 switch (VT.getSimpleVT().SimpleTy) {
2121 default: assert(false && "Illegal conditional move type!");
2122 break;
2123 case MVT::i32:
2124 Opc = Subtarget->isThumb()
2125 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2126 : ARM::MOVCCr;
2127 break;
2128 case MVT::f32:
2129 Opc = ARM::VMOVScc;
2130 break;
2131 case MVT::f64:
2132 Opc = ARM::VMOVDcc;
2133 break;
2134 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002135 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002136}
2137
Evan Chengde8aa4e2010-05-05 18:28:36 +00002138SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2139 // The only time a CONCAT_VECTORS operation can have legal types is when
2140 // two 64-bit vectors are concatenated to a 128-bit vector.
2141 EVT VT = N->getValueType(0);
2142 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2143 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002144 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002145}
2146
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002147SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002148 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002149
Dan Gohmane8be6c62008-07-17 19:10:17 +00002150 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002151 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002152
2153 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002154 default: break;
2155 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002156 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002157 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002158 if (Subtarget->hasThumb2())
2159 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2160 // be done with MOV + MOVT, at worst.
2161 UseCP = 0;
2162 else {
2163 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002164 UseCP = (Val > 255 && // MOV
2165 ~Val > 255 && // MOV + MVN
2166 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002167 } else
2168 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2169 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2170 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2171 }
2172
Evan Chenga8e29892007-01-19 07:51:42 +00002173 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002174 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002175 CurDAG->getTargetConstantPool(ConstantInt::get(
2176 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002177 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002178
2179 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002180 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002181 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002182 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002183 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002184 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002185 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002186 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002187 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002188 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002189 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002190 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002191 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002192 CurDAG->getEntryNode()
2193 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002194 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002195 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002196 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002197 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002198 return NULL;
2199 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002200
Evan Chenga8e29892007-01-19 07:51:42 +00002201 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002202 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002203 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002204 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002205 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002206 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002207 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002208 if (Subtarget->isThumb1Only()) {
Owen Anderson825b72b2009-08-11 20:47:22 +00002209 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, TFI,
2210 CurDAG->getTargetConstant(0, MVT::i32));
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002211 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002212 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2213 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002214 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2215 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2216 CurDAG->getRegister(0, MVT::i32) };
2217 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002218 }
Evan Chenga8e29892007-01-19 07:51:42 +00002219 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002220 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002221 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002222 return I;
2223 break;
2224 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002225 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002226 return I;
2227 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002228 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002229 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002230 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002231 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002232 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002233 if (!RHSV) break;
2234 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002235 unsigned ShImm = Log2_32(RHSV-1);
2236 if (ShImm >= 32)
2237 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002238 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002239 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002240 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2241 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002242 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002243 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002244 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002245 } else {
2246 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002247 return CurDAG->SelectNodeTo(N, ARM::ADDrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002248 }
Evan Chenga8e29892007-01-19 07:51:42 +00002249 }
2250 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002251 unsigned ShImm = Log2_32(RHSV+1);
2252 if (ShImm >= 32)
2253 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002254 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002255 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002256 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2257 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002258 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002259 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2260 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002261 } else {
2262 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002263 return CurDAG->SelectNodeTo(N, ARM::RSBrs, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002264 }
Evan Chenga8e29892007-01-19 07:51:42 +00002265 }
2266 }
2267 break;
Evan Cheng20956592009-10-21 08:15:52 +00002268 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002269 // Check for unsigned bitfield extract
2270 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2271 return I;
2272
Evan Cheng20956592009-10-21 08:15:52 +00002273 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2274 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2275 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2276 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2277 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002278 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002279 if (VT != MVT::i32)
2280 break;
2281 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2282 ? ARM::t2MOVTi16
2283 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2284 if (!Opc)
2285 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002286 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002287 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2288 if (!N1C)
2289 break;
2290 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2291 SDValue N2 = N0.getOperand(1);
2292 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2293 if (!N2C)
2294 break;
2295 unsigned N1CVal = N1C->getZExtValue();
2296 unsigned N2CVal = N2C->getZExtValue();
2297 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2298 (N1CVal & 0xffffU) == 0xffffU &&
2299 (N2CVal & 0xffffU) == 0x0U) {
2300 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2301 MVT::i32);
2302 SDValue Ops[] = { N0.getOperand(0), Imm16,
2303 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2304 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2305 }
2306 }
2307 break;
2308 }
Jim Grosbache5165492009-11-09 00:11:35 +00002309 case ARMISD::VMOVRRD:
2310 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002311 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002312 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002313 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002314 if (Subtarget->isThumb1Only())
2315 break;
2316 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002317 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002318 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2319 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002320 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002321 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002322 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002323 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2324 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002325 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2326 ARM::UMULL : ARM::UMULLv5,
2327 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002328 }
Evan Chengee568cf2007-07-05 07:15:27 +00002329 }
Dan Gohman525178c2007-10-08 18:33:35 +00002330 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002331 if (Subtarget->isThumb1Only())
2332 break;
2333 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002334 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002335 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002336 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002337 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002338 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002339 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2340 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002341 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2342 ARM::SMULL : ARM::SMULLv5,
2343 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002344 }
Evan Chengee568cf2007-07-05 07:15:27 +00002345 }
Evan Chenga8e29892007-01-19 07:51:42 +00002346 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002347 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002348 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002349 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002350 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002351 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002352 if (ResNode)
2353 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002354 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002355 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002356 }
Evan Chengee568cf2007-07-05 07:15:27 +00002357 case ARMISD::BRCOND: {
2358 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2359 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2360 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002361
Evan Chengee568cf2007-07-05 07:15:27 +00002362 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2363 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2364 // Pattern complexity = 6 cost = 1 size = 0
2365
David Goodwin5e47a9a2009-06-30 18:04:13 +00002366 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2367 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2368 // Pattern complexity = 6 cost = 1 size = 0
2369
Jim Grosbach764ab522009-08-11 15:33:49 +00002370 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002371 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002372 SDValue Chain = N->getOperand(0);
2373 SDValue N1 = N->getOperand(1);
2374 SDValue N2 = N->getOperand(2);
2375 SDValue N3 = N->getOperand(3);
2376 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002377 assert(N1.getOpcode() == ISD::BasicBlock);
2378 assert(N2.getOpcode() == ISD::Constant);
2379 assert(N3.getOpcode() == ISD::Register);
2380
Dan Gohman475871a2008-07-27 21:46:04 +00002381 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002382 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002383 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002384 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002385 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002386 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002387 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002388 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002389 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002390 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002391 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002392 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002393 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002394 return NULL;
2395 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002396 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002397 return SelectCMOVOp(N);
Evan Chengee568cf2007-07-05 07:15:27 +00002398 case ARMISD::CNEG: {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002399 EVT VT = N->getValueType(0);
2400 SDValue N0 = N->getOperand(0);
2401 SDValue N1 = N->getOperand(1);
2402 SDValue N2 = N->getOperand(2);
2403 SDValue N3 = N->getOperand(3);
2404 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002405 assert(N2.getOpcode() == ISD::Constant);
2406 assert(N3.getOpcode() == ISD::Register);
2407
Dan Gohman475871a2008-07-27 21:46:04 +00002408 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002409 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002410 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002411 SDValue Ops[] = { N0, N1, Tmp2, N3, InFlag };
Evan Chengee568cf2007-07-05 07:15:27 +00002412 unsigned Opc = 0;
Owen Anderson825b72b2009-08-11 20:47:22 +00002413 switch (VT.getSimpleVT().SimpleTy) {
Evan Chengee568cf2007-07-05 07:15:27 +00002414 default: assert(false && "Illegal conditional move type!");
2415 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002416 case MVT::f32:
Jim Grosbache5165492009-11-09 00:11:35 +00002417 Opc = ARM::VNEGScc;
Evan Chengee568cf2007-07-05 07:15:27 +00002418 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00002419 case MVT::f64:
Jim Grosbache5165492009-11-09 00:11:35 +00002420 Opc = ARM::VNEGDcc;
Evan Chenge5ad88e2008-12-10 21:54:21 +00002421 break;
Evan Chengee568cf2007-07-05 07:15:27 +00002422 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002423 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002424 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002425
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002426 case ARMISD::VZIP: {
2427 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002428 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002429 switch (VT.getSimpleVT().SimpleTy) {
2430 default: return NULL;
2431 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2432 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2433 case MVT::v2f32:
2434 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2435 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2436 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2437 case MVT::v4f32:
2438 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2439 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002440 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002441 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2442 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2443 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002444 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002445 case ARMISD::VUZP: {
2446 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002447 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002448 switch (VT.getSimpleVT().SimpleTy) {
2449 default: return NULL;
2450 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2451 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2452 case MVT::v2f32:
2453 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2454 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2455 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2456 case MVT::v4f32:
2457 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2458 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002459 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002460 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2461 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2462 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002463 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002464 case ARMISD::VTRN: {
2465 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002466 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002467 switch (VT.getSimpleVT().SimpleTy) {
2468 default: return NULL;
2469 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2470 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2471 case MVT::v2f32:
2472 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2473 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2474 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2475 case MVT::v4f32:
2476 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2477 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002478 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002479 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2480 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2481 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002482 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002483 case ARMISD::BUILD_VECTOR: {
2484 EVT VecVT = N->getValueType(0);
2485 EVT EltVT = VecVT.getVectorElementType();
2486 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002487 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002488 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2489 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2490 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002491 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002492 if (NumElts == 2)
2493 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2494 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2495 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2496 N->getOperand(2), N->getOperand(3));
2497 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002498
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002499 case ARMISD::VLD2DUP: {
2500 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2501 ARM::VLD2DUPd32Pseudo };
2502 return SelectVLDDup(N, 2, Opcodes);
2503 }
2504
Bob Wilson86c6d802010-11-29 19:35:29 +00002505 case ARMISD::VLD3DUP: {
2506 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2507 ARM::VLD3DUPd32Pseudo };
2508 return SelectVLDDup(N, 3, Opcodes);
2509 }
2510
Bob Wilson6c4c9822010-11-30 00:00:35 +00002511 case ARMISD::VLD4DUP: {
2512 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2513 ARM::VLD4DUPd32Pseudo };
2514 return SelectVLDDup(N, 4, Opcodes);
2515 }
2516
Bob Wilson31fb12f2009-08-26 17:39:53 +00002517 case ISD::INTRINSIC_VOID:
2518 case ISD::INTRINSIC_W_CHAIN: {
2519 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00002520 switch (IntNo) {
2521 default:
Bob Wilson429009b2010-05-06 16:05:26 +00002522 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002523
Bob Wilson621f1952010-03-23 05:25:43 +00002524 case Intrinsic::arm_neon_vld1: {
2525 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
2526 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00002527 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
2528 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson621f1952010-03-23 05:25:43 +00002529 return SelectVLD(N, 1, DOpcodes, QOpcodes, 0);
2530 }
2531
Bob Wilson31fb12f2009-08-26 17:39:53 +00002532 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00002533 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
2534 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
2535 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
2536 ARM::VLD2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002537 return SelectVLD(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002538 }
2539
2540 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002541 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
2542 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
2543 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2544 ARM::VLD3q16Pseudo_UPD,
2545 ARM::VLD3q32Pseudo_UPD };
2546 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2547 ARM::VLD3q16oddPseudo_UPD,
2548 ARM::VLD3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002549 return SelectVLD(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002550 }
2551
2552 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00002553 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
2554 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
2555 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2556 ARM::VLD4q16Pseudo_UPD,
2557 ARM::VLD4q32Pseudo_UPD };
2558 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2559 ARM::VLD4q16oddPseudo_UPD,
2560 ARM::VLD4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002561 return SelectVLD(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002562 }
2563
Bob Wilson243fcc52009-09-01 04:26:28 +00002564 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002565 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
2566 ARM::VLD2LNd32Pseudo };
2567 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
2568 return SelectVLDSTLane(N, true, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002569 }
2570
2571 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002572 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
2573 ARM::VLD3LNd32Pseudo };
2574 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
2575 return SelectVLDSTLane(N, true, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002576 }
2577
2578 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002579 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
2580 ARM::VLD4LNd32Pseudo };
2581 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
2582 return SelectVLDSTLane(N, true, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00002583 }
2584
Bob Wilson11d98992010-03-23 06:20:33 +00002585 case Intrinsic::arm_neon_vst1: {
2586 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
2587 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002588 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
2589 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson11d98992010-03-23 06:20:33 +00002590 return SelectVST(N, 1, DOpcodes, QOpcodes, 0);
2591 }
2592
Bob Wilson31fb12f2009-08-26 17:39:53 +00002593 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00002594 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
2595 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
2596 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
2597 ARM::VST2q32Pseudo };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002598 return SelectVST(N, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002599 }
2600
2601 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00002602 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
2603 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
2604 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
2605 ARM::VST3q16Pseudo_UPD,
2606 ARM::VST3q32Pseudo_UPD };
2607 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
2608 ARM::VST3q16oddPseudo_UPD,
2609 ARM::VST3q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002610 return SelectVST(N, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002611 }
2612
2613 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00002614 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00002615 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00002616 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
2617 ARM::VST4q16Pseudo_UPD,
2618 ARM::VST4q32Pseudo_UPD };
2619 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
2620 ARM::VST4q16oddPseudo_UPD,
2621 ARM::VST4q32oddPseudo_UPD };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002622 return SelectVST(N, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00002623 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00002624
2625 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002626 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
2627 ARM::VST2LNd32Pseudo };
2628 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
2629 return SelectVLDSTLane(N, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002630 }
2631
2632 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002633 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
2634 ARM::VST3LNd32Pseudo };
2635 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
2636 return SelectVLDSTLane(N, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002637 }
2638
2639 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00002640 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
2641 ARM::VST4LNd32Pseudo };
2642 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
2643 return SelectVLDSTLane(N, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00002644 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002645 }
Bob Wilson429009b2010-05-06 16:05:26 +00002646 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00002647 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00002648
Bob Wilsond491d6e2010-07-06 23:36:25 +00002649 case ISD::INTRINSIC_WO_CHAIN: {
2650 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
2651 switch (IntNo) {
2652 default:
2653 break;
2654
2655 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002656 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002657 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002658 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002659 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002660 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002661
2662 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002663 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002664 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002665 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002666 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00002667 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002668 }
2669 break;
2670 }
2671
Bob Wilson429009b2010-05-06 16:05:26 +00002672 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00002673 return SelectConcatVector(N);
2674 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00002675
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002676 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00002677}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002678
Bob Wilson224c2442009-05-19 05:53:42 +00002679bool ARMDAGToDAGISel::
2680SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
2681 std::vector<SDValue> &OutOps) {
2682 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00002683 // Require the address to be in a register. That is safe for all ARM
2684 // variants and it is hard to do anything much smarter without knowing
2685 // how the operand is used.
2686 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00002687 return false;
2688}
2689
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002690/// createARMISelDag - This pass converts a legalized DAG into a
2691/// ARM-specific DAG, ready for instruction scheduling.
2692///
Bob Wilson522ce972009-09-28 14:30:20 +00002693FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
2694 CodeGenOpt::Level OptLevel) {
2695 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002696}