blob: d3cce5899b8edf6b251aba3b661aceb7f690aeda [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"
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000017#include "ARMTargetMachine.h"
Evan Chengee04a6d2011-07-20 23:34:39 +000018#include "MCTargetDesc/ARMAddressingModes.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"),
Bob Wilson84c5eed2011-04-19 18:11:57 +000048 cl::init(true));
Evan Cheng48575f62010-12-05 22:04:16 +000049
Bill Wendlingef2c86f2011-10-10 22:59:55 +000050static cl::opt<bool>
51DisableARMIntABS("disable-arm-int-abs", cl::Hidden,
52 cl::desc("Enable / disable ARM integer abs transform"),
53 cl::init(false));
54
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000055//===--------------------------------------------------------------------===//
56/// ARMDAGToDAGISel - ARM specific code to select ARM machine
57/// instructions for SelectionDAG operations.
58///
59namespace {
Jim Grosbach82891622010-09-29 19:03:54 +000060
61enum AddrMode2Type {
62 AM2_BASE, // Simple AM2 (+-imm12)
63 AM2_SHOP // Shifter-op AM2
64};
65
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000066class ARMDAGToDAGISel : public SelectionDAGISel {
Anton Korobeynikovd49ea772009-06-26 21:28:53 +000067 ARMBaseTargetMachine &TM;
Evan Cheng48575f62010-12-05 22:04:16 +000068 const ARMBaseInstrInfo *TII;
Evan Cheng3f7eb8e2008-09-18 07:24:33 +000069
Evan Chenga8e29892007-01-19 07:51:42 +000070 /// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
71 /// make the right decision when generating code for different targets.
72 const ARMSubtarget *Subtarget;
73
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000074public:
Bob Wilson522ce972009-09-28 14:30:20 +000075 explicit ARMDAGToDAGISel(ARMBaseTargetMachine &tm,
76 CodeGenOpt::Level OptLevel)
77 : SelectionDAGISel(tm, OptLevel), TM(tm),
Evan Cheng48575f62010-12-05 22:04:16 +000078 TII(static_cast<const ARMBaseInstrInfo*>(TM.getInstrInfo())),
79 Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
Rafael Espindola7bc59bc2006-05-14 22:18:28 +000080 }
81
Evan Chenga8e29892007-01-19 07:51:42 +000082 virtual const char *getPassName() const {
83 return "ARM Instruction Selection";
Anton Korobeynikov52237112009-06-17 18:13:58 +000084 }
85
Bob Wilsonaf4a8912009-10-08 18:51:31 +000086 /// getI32Imm - Return a target constant of type i32 with the specified
87 /// value.
Anton Korobeynikov52237112009-06-17 18:13:58 +000088 inline SDValue getI32Imm(unsigned Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +000089 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000090 }
91
Dan Gohmaneeb3a002010-01-05 01:24:18 +000092 SDNode *Select(SDNode *N);
Evan Cheng014bf212010-02-15 19:41:07 +000093
Evan Cheng48575f62010-12-05 22:04:16 +000094
95 bool hasNoVMLxHazardUse(SDNode *N) const;
Evan Chengf40deed2010-10-27 23:41:30 +000096 bool isShifterOpProfitable(const SDValue &Shift,
97 ARM_AM::ShiftOpc ShOpcVal, unsigned ShAmt);
Owen Anderson92a20222011-07-21 18:54:16 +000098 bool SelectRegShifterOperand(SDValue N, SDValue &A,
99 SDValue &B, SDValue &C,
100 bool CheckProfitability = true);
101 bool SelectImmShifterOperand(SDValue N, SDValue &A,
Owen Anderson152d4a42011-07-21 23:38:37 +0000102 SDValue &B, bool CheckProfitability = true);
103 bool SelectShiftRegShifterOperand(SDValue N, SDValue &A,
Owen Anderson099e5552011-03-18 19:46:58 +0000104 SDValue &B, SDValue &C) {
105 // Don't apply the profitability check
Owen Anderson152d4a42011-07-21 23:38:37 +0000106 return SelectRegShifterOperand(N, A, B, C, false);
107 }
108 bool SelectShiftImmShifterOperand(SDValue N, SDValue &A,
109 SDValue &B) {
110 // Don't apply the profitability check
111 return SelectImmShifterOperand(N, A, B, false);
Owen Anderson099e5552011-03-18 19:46:58 +0000112 }
113
Jim Grosbach3e556122010-10-26 22:37:02 +0000114 bool SelectAddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
115 bool SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset, SDValue &Opc);
116
Jim Grosbach82891622010-09-29 19:03:54 +0000117 AddrMode2Type SelectAddrMode2Worker(SDValue N, SDValue &Base,
118 SDValue &Offset, SDValue &Opc);
119 bool SelectAddrMode2Base(SDValue N, SDValue &Base, SDValue &Offset,
120 SDValue &Opc) {
121 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_BASE;
122 }
123
124 bool SelectAddrMode2ShOp(SDValue N, SDValue &Base, SDValue &Offset,
125 SDValue &Opc) {
126 return SelectAddrMode2Worker(N, Base, Offset, Opc) == AM2_SHOP;
127 }
128
129 bool SelectAddrMode2(SDValue N, SDValue &Base, SDValue &Offset,
130 SDValue &Opc) {
131 SelectAddrMode2Worker(N, Base, Offset, Opc);
Jim Grosbach3e556122010-10-26 22:37:02 +0000132// return SelectAddrMode2ShOp(N, Base, Offset, Opc);
Jim Grosbach82891622010-09-29 19:03:54 +0000133 // This always matches one way or another.
134 return true;
135 }
136
Owen Anderson793e7962011-07-26 20:54:26 +0000137 bool SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
138 SDValue &Offset, SDValue &Opc);
139 bool SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000140 SDValue &Offset, SDValue &Opc);
Owen Andersonc4e16de2011-08-29 20:16:50 +0000141 bool SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
142 SDValue &Offset, SDValue &Opc);
Jim Grosbach19dec202011-08-05 20:35:44 +0000143 bool SelectAddrOffsetNone(SDValue N, SDValue &Base);
Chris Lattner52a261b2010-09-21 20:31:19 +0000144 bool SelectAddrMode3(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000145 SDValue &Offset, SDValue &Opc);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000146 bool SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000147 SDValue &Offset, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000148 bool SelectAddrMode5(SDValue N, SDValue &Base,
Dan Gohman475871a2008-07-27 21:46:04 +0000149 SDValue &Offset);
Bob Wilson665814b2010-11-01 23:40:51 +0000150 bool SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,SDValue &Align);
Bob Wilsonda525062011-02-25 06:42:42 +0000151 bool SelectAddrMode6Offset(SDNode *Op, SDValue N, SDValue &Offset);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000152
Evan Cheng5de5d4b2011-01-17 08:03:18 +0000153 bool SelectAddrModePC(SDValue N, SDValue &Offset, SDValue &Label);
Evan Chenga8e29892007-01-19 07:51:42 +0000154
Bill Wendlingf4caf692010-12-14 03:36:38 +0000155 // Thumb Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000156 bool SelectThumbAddrModeRR(SDValue N, SDValue &Base, SDValue &Offset);
Bill Wendlingf4caf692010-12-14 03:36:38 +0000157 bool SelectThumbAddrModeRI(SDValue N, SDValue &Base, SDValue &Offset,
158 unsigned Scale);
159 bool SelectThumbAddrModeRI5S1(SDValue N, SDValue &Base, SDValue &Offset);
160 bool SelectThumbAddrModeRI5S2(SDValue N, SDValue &Base, SDValue &Offset);
161 bool SelectThumbAddrModeRI5S4(SDValue N, SDValue &Base, SDValue &Offset);
162 bool SelectThumbAddrModeImm5S(SDValue N, unsigned Scale, SDValue &Base,
163 SDValue &OffImm);
164 bool SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
165 SDValue &OffImm);
166 bool SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
167 SDValue &OffImm);
168 bool SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
169 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000170 bool SelectThumbAddrModeSP(SDValue N, SDValue &Base, SDValue &OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +0000171
Bill Wendlingf4caf692010-12-14 03:36:38 +0000172 // Thumb 2 Addressing Modes:
Chris Lattner52a261b2010-09-21 20:31:19 +0000173 bool SelectT2ShifterOperandReg(SDValue N,
Evan Cheng9cb9e672009-06-27 02:26:13 +0000174 SDValue &BaseReg, SDValue &Opc);
Chris Lattner52a261b2010-09-21 20:31:19 +0000175 bool SelectT2AddrModeImm12(SDValue N, SDValue &Base, SDValue &OffImm);
176 bool SelectT2AddrModeImm8(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000177 SDValue &OffImm);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000178 bool SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +0000179 SDValue &OffImm);
Chris Lattner52a261b2010-09-21 20:31:19 +0000180 bool SelectT2AddrModeSoReg(SDValue N, SDValue &Base,
Evan Cheng055b0312009-06-29 07:51:04 +0000181 SDValue &OffReg, SDValue &ShImm);
182
Evan Cheng875a6ac2010-11-12 22:42:47 +0000183 inline bool is_so_imm(unsigned Imm) const {
184 return ARM_AM::getSOImmVal(Imm) != -1;
185 }
186
187 inline bool is_so_imm_not(unsigned Imm) const {
188 return ARM_AM::getSOImmVal(~Imm) != -1;
189 }
190
191 inline bool is_t2_so_imm(unsigned Imm) const {
192 return ARM_AM::getT2SOImmVal(Imm) != -1;
193 }
194
195 inline bool is_t2_so_imm_not(unsigned Imm) const {
196 return ARM_AM::getT2SOImmVal(~Imm) != -1;
197 }
198
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000199 // Include the pieces autogenerated from the target description.
200#include "ARMGenDAGISel.inc"
Bob Wilson224c2442009-05-19 05:53:42 +0000201
202private:
Evan Chenge88d5ce2009-07-02 07:28:31 +0000203 /// SelectARMIndexedLoad - Indexed (pre/post inc/dec) load matching code for
204 /// ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000205 SDNode *SelectARMIndexedLoad(SDNode *N);
206 SDNode *SelectT2IndexedLoad(SDNode *N);
Evan Chenge88d5ce2009-07-02 07:28:31 +0000207
Bob Wilson621f1952010-03-23 05:25:43 +0000208 /// SelectVLD - Select NEON load intrinsics. NumVecs should be
209 /// 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson3e36f132009-10-14 17:28:52 +0000210 /// loads of D registers and even subregs and odd subregs of Q registers.
Bob Wilson621f1952010-03-23 05:25:43 +0000211 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000212 SDNode *SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
213 unsigned *DOpcodes,
Bob Wilson3e36f132009-10-14 17:28:52 +0000214 unsigned *QOpcodes0, unsigned *QOpcodes1);
215
Bob Wilson24f995d2009-10-14 18:32:29 +0000216 /// SelectVST - Select NEON store intrinsics. NumVecs should
Bob Wilson11d98992010-03-23 06:20:33 +0000217 /// be 1, 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson24f995d2009-10-14 18:32:29 +0000218 /// stores of D registers and even subregs and odd subregs of Q registers.
Bob Wilson11d98992010-03-23 06:20:33 +0000219 /// For NumVecs <= 2, QOpcodes1 is not used.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000220 SDNode *SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
221 unsigned *DOpcodes,
Bob Wilson24f995d2009-10-14 18:32:29 +0000222 unsigned *QOpcodes0, unsigned *QOpcodes1);
223
Bob Wilson96493442009-10-14 16:46:45 +0000224 /// SelectVLDSTLane - Select NEON load/store lane intrinsics. NumVecs should
Bob Wilsona7c397c2009-10-14 16:19:03 +0000225 /// be 2, 3 or 4. The opcode arrays specify the instructions used for
Bob Wilson8466fa12010-09-13 23:01:35 +0000226 /// load/store of D registers and Q registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +0000227 SDNode *SelectVLDSTLane(SDNode *N, bool IsLoad,
228 bool isUpdating, unsigned NumVecs,
Bob Wilson8466fa12010-09-13 23:01:35 +0000229 unsigned *DOpcodes, unsigned *QOpcodes);
Bob Wilsona7c397c2009-10-14 16:19:03 +0000230
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000231 /// SelectVLDDup - Select NEON load-duplicate intrinsics. NumVecs
232 /// should be 2, 3 or 4. The opcode array specifies the instructions used
233 /// for loading D registers. (Q registers are not supported.)
Bob Wilson1c3ef902011-02-07 17:43:21 +0000234 SDNode *SelectVLDDup(SDNode *N, bool isUpdating, unsigned NumVecs,
235 unsigned *Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +0000236
Bob Wilson78dfbc32010-07-07 00:08:54 +0000237 /// SelectVTBL - Select NEON VTBL and VTBX intrinsics. NumVecs should be 2,
238 /// 3 or 4. These are custom-selected so that a REG_SEQUENCE can be
239 /// generated to force the table registers to be consecutive.
240 SDNode *SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs, unsigned Opc);
Bob Wilsond491d6e2010-07-06 23:36:25 +0000241
Sandeep Patel4e1ed882009-10-13 20:25:58 +0000242 /// SelectV6T2BitfieldExtractOp - Select SBFX/UBFX instructions for ARM.
Jim Grosbach3a1287b2010-04-22 23:24:18 +0000243 SDNode *SelectV6T2BitfieldExtractOp(SDNode *N, bool isSigned);
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000244
Evan Cheng07ba9062009-11-19 21:45:22 +0000245 /// SelectCMOVOp - Select CMOV instructions for ARM.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000246 SDNode *SelectCMOVOp(SDNode *N);
Evan Chengc892aeb2012-02-23 01:19:06 +0000247 SDNode *SelectConditionalOp(SDNode *N);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000248 SDNode *SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000249 ARMCC::CondCodes CCVal, SDValue CCR,
250 SDValue InFlag);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000251 SDNode *SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000252 ARMCC::CondCodes CCVal, SDValue CCR,
253 SDValue InFlag);
Jim Grosbacha4257162010-10-07 00:53:56 +0000254 SDNode *SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000255 ARMCC::CondCodes CCVal, SDValue CCR,
256 SDValue InFlag);
Jim Grosbach3bbdcea2010-10-07 00:42:42 +0000257 SDNode *SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +0000258 ARMCC::CondCodes CCVal, SDValue CCR,
259 SDValue InFlag);
Evan Cheng07ba9062009-11-19 21:45:22 +0000260
Bill Wendlingef2c86f2011-10-10 22:59:55 +0000261 // Select special operations if node forms integer ABS pattern
262 SDNode *SelectABSOp(SDNode *N);
263
Evan Chengde8aa4e2010-05-05 18:28:36 +0000264 SDNode *SelectConcatVector(SDNode *N);
265
Eli Friedman2bdffe42011-08-31 00:31:29 +0000266 SDNode *SelectAtomic64(SDNode *Node, unsigned Opc);
267
Evan Chengaf4550f2009-07-02 01:23:32 +0000268 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
269 /// inline asm expressions.
270 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
271 char ConstraintCode,
272 std::vector<SDValue> &OutOps);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000273
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000274 // Form pairs of consecutive S, D, or Q registers.
275 SDNode *PairSRegs(EVT VT, SDValue V0, SDValue V1);
Bob Wilson3bf12ab2009-10-06 22:01:59 +0000276 SDNode *PairDRegs(EVT VT, SDValue V0, SDValue V1);
Evan Cheng603afbf2010-05-10 17:34:18 +0000277 SDNode *PairQRegs(EVT VT, SDValue V0, SDValue V1);
278
Bob Wilson40cbe7d2010-06-04 00:04:02 +0000279 // Form sequences of 4 consecutive S, D, or Q registers.
280 SDNode *QuadSRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng603afbf2010-05-10 17:34:18 +0000281 SDNode *QuadDRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Evan Cheng8f6de382010-05-16 03:27:48 +0000282 SDNode *QuadQRegs(EVT VT, SDValue V0, SDValue V1, SDValue V2, SDValue V3);
Bob Wilson665814b2010-11-01 23:40:51 +0000283
284 // Get the alignment operand for a NEON VLD or VST instruction.
285 SDValue GetVLDSTAlign(SDValue Align, unsigned NumVecs, bool is64BitVector);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000286};
Evan Chenga8e29892007-01-19 07:51:42 +0000287}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +0000288
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000289/// isInt32Immediate - This method tests to see if the node is a 32-bit constant
290/// operand. If so Imm will receive the 32-bit value.
291static bool isInt32Immediate(SDNode *N, unsigned &Imm) {
292 if (N->getOpcode() == ISD::Constant && N->getValueType(0) == MVT::i32) {
293 Imm = cast<ConstantSDNode>(N)->getZExtValue();
294 return true;
295 }
296 return false;
297}
298
299// isInt32Immediate - This method tests to see if a constant operand.
300// If so Imm will receive the 32 bit value.
301static bool isInt32Immediate(SDValue N, unsigned &Imm) {
302 return isInt32Immediate(N.getNode(), Imm);
303}
304
305// isOpcWithIntImmediate - This method tests to see if the node is a specific
306// opcode and that it has a immediate integer right operand.
307// If so Imm will receive the 32 bit value.
308static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned& Imm) {
309 return N->getOpcode() == Opc &&
310 isInt32Immediate(N->getOperand(1).getNode(), Imm);
311}
312
Daniel Dunbarec91d522011-01-19 15:12:16 +0000313/// \brief Check whether a particular node is a constant value representable as
314/// (N * Scale) where (N in [\arg RangeMin, \arg RangeMax).
315///
316/// \param ScaledConstant [out] - On success, the pre-scaled constant value.
Jakob Stoklund Olesen11ebe3d2011-09-23 22:10:33 +0000317static bool isScaledConstantInRange(SDValue Node, int Scale,
Daniel Dunbarec91d522011-01-19 15:12:16 +0000318 int RangeMin, int RangeMax,
319 int &ScaledConstant) {
Jakob Stoklund Olesen11ebe3d2011-09-23 22:10:33 +0000320 assert(Scale > 0 && "Invalid scale!");
Daniel Dunbarec91d522011-01-19 15:12:16 +0000321
322 // Check that this is a constant.
323 const ConstantSDNode *C = dyn_cast<ConstantSDNode>(Node);
324 if (!C)
325 return false;
326
327 ScaledConstant = (int) C->getZExtValue();
328 if ((ScaledConstant % Scale) != 0)
329 return false;
330
331 ScaledConstant /= Scale;
332 return ScaledConstant >= RangeMin && ScaledConstant < RangeMax;
333}
334
Evan Cheng48575f62010-12-05 22:04:16 +0000335/// hasNoVMLxHazardUse - Return true if it's desirable to select a FP MLA / MLS
336/// node. VFP / NEON fp VMLA / VMLS instructions have special RAW hazards (at
337/// least on current ARM implementations) which should be avoidded.
338bool ARMDAGToDAGISel::hasNoVMLxHazardUse(SDNode *N) const {
339 if (OptLevel == CodeGenOpt::None)
340 return true;
341
342 if (!CheckVMLxHazard)
343 return true;
344
345 if (!Subtarget->isCortexA8() && !Subtarget->isCortexA9())
346 return true;
347
348 if (!N->hasOneUse())
349 return false;
350
351 SDNode *Use = *N->use_begin();
352 if (Use->getOpcode() == ISD::CopyToReg)
353 return true;
354 if (Use->isMachineOpcode()) {
Evan Chenge837dea2011-06-28 19:10:37 +0000355 const MCInstrDesc &MCID = TII->get(Use->getMachineOpcode());
356 if (MCID.mayStore())
Evan Cheng48575f62010-12-05 22:04:16 +0000357 return true;
Evan Chenge837dea2011-06-28 19:10:37 +0000358 unsigned Opcode = MCID.getOpcode();
Evan Cheng48575f62010-12-05 22:04:16 +0000359 if (Opcode == ARM::VMOVRS || Opcode == ARM::VMOVRRD)
360 return true;
361 // vmlx feeding into another vmlx. We actually want to unfold
362 // the use later in the MLxExpansion pass. e.g.
363 // vmla
364 // vmla (stall 8 cycles)
365 //
366 // vmul (5 cycles)
367 // vadd (5 cycles)
368 // vmla
369 // This adds up to about 18 - 19 cycles.
370 //
371 // vmla
372 // vmul (stall 4 cycles)
373 // vadd adds up to about 14 cycles.
374 return TII->isFpMLxInstruction(Opcode);
375 }
376
377 return false;
378}
Sandeep Patel47eedaa2009-10-13 18:59:48 +0000379
Evan Chengf40deed2010-10-27 23:41:30 +0000380bool ARMDAGToDAGISel::isShifterOpProfitable(const SDValue &Shift,
381 ARM_AM::ShiftOpc ShOpcVal,
382 unsigned ShAmt) {
383 if (!Subtarget->isCortexA9())
384 return true;
385 if (Shift.hasOneUse())
386 return true;
387 // R << 2 is free.
388 return ShOpcVal == ARM_AM::lsl && ShAmt == 2;
389}
390
Owen Anderson92a20222011-07-21 18:54:16 +0000391bool ARMDAGToDAGISel::SelectImmShifterOperand(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +0000392 SDValue &BaseReg,
Owen Anderson099e5552011-03-18 19:46:58 +0000393 SDValue &Opc,
394 bool CheckProfitability) {
Evan Chenga2c519b2010-07-30 23:33:54 +0000395 if (DisableShifterOp)
396 return false;
397
Evan Chengee04a6d2011-07-20 23:34:39 +0000398 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +0000399
400 // Don't match base register only case. That is matched to a separate
401 // lower complexity pattern with explicit register operand.
402 if (ShOpcVal == ARM_AM::no_shift) return false;
Jim Grosbach764ab522009-08-11 15:33:49 +0000403
Evan Cheng055b0312009-06-29 07:51:04 +0000404 BaseReg = N.getOperand(0);
405 unsigned ShImmVal = 0;
Owen Anderson92a20222011-07-21 18:54:16 +0000406 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
407 if (!RHS) return false;
Owen Anderson92a20222011-07-21 18:54:16 +0000408 ShImmVal = RHS->getZExtValue() & 31;
Evan Chengf40deed2010-10-27 23:41:30 +0000409 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
410 MVT::i32);
411 return true;
412}
413
Owen Anderson92a20222011-07-21 18:54:16 +0000414bool ARMDAGToDAGISel::SelectRegShifterOperand(SDValue N,
415 SDValue &BaseReg,
416 SDValue &ShReg,
417 SDValue &Opc,
418 bool CheckProfitability) {
419 if (DisableShifterOp)
420 return false;
421
422 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
423
424 // Don't match base register only case. That is matched to a separate
425 // lower complexity pattern with explicit register operand.
426 if (ShOpcVal == ARM_AM::no_shift) return false;
427
428 BaseReg = N.getOperand(0);
429 unsigned ShImmVal = 0;
430 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
431 if (RHS) return false;
432
433 ShReg = N.getOperand(1);
434 if (CheckProfitability && !isShifterOpProfitable(N, ShOpcVal, ShImmVal))
435 return false;
436 Opc = CurDAG->getTargetConstant(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal),
437 MVT::i32);
438 return true;
439}
440
441
Jim Grosbach3e556122010-10-26 22:37:02 +0000442bool ARMDAGToDAGISel::SelectAddrModeImm12(SDValue N,
443 SDValue &Base,
444 SDValue &OffImm) {
445 // Match simple R + imm12 operands.
446
447 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000448 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
449 !CurDAG->isBaseWithConstantOffset(N)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000450 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000451 // Match frame index.
Jim Grosbach3e556122010-10-26 22:37:02 +0000452 int FI = cast<FrameIndexSDNode>(N)->getIndex();
453 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
454 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
455 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000456 }
Owen Anderson099e5552011-03-18 19:46:58 +0000457
Chris Lattner0a9481f2011-02-13 22:25:43 +0000458 if (N.getOpcode() == ARMISD::Wrapper &&
459 !(Subtarget->useMovt() &&
460 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000461 Base = N.getOperand(0);
462 } else
463 Base = N;
464 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
465 return true;
466 }
467
468 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
469 int RHSC = (int)RHS->getZExtValue();
470 if (N.getOpcode() == ISD::SUB)
471 RHSC = -RHSC;
472
473 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
474 Base = N.getOperand(0);
475 if (Base.getOpcode() == ISD::FrameIndex) {
476 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
477 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
478 }
479 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
480 return true;
481 }
482 }
483
484 // Base only.
485 Base = N;
486 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
487 return true;
488}
489
490
491
492bool ARMDAGToDAGISel::SelectLdStSOReg(SDValue N, SDValue &Base, SDValue &Offset,
493 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000494 if (N.getOpcode() == ISD::MUL &&
495 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Jim Grosbach3e556122010-10-26 22:37:02 +0000496 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
497 // X * [3,5,9] -> X + X * [2,4,8] etc.
498 int RHSC = (int)RHS->getZExtValue();
499 if (RHSC & 1) {
500 RHSC = RHSC & ~1;
501 ARM_AM::AddrOpc AddSub = ARM_AM::add;
502 if (RHSC < 0) {
503 AddSub = ARM_AM::sub;
504 RHSC = - RHSC;
505 }
506 if (isPowerOf2_32(RHSC)) {
507 unsigned ShAmt = Log2_32(RHSC);
508 Base = Offset = N.getOperand(0);
509 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
510 ARM_AM::lsl),
511 MVT::i32);
512 return true;
513 }
514 }
515 }
516 }
517
Chris Lattner0a9481f2011-02-13 22:25:43 +0000518 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
519 // ISD::OR that is equivalent to an ISD::ADD.
520 !CurDAG->isBaseWithConstantOffset(N))
Jim Grosbach3e556122010-10-26 22:37:02 +0000521 return false;
522
523 // Leave simple R +/- imm12 operands for LDRi12
Chris Lattner0a9481f2011-02-13 22:25:43 +0000524 if (N.getOpcode() == ISD::ADD || N.getOpcode() == ISD::OR) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000525 int RHSC;
526 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
527 -0x1000+1, 0x1000, RHSC)) // 12 bits.
528 return false;
Jim Grosbach3e556122010-10-26 22:37:02 +0000529 }
530
531 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000532 ARM_AM::AddrOpc AddSub = N.getOpcode() == ISD::SUB ? ARM_AM::sub:ARM_AM::add;
Evan Chengee04a6d2011-07-20 23:34:39 +0000533 ARM_AM::ShiftOpc ShOpcVal =
534 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000535 unsigned ShAmt = 0;
536
537 Base = N.getOperand(0);
538 Offset = N.getOperand(1);
539
540 if (ShOpcVal != ARM_AM::no_shift) {
541 // Check to see if the RHS of the shift is a constant, if not, we can't fold
542 // it.
543 if (ConstantSDNode *Sh =
544 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
545 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000546 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
547 Offset = N.getOperand(1).getOperand(0);
548 else {
549 ShAmt = 0;
550 ShOpcVal = ARM_AM::no_shift;
551 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000552 } else {
553 ShOpcVal = ARM_AM::no_shift;
554 }
555 }
556
557 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000558 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000559 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000560 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Jim Grosbach3e556122010-10-26 22:37:02 +0000561 if (ShOpcVal != ARM_AM::no_shift) {
562 // Check to see if the RHS of the shift is a constant, if not, we can't
563 // fold it.
564 if (ConstantSDNode *Sh =
565 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
566 ShAmt = Sh->getZExtValue();
Cameron Zwarich8f8aa812011-10-05 23:39:02 +0000567 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Chengf40deed2010-10-27 23:41:30 +0000568 Offset = N.getOperand(0).getOperand(0);
569 Base = N.getOperand(1);
570 } else {
571 ShAmt = 0;
572 ShOpcVal = ARM_AM::no_shift;
573 }
Jim Grosbach3e556122010-10-26 22:37:02 +0000574 } else {
575 ShOpcVal = ARM_AM::no_shift;
576 }
577 }
578 }
579
580 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
581 MVT::i32);
582 return true;
583}
584
585
586
587
588//-----
589
Jim Grosbach82891622010-09-29 19:03:54 +0000590AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
591 SDValue &Base,
592 SDValue &Offset,
593 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000594 if (N.getOpcode() == ISD::MUL &&
595 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000596 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
597 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000598 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000599 if (RHSC & 1) {
600 RHSC = RHSC & ~1;
601 ARM_AM::AddrOpc AddSub = ARM_AM::add;
602 if (RHSC < 0) {
603 AddSub = ARM_AM::sub;
604 RHSC = - RHSC;
605 }
606 if (isPowerOf2_32(RHSC)) {
607 unsigned ShAmt = Log2_32(RHSC);
608 Base = Offset = N.getOperand(0);
609 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
610 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000611 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000612 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000613 }
614 }
615 }
616 }
617
Chris Lattner0a9481f2011-02-13 22:25:43 +0000618 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
619 // ISD::OR that is equivalent to an ADD.
620 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000621 Base = N;
622 if (N.getOpcode() == ISD::FrameIndex) {
623 int FI = cast<FrameIndexSDNode>(N)->getIndex();
624 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000625 } else if (N.getOpcode() == ARMISD::Wrapper &&
626 !(Subtarget->useMovt() &&
627 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000628 Base = N.getOperand(0);
629 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000630 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000631 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
632 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000633 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000634 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000635 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000636
Evan Chenga8e29892007-01-19 07:51:42 +0000637 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000638 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000639 int RHSC;
640 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
641 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
642 Base = N.getOperand(0);
643 if (Base.getOpcode() == ISD::FrameIndex) {
644 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
645 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000646 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000647 Offset = CurDAG->getRegister(0, MVT::i32);
648
649 ARM_AM::AddrOpc AddSub = ARM_AM::add;
650 if (RHSC < 0) {
651 AddSub = ARM_AM::sub;
652 RHSC = - RHSC;
653 }
654 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
655 ARM_AM::no_shift),
656 MVT::i32);
657 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000658 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000659 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000660
Evan Chengf40deed2010-10-27 23:41:30 +0000661 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
662 // Compute R +/- (R << N) and reuse it.
663 Base = N;
664 Offset = CurDAG->getRegister(0, MVT::i32);
665 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
666 ARM_AM::no_shift),
667 MVT::i32);
668 return AM2_BASE;
669 }
670
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000671 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000672 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chengee04a6d2011-07-20 23:34:39 +0000673 ARM_AM::ShiftOpc ShOpcVal =
674 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000675 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000676
Evan Chenga8e29892007-01-19 07:51:42 +0000677 Base = N.getOperand(0);
678 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000679
Evan Chenga8e29892007-01-19 07:51:42 +0000680 if (ShOpcVal != ARM_AM::no_shift) {
681 // Check to see if the RHS of the shift is a constant, if not, we can't fold
682 // it.
683 if (ConstantSDNode *Sh =
684 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000685 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000686 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
687 Offset = N.getOperand(1).getOperand(0);
688 else {
689 ShAmt = 0;
690 ShOpcVal = ARM_AM::no_shift;
691 }
Evan Chenga8e29892007-01-19 07:51:42 +0000692 } else {
693 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000694 }
695 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000696
Evan Chenga8e29892007-01-19 07:51:42 +0000697 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000698 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000699 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000700 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000701 if (ShOpcVal != ARM_AM::no_shift) {
702 // Check to see if the RHS of the shift is a constant, if not, we can't
703 // fold it.
704 if (ConstantSDNode *Sh =
705 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000706 ShAmt = Sh->getZExtValue();
Cameron Zwarich8f8aa812011-10-05 23:39:02 +0000707 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Chengf40deed2010-10-27 23:41:30 +0000708 Offset = N.getOperand(0).getOperand(0);
709 Base = N.getOperand(1);
710 } else {
711 ShAmt = 0;
712 ShOpcVal = ARM_AM::no_shift;
713 }
Evan Chenga8e29892007-01-19 07:51:42 +0000714 } else {
715 ShOpcVal = ARM_AM::no_shift;
716 }
717 }
718 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000719
Evan Chenga8e29892007-01-19 07:51:42 +0000720 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000721 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000722 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000723}
724
Owen Anderson793e7962011-07-26 20:54:26 +0000725bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000726 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000727 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000728 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
729 ? cast<LoadSDNode>(Op)->getAddressingMode()
730 : cast<StoreSDNode>(Op)->getAddressingMode();
731 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
732 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000733 int Val;
Owen Anderson793e7962011-07-26 20:54:26 +0000734 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
735 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000736
737 Offset = N;
Evan Chengee04a6d2011-07-20 23:34:39 +0000738 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000739 unsigned ShAmt = 0;
740 if (ShOpcVal != ARM_AM::no_shift) {
741 // Check to see if the RHS of the shift is a constant, if not, we can't fold
742 // it.
743 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000744 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000745 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
746 Offset = N.getOperand(0);
747 else {
748 ShAmt = 0;
749 ShOpcVal = ARM_AM::no_shift;
750 }
Evan Chenga8e29892007-01-19 07:51:42 +0000751 } else {
752 ShOpcVal = ARM_AM::no_shift;
753 }
754 }
755
756 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000757 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000758 return true;
759}
760
Owen Andersonc4e16de2011-08-29 20:16:50 +0000761bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
762 SDValue &Offset, SDValue &Opc) {
Owen Andersond84192f2011-08-31 20:00:11 +0000763 unsigned Opcode = Op->getOpcode();
764 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
765 ? cast<LoadSDNode>(Op)->getAddressingMode()
766 : cast<StoreSDNode>(Op)->getAddressingMode();
767 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
768 ? ARM_AM::add : ARM_AM::sub;
Owen Andersonc4e16de2011-08-29 20:16:50 +0000769 int Val;
770 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
Owen Andersond84192f2011-08-31 20:00:11 +0000771 if (AddSub == ARM_AM::sub) Val *= -1;
Owen Andersonc4e16de2011-08-29 20:16:50 +0000772 Offset = CurDAG->getRegister(0, MVT::i32);
773 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
774 return true;
775 }
776
777 return false;
778}
779
780
Owen Anderson793e7962011-07-26 20:54:26 +0000781bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
782 SDValue &Offset, SDValue &Opc) {
783 unsigned Opcode = Op->getOpcode();
784 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
785 ? cast<LoadSDNode>(Op)->getAddressingMode()
786 : cast<StoreSDNode>(Op)->getAddressingMode();
787 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
788 ? ARM_AM::add : ARM_AM::sub;
789 int Val;
790 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
791 Offset = CurDAG->getRegister(0, MVT::i32);
792 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
793 ARM_AM::no_shift),
794 MVT::i32);
795 return true;
796 }
797
798 return false;
799}
800
Jim Grosbach19dec202011-08-05 20:35:44 +0000801bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
802 Base = N;
803 return true;
804}
Evan Chenga8e29892007-01-19 07:51:42 +0000805
Chris Lattner52a261b2010-09-21 20:31:19 +0000806bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000807 SDValue &Base, SDValue &Offset,
808 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000809 if (N.getOpcode() == ISD::SUB) {
810 // X - C is canonicalize to X + -C, no need to handle it here.
811 Base = N.getOperand(0);
812 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000813 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000814 return true;
815 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000816
Chris Lattner0a9481f2011-02-13 22:25:43 +0000817 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000818 Base = N;
819 if (N.getOpcode() == ISD::FrameIndex) {
820 int FI = cast<FrameIndexSDNode>(N)->getIndex();
821 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
822 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000823 Offset = CurDAG->getRegister(0, MVT::i32);
824 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000825 return true;
826 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000827
Evan Chenga8e29892007-01-19 07:51:42 +0000828 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000829 int RHSC;
830 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
831 -256 + 1, 256, RHSC)) { // 8 bits.
832 Base = N.getOperand(0);
833 if (Base.getOpcode() == ISD::FrameIndex) {
834 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
835 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000836 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000837 Offset = CurDAG->getRegister(0, MVT::i32);
838
839 ARM_AM::AddrOpc AddSub = ARM_AM::add;
840 if (RHSC < 0) {
841 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000842 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000843 }
844 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
845 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000846 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000847
Evan Chenga8e29892007-01-19 07:51:42 +0000848 Base = N.getOperand(0);
849 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000850 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000851 return true;
852}
853
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000854bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000855 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000856 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000857 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
858 ? cast<LoadSDNode>(Op)->getAddressingMode()
859 : cast<StoreSDNode>(Op)->getAddressingMode();
860 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
861 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000862 int Val;
863 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
864 Offset = CurDAG->getRegister(0, MVT::i32);
865 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
866 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000867 }
868
869 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000870 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000871 return true;
872}
873
Jim Grosbach3ab56582010-10-21 19:38:40 +0000874bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000875 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000876 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000877 Base = N;
878 if (N.getOpcode() == ISD::FrameIndex) {
879 int FI = cast<FrameIndexSDNode>(N)->getIndex();
880 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000881 } else if (N.getOpcode() == ARMISD::Wrapper &&
882 !(Subtarget->useMovt() &&
883 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000884 Base = N.getOperand(0);
885 }
886 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000887 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000888 return true;
889 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000890
Evan Chenga8e29892007-01-19 07:51:42 +0000891 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000892 int RHSC;
893 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
894 -256 + 1, 256, RHSC)) {
895 Base = N.getOperand(0);
896 if (Base.getOpcode() == ISD::FrameIndex) {
897 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
898 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000899 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000900
901 ARM_AM::AddrOpc AddSub = ARM_AM::add;
902 if (RHSC < 0) {
903 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000904 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000905 }
906 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
907 MVT::i32);
908 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000909 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000910
Evan Chenga8e29892007-01-19 07:51:42 +0000911 Base = N;
912 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000913 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000914 return true;
915}
916
Bob Wilson665814b2010-11-01 23:40:51 +0000917bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
918 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000919 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000920
921 unsigned Alignment = 0;
922 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
923 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
924 // The maximum alignment is equal to the memory size being referenced.
925 unsigned LSNAlign = LSN->getAlignment();
926 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
Jakob Stoklund Olesenb0117ee2011-10-27 22:39:16 +0000927 if (LSNAlign >= MemSize && MemSize > 1)
Bob Wilson665814b2010-11-01 23:40:51 +0000928 Alignment = MemSize;
929 } else {
930 // All other uses of addrmode6 are for intrinsics. For now just record
931 // the raw alignment value; it will be refined later based on the legal
932 // alignment operands for the intrinsic.
933 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
934 }
935
936 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000937 return true;
938}
939
Bob Wilsonda525062011-02-25 06:42:42 +0000940bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
941 SDValue &Offset) {
942 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
943 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
944 if (AM != ISD::POST_INC)
945 return false;
946 Offset = N;
947 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
948 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
949 Offset = CurDAG->getRegister(0, MVT::i32);
950 }
951 return true;
952}
953
Chris Lattner52a261b2010-09-21 20:31:19 +0000954bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000955 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000956 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
957 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000958 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000959 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
960 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000961 return true;
962 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000963
Evan Chenga8e29892007-01-19 07:51:42 +0000964 return false;
965}
966
Bill Wendlingf4caf692010-12-14 03:36:38 +0000967
968//===----------------------------------------------------------------------===//
969// Thumb Addressing Modes
970//===----------------------------------------------------------------------===//
971
Chris Lattner52a261b2010-09-21 20:31:19 +0000972bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000973 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000974 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000975 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000976 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000977 return false;
978
979 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000980 return true;
981 }
982
Evan Chenga8e29892007-01-19 07:51:42 +0000983 Base = N.getOperand(0);
984 Offset = N.getOperand(1);
985 return true;
986}
987
Evan Cheng79d43262007-01-24 02:21:22 +0000988bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000989ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
990 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000991 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000992 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000993 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000994 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000995
Evan Cheng012f2d92007-01-24 08:53:17 +0000996 if (N.getOpcode() == ARMISD::Wrapper &&
997 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
998 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000999 }
1000
Chris Lattner0a9481f2011-02-13 22:25:43 +00001001 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001002 return false;
Evan Chenga8e29892007-01-19 07:51:42 +00001003
Evan Chengad0e4652007-02-06 00:22:06 +00001004 // Thumb does not have [sp, r] address mode.
1005 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1006 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1007 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001008 (RHSR && RHSR->getReg() == ARM::SP))
1009 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001010
Daniel Dunbarec91d522011-01-19 15:12:16 +00001011 // FIXME: Why do we explicitly check for a match here and then return false?
1012 // Presumably to allow something else to match, but shouldn't this be
1013 // documented?
1014 int RHSC;
1015 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1016 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001017
1018 Base = N.getOperand(0);
1019 Offset = N.getOperand(1);
1020 return true;
1021}
1022
1023bool
1024ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1025 SDValue &Base,
1026 SDValue &Offset) {
1027 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1028}
1029
1030bool
1031ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1032 SDValue &Base,
1033 SDValue &Offset) {
1034 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1035}
1036
1037bool
1038ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1039 SDValue &Base,
1040 SDValue &Offset) {
1041 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1042}
1043
1044bool
1045ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1046 SDValue &Base, SDValue &OffImm) {
1047 if (Scale == 4) {
1048 SDValue TmpBase, TmpOffImm;
1049 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1050 return false; // We want to select tLDRspi / tSTRspi instead.
1051
1052 if (N.getOpcode() == ARMISD::Wrapper &&
1053 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1054 return false; // We want to select tLDRpci instead.
1055 }
1056
Chris Lattner0a9481f2011-02-13 22:25:43 +00001057 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +00001058 if (N.getOpcode() == ARMISD::Wrapper &&
1059 !(Subtarget->useMovt() &&
1060 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1061 Base = N.getOperand(0);
1062 } else {
1063 Base = N;
1064 }
1065
Owen Anderson825b72b2009-08-11 20:47:22 +00001066 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001067 return true;
1068 }
1069
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001070 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1071 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1072 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1073 (RHSR && RHSR->getReg() == ARM::SP)) {
1074 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1075 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1076 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1077 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1078
1079 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1080 if (LHSC != 0 || RHSC != 0) return false;
1081
1082 Base = N;
1083 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1084 return true;
1085 }
1086
Evan Chenga8e29892007-01-19 07:51:42 +00001087 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001088 int RHSC;
1089 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1090 Base = N.getOperand(0);
1091 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1092 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001093 }
1094
Evan Chengc38f2bc2007-01-23 22:59:13 +00001095 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001096 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001097 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001098}
1099
Bill Wendlingf4caf692010-12-14 03:36:38 +00001100bool
1101ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1102 SDValue &OffImm) {
1103 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001104}
1105
Bill Wendlingf4caf692010-12-14 03:36:38 +00001106bool
1107ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1108 SDValue &OffImm) {
1109 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001110}
1111
Bill Wendlingf4caf692010-12-14 03:36:38 +00001112bool
1113ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1114 SDValue &OffImm) {
1115 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001116}
1117
Chris Lattner52a261b2010-09-21 20:31:19 +00001118bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1119 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001120 if (N.getOpcode() == ISD::FrameIndex) {
1121 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);
Evan Chenga8e29892007-01-19 07:51:42 +00001124 return true;
1125 }
Evan Cheng79d43262007-01-24 02:21:22 +00001126
Chris Lattner0a9481f2011-02-13 22:25:43 +00001127 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001128 return false;
1129
1130 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001131 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1132 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001133 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001134 int RHSC;
1135 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1136 Base = N.getOperand(0);
1137 if (Base.getOpcode() == ISD::FrameIndex) {
1138 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1139 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001140 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001141 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1142 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001143 }
1144 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001145
Evan Chenga8e29892007-01-19 07:51:42 +00001146 return false;
1147}
1148
Bill Wendlingf4caf692010-12-14 03:36:38 +00001149
1150//===----------------------------------------------------------------------===//
1151// Thumb 2 Addressing Modes
1152//===----------------------------------------------------------------------===//
1153
1154
Chris Lattner52a261b2010-09-21 20:31:19 +00001155bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001156 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001157 if (DisableShifterOp)
1158 return false;
1159
Evan Chengee04a6d2011-07-20 23:34:39 +00001160 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng9cb9e672009-06-27 02:26:13 +00001161
1162 // Don't match base register only case. That is matched to a separate
1163 // lower complexity pattern with explicit register operand.
1164 if (ShOpcVal == ARM_AM::no_shift) return false;
1165
1166 BaseReg = N.getOperand(0);
1167 unsigned ShImmVal = 0;
1168 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1169 ShImmVal = RHS->getZExtValue() & 31;
1170 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1171 return true;
1172 }
1173
1174 return false;
1175}
1176
Chris Lattner52a261b2010-09-21 20:31:19 +00001177bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001178 SDValue &Base, SDValue &OffImm) {
1179 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001180
Evan Cheng3a214252009-08-11 08:52:18 +00001181 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001182 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1183 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001184 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001185 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001186 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1187 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001188 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001189 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001190 }
Owen Anderson099e5552011-03-18 19:46:58 +00001191
Chris Lattner0a9481f2011-02-13 22:25:43 +00001192 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001193 !(Subtarget->useMovt() &&
1194 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001195 Base = N.getOperand(0);
1196 if (Base.getOpcode() == ISD::TargetConstantPool)
1197 return false; // We want to select t2LDRpci instead.
1198 } else
1199 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001200 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001201 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001202 }
Evan Cheng055b0312009-06-29 07:51:04 +00001203
1204 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001205 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001206 // Let t2LDRi8 handle (R - imm8).
1207 return false;
1208
Evan Cheng055b0312009-06-29 07:51:04 +00001209 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001210 if (N.getOpcode() == ISD::SUB)
1211 RHSC = -RHSC;
1212
1213 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001214 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001215 if (Base.getOpcode() == ISD::FrameIndex) {
1216 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1217 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1218 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001219 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001220 return true;
1221 }
1222 }
1223
Evan Cheng3a214252009-08-11 08:52:18 +00001224 // Base only.
1225 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001226 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001227 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001228}
1229
Chris Lattner52a261b2010-09-21 20:31:19 +00001230bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001231 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001232 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001233 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1234 !CurDAG->isBaseWithConstantOffset(N))
1235 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001236
Chris Lattner0a9481f2011-02-13 22:25:43 +00001237 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1238 int RHSC = (int)RHS->getSExtValue();
1239 if (N.getOpcode() == ISD::SUB)
1240 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001241
Chris Lattner0a9481f2011-02-13 22:25:43 +00001242 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1243 Base = N.getOperand(0);
1244 if (Base.getOpcode() == ISD::FrameIndex) {
1245 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1246 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001247 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001248 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1249 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001250 }
1251 }
1252
1253 return false;
1254}
1255
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001256bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001257 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001258 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001259 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1260 ? cast<LoadSDNode>(Op)->getAddressingMode()
1261 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001262 int RHSC;
1263 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1264 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1265 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1266 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1267 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001268 }
1269
1270 return false;
1271}
1272
Chris Lattner52a261b2010-09-21 20:31:19 +00001273bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001274 SDValue &Base,
1275 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001276 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001277 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001278 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001279
Evan Cheng3a214252009-08-11 08:52:18 +00001280 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1281 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1282 int RHSC = (int)RHS->getZExtValue();
1283 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1284 return false;
1285 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001286 return false;
1287 }
1288
Evan Cheng055b0312009-06-29 07:51:04 +00001289 // Look for (R + R) or (R + (R << [1,2,3])).
1290 unsigned ShAmt = 0;
1291 Base = N.getOperand(0);
1292 OffReg = N.getOperand(1);
1293
1294 // Swap if it is ((R << c) + R).
Evan Chengee04a6d2011-07-20 23:34:39 +00001295 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001296 if (ShOpcVal != ARM_AM::lsl) {
Evan Chengee04a6d2011-07-20 23:34:39 +00001297 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001298 if (ShOpcVal == ARM_AM::lsl)
1299 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001300 }
1301
Evan Cheng055b0312009-06-29 07:51:04 +00001302 if (ShOpcVal == ARM_AM::lsl) {
1303 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1304 // it.
1305 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1306 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001307 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1308 OffReg = OffReg.getOperand(0);
1309 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001310 ShAmt = 0;
1311 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001312 }
Evan Cheng055b0312009-06-29 07:51:04 +00001313 } else {
1314 ShOpcVal = ARM_AM::no_shift;
1315 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001316 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001317
Owen Anderson825b72b2009-08-11 20:47:22 +00001318 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001319
1320 return true;
1321}
1322
1323//===--------------------------------------------------------------------===//
1324
Evan Chengee568cf2007-07-05 07:15:27 +00001325/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001326static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001327 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001328}
1329
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001330SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1331 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001332 ISD::MemIndexedMode AM = LD->getAddressingMode();
1333 if (AM == ISD::UNINDEXED)
1334 return NULL;
1335
Owen Andersone50ed302009-08-10 22:56:29 +00001336 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001337 SDValue Offset, AMOpc;
1338 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1339 unsigned Opcode = 0;
1340 bool Match = false;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001341 if (LoadedVT == MVT::i32 && isPre &&
1342 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1343 Opcode = ARM::LDR_PRE_IMM;
1344 Match = true;
1345 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson793e7962011-07-26 20:54:26 +00001346 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001347 Opcode = ARM::LDR_POST_IMM;
Evan Chengaf4550f2009-07-02 01:23:32 +00001348 Match = true;
Owen Anderson793e7962011-07-26 20:54:26 +00001349 } else if (LoadedVT == MVT::i32 &&
1350 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson9ab0f252011-08-26 20:43:14 +00001351 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson793e7962011-07-26 20:54:26 +00001352 Match = true;
1353
Owen Anderson825b72b2009-08-11 20:47:22 +00001354 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001355 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001356 Match = true;
1357 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1358 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1359 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001360 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001361 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001362 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001363 Match = true;
1364 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1365 }
1366 } else {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001367 if (isPre &&
1368 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001369 Match = true;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001370 Opcode = ARM::LDRB_PRE_IMM;
1371 } else if (!isPre &&
1372 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1373 Match = true;
1374 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson793e7962011-07-26 20:54:26 +00001375 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1376 Match = true;
Owen Anderson9ab0f252011-08-26 20:43:14 +00001377 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengaf4550f2009-07-02 01:23:32 +00001378 }
1379 }
1380 }
1381
1382 if (Match) {
Owen Anderson2b568fb2011-08-26 21:12:37 +00001383 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1384 SDValue Chain = LD->getChain();
1385 SDValue Base = LD->getBasePtr();
1386 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1387 CurDAG->getRegister(0, MVT::i32), Chain };
Jim Grosbachb04546f2011-09-13 20:30:37 +00001388 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1389 MVT::i32, MVT::Other, Ops, 5);
Owen Anderson2b568fb2011-08-26 21:12:37 +00001390 } else {
1391 SDValue Chain = LD->getChain();
1392 SDValue Base = LD->getBasePtr();
1393 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1394 CurDAG->getRegister(0, MVT::i32), Chain };
Jim Grosbachb04546f2011-09-13 20:30:37 +00001395 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1396 MVT::i32, MVT::Other, Ops, 6);
Owen Anderson2b568fb2011-08-26 21:12:37 +00001397 }
Evan Chengaf4550f2009-07-02 01:23:32 +00001398 }
1399
1400 return NULL;
1401}
1402
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001403SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1404 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001405 ISD::MemIndexedMode AM = LD->getAddressingMode();
1406 if (AM == ISD::UNINDEXED)
1407 return NULL;
1408
Owen Andersone50ed302009-08-10 22:56:29 +00001409 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001410 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001411 SDValue Offset;
1412 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1413 unsigned Opcode = 0;
1414 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001415 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001416 switch (LoadedVT.getSimpleVT().SimpleTy) {
1417 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001418 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1419 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001420 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001421 if (isSExtLd)
1422 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1423 else
1424 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001425 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001426 case MVT::i8:
1427 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001428 if (isSExtLd)
1429 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1430 else
1431 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001432 break;
1433 default:
1434 return NULL;
1435 }
1436 Match = true;
1437 }
1438
1439 if (Match) {
1440 SDValue Chain = LD->getChain();
1441 SDValue Base = LD->getBasePtr();
1442 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001443 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001444 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001445 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001446 }
1447
1448 return NULL;
1449}
1450
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001451/// PairSRegs - Form a D register from a pair of S registers.
1452///
1453SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1454 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001455 SDValue RegClass =
1456 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001457 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1458 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001459 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1460 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001461}
1462
Evan Cheng603afbf2010-05-10 17:34:18 +00001463/// PairDRegs - Form a quad register from a pair of D registers.
1464///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001465SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1466 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001467 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001468 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1469 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001470 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1471 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001472}
1473
Evan Cheng7f687192010-05-14 00:21:45 +00001474/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001475///
1476SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1477 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001478 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001479 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1480 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001481 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1482 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001483}
1484
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001485/// QuadSRegs - Form 4 consecutive S registers.
1486///
1487SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1488 SDValue V2, SDValue V3) {
1489 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001490 SDValue RegClass =
1491 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001492 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1493 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1494 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1495 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001496 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1497 V2, SubReg2, V3, SubReg3 };
1498 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001499}
1500
Evan Cheng7f687192010-05-14 00:21:45 +00001501/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001502///
1503SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1504 SDValue V2, SDValue V3) {
1505 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001506 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001507 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1508 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1509 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1510 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001511 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1512 V2, SubReg2, V3, SubReg3 };
1513 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001514}
1515
Evan Cheng8f6de382010-05-16 03:27:48 +00001516/// QuadQRegs - Form 4 consecutive Q registers.
1517///
1518SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1519 SDValue V2, SDValue V3) {
1520 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001521 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001522 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1523 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1524 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1525 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001526 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1527 V2, SubReg2, V3, SubReg3 };
1528 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001529}
1530
Bob Wilson2a6e6162010-09-23 23:42:37 +00001531/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1532/// of a NEON VLD or VST instruction. The supported values depend on the
1533/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001534SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1535 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001536 unsigned NumRegs = NumVecs;
1537 if (!is64BitVector && NumVecs < 3)
1538 NumRegs *= 2;
1539
Bob Wilson665814b2010-11-01 23:40:51 +00001540 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001541 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001542 Alignment = 32;
1543 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1544 Alignment = 16;
1545 else if (Alignment >= 8)
1546 Alignment = 8;
1547 else
1548 Alignment = 0;
1549
1550 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001551}
1552
Jim Grosbach10b90a92011-10-24 21:45:13 +00001553// Get the register stride update opcode of a VLD/VST instruction that
1554// is otherwise equivalent to the given fixed stride updating instruction.
1555static unsigned getVLDSTRegisterUpdateOpcode(unsigned Opc) {
1556 switch (Opc) {
1557 default: break;
1558 case ARM::VLD1d8wb_fixed: return ARM::VLD1d8wb_register;
1559 case ARM::VLD1d16wb_fixed: return ARM::VLD1d16wb_register;
1560 case ARM::VLD1d32wb_fixed: return ARM::VLD1d32wb_register;
1561 case ARM::VLD1d64wb_fixed: return ARM::VLD1d64wb_register;
1562 case ARM::VLD1q8wb_fixed: return ARM::VLD1q8wb_register;
1563 case ARM::VLD1q16wb_fixed: return ARM::VLD1q16wb_register;
1564 case ARM::VLD1q32wb_fixed: return ARM::VLD1q32wb_register;
1565 case ARM::VLD1q64wb_fixed: return ARM::VLD1q64wb_register;
Jim Grosbach55dabaa2011-10-27 22:25:42 +00001566 case ARM::VLD1q8PseudoWB_fixed: return ARM::VLD1q8PseudoWB_register;
1567 case ARM::VLD1q16PseudoWB_fixed: return ARM::VLD1q16PseudoWB_register;
1568 case ARM::VLD1q32PseudoWB_fixed: return ARM::VLD1q32PseudoWB_register;
1569 case ARM::VLD1q64PseudoWB_fixed: return ARM::VLD1q64PseudoWB_register;
Jim Grosbach4334e032011-10-31 21:50:31 +00001570
1571 case ARM::VST1d8wb_fixed: return ARM::VST1d8wb_register;
1572 case ARM::VST1d16wb_fixed: return ARM::VST1d16wb_register;
1573 case ARM::VST1d32wb_fixed: return ARM::VST1d32wb_register;
1574 case ARM::VST1d64wb_fixed: return ARM::VST1d64wb_register;
1575 case ARM::VST1q8wb_fixed: return ARM::VST1q8wb_register;
1576 case ARM::VST1q16wb_fixed: return ARM::VST1q16wb_register;
1577 case ARM::VST1q32wb_fixed: return ARM::VST1q32wb_register;
1578 case ARM::VST1q64wb_fixed: return ARM::VST1q64wb_register;
1579 case ARM::VST1q8PseudoWB_fixed: return ARM::VST1q8PseudoWB_register;
1580 case ARM::VST1q16PseudoWB_fixed: return ARM::VST1q16PseudoWB_register;
1581 case ARM::VST1q32PseudoWB_fixed: return ARM::VST1q32PseudoWB_register;
1582 case ARM::VST1q64PseudoWB_fixed: return ARM::VST1q64PseudoWB_register;
Jim Grosbachd5ca2012011-11-29 22:38:04 +00001583 case ARM::VST1d64TPseudoWB_fixed: return ARM::VST1d64TPseudoWB_register;
Jim Grosbach4c7edb32011-11-29 22:58:48 +00001584 case ARM::VST1d64QPseudoWB_fixed: return ARM::VST1d64QPseudoWB_register;
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001585
1586 case ARM::VLD2d8PseudoWB_fixed: return ARM::VLD2d8PseudoWB_register;
1587 case ARM::VLD2d16PseudoWB_fixed: return ARM::VLD2d16PseudoWB_register;
1588 case ARM::VLD2d32PseudoWB_fixed: return ARM::VLD2d32PseudoWB_register;
1589 case ARM::VLD2q8PseudoWB_fixed: return ARM::VLD2q8PseudoWB_register;
1590 case ARM::VLD2q16PseudoWB_fixed: return ARM::VLD2q16PseudoWB_register;
1591 case ARM::VLD2q32PseudoWB_fixed: return ARM::VLD2q32PseudoWB_register;
1592
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001593 case ARM::VST2d8PseudoWB_fixed: return ARM::VST2d8PseudoWB_register;
1594 case ARM::VST2d16PseudoWB_fixed: return ARM::VST2d16PseudoWB_register;
1595 case ARM::VST2d32PseudoWB_fixed: return ARM::VST2d32PseudoWB_register;
1596 case ARM::VST2q8PseudoWB_fixed: return ARM::VST2q8PseudoWB_register;
1597 case ARM::VST2q16PseudoWB_fixed: return ARM::VST2q16PseudoWB_register;
1598 case ARM::VST2q32PseudoWB_fixed: return ARM::VST2q32PseudoWB_register;
Jim Grosbache6949b12011-12-21 19:40:55 +00001599
1600 case ARM::VLD2DUPd8PseudoWB_fixed: return ARM::VLD2DUPd8PseudoWB_register;
1601 case ARM::VLD2DUPd16PseudoWB_fixed: return ARM::VLD2DUPd16PseudoWB_register;
1602 case ARM::VLD2DUPd32PseudoWB_fixed: return ARM::VLD2DUPd32PseudoWB_register;
Jim Grosbach10b90a92011-10-24 21:45:13 +00001603 }
1604 return Opc; // If not one we handle, return it unchanged.
1605}
1606
Bob Wilson1c3ef902011-02-07 17:43:21 +00001607SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson3e36f132009-10-14 17:28:52 +00001608 unsigned *DOpcodes, unsigned *QOpcodes0,
1609 unsigned *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001610 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001611 DebugLoc dl = N->getDebugLoc();
1612
Bob Wilson226036e2010-03-20 22:13:40 +00001613 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001614 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1615 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001616 return NULL;
1617
1618 SDValue Chain = N->getOperand(0);
1619 EVT VT = N->getValueType(0);
1620 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001621 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001622
Bob Wilson3e36f132009-10-14 17:28:52 +00001623 unsigned OpcodeIndex;
1624 switch (VT.getSimpleVT().SimpleTy) {
1625 default: llvm_unreachable("unhandled vld type");
1626 // Double-register operations:
1627 case MVT::v8i8: OpcodeIndex = 0; break;
1628 case MVT::v4i16: OpcodeIndex = 1; break;
1629 case MVT::v2f32:
1630 case MVT::v2i32: OpcodeIndex = 2; break;
1631 case MVT::v1i64: OpcodeIndex = 3; break;
1632 // Quad-register operations:
1633 case MVT::v16i8: OpcodeIndex = 0; break;
1634 case MVT::v8i16: OpcodeIndex = 1; break;
1635 case MVT::v4f32:
1636 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001637 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001638 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001639 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001640 }
1641
Bob Wilsonf5721912010-09-03 18:16:02 +00001642 EVT ResTy;
1643 if (NumVecs == 1)
1644 ResTy = VT;
1645 else {
1646 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1647 if (!is64BitVector)
1648 ResTyElts *= 2;
1649 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1650 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001651 std::vector<EVT> ResTys;
1652 ResTys.push_back(ResTy);
1653 if (isUpdating)
1654 ResTys.push_back(MVT::i32);
1655 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001656
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001657 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001658 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001659 SDNode *VLd;
1660 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001661
Bob Wilson1c3ef902011-02-07 17:43:21 +00001662 // Double registers and VLD1/VLD2 quad registers are directly supported.
1663 if (is64BitVector || NumVecs <= 2) {
1664 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1665 QOpcodes0[OpcodeIndex]);
1666 Ops.push_back(MemAddr);
1667 Ops.push_back(Align);
1668 if (isUpdating) {
1669 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001670 // FIXME: VLD1/VLD2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach10b90a92011-10-24 21:45:13 +00001671 // case entirely when the rest are updated to that form, too.
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001672 if ((NumVecs == 1 || NumVecs == 2) && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach10b90a92011-10-24 21:45:13 +00001673 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001674 // We use a VLD1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach4334e032011-10-31 21:50:31 +00001675 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001676 if ((NumVecs != 1 && NumVecs != 2 && Opc != ARM::VLD1q64PseudoWB_fixed) ||
Jim Grosbach4334e032011-10-31 21:50:31 +00001677 !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach10b90a92011-10-24 21:45:13 +00001678 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001679 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001680 Ops.push_back(Pred);
1681 Ops.push_back(Reg0);
1682 Ops.push_back(Chain);
1683 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001684
Bob Wilson3e36f132009-10-14 17:28:52 +00001685 } else {
1686 // Otherwise, quad registers are loaded with two separate instructions,
1687 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001688 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001689
Bob Wilson1c3ef902011-02-07 17:43:21 +00001690 // Load the even subregs. This is always an updating load, so that it
1691 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001692 SDValue ImplDef =
1693 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1694 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001695 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1696 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001697 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001698
Bob Wilson24f995d2009-10-14 18:32:29 +00001699 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001700 Ops.push_back(SDValue(VLdA, 1));
1701 Ops.push_back(Align);
1702 if (isUpdating) {
1703 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1704 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1705 "only constant post-increment update allowed for VLD3/4");
1706 (void)Inc;
1707 Ops.push_back(Reg0);
1708 }
1709 Ops.push_back(SDValue(VLdA, 0));
1710 Ops.push_back(Pred);
1711 Ops.push_back(Reg0);
1712 Ops.push_back(Chain);
1713 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1714 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001715 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001716
Evan Chengb58a3402011-04-19 00:04:03 +00001717 // Transfer memoperands.
1718 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1719 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1720 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1721
Bob Wilson1c3ef902011-02-07 17:43:21 +00001722 if (NumVecs == 1)
1723 return VLd;
1724
1725 // Extract out the subregisters.
1726 SDValue SuperReg = SDValue(VLd, 0);
1727 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1728 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1729 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1730 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1731 ReplaceUses(SDValue(N, Vec),
1732 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1733 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1734 if (isUpdating)
1735 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001736 return NULL;
1737}
1738
Bob Wilson1c3ef902011-02-07 17:43:21 +00001739SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Bob Wilson24f995d2009-10-14 18:32:29 +00001740 unsigned *DOpcodes, unsigned *QOpcodes0,
1741 unsigned *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001742 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001743 DebugLoc dl = N->getDebugLoc();
1744
Bob Wilson226036e2010-03-20 22:13:40 +00001745 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001746 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1747 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1748 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001749 return NULL;
1750
Evan Chengb58a3402011-04-19 00:04:03 +00001751 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1752 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1753
Bob Wilson24f995d2009-10-14 18:32:29 +00001754 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001755 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001756 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001757 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001758
Bob Wilson24f995d2009-10-14 18:32:29 +00001759 unsigned OpcodeIndex;
1760 switch (VT.getSimpleVT().SimpleTy) {
1761 default: llvm_unreachable("unhandled vst type");
1762 // Double-register operations:
1763 case MVT::v8i8: OpcodeIndex = 0; break;
1764 case MVT::v4i16: OpcodeIndex = 1; break;
1765 case MVT::v2f32:
1766 case MVT::v2i32: OpcodeIndex = 2; break;
1767 case MVT::v1i64: OpcodeIndex = 3; break;
1768 // Quad-register operations:
1769 case MVT::v16i8: OpcodeIndex = 0; break;
1770 case MVT::v8i16: OpcodeIndex = 1; break;
1771 case MVT::v4f32:
1772 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001773 case MVT::v2i64: OpcodeIndex = 3;
1774 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1775 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001776 }
1777
Bob Wilson1c3ef902011-02-07 17:43:21 +00001778 std::vector<EVT> ResTys;
1779 if (isUpdating)
1780 ResTys.push_back(MVT::i32);
1781 ResTys.push_back(MVT::Other);
1782
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001783 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001784 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001785 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001786
Bob Wilson1c3ef902011-02-07 17:43:21 +00001787 // Double registers and VST1/VST2 quad registers are directly supported.
1788 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001789 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001790 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001791 SrcReg = N->getOperand(Vec0Idx);
1792 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001793 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001794 SDValue V0 = N->getOperand(Vec0Idx + 0);
1795 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001796 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001797 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001798 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001799 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001800 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001801 // an undef.
1802 SDValue V3 = (NumVecs == 3)
1803 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001804 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001805 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001806 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001807 } else {
1808 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001809 SDValue Q0 = N->getOperand(Vec0Idx);
1810 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001811 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001812 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001813
1814 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1815 QOpcodes0[OpcodeIndex]);
1816 Ops.push_back(MemAddr);
1817 Ops.push_back(Align);
1818 if (isUpdating) {
1819 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001820 // FIXME: VST1/VST2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach4334e032011-10-31 21:50:31 +00001821 // case entirely when the rest are updated to that form, too.
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001822 if (NumVecs <= 2 && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach4334e032011-10-31 21:50:31 +00001823 Opc = getVLDSTRegisterUpdateOpcode(Opc);
1824 // We use a VST1 for v1i64 even if the pseudo says vld2/3/4, so
1825 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbachf1f16c82012-01-10 21:11:12 +00001826 if ((NumVecs > 2 && Opc != ARM::VST1q64PseudoWB_fixed) ||
Jim Grosbach4334e032011-10-31 21:50:31 +00001827 !isa<ConstantSDNode>(Inc.getNode()))
1828 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001829 }
1830 Ops.push_back(SrcReg);
1831 Ops.push_back(Pred);
1832 Ops.push_back(Reg0);
1833 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001834 SDNode *VSt =
1835 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1836
1837 // Transfer memoperands.
1838 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1839
1840 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001841 }
1842
1843 // Otherwise, quad registers are stored with two separate instructions,
1844 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001845
Bob Wilson07f6e802010-06-16 21:34:01 +00001846 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001847 SDValue V0 = N->getOperand(Vec0Idx + 0);
1848 SDValue V1 = N->getOperand(Vec0Idx + 1);
1849 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001850 SDValue V3 = (NumVecs == 3)
1851 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001852 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001853 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001854
Bob Wilson1c3ef902011-02-07 17:43:21 +00001855 // Store the even D registers. This is always an updating store, so that it
1856 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001857 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1858 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1859 MemAddr.getValueType(),
1860 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001861 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001862 Chain = SDValue(VStA, 1);
1863
1864 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001865 Ops.push_back(SDValue(VStA, 0));
1866 Ops.push_back(Align);
1867 if (isUpdating) {
1868 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1869 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1870 "only constant post-increment update allowed for VST3/4");
1871 (void)Inc;
1872 Ops.push_back(Reg0);
1873 }
1874 Ops.push_back(RegSeq);
1875 Ops.push_back(Pred);
1876 Ops.push_back(Reg0);
1877 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001878 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1879 Ops.data(), Ops.size());
1880 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1881 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001882}
1883
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001884SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001885 bool isUpdating, unsigned NumVecs,
1886 unsigned *DOpcodes,
Bob Wilson8466fa12010-09-13 23:01:35 +00001887 unsigned *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001888 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001889 DebugLoc dl = N->getDebugLoc();
1890
Bob Wilson226036e2010-03-20 22:13:40 +00001891 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001892 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1893 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1894 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001895 return NULL;
1896
Evan Chengb58a3402011-04-19 00:04:03 +00001897 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1898 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1899
Bob Wilsona7c397c2009-10-14 16:19:03 +00001900 SDValue Chain = N->getOperand(0);
1901 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001902 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1903 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001904 bool is64BitVector = VT.is64BitVector();
1905
Bob Wilson665814b2010-11-01 23:40:51 +00001906 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001907 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001908 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001909 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1910 if (Alignment > NumBytes)
1911 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001912 if (Alignment < 8 && Alignment < NumBytes)
1913 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001914 // Alignment must be a power of two; make sure of that.
1915 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001916 if (Alignment == 1)
1917 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001918 }
Bob Wilson665814b2010-11-01 23:40:51 +00001919 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001920
Bob Wilsona7c397c2009-10-14 16:19:03 +00001921 unsigned OpcodeIndex;
1922 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001923 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001924 // Double-register operations:
1925 case MVT::v8i8: OpcodeIndex = 0; break;
1926 case MVT::v4i16: OpcodeIndex = 1; break;
1927 case MVT::v2f32:
1928 case MVT::v2i32: OpcodeIndex = 2; break;
1929 // Quad-register operations:
1930 case MVT::v8i16: OpcodeIndex = 0; break;
1931 case MVT::v4f32:
1932 case MVT::v4i32: OpcodeIndex = 1; break;
1933 }
1934
Bob Wilson1c3ef902011-02-07 17:43:21 +00001935 std::vector<EVT> ResTys;
1936 if (IsLoad) {
1937 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1938 if (!is64BitVector)
1939 ResTyElts *= 2;
1940 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1941 MVT::i64, ResTyElts));
1942 }
1943 if (isUpdating)
1944 ResTys.push_back(MVT::i32);
1945 ResTys.push_back(MVT::Other);
1946
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001947 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001948 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001949
Bob Wilson1c3ef902011-02-07 17:43:21 +00001950 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001951 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001952 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001953 if (isUpdating) {
1954 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1955 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1956 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001957
Bob Wilson8466fa12010-09-13 23:01:35 +00001958 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001959 SDValue V0 = N->getOperand(Vec0Idx + 0);
1960 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001961 if (NumVecs == 2) {
1962 if (is64BitVector)
1963 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1964 else
1965 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001966 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001967 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001968 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001969 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1970 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001971 if (is64BitVector)
1972 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1973 else
1974 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001975 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001976 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001977 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001978 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001979 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001980 Ops.push_back(Chain);
1981
Bob Wilson1c3ef902011-02-07 17:43:21 +00001982 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1983 QOpcodes[OpcodeIndex]);
1984 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1985 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001986 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001987 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001988 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001989
Bob Wilson8466fa12010-09-13 23:01:35 +00001990 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001991 SuperReg = SDValue(VLdLn, 0);
1992 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1993 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1994 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001995 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1996 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001997 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1998 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1999 if (isUpdating)
2000 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00002001 return NULL;
2002}
2003
Bob Wilson1c3ef902011-02-07 17:43:21 +00002004SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
2005 unsigned NumVecs, unsigned *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002006 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
2007 DebugLoc dl = N->getDebugLoc();
2008
2009 SDValue MemAddr, Align;
2010 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
2011 return NULL;
2012
Evan Chengb58a3402011-04-19 00:04:03 +00002013 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2014 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2015
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002016 SDValue Chain = N->getOperand(0);
2017 EVT VT = N->getValueType(0);
2018
2019 unsigned Alignment = 0;
2020 if (NumVecs != 3) {
2021 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2022 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2023 if (Alignment > NumBytes)
2024 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00002025 if (Alignment < 8 && Alignment < NumBytes)
2026 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002027 // Alignment must be a power of two; make sure of that.
2028 Alignment = (Alignment & -Alignment);
2029 if (Alignment == 1)
2030 Alignment = 0;
2031 }
2032 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
2033
2034 unsigned OpcodeIndex;
2035 switch (VT.getSimpleVT().SimpleTy) {
2036 default: llvm_unreachable("unhandled vld-dup type");
2037 case MVT::v8i8: OpcodeIndex = 0; break;
2038 case MVT::v4i16: OpcodeIndex = 1; break;
2039 case MVT::v2f32:
2040 case MVT::v2i32: OpcodeIndex = 2; break;
2041 }
2042
2043 SDValue Pred = getAL(CurDAG);
2044 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2045 SDValue SuperReg;
2046 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00002047 SmallVector<SDValue, 6> Ops;
2048 Ops.push_back(MemAddr);
2049 Ops.push_back(Align);
2050 if (isUpdating) {
Jim Grosbache6949b12011-12-21 19:40:55 +00002051 // fixed-stride update instructions don't have an explicit writeback
2052 // operand. It's implicit in the opcode itself.
Bob Wilson1c3ef902011-02-07 17:43:21 +00002053 SDValue Inc = N->getOperand(2);
Jim Grosbache6949b12011-12-21 19:40:55 +00002054 if (!isa<ConstantSDNode>(Inc.getNode()))
2055 Ops.push_back(Inc);
2056 // FIXME: VLD3 and VLD4 haven't been updated to that form yet.
2057 else if (NumVecs > 2)
2058 Ops.push_back(Reg0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00002059 }
2060 Ops.push_back(Pred);
2061 Ops.push_back(Reg0);
2062 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002063
2064 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00002065 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00002066 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00002067 if (isUpdating)
2068 ResTys.push_back(MVT::i32);
2069 ResTys.push_back(MVT::Other);
2070 SDNode *VLdDup =
2071 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00002072 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002073 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002074
2075 // Extract the subregisters.
2076 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
2077 unsigned SubIdx = ARM::dsub_0;
2078 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2079 ReplaceUses(SDValue(N, Vec),
2080 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00002081 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2082 if (isUpdating)
2083 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002084 return NULL;
2085}
2086
Bob Wilson78dfbc32010-07-07 00:08:54 +00002087SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2088 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00002089 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
2090 DebugLoc dl = N->getDebugLoc();
2091 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002092 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00002093
2094 // Form a REG_SEQUENCE to force register allocation.
2095 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00002096 SDValue V0 = N->getOperand(FirstTblReg + 0);
2097 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002098 if (NumVecs == 2)
2099 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
2100 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00002101 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00002102 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00002103 // an undef.
2104 SDValue V3 = (NumVecs == 3)
2105 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00002106 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002107 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
2108 }
2109
Bob Wilson78dfbc32010-07-07 00:08:54 +00002110 SmallVector<SDValue, 6> Ops;
2111 if (IsExt)
2112 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00002113 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002114 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00002115 Ops.push_back(getAL(CurDAG)); // predicate
2116 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00002117 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00002118}
2119
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002120SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002121 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002122 if (!Subtarget->hasV6T2Ops())
2123 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00002124
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002125 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
2126 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2127
2128
2129 // For unsigned extracts, check for a shift right and mask
2130 unsigned And_imm = 0;
2131 if (N->getOpcode() == ISD::AND) {
2132 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2133
2134 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
2135 if (And_imm & (And_imm + 1))
2136 return NULL;
2137
2138 unsigned Srl_imm = 0;
2139 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2140 Srl_imm)) {
2141 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2142
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002143 // Note: The width operand is encoded as width-1.
2144 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002145 unsigned LSB = Srl_imm;
2146 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2147 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2148 CurDAG->getTargetConstant(LSB, MVT::i32),
2149 CurDAG->getTargetConstant(Width, MVT::i32),
2150 getAL(CurDAG), Reg0 };
2151 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2152 }
2153 }
2154 return NULL;
2155 }
2156
2157 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002158 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002159 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002160 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2161 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002162 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002163 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002164 // Note: The width operand is encoded as width-1.
2165 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002166 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00002167 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002168 return NULL;
2169 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002170 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002171 CurDAG->getTargetConstant(LSB, MVT::i32),
2172 CurDAG->getTargetConstant(Width, MVT::i32),
2173 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002174 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002175 }
2176 }
2177 return NULL;
2178}
2179
Evan Cheng9ef48352009-11-20 00:54:03 +00002180SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002181SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002182 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2183 SDValue CPTmp0;
2184 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002185 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002186 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2187 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2188 unsigned Opc = 0;
2189 switch (SOShOp) {
2190 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2191 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2192 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2193 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2194 default:
2195 llvm_unreachable("Unknown so_reg opcode!");
Evan Cheng9ef48352009-11-20 00:54:03 +00002196 }
2197 SDValue SOShImm =
2198 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2199 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2200 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002201 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002202 }
2203 return 0;
2204}
2205
2206SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002207SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002208 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2209 SDValue CPTmp0;
2210 SDValue CPTmp1;
2211 SDValue CPTmp2;
Owen Anderson152d4a42011-07-21 23:38:37 +00002212 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002213 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
Owen Andersone0a03142011-07-22 18:30:30 +00002214 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, InFlag };
2215 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 6);
Owen Anderson92a20222011-07-21 18:54:16 +00002216 }
2217
2218 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2219 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2220 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2221 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002222 }
2223 return 0;
2224}
2225
2226SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002227SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002228 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002229 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002230 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002231 return 0;
2232
Evan Cheng63f35442010-11-13 02:25:14 +00002233 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002234 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002235 if (is_t2_so_imm(TrueImm)) {
2236 Opc = ARM::t2MOVCCi;
2237 } else if (TrueImm <= 0xffff) {
2238 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002239 } else if (is_t2_so_imm_not(TrueImm)) {
2240 TrueImm = ~TrueImm;
2241 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002242 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002243 // Large immediate.
2244 Opc = ARM::t2MOVCCi32imm;
2245 }
2246
2247 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002248 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002249 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2250 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002251 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002252 }
Evan Cheng63f35442010-11-13 02:25:14 +00002253
Evan Cheng9ef48352009-11-20 00:54:03 +00002254 return 0;
2255}
2256
2257SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002258SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002259 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002260 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2261 if (!T)
2262 return 0;
2263
Evan Cheng63f35442010-11-13 02:25:14 +00002264 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002265 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002266 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002267 if (isSoImm) {
2268 Opc = ARM::MOVCCi;
2269 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2270 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002271 } else if (is_so_imm_not(TrueImm)) {
2272 TrueImm = ~TrueImm;
2273 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002274 } else if (TrueVal.getNode()->hasOneUse() &&
2275 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002276 // Large immediate.
2277 Opc = ARM::MOVCCi32imm;
2278 }
2279
2280 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002281 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002282 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2283 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002284 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002285 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002286
Evan Cheng9ef48352009-11-20 00:54:03 +00002287 return 0;
2288}
2289
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002290SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2291 EVT VT = N->getValueType(0);
2292 SDValue FalseVal = N->getOperand(0);
2293 SDValue TrueVal = N->getOperand(1);
2294 SDValue CC = N->getOperand(2);
2295 SDValue CCR = N->getOperand(3);
2296 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002297 assert(CC.getOpcode() == ISD::Constant);
2298 assert(CCR.getOpcode() == ISD::Register);
2299 ARMCC::CondCodes CCVal =
2300 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002301
2302 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2303 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2304 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2305 // Pattern complexity = 18 cost = 1 size = 0
Evan Cheng07ba9062009-11-19 21:45:22 +00002306 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002307 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002308 CCVal, CCR, InFlag);
2309 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002310 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002311 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2312 if (Res)
2313 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002314 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002315 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002316 CCVal, CCR, InFlag);
2317 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002318 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002319 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2320 if (Res)
2321 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002322 }
2323
2324 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002325 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002326 // (imm:i32):$cc)
2327 // Emits: (MOVCCi:i32 GPR:i32:$false,
2328 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2329 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002330 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002331 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002332 CCVal, CCR, InFlag);
2333 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002334 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002335 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2336 if (Res)
2337 return Res;
2338 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002339 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002340 CCVal, CCR, InFlag);
2341 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002342 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002343 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2344 if (Res)
2345 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002346 }
2347 }
2348
2349 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2350 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2351 // Pattern complexity = 6 cost = 1 size = 0
2352 //
2353 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2354 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2355 // Pattern complexity = 6 cost = 11 size = 0
2356 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002357 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002358 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2359 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002360 unsigned Opc = 0;
2361 switch (VT.getSimpleVT().SimpleTy) {
Craig Topperbc219812012-02-07 02:50:20 +00002362 default: llvm_unreachable("Illegal conditional move type!");
Evan Cheng07ba9062009-11-19 21:45:22 +00002363 case MVT::i32:
2364 Opc = Subtarget->isThumb()
2365 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2366 : ARM::MOVCCr;
2367 break;
2368 case MVT::f32:
2369 Opc = ARM::VMOVScc;
2370 break;
2371 case MVT::f64:
2372 Opc = ARM::VMOVDcc;
2373 break;
2374 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002375 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002376}
2377
Evan Chengc892aeb2012-02-23 01:19:06 +00002378SDNode *ARMDAGToDAGISel::SelectConditionalOp(SDNode *N) {
Evan Chengc892aeb2012-02-23 01:19:06 +00002379 SDValue FalseVal = N->getOperand(0);
2380 SDValue TrueVal = N->getOperand(1);
2381 ARMCC::CondCodes CCVal =
2382 (ARMCC::CondCodes)cast<ConstantSDNode>(N->getOperand(2))->getZExtValue();
2383 SDValue CCR = N->getOperand(3);
2384 assert(CCR.getOpcode() == ISD::Register);
2385 SDValue InFlag = N->getOperand(4);
2386 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2387 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2388
2389 if (Subtarget->isThumb()) {
2390 SDValue CPTmp0;
2391 SDValue CPTmp1;
2392 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
2393 unsigned Opc;
2394 switch (N->getOpcode()) {
2395 default: llvm_unreachable("Unexpected node");
2396 case ARMISD::CAND: Opc = ARM::t2ANDCCrs; break;
2397 case ARMISD::COR: Opc = ARM::t2ORRCCrs; break;
2398 case ARMISD::CXOR: Opc = ARM::t2EORCCrs; break;
2399 }
2400 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CC, CCR, Reg0, InFlag };
2401 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 7);
2402 }
2403
2404 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2405 if (T) {
2406 unsigned TrueImm = T->getZExtValue();
2407 if (is_t2_so_imm(TrueImm)) {
2408 unsigned Opc;
2409 switch (N->getOpcode()) {
2410 default: llvm_unreachable("Unexpected node");
2411 case ARMISD::CAND: Opc = ARM::t2ANDCCri; break;
2412 case ARMISD::COR: Opc = ARM::t2ORRCCri; break;
2413 case ARMISD::CXOR: Opc = ARM::t2EORCCri; break;
2414 }
2415 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
2416 SDValue Ops[] = { FalseVal, True, CC, CCR, Reg0, InFlag };
2417 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 6);
2418 }
2419 }
2420
2421 unsigned Opc;
2422 switch (N->getOpcode()) {
2423 default: llvm_unreachable("Unexpected node");
2424 case ARMISD::CAND: Opc = ARM::t2ANDCCrr; break;
2425 case ARMISD::COR: Opc = ARM::t2ORRCCrr; break;
2426 case ARMISD::CXOR: Opc = ARM::t2EORCCrr; break;
2427 }
2428 SDValue Ops[] = { FalseVal, TrueVal, CC, CCR, Reg0, InFlag };
2429 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 6);
2430 }
2431
2432 SDValue CPTmp0;
2433 SDValue CPTmp1;
2434 SDValue CPTmp2;
2435 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
2436 unsigned Opc;
2437 switch (N->getOpcode()) {
2438 default: llvm_unreachable("Unexpected node");
2439 case ARMISD::CAND: Opc = ARM::ANDCCrsi; break;
2440 case ARMISD::COR: Opc = ARM::ORRCCrsi; break;
2441 case ARMISD::CXOR: Opc = ARM::EORCCrsi; break;
2442 }
2443 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, Reg0, InFlag };
2444 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 7);
2445 }
2446
2447 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2448 unsigned Opc;
2449 switch (N->getOpcode()) {
2450 default: llvm_unreachable("Unexpected node");
2451 case ARMISD::CAND: Opc = ARM::ANDCCrsr; break;
2452 case ARMISD::COR: Opc = ARM::ORRCCrsr; break;
2453 case ARMISD::CXOR: Opc = ARM::EORCCrsr; break;
2454 }
2455 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, Reg0, InFlag };
2456 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 8);
2457 }
2458
2459 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2460 if (T) {
2461 unsigned TrueImm = T->getZExtValue();
2462 if (is_so_imm(TrueImm)) {
2463 unsigned Opc;
2464 switch (N->getOpcode()) {
2465 default: llvm_unreachable("Unexpected node");
2466 case ARMISD::CAND: Opc = ARM::ANDCCri; break;
2467 case ARMISD::COR: Opc = ARM::ORRCCri; break;
2468 case ARMISD::CXOR: Opc = ARM::EORCCri; break;
2469 }
2470 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
2471 SDValue Ops[] = { FalseVal, True, CC, CCR, Reg0, InFlag };
2472 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 6);
2473 }
2474 }
2475
2476 unsigned Opc;
2477 switch (N->getOpcode()) {
2478 default: llvm_unreachable("Unexpected node");
2479 case ARMISD::CAND: Opc = ARM::ANDCCrr; break;
2480 case ARMISD::COR: Opc = ARM::ORRCCrr; break;
2481 case ARMISD::CXOR: Opc = ARM::EORCCrr; break;
2482 }
2483 SDValue Ops[] = { FalseVal, TrueVal, CC, CCR, Reg0, InFlag };
2484 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 6);
2485}
2486
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002487/// Target-specific DAG combining for ISD::XOR.
2488/// Target-independent combining lowers SELECT_CC nodes of the form
2489/// select_cc setg[ge] X, 0, X, -X
2490/// select_cc setgt X, -1, X, -X
2491/// select_cc setl[te] X, 0, -X, X
2492/// select_cc setlt X, 1, -X, X
2493/// which represent Integer ABS into:
2494/// Y = sra (X, size(X)-1); xor (add (X, Y), Y)
2495/// ARM instruction selection detects the latter and matches it to
2496/// ARM::ABS or ARM::t2ABS machine node.
2497SDNode *ARMDAGToDAGISel::SelectABSOp(SDNode *N){
2498 SDValue XORSrc0 = N->getOperand(0);
2499 SDValue XORSrc1 = N->getOperand(1);
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002500 EVT VT = N->getValueType(0);
2501
2502 if (DisableARMIntABS)
2503 return NULL;
2504
2505 if (Subtarget->isThumb1Only())
2506 return NULL;
2507
2508 if (XORSrc0.getOpcode() != ISD::ADD ||
2509 XORSrc1.getOpcode() != ISD::SRA)
2510 return NULL;
2511
2512 SDValue ADDSrc0 = XORSrc0.getOperand(0);
2513 SDValue ADDSrc1 = XORSrc0.getOperand(1);
2514 SDValue SRASrc0 = XORSrc1.getOperand(0);
2515 SDValue SRASrc1 = XORSrc1.getOperand(1);
2516 ConstantSDNode *SRAConstant = dyn_cast<ConstantSDNode>(SRASrc1);
2517 EVT XType = SRASrc0.getValueType();
2518 unsigned Size = XType.getSizeInBits() - 1;
2519
2520 if (ADDSrc1 == XORSrc1 &&
2521 ADDSrc0 == SRASrc0 &&
2522 XType.isInteger() &&
2523 SRAConstant != NULL &&
2524 Size == SRAConstant->getZExtValue()) {
2525
2526 unsigned Opcode = ARM::ABS;
2527 if (Subtarget->isThumb2())
2528 Opcode = ARM::t2ABS;
2529
2530 return CurDAG->SelectNodeTo(N, Opcode, VT, ADDSrc0);
2531 }
2532
2533 return NULL;
2534}
2535
Evan Chengde8aa4e2010-05-05 18:28:36 +00002536SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2537 // The only time a CONCAT_VECTORS operation can have legal types is when
2538 // two 64-bit vectors are concatenated to a 128-bit vector.
2539 EVT VT = N->getValueType(0);
2540 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2541 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002542 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002543}
2544
Eli Friedman2bdffe42011-08-31 00:31:29 +00002545SDNode *ARMDAGToDAGISel::SelectAtomic64(SDNode *Node, unsigned Opc) {
Eli Friedman4d3f3292011-08-31 17:52:22 +00002546 SmallVector<SDValue, 6> Ops;
2547 Ops.push_back(Node->getOperand(1)); // Ptr
2548 Ops.push_back(Node->getOperand(2)); // Low part of Val1
2549 Ops.push_back(Node->getOperand(3)); // High part of Val1
Owen Andersond84192f2011-08-31 20:00:11 +00002550 if (Opc == ARM::ATOMCMPXCHG6432) {
Eli Friedman4d3f3292011-08-31 17:52:22 +00002551 Ops.push_back(Node->getOperand(4)); // Low part of Val2
2552 Ops.push_back(Node->getOperand(5)); // High part of Val2
2553 }
2554 Ops.push_back(Node->getOperand(0)); // Chain
Eli Friedman2bdffe42011-08-31 00:31:29 +00002555 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2556 MemOp[0] = cast<MemSDNode>(Node)->getMemOperand();
Eli Friedman2bdffe42011-08-31 00:31:29 +00002557 SDNode *ResNode = CurDAG->getMachineNode(Opc, Node->getDebugLoc(),
Eli Friedman4d3f3292011-08-31 17:52:22 +00002558 MVT::i32, MVT::i32, MVT::Other,
2559 Ops.data() ,Ops.size());
Eli Friedman2bdffe42011-08-31 00:31:29 +00002560 cast<MachineSDNode>(ResNode)->setMemRefs(MemOp, MemOp + 1);
2561 return ResNode;
2562}
2563
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002564SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002565 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002566
Dan Gohmane8be6c62008-07-17 19:10:17 +00002567 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002568 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002569
2570 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002571 default: break;
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002572 case ISD::XOR: {
2573 // Select special operations if XOR node forms integer ABS pattern
2574 SDNode *ResNode = SelectABSOp(N);
2575 if (ResNode)
2576 return ResNode;
2577 // Other cases are autogenerated.
2578 break;
2579 }
Evan Chenga8e29892007-01-19 07:51:42 +00002580 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002581 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002582 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002583 if (Subtarget->hasThumb2())
2584 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2585 // be done with MOV + MOVT, at worst.
2586 UseCP = 0;
2587 else {
2588 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002589 UseCP = (Val > 255 && // MOV
2590 ~Val > 255 && // MOV + MVN
2591 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002592 } else
2593 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2594 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2595 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2596 }
2597
Evan Chenga8e29892007-01-19 07:51:42 +00002598 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002599 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002600 CurDAG->getTargetConstantPool(ConstantInt::get(
2601 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002602 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002603
2604 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002605 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002606 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002607 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002608 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002609 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002610 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002611 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002612 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002613 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002614 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002615 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002616 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002617 CurDAG->getEntryNode()
2618 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002619 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002620 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002621 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002622 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002623 return NULL;
2624 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002625
Evan Chenga8e29892007-01-19 07:51:42 +00002626 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002627 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002628 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002629 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002630 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002631 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002632 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002633 if (Subtarget->isThumb1Only()) {
Jim Grosbach5b815842011-08-24 17:46:13 +00002634 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2635 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2636 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002637 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002638 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2639 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002640 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2641 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2642 CurDAG->getRegister(0, MVT::i32) };
2643 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002644 }
Evan Chenga8e29892007-01-19 07:51:42 +00002645 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002646 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002647 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002648 return I;
2649 break;
2650 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002651 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002652 return I;
2653 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002654 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002655 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002656 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002657 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002658 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002659 if (!RHSV) break;
2660 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002661 unsigned ShImm = Log2_32(RHSV-1);
2662 if (ShImm >= 32)
2663 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002664 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002665 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002666 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2667 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002668 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002669 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002670 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002671 } else {
2672 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002673 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002674 }
Evan Chenga8e29892007-01-19 07:51:42 +00002675 }
2676 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002677 unsigned ShImm = Log2_32(RHSV+1);
2678 if (ShImm >= 32)
2679 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002680 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002681 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002682 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2683 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002684 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002685 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2686 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002687 } else {
2688 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002689 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002690 }
Evan Chenga8e29892007-01-19 07:51:42 +00002691 }
2692 }
2693 break;
Evan Cheng20956592009-10-21 08:15:52 +00002694 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002695 // Check for unsigned bitfield extract
2696 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2697 return I;
2698
Evan Cheng20956592009-10-21 08:15:52 +00002699 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2700 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2701 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2702 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2703 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002704 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002705 if (VT != MVT::i32)
2706 break;
2707 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2708 ? ARM::t2MOVTi16
2709 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2710 if (!Opc)
2711 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002712 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002713 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2714 if (!N1C)
2715 break;
2716 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2717 SDValue N2 = N0.getOperand(1);
2718 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2719 if (!N2C)
2720 break;
2721 unsigned N1CVal = N1C->getZExtValue();
2722 unsigned N2CVal = N2C->getZExtValue();
2723 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2724 (N1CVal & 0xffffU) == 0xffffU &&
2725 (N2CVal & 0xffffU) == 0x0U) {
2726 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2727 MVT::i32);
2728 SDValue Ops[] = { N0.getOperand(0), Imm16,
2729 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2730 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2731 }
2732 }
2733 break;
2734 }
Jim Grosbache5165492009-11-09 00:11:35 +00002735 case ARMISD::VMOVRRD:
2736 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002737 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002738 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002739 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002740 if (Subtarget->isThumb1Only())
2741 break;
2742 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002743 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002744 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2745 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002746 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002747 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002748 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002749 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2750 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002751 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2752 ARM::UMULL : ARM::UMULLv5,
2753 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002754 }
Evan Chengee568cf2007-07-05 07:15:27 +00002755 }
Dan Gohman525178c2007-10-08 18:33:35 +00002756 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002757 if (Subtarget->isThumb1Only())
2758 break;
2759 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002760 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002761 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002762 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002763 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002764 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002765 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2766 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002767 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2768 ARM::SMULL : ARM::SMULLv5,
2769 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002770 }
Evan Chengee568cf2007-07-05 07:15:27 +00002771 }
Evan Chenga8e29892007-01-19 07:51:42 +00002772 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002773 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002774 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002775 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002776 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002777 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002778 if (ResNode)
2779 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002780 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002781 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002782 }
Evan Chengee568cf2007-07-05 07:15:27 +00002783 case ARMISD::BRCOND: {
2784 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2785 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2786 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002787
Evan Chengee568cf2007-07-05 07:15:27 +00002788 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2789 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2790 // Pattern complexity = 6 cost = 1 size = 0
2791
David Goodwin5e47a9a2009-06-30 18:04:13 +00002792 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2793 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2794 // Pattern complexity = 6 cost = 1 size = 0
2795
Jim Grosbach764ab522009-08-11 15:33:49 +00002796 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002797 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002798 SDValue Chain = N->getOperand(0);
2799 SDValue N1 = N->getOperand(1);
2800 SDValue N2 = N->getOperand(2);
2801 SDValue N3 = N->getOperand(3);
2802 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002803 assert(N1.getOpcode() == ISD::BasicBlock);
2804 assert(N2.getOpcode() == ISD::Constant);
2805 assert(N3.getOpcode() == ISD::Register);
2806
Dan Gohman475871a2008-07-27 21:46:04 +00002807 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002808 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002809 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002810 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002811 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002812 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002813 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002814 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002815 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002816 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002817 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002818 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002819 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002820 return NULL;
2821 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002822 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002823 return SelectCMOVOp(N);
Evan Chengc892aeb2012-02-23 01:19:06 +00002824 case ARMISD::CAND:
2825 case ARMISD::COR:
2826 case ARMISD::CXOR:
2827 return SelectConditionalOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002828 case ARMISD::VZIP: {
2829 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002830 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002831 switch (VT.getSimpleVT().SimpleTy) {
2832 default: return NULL;
2833 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2834 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2835 case MVT::v2f32:
2836 case MVT::v2i32: Opc = ARM::VZIPd32; break;
2837 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2838 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2839 case MVT::v4f32:
2840 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2841 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002842 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002843 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2844 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2845 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002846 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002847 case ARMISD::VUZP: {
2848 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002849 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002850 switch (VT.getSimpleVT().SimpleTy) {
2851 default: return NULL;
2852 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2853 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2854 case MVT::v2f32:
2855 case MVT::v2i32: Opc = ARM::VUZPd32; break;
2856 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2857 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2858 case MVT::v4f32:
2859 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2860 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002861 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002862 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2863 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2864 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002865 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002866 case ARMISD::VTRN: {
2867 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002868 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002869 switch (VT.getSimpleVT().SimpleTy) {
2870 default: return NULL;
2871 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2872 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2873 case MVT::v2f32:
2874 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2875 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2876 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2877 case MVT::v4f32:
2878 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2879 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002880 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002881 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2882 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2883 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002884 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002885 case ARMISD::BUILD_VECTOR: {
2886 EVT VecVT = N->getValueType(0);
2887 EVT EltVT = VecVT.getVectorElementType();
2888 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002889 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002890 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2891 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2892 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002893 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002894 if (NumElts == 2)
2895 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2896 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2897 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2898 N->getOperand(2), N->getOperand(3));
2899 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002900
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002901 case ARMISD::VLD2DUP: {
2902 unsigned Opcodes[] = { ARM::VLD2DUPd8Pseudo, ARM::VLD2DUPd16Pseudo,
2903 ARM::VLD2DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002904 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002905 }
2906
Bob Wilson86c6d802010-11-29 19:35:29 +00002907 case ARMISD::VLD3DUP: {
2908 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo, ARM::VLD3DUPd16Pseudo,
2909 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002910 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002911 }
2912
Bob Wilson6c4c9822010-11-30 00:00:35 +00002913 case ARMISD::VLD4DUP: {
2914 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo, ARM::VLD4DUPd16Pseudo,
2915 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002916 return SelectVLDDup(N, false, 4, Opcodes);
2917 }
2918
2919 case ARMISD::VLD2DUP_UPD: {
Jim Grosbache6949b12011-12-21 19:40:55 +00002920 unsigned Opcodes[] = { ARM::VLD2DUPd8PseudoWB_fixed,
2921 ARM::VLD2DUPd16PseudoWB_fixed,
2922 ARM::VLD2DUPd32PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002923 return SelectVLDDup(N, true, 2, Opcodes);
2924 }
2925
2926 case ARMISD::VLD3DUP_UPD: {
2927 unsigned Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD, ARM::VLD3DUPd16Pseudo_UPD,
2928 ARM::VLD3DUPd32Pseudo_UPD };
2929 return SelectVLDDup(N, true, 3, Opcodes);
2930 }
2931
2932 case ARMISD::VLD4DUP_UPD: {
2933 unsigned Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD, ARM::VLD4DUPd16Pseudo_UPD,
2934 ARM::VLD4DUPd32Pseudo_UPD };
2935 return SelectVLDDup(N, true, 4, Opcodes);
2936 }
2937
2938 case ARMISD::VLD1_UPD: {
Jim Grosbach10b90a92011-10-24 21:45:13 +00002939 unsigned DOpcodes[] = { ARM::VLD1d8wb_fixed, ARM::VLD1d16wb_fixed,
2940 ARM::VLD1d32wb_fixed, ARM::VLD1d64wb_fixed };
2941 unsigned QOpcodes[] = { ARM::VLD1q8PseudoWB_fixed,
2942 ARM::VLD1q16PseudoWB_fixed,
2943 ARM::VLD1q32PseudoWB_fixed,
2944 ARM::VLD1q64PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002945 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2946 }
2947
2948 case ARMISD::VLD2_UPD: {
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00002949 unsigned DOpcodes[] = { ARM::VLD2d8PseudoWB_fixed,
2950 ARM::VLD2d16PseudoWB_fixed,
2951 ARM::VLD2d32PseudoWB_fixed,
2952 ARM::VLD1q64PseudoWB_fixed};
2953 unsigned QOpcodes[] = { ARM::VLD2q8PseudoWB_fixed,
2954 ARM::VLD2q16PseudoWB_fixed,
2955 ARM::VLD2q32PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002956 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2957 }
2958
2959 case ARMISD::VLD3_UPD: {
2960 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo_UPD, ARM::VLD3d16Pseudo_UPD,
Jim Grosbach10b90a92011-10-24 21:45:13 +00002961 ARM::VLD3d32Pseudo_UPD, ARM::VLD1q64PseudoWB_fixed};
Bob Wilson1c3ef902011-02-07 17:43:21 +00002962 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2963 ARM::VLD3q16Pseudo_UPD,
2964 ARM::VLD3q32Pseudo_UPD };
2965 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2966 ARM::VLD3q16oddPseudo_UPD,
2967 ARM::VLD3q32oddPseudo_UPD };
2968 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2969 }
2970
2971 case ARMISD::VLD4_UPD: {
2972 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo_UPD, ARM::VLD4d16Pseudo_UPD,
Jim Grosbach10b90a92011-10-24 21:45:13 +00002973 ARM::VLD4d32Pseudo_UPD, ARM::VLD1q64PseudoWB_fixed};
Bob Wilson1c3ef902011-02-07 17:43:21 +00002974 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2975 ARM::VLD4q16Pseudo_UPD,
2976 ARM::VLD4q32Pseudo_UPD };
2977 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2978 ARM::VLD4q16oddPseudo_UPD,
2979 ARM::VLD4q32oddPseudo_UPD };
2980 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2981 }
2982
2983 case ARMISD::VLD2LN_UPD: {
2984 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD, ARM::VLD2LNd16Pseudo_UPD,
2985 ARM::VLD2LNd32Pseudo_UPD };
2986 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2987 ARM::VLD2LNq32Pseudo_UPD };
2988 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2989 }
2990
2991 case ARMISD::VLD3LN_UPD: {
2992 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD, ARM::VLD3LNd16Pseudo_UPD,
2993 ARM::VLD3LNd32Pseudo_UPD };
2994 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
2995 ARM::VLD3LNq32Pseudo_UPD };
2996 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
2997 }
2998
2999 case ARMISD::VLD4LN_UPD: {
3000 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD, ARM::VLD4LNd16Pseudo_UPD,
3001 ARM::VLD4LNd32Pseudo_UPD };
3002 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
3003 ARM::VLD4LNq32Pseudo_UPD };
3004 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
3005 }
3006
3007 case ARMISD::VST1_UPD: {
Jim Grosbach4334e032011-10-31 21:50:31 +00003008 unsigned DOpcodes[] = { ARM::VST1d8wb_fixed, ARM::VST1d16wb_fixed,
3009 ARM::VST1d32wb_fixed, ARM::VST1d64wb_fixed };
3010 unsigned QOpcodes[] = { ARM::VST1q8PseudoWB_fixed,
3011 ARM::VST1q16PseudoWB_fixed,
3012 ARM::VST1q32PseudoWB_fixed,
3013 ARM::VST1q64PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003014 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
3015 }
3016
3017 case ARMISD::VST2_UPD: {
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00003018 unsigned DOpcodes[] = { ARM::VST2d8PseudoWB_fixed,
3019 ARM::VST2d16PseudoWB_fixed,
3020 ARM::VST2d32PseudoWB_fixed,
3021 ARM::VST1q64PseudoWB_fixed};
3022 unsigned QOpcodes[] = { ARM::VST2q8PseudoWB_fixed,
3023 ARM::VST2q16PseudoWB_fixed,
3024 ARM::VST2q32PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003025 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
3026 }
3027
3028 case ARMISD::VST3_UPD: {
3029 unsigned DOpcodes[] = { ARM::VST3d8Pseudo_UPD, ARM::VST3d16Pseudo_UPD,
Jim Grosbachd5ca2012011-11-29 22:38:04 +00003030 ARM::VST3d32Pseudo_UPD,ARM::VST1d64TPseudoWB_fixed};
Bob Wilson1c3ef902011-02-07 17:43:21 +00003031 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3032 ARM::VST3q16Pseudo_UPD,
3033 ARM::VST3q32Pseudo_UPD };
3034 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
3035 ARM::VST3q16oddPseudo_UPD,
3036 ARM::VST3q32oddPseudo_UPD };
3037 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
3038 }
3039
3040 case ARMISD::VST4_UPD: {
3041 unsigned DOpcodes[] = { ARM::VST4d8Pseudo_UPD, ARM::VST4d16Pseudo_UPD,
Jim Grosbach4c7edb32011-11-29 22:58:48 +00003042 ARM::VST4d32Pseudo_UPD,ARM::VST1d64QPseudoWB_fixed};
Bob Wilson1c3ef902011-02-07 17:43:21 +00003043 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3044 ARM::VST4q16Pseudo_UPD,
3045 ARM::VST4q32Pseudo_UPD };
3046 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
3047 ARM::VST4q16oddPseudo_UPD,
3048 ARM::VST4q32oddPseudo_UPD };
3049 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
3050 }
3051
3052 case ARMISD::VST2LN_UPD: {
3053 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD, ARM::VST2LNd16Pseudo_UPD,
3054 ARM::VST2LNd32Pseudo_UPD };
3055 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
3056 ARM::VST2LNq32Pseudo_UPD };
3057 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
3058 }
3059
3060 case ARMISD::VST3LN_UPD: {
3061 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD, ARM::VST3LNd16Pseudo_UPD,
3062 ARM::VST3LNd32Pseudo_UPD };
3063 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
3064 ARM::VST3LNq32Pseudo_UPD };
3065 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
3066 }
3067
3068 case ARMISD::VST4LN_UPD: {
3069 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD, ARM::VST4LNd16Pseudo_UPD,
3070 ARM::VST4LNd32Pseudo_UPD };
3071 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
3072 ARM::VST4LNq32Pseudo_UPD };
3073 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00003074 }
3075
Bob Wilson31fb12f2009-08-26 17:39:53 +00003076 case ISD::INTRINSIC_VOID:
3077 case ISD::INTRINSIC_W_CHAIN: {
3078 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00003079 switch (IntNo) {
3080 default:
Bob Wilson429009b2010-05-06 16:05:26 +00003081 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00003082
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00003083 case Intrinsic::arm_ldrexd: {
3084 SDValue MemAddr = N->getOperand(2);
3085 DebugLoc dl = N->getDebugLoc();
3086 SDValue Chain = N->getOperand(0);
3087
3088 unsigned NewOpc = ARM::LDREXD;
3089 if (Subtarget->isThumb() && Subtarget->hasThumb2())
3090 NewOpc = ARM::t2LDREXD;
3091
3092 // arm_ldrexd returns a i64 value in {i32, i32}
3093 std::vector<EVT> ResTys;
3094 ResTys.push_back(MVT::i32);
3095 ResTys.push_back(MVT::i32);
3096 ResTys.push_back(MVT::Other);
3097
3098 // place arguments in the right order
3099 SmallVector<SDValue, 7> Ops;
3100 Ops.push_back(MemAddr);
3101 Ops.push_back(getAL(CurDAG));
3102 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3103 Ops.push_back(Chain);
3104 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
3105 Ops.size());
3106 // Transfer memoperands.
3107 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3108 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3109 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
3110
3111 // Until there's support for specifing explicit register constraints
3112 // like the use of even/odd register pair, hardcode ldrexd to always
3113 // use the pair [R0, R1] to hold the load result.
3114 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
3115 SDValue(Ld, 0), SDValue(0,0));
3116 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
3117 SDValue(Ld, 1), Chain.getValue(1));
3118
3119 // Remap uses.
3120 SDValue Glue = Chain.getValue(1);
3121 if (!SDValue(N, 0).use_empty()) {
3122 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3123 ARM::R0, MVT::i32, Glue);
3124 Glue = Result.getValue(2);
3125 ReplaceUses(SDValue(N, 0), Result);
3126 }
3127 if (!SDValue(N, 1).use_empty()) {
3128 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3129 ARM::R1, MVT::i32, Glue);
3130 Glue = Result.getValue(2);
3131 ReplaceUses(SDValue(N, 1), Result);
3132 }
3133
3134 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
3135 return NULL;
3136 }
3137
3138 case Intrinsic::arm_strexd: {
3139 DebugLoc dl = N->getDebugLoc();
3140 SDValue Chain = N->getOperand(0);
3141 SDValue Val0 = N->getOperand(2);
3142 SDValue Val1 = N->getOperand(3);
3143 SDValue MemAddr = N->getOperand(4);
3144
3145 // Until there's support for specifing explicit register constraints
3146 // like the use of even/odd register pair, hardcode strexd to always
3147 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
3148 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
3149 SDValue(0, 0));
3150 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
3151
3152 SDValue Glue = Chain.getValue(1);
3153 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3154 ARM::R2, MVT::i32, Glue);
3155 Glue = Val0.getValue(1);
3156 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3157 ARM::R3, MVT::i32, Glue);
3158
3159 // Store exclusive double return a i32 value which is the return status
3160 // of the issued store.
3161 std::vector<EVT> ResTys;
3162 ResTys.push_back(MVT::i32);
3163 ResTys.push_back(MVT::Other);
3164
3165 // place arguments in the right order
3166 SmallVector<SDValue, 7> Ops;
3167 Ops.push_back(Val0);
3168 Ops.push_back(Val1);
3169 Ops.push_back(MemAddr);
3170 Ops.push_back(getAL(CurDAG));
3171 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3172 Ops.push_back(Chain);
3173
3174 unsigned NewOpc = ARM::STREXD;
3175 if (Subtarget->isThumb() && Subtarget->hasThumb2())
3176 NewOpc = ARM::t2STREXD;
3177
3178 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
3179 Ops.size());
3180 // Transfer memoperands.
3181 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3182 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3183 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
3184
3185 return St;
3186 }
3187
Bob Wilson621f1952010-03-23 05:25:43 +00003188 case Intrinsic::arm_neon_vld1: {
3189 unsigned DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
3190 ARM::VLD1d32, ARM::VLD1d64 };
Bob Wilsonffde0802010-09-02 16:00:54 +00003191 unsigned QOpcodes[] = { ARM::VLD1q8Pseudo, ARM::VLD1q16Pseudo,
3192 ARM::VLD1q32Pseudo, ARM::VLD1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003193 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00003194 }
3195
Bob Wilson31fb12f2009-08-26 17:39:53 +00003196 case Intrinsic::arm_neon_vld2: {
Bob Wilsonffde0802010-09-02 16:00:54 +00003197 unsigned DOpcodes[] = { ARM::VLD2d8Pseudo, ARM::VLD2d16Pseudo,
3198 ARM::VLD2d32Pseudo, ARM::VLD1q64Pseudo };
3199 unsigned QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
3200 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003201 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003202 }
3203
3204 case Intrinsic::arm_neon_vld3: {
Bob Wilsonf5721912010-09-03 18:16:02 +00003205 unsigned DOpcodes[] = { ARM::VLD3d8Pseudo, ARM::VLD3d16Pseudo,
3206 ARM::VLD3d32Pseudo, ARM::VLD1d64TPseudo };
3207 unsigned QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
3208 ARM::VLD3q16Pseudo_UPD,
3209 ARM::VLD3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00003210 unsigned QOpcodes1[] = { ARM::VLD3q8oddPseudo,
3211 ARM::VLD3q16oddPseudo,
3212 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003213 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003214 }
3215
3216 case Intrinsic::arm_neon_vld4: {
Bob Wilsonf5721912010-09-03 18:16:02 +00003217 unsigned DOpcodes[] = { ARM::VLD4d8Pseudo, ARM::VLD4d16Pseudo,
3218 ARM::VLD4d32Pseudo, ARM::VLD1d64QPseudo };
3219 unsigned QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
3220 ARM::VLD4q16Pseudo_UPD,
3221 ARM::VLD4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00003222 unsigned QOpcodes1[] = { ARM::VLD4q8oddPseudo,
3223 ARM::VLD4q16oddPseudo,
3224 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003225 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003226 }
3227
Bob Wilson243fcc52009-09-01 04:26:28 +00003228 case Intrinsic::arm_neon_vld2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003229 unsigned DOpcodes[] = { ARM::VLD2LNd8Pseudo, ARM::VLD2LNd16Pseudo,
3230 ARM::VLD2LNd32Pseudo };
3231 unsigned QOpcodes[] = { ARM::VLD2LNq16Pseudo, ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003232 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003233 }
3234
3235 case Intrinsic::arm_neon_vld3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003236 unsigned DOpcodes[] = { ARM::VLD3LNd8Pseudo, ARM::VLD3LNd16Pseudo,
3237 ARM::VLD3LNd32Pseudo };
3238 unsigned QOpcodes[] = { ARM::VLD3LNq16Pseudo, ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003239 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003240 }
3241
3242 case Intrinsic::arm_neon_vld4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003243 unsigned DOpcodes[] = { ARM::VLD4LNd8Pseudo, ARM::VLD4LNd16Pseudo,
3244 ARM::VLD4LNd32Pseudo };
3245 unsigned QOpcodes[] = { ARM::VLD4LNq16Pseudo, ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003246 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003247 }
3248
Bob Wilson11d98992010-03-23 06:20:33 +00003249 case Intrinsic::arm_neon_vst1: {
3250 unsigned DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
3251 ARM::VST1d32, ARM::VST1d64 };
Bob Wilsone5ce4f62010-08-28 05:12:57 +00003252 unsigned QOpcodes[] = { ARM::VST1q8Pseudo, ARM::VST1q16Pseudo,
3253 ARM::VST1q32Pseudo, ARM::VST1q64Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003254 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00003255 }
3256
Bob Wilson31fb12f2009-08-26 17:39:53 +00003257 case Intrinsic::arm_neon_vst2: {
Bob Wilsone5ce4f62010-08-28 05:12:57 +00003258 unsigned DOpcodes[] = { ARM::VST2d8Pseudo, ARM::VST2d16Pseudo,
3259 ARM::VST2d32Pseudo, ARM::VST1q64Pseudo };
3260 unsigned QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3261 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003262 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003263 }
3264
3265 case Intrinsic::arm_neon_vst3: {
Bob Wilson01ba4612010-08-26 18:51:29 +00003266 unsigned DOpcodes[] = { ARM::VST3d8Pseudo, ARM::VST3d16Pseudo,
3267 ARM::VST3d32Pseudo, ARM::VST1d64TPseudo };
3268 unsigned QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3269 ARM::VST3q16Pseudo_UPD,
3270 ARM::VST3q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00003271 unsigned QOpcodes1[] = { ARM::VST3q8oddPseudo,
3272 ARM::VST3q16oddPseudo,
3273 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003274 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003275 }
3276
3277 case Intrinsic::arm_neon_vst4: {
Bob Wilson709d5922010-08-25 23:27:42 +00003278 unsigned DOpcodes[] = { ARM::VST4d8Pseudo, ARM::VST4d16Pseudo,
Bob Wilson70e48b22010-08-26 05:33:30 +00003279 ARM::VST4d32Pseudo, ARM::VST1d64QPseudo };
Bob Wilson709d5922010-08-25 23:27:42 +00003280 unsigned QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3281 ARM::VST4q16Pseudo_UPD,
3282 ARM::VST4q32Pseudo_UPD };
Bob Wilson7de68142011-02-07 17:43:15 +00003283 unsigned QOpcodes1[] = { ARM::VST4q8oddPseudo,
3284 ARM::VST4q16oddPseudo,
3285 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003286 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003287 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00003288
3289 case Intrinsic::arm_neon_vst2lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003290 unsigned DOpcodes[] = { ARM::VST2LNd8Pseudo, ARM::VST2LNd16Pseudo,
3291 ARM::VST2LNd32Pseudo };
3292 unsigned QOpcodes[] = { ARM::VST2LNq16Pseudo, ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003293 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003294 }
3295
3296 case Intrinsic::arm_neon_vst3lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003297 unsigned DOpcodes[] = { ARM::VST3LNd8Pseudo, ARM::VST3LNd16Pseudo,
3298 ARM::VST3LNd32Pseudo };
3299 unsigned QOpcodes[] = { ARM::VST3LNq16Pseudo, ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003300 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003301 }
3302
3303 case Intrinsic::arm_neon_vst4lane: {
Bob Wilson8466fa12010-09-13 23:01:35 +00003304 unsigned DOpcodes[] = { ARM::VST4LNd8Pseudo, ARM::VST4LNd16Pseudo,
3305 ARM::VST4LNd32Pseudo };
3306 unsigned QOpcodes[] = { ARM::VST4LNq16Pseudo, ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003307 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003308 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00003309 }
Bob Wilson429009b2010-05-06 16:05:26 +00003310 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00003311 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00003312
Bob Wilsond491d6e2010-07-06 23:36:25 +00003313 case ISD::INTRINSIC_WO_CHAIN: {
3314 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3315 switch (IntNo) {
3316 default:
3317 break;
3318
3319 case Intrinsic::arm_neon_vtbl2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003320 return SelectVTBL(N, false, 2, ARM::VTBL2Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003321 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003322 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003323 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003324 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003325
3326 case Intrinsic::arm_neon_vtbx2:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003327 return SelectVTBL(N, true, 2, ARM::VTBX2Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003328 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003329 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003330 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003331 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003332 }
3333 break;
3334 }
3335
Bill Wendling69a05a72011-03-14 23:02:38 +00003336 case ARMISD::VTBL1: {
3337 DebugLoc dl = N->getDebugLoc();
3338 EVT VT = N->getValueType(0);
3339 SmallVector<SDValue, 6> Ops;
3340
3341 Ops.push_back(N->getOperand(0));
3342 Ops.push_back(N->getOperand(1));
3343 Ops.push_back(getAL(CurDAG)); // Predicate
3344 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3345 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
3346 }
3347 case ARMISD::VTBL2: {
3348 DebugLoc dl = N->getDebugLoc();
3349 EVT VT = N->getValueType(0);
3350
3351 // Form a REG_SEQUENCE to force register allocation.
3352 SDValue V0 = N->getOperand(0);
3353 SDValue V1 = N->getOperand(1);
3354 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
3355
3356 SmallVector<SDValue, 6> Ops;
3357 Ops.push_back(RegSeq);
3358 Ops.push_back(N->getOperand(2));
3359 Ops.push_back(getAL(CurDAG)); // Predicate
3360 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3361 return CurDAG->getMachineNode(ARM::VTBL2Pseudo, dl, VT,
3362 Ops.data(), Ops.size());
3363 }
3364
Bob Wilson429009b2010-05-06 16:05:26 +00003365 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00003366 return SelectConcatVector(N);
Eli Friedman2bdffe42011-08-31 00:31:29 +00003367
3368 case ARMISD::ATOMOR64_DAG:
3369 return SelectAtomic64(N, ARM::ATOMOR6432);
3370 case ARMISD::ATOMXOR64_DAG:
3371 return SelectAtomic64(N, ARM::ATOMXOR6432);
3372 case ARMISD::ATOMADD64_DAG:
3373 return SelectAtomic64(N, ARM::ATOMADD6432);
3374 case ARMISD::ATOMSUB64_DAG:
3375 return SelectAtomic64(N, ARM::ATOMSUB6432);
3376 case ARMISD::ATOMNAND64_DAG:
3377 return SelectAtomic64(N, ARM::ATOMNAND6432);
3378 case ARMISD::ATOMAND64_DAG:
3379 return SelectAtomic64(N, ARM::ATOMAND6432);
3380 case ARMISD::ATOMSWAP64_DAG:
3381 return SelectAtomic64(N, ARM::ATOMSWAP6432);
Eli Friedman4d3f3292011-08-31 17:52:22 +00003382 case ARMISD::ATOMCMPXCHG64_DAG:
3383 return SelectAtomic64(N, ARM::ATOMCMPXCHG6432);
Evan Chengde8aa4e2010-05-05 18:28:36 +00003384 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00003385
Dan Gohmaneeb3a002010-01-05 01:24:18 +00003386 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00003387}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003388
Bob Wilson224c2442009-05-19 05:53:42 +00003389bool ARMDAGToDAGISel::
3390SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3391 std::vector<SDValue> &OutOps) {
3392 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00003393 // Require the address to be in a register. That is safe for all ARM
3394 // variants and it is hard to do anything much smarter without knowing
3395 // how the operand is used.
3396 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003397 return false;
3398}
3399
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003400/// createARMISelDag - This pass converts a legalized DAG into a
3401/// ARM-specific DAG, ready for instruction scheduling.
3402///
Bob Wilson522ce972009-09-28 14:30:20 +00003403FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3404 CodeGenOpt::Level OptLevel) {
3405 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003406}