blob: 1953192a0ce5f8bd03eb0252ccd639f1db0448ce [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,
Craig Topper51f50c12012-05-24 05:17:00 +0000213 const uint16_t *DOpcodes,
214 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilson3e36f132009-10-14 17:28:52 +0000215
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,
Craig Topper51f50c12012-05-24 05:17:00 +0000221 const uint16_t *DOpcodes,
222 const uint16_t *QOpcodes0, const uint16_t *QOpcodes1);
Bob Wilson24f995d2009-10-14 18:32:29 +0000223
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,
Craig Topper51f50c12012-05-24 05:17:00 +0000229 const uint16_t *DOpcodes, const uint16_t *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,
Craig Topper51f50c12012-05-24 05:17:00 +0000235 const uint16_t *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
Jim Grosbach3e556122010-10-26 22:37:02 +0000586//-----
587
Jim Grosbach82891622010-09-29 19:03:54 +0000588AddrMode2Type ARMDAGToDAGISel::SelectAddrMode2Worker(SDValue N,
589 SDValue &Base,
590 SDValue &Offset,
591 SDValue &Opc) {
Evan Chengf40deed2010-10-27 23:41:30 +0000592 if (N.getOpcode() == ISD::MUL &&
593 (!Subtarget->isCortexA9() || N.hasOneUse())) {
Evan Chenga13fd102007-03-13 21:05:54 +0000594 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
595 // X * [3,5,9] -> X + X * [2,4,8] etc.
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000596 int RHSC = (int)RHS->getZExtValue();
Evan Chenga13fd102007-03-13 21:05:54 +0000597 if (RHSC & 1) {
598 RHSC = RHSC & ~1;
599 ARM_AM::AddrOpc AddSub = ARM_AM::add;
600 if (RHSC < 0) {
601 AddSub = ARM_AM::sub;
602 RHSC = - RHSC;
603 }
604 if (isPowerOf2_32(RHSC)) {
605 unsigned ShAmt = Log2_32(RHSC);
606 Base = Offset = N.getOperand(0);
607 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt,
608 ARM_AM::lsl),
Owen Anderson825b72b2009-08-11 20:47:22 +0000609 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000610 return AM2_SHOP;
Evan Chenga13fd102007-03-13 21:05:54 +0000611 }
612 }
613 }
614 }
615
Chris Lattner0a9481f2011-02-13 22:25:43 +0000616 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
617 // ISD::OR that is equivalent to an ADD.
618 !CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000619 Base = N;
620 if (N.getOpcode() == ISD::FrameIndex) {
621 int FI = cast<FrameIndexSDNode>(N)->getIndex();
622 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000623 } else if (N.getOpcode() == ARMISD::Wrapper &&
624 !(Subtarget->useMovt() &&
625 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000626 Base = N.getOperand(0);
627 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000628 Offset = CurDAG->getRegister(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000629 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
630 ARM_AM::no_shift),
Owen Anderson825b72b2009-08-11 20:47:22 +0000631 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000632 return AM2_BASE;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000633 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000634
Evan Chenga8e29892007-01-19 07:51:42 +0000635 // Match simple R +/- imm12 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000636 if (N.getOpcode() != ISD::SUB) {
Daniel Dunbarec91d522011-01-19 15:12:16 +0000637 int RHSC;
638 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
639 -0x1000+1, 0x1000, RHSC)) { // 12 bits.
640 Base = N.getOperand(0);
641 if (Base.getOpcode() == ISD::FrameIndex) {
642 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
643 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000644 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000645 Offset = CurDAG->getRegister(0, MVT::i32);
646
647 ARM_AM::AddrOpc AddSub = ARM_AM::add;
648 if (RHSC < 0) {
649 AddSub = ARM_AM::sub;
650 RHSC = - RHSC;
651 }
652 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, RHSC,
653 ARM_AM::no_shift),
654 MVT::i32);
655 return AM2_BASE;
Evan Chenga8e29892007-01-19 07:51:42 +0000656 }
Jim Grosbachbe912322010-09-29 17:32:29 +0000657 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000658
Evan Chengf40deed2010-10-27 23:41:30 +0000659 if (Subtarget->isCortexA9() && !N.hasOneUse()) {
660 // Compute R +/- (R << N) and reuse it.
661 Base = N;
662 Offset = CurDAG->getRegister(0, MVT::i32);
663 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(ARM_AM::add, 0,
664 ARM_AM::no_shift),
665 MVT::i32);
666 return AM2_BASE;
667 }
668
Johnny Chen6a3b5ee2009-10-27 17:25:15 +0000669 // Otherwise this is R +/- [possibly shifted] R.
Chris Lattner0a9481f2011-02-13 22:25:43 +0000670 ARM_AM::AddrOpc AddSub = N.getOpcode() != ISD::SUB ? ARM_AM::add:ARM_AM::sub;
Evan Chengee04a6d2011-07-20 23:34:39 +0000671 ARM_AM::ShiftOpc ShOpcVal =
672 ARM_AM::getShiftOpcForNode(N.getOperand(1).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000673 unsigned ShAmt = 0;
Jim Grosbach764ab522009-08-11 15:33:49 +0000674
Evan Chenga8e29892007-01-19 07:51:42 +0000675 Base = N.getOperand(0);
676 Offset = N.getOperand(1);
Jim Grosbach764ab522009-08-11 15:33:49 +0000677
Evan Chenga8e29892007-01-19 07:51:42 +0000678 if (ShOpcVal != ARM_AM::no_shift) {
679 // Check to see if the RHS of the shift is a constant, if not, we can't fold
680 // it.
681 if (ConstantSDNode *Sh =
682 dyn_cast<ConstantSDNode>(N.getOperand(1).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000683 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000684 if (isShifterOpProfitable(Offset, ShOpcVal, ShAmt))
685 Offset = N.getOperand(1).getOperand(0);
686 else {
687 ShAmt = 0;
688 ShOpcVal = ARM_AM::no_shift;
689 }
Evan Chenga8e29892007-01-19 07:51:42 +0000690 } else {
691 ShOpcVal = ARM_AM::no_shift;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000692 }
693 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000694
Evan Chenga8e29892007-01-19 07:51:42 +0000695 // Try matching (R shl C) + (R).
Chris Lattner0a9481f2011-02-13 22:25:43 +0000696 if (N.getOpcode() != ISD::SUB && ShOpcVal == ARM_AM::no_shift &&
Evan Chengf40deed2010-10-27 23:41:30 +0000697 !(Subtarget->isCortexA9() || N.getOperand(0).hasOneUse())) {
Evan Chengee04a6d2011-07-20 23:34:39 +0000698 ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOperand(0).getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000699 if (ShOpcVal != ARM_AM::no_shift) {
700 // Check to see if the RHS of the shift is a constant, if not, we can't
701 // fold it.
702 if (ConstantSDNode *Sh =
703 dyn_cast<ConstantSDNode>(N.getOperand(0).getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000704 ShAmt = Sh->getZExtValue();
Cameron Zwarich8f8aa812011-10-05 23:39:02 +0000705 if (isShifterOpProfitable(N.getOperand(0), ShOpcVal, ShAmt)) {
Evan Chengf40deed2010-10-27 23:41:30 +0000706 Offset = N.getOperand(0).getOperand(0);
707 Base = N.getOperand(1);
708 } else {
709 ShAmt = 0;
710 ShOpcVal = ARM_AM::no_shift;
711 }
Evan Chenga8e29892007-01-19 07:51:42 +0000712 } else {
713 ShOpcVal = ARM_AM::no_shift;
714 }
715 }
716 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000717
Evan Chenga8e29892007-01-19 07:51:42 +0000718 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000719 MVT::i32);
Jim Grosbach82891622010-09-29 19:03:54 +0000720 return AM2_SHOP;
Rafael Espindola6e8c6492006-11-08 17:07:32 +0000721}
722
Owen Anderson793e7962011-07-26 20:54:26 +0000723bool ARMDAGToDAGISel::SelectAddrMode2OffsetReg(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000724 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000725 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000726 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
727 ? cast<LoadSDNode>(Op)->getAddressingMode()
728 : cast<StoreSDNode>(Op)->getAddressingMode();
729 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
730 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000731 int Val;
Owen Anderson793e7962011-07-26 20:54:26 +0000732 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val))
733 return false;
Evan Chenga8e29892007-01-19 07:51:42 +0000734
735 Offset = N;
Evan Chengee04a6d2011-07-20 23:34:39 +0000736 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Chenga8e29892007-01-19 07:51:42 +0000737 unsigned ShAmt = 0;
738 if (ShOpcVal != ARM_AM::no_shift) {
739 // Check to see if the RHS of the shift is a constant, if not, we can't fold
740 // it.
741 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +0000742 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +0000743 if (isShifterOpProfitable(N, ShOpcVal, ShAmt))
744 Offset = N.getOperand(0);
745 else {
746 ShAmt = 0;
747 ShOpcVal = ARM_AM::no_shift;
748 }
Evan Chenga8e29892007-01-19 07:51:42 +0000749 } else {
750 ShOpcVal = ARM_AM::no_shift;
751 }
752 }
753
754 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, ShAmt, ShOpcVal),
Owen Anderson825b72b2009-08-11 20:47:22 +0000755 MVT::i32);
Rafael Espindola32bd5f42006-10-17 18:04:53 +0000756 return true;
757}
758
Owen Andersonc4e16de2011-08-29 20:16:50 +0000759bool ARMDAGToDAGISel::SelectAddrMode2OffsetImmPre(SDNode *Op, SDValue N,
760 SDValue &Offset, SDValue &Opc) {
Owen Andersond84192f2011-08-31 20:00:11 +0000761 unsigned Opcode = Op->getOpcode();
762 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
763 ? cast<LoadSDNode>(Op)->getAddressingMode()
764 : cast<StoreSDNode>(Op)->getAddressingMode();
765 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
766 ? ARM_AM::add : ARM_AM::sub;
Owen Andersonc4e16de2011-08-29 20:16:50 +0000767 int Val;
768 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
Owen Andersond84192f2011-08-31 20:00:11 +0000769 if (AddSub == ARM_AM::sub) Val *= -1;
Owen Andersonc4e16de2011-08-29 20:16:50 +0000770 Offset = CurDAG->getRegister(0, MVT::i32);
771 Opc = CurDAG->getTargetConstant(Val, MVT::i32);
772 return true;
773 }
774
775 return false;
776}
777
778
Owen Anderson793e7962011-07-26 20:54:26 +0000779bool ARMDAGToDAGISel::SelectAddrMode2OffsetImm(SDNode *Op, SDValue N,
780 SDValue &Offset, SDValue &Opc) {
781 unsigned Opcode = Op->getOpcode();
782 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
783 ? cast<LoadSDNode>(Op)->getAddressingMode()
784 : cast<StoreSDNode>(Op)->getAddressingMode();
785 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
786 ? ARM_AM::add : ARM_AM::sub;
787 int Val;
788 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x1000, Val)) { // 12 bits.
789 Offset = CurDAG->getRegister(0, MVT::i32);
790 Opc = CurDAG->getTargetConstant(ARM_AM::getAM2Opc(AddSub, Val,
791 ARM_AM::no_shift),
792 MVT::i32);
793 return true;
794 }
795
796 return false;
797}
798
Jim Grosbach19dec202011-08-05 20:35:44 +0000799bool ARMDAGToDAGISel::SelectAddrOffsetNone(SDValue N, SDValue &Base) {
800 Base = N;
801 return true;
802}
Evan Chenga8e29892007-01-19 07:51:42 +0000803
Chris Lattner52a261b2010-09-21 20:31:19 +0000804bool ARMDAGToDAGISel::SelectAddrMode3(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000805 SDValue &Base, SDValue &Offset,
806 SDValue &Opc) {
Evan Chenga8e29892007-01-19 07:51:42 +0000807 if (N.getOpcode() == ISD::SUB) {
808 // X - C is canonicalize to X + -C, no need to handle it here.
809 Base = N.getOperand(0);
810 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000811 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::sub, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000812 return true;
813 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000814
Chris Lattner0a9481f2011-02-13 22:25:43 +0000815 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000816 Base = N;
817 if (N.getOpcode() == ISD::FrameIndex) {
818 int FI = cast<FrameIndexSDNode>(N)->getIndex();
819 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
820 }
Owen Anderson825b72b2009-08-11 20:47:22 +0000821 Offset = CurDAG->getRegister(0, MVT::i32);
822 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0),MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000823 return true;
824 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000825
Evan Chenga8e29892007-01-19 07:51:42 +0000826 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000827 int RHSC;
828 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/1,
829 -256 + 1, 256, RHSC)) { // 8 bits.
830 Base = N.getOperand(0);
831 if (Base.getOpcode() == ISD::FrameIndex) {
832 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
833 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000834 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000835 Offset = CurDAG->getRegister(0, MVT::i32);
836
837 ARM_AM::AddrOpc AddSub = ARM_AM::add;
838 if (RHSC < 0) {
839 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000840 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000841 }
842 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, RHSC),MVT::i32);
843 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000844 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000845
Evan Chenga8e29892007-01-19 07:51:42 +0000846 Base = N.getOperand(0);
847 Offset = N.getOperand(1);
Owen Anderson825b72b2009-08-11 20:47:22 +0000848 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(ARM_AM::add, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000849 return true;
850}
851
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000852bool ARMDAGToDAGISel::SelectAddrMode3Offset(SDNode *Op, SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000853 SDValue &Offset, SDValue &Opc) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000854 unsigned Opcode = Op->getOpcode();
Evan Chenga8e29892007-01-19 07:51:42 +0000855 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
856 ? cast<LoadSDNode>(Op)->getAddressingMode()
857 : cast<StoreSDNode>(Op)->getAddressingMode();
858 ARM_AM::AddrOpc AddSub = (AM == ISD::PRE_INC || AM == ISD::POST_INC)
859 ? ARM_AM::add : ARM_AM::sub;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000860 int Val;
861 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 256, Val)) { // 12 bits.
862 Offset = CurDAG->getRegister(0, MVT::i32);
863 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, Val), MVT::i32);
864 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000865 }
866
867 Offset = N;
Owen Anderson825b72b2009-08-11 20:47:22 +0000868 Opc = CurDAG->getTargetConstant(ARM_AM::getAM3Opc(AddSub, 0), MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000869 return true;
870}
871
Jim Grosbach3ab56582010-10-21 19:38:40 +0000872bool ARMDAGToDAGISel::SelectAddrMode5(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000873 SDValue &Base, SDValue &Offset) {
Chris Lattner0a9481f2011-02-13 22:25:43 +0000874 if (!CurDAG->isBaseWithConstantOffset(N)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000875 Base = N;
876 if (N.getOpcode() == ISD::FrameIndex) {
877 int FI = cast<FrameIndexSDNode>(N)->getIndex();
878 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +0000879 } else if (N.getOpcode() == ARMISD::Wrapper &&
880 !(Subtarget->useMovt() &&
881 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Chenga8e29892007-01-19 07:51:42 +0000882 Base = N.getOperand(0);
883 }
884 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000885 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000886 return true;
887 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000888
Evan Chenga8e29892007-01-19 07:51:42 +0000889 // If the RHS is +/- imm8, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +0000890 int RHSC;
891 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4,
892 -256 + 1, 256, RHSC)) {
893 Base = N.getOperand(0);
894 if (Base.getOpcode() == ISD::FrameIndex) {
895 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
896 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Chenga8e29892007-01-19 07:51:42 +0000897 }
Daniel Dunbarec91d522011-01-19 15:12:16 +0000898
899 ARM_AM::AddrOpc AddSub = ARM_AM::add;
900 if (RHSC < 0) {
901 AddSub = ARM_AM::sub;
Chris Lattner0a9481f2011-02-13 22:25:43 +0000902 RHSC = -RHSC;
Daniel Dunbarec91d522011-01-19 15:12:16 +0000903 }
904 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(AddSub, RHSC),
905 MVT::i32);
906 return true;
Evan Chenga8e29892007-01-19 07:51:42 +0000907 }
Jim Grosbach764ab522009-08-11 15:33:49 +0000908
Evan Chenga8e29892007-01-19 07:51:42 +0000909 Base = N;
910 Offset = CurDAG->getTargetConstant(ARM_AM::getAM5Opc(ARM_AM::add, 0),
Owen Anderson825b72b2009-08-11 20:47:22 +0000911 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000912 return true;
913}
914
Bob Wilson665814b2010-11-01 23:40:51 +0000915bool ARMDAGToDAGISel::SelectAddrMode6(SDNode *Parent, SDValue N, SDValue &Addr,
916 SDValue &Align) {
Bob Wilson8b024a52009-07-01 23:16:05 +0000917 Addr = N;
Bob Wilson665814b2010-11-01 23:40:51 +0000918
919 unsigned Alignment = 0;
920 if (LSBaseSDNode *LSN = dyn_cast<LSBaseSDNode>(Parent)) {
921 // This case occurs only for VLD1-lane/dup and VST1-lane instructions.
922 // The maximum alignment is equal to the memory size being referenced.
923 unsigned LSNAlign = LSN->getAlignment();
924 unsigned MemSize = LSN->getMemoryVT().getSizeInBits() / 8;
Jakob Stoklund Olesenb0117ee2011-10-27 22:39:16 +0000925 if (LSNAlign >= MemSize && MemSize > 1)
Bob Wilson665814b2010-11-01 23:40:51 +0000926 Alignment = MemSize;
927 } else {
928 // All other uses of addrmode6 are for intrinsics. For now just record
929 // the raw alignment value; it will be refined later based on the legal
930 // alignment operands for the intrinsic.
931 Alignment = cast<MemIntrinsicSDNode>(Parent)->getAlignment();
932 }
933
934 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson8b024a52009-07-01 23:16:05 +0000935 return true;
936}
937
Bob Wilsonda525062011-02-25 06:42:42 +0000938bool ARMDAGToDAGISel::SelectAddrMode6Offset(SDNode *Op, SDValue N,
939 SDValue &Offset) {
940 LSBaseSDNode *LdSt = cast<LSBaseSDNode>(Op);
941 ISD::MemIndexedMode AM = LdSt->getAddressingMode();
942 if (AM != ISD::POST_INC)
943 return false;
944 Offset = N;
945 if (ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N)) {
946 if (NC->getZExtValue() * 8 == LdSt->getMemoryVT().getSizeInBits())
947 Offset = CurDAG->getRegister(0, MVT::i32);
948 }
949 return true;
950}
951
Chris Lattner52a261b2010-09-21 20:31:19 +0000952bool ARMDAGToDAGISel::SelectAddrModePC(SDValue N,
Evan Chengbba9f5f2009-08-14 19:01:37 +0000953 SDValue &Offset, SDValue &Label) {
Evan Chenga8e29892007-01-19 07:51:42 +0000954 if (N.getOpcode() == ARMISD::PIC_ADD && N.hasOneUse()) {
955 Offset = N.getOperand(0);
Dan Gohman475871a2008-07-27 21:46:04 +0000956 SDValue N1 = N.getOperand(1);
Evan Cheng9fe20092011-01-20 08:34:58 +0000957 Label = CurDAG->getTargetConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
958 MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +0000959 return true;
960 }
Bill Wendlingf4caf692010-12-14 03:36:38 +0000961
Evan Chenga8e29892007-01-19 07:51:42 +0000962 return false;
963}
964
Bill Wendlingf4caf692010-12-14 03:36:38 +0000965
966//===----------------------------------------------------------------------===//
967// Thumb Addressing Modes
968//===----------------------------------------------------------------------===//
969
Chris Lattner52a261b2010-09-21 20:31:19 +0000970bool ARMDAGToDAGISel::SelectThumbAddrModeRR(SDValue N,
Dan Gohman475871a2008-07-27 21:46:04 +0000971 SDValue &Base, SDValue &Offset){
Chris Lattner0a9481f2011-02-13 22:25:43 +0000972 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N)) {
Evan Cheng2f297df2009-07-11 07:08:13 +0000973 ConstantSDNode *NC = dyn_cast<ConstantSDNode>(N);
Dan Gohmane368b462010-06-18 14:22:04 +0000974 if (!NC || !NC->isNullValue())
Evan Cheng2f297df2009-07-11 07:08:13 +0000975 return false;
976
977 Base = Offset = N;
Evan Chengc38f2bc2007-01-23 22:59:13 +0000978 return true;
979 }
980
Evan Chenga8e29892007-01-19 07:51:42 +0000981 Base = N.getOperand(0);
982 Offset = N.getOperand(1);
983 return true;
984}
985
Evan Cheng79d43262007-01-24 02:21:22 +0000986bool
Bill Wendlingf4caf692010-12-14 03:36:38 +0000987ARMDAGToDAGISel::SelectThumbAddrModeRI(SDValue N, SDValue &Base,
988 SDValue &Offset, unsigned Scale) {
Evan Cheng79d43262007-01-24 02:21:22 +0000989 if (Scale == 4) {
Dan Gohman475871a2008-07-27 21:46:04 +0000990 SDValue TmpBase, TmpOffImm;
Chris Lattner52a261b2010-09-21 20:31:19 +0000991 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
Evan Cheng79d43262007-01-24 02:21:22 +0000992 return false; // We want to select tLDRspi / tSTRspi instead.
Bill Wendlingf4caf692010-12-14 03:36:38 +0000993
Evan Cheng012f2d92007-01-24 08:53:17 +0000994 if (N.getOpcode() == ARMISD::Wrapper &&
995 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
996 return false; // We want to select tLDRpci instead.
Evan Cheng79d43262007-01-24 02:21:22 +0000997 }
998
Chris Lattner0a9481f2011-02-13 22:25:43 +0000999 if (!CurDAG->isBaseWithConstantOffset(N))
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001000 return false;
Evan Chenga8e29892007-01-19 07:51:42 +00001001
Evan Chengad0e4652007-02-06 00:22:06 +00001002 // Thumb does not have [sp, r] address mode.
1003 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1004 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1005 if ((LHSR && LHSR->getReg() == ARM::SP) ||
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001006 (RHSR && RHSR->getReg() == ARM::SP))
1007 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001008
Daniel Dunbarec91d522011-01-19 15:12:16 +00001009 // FIXME: Why do we explicitly check for a match here and then return false?
1010 // Presumably to allow something else to match, but shouldn't this be
1011 // documented?
1012 int RHSC;
1013 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC))
1014 return false;
Bill Wendlingf4caf692010-12-14 03:36:38 +00001015
1016 Base = N.getOperand(0);
1017 Offset = N.getOperand(1);
1018 return true;
1019}
1020
1021bool
1022ARMDAGToDAGISel::SelectThumbAddrModeRI5S1(SDValue N,
1023 SDValue &Base,
1024 SDValue &Offset) {
1025 return SelectThumbAddrModeRI(N, Base, Offset, 1);
1026}
1027
1028bool
1029ARMDAGToDAGISel::SelectThumbAddrModeRI5S2(SDValue N,
1030 SDValue &Base,
1031 SDValue &Offset) {
1032 return SelectThumbAddrModeRI(N, Base, Offset, 2);
1033}
1034
1035bool
1036ARMDAGToDAGISel::SelectThumbAddrModeRI5S4(SDValue N,
1037 SDValue &Base,
1038 SDValue &Offset) {
1039 return SelectThumbAddrModeRI(N, Base, Offset, 4);
1040}
1041
1042bool
1043ARMDAGToDAGISel::SelectThumbAddrModeImm5S(SDValue N, unsigned Scale,
1044 SDValue &Base, SDValue &OffImm) {
1045 if (Scale == 4) {
1046 SDValue TmpBase, TmpOffImm;
1047 if (SelectThumbAddrModeSP(N, TmpBase, TmpOffImm))
1048 return false; // We want to select tLDRspi / tSTRspi instead.
1049
1050 if (N.getOpcode() == ARMISD::Wrapper &&
1051 N.getOperand(0).getOpcode() == ISD::TargetConstantPool)
1052 return false; // We want to select tLDRpci instead.
1053 }
1054
Chris Lattner0a9481f2011-02-13 22:25:43 +00001055 if (!CurDAG->isBaseWithConstantOffset(N)) {
Bill Wendlingf4caf692010-12-14 03:36:38 +00001056 if (N.getOpcode() == ARMISD::Wrapper &&
1057 !(Subtarget->useMovt() &&
1058 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
1059 Base = N.getOperand(0);
1060 } else {
1061 Base = N;
1062 }
1063
Owen Anderson825b72b2009-08-11 20:47:22 +00001064 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengad0e4652007-02-06 00:22:06 +00001065 return true;
1066 }
1067
Bill Wendlingbc4224b2010-12-15 01:03:19 +00001068 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
1069 RegisterSDNode *RHSR = dyn_cast<RegisterSDNode>(N.getOperand(1));
1070 if ((LHSR && LHSR->getReg() == ARM::SP) ||
1071 (RHSR && RHSR->getReg() == ARM::SP)) {
1072 ConstantSDNode *LHS = dyn_cast<ConstantSDNode>(N.getOperand(0));
1073 ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1));
1074 unsigned LHSC = LHS ? LHS->getZExtValue() : 0;
1075 unsigned RHSC = RHS ? RHS->getZExtValue() : 0;
1076
1077 // Thumb does not have [sp, #imm5] address mode for non-zero imm5.
1078 if (LHSC != 0 || RHSC != 0) return false;
1079
1080 Base = N;
1081 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
1082 return true;
1083 }
1084
Evan Chenga8e29892007-01-19 07:51:42 +00001085 // If the RHS is + imm5 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001086 int RHSC;
1087 if (isScaledConstantInRange(N.getOperand(1), Scale, 0, 32, RHSC)) {
1088 Base = N.getOperand(0);
1089 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1090 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001091 }
1092
Evan Chengc38f2bc2007-01-23 22:59:13 +00001093 Base = N.getOperand(0);
Owen Anderson825b72b2009-08-11 20:47:22 +00001094 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chengc38f2bc2007-01-23 22:59:13 +00001095 return true;
Evan Chenga8e29892007-01-19 07:51:42 +00001096}
1097
Bill Wendlingf4caf692010-12-14 03:36:38 +00001098bool
1099ARMDAGToDAGISel::SelectThumbAddrModeImm5S4(SDValue N, SDValue &Base,
1100 SDValue &OffImm) {
1101 return SelectThumbAddrModeImm5S(N, 4, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001102}
1103
Bill Wendlingf4caf692010-12-14 03:36:38 +00001104bool
1105ARMDAGToDAGISel::SelectThumbAddrModeImm5S2(SDValue N, SDValue &Base,
1106 SDValue &OffImm) {
1107 return SelectThumbAddrModeImm5S(N, 2, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001108}
1109
Bill Wendlingf4caf692010-12-14 03:36:38 +00001110bool
1111ARMDAGToDAGISel::SelectThumbAddrModeImm5S1(SDValue N, SDValue &Base,
1112 SDValue &OffImm) {
1113 return SelectThumbAddrModeImm5S(N, 1, Base, OffImm);
Evan Chenga8e29892007-01-19 07:51:42 +00001114}
1115
Chris Lattner52a261b2010-09-21 20:31:19 +00001116bool ARMDAGToDAGISel::SelectThumbAddrModeSP(SDValue N,
1117 SDValue &Base, SDValue &OffImm) {
Evan Chenga8e29892007-01-19 07:51:42 +00001118 if (N.getOpcode() == ISD::FrameIndex) {
1119 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1120 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001121 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Chenga8e29892007-01-19 07:51:42 +00001122 return true;
1123 }
Evan Cheng79d43262007-01-24 02:21:22 +00001124
Chris Lattner0a9481f2011-02-13 22:25:43 +00001125 if (!CurDAG->isBaseWithConstantOffset(N))
Evan Chengad0e4652007-02-06 00:22:06 +00001126 return false;
1127
1128 RegisterSDNode *LHSR = dyn_cast<RegisterSDNode>(N.getOperand(0));
Evan Cheng8c1a73a2007-02-06 09:11:20 +00001129 if (N.getOperand(0).getOpcode() == ISD::FrameIndex ||
1130 (LHSR && LHSR->getReg() == ARM::SP)) {
Evan Cheng79d43262007-01-24 02:21:22 +00001131 // If the RHS is + imm8 * scale, fold into addr mode.
Daniel Dunbarec91d522011-01-19 15:12:16 +00001132 int RHSC;
1133 if (isScaledConstantInRange(N.getOperand(1), /*Scale=*/4, 0, 256, RHSC)) {
1134 Base = N.getOperand(0);
1135 if (Base.getOpcode() == ISD::FrameIndex) {
1136 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1137 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng79d43262007-01-24 02:21:22 +00001138 }
Daniel Dunbarec91d522011-01-19 15:12:16 +00001139 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1140 return true;
Evan Cheng79d43262007-01-24 02:21:22 +00001141 }
1142 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001143
Evan Chenga8e29892007-01-19 07:51:42 +00001144 return false;
1145}
1146
Bill Wendlingf4caf692010-12-14 03:36:38 +00001147
1148//===----------------------------------------------------------------------===//
1149// Thumb 2 Addressing Modes
1150//===----------------------------------------------------------------------===//
1151
1152
Chris Lattner52a261b2010-09-21 20:31:19 +00001153bool ARMDAGToDAGISel::SelectT2ShifterOperandReg(SDValue N, SDValue &BaseReg,
Evan Cheng9cb9e672009-06-27 02:26:13 +00001154 SDValue &Opc) {
Evan Chenga2c519b2010-07-30 23:33:54 +00001155 if (DisableShifterOp)
1156 return false;
1157
Evan Chengee04a6d2011-07-20 23:34:39 +00001158 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(N.getOpcode());
Evan Cheng9cb9e672009-06-27 02:26:13 +00001159
1160 // Don't match base register only case. That is matched to a separate
1161 // lower complexity pattern with explicit register operand.
1162 if (ShOpcVal == ARM_AM::no_shift) return false;
1163
1164 BaseReg = N.getOperand(0);
1165 unsigned ShImmVal = 0;
1166 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1167 ShImmVal = RHS->getZExtValue() & 31;
1168 Opc = getI32Imm(ARM_AM::getSORegOpc(ShOpcVal, ShImmVal));
1169 return true;
1170 }
1171
1172 return false;
1173}
1174
Chris Lattner52a261b2010-09-21 20:31:19 +00001175bool ARMDAGToDAGISel::SelectT2AddrModeImm12(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001176 SDValue &Base, SDValue &OffImm) {
1177 // Match simple R + imm12 operands.
David Goodwin31e7eba2009-07-20 15:55:39 +00001178
Evan Cheng3a214252009-08-11 08:52:18 +00001179 // Base only.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001180 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1181 !CurDAG->isBaseWithConstantOffset(N)) {
David Goodwin31e7eba2009-07-20 15:55:39 +00001182 if (N.getOpcode() == ISD::FrameIndex) {
Chris Lattner0a9481f2011-02-13 22:25:43 +00001183 // Match frame index.
David Goodwin31e7eba2009-07-20 15:55:39 +00001184 int FI = cast<FrameIndexSDNode>(N)->getIndex();
1185 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +00001186 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
David Goodwin31e7eba2009-07-20 15:55:39 +00001187 return true;
Chris Lattner0a9481f2011-02-13 22:25:43 +00001188 }
Owen Anderson099e5552011-03-18 19:46:58 +00001189
Chris Lattner0a9481f2011-02-13 22:25:43 +00001190 if (N.getOpcode() == ARMISD::Wrapper &&
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00001191 !(Subtarget->useMovt() &&
1192 N.getOperand(0).getOpcode() == ISD::TargetGlobalAddress)) {
Evan Cheng3a214252009-08-11 08:52:18 +00001193 Base = N.getOperand(0);
1194 if (Base.getOpcode() == ISD::TargetConstantPool)
1195 return false; // We want to select t2LDRpci instead.
1196 } else
1197 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001198 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001199 return true;
David Goodwin31e7eba2009-07-20 15:55:39 +00001200 }
Evan Cheng055b0312009-06-29 07:51:04 +00001201
1202 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
Chris Lattner52a261b2010-09-21 20:31:19 +00001203 if (SelectT2AddrModeImm8(N, Base, OffImm))
Evan Cheng3a214252009-08-11 08:52:18 +00001204 // Let t2LDRi8 handle (R - imm8).
1205 return false;
1206
Evan Cheng055b0312009-06-29 07:51:04 +00001207 int RHSC = (int)RHS->getZExtValue();
David Goodwind8c95b52009-07-30 18:56:48 +00001208 if (N.getOpcode() == ISD::SUB)
1209 RHSC = -RHSC;
1210
1211 if (RHSC >= 0 && RHSC < 0x1000) { // 12 bits (unsigned)
Evan Cheng055b0312009-06-29 07:51:04 +00001212 Base = N.getOperand(0);
David Goodwind8c95b52009-07-30 18:56:48 +00001213 if (Base.getOpcode() == ISD::FrameIndex) {
1214 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1215 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
1216 }
Owen Anderson825b72b2009-08-11 20:47:22 +00001217 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001218 return true;
1219 }
1220 }
1221
Evan Cheng3a214252009-08-11 08:52:18 +00001222 // Base only.
1223 Base = N;
Owen Anderson825b72b2009-08-11 20:47:22 +00001224 OffImm = CurDAG->getTargetConstant(0, MVT::i32);
Evan Cheng3a214252009-08-11 08:52:18 +00001225 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001226}
1227
Chris Lattner52a261b2010-09-21 20:31:19 +00001228bool ARMDAGToDAGISel::SelectT2AddrModeImm8(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001229 SDValue &Base, SDValue &OffImm) {
David Goodwind8c95b52009-07-30 18:56:48 +00001230 // Match simple R - imm8 operands.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001231 if (N.getOpcode() != ISD::ADD && N.getOpcode() != ISD::SUB &&
1232 !CurDAG->isBaseWithConstantOffset(N))
1233 return false;
Owen Anderson099e5552011-03-18 19:46:58 +00001234
Chris Lattner0a9481f2011-02-13 22:25:43 +00001235 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1236 int RHSC = (int)RHS->getSExtValue();
1237 if (N.getOpcode() == ISD::SUB)
1238 RHSC = -RHSC;
Jim Grosbach764ab522009-08-11 15:33:49 +00001239
Chris Lattner0a9481f2011-02-13 22:25:43 +00001240 if ((RHSC >= -255) && (RHSC < 0)) { // 8 bits (always negative)
1241 Base = N.getOperand(0);
1242 if (Base.getOpcode() == ISD::FrameIndex) {
1243 int FI = cast<FrameIndexSDNode>(Base)->getIndex();
1244 Base = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
Evan Cheng055b0312009-06-29 07:51:04 +00001245 }
Chris Lattner0a9481f2011-02-13 22:25:43 +00001246 OffImm = CurDAG->getTargetConstant(RHSC, MVT::i32);
1247 return true;
Evan Cheng055b0312009-06-29 07:51:04 +00001248 }
1249 }
1250
1251 return false;
1252}
1253
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001254bool ARMDAGToDAGISel::SelectT2AddrModeImm8Offset(SDNode *Op, SDValue N,
Evan Chenge88d5ce2009-07-02 07:28:31 +00001255 SDValue &OffImm){
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001256 unsigned Opcode = Op->getOpcode();
Evan Chenge88d5ce2009-07-02 07:28:31 +00001257 ISD::MemIndexedMode AM = (Opcode == ISD::LOAD)
1258 ? cast<LoadSDNode>(Op)->getAddressingMode()
1259 : cast<StoreSDNode>(Op)->getAddressingMode();
Daniel Dunbarec91d522011-01-19 15:12:16 +00001260 int RHSC;
1261 if (isScaledConstantInRange(N, /*Scale=*/1, 0, 0x100, RHSC)) { // 8 bits.
1262 OffImm = ((AM == ISD::PRE_INC) || (AM == ISD::POST_INC))
1263 ? CurDAG->getTargetConstant(RHSC, MVT::i32)
1264 : CurDAG->getTargetConstant(-RHSC, MVT::i32);
1265 return true;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001266 }
1267
1268 return false;
1269}
1270
Chris Lattner52a261b2010-09-21 20:31:19 +00001271bool ARMDAGToDAGISel::SelectT2AddrModeSoReg(SDValue N,
Evan Cheng055b0312009-06-29 07:51:04 +00001272 SDValue &Base,
1273 SDValue &OffReg, SDValue &ShImm) {
Evan Cheng3a214252009-08-11 08:52:18 +00001274 // (R - imm8) should be handled by t2LDRi8. The rest are handled by t2LDRi12.
Chris Lattner0a9481f2011-02-13 22:25:43 +00001275 if (N.getOpcode() != ISD::ADD && !CurDAG->isBaseWithConstantOffset(N))
Evan Cheng3a214252009-08-11 08:52:18 +00001276 return false;
Evan Cheng055b0312009-06-29 07:51:04 +00001277
Evan Cheng3a214252009-08-11 08:52:18 +00001278 // Leave (R + imm12) for t2LDRi12, (R - imm8) for t2LDRi8.
1279 if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1280 int RHSC = (int)RHS->getZExtValue();
1281 if (RHSC >= 0 && RHSC < 0x1000) // 12 bits (unsigned)
1282 return false;
1283 else if (RHSC < 0 && RHSC >= -255) // 8 bits
David Goodwind8c95b52009-07-30 18:56:48 +00001284 return false;
1285 }
1286
Evan Cheng055b0312009-06-29 07:51:04 +00001287 // Look for (R + R) or (R + (R << [1,2,3])).
1288 unsigned ShAmt = 0;
1289 Base = N.getOperand(0);
1290 OffReg = N.getOperand(1);
1291
1292 // Swap if it is ((R << c) + R).
Evan Chengee04a6d2011-07-20 23:34:39 +00001293 ARM_AM::ShiftOpc ShOpcVal = ARM_AM::getShiftOpcForNode(OffReg.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001294 if (ShOpcVal != ARM_AM::lsl) {
Evan Chengee04a6d2011-07-20 23:34:39 +00001295 ShOpcVal = ARM_AM::getShiftOpcForNode(Base.getOpcode());
Evan Cheng055b0312009-06-29 07:51:04 +00001296 if (ShOpcVal == ARM_AM::lsl)
1297 std::swap(Base, OffReg);
Jim Grosbach764ab522009-08-11 15:33:49 +00001298 }
1299
Evan Cheng055b0312009-06-29 07:51:04 +00001300 if (ShOpcVal == ARM_AM::lsl) {
1301 // Check to see if the RHS of the shift is a constant, if not, we can't fold
1302 // it.
1303 if (ConstantSDNode *Sh = dyn_cast<ConstantSDNode>(OffReg.getOperand(1))) {
1304 ShAmt = Sh->getZExtValue();
Evan Chengf40deed2010-10-27 23:41:30 +00001305 if (ShAmt < 4 && isShifterOpProfitable(OffReg, ShOpcVal, ShAmt))
1306 OffReg = OffReg.getOperand(0);
1307 else {
Evan Cheng055b0312009-06-29 07:51:04 +00001308 ShAmt = 0;
1309 ShOpcVal = ARM_AM::no_shift;
Evan Chengf40deed2010-10-27 23:41:30 +00001310 }
Evan Cheng055b0312009-06-29 07:51:04 +00001311 } else {
1312 ShOpcVal = ARM_AM::no_shift;
1313 }
David Goodwin7ecc8502009-07-15 15:50:19 +00001314 }
Jim Grosbach764ab522009-08-11 15:33:49 +00001315
Owen Anderson825b72b2009-08-11 20:47:22 +00001316 ShImm = CurDAG->getTargetConstant(ShAmt, MVT::i32);
Evan Cheng055b0312009-06-29 07:51:04 +00001317
1318 return true;
1319}
1320
1321//===--------------------------------------------------------------------===//
1322
Evan Chengee568cf2007-07-05 07:15:27 +00001323/// getAL - Returns a ARMCC::AL immediate node.
Dan Gohman475871a2008-07-27 21:46:04 +00001324static inline SDValue getAL(SelectionDAG *CurDAG) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001325 return CurDAG->getTargetConstant((uint64_t)ARMCC::AL, MVT::i32);
Evan Cheng44bec522007-05-15 01:29:07 +00001326}
1327
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001328SDNode *ARMDAGToDAGISel::SelectARMIndexedLoad(SDNode *N) {
1329 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00001330 ISD::MemIndexedMode AM = LD->getAddressingMode();
1331 if (AM == ISD::UNINDEXED)
1332 return NULL;
1333
Owen Andersone50ed302009-08-10 22:56:29 +00001334 EVT LoadedVT = LD->getMemoryVT();
Evan Chengaf4550f2009-07-02 01:23:32 +00001335 SDValue Offset, AMOpc;
1336 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1337 unsigned Opcode = 0;
1338 bool Match = false;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001339 if (LoadedVT == MVT::i32 && isPre &&
1340 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
1341 Opcode = ARM::LDR_PRE_IMM;
1342 Match = true;
1343 } else if (LoadedVT == MVT::i32 && !isPre &&
Owen Anderson793e7962011-07-26 20:54:26 +00001344 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001345 Opcode = ARM::LDR_POST_IMM;
Evan Chengaf4550f2009-07-02 01:23:32 +00001346 Match = true;
Owen Anderson793e7962011-07-26 20:54:26 +00001347 } else if (LoadedVT == MVT::i32 &&
1348 SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
Owen Anderson9ab0f252011-08-26 20:43:14 +00001349 Opcode = isPre ? ARM::LDR_PRE_REG : ARM::LDR_POST_REG;
Owen Anderson793e7962011-07-26 20:54:26 +00001350 Match = true;
1351
Owen Anderson825b72b2009-08-11 20:47:22 +00001352 } else if (LoadedVT == MVT::i16 &&
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001353 SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001354 Match = true;
1355 Opcode = (LD->getExtensionType() == ISD::SEXTLOAD)
1356 ? (isPre ? ARM::LDRSH_PRE : ARM::LDRSH_POST)
1357 : (isPre ? ARM::LDRH_PRE : ARM::LDRH_POST);
Owen Anderson825b72b2009-08-11 20:47:22 +00001358 } else if (LoadedVT == MVT::i8 || LoadedVT == MVT::i1) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001359 if (LD->getExtensionType() == ISD::SEXTLOAD) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001360 if (SelectAddrMode3Offset(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001361 Match = true;
1362 Opcode = isPre ? ARM::LDRSB_PRE : ARM::LDRSB_POST;
1363 }
1364 } else {
Owen Andersonc4e16de2011-08-29 20:16:50 +00001365 if (isPre &&
1366 SelectAddrMode2OffsetImmPre(N, LD->getOffset(), Offset, AMOpc)) {
Evan Chengaf4550f2009-07-02 01:23:32 +00001367 Match = true;
Owen Andersonc4e16de2011-08-29 20:16:50 +00001368 Opcode = ARM::LDRB_PRE_IMM;
1369 } else if (!isPre &&
1370 SelectAddrMode2OffsetImm(N, LD->getOffset(), Offset, AMOpc)) {
1371 Match = true;
1372 Opcode = ARM::LDRB_POST_IMM;
Owen Anderson793e7962011-07-26 20:54:26 +00001373 } else if (SelectAddrMode2OffsetReg(N, LD->getOffset(), Offset, AMOpc)) {
1374 Match = true;
Owen Anderson9ab0f252011-08-26 20:43:14 +00001375 Opcode = isPre ? ARM::LDRB_PRE_REG : ARM::LDRB_POST_REG;
Evan Chengaf4550f2009-07-02 01:23:32 +00001376 }
1377 }
1378 }
1379
1380 if (Match) {
Owen Anderson2b568fb2011-08-26 21:12:37 +00001381 if (Opcode == ARM::LDR_PRE_IMM || Opcode == ARM::LDRB_PRE_IMM) {
1382 SDValue Chain = LD->getChain();
1383 SDValue Base = LD->getBasePtr();
1384 SDValue Ops[]= { Base, AMOpc, getAL(CurDAG),
1385 CurDAG->getRegister(0, MVT::i32), Chain };
Jim Grosbachb04546f2011-09-13 20:30:37 +00001386 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1387 MVT::i32, MVT::Other, Ops, 5);
Owen Anderson2b568fb2011-08-26 21:12:37 +00001388 } else {
1389 SDValue Chain = LD->getChain();
1390 SDValue Base = LD->getBasePtr();
1391 SDValue Ops[]= { Base, Offset, AMOpc, getAL(CurDAG),
1392 CurDAG->getRegister(0, MVT::i32), Chain };
Jim Grosbachb04546f2011-09-13 20:30:37 +00001393 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32,
1394 MVT::i32, MVT::Other, Ops, 6);
Owen Anderson2b568fb2011-08-26 21:12:37 +00001395 }
Evan Chengaf4550f2009-07-02 01:23:32 +00001396 }
1397
1398 return NULL;
1399}
1400
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001401SDNode *ARMDAGToDAGISel::SelectT2IndexedLoad(SDNode *N) {
1402 LoadSDNode *LD = cast<LoadSDNode>(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001403 ISD::MemIndexedMode AM = LD->getAddressingMode();
1404 if (AM == ISD::UNINDEXED)
1405 return NULL;
1406
Owen Andersone50ed302009-08-10 22:56:29 +00001407 EVT LoadedVT = LD->getMemoryVT();
Evan Cheng4fbb9962009-07-02 23:16:11 +00001408 bool isSExtLd = LD->getExtensionType() == ISD::SEXTLOAD;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001409 SDValue Offset;
1410 bool isPre = (AM == ISD::PRE_INC) || (AM == ISD::PRE_DEC);
1411 unsigned Opcode = 0;
1412 bool Match = false;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001413 if (SelectT2AddrModeImm8Offset(N, LD->getOffset(), Offset)) {
Owen Anderson825b72b2009-08-11 20:47:22 +00001414 switch (LoadedVT.getSimpleVT().SimpleTy) {
1415 case MVT::i32:
Evan Chenge88d5ce2009-07-02 07:28:31 +00001416 Opcode = isPre ? ARM::t2LDR_PRE : ARM::t2LDR_POST;
1417 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001418 case MVT::i16:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001419 if (isSExtLd)
1420 Opcode = isPre ? ARM::t2LDRSH_PRE : ARM::t2LDRSH_POST;
1421 else
1422 Opcode = isPre ? ARM::t2LDRH_PRE : ARM::t2LDRH_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001423 break;
Owen Anderson825b72b2009-08-11 20:47:22 +00001424 case MVT::i8:
1425 case MVT::i1:
Evan Cheng4fbb9962009-07-02 23:16:11 +00001426 if (isSExtLd)
1427 Opcode = isPre ? ARM::t2LDRSB_PRE : ARM::t2LDRSB_POST;
1428 else
1429 Opcode = isPre ? ARM::t2LDRB_PRE : ARM::t2LDRB_POST;
Evan Chenge88d5ce2009-07-02 07:28:31 +00001430 break;
1431 default:
1432 return NULL;
1433 }
1434 Match = true;
1435 }
1436
1437 if (Match) {
1438 SDValue Chain = LD->getChain();
1439 SDValue Base = LD->getBasePtr();
1440 SDValue Ops[]= { Base, Offset, getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00001441 CurDAG->getRegister(0, MVT::i32), Chain };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001442 return CurDAG->getMachineNode(Opcode, N->getDebugLoc(), MVT::i32, MVT::i32,
Dan Gohman602b0c82009-09-25 18:54:59 +00001443 MVT::Other, Ops, 5);
Evan Chenge88d5ce2009-07-02 07:28:31 +00001444 }
1445
1446 return NULL;
1447}
1448
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001449/// PairSRegs - Form a D register from a pair of S registers.
1450///
1451SDNode *ARMDAGToDAGISel::PairSRegs(EVT VT, SDValue V0, SDValue V1) {
1452 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001453 SDValue RegClass =
1454 CurDAG->getTargetConstant(ARM::DPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001455 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1456 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001457 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1458 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001459}
1460
Evan Cheng603afbf2010-05-10 17:34:18 +00001461/// PairDRegs - Form a quad register from a pair of D registers.
1462///
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001463SDNode *ARMDAGToDAGISel::PairDRegs(EVT VT, SDValue V0, SDValue V1) {
1464 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001465 SDValue RegClass = CurDAG->getTargetConstant(ARM::QPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001466 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1467 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001468 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1469 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Bob Wilson3bf12ab2009-10-06 22:01:59 +00001470}
1471
Evan Cheng7f687192010-05-14 00:21:45 +00001472/// PairQRegs - Form 4 consecutive D registers from a pair of Q registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001473///
1474SDNode *ARMDAGToDAGISel::PairQRegs(EVT VT, SDValue V0, SDValue V1) {
1475 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001476 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001477 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1478 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001479 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1 };
1480 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 5);
Evan Cheng603afbf2010-05-10 17:34:18 +00001481}
1482
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001483/// QuadSRegs - Form 4 consecutive S registers.
1484///
1485SDNode *ARMDAGToDAGISel::QuadSRegs(EVT VT, SDValue V0, SDValue V1,
1486 SDValue V2, SDValue V3) {
1487 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001488 SDValue RegClass =
1489 CurDAG->getTargetConstant(ARM::QPR_VFP2RegClassID, MVT::i32);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001490 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::ssub_0, MVT::i32);
1491 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::ssub_1, MVT::i32);
1492 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::ssub_2, MVT::i32);
1493 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::ssub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001494 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1495 V2, SubReg2, V3, SubReg3 };
1496 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Bob Wilson40cbe7d2010-06-04 00:04:02 +00001497}
1498
Evan Cheng7f687192010-05-14 00:21:45 +00001499/// QuadDRegs - Form 4 consecutive D registers.
Evan Cheng603afbf2010-05-10 17:34:18 +00001500///
1501SDNode *ARMDAGToDAGISel::QuadDRegs(EVT VT, SDValue V0, SDValue V1,
1502 SDValue V2, SDValue V3) {
1503 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001504 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001505 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::dsub_0, MVT::i32);
1506 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::dsub_1, MVT::i32);
1507 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::dsub_2, MVT::i32);
1508 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::dsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001509 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1510 V2, SubReg2, V3, SubReg3 };
1511 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng603afbf2010-05-10 17:34:18 +00001512}
1513
Evan Cheng8f6de382010-05-16 03:27:48 +00001514/// QuadQRegs - Form 4 consecutive Q registers.
1515///
1516SDNode *ARMDAGToDAGISel::QuadQRegs(EVT VT, SDValue V0, SDValue V1,
1517 SDValue V2, SDValue V3) {
1518 DebugLoc dl = V0.getNode()->getDebugLoc();
Owen Anderson1300f302011-06-16 18:17:13 +00001519 SDValue RegClass = CurDAG->getTargetConstant(ARM::QQQQPRRegClassID, MVT::i32);
Jakob Stoklund Olesen558661d2010-05-24 16:54:32 +00001520 SDValue SubReg0 = CurDAG->getTargetConstant(ARM::qsub_0, MVT::i32);
1521 SDValue SubReg1 = CurDAG->getTargetConstant(ARM::qsub_1, MVT::i32);
1522 SDValue SubReg2 = CurDAG->getTargetConstant(ARM::qsub_2, MVT::i32);
1523 SDValue SubReg3 = CurDAG->getTargetConstant(ARM::qsub_3, MVT::i32);
Owen Anderson1300f302011-06-16 18:17:13 +00001524 const SDValue Ops[] = { RegClass, V0, SubReg0, V1, SubReg1,
1525 V2, SubReg2, V3, SubReg3 };
1526 return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE, dl, VT, Ops, 9);
Evan Cheng8f6de382010-05-16 03:27:48 +00001527}
1528
Bob Wilson2a6e6162010-09-23 23:42:37 +00001529/// GetVLDSTAlign - Get the alignment (in bytes) for the alignment operand
1530/// of a NEON VLD or VST instruction. The supported values depend on the
1531/// number of registers being loaded.
Bob Wilson665814b2010-11-01 23:40:51 +00001532SDValue ARMDAGToDAGISel::GetVLDSTAlign(SDValue Align, unsigned NumVecs,
1533 bool is64BitVector) {
Bob Wilson2a6e6162010-09-23 23:42:37 +00001534 unsigned NumRegs = NumVecs;
1535 if (!is64BitVector && NumVecs < 3)
1536 NumRegs *= 2;
1537
Bob Wilson665814b2010-11-01 23:40:51 +00001538 unsigned Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson2a6e6162010-09-23 23:42:37 +00001539 if (Alignment >= 32 && NumRegs == 4)
Bob Wilson665814b2010-11-01 23:40:51 +00001540 Alignment = 32;
1541 else if (Alignment >= 16 && (NumRegs == 2 || NumRegs == 4))
1542 Alignment = 16;
1543 else if (Alignment >= 8)
1544 Alignment = 8;
1545 else
1546 Alignment = 0;
1547
1548 return CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001549}
1550
Jim Grosbach10b90a92011-10-24 21:45:13 +00001551// Get the register stride update opcode of a VLD/VST instruction that
1552// is otherwise equivalent to the given fixed stride updating instruction.
1553static unsigned getVLDSTRegisterUpdateOpcode(unsigned Opc) {
1554 switch (Opc) {
1555 default: break;
1556 case ARM::VLD1d8wb_fixed: return ARM::VLD1d8wb_register;
1557 case ARM::VLD1d16wb_fixed: return ARM::VLD1d16wb_register;
1558 case ARM::VLD1d32wb_fixed: return ARM::VLD1d32wb_register;
1559 case ARM::VLD1d64wb_fixed: return ARM::VLD1d64wb_register;
1560 case ARM::VLD1q8wb_fixed: return ARM::VLD1q8wb_register;
1561 case ARM::VLD1q16wb_fixed: return ARM::VLD1q16wb_register;
1562 case ARM::VLD1q32wb_fixed: return ARM::VLD1q32wb_register;
1563 case ARM::VLD1q64wb_fixed: return ARM::VLD1q64wb_register;
Jim Grosbach4334e032011-10-31 21:50:31 +00001564
1565 case ARM::VST1d8wb_fixed: return ARM::VST1d8wb_register;
1566 case ARM::VST1d16wb_fixed: return ARM::VST1d16wb_register;
1567 case ARM::VST1d32wb_fixed: return ARM::VST1d32wb_register;
1568 case ARM::VST1d64wb_fixed: return ARM::VST1d64wb_register;
1569 case ARM::VST1q8wb_fixed: return ARM::VST1q8wb_register;
1570 case ARM::VST1q16wb_fixed: return ARM::VST1q16wb_register;
1571 case ARM::VST1q32wb_fixed: return ARM::VST1q32wb_register;
1572 case ARM::VST1q64wb_fixed: return ARM::VST1q64wb_register;
Jim Grosbachd5ca2012011-11-29 22:38:04 +00001573 case ARM::VST1d64TPseudoWB_fixed: return ARM::VST1d64TPseudoWB_register;
Jim Grosbach4c7edb32011-11-29 22:58:48 +00001574 case ARM::VST1d64QPseudoWB_fixed: return ARM::VST1d64QPseudoWB_register;
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001575
Jim Grosbach28f08c92012-03-05 19:33:30 +00001576 case ARM::VLD2d8wb_fixed: return ARM::VLD2d8wb_register;
1577 case ARM::VLD2d16wb_fixed: return ARM::VLD2d16wb_register;
1578 case ARM::VLD2d32wb_fixed: return ARM::VLD2d32wb_register;
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001579 case ARM::VLD2q8PseudoWB_fixed: return ARM::VLD2q8PseudoWB_register;
1580 case ARM::VLD2q16PseudoWB_fixed: return ARM::VLD2q16PseudoWB_register;
1581 case ARM::VLD2q32PseudoWB_fixed: return ARM::VLD2q32PseudoWB_register;
1582
Jim Grosbach28f08c92012-03-05 19:33:30 +00001583 case ARM::VST2d8wb_fixed: return ARM::VST2d8wb_register;
1584 case ARM::VST2d16wb_fixed: return ARM::VST2d16wb_register;
1585 case ARM::VST2d32wb_fixed: return ARM::VST2d32wb_register;
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001586 case ARM::VST2q8PseudoWB_fixed: return ARM::VST2q8PseudoWB_register;
1587 case ARM::VST2q16PseudoWB_fixed: return ARM::VST2q16PseudoWB_register;
1588 case ARM::VST2q32PseudoWB_fixed: return ARM::VST2q32PseudoWB_register;
Jim Grosbache6949b12011-12-21 19:40:55 +00001589
Jim Grosbachc0fc4502012-03-06 22:01:44 +00001590 case ARM::VLD2DUPd8wb_fixed: return ARM::VLD2DUPd8wb_register;
1591 case ARM::VLD2DUPd16wb_fixed: return ARM::VLD2DUPd16wb_register;
1592 case ARM::VLD2DUPd32wb_fixed: return ARM::VLD2DUPd32wb_register;
Jim Grosbach10b90a92011-10-24 21:45:13 +00001593 }
1594 return Opc; // If not one we handle, return it unchanged.
1595}
1596
Bob Wilson1c3ef902011-02-07 17:43:21 +00001597SDNode *ARMDAGToDAGISel::SelectVLD(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +00001598 const uint16_t *DOpcodes,
1599 const uint16_t *QOpcodes0,
1600 const uint16_t *QOpcodes1) {
Bob Wilson621f1952010-03-23 05:25:43 +00001601 assert(NumVecs >= 1 && NumVecs <= 4 && "VLD NumVecs out-of-range");
Bob Wilson3e36f132009-10-14 17:28:52 +00001602 DebugLoc dl = N->getDebugLoc();
1603
Bob Wilson226036e2010-03-20 22:13:40 +00001604 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001605 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1606 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson3e36f132009-10-14 17:28:52 +00001607 return NULL;
1608
1609 SDValue Chain = N->getOperand(0);
1610 EVT VT = N->getValueType(0);
1611 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001612 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson40ff01a2010-09-23 21:43:54 +00001613
Bob Wilson3e36f132009-10-14 17:28:52 +00001614 unsigned OpcodeIndex;
1615 switch (VT.getSimpleVT().SimpleTy) {
1616 default: llvm_unreachable("unhandled vld type");
1617 // Double-register operations:
1618 case MVT::v8i8: OpcodeIndex = 0; break;
1619 case MVT::v4i16: OpcodeIndex = 1; break;
1620 case MVT::v2f32:
1621 case MVT::v2i32: OpcodeIndex = 2; break;
1622 case MVT::v1i64: OpcodeIndex = 3; break;
1623 // Quad-register operations:
1624 case MVT::v16i8: OpcodeIndex = 0; break;
1625 case MVT::v8i16: OpcodeIndex = 1; break;
1626 case MVT::v4f32:
1627 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson621f1952010-03-23 05:25:43 +00001628 case MVT::v2i64: OpcodeIndex = 3;
Bob Wilson11d98992010-03-23 06:20:33 +00001629 assert(NumVecs == 1 && "v2i64 type only supported for VLD1");
Bob Wilson621f1952010-03-23 05:25:43 +00001630 break;
Bob Wilson3e36f132009-10-14 17:28:52 +00001631 }
1632
Bob Wilsonf5721912010-09-03 18:16:02 +00001633 EVT ResTy;
1634 if (NumVecs == 1)
1635 ResTy = VT;
1636 else {
1637 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1638 if (!is64BitVector)
1639 ResTyElts *= 2;
1640 ResTy = EVT::getVectorVT(*CurDAG->getContext(), MVT::i64, ResTyElts);
1641 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001642 std::vector<EVT> ResTys;
1643 ResTys.push_back(ResTy);
1644 if (isUpdating)
1645 ResTys.push_back(MVT::i32);
1646 ResTys.push_back(MVT::Other);
Bob Wilsonf5721912010-09-03 18:16:02 +00001647
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001648 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001649 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001650 SDNode *VLd;
1651 SmallVector<SDValue, 7> Ops;
Evan Chenge9e2ba02010-05-10 21:26:24 +00001652
Bob Wilson1c3ef902011-02-07 17:43:21 +00001653 // Double registers and VLD1/VLD2 quad registers are directly supported.
1654 if (is64BitVector || NumVecs <= 2) {
1655 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1656 QOpcodes0[OpcodeIndex]);
1657 Ops.push_back(MemAddr);
1658 Ops.push_back(Align);
1659 if (isUpdating) {
1660 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001661 // FIXME: VLD1/VLD2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach10b90a92011-10-24 21:45:13 +00001662 // case entirely when the rest are updated to that form, too.
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001663 if ((NumVecs == 1 || NumVecs == 2) && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach10b90a92011-10-24 21:45:13 +00001664 Opc = getVLDSTRegisterUpdateOpcode(Opc);
Jim Grosbacha4e3c7f2011-12-09 21:28:25 +00001665 // We use a VLD1 for v1i64 even if the pseudo says vld2/3/4, so
Jim Grosbach4334e032011-10-31 21:50:31 +00001666 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbach28f08c92012-03-05 19:33:30 +00001667 if ((NumVecs != 1 && NumVecs != 2 && Opc != ARM::VLD1q64wb_fixed) ||
Jim Grosbach4334e032011-10-31 21:50:31 +00001668 !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach10b90a92011-10-24 21:45:13 +00001669 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Evan Chenge9e2ba02010-05-10 21:26:24 +00001670 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001671 Ops.push_back(Pred);
1672 Ops.push_back(Reg0);
1673 Ops.push_back(Chain);
1674 VLd = CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Bob Wilsonffde0802010-09-02 16:00:54 +00001675
Bob Wilson3e36f132009-10-14 17:28:52 +00001676 } else {
1677 // Otherwise, quad registers are loaded with two separate instructions,
1678 // where one loads the even registers and the other loads the odd registers.
Bob Wilsonf5721912010-09-03 18:16:02 +00001679 EVT AddrTy = MemAddr.getValueType();
Bob Wilson3e36f132009-10-14 17:28:52 +00001680
Bob Wilson1c3ef902011-02-07 17:43:21 +00001681 // Load the even subregs. This is always an updating load, so that it
1682 // provides the address to the second load for the odd subregs.
Bob Wilsonf5721912010-09-03 18:16:02 +00001683 SDValue ImplDef =
1684 SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, ResTy), 0);
1685 const SDValue OpsA[] = { MemAddr, Align, Reg0, ImplDef, Pred, Reg0, Chain };
Bob Wilson7de68142011-02-07 17:43:15 +00001686 SDNode *VLdA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1687 ResTy, AddrTy, MVT::Other, OpsA, 7);
Bob Wilsonf5721912010-09-03 18:16:02 +00001688 Chain = SDValue(VLdA, 2);
Bob Wilson3e36f132009-10-14 17:28:52 +00001689
Bob Wilson24f995d2009-10-14 18:32:29 +00001690 // Load the odd subregs.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001691 Ops.push_back(SDValue(VLdA, 1));
1692 Ops.push_back(Align);
1693 if (isUpdating) {
1694 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1695 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1696 "only constant post-increment update allowed for VLD3/4");
1697 (void)Inc;
1698 Ops.push_back(Reg0);
1699 }
1700 Ops.push_back(SDValue(VLdA, 0));
1701 Ops.push_back(Pred);
1702 Ops.push_back(Reg0);
1703 Ops.push_back(Chain);
1704 VLd = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1705 Ops.data(), Ops.size());
Bob Wilsonf5721912010-09-03 18:16:02 +00001706 }
Bob Wilson3e36f132009-10-14 17:28:52 +00001707
Evan Chengb58a3402011-04-19 00:04:03 +00001708 // Transfer memoperands.
1709 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1710 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1711 cast<MachineSDNode>(VLd)->setMemRefs(MemOp, MemOp + 1);
1712
Bob Wilson1c3ef902011-02-07 17:43:21 +00001713 if (NumVecs == 1)
1714 return VLd;
1715
1716 // Extract out the subregisters.
1717 SDValue SuperReg = SDValue(VLd, 0);
1718 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1719 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1720 unsigned Sub0 = (is64BitVector ? ARM::dsub_0 : ARM::qsub_0);
1721 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1722 ReplaceUses(SDValue(N, Vec),
1723 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1724 ReplaceUses(SDValue(N, NumVecs), SDValue(VLd, 1));
1725 if (isUpdating)
1726 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLd, 2));
Bob Wilson3e36f132009-10-14 17:28:52 +00001727 return NULL;
1728}
1729
Bob Wilson1c3ef902011-02-07 17:43:21 +00001730SDNode *ARMDAGToDAGISel::SelectVST(SDNode *N, bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +00001731 const uint16_t *DOpcodes,
1732 const uint16_t *QOpcodes0,
1733 const uint16_t *QOpcodes1) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00001734 assert(NumVecs >= 1 && NumVecs <= 4 && "VST NumVecs out-of-range");
Bob Wilson24f995d2009-10-14 18:32:29 +00001735 DebugLoc dl = N->getDebugLoc();
1736
Bob Wilson226036e2010-03-20 22:13:40 +00001737 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001738 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1739 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1740 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilson24f995d2009-10-14 18:32:29 +00001741 return NULL;
1742
Evan Chengb58a3402011-04-19 00:04:03 +00001743 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1744 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1745
Bob Wilson24f995d2009-10-14 18:32:29 +00001746 SDValue Chain = N->getOperand(0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001747 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilson24f995d2009-10-14 18:32:29 +00001748 bool is64BitVector = VT.is64BitVector();
Bob Wilson665814b2010-11-01 23:40:51 +00001749 Align = GetVLDSTAlign(Align, NumVecs, is64BitVector);
Bob Wilson2a6e6162010-09-23 23:42:37 +00001750
Bob Wilson24f995d2009-10-14 18:32:29 +00001751 unsigned OpcodeIndex;
1752 switch (VT.getSimpleVT().SimpleTy) {
1753 default: llvm_unreachable("unhandled vst type");
1754 // Double-register operations:
1755 case MVT::v8i8: OpcodeIndex = 0; break;
1756 case MVT::v4i16: OpcodeIndex = 1; break;
1757 case MVT::v2f32:
1758 case MVT::v2i32: OpcodeIndex = 2; break;
1759 case MVT::v1i64: OpcodeIndex = 3; break;
1760 // Quad-register operations:
1761 case MVT::v16i8: OpcodeIndex = 0; break;
1762 case MVT::v8i16: OpcodeIndex = 1; break;
1763 case MVT::v4f32:
1764 case MVT::v4i32: OpcodeIndex = 2; break;
Bob Wilson11d98992010-03-23 06:20:33 +00001765 case MVT::v2i64: OpcodeIndex = 3;
1766 assert(NumVecs == 1 && "v2i64 type only supported for VST1");
1767 break;
Bob Wilson24f995d2009-10-14 18:32:29 +00001768 }
1769
Bob Wilson1c3ef902011-02-07 17:43:21 +00001770 std::vector<EVT> ResTys;
1771 if (isUpdating)
1772 ResTys.push_back(MVT::i32);
1773 ResTys.push_back(MVT::Other);
1774
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001775 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001776 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001777 SmallVector<SDValue, 7> Ops;
Evan Chengac0869d2009-11-21 06:21:52 +00001778
Bob Wilson1c3ef902011-02-07 17:43:21 +00001779 // Double registers and VST1/VST2 quad registers are directly supported.
1780 if (is64BitVector || NumVecs <= 2) {
Bob Wilson7de68142011-02-07 17:43:15 +00001781 SDValue SrcReg;
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001782 if (NumVecs == 1) {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001783 SrcReg = N->getOperand(Vec0Idx);
1784 } else if (is64BitVector) {
Evan Cheng0ce537a2010-05-11 01:19:40 +00001785 // Form a REG_SEQUENCE to force register allocation.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001786 SDValue V0 = N->getOperand(Vec0Idx + 0);
1787 SDValue V1 = N->getOperand(Vec0Idx + 1);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001788 if (NumVecs == 2)
Bob Wilson7de68142011-02-07 17:43:15 +00001789 SrcReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001790 else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001791 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson7de68142011-02-07 17:43:15 +00001792 // If it's a vst3, form a quad D-register and leave the last part as
Evan Cheng0ce537a2010-05-11 01:19:40 +00001793 // an undef.
1794 SDValue V3 = (NumVecs == 3)
1795 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,dl,VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001796 : N->getOperand(Vec0Idx + 3);
Bob Wilson7de68142011-02-07 17:43:15 +00001797 SrcReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
Evan Cheng0ce537a2010-05-11 01:19:40 +00001798 }
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001799 } else {
1800 // Form a QQ register.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001801 SDValue Q0 = N->getOperand(Vec0Idx);
1802 SDValue Q1 = N->getOperand(Vec0Idx + 1);
Bob Wilson7de68142011-02-07 17:43:15 +00001803 SrcReg = SDValue(PairQRegs(MVT::v4i64, Q0, Q1), 0);
Bob Wilson24f995d2009-10-14 18:32:29 +00001804 }
Bob Wilson1c3ef902011-02-07 17:43:21 +00001805
1806 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1807 QOpcodes0[OpcodeIndex]);
1808 Ops.push_back(MemAddr);
1809 Ops.push_back(Align);
1810 if (isUpdating) {
1811 SDValue Inc = N->getOperand(AddrOpIdx + 1);
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001812 // FIXME: VST1/VST2 fixed increment doesn't need Reg0. Remove the reg0
Jim Grosbach4334e032011-10-31 21:50:31 +00001813 // case entirely when the rest are updated to that form, too.
Jim Grosbachbb3a2e42011-12-14 21:32:11 +00001814 if (NumVecs <= 2 && !isa<ConstantSDNode>(Inc.getNode()))
Jim Grosbach4334e032011-10-31 21:50:31 +00001815 Opc = getVLDSTRegisterUpdateOpcode(Opc);
1816 // We use a VST1 for v1i64 even if the pseudo says vld2/3/4, so
1817 // check for that explicitly too. Horribly hacky, but temporary.
Jim Grosbach28f08c92012-03-05 19:33:30 +00001818 if ((NumVecs > 2 && Opc != ARM::VST1q64wb_fixed) ||
Jim Grosbach4334e032011-10-31 21:50:31 +00001819 !isa<ConstantSDNode>(Inc.getNode()))
1820 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001821 }
1822 Ops.push_back(SrcReg);
1823 Ops.push_back(Pred);
1824 Ops.push_back(Reg0);
1825 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001826 SDNode *VSt =
1827 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
1828
1829 // Transfer memoperands.
1830 cast<MachineSDNode>(VSt)->setMemRefs(MemOp, MemOp + 1);
1831
1832 return VSt;
Bob Wilson24f995d2009-10-14 18:32:29 +00001833 }
1834
1835 // Otherwise, quad registers are stored with two separate instructions,
1836 // where one stores the even registers and the other stores the odd registers.
Evan Cheng7189fd02010-05-15 07:53:37 +00001837
Bob Wilson07f6e802010-06-16 21:34:01 +00001838 // Form the QQQQ REG_SEQUENCE.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001839 SDValue V0 = N->getOperand(Vec0Idx + 0);
1840 SDValue V1 = N->getOperand(Vec0Idx + 1);
1841 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001842 SDValue V3 = (NumVecs == 3)
1843 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001844 : N->getOperand(Vec0Idx + 3);
Bob Wilsone5ce4f62010-08-28 05:12:57 +00001845 SDValue RegSeq = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilson07f6e802010-06-16 21:34:01 +00001846
Bob Wilson1c3ef902011-02-07 17:43:21 +00001847 // Store the even D registers. This is always an updating store, so that it
1848 // provides the address to the second store for the odd subregs.
Bob Wilson7de68142011-02-07 17:43:15 +00001849 const SDValue OpsA[] = { MemAddr, Align, Reg0, RegSeq, Pred, Reg0, Chain };
1850 SDNode *VStA = CurDAG->getMachineNode(QOpcodes0[OpcodeIndex], dl,
1851 MemAddr.getValueType(),
1852 MVT::Other, OpsA, 7);
Evan Chengb58a3402011-04-19 00:04:03 +00001853 cast<MachineSDNode>(VStA)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson07f6e802010-06-16 21:34:01 +00001854 Chain = SDValue(VStA, 1);
1855
1856 // Store the odd D registers.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001857 Ops.push_back(SDValue(VStA, 0));
1858 Ops.push_back(Align);
1859 if (isUpdating) {
1860 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1861 assert(isa<ConstantSDNode>(Inc.getNode()) &&
1862 "only constant post-increment update allowed for VST3/4");
1863 (void)Inc;
1864 Ops.push_back(Reg0);
1865 }
1866 Ops.push_back(RegSeq);
1867 Ops.push_back(Pred);
1868 Ops.push_back(Reg0);
1869 Ops.push_back(Chain);
Evan Chengb58a3402011-04-19 00:04:03 +00001870 SDNode *VStB = CurDAG->getMachineNode(QOpcodes1[OpcodeIndex], dl, ResTys,
1871 Ops.data(), Ops.size());
1872 cast<MachineSDNode>(VStB)->setMemRefs(MemOp, MemOp + 1);
1873 return VStB;
Bob Wilson24f995d2009-10-14 18:32:29 +00001874}
1875
Dan Gohmaneeb3a002010-01-05 01:24:18 +00001876SDNode *ARMDAGToDAGISel::SelectVLDSTLane(SDNode *N, bool IsLoad,
Bob Wilson1c3ef902011-02-07 17:43:21 +00001877 bool isUpdating, unsigned NumVecs,
Craig Topper51f50c12012-05-24 05:17:00 +00001878 const uint16_t *DOpcodes,
1879 const uint16_t *QOpcodes) {
Bob Wilson96493442009-10-14 16:46:45 +00001880 assert(NumVecs >=2 && NumVecs <= 4 && "VLDSTLane NumVecs out-of-range");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001881 DebugLoc dl = N->getDebugLoc();
1882
Bob Wilson226036e2010-03-20 22:13:40 +00001883 SDValue MemAddr, Align;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001884 unsigned AddrOpIdx = isUpdating ? 1 : 2;
1885 unsigned Vec0Idx = 3; // AddrOpIdx + (isUpdating ? 2 : 1)
1886 if (!SelectAddrMode6(N, N->getOperand(AddrOpIdx), MemAddr, Align))
Bob Wilsona7c397c2009-10-14 16:19:03 +00001887 return NULL;
1888
Evan Chengb58a3402011-04-19 00:04:03 +00001889 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
1890 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
1891
Bob Wilsona7c397c2009-10-14 16:19:03 +00001892 SDValue Chain = N->getOperand(0);
1893 unsigned Lane =
Bob Wilson1c3ef902011-02-07 17:43:21 +00001894 cast<ConstantSDNode>(N->getOperand(Vec0Idx + NumVecs))->getZExtValue();
1895 EVT VT = N->getOperand(Vec0Idx).getValueType();
Bob Wilsona7c397c2009-10-14 16:19:03 +00001896 bool is64BitVector = VT.is64BitVector();
1897
Bob Wilson665814b2010-11-01 23:40:51 +00001898 unsigned Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001899 if (NumVecs != 3) {
Bob Wilson665814b2010-11-01 23:40:51 +00001900 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
Bob Wilson3454ed92010-10-19 00:16:32 +00001901 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
1902 if (Alignment > NumBytes)
1903 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00001904 if (Alignment < 8 && Alignment < NumBytes)
1905 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001906 // Alignment must be a power of two; make sure of that.
1907 Alignment = (Alignment & -Alignment);
Bob Wilson665814b2010-11-01 23:40:51 +00001908 if (Alignment == 1)
1909 Alignment = 0;
Bob Wilson3454ed92010-10-19 00:16:32 +00001910 }
Bob Wilson665814b2010-11-01 23:40:51 +00001911 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
Bob Wilson3454ed92010-10-19 00:16:32 +00001912
Bob Wilsona7c397c2009-10-14 16:19:03 +00001913 unsigned OpcodeIndex;
1914 switch (VT.getSimpleVT().SimpleTy) {
Bob Wilson96493442009-10-14 16:46:45 +00001915 default: llvm_unreachable("unhandled vld/vst lane type");
Bob Wilsona7c397c2009-10-14 16:19:03 +00001916 // Double-register operations:
1917 case MVT::v8i8: OpcodeIndex = 0; break;
1918 case MVT::v4i16: OpcodeIndex = 1; break;
1919 case MVT::v2f32:
1920 case MVT::v2i32: OpcodeIndex = 2; break;
1921 // Quad-register operations:
1922 case MVT::v8i16: OpcodeIndex = 0; break;
1923 case MVT::v4f32:
1924 case MVT::v4i32: OpcodeIndex = 1; break;
1925 }
1926
Bob Wilson1c3ef902011-02-07 17:43:21 +00001927 std::vector<EVT> ResTys;
1928 if (IsLoad) {
1929 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
1930 if (!is64BitVector)
1931 ResTyElts *= 2;
1932 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(),
1933 MVT::i64, ResTyElts));
1934 }
1935 if (isUpdating)
1936 ResTys.push_back(MVT::i32);
1937 ResTys.push_back(MVT::Other);
1938
Evan Cheng47b7b9f2010-04-16 05:46:06 +00001939 SDValue Pred = getAL(CurDAG);
Bob Wilson226036e2010-03-20 22:13:40 +00001940 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Chengac0869d2009-11-21 06:21:52 +00001941
Bob Wilson1c3ef902011-02-07 17:43:21 +00001942 SmallVector<SDValue, 8> Ops;
Bob Wilsona7c397c2009-10-14 16:19:03 +00001943 Ops.push_back(MemAddr);
Jim Grosbach8a5ec862009-11-07 21:25:39 +00001944 Ops.push_back(Align);
Bob Wilson1c3ef902011-02-07 17:43:21 +00001945 if (isUpdating) {
1946 SDValue Inc = N->getOperand(AddrOpIdx + 1);
1947 Ops.push_back(isa<ConstantSDNode>(Inc.getNode()) ? Reg0 : Inc);
1948 }
Bob Wilson07f6e802010-06-16 21:34:01 +00001949
Bob Wilson8466fa12010-09-13 23:01:35 +00001950 SDValue SuperReg;
Bob Wilson1c3ef902011-02-07 17:43:21 +00001951 SDValue V0 = N->getOperand(Vec0Idx + 0);
1952 SDValue V1 = N->getOperand(Vec0Idx + 1);
Bob Wilson8466fa12010-09-13 23:01:35 +00001953 if (NumVecs == 2) {
1954 if (is64BitVector)
1955 SuperReg = SDValue(PairDRegs(MVT::v2i64, V0, V1), 0);
1956 else
1957 SuperReg = SDValue(PairQRegs(MVT::v4i64, V0, V1), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001958 } else {
Bob Wilson1c3ef902011-02-07 17:43:21 +00001959 SDValue V2 = N->getOperand(Vec0Idx + 2);
Bob Wilson8466fa12010-09-13 23:01:35 +00001960 SDValue V3 = (NumVecs == 3)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001961 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
1962 : N->getOperand(Vec0Idx + 3);
Bob Wilson8466fa12010-09-13 23:01:35 +00001963 if (is64BitVector)
1964 SuperReg = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
1965 else
1966 SuperReg = SDValue(QuadQRegs(MVT::v8i64, V0, V1, V2, V3), 0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001967 }
Bob Wilson8466fa12010-09-13 23:01:35 +00001968 Ops.push_back(SuperReg);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001969 Ops.push_back(getI32Imm(Lane));
Evan Chengac0869d2009-11-21 06:21:52 +00001970 Ops.push_back(Pred);
Bob Wilson226036e2010-03-20 22:13:40 +00001971 Ops.push_back(Reg0);
Bob Wilsona7c397c2009-10-14 16:19:03 +00001972 Ops.push_back(Chain);
1973
Bob Wilson1c3ef902011-02-07 17:43:21 +00001974 unsigned Opc = (is64BitVector ? DOpcodes[OpcodeIndex] :
1975 QOpcodes[OpcodeIndex]);
1976 SDNode *VLdLn = CurDAG->getMachineNode(Opc, dl, ResTys,
1977 Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00001978 cast<MachineSDNode>(VLdLn)->setMemRefs(MemOp, MemOp + 1);
Bob Wilson96493442009-10-14 16:46:45 +00001979 if (!IsLoad)
Bob Wilson1c3ef902011-02-07 17:43:21 +00001980 return VLdLn;
Evan Cheng7092c2b2010-05-15 01:36:29 +00001981
Bob Wilson8466fa12010-09-13 23:01:35 +00001982 // Extract the subregisters.
Bob Wilson1c3ef902011-02-07 17:43:21 +00001983 SuperReg = SDValue(VLdLn, 0);
1984 assert(ARM::dsub_7 == ARM::dsub_0+7 &&
1985 ARM::qsub_3 == ARM::qsub_0+3 && "Unexpected subreg numbering");
1986 unsigned Sub0 = is64BitVector ? ARM::dsub_0 : ARM::qsub_0;
Bob Wilson07f6e802010-06-16 21:34:01 +00001987 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
1988 ReplaceUses(SDValue(N, Vec),
Bob Wilson1c3ef902011-02-07 17:43:21 +00001989 CurDAG->getTargetExtractSubreg(Sub0 + Vec, dl, VT, SuperReg));
1990 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdLn, 1));
1991 if (isUpdating)
1992 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdLn, 2));
Bob Wilsona7c397c2009-10-14 16:19:03 +00001993 return NULL;
1994}
1995
Bob Wilson1c3ef902011-02-07 17:43:21 +00001996SDNode *ARMDAGToDAGISel::SelectVLDDup(SDNode *N, bool isUpdating,
Craig Topper51f50c12012-05-24 05:17:00 +00001997 unsigned NumVecs,
1998 const uint16_t *Opcodes) {
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00001999 assert(NumVecs >=2 && NumVecs <= 4 && "VLDDup NumVecs out-of-range");
2000 DebugLoc dl = N->getDebugLoc();
2001
2002 SDValue MemAddr, Align;
2003 if (!SelectAddrMode6(N, N->getOperand(1), MemAddr, Align))
2004 return NULL;
2005
Evan Chengb58a3402011-04-19 00:04:03 +00002006 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2007 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
2008
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002009 SDValue Chain = N->getOperand(0);
2010 EVT VT = N->getValueType(0);
2011
2012 unsigned Alignment = 0;
2013 if (NumVecs != 3) {
2014 Alignment = cast<ConstantSDNode>(Align)->getZExtValue();
2015 unsigned NumBytes = NumVecs * VT.getVectorElementType().getSizeInBits()/8;
2016 if (Alignment > NumBytes)
2017 Alignment = NumBytes;
Bob Wilsona92bac62010-12-10 19:37:42 +00002018 if (Alignment < 8 && Alignment < NumBytes)
2019 Alignment = 0;
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002020 // Alignment must be a power of two; make sure of that.
2021 Alignment = (Alignment & -Alignment);
2022 if (Alignment == 1)
2023 Alignment = 0;
2024 }
2025 Align = CurDAG->getTargetConstant(Alignment, MVT::i32);
2026
2027 unsigned OpcodeIndex;
2028 switch (VT.getSimpleVT().SimpleTy) {
2029 default: llvm_unreachable("unhandled vld-dup type");
2030 case MVT::v8i8: OpcodeIndex = 0; break;
2031 case MVT::v4i16: OpcodeIndex = 1; break;
2032 case MVT::v2f32:
2033 case MVT::v2i32: OpcodeIndex = 2; break;
2034 }
2035
2036 SDValue Pred = getAL(CurDAG);
2037 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2038 SDValue SuperReg;
2039 unsigned Opc = Opcodes[OpcodeIndex];
Bob Wilson1c3ef902011-02-07 17:43:21 +00002040 SmallVector<SDValue, 6> Ops;
2041 Ops.push_back(MemAddr);
2042 Ops.push_back(Align);
2043 if (isUpdating) {
Jim Grosbache6949b12011-12-21 19:40:55 +00002044 // fixed-stride update instructions don't have an explicit writeback
2045 // operand. It's implicit in the opcode itself.
Bob Wilson1c3ef902011-02-07 17:43:21 +00002046 SDValue Inc = N->getOperand(2);
Jim Grosbache6949b12011-12-21 19:40:55 +00002047 if (!isa<ConstantSDNode>(Inc.getNode()))
2048 Ops.push_back(Inc);
2049 // FIXME: VLD3 and VLD4 haven't been updated to that form yet.
2050 else if (NumVecs > 2)
2051 Ops.push_back(Reg0);
Bob Wilson1c3ef902011-02-07 17:43:21 +00002052 }
2053 Ops.push_back(Pred);
2054 Ops.push_back(Reg0);
2055 Ops.push_back(Chain);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002056
2057 unsigned ResTyElts = (NumVecs == 3) ? 4 : NumVecs;
Bob Wilson1c3ef902011-02-07 17:43:21 +00002058 std::vector<EVT> ResTys;
Evan Chengb58a3402011-04-19 00:04:03 +00002059 ResTys.push_back(EVT::getVectorVT(*CurDAG->getContext(), MVT::i64,ResTyElts));
Bob Wilson1c3ef902011-02-07 17:43:21 +00002060 if (isUpdating)
2061 ResTys.push_back(MVT::i32);
2062 ResTys.push_back(MVT::Other);
2063 SDNode *VLdDup =
2064 CurDAG->getMachineNode(Opc, dl, ResTys, Ops.data(), Ops.size());
Evan Chengb58a3402011-04-19 00:04:03 +00002065 cast<MachineSDNode>(VLdDup)->setMemRefs(MemOp, MemOp + 1);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002066 SuperReg = SDValue(VLdDup, 0);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002067
2068 // Extract the subregisters.
2069 assert(ARM::dsub_7 == ARM::dsub_0+7 && "Unexpected subreg numbering");
2070 unsigned SubIdx = ARM::dsub_0;
2071 for (unsigned Vec = 0; Vec < NumVecs; ++Vec)
2072 ReplaceUses(SDValue(N, Vec),
2073 CurDAG->getTargetExtractSubreg(SubIdx+Vec, dl, VT, SuperReg));
Bob Wilson1c3ef902011-02-07 17:43:21 +00002074 ReplaceUses(SDValue(N, NumVecs), SDValue(VLdDup, 1));
2075 if (isUpdating)
2076 ReplaceUses(SDValue(N, NumVecs + 1), SDValue(VLdDup, 2));
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002077 return NULL;
2078}
2079
Bob Wilson78dfbc32010-07-07 00:08:54 +00002080SDNode *ARMDAGToDAGISel::SelectVTBL(SDNode *N, bool IsExt, unsigned NumVecs,
2081 unsigned Opc) {
Bob Wilsond491d6e2010-07-06 23:36:25 +00002082 assert(NumVecs >= 2 && NumVecs <= 4 && "VTBL NumVecs out-of-range");
2083 DebugLoc dl = N->getDebugLoc();
2084 EVT VT = N->getValueType(0);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002085 unsigned FirstTblReg = IsExt ? 2 : 1;
Bob Wilsond491d6e2010-07-06 23:36:25 +00002086
2087 // Form a REG_SEQUENCE to force register allocation.
2088 SDValue RegSeq;
Bob Wilson78dfbc32010-07-07 00:08:54 +00002089 SDValue V0 = N->getOperand(FirstTblReg + 0);
2090 SDValue V1 = N->getOperand(FirstTblReg + 1);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002091 if (NumVecs == 2)
2092 RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
2093 else {
Bob Wilson78dfbc32010-07-07 00:08:54 +00002094 SDValue V2 = N->getOperand(FirstTblReg + 2);
Jim Grosbach3ab56582010-10-21 19:38:40 +00002095 // If it's a vtbl3, form a quad D-register and leave the last part as
Bob Wilsond491d6e2010-07-06 23:36:25 +00002096 // an undef.
2097 SDValue V3 = (NumVecs == 3)
2098 ? SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, VT), 0)
Bob Wilson78dfbc32010-07-07 00:08:54 +00002099 : N->getOperand(FirstTblReg + 3);
Bob Wilsond491d6e2010-07-06 23:36:25 +00002100 RegSeq = SDValue(QuadDRegs(MVT::v4i64, V0, V1, V2, V3), 0);
2101 }
2102
Bob Wilson78dfbc32010-07-07 00:08:54 +00002103 SmallVector<SDValue, 6> Ops;
2104 if (IsExt)
2105 Ops.push_back(N->getOperand(1));
Bob Wilsonbd916c52010-09-13 23:55:10 +00002106 Ops.push_back(RegSeq);
Bob Wilson78dfbc32010-07-07 00:08:54 +00002107 Ops.push_back(N->getOperand(FirstTblReg + NumVecs));
Bob Wilsond491d6e2010-07-06 23:36:25 +00002108 Ops.push_back(getAL(CurDAG)); // predicate
2109 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // predicate register
Bob Wilson78dfbc32010-07-07 00:08:54 +00002110 return CurDAG->getMachineNode(Opc, dl, VT, Ops.data(), Ops.size());
Bob Wilsond491d6e2010-07-06 23:36:25 +00002111}
2112
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002113SDNode *ARMDAGToDAGISel::SelectV6T2BitfieldExtractOp(SDNode *N,
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002114 bool isSigned) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002115 if (!Subtarget->hasV6T2Ops())
2116 return NULL;
Bob Wilson96493442009-10-14 16:46:45 +00002117
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002118 unsigned Opc = isSigned ? (Subtarget->isThumb() ? ARM::t2SBFX : ARM::SBFX)
2119 : (Subtarget->isThumb() ? ARM::t2UBFX : ARM::UBFX);
2120
2121
2122 // For unsigned extracts, check for a shift right and mask
2123 unsigned And_imm = 0;
2124 if (N->getOpcode() == ISD::AND) {
2125 if (isOpcWithIntImmediate(N, ISD::AND, And_imm)) {
2126
2127 // The immediate is a mask of the low bits iff imm & (imm+1) == 0
2128 if (And_imm & (And_imm + 1))
2129 return NULL;
2130
2131 unsigned Srl_imm = 0;
2132 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SRL,
2133 Srl_imm)) {
2134 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
2135
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002136 // Note: The width operand is encoded as width-1.
2137 unsigned Width = CountTrailingOnes_32(And_imm) - 1;
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002138 unsigned LSB = Srl_imm;
2139 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2140 SDValue Ops[] = { N->getOperand(0).getOperand(0),
2141 CurDAG->getTargetConstant(LSB, MVT::i32),
2142 CurDAG->getTargetConstant(Width, MVT::i32),
2143 getAL(CurDAG), Reg0 };
2144 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
2145 }
2146 }
2147 return NULL;
2148 }
2149
2150 // Otherwise, we're looking for a shift of a shift
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002151 unsigned Shl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002152 if (isOpcWithIntImmediate(N->getOperand(0).getNode(), ISD::SHL, Shl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002153 assert(Shl_imm > 0 && Shl_imm < 32 && "bad amount in shift node!");
2154 unsigned Srl_imm = 0;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002155 if (isInt32Immediate(N->getOperand(1), Srl_imm)) {
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002156 assert(Srl_imm > 0 && Srl_imm < 32 && "bad amount in shift node!");
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002157 // Note: The width operand is encoded as width-1.
2158 unsigned Width = 32 - Srl_imm - 1;
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002159 int LSB = Srl_imm - Shl_imm;
Evan Cheng8000c6c2009-10-22 00:40:00 +00002160 if (LSB < 0)
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002161 return NULL;
2162 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002163 SDValue Ops[] = { N->getOperand(0).getOperand(0),
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002164 CurDAG->getTargetConstant(LSB, MVT::i32),
2165 CurDAG->getTargetConstant(Width, MVT::i32),
2166 getAL(CurDAG), Reg0 };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002167 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002168 }
2169 }
2170 return NULL;
2171}
2172
Evan Cheng9ef48352009-11-20 00:54:03 +00002173SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002174SelectT2CMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002175 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2176 SDValue CPTmp0;
2177 SDValue CPTmp1;
Chris Lattner52a261b2010-09-21 20:31:19 +00002178 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002179 unsigned SOVal = cast<ConstantSDNode>(CPTmp1)->getZExtValue();
2180 unsigned SOShOp = ARM_AM::getSORegShOp(SOVal);
2181 unsigned Opc = 0;
2182 switch (SOShOp) {
2183 case ARM_AM::lsl: Opc = ARM::t2MOVCClsl; break;
2184 case ARM_AM::lsr: Opc = ARM::t2MOVCClsr; break;
2185 case ARM_AM::asr: Opc = ARM::t2MOVCCasr; break;
2186 case ARM_AM::ror: Opc = ARM::t2MOVCCror; break;
2187 default:
2188 llvm_unreachable("Unknown so_reg opcode!");
Evan Cheng9ef48352009-11-20 00:54:03 +00002189 }
2190 SDValue SOShImm =
2191 CurDAG->getTargetConstant(ARM_AM::getSORegOffset(SOVal), MVT::i32);
2192 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2193 SDValue Ops[] = { FalseVal, CPTmp0, SOShImm, CC, CCR, InFlag };
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002194 return CurDAG->SelectNodeTo(N, Opc, MVT::i32,Ops, 6);
Evan Cheng9ef48352009-11-20 00:54:03 +00002195 }
2196 return 0;
2197}
2198
2199SDNode *ARMDAGToDAGISel::
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002200SelectARMCMOVShiftOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002201 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
2202 SDValue CPTmp0;
2203 SDValue CPTmp1;
2204 SDValue CPTmp2;
Owen Anderson152d4a42011-07-21 23:38:37 +00002205 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002206 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
Owen Andersone0a03142011-07-22 18:30:30 +00002207 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, InFlag };
2208 return CurDAG->SelectNodeTo(N, ARM::MOVCCsi, MVT::i32, Ops, 6);
Owen Anderson92a20222011-07-21 18:54:16 +00002209 }
2210
2211 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2212 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2213 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, InFlag };
2214 return CurDAG->SelectNodeTo(N, ARM::MOVCCsr, MVT::i32, Ops, 7);
Evan Cheng9ef48352009-11-20 00:54:03 +00002215 }
2216 return 0;
2217}
2218
2219SDNode *ARMDAGToDAGISel::
Jim Grosbacha4257162010-10-07 00:53:56 +00002220SelectT2CMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002221 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002222 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
Evan Chengff96b632010-11-19 23:01:16 +00002223 if (!T)
Evan Cheng9ef48352009-11-20 00:54:03 +00002224 return 0;
2225
Evan Cheng63f35442010-11-13 02:25:14 +00002226 unsigned Opc = 0;
Jim Grosbacha4257162010-10-07 00:53:56 +00002227 unsigned TrueImm = T->getZExtValue();
Evan Cheng6b194912010-11-17 20:56:30 +00002228 if (is_t2_so_imm(TrueImm)) {
2229 Opc = ARM::t2MOVCCi;
2230 } else if (TrueImm <= 0xffff) {
2231 Opc = ARM::t2MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002232 } else if (is_t2_so_imm_not(TrueImm)) {
2233 TrueImm = ~TrueImm;
2234 Opc = ARM::t2MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002235 } else if (TrueVal.getNode()->hasOneUse() && Subtarget->hasV6T2Ops()) {
Evan Cheng63f35442010-11-13 02:25:14 +00002236 // Large immediate.
2237 Opc = ARM::t2MOVCCi32imm;
2238 }
2239
2240 if (Opc) {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002241 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002242 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2243 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002244 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002245 }
Evan Cheng63f35442010-11-13 02:25:14 +00002246
Evan Cheng9ef48352009-11-20 00:54:03 +00002247 return 0;
2248}
2249
2250SDNode *ARMDAGToDAGISel::
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002251SelectARMCMOVImmOp(SDNode *N, SDValue FalseVal, SDValue TrueVal,
Evan Cheng6b194912010-11-17 20:56:30 +00002252 ARMCC::CondCodes CCVal, SDValue CCR, SDValue InFlag) {
Evan Cheng9ef48352009-11-20 00:54:03 +00002253 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2254 if (!T)
2255 return 0;
2256
Evan Cheng63f35442010-11-13 02:25:14 +00002257 unsigned Opc = 0;
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002258 unsigned TrueImm = T->getZExtValue();
Evan Cheng875a6ac2010-11-12 22:42:47 +00002259 bool isSoImm = is_so_imm(TrueImm);
Evan Cheng6b194912010-11-17 20:56:30 +00002260 if (isSoImm) {
2261 Opc = ARM::MOVCCi;
2262 } else if (Subtarget->hasV6T2Ops() && TrueImm <= 0xffff) {
2263 Opc = ARM::MOVCCi16;
Evan Cheng63f35442010-11-13 02:25:14 +00002264 } else if (is_so_imm_not(TrueImm)) {
2265 TrueImm = ~TrueImm;
2266 Opc = ARM::MVNCCi;
Evan Cheng6b194912010-11-17 20:56:30 +00002267 } else if (TrueVal.getNode()->hasOneUse() &&
2268 (Subtarget->hasV6T2Ops() || ARM_AM::isSOImmTwoPartVal(TrueImm))) {
Evan Cheng63f35442010-11-13 02:25:14 +00002269 // Large immediate.
2270 Opc = ARM::MOVCCi32imm;
2271 }
2272
2273 if (Opc) {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002274 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
Evan Cheng9ef48352009-11-20 00:54:03 +00002275 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2276 SDValue Ops[] = { FalseVal, True, CC, CCR, InFlag };
Evan Cheng63f35442010-11-13 02:25:14 +00002277 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Cheng9ef48352009-11-20 00:54:03 +00002278 }
Andrew Trick6e8f4c42010-12-24 04:28:06 +00002279
Evan Cheng9ef48352009-11-20 00:54:03 +00002280 return 0;
2281}
2282
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002283SDNode *ARMDAGToDAGISel::SelectCMOVOp(SDNode *N) {
2284 EVT VT = N->getValueType(0);
2285 SDValue FalseVal = N->getOperand(0);
2286 SDValue TrueVal = N->getOperand(1);
2287 SDValue CC = N->getOperand(2);
2288 SDValue CCR = N->getOperand(3);
2289 SDValue InFlag = N->getOperand(4);
Evan Cheng9ef48352009-11-20 00:54:03 +00002290 assert(CC.getOpcode() == ISD::Constant);
2291 assert(CCR.getOpcode() == ISD::Register);
2292 ARMCC::CondCodes CCVal =
2293 (ARMCC::CondCodes)cast<ConstantSDNode>(CC)->getZExtValue();
Evan Cheng07ba9062009-11-19 21:45:22 +00002294
2295 if (!Subtarget->isThumb1Only() && VT == MVT::i32) {
2296 // Pattern: (ARMcmov:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2297 // Emits: (MOVCCs:i32 GPR:i32:$false, so_reg:i32:$true, (imm:i32):$cc)
2298 // Pattern complexity = 18 cost = 1 size = 0
Evan Cheng07ba9062009-11-19 21:45:22 +00002299 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002300 SDNode *Res = SelectT2CMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002301 CCVal, CCR, InFlag);
2302 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002303 Res = SelectT2CMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002304 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2305 if (Res)
2306 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002307 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002308 SDNode *Res = SelectARMCMOVShiftOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002309 CCVal, CCR, InFlag);
2310 if (!Res)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002311 Res = SelectARMCMOVShiftOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002312 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2313 if (Res)
2314 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002315 }
2316
2317 // Pattern: (ARMcmov:i32 GPR:i32:$false,
Jakob Stoklund Olesen00d3dda2010-08-17 20:39:04 +00002318 // (imm:i32)<<P:Pred_so_imm>>:$true,
Evan Cheng07ba9062009-11-19 21:45:22 +00002319 // (imm:i32):$cc)
2320 // Emits: (MOVCCi:i32 GPR:i32:$false,
2321 // (so_imm:i32 (imm:i32):$true), (imm:i32):$cc)
2322 // Pattern complexity = 10 cost = 1 size = 0
Evan Cheng9ef48352009-11-20 00:54:03 +00002323 if (Subtarget->isThumb()) {
Jim Grosbacha4257162010-10-07 00:53:56 +00002324 SDNode *Res = SelectT2CMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002325 CCVal, CCR, InFlag);
2326 if (!Res)
Jim Grosbacha4257162010-10-07 00:53:56 +00002327 Res = SelectT2CMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002328 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2329 if (Res)
2330 return Res;
2331 } else {
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002332 SDNode *Res = SelectARMCMOVImmOp(N, FalseVal, TrueVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002333 CCVal, CCR, InFlag);
2334 if (!Res)
Jim Grosbach3bbdcea2010-10-07 00:42:42 +00002335 Res = SelectARMCMOVImmOp(N, TrueVal, FalseVal,
Evan Cheng9ef48352009-11-20 00:54:03 +00002336 ARMCC::getOppositeCondition(CCVal), CCR, InFlag);
2337 if (Res)
2338 return Res;
Evan Cheng07ba9062009-11-19 21:45:22 +00002339 }
2340 }
2341
2342 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2343 // Emits: (MOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2344 // Pattern complexity = 6 cost = 1 size = 0
2345 //
2346 // Pattern: (ARMcmov:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2347 // Emits: (tMOVCCr:i32 GPR:i32:$false, GPR:i32:$true, (imm:i32):$cc)
2348 // Pattern complexity = 6 cost = 11 size = 0
2349 //
Jim Grosbach3c5edaa2011-03-11 23:15:02 +00002350 // Also VMOVScc and VMOVDcc.
Evan Cheng9ef48352009-11-20 00:54:03 +00002351 SDValue Tmp2 = CurDAG->getTargetConstant(CCVal, MVT::i32);
2352 SDValue Ops[] = { FalseVal, TrueVal, Tmp2, CCR, InFlag };
Evan Cheng07ba9062009-11-19 21:45:22 +00002353 unsigned Opc = 0;
2354 switch (VT.getSimpleVT().SimpleTy) {
Craig Topperbc219812012-02-07 02:50:20 +00002355 default: llvm_unreachable("Illegal conditional move type!");
Evan Cheng07ba9062009-11-19 21:45:22 +00002356 case MVT::i32:
2357 Opc = Subtarget->isThumb()
2358 ? (Subtarget->hasThumb2() ? ARM::t2MOVCCr : ARM::tMOVCCr_pseudo)
2359 : ARM::MOVCCr;
2360 break;
2361 case MVT::f32:
2362 Opc = ARM::VMOVScc;
2363 break;
2364 case MVT::f64:
2365 Opc = ARM::VMOVDcc;
2366 break;
2367 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002368 return CurDAG->SelectNodeTo(N, Opc, VT, Ops, 5);
Evan Cheng07ba9062009-11-19 21:45:22 +00002369}
2370
Evan Chengc892aeb2012-02-23 01:19:06 +00002371SDNode *ARMDAGToDAGISel::SelectConditionalOp(SDNode *N) {
Evan Chengc892aeb2012-02-23 01:19:06 +00002372 SDValue FalseVal = N->getOperand(0);
2373 SDValue TrueVal = N->getOperand(1);
2374 ARMCC::CondCodes CCVal =
2375 (ARMCC::CondCodes)cast<ConstantSDNode>(N->getOperand(2))->getZExtValue();
2376 SDValue CCR = N->getOperand(3);
2377 assert(CCR.getOpcode() == ISD::Register);
2378 SDValue InFlag = N->getOperand(4);
2379 SDValue CC = CurDAG->getTargetConstant(CCVal, MVT::i32);
2380 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
2381
2382 if (Subtarget->isThumb()) {
2383 SDValue CPTmp0;
2384 SDValue CPTmp1;
2385 if (SelectT2ShifterOperandReg(TrueVal, CPTmp0, CPTmp1)) {
2386 unsigned Opc;
2387 switch (N->getOpcode()) {
2388 default: llvm_unreachable("Unexpected node");
2389 case ARMISD::CAND: Opc = ARM::t2ANDCCrs; break;
2390 case ARMISD::COR: Opc = ARM::t2ORRCCrs; break;
2391 case ARMISD::CXOR: Opc = ARM::t2EORCCrs; break;
2392 }
2393 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CC, CCR, Reg0, InFlag };
2394 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 7);
2395 }
2396
2397 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2398 if (T) {
2399 unsigned TrueImm = T->getZExtValue();
2400 if (is_t2_so_imm(TrueImm)) {
2401 unsigned Opc;
2402 switch (N->getOpcode()) {
2403 default: llvm_unreachable("Unexpected node");
2404 case ARMISD::CAND: Opc = ARM::t2ANDCCri; break;
2405 case ARMISD::COR: Opc = ARM::t2ORRCCri; break;
2406 case ARMISD::CXOR: Opc = ARM::t2EORCCri; break;
2407 }
2408 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
2409 SDValue Ops[] = { FalseVal, True, CC, CCR, Reg0, InFlag };
2410 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 6);
2411 }
2412 }
2413
2414 unsigned Opc;
2415 switch (N->getOpcode()) {
2416 default: llvm_unreachable("Unexpected node");
2417 case ARMISD::CAND: Opc = ARM::t2ANDCCrr; break;
2418 case ARMISD::COR: Opc = ARM::t2ORRCCrr; break;
2419 case ARMISD::CXOR: Opc = ARM::t2EORCCrr; break;
2420 }
2421 SDValue Ops[] = { FalseVal, TrueVal, CC, CCR, Reg0, InFlag };
2422 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 6);
2423 }
2424
2425 SDValue CPTmp0;
2426 SDValue CPTmp1;
2427 SDValue CPTmp2;
2428 if (SelectImmShifterOperand(TrueVal, CPTmp0, CPTmp2)) {
2429 unsigned Opc;
2430 switch (N->getOpcode()) {
2431 default: llvm_unreachable("Unexpected node");
2432 case ARMISD::CAND: Opc = ARM::ANDCCrsi; break;
2433 case ARMISD::COR: Opc = ARM::ORRCCrsi; break;
2434 case ARMISD::CXOR: Opc = ARM::EORCCrsi; break;
2435 }
2436 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp2, CC, CCR, Reg0, InFlag };
2437 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 7);
2438 }
2439
2440 if (SelectRegShifterOperand(TrueVal, CPTmp0, CPTmp1, CPTmp2)) {
2441 unsigned Opc;
2442 switch (N->getOpcode()) {
2443 default: llvm_unreachable("Unexpected node");
2444 case ARMISD::CAND: Opc = ARM::ANDCCrsr; break;
2445 case ARMISD::COR: Opc = ARM::ORRCCrsr; break;
2446 case ARMISD::CXOR: Opc = ARM::EORCCrsr; break;
2447 }
2448 SDValue Ops[] = { FalseVal, CPTmp0, CPTmp1, CPTmp2, CC, CCR, Reg0, InFlag };
2449 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 8);
2450 }
2451
2452 ConstantSDNode *T = dyn_cast<ConstantSDNode>(TrueVal);
2453 if (T) {
2454 unsigned TrueImm = T->getZExtValue();
2455 if (is_so_imm(TrueImm)) {
2456 unsigned Opc;
2457 switch (N->getOpcode()) {
2458 default: llvm_unreachable("Unexpected node");
2459 case ARMISD::CAND: Opc = ARM::ANDCCri; break;
2460 case ARMISD::COR: Opc = ARM::ORRCCri; break;
2461 case ARMISD::CXOR: Opc = ARM::EORCCri; break;
2462 }
2463 SDValue True = CurDAG->getTargetConstant(TrueImm, MVT::i32);
2464 SDValue Ops[] = { FalseVal, True, CC, CCR, Reg0, InFlag };
2465 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 6);
2466 }
2467 }
2468
2469 unsigned Opc;
2470 switch (N->getOpcode()) {
2471 default: llvm_unreachable("Unexpected node");
2472 case ARMISD::CAND: Opc = ARM::ANDCCrr; break;
2473 case ARMISD::COR: Opc = ARM::ORRCCrr; break;
2474 case ARMISD::CXOR: Opc = ARM::EORCCrr; break;
2475 }
2476 SDValue Ops[] = { FalseVal, TrueVal, CC, CCR, Reg0, InFlag };
2477 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 6);
2478}
2479
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002480/// Target-specific DAG combining for ISD::XOR.
2481/// Target-independent combining lowers SELECT_CC nodes of the form
2482/// select_cc setg[ge] X, 0, X, -X
2483/// select_cc setgt X, -1, X, -X
2484/// select_cc setl[te] X, 0, -X, X
2485/// select_cc setlt X, 1, -X, X
2486/// which represent Integer ABS into:
2487/// Y = sra (X, size(X)-1); xor (add (X, Y), Y)
2488/// ARM instruction selection detects the latter and matches it to
2489/// ARM::ABS or ARM::t2ABS machine node.
2490SDNode *ARMDAGToDAGISel::SelectABSOp(SDNode *N){
2491 SDValue XORSrc0 = N->getOperand(0);
2492 SDValue XORSrc1 = N->getOperand(1);
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002493 EVT VT = N->getValueType(0);
2494
2495 if (DisableARMIntABS)
2496 return NULL;
2497
2498 if (Subtarget->isThumb1Only())
2499 return NULL;
2500
2501 if (XORSrc0.getOpcode() != ISD::ADD ||
2502 XORSrc1.getOpcode() != ISD::SRA)
2503 return NULL;
2504
2505 SDValue ADDSrc0 = XORSrc0.getOperand(0);
2506 SDValue ADDSrc1 = XORSrc0.getOperand(1);
2507 SDValue SRASrc0 = XORSrc1.getOperand(0);
2508 SDValue SRASrc1 = XORSrc1.getOperand(1);
2509 ConstantSDNode *SRAConstant = dyn_cast<ConstantSDNode>(SRASrc1);
2510 EVT XType = SRASrc0.getValueType();
2511 unsigned Size = XType.getSizeInBits() - 1;
2512
2513 if (ADDSrc1 == XORSrc1 &&
2514 ADDSrc0 == SRASrc0 &&
2515 XType.isInteger() &&
2516 SRAConstant != NULL &&
2517 Size == SRAConstant->getZExtValue()) {
2518
2519 unsigned Opcode = ARM::ABS;
2520 if (Subtarget->isThumb2())
2521 Opcode = ARM::t2ABS;
2522
2523 return CurDAG->SelectNodeTo(N, Opcode, VT, ADDSrc0);
2524 }
2525
2526 return NULL;
2527}
2528
Evan Chengde8aa4e2010-05-05 18:28:36 +00002529SDNode *ARMDAGToDAGISel::SelectConcatVector(SDNode *N) {
2530 // The only time a CONCAT_VECTORS operation can have legal types is when
2531 // two 64-bit vectors are concatenated to a 128-bit vector.
2532 EVT VT = N->getValueType(0);
2533 if (!VT.is128BitVector() || N->getNumOperands() != 2)
2534 llvm_unreachable("unexpected CONCAT_VECTORS");
Bob Wilsona1f544b2010-12-17 01:21:08 +00002535 return PairDRegs(VT, N->getOperand(0), N->getOperand(1));
Evan Chengde8aa4e2010-05-05 18:28:36 +00002536}
2537
Eli Friedman2bdffe42011-08-31 00:31:29 +00002538SDNode *ARMDAGToDAGISel::SelectAtomic64(SDNode *Node, unsigned Opc) {
Eli Friedman4d3f3292011-08-31 17:52:22 +00002539 SmallVector<SDValue, 6> Ops;
2540 Ops.push_back(Node->getOperand(1)); // Ptr
2541 Ops.push_back(Node->getOperand(2)); // Low part of Val1
2542 Ops.push_back(Node->getOperand(3)); // High part of Val1
Owen Andersond84192f2011-08-31 20:00:11 +00002543 if (Opc == ARM::ATOMCMPXCHG6432) {
Eli Friedman4d3f3292011-08-31 17:52:22 +00002544 Ops.push_back(Node->getOperand(4)); // Low part of Val2
2545 Ops.push_back(Node->getOperand(5)); // High part of Val2
2546 }
2547 Ops.push_back(Node->getOperand(0)); // Chain
Eli Friedman2bdffe42011-08-31 00:31:29 +00002548 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
2549 MemOp[0] = cast<MemSDNode>(Node)->getMemOperand();
Eli Friedman2bdffe42011-08-31 00:31:29 +00002550 SDNode *ResNode = CurDAG->getMachineNode(Opc, Node->getDebugLoc(),
Eli Friedman4d3f3292011-08-31 17:52:22 +00002551 MVT::i32, MVT::i32, MVT::Other,
2552 Ops.data() ,Ops.size());
Eli Friedman2bdffe42011-08-31 00:31:29 +00002553 cast<MachineSDNode>(ResNode)->setMemRefs(MemOp, MemOp + 1);
2554 return ResNode;
2555}
2556
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002557SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
Dale Johannesened2eee62009-02-06 01:31:28 +00002558 DebugLoc dl = N->getDebugLoc();
Evan Chenga8e29892007-01-19 07:51:42 +00002559
Dan Gohmane8be6c62008-07-17 19:10:17 +00002560 if (N->isMachineOpcode())
Evan Chenga8e29892007-01-19 07:51:42 +00002561 return NULL; // Already selected.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002562
2563 switch (N->getOpcode()) {
Evan Chenga8e29892007-01-19 07:51:42 +00002564 default: break;
Bill Wendlingef2c86f2011-10-10 22:59:55 +00002565 case ISD::XOR: {
2566 // Select special operations if XOR node forms integer ABS pattern
2567 SDNode *ResNode = SelectABSOp(N);
2568 if (ResNode)
2569 return ResNode;
2570 // Other cases are autogenerated.
2571 break;
2572 }
Evan Chenga8e29892007-01-19 07:51:42 +00002573 case ISD::Constant: {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002574 unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002575 bool UseCP = true;
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002576 if (Subtarget->hasThumb2())
2577 // Thumb2-aware targets have the MOVT instruction, so all immediates can
2578 // be done with MOV + MOVT, at worst.
2579 UseCP = 0;
2580 else {
2581 if (Subtarget->isThumb()) {
Bob Wilsone64e3cf2009-06-22 17:29:13 +00002582 UseCP = (Val > 255 && // MOV
2583 ~Val > 255 && // MOV + MVN
2584 !ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
Anton Korobeynikov6a2fa322009-09-27 23:52:58 +00002585 } else
2586 UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2587 ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2588 !ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2589 }
2590
Evan Chenga8e29892007-01-19 07:51:42 +00002591 if (UseCP) {
Dan Gohman475871a2008-07-27 21:46:04 +00002592 SDValue CPIdx =
Owen Anderson1d0be152009-08-13 21:58:54 +00002593 CurDAG->getTargetConstantPool(ConstantInt::get(
2594 Type::getInt32Ty(*CurDAG->getContext()), Val),
Evan Chenga8e29892007-01-19 07:51:42 +00002595 TLI.getPointerTy());
Evan Cheng012f2d92007-01-24 08:53:17 +00002596
2597 SDNode *ResNode;
Evan Cheng446c4282009-07-11 06:43:01 +00002598 if (Subtarget->isThumb1Only()) {
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002599 SDValue Pred = getAL(CurDAG);
Owen Anderson825b72b2009-08-11 20:47:22 +00002600 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
Evan Cheng446c4282009-07-11 06:43:01 +00002601 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
Jim Grosbach3e333632010-12-15 23:52:36 +00002602 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +00002603 Ops, 4);
Evan Cheng446c4282009-07-11 06:43:01 +00002604 } else {
Dan Gohman475871a2008-07-27 21:46:04 +00002605 SDValue Ops[] = {
Jim Grosbach764ab522009-08-11 15:33:49 +00002606 CPIdx,
Owen Anderson825b72b2009-08-11 20:47:22 +00002607 CurDAG->getTargetConstant(0, MVT::i32),
Evan Chengee568cf2007-07-05 07:15:27 +00002608 getAL(CurDAG),
Owen Anderson825b72b2009-08-11 20:47:22 +00002609 CurDAG->getRegister(0, MVT::i32),
Evan Cheng012f2d92007-01-24 08:53:17 +00002610 CurDAG->getEntryNode()
2611 };
Dan Gohman602b0c82009-09-25 18:54:59 +00002612 ResNode=CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
Jim Grosbach3e556122010-10-26 22:37:02 +00002613 Ops, 5);
Evan Cheng012f2d92007-01-24 08:53:17 +00002614 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002615 ReplaceUses(SDValue(N, 0), SDValue(ResNode, 0));
Evan Chenga8e29892007-01-19 07:51:42 +00002616 return NULL;
2617 }
Jim Grosbach764ab522009-08-11 15:33:49 +00002618
Evan Chenga8e29892007-01-19 07:51:42 +00002619 // Other cases are autogenerated.
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002620 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002621 }
Rafael Espindolaf819a492006-11-09 13:58:55 +00002622 case ISD::FrameIndex: {
Evan Chenga8e29892007-01-19 07:51:42 +00002623 // Selects to ADDri FI, 0 which in turn will become ADDri SP, imm.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002624 int FI = cast<FrameIndexSDNode>(N)->getIndex();
Dan Gohman475871a2008-07-27 21:46:04 +00002625 SDValue TFI = CurDAG->getTargetFrameIndex(FI, TLI.getPointerTy());
David Goodwinf1daf7d2009-07-08 23:10:31 +00002626 if (Subtarget->isThumb1Only()) {
Jim Grosbach5b815842011-08-24 17:46:13 +00002627 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2628 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2629 return CurDAG->SelectNodeTo(N, ARM::tADDrSPi, MVT::i32, Ops, 4);
Jim Grosbach30eae3c2009-04-07 20:34:09 +00002630 } else {
David Goodwin419c6152009-07-14 18:48:51 +00002631 unsigned Opc = ((Subtarget->isThumb() && Subtarget->hasThumb2()) ?
2632 ARM::t2ADDri : ARM::ADDri);
Owen Anderson825b72b2009-08-11 20:47:22 +00002633 SDValue Ops[] = { TFI, CurDAG->getTargetConstant(0, MVT::i32),
2634 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2635 CurDAG->getRegister(0, MVT::i32) };
2636 return CurDAG->SelectNodeTo(N, Opc, MVT::i32, Ops, 5);
Evan Chengee568cf2007-07-05 07:15:27 +00002637 }
Evan Chenga8e29892007-01-19 07:51:42 +00002638 }
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002639 case ISD::SRL:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002640 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002641 return I;
2642 break;
2643 case ISD::SRA:
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002644 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, true))
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002645 return I;
2646 break;
Evan Chenga8e29892007-01-19 07:51:42 +00002647 case ISD::MUL:
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002648 if (Subtarget->isThumb1Only())
Evan Cheng79d43262007-01-24 02:21:22 +00002649 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002650 if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002651 unsigned RHSV = C->getZExtValue();
Evan Chenga8e29892007-01-19 07:51:42 +00002652 if (!RHSV) break;
2653 if (isPowerOf2_32(RHSV-1)) { // 2^n+1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002654 unsigned ShImm = Log2_32(RHSV-1);
2655 if (ShImm >= 32)
2656 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002657 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002658 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002659 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2660 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002661 if (Subtarget->isThumb()) {
Evan Chengaf9e7a72009-07-21 00:31:12 +00002662 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson825b72b2009-08-11 20:47:22 +00002663 return CurDAG->SelectNodeTo(N, ARM::t2ADDrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002664 } else {
2665 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002666 return CurDAG->SelectNodeTo(N, ARM::ADDrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002667 }
Evan Chenga8e29892007-01-19 07:51:42 +00002668 }
2669 if (isPowerOf2_32(RHSV+1)) { // 2^n-1?
Evan Chengaf9e7a72009-07-21 00:31:12 +00002670 unsigned ShImm = Log2_32(RHSV+1);
2671 if (ShImm >= 32)
2672 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002673 SDValue V = N->getOperand(0);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002674 ShImm = ARM_AM::getSORegOpc(ARM_AM::lsl, ShImm);
Owen Anderson825b72b2009-08-11 20:47:22 +00002675 SDValue ShImmOp = CurDAG->getTargetConstant(ShImm, MVT::i32);
2676 SDValue Reg0 = CurDAG->getRegister(0, MVT::i32);
Evan Cheng78dd9db2009-07-22 18:08:05 +00002677 if (Subtarget->isThumb()) {
Bob Wilson13ef8402010-05-28 00:27:15 +00002678 SDValue Ops[] = { V, V, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
2679 return CurDAG->SelectNodeTo(N, ARM::t2RSBrs, MVT::i32, Ops, 6);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002680 } else {
2681 SDValue Ops[] = { V, V, Reg0, ShImmOp, getAL(CurDAG), Reg0, Reg0 };
Owen Anderson92a20222011-07-21 18:54:16 +00002682 return CurDAG->SelectNodeTo(N, ARM::RSBrsi, MVT::i32, Ops, 7);
Evan Chengaf9e7a72009-07-21 00:31:12 +00002683 }
Evan Chenga8e29892007-01-19 07:51:42 +00002684 }
2685 }
2686 break;
Evan Cheng20956592009-10-21 08:15:52 +00002687 case ISD::AND: {
Jim Grosbach3a1287b2010-04-22 23:24:18 +00002688 // Check for unsigned bitfield extract
2689 if (SDNode *I = SelectV6T2BitfieldExtractOp(N, false))
2690 return I;
2691
Evan Cheng20956592009-10-21 08:15:52 +00002692 // (and (or x, c2), c1) and top 16-bits of c1 and c2 match, lower 16-bits
2693 // of c1 are 0xffff, and lower 16-bit of c2 are 0. That is, the top 16-bits
2694 // are entirely contributed by c2 and lower 16-bits are entirely contributed
2695 // by x. That's equal to (or (and x, 0xffff), (and c1, 0xffff0000)).
2696 // Select it to: "movt x, ((c1 & 0xffff) >> 16)
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002697 EVT VT = N->getValueType(0);
Evan Cheng20956592009-10-21 08:15:52 +00002698 if (VT != MVT::i32)
2699 break;
2700 unsigned Opc = (Subtarget->isThumb() && Subtarget->hasThumb2())
2701 ? ARM::t2MOVTi16
2702 : (Subtarget->hasV6T2Ops() ? ARM::MOVTi16 : 0);
2703 if (!Opc)
2704 break;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002705 SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
Evan Cheng20956592009-10-21 08:15:52 +00002706 ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
2707 if (!N1C)
2708 break;
2709 if (N0.getOpcode() == ISD::OR && N0.getNode()->hasOneUse()) {
2710 SDValue N2 = N0.getOperand(1);
2711 ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2);
2712 if (!N2C)
2713 break;
2714 unsigned N1CVal = N1C->getZExtValue();
2715 unsigned N2CVal = N2C->getZExtValue();
2716 if ((N1CVal & 0xffff0000U) == (N2CVal & 0xffff0000U) &&
2717 (N1CVal & 0xffffU) == 0xffffU &&
2718 (N2CVal & 0xffffU) == 0x0U) {
2719 SDValue Imm16 = CurDAG->getTargetConstant((N2CVal & 0xFFFF0000U) >> 16,
2720 MVT::i32);
2721 SDValue Ops[] = { N0.getOperand(0), Imm16,
2722 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
2723 return CurDAG->getMachineNode(Opc, dl, VT, Ops, 4);
2724 }
2725 }
2726 break;
2727 }
Jim Grosbache5165492009-11-09 00:11:35 +00002728 case ARMISD::VMOVRRD:
2729 return CurDAG->getMachineNode(ARM::VMOVRRD, dl, MVT::i32, MVT::i32,
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002730 N->getOperand(0), getAL(CurDAG),
Dan Gohman602b0c82009-09-25 18:54:59 +00002731 CurDAG->getRegister(0, MVT::i32));
Dan Gohman525178c2007-10-08 18:33:35 +00002732 case ISD::UMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002733 if (Subtarget->isThumb1Only())
2734 break;
2735 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002736 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002737 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2738 CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002739 return CurDAG->getMachineNode(ARM::t2UMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002740 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002741 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002742 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2743 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002744 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2745 ARM::UMULL : ARM::UMULLv5,
2746 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002747 }
Evan Chengee568cf2007-07-05 07:15:27 +00002748 }
Dan Gohman525178c2007-10-08 18:33:35 +00002749 case ISD::SMUL_LOHI: {
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002750 if (Subtarget->isThumb1Only())
2751 break;
2752 if (Subtarget->isThumb()) {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002753 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002754 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32) };
Jim Grosbach18f30e62010-06-02 21:53:11 +00002755 return CurDAG->getMachineNode(ARM::t2SMULL, dl, MVT::i32, MVT::i32,Ops,4);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002756 } else {
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002757 SDValue Ops[] = { N->getOperand(0), N->getOperand(1),
Owen Anderson825b72b2009-08-11 20:47:22 +00002758 getAL(CurDAG), CurDAG->getRegister(0, MVT::i32),
2759 CurDAG->getRegister(0, MVT::i32) };
Anton Korobeynikov4d728602011-01-01 20:38:38 +00002760 return CurDAG->getMachineNode(Subtarget->hasV6Ops() ?
2761 ARM::SMULL : ARM::SMULLv5,
2762 dl, MVT::i32, MVT::i32, Ops, 5);
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002763 }
Evan Chengee568cf2007-07-05 07:15:27 +00002764 }
Evan Chenga8e29892007-01-19 07:51:42 +00002765 case ISD::LOAD: {
Evan Chenge88d5ce2009-07-02 07:28:31 +00002766 SDNode *ResNode = 0;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002767 if (Subtarget->isThumb() && Subtarget->hasThumb2())
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002768 ResNode = SelectT2IndexedLoad(N);
Evan Chenge88d5ce2009-07-02 07:28:31 +00002769 else
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002770 ResNode = SelectARMIndexedLoad(N);
Evan Chengaf4550f2009-07-02 01:23:32 +00002771 if (ResNode)
2772 return ResNode;
Evan Chenga8e29892007-01-19 07:51:42 +00002773 // Other cases are autogenerated.
Rafael Espindolaf819a492006-11-09 13:58:55 +00002774 break;
Rafael Espindola337c4ad62006-06-12 12:28:08 +00002775 }
Evan Chengee568cf2007-07-05 07:15:27 +00002776 case ARMISD::BRCOND: {
2777 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2778 // Emits: (Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2779 // Pattern complexity = 6 cost = 1 size = 0
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00002780
Evan Chengee568cf2007-07-05 07:15:27 +00002781 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2782 // Emits: (tBcc:void (bb:Other):$dst, (imm:i32):$cc)
2783 // Pattern complexity = 6 cost = 1 size = 0
2784
David Goodwin5e47a9a2009-06-30 18:04:13 +00002785 // Pattern: (ARMbrcond:void (bb:Other):$dst, (imm:i32):$cc)
2786 // Emits: (t2Bcc:void (bb:Other):$dst, (imm:i32):$cc)
2787 // Pattern complexity = 6 cost = 1 size = 0
2788
Jim Grosbach764ab522009-08-11 15:33:49 +00002789 unsigned Opc = Subtarget->isThumb() ?
David Goodwin5e47a9a2009-06-30 18:04:13 +00002790 ((Subtarget->hasThumb2()) ? ARM::t2Bcc : ARM::tBcc) : ARM::Bcc;
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002791 SDValue Chain = N->getOperand(0);
2792 SDValue N1 = N->getOperand(1);
2793 SDValue N2 = N->getOperand(2);
2794 SDValue N3 = N->getOperand(3);
2795 SDValue InFlag = N->getOperand(4);
Evan Chengee568cf2007-07-05 07:15:27 +00002796 assert(N1.getOpcode() == ISD::BasicBlock);
2797 assert(N2.getOpcode() == ISD::Constant);
2798 assert(N3.getOpcode() == ISD::Register);
2799
Dan Gohman475871a2008-07-27 21:46:04 +00002800 SDValue Tmp2 = CurDAG->getTargetConstant(((unsigned)
Dan Gohmanf5aeb1a2008-09-12 16:56:44 +00002801 cast<ConstantSDNode>(N2)->getZExtValue()),
Owen Anderson825b72b2009-08-11 20:47:22 +00002802 MVT::i32);
Dan Gohman475871a2008-07-27 21:46:04 +00002803 SDValue Ops[] = { N1, Tmp2, N3, Chain, InFlag };
Dan Gohman602b0c82009-09-25 18:54:59 +00002804 SDNode *ResNode = CurDAG->getMachineNode(Opc, dl, MVT::Other,
Chris Lattnerf1b4eaf2010-12-21 02:38:05 +00002805 MVT::Glue, Ops, 5);
Dan Gohman475871a2008-07-27 21:46:04 +00002806 Chain = SDValue(ResNode, 0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002807 if (N->getNumValues() == 2) {
Dan Gohman475871a2008-07-27 21:46:04 +00002808 InFlag = SDValue(ResNode, 1);
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002809 ReplaceUses(SDValue(N, 1), InFlag);
Chris Lattnera47b9bc2008-02-03 03:20:59 +00002810 }
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002811 ReplaceUses(SDValue(N, 0),
Evan Chenged54de42009-11-19 08:16:50 +00002812 SDValue(Chain.getNode(), Chain.getResNo()));
Evan Chengee568cf2007-07-05 07:15:27 +00002813 return NULL;
2814 }
Evan Cheng07ba9062009-11-19 21:45:22 +00002815 case ARMISD::CMOV:
Dan Gohmaneeb3a002010-01-05 01:24:18 +00002816 return SelectCMOVOp(N);
Evan Chengc892aeb2012-02-23 01:19:06 +00002817 case ARMISD::CAND:
2818 case ARMISD::COR:
2819 case ARMISD::CXOR:
2820 return SelectConditionalOp(N);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002821 case ARMISD::VZIP: {
2822 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002823 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002824 switch (VT.getSimpleVT().SimpleTy) {
2825 default: return NULL;
2826 case MVT::v8i8: Opc = ARM::VZIPd8; break;
2827 case MVT::v4i16: Opc = ARM::VZIPd16; break;
2828 case MVT::v2f32:
Jim Grosbach6073b302012-04-11 16:53:25 +00002829 // vzip.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2830 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002831 case MVT::v16i8: Opc = ARM::VZIPq8; break;
2832 case MVT::v8i16: Opc = ARM::VZIPq16; break;
2833 case MVT::v4f32:
2834 case MVT::v4i32: Opc = ARM::VZIPq32; break;
2835 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002836 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002837 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2838 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2839 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002840 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002841 case ARMISD::VUZP: {
2842 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002843 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002844 switch (VT.getSimpleVT().SimpleTy) {
2845 default: return NULL;
2846 case MVT::v8i8: Opc = ARM::VUZPd8; break;
2847 case MVT::v4i16: Opc = ARM::VUZPd16; break;
2848 case MVT::v2f32:
Jim Grosbach18355472012-04-11 17:40:18 +00002849 // vuzp.32 Dd, Dm is a pseudo-instruction expanded to vtrn.32 Dd, Dm.
2850 case MVT::v2i32: Opc = ARM::VTRNd32; break;
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002851 case MVT::v16i8: Opc = ARM::VUZPq8; break;
2852 case MVT::v8i16: Opc = ARM::VUZPq16; break;
2853 case MVT::v4f32:
2854 case MVT::v4i32: Opc = ARM::VUZPq32; break;
2855 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002856 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002857 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2858 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2859 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002860 }
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002861 case ARMISD::VTRN: {
2862 unsigned Opc = 0;
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002863 EVT VT = N->getValueType(0);
Anton Korobeynikov051cfd62009-08-21 12:41:42 +00002864 switch (VT.getSimpleVT().SimpleTy) {
2865 default: return NULL;
2866 case MVT::v8i8: Opc = ARM::VTRNd8; break;
2867 case MVT::v4i16: Opc = ARM::VTRNd16; break;
2868 case MVT::v2f32:
2869 case MVT::v2i32: Opc = ARM::VTRNd32; break;
2870 case MVT::v16i8: Opc = ARM::VTRNq8; break;
2871 case MVT::v8i16: Opc = ARM::VTRNq16; break;
2872 case MVT::v4f32:
2873 case MVT::v4i32: Opc = ARM::VTRNq32; break;
2874 }
Evan Cheng47b7b9f2010-04-16 05:46:06 +00002875 SDValue Pred = getAL(CurDAG);
Evan Chengac0869d2009-11-21 06:21:52 +00002876 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2877 SDValue Ops[] = { N->getOperand(0), N->getOperand(1), Pred, PredReg };
2878 return CurDAG->getMachineNode(Opc, dl, VT, VT, Ops, 4);
Anton Korobeynikov62e84f12009-08-21 12:40:50 +00002879 }
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002880 case ARMISD::BUILD_VECTOR: {
2881 EVT VecVT = N->getValueType(0);
2882 EVT EltVT = VecVT.getVectorElementType();
2883 unsigned NumElts = VecVT.getVectorNumElements();
Duncan Sandscdfad362010-11-03 12:17:33 +00002884 if (EltVT == MVT::f64) {
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002885 assert(NumElts == 2 && "unexpected type for BUILD_VECTOR");
2886 return PairDRegs(VecVT, N->getOperand(0), N->getOperand(1));
2887 }
Duncan Sandscdfad362010-11-03 12:17:33 +00002888 assert(EltVT == MVT::f32 && "unexpected type for BUILD_VECTOR");
Bob Wilson40cbe7d2010-06-04 00:04:02 +00002889 if (NumElts == 2)
2890 return PairSRegs(VecVT, N->getOperand(0), N->getOperand(1));
2891 assert(NumElts == 4 && "unexpected type for BUILD_VECTOR");
2892 return QuadSRegs(VecVT, N->getOperand(0), N->getOperand(1),
2893 N->getOperand(2), N->getOperand(3));
2894 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00002895
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002896 case ARMISD::VLD2DUP: {
Craig Topper51f50c12012-05-24 05:17:00 +00002897 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8, ARM::VLD2DUPd16,
2898 ARM::VLD2DUPd32 };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002899 return SelectVLDDup(N, false, 2, Opcodes);
Bob Wilsonb1dfa7a2010-11-28 06:51:26 +00002900 }
2901
Bob Wilson86c6d802010-11-29 19:35:29 +00002902 case ARMISD::VLD3DUP: {
Craig Topper51f50c12012-05-24 05:17:00 +00002903 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo,
2904 ARM::VLD3DUPd16Pseudo,
2905 ARM::VLD3DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002906 return SelectVLDDup(N, false, 3, Opcodes);
Bob Wilson86c6d802010-11-29 19:35:29 +00002907 }
2908
Bob Wilson6c4c9822010-11-30 00:00:35 +00002909 case ARMISD::VLD4DUP: {
Craig Topper51f50c12012-05-24 05:17:00 +00002910 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo,
2911 ARM::VLD4DUPd16Pseudo,
2912 ARM::VLD4DUPd32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002913 return SelectVLDDup(N, false, 4, Opcodes);
2914 }
2915
2916 case ARMISD::VLD2DUP_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002917 static const uint16_t Opcodes[] = { ARM::VLD2DUPd8wb_fixed,
2918 ARM::VLD2DUPd16wb_fixed,
2919 ARM::VLD2DUPd32wb_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002920 return SelectVLDDup(N, true, 2, Opcodes);
2921 }
2922
2923 case ARMISD::VLD3DUP_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002924 static const uint16_t Opcodes[] = { ARM::VLD3DUPd8Pseudo_UPD,
2925 ARM::VLD3DUPd16Pseudo_UPD,
2926 ARM::VLD3DUPd32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002927 return SelectVLDDup(N, true, 3, Opcodes);
2928 }
2929
2930 case ARMISD::VLD4DUP_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002931 static const uint16_t Opcodes[] = { ARM::VLD4DUPd8Pseudo_UPD,
2932 ARM::VLD4DUPd16Pseudo_UPD,
2933 ARM::VLD4DUPd32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002934 return SelectVLDDup(N, true, 4, Opcodes);
2935 }
2936
2937 case ARMISD::VLD1_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002938 static const uint16_t DOpcodes[] = { ARM::VLD1d8wb_fixed,
2939 ARM::VLD1d16wb_fixed,
2940 ARM::VLD1d32wb_fixed,
2941 ARM::VLD1d64wb_fixed };
2942 static const uint16_t QOpcodes[] = { ARM::VLD1q8wb_fixed,
2943 ARM::VLD1q16wb_fixed,
2944 ARM::VLD1q32wb_fixed,
2945 ARM::VLD1q64wb_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002946 return SelectVLD(N, true, 1, DOpcodes, QOpcodes, 0);
2947 }
2948
2949 case ARMISD::VLD2_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002950 static const uint16_t DOpcodes[] = { ARM::VLD2d8wb_fixed,
2951 ARM::VLD2d16wb_fixed,
2952 ARM::VLD2d32wb_fixed,
2953 ARM::VLD1q64wb_fixed};
2954 static const uint16_t QOpcodes[] = { ARM::VLD2q8PseudoWB_fixed,
2955 ARM::VLD2q16PseudoWB_fixed,
2956 ARM::VLD2q32PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002957 return SelectVLD(N, true, 2, DOpcodes, QOpcodes, 0);
2958 }
2959
2960 case ARMISD::VLD3_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002961 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo_UPD,
2962 ARM::VLD3d16Pseudo_UPD,
2963 ARM::VLD3d32Pseudo_UPD,
2964 ARM::VLD1q64wb_fixed};
2965 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
2966 ARM::VLD3q16Pseudo_UPD,
2967 ARM::VLD3q32Pseudo_UPD };
2968 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo_UPD,
2969 ARM::VLD3q16oddPseudo_UPD,
2970 ARM::VLD3q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002971 return SelectVLD(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
2972 }
2973
2974 case ARMISD::VLD4_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002975 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo_UPD,
2976 ARM::VLD4d16Pseudo_UPD,
2977 ARM::VLD4d32Pseudo_UPD,
2978 ARM::VLD1q64wb_fixed};
2979 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
2980 ARM::VLD4q16Pseudo_UPD,
2981 ARM::VLD4q32Pseudo_UPD };
2982 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo_UPD,
2983 ARM::VLD4q16oddPseudo_UPD,
2984 ARM::VLD4q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002985 return SelectVLD(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
2986 }
2987
2988 case ARMISD::VLD2LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002989 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo_UPD,
2990 ARM::VLD2LNd16Pseudo_UPD,
2991 ARM::VLD2LNd32Pseudo_UPD };
2992 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo_UPD,
2993 ARM::VLD2LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00002994 return SelectVLDSTLane(N, true, true, 2, DOpcodes, QOpcodes);
2995 }
2996
2997 case ARMISD::VLD3LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00002998 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo_UPD,
2999 ARM::VLD3LNd16Pseudo_UPD,
3000 ARM::VLD3LNd32Pseudo_UPD };
3001 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo_UPD,
3002 ARM::VLD3LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003003 return SelectVLDSTLane(N, true, true, 3, DOpcodes, QOpcodes);
3004 }
3005
3006 case ARMISD::VLD4LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00003007 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo_UPD,
3008 ARM::VLD4LNd16Pseudo_UPD,
3009 ARM::VLD4LNd32Pseudo_UPD };
3010 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo_UPD,
3011 ARM::VLD4LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003012 return SelectVLDSTLane(N, true, true, 4, DOpcodes, QOpcodes);
3013 }
3014
3015 case ARMISD::VST1_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00003016 static const uint16_t DOpcodes[] = { ARM::VST1d8wb_fixed,
3017 ARM::VST1d16wb_fixed,
3018 ARM::VST1d32wb_fixed,
3019 ARM::VST1d64wb_fixed };
3020 static const uint16_t QOpcodes[] = { ARM::VST1q8wb_fixed,
3021 ARM::VST1q16wb_fixed,
3022 ARM::VST1q32wb_fixed,
3023 ARM::VST1q64wb_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003024 return SelectVST(N, true, 1, DOpcodes, QOpcodes, 0);
3025 }
3026
3027 case ARMISD::VST2_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00003028 static const uint16_t DOpcodes[] = { ARM::VST2d8wb_fixed,
3029 ARM::VST2d16wb_fixed,
3030 ARM::VST2d32wb_fixed,
3031 ARM::VST1q64wb_fixed};
3032 static const uint16_t QOpcodes[] = { ARM::VST2q8PseudoWB_fixed,
3033 ARM::VST2q16PseudoWB_fixed,
3034 ARM::VST2q32PseudoWB_fixed };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003035 return SelectVST(N, true, 2, DOpcodes, QOpcodes, 0);
3036 }
3037
3038 case ARMISD::VST3_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00003039 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo_UPD,
3040 ARM::VST3d16Pseudo_UPD,
3041 ARM::VST3d32Pseudo_UPD,
3042 ARM::VST1d64TPseudoWB_fixed};
3043 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3044 ARM::VST3q16Pseudo_UPD,
3045 ARM::VST3q32Pseudo_UPD };
3046 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo_UPD,
3047 ARM::VST3q16oddPseudo_UPD,
3048 ARM::VST3q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003049 return SelectVST(N, true, 3, DOpcodes, QOpcodes0, QOpcodes1);
3050 }
3051
3052 case ARMISD::VST4_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00003053 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo_UPD,
3054 ARM::VST4d16Pseudo_UPD,
3055 ARM::VST4d32Pseudo_UPD,
3056 ARM::VST1d64QPseudoWB_fixed};
3057 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3058 ARM::VST4q16Pseudo_UPD,
3059 ARM::VST4q32Pseudo_UPD };
3060 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo_UPD,
3061 ARM::VST4q16oddPseudo_UPD,
3062 ARM::VST4q32oddPseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003063 return SelectVST(N, true, 4, DOpcodes, QOpcodes0, QOpcodes1);
3064 }
3065
3066 case ARMISD::VST2LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00003067 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo_UPD,
3068 ARM::VST2LNd16Pseudo_UPD,
3069 ARM::VST2LNd32Pseudo_UPD };
3070 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo_UPD,
3071 ARM::VST2LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003072 return SelectVLDSTLane(N, false, true, 2, DOpcodes, QOpcodes);
3073 }
3074
3075 case ARMISD::VST3LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00003076 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo_UPD,
3077 ARM::VST3LNd16Pseudo_UPD,
3078 ARM::VST3LNd32Pseudo_UPD };
3079 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo_UPD,
3080 ARM::VST3LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003081 return SelectVLDSTLane(N, false, true, 3, DOpcodes, QOpcodes);
3082 }
3083
3084 case ARMISD::VST4LN_UPD: {
Craig Topper51f50c12012-05-24 05:17:00 +00003085 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo_UPD,
3086 ARM::VST4LNd16Pseudo_UPD,
3087 ARM::VST4LNd32Pseudo_UPD };
3088 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo_UPD,
3089 ARM::VST4LNq32Pseudo_UPD };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003090 return SelectVLDSTLane(N, false, true, 4, DOpcodes, QOpcodes);
Bob Wilson6c4c9822010-11-30 00:00:35 +00003091 }
3092
Bob Wilson31fb12f2009-08-26 17:39:53 +00003093 case ISD::INTRINSIC_VOID:
3094 case ISD::INTRINSIC_W_CHAIN: {
3095 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue();
Bob Wilson31fb12f2009-08-26 17:39:53 +00003096 switch (IntNo) {
3097 default:
Bob Wilson429009b2010-05-06 16:05:26 +00003098 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00003099
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00003100 case Intrinsic::arm_ldrexd: {
3101 SDValue MemAddr = N->getOperand(2);
3102 DebugLoc dl = N->getDebugLoc();
3103 SDValue Chain = N->getOperand(0);
3104
3105 unsigned NewOpc = ARM::LDREXD;
3106 if (Subtarget->isThumb() && Subtarget->hasThumb2())
3107 NewOpc = ARM::t2LDREXD;
3108
3109 // arm_ldrexd returns a i64 value in {i32, i32}
3110 std::vector<EVT> ResTys;
3111 ResTys.push_back(MVT::i32);
3112 ResTys.push_back(MVT::i32);
3113 ResTys.push_back(MVT::Other);
3114
3115 // place arguments in the right order
3116 SmallVector<SDValue, 7> Ops;
3117 Ops.push_back(MemAddr);
3118 Ops.push_back(getAL(CurDAG));
3119 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3120 Ops.push_back(Chain);
3121 SDNode *Ld = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
3122 Ops.size());
3123 // Transfer memoperands.
3124 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3125 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3126 cast<MachineSDNode>(Ld)->setMemRefs(MemOp, MemOp + 1);
3127
3128 // Until there's support for specifing explicit register constraints
3129 // like the use of even/odd register pair, hardcode ldrexd to always
3130 // use the pair [R0, R1] to hold the load result.
3131 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R0,
3132 SDValue(Ld, 0), SDValue(0,0));
3133 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R1,
3134 SDValue(Ld, 1), Chain.getValue(1));
3135
3136 // Remap uses.
3137 SDValue Glue = Chain.getValue(1);
3138 if (!SDValue(N, 0).use_empty()) {
3139 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3140 ARM::R0, MVT::i32, Glue);
3141 Glue = Result.getValue(2);
3142 ReplaceUses(SDValue(N, 0), Result);
3143 }
3144 if (!SDValue(N, 1).use_empty()) {
3145 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3146 ARM::R1, MVT::i32, Glue);
3147 Glue = Result.getValue(2);
3148 ReplaceUses(SDValue(N, 1), Result);
3149 }
3150
3151 ReplaceUses(SDValue(N, 2), SDValue(Ld, 2));
3152 return NULL;
3153 }
3154
3155 case Intrinsic::arm_strexd: {
3156 DebugLoc dl = N->getDebugLoc();
3157 SDValue Chain = N->getOperand(0);
3158 SDValue Val0 = N->getOperand(2);
3159 SDValue Val1 = N->getOperand(3);
3160 SDValue MemAddr = N->getOperand(4);
3161
3162 // Until there's support for specifing explicit register constraints
3163 // like the use of even/odd register pair, hardcode strexd to always
3164 // use the pair [R2, R3] to hold the i64 (i32, i32) value to be stored.
3165 Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ARM::R2, Val0,
3166 SDValue(0, 0));
3167 Chain = CurDAG->getCopyToReg(Chain, dl, ARM::R3, Val1, Chain.getValue(1));
3168
3169 SDValue Glue = Chain.getValue(1);
3170 Val0 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3171 ARM::R2, MVT::i32, Glue);
3172 Glue = Val0.getValue(1);
3173 Val1 = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3174 ARM::R3, MVT::i32, Glue);
3175
3176 // Store exclusive double return a i32 value which is the return status
3177 // of the issued store.
3178 std::vector<EVT> ResTys;
3179 ResTys.push_back(MVT::i32);
3180 ResTys.push_back(MVT::Other);
3181
3182 // place arguments in the right order
3183 SmallVector<SDValue, 7> Ops;
3184 Ops.push_back(Val0);
3185 Ops.push_back(Val1);
3186 Ops.push_back(MemAddr);
3187 Ops.push_back(getAL(CurDAG));
3188 Ops.push_back(CurDAG->getRegister(0, MVT::i32));
3189 Ops.push_back(Chain);
3190
3191 unsigned NewOpc = ARM::STREXD;
3192 if (Subtarget->isThumb() && Subtarget->hasThumb2())
3193 NewOpc = ARM::t2STREXD;
3194
3195 SDNode *St = CurDAG->getMachineNode(NewOpc, dl, ResTys, Ops.data(),
3196 Ops.size());
3197 // Transfer memoperands.
3198 MachineSDNode::mmo_iterator MemOp = MF->allocateMemRefsArray(1);
3199 MemOp[0] = cast<MemIntrinsicSDNode>(N)->getMemOperand();
3200 cast<MachineSDNode>(St)->setMemRefs(MemOp, MemOp + 1);
3201
3202 return St;
3203 }
3204
Bob Wilson621f1952010-03-23 05:25:43 +00003205 case Intrinsic::arm_neon_vld1: {
Craig Topper51f50c12012-05-24 05:17:00 +00003206 static const uint16_t DOpcodes[] = { ARM::VLD1d8, ARM::VLD1d16,
3207 ARM::VLD1d32, ARM::VLD1d64 };
3208 static const uint16_t QOpcodes[] = { ARM::VLD1q8, ARM::VLD1q16,
3209 ARM::VLD1q32, ARM::VLD1q64};
Bob Wilson1c3ef902011-02-07 17:43:21 +00003210 return SelectVLD(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson621f1952010-03-23 05:25:43 +00003211 }
3212
Bob Wilson31fb12f2009-08-26 17:39:53 +00003213 case Intrinsic::arm_neon_vld2: {
Craig Topper51f50c12012-05-24 05:17:00 +00003214 static const uint16_t DOpcodes[] = { ARM::VLD2d8, ARM::VLD2d16,
3215 ARM::VLD2d32, ARM::VLD1q64 };
3216 static const uint16_t QOpcodes[] = { ARM::VLD2q8Pseudo, ARM::VLD2q16Pseudo,
3217 ARM::VLD2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003218 return SelectVLD(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003219 }
3220
3221 case Intrinsic::arm_neon_vld3: {
Craig Topper51f50c12012-05-24 05:17:00 +00003222 static const uint16_t DOpcodes[] = { ARM::VLD3d8Pseudo,
3223 ARM::VLD3d16Pseudo,
3224 ARM::VLD3d32Pseudo,
3225 ARM::VLD1d64TPseudo };
3226 static const uint16_t QOpcodes0[] = { ARM::VLD3q8Pseudo_UPD,
3227 ARM::VLD3q16Pseudo_UPD,
3228 ARM::VLD3q32Pseudo_UPD };
3229 static const uint16_t QOpcodes1[] = { ARM::VLD3q8oddPseudo,
3230 ARM::VLD3q16oddPseudo,
3231 ARM::VLD3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003232 return SelectVLD(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003233 }
3234
3235 case Intrinsic::arm_neon_vld4: {
Craig Topper51f50c12012-05-24 05:17:00 +00003236 static const uint16_t DOpcodes[] = { ARM::VLD4d8Pseudo,
3237 ARM::VLD4d16Pseudo,
3238 ARM::VLD4d32Pseudo,
3239 ARM::VLD1d64QPseudo };
3240 static const uint16_t QOpcodes0[] = { ARM::VLD4q8Pseudo_UPD,
3241 ARM::VLD4q16Pseudo_UPD,
3242 ARM::VLD4q32Pseudo_UPD };
3243 static const uint16_t QOpcodes1[] = { ARM::VLD4q8oddPseudo,
3244 ARM::VLD4q16oddPseudo,
3245 ARM::VLD4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003246 return SelectVLD(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003247 }
3248
Bob Wilson243fcc52009-09-01 04:26:28 +00003249 case Intrinsic::arm_neon_vld2lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003250 static const uint16_t DOpcodes[] = { ARM::VLD2LNd8Pseudo,
3251 ARM::VLD2LNd16Pseudo,
3252 ARM::VLD2LNd32Pseudo };
3253 static const uint16_t QOpcodes[] = { ARM::VLD2LNq16Pseudo,
3254 ARM::VLD2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003255 return SelectVLDSTLane(N, true, false, 2, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003256 }
3257
3258 case Intrinsic::arm_neon_vld3lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003259 static const uint16_t DOpcodes[] = { ARM::VLD3LNd8Pseudo,
3260 ARM::VLD3LNd16Pseudo,
3261 ARM::VLD3LNd32Pseudo };
3262 static const uint16_t QOpcodes[] = { ARM::VLD3LNq16Pseudo,
3263 ARM::VLD3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003264 return SelectVLDSTLane(N, true, false, 3, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003265 }
3266
3267 case Intrinsic::arm_neon_vld4lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003268 static const uint16_t DOpcodes[] = { ARM::VLD4LNd8Pseudo,
3269 ARM::VLD4LNd16Pseudo,
3270 ARM::VLD4LNd32Pseudo };
3271 static const uint16_t QOpcodes[] = { ARM::VLD4LNq16Pseudo,
3272 ARM::VLD4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003273 return SelectVLDSTLane(N, true, false, 4, DOpcodes, QOpcodes);
Bob Wilson243fcc52009-09-01 04:26:28 +00003274 }
3275
Bob Wilson11d98992010-03-23 06:20:33 +00003276 case Intrinsic::arm_neon_vst1: {
Craig Topper51f50c12012-05-24 05:17:00 +00003277 static const uint16_t DOpcodes[] = { ARM::VST1d8, ARM::VST1d16,
3278 ARM::VST1d32, ARM::VST1d64 };
3279 static const uint16_t QOpcodes[] = { ARM::VST1q8, ARM::VST1q16,
3280 ARM::VST1q32, ARM::VST1q64 };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003281 return SelectVST(N, false, 1, DOpcodes, QOpcodes, 0);
Bob Wilson11d98992010-03-23 06:20:33 +00003282 }
3283
Bob Wilson31fb12f2009-08-26 17:39:53 +00003284 case Intrinsic::arm_neon_vst2: {
Craig Topper51f50c12012-05-24 05:17:00 +00003285 static const uint16_t DOpcodes[] = { ARM::VST2d8, ARM::VST2d16,
3286 ARM::VST2d32, ARM::VST1q64 };
3287 static uint16_t QOpcodes[] = { ARM::VST2q8Pseudo, ARM::VST2q16Pseudo,
3288 ARM::VST2q32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003289 return SelectVST(N, false, 2, DOpcodes, QOpcodes, 0);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003290 }
3291
3292 case Intrinsic::arm_neon_vst3: {
Craig Topper51f50c12012-05-24 05:17:00 +00003293 static const uint16_t DOpcodes[] = { ARM::VST3d8Pseudo,
3294 ARM::VST3d16Pseudo,
3295 ARM::VST3d32Pseudo,
3296 ARM::VST1d64TPseudo };
3297 static const uint16_t QOpcodes0[] = { ARM::VST3q8Pseudo_UPD,
3298 ARM::VST3q16Pseudo_UPD,
3299 ARM::VST3q32Pseudo_UPD };
3300 static const uint16_t QOpcodes1[] = { ARM::VST3q8oddPseudo,
3301 ARM::VST3q16oddPseudo,
3302 ARM::VST3q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003303 return SelectVST(N, false, 3, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003304 }
3305
3306 case Intrinsic::arm_neon_vst4: {
Craig Topper51f50c12012-05-24 05:17:00 +00003307 static const uint16_t DOpcodes[] = { ARM::VST4d8Pseudo,
3308 ARM::VST4d16Pseudo,
3309 ARM::VST4d32Pseudo,
3310 ARM::VST1d64QPseudo };
3311 static const uint16_t QOpcodes0[] = { ARM::VST4q8Pseudo_UPD,
3312 ARM::VST4q16Pseudo_UPD,
3313 ARM::VST4q32Pseudo_UPD };
3314 static const uint16_t QOpcodes1[] = { ARM::VST4q8oddPseudo,
3315 ARM::VST4q16oddPseudo,
3316 ARM::VST4q32oddPseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003317 return SelectVST(N, false, 4, DOpcodes, QOpcodes0, QOpcodes1);
Bob Wilson31fb12f2009-08-26 17:39:53 +00003318 }
Bob Wilson8a3198b2009-09-01 18:51:56 +00003319
3320 case Intrinsic::arm_neon_vst2lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003321 static const uint16_t DOpcodes[] = { ARM::VST2LNd8Pseudo,
3322 ARM::VST2LNd16Pseudo,
3323 ARM::VST2LNd32Pseudo };
3324 static const uint16_t QOpcodes[] = { ARM::VST2LNq16Pseudo,
3325 ARM::VST2LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003326 return SelectVLDSTLane(N, false, false, 2, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003327 }
3328
3329 case Intrinsic::arm_neon_vst3lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003330 static const uint16_t DOpcodes[] = { ARM::VST3LNd8Pseudo,
3331 ARM::VST3LNd16Pseudo,
3332 ARM::VST3LNd32Pseudo };
3333 static const uint16_t QOpcodes[] = { ARM::VST3LNq16Pseudo,
3334 ARM::VST3LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003335 return SelectVLDSTLane(N, false, false, 3, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003336 }
3337
3338 case Intrinsic::arm_neon_vst4lane: {
Craig Topper51f50c12012-05-24 05:17:00 +00003339 static const uint16_t DOpcodes[] = { ARM::VST4LNd8Pseudo,
3340 ARM::VST4LNd16Pseudo,
3341 ARM::VST4LNd32Pseudo };
3342 static const uint16_t QOpcodes[] = { ARM::VST4LNq16Pseudo,
3343 ARM::VST4LNq32Pseudo };
Bob Wilson1c3ef902011-02-07 17:43:21 +00003344 return SelectVLDSTLane(N, false, false, 4, DOpcodes, QOpcodes);
Bob Wilson8a3198b2009-09-01 18:51:56 +00003345 }
Bob Wilson31fb12f2009-08-26 17:39:53 +00003346 }
Bob Wilson429009b2010-05-06 16:05:26 +00003347 break;
Bob Wilson31fb12f2009-08-26 17:39:53 +00003348 }
Evan Chengde8aa4e2010-05-05 18:28:36 +00003349
Bob Wilsond491d6e2010-07-06 23:36:25 +00003350 case ISD::INTRINSIC_WO_CHAIN: {
3351 unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue();
3352 switch (IntNo) {
3353 default:
3354 break;
3355
3356 case Intrinsic::arm_neon_vtbl2:
Jim Grosbach28f08c92012-03-05 19:33:30 +00003357 return SelectVTBL(N, false, 2, ARM::VTBL2);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003358 case Intrinsic::arm_neon_vtbl3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003359 return SelectVTBL(N, false, 3, ARM::VTBL3Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003360 case Intrinsic::arm_neon_vtbl4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003361 return SelectVTBL(N, false, 4, ARM::VTBL4Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003362
3363 case Intrinsic::arm_neon_vtbx2:
Jim Grosbach28f08c92012-03-05 19:33:30 +00003364 return SelectVTBL(N, true, 2, ARM::VTBX2);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003365 case Intrinsic::arm_neon_vtbx3:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003366 return SelectVTBL(N, true, 3, ARM::VTBX3Pseudo);
Bob Wilson78dfbc32010-07-07 00:08:54 +00003367 case Intrinsic::arm_neon_vtbx4:
Bob Wilsonbd916c52010-09-13 23:55:10 +00003368 return SelectVTBL(N, true, 4, ARM::VTBX4Pseudo);
Bob Wilsond491d6e2010-07-06 23:36:25 +00003369 }
3370 break;
3371 }
3372
Bill Wendling69a05a72011-03-14 23:02:38 +00003373 case ARMISD::VTBL1: {
3374 DebugLoc dl = N->getDebugLoc();
3375 EVT VT = N->getValueType(0);
3376 SmallVector<SDValue, 6> Ops;
3377
3378 Ops.push_back(N->getOperand(0));
3379 Ops.push_back(N->getOperand(1));
3380 Ops.push_back(getAL(CurDAG)); // Predicate
3381 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
3382 return CurDAG->getMachineNode(ARM::VTBL1, dl, VT, Ops.data(), Ops.size());
3383 }
3384 case ARMISD::VTBL2: {
3385 DebugLoc dl = N->getDebugLoc();
3386 EVT VT = N->getValueType(0);
3387
3388 // Form a REG_SEQUENCE to force register allocation.
3389 SDValue V0 = N->getOperand(0);
3390 SDValue V1 = N->getOperand(1);
3391 SDValue RegSeq = SDValue(PairDRegs(MVT::v16i8, V0, V1), 0);
3392
3393 SmallVector<SDValue, 6> Ops;
3394 Ops.push_back(RegSeq);
3395 Ops.push_back(N->getOperand(2));
3396 Ops.push_back(getAL(CurDAG)); // Predicate
3397 Ops.push_back(CurDAG->getRegister(0, MVT::i32)); // Predicate Register
Jim Grosbach28f08c92012-03-05 19:33:30 +00003398 return CurDAG->getMachineNode(ARM::VTBL2, dl, VT,
Bill Wendling69a05a72011-03-14 23:02:38 +00003399 Ops.data(), Ops.size());
3400 }
3401
Bob Wilson429009b2010-05-06 16:05:26 +00003402 case ISD::CONCAT_VECTORS:
Evan Chengde8aa4e2010-05-05 18:28:36 +00003403 return SelectConcatVector(N);
Eli Friedman2bdffe42011-08-31 00:31:29 +00003404
3405 case ARMISD::ATOMOR64_DAG:
3406 return SelectAtomic64(N, ARM::ATOMOR6432);
3407 case ARMISD::ATOMXOR64_DAG:
3408 return SelectAtomic64(N, ARM::ATOMXOR6432);
3409 case ARMISD::ATOMADD64_DAG:
3410 return SelectAtomic64(N, ARM::ATOMADD6432);
3411 case ARMISD::ATOMSUB64_DAG:
3412 return SelectAtomic64(N, ARM::ATOMSUB6432);
3413 case ARMISD::ATOMNAND64_DAG:
3414 return SelectAtomic64(N, ARM::ATOMNAND6432);
3415 case ARMISD::ATOMAND64_DAG:
3416 return SelectAtomic64(N, ARM::ATOMAND6432);
3417 case ARMISD::ATOMSWAP64_DAG:
3418 return SelectAtomic64(N, ARM::ATOMSWAP6432);
Eli Friedman4d3f3292011-08-31 17:52:22 +00003419 case ARMISD::ATOMCMPXCHG64_DAG:
3420 return SelectAtomic64(N, ARM::ATOMCMPXCHG6432);
Evan Chengde8aa4e2010-05-05 18:28:36 +00003421 }
Evan Chenge5ad88e2008-12-10 21:54:21 +00003422
Dan Gohmaneeb3a002010-01-05 01:24:18 +00003423 return SelectCode(N);
Evan Chenga8e29892007-01-19 07:51:42 +00003424}
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003425
Bob Wilson224c2442009-05-19 05:53:42 +00003426bool ARMDAGToDAGISel::
3427SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
3428 std::vector<SDValue> &OutOps) {
3429 assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
Bob Wilson765cc0b2009-10-13 20:50:28 +00003430 // Require the address to be in a register. That is safe for all ARM
3431 // variants and it is hard to do anything much smarter without knowing
3432 // how the operand is used.
3433 OutOps.push_back(Op);
Bob Wilson224c2442009-05-19 05:53:42 +00003434 return false;
3435}
3436
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003437/// createARMISelDag - This pass converts a legalized DAG into a
3438/// ARM-specific DAG, ready for instruction scheduling.
3439///
Bob Wilson522ce972009-09-28 14:30:20 +00003440FunctionPass *llvm::createARMISelDag(ARMBaseTargetMachine &TM,
3441 CodeGenOpt::Level OptLevel) {
3442 return new ARMDAGToDAGISel(TM, OptLevel);
Rafael Espindola7bc59bc2006-05-14 22:18:28 +00003443}