blob: 8152e1dbe1a1c78271cb890b0c7a036c8ba74102 [file] [log] [blame]
Anton Korobeynikov4403b932009-07-16 13:27:25 +00001//==-- SystemZISelDAGToDAG.cpp - A dag to dag inst selector for SystemZ ---===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines an instruction selector for the SystemZ target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "SystemZ.h"
15#include "SystemZISelLowering.h"
16#include "SystemZTargetMachine.h"
17#include "llvm/DerivedTypes.h"
18#include "llvm/Function.h"
19#include "llvm/Intrinsics.h"
20#include "llvm/CallingConv.h"
21#include "llvm/Constants.h"
22#include "llvm/CodeGen/MachineFrameInfo.h"
23#include "llvm/CodeGen/MachineFunction.h"
24#include "llvm/CodeGen/MachineInstrBuilder.h"
25#include "llvm/CodeGen/MachineRegisterInfo.h"
26#include "llvm/CodeGen/SelectionDAG.h"
27#include "llvm/CodeGen/SelectionDAGISel.h"
28#include "llvm/Target/TargetLowering.h"
29#include "llvm/Support/Compiler.h"
30#include "llvm/Support/Debug.h"
Anton Korobeynikov7df84622009-07-16 14:36:52 +000031#include "llvm/Support/raw_ostream.h"
Anton Korobeynikov4403b932009-07-16 13:27:25 +000032using namespace llvm;
33
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +000034static const unsigned subreg_even32 = 1;
35static const unsigned subreg_odd32 = 2;
36static const unsigned subreg_even = 3;
37static const unsigned subreg_odd = 4;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +000038
Anton Korobeynikov3360da92009-07-16 13:44:00 +000039namespace {
40 /// SystemZRRIAddressMode - This corresponds to rriaddr, but uses SDValue's
41 /// instead of register numbers for the leaves of the matched tree.
42 struct SystemZRRIAddressMode {
43 enum {
44 RegBase,
45 FrameIndexBase
46 } BaseType;
47
48 struct { // This is really a union, discriminated by BaseType!
49 SDValue Reg;
50 int FrameIndex;
51 } Base;
52
53 SDValue IndexReg;
Anton Korobeynikov32407402009-07-16 13:48:23 +000054 int64_t Disp;
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000055 bool isRI;
Anton Korobeynikov3360da92009-07-16 13:44:00 +000056
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000057 SystemZRRIAddressMode(bool RI = false)
58 : BaseType(RegBase), IndexReg(), Disp(0), isRI(RI) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +000059 }
60
61 void dump() {
Chris Lattner4437ae22009-08-23 07:05:07 +000062 errs() << "SystemZRRIAddressMode " << this << '\n';
Anton Korobeynikov3360da92009-07-16 13:44:00 +000063 if (BaseType == RegBase) {
Chris Lattner4437ae22009-08-23 07:05:07 +000064 errs() << "Base.Reg ";
65 if (Base.Reg.getNode() != 0)
66 Base.Reg.getNode()->dump();
67 else
68 errs() << "nul";
69 errs() << '\n';
Anton Korobeynikov3360da92009-07-16 13:44:00 +000070 } else {
Chris Lattner4437ae22009-08-23 07:05:07 +000071 errs() << " Base.FrameIndex " << Base.FrameIndex << '\n';
Anton Korobeynikov3360da92009-07-16 13:44:00 +000072 }
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000073 if (!isRI) {
Chris Lattner4437ae22009-08-23 07:05:07 +000074 errs() << "IndexReg ";
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000075 if (IndexReg.getNode() != 0) IndexReg.getNode()->dump();
Chris Lattner4437ae22009-08-23 07:05:07 +000076 else errs() << "nul";
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000077 }
Chris Lattner4437ae22009-08-23 07:05:07 +000078 errs() << " Disp " << Disp << '\n';
Anton Korobeynikov3360da92009-07-16 13:44:00 +000079 }
80 };
81}
82
Anton Korobeynikov4403b932009-07-16 13:27:25 +000083/// SystemZDAGToDAGISel - SystemZ specific code to select SystemZ machine
84/// instructions for SelectionDAG operations.
85///
86namespace {
87 class SystemZDAGToDAGISel : public SelectionDAGISel {
88 SystemZTargetLowering &Lowering;
89 const SystemZSubtarget &Subtarget;
90
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000091 void getAddressOperandsRI(const SystemZRRIAddressMode &AM,
92 SDValue &Base, SDValue &Disp);
Anton Korobeynikov720e3b02009-07-16 14:09:35 +000093 void getAddressOperands(const SystemZRRIAddressMode &AM,
94 SDValue &Base, SDValue &Disp,
95 SDValue &Index);
96
Anton Korobeynikov4403b932009-07-16 13:27:25 +000097 public:
98 SystemZDAGToDAGISel(SystemZTargetMachine &TM, CodeGenOpt::Level OptLevel)
99 : SelectionDAGISel(TM, OptLevel),
100 Lowering(*TM.getTargetLowering()),
101 Subtarget(*TM.getSubtargetImpl()) { }
102
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000103 virtual const char *getPassName() const {
104 return "SystemZ DAG->DAG Pattern Instruction Selection";
105 }
106
Anton Korobeynikovb6831cb2009-07-16 14:26:38 +0000107 /// getI8Imm - Return a target constant with the specified value, of type
108 /// i8.
109 inline SDValue getI8Imm(uint64_t Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000110 return CurDAG->getTargetConstant(Imm, MVT::i8);
Anton Korobeynikovb6831cb2009-07-16 14:26:38 +0000111 }
112
Anton Korobeynikov89edcd02009-07-16 13:33:57 +0000113 /// getI16Imm - Return a target constant with the specified value, of type
114 /// i16.
115 inline SDValue getI16Imm(uint64_t Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000116 return CurDAG->getTargetConstant(Imm, MVT::i16);
Anton Korobeynikov89edcd02009-07-16 13:33:57 +0000117 }
118
Anton Korobeynikovda308c92009-07-16 13:34:50 +0000119 /// getI32Imm - Return a target constant with the specified value, of type
120 /// i32.
121 inline SDValue getI32Imm(uint64_t Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000122 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikovda308c92009-07-16 13:34:50 +0000123 }
124
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000125 // Include the pieces autogenerated from the target description.
Anton Korobeynikov89edcd02009-07-16 13:33:57 +0000126 #include "SystemZGenDAGISel.inc"
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000127
128 private:
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000129 bool SelectAddrRI12Only(SDNode *Op, SDValue& Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000130 SDValue &Base, SDValue &Disp);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000131 bool SelectAddrRI12(SDNode *Op, SDValue& Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000132 SDValue &Base, SDValue &Disp,
133 bool is12BitOnly = false);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000134 bool SelectAddrRI(SDNode *Op, SDValue& Addr,
Anton Korobeynikov9e4816e2009-07-16 13:43:18 +0000135 SDValue &Base, SDValue &Disp);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000136 bool SelectAddrRRI12(SDNode *Op, SDValue Addr,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000137 SDValue &Base, SDValue &Disp, SDValue &Index);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000138 bool SelectAddrRRI20(SDNode *Op, SDValue Addr,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000139 SDValue &Base, SDValue &Disp, SDValue &Index);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000140 bool SelectLAAddr(SDNode *Op, SDValue Addr,
Anton Korobeynikovc4368a12009-07-16 13:48:42 +0000141 SDValue &Base, SDValue &Disp, SDValue &Index);
142
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000143 SDNode *Select(SDNode *Node);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000144
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000145 bool TryFoldLoad(SDNode *P, SDValue N,
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000146 SDValue &Base, SDValue &Disp, SDValue &Index);
147
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000148 bool MatchAddress(SDValue N, SystemZRRIAddressMode &AM,
149 bool is12Bit, unsigned Depth = 0);
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000150 bool MatchAddressBase(SDValue N, SystemZRRIAddressMode &AM);
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000151 bool MatchAddressRI(SDValue N, SystemZRRIAddressMode &AM,
152 bool is12Bit);
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000153 };
154} // end anonymous namespace
155
156/// createSystemZISelDag - This pass converts a legalized DAG into a
157/// SystemZ-specific DAG, ready for instruction scheduling.
158///
159FunctionPass *llvm::createSystemZISelDag(SystemZTargetMachine &TM,
160 CodeGenOpt::Level OptLevel) {
161 return new SystemZDAGToDAGISel(TM, OptLevel);
162}
163
Anton Korobeynikov9e4816e2009-07-16 13:43:18 +0000164/// isImmSExt20 - This method tests to see if the node is either a 32-bit
165/// or 64-bit immediate, and if the value can be accurately represented as a
166/// sign extension from a 20-bit value. If so, this returns true and the
167/// immediate.
Anton Korobeynikov32407402009-07-16 13:48:23 +0000168static bool isImmSExt20(int64_t Val, int64_t &Imm) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000169 if (Val >= -524288 && Val <= 524287) {
Anton Korobeynikov32407402009-07-16 13:48:23 +0000170 Imm = Val;
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000171 return true;
172 }
173 return false;
174}
175
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000176/// isImmZExt12 - This method tests to see if the node is either a 32-bit
Anton Korobeynikov3166a9a2009-07-16 14:03:41 +0000177/// or 64-bit immediate, and if the value can be accurately represented as a
178/// zero extension from a 12-bit value. If so, this returns true and the
179/// immediate.
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000180static bool isImmZExt12(int64_t Val, int64_t &Imm) {
181 if (Val >= 0 && Val <= 0xFFF) {
Anton Korobeynikov3166a9a2009-07-16 14:03:41 +0000182 Imm = Val;
183 return true;
184 }
Anton Korobeynikov3166a9a2009-07-16 14:03:41 +0000185 return false;
186}
187
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000188/// MatchAddress - Add the specified node to the specified addressing mode,
189/// returning true if it cannot be done. This just pattern matches for the
190/// addressing mode.
191bool SystemZDAGToDAGISel::MatchAddress(SDValue N, SystemZRRIAddressMode &AM,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000192 bool is12Bit, unsigned Depth) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000193 DebugLoc dl = N.getDebugLoc();
Chris Lattner893e1c92009-08-23 06:49:22 +0000194 DEBUG(errs() << "MatchAddress: "; AM.dump());
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000195 // Limit recursion.
196 if (Depth > 5)
197 return MatchAddressBase(N, AM);
198
Anton Korobeynikovdc289552009-07-16 13:44:30 +0000199 // FIXME: We can perform better here. If we have something like
200 // (shift (add A, imm), N), we can try to reassociate stuff and fold shift of
201 // imm into addressing mode.
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000202 switch (N.getOpcode()) {
203 default: break;
204 case ISD::Constant: {
Anton Korobeynikov32407402009-07-16 13:48:23 +0000205 int64_t Val = cast<ConstantSDNode>(N)->getSExtValue();
Daniel Dunbar19c29f52009-07-17 02:19:26 +0000206 int64_t Imm = 0;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000207 bool Match = (is12Bit ?
208 isImmZExt12(AM.Disp + Val, Imm) :
209 isImmSExt20(AM.Disp + Val, Imm));
210 if (Match) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000211 AM.Disp = Imm;
212 return false;
213 }
214 break;
215 }
216
217 case ISD::FrameIndex:
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000218 if (AM.BaseType == SystemZRRIAddressMode::RegBase &&
219 AM.Base.Reg.getNode() == 0) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000220 AM.BaseType = SystemZRRIAddressMode::FrameIndexBase;
221 AM.Base.FrameIndex = cast<FrameIndexSDNode>(N)->getIndex();
222 return false;
223 }
224 break;
225
226 case ISD::SUB: {
227 // Given A-B, if A can be completely folded into the address and
228 // the index field with the index field unused, use -B as the index.
229 // This is a win if a has multiple parts that can be folded into
230 // the address. Also, this saves a mov if the base register has
231 // other uses, since it avoids a two-address sub instruction, however
232 // it costs an additional mov if the index register has other uses.
233
234 // Test if the LHS of the sub can be folded.
235 SystemZRRIAddressMode Backup = AM;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000236 if (MatchAddress(N.getNode()->getOperand(0), AM, is12Bit, Depth+1)) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000237 AM = Backup;
238 break;
239 }
240 // Test if the index field is free for use.
Anton Korobeynikov54681ec2009-07-16 14:31:14 +0000241 if (AM.IndexReg.getNode() || AM.isRI) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000242 AM = Backup;
243 break;
244 }
245
246 // If the base is a register with multiple uses, this transformation may
247 // save a mov. Otherwise it's probably better not to do it.
248 if (AM.BaseType == SystemZRRIAddressMode::RegBase &&
249 (!AM.Base.Reg.getNode() || AM.Base.Reg.getNode()->hasOneUse())) {
250 AM = Backup;
251 break;
252 }
253
254 // Ok, the transformation is legal and appears profitable. Go for it.
255 SDValue RHS = N.getNode()->getOperand(1);
256 SDValue Zero = CurDAG->getConstant(0, N.getValueType());
257 SDValue Neg = CurDAG->getNode(ISD::SUB, dl, N.getValueType(), Zero, RHS);
258 AM.IndexReg = Neg;
259
260 // Insert the new nodes into the topological ordering.
261 if (Zero.getNode()->getNodeId() == -1 ||
262 Zero.getNode()->getNodeId() > N.getNode()->getNodeId()) {
263 CurDAG->RepositionNode(N.getNode(), Zero.getNode());
264 Zero.getNode()->setNodeId(N.getNode()->getNodeId());
265 }
266 if (Neg.getNode()->getNodeId() == -1 ||
267 Neg.getNode()->getNodeId() > N.getNode()->getNodeId()) {
268 CurDAG->RepositionNode(N.getNode(), Neg.getNode());
269 Neg.getNode()->setNodeId(N.getNode()->getNodeId());
270 }
271 return false;
272 }
273
274 case ISD::ADD: {
275 SystemZRRIAddressMode Backup = AM;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000276 if (!MatchAddress(N.getNode()->getOperand(0), AM, is12Bit, Depth+1) &&
277 !MatchAddress(N.getNode()->getOperand(1), AM, is12Bit, Depth+1))
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000278 return false;
279 AM = Backup;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000280 if (!MatchAddress(N.getNode()->getOperand(1), AM, is12Bit, Depth+1) &&
281 !MatchAddress(N.getNode()->getOperand(0), AM, is12Bit, Depth+1))
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000282 return false;
283 AM = Backup;
284
285 // If we couldn't fold both operands into the address at the same time,
286 // see if we can just put each operand into a register and fold at least
287 // the add.
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000288 if (!AM.isRI &&
289 AM.BaseType == SystemZRRIAddressMode::RegBase &&
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000290 !AM.Base.Reg.getNode() && !AM.IndexReg.getNode()) {
291 AM.Base.Reg = N.getNode()->getOperand(0);
292 AM.IndexReg = N.getNode()->getOperand(1);
293 return false;
294 }
295 break;
296 }
297
298 case ISD::OR:
299 // Handle "X | C" as "X + C" iff X is known to have C bits clear.
300 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
301 SystemZRRIAddressMode Backup = AM;
Anton Korobeynikov32407402009-07-16 13:48:23 +0000302 int64_t Offset = CN->getSExtValue();
Daniel Dunbar19c29f52009-07-17 02:19:26 +0000303 int64_t Imm = 0;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000304 bool MatchOffset = (is12Bit ?
305 isImmZExt12(AM.Disp + Offset, Imm) :
306 isImmSExt20(AM.Disp + Offset, Imm));
307 // The resultant disp must fit in 12 or 20-bits.
308 if (MatchOffset &&
309 // LHS should be an addr mode.
310 !MatchAddress(N.getOperand(0), AM, is12Bit, Depth+1) &&
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000311 // Check to see if the LHS & C is zero.
312 CurDAG->MaskedValueIsZero(N.getOperand(0), CN->getAPIntValue())) {
313 AM.Disp = Imm;
314 return false;
315 }
316 AM = Backup;
317 }
318 break;
319 }
320
321 return MatchAddressBase(N, AM);
322}
323
324/// MatchAddressBase - Helper for MatchAddress. Add the specified node to the
325/// specified addressing mode without any further recursion.
326bool SystemZDAGToDAGISel::MatchAddressBase(SDValue N,
327 SystemZRRIAddressMode &AM) {
328 // Is the base register already occupied?
329 if (AM.BaseType != SystemZRRIAddressMode::RegBase || AM.Base.Reg.getNode()) {
Anton Korobeynikov46567602009-07-16 14:10:35 +0000330 // If so, check to see if the index register is set.
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000331 if (AM.IndexReg.getNode() == 0 && !AM.isRI) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000332 AM.IndexReg = N;
333 return false;
334 }
335
336 // Otherwise, we cannot select it.
337 return true;
338 }
339
340 // Default, generate it as a register.
341 AM.BaseType = SystemZRRIAddressMode::RegBase;
342 AM.Base.Reg = N;
343 return false;
344}
345
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000346void SystemZDAGToDAGISel::getAddressOperandsRI(const SystemZRRIAddressMode &AM,
347 SDValue &Base, SDValue &Disp) {
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000348 if (AM.BaseType == SystemZRRIAddressMode::RegBase)
349 Base = AM.Base.Reg;
350 else
351 Base = CurDAG->getTargetFrameIndex(AM.Base.FrameIndex, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000352 Disp = CurDAG->getTargetConstant(AM.Disp, MVT::i64);
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000353}
354
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000355void SystemZDAGToDAGISel::getAddressOperands(const SystemZRRIAddressMode &AM,
356 SDValue &Base, SDValue &Disp,
357 SDValue &Index) {
358 getAddressOperandsRI(AM, Base, Disp);
359 Index = AM.IndexReg;
360}
361
362/// Returns true if the address can be represented by a base register plus
363/// an unsigned 12-bit displacement [r+imm].
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000364bool SystemZDAGToDAGISel::SelectAddrRI12Only(SDNode *Op, SDValue& Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000365 SDValue &Base, SDValue &Disp) {
366 return SelectAddrRI12(Op, Addr, Base, Disp, /*is12BitOnly*/true);
367}
368
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000369bool SystemZDAGToDAGISel::SelectAddrRI12(SDNode *Op, SDValue& Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000370 SDValue &Base, SDValue &Disp,
371 bool is12BitOnly) {
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000372 SystemZRRIAddressMode AM20(/*isRI*/true), AM12(/*isRI*/true);
373 bool Done = false;
374
375 if (!Addr.hasOneUse()) {
376 unsigned Opcode = Addr.getOpcode();
377 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
378 // If we are able to fold N into addressing mode, then we'll allow it even
379 // if N has multiple uses. In general, addressing computation is used as
380 // addresses by all of its uses. But watch out for CopyToReg uses, that
381 // means the address computation is liveout. It will be computed by a LA
382 // so we want to avoid computing the address twice.
383 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
384 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
385 if (UI->getOpcode() == ISD::CopyToReg) {
386 MatchAddressBase(Addr, AM12);
387 Done = true;
388 break;
389 }
390 }
391 }
392 }
393 if (!Done && MatchAddress(Addr, AM12, /* is12Bit */ true))
394 return false;
395
396 // Check, whether we can match stuff using 20-bit displacements
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000397 if (!Done && !is12BitOnly &&
398 !MatchAddress(Addr, AM20, /* is12Bit */ false))
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000399 if (AM12.Disp == 0 && AM20.Disp != 0)
400 return false;
401
Chris Lattner893e1c92009-08-23 06:49:22 +0000402 DEBUG(errs() << "MatchAddress (final): "; AM12.dump());
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000403
Owen Andersone50ed302009-08-10 22:56:29 +0000404 EVT VT = Addr.getValueType();
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000405 if (AM12.BaseType == SystemZRRIAddressMode::RegBase) {
406 if (!AM12.Base.Reg.getNode())
407 AM12.Base.Reg = CurDAG->getRegister(0, VT);
408 }
409
410 assert(AM12.IndexReg.getNode() == 0 && "Invalid reg-imm address mode!");
411
412 getAddressOperandsRI(AM12, Base, Disp);
413
414 return true;
415}
416
417/// Returns true if the address can be represented by a base register plus
418/// a signed 20-bit displacement [r+imm].
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000419bool SystemZDAGToDAGISel::SelectAddrRI(SDNode *Op, SDValue& Addr,
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000420 SDValue &Base, SDValue &Disp) {
421 SystemZRRIAddressMode AM(/*isRI*/true);
422 bool Done = false;
423
424 if (!Addr.hasOneUse()) {
425 unsigned Opcode = Addr.getOpcode();
426 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
427 // If we are able to fold N into addressing mode, then we'll allow it even
428 // if N has multiple uses. In general, addressing computation is used as
429 // addresses by all of its uses. But watch out for CopyToReg uses, that
430 // means the address computation is liveout. It will be computed by a LA
431 // so we want to avoid computing the address twice.
432 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
433 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
434 if (UI->getOpcode() == ISD::CopyToReg) {
435 MatchAddressBase(Addr, AM);
436 Done = true;
437 break;
438 }
439 }
440 }
441 }
442 if (!Done && MatchAddress(Addr, AM, /* is12Bit */ false))
443 return false;
444
Chris Lattner893e1c92009-08-23 06:49:22 +0000445 DEBUG(errs() << "MatchAddress (final): "; AM.dump());
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000446
Owen Andersone50ed302009-08-10 22:56:29 +0000447 EVT VT = Addr.getValueType();
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000448 if (AM.BaseType == SystemZRRIAddressMode::RegBase) {
449 if (!AM.Base.Reg.getNode())
450 AM.Base.Reg = CurDAG->getRegister(0, VT);
451 }
452
453 assert(AM.IndexReg.getNode() == 0 && "Invalid reg-imm address mode!");
454
455 getAddressOperandsRI(AM, Base, Disp);
456
457 return true;
458}
459
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000460/// Returns true if the address can be represented by a base register plus
461/// index register plus an unsigned 12-bit displacement [base + idx + imm].
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000462bool SystemZDAGToDAGISel::SelectAddrRRI12(SDNode *Op, SDValue Addr,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000463 SDValue &Base, SDValue &Disp, SDValue &Index) {
Anton Korobeynikov46567602009-07-16 14:10:35 +0000464 SystemZRRIAddressMode AM20, AM12;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000465 bool Done = false;
466
467 if (!Addr.hasOneUse()) {
468 unsigned Opcode = Addr.getOpcode();
469 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
470 // If we are able to fold N into addressing mode, then we'll allow it even
471 // if N has multiple uses. In general, addressing computation is used as
472 // addresses by all of its uses. But watch out for CopyToReg uses, that
473 // means the address computation is liveout. It will be computed by a LA
474 // so we want to avoid computing the address twice.
475 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
476 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
477 if (UI->getOpcode() == ISD::CopyToReg) {
478 MatchAddressBase(Addr, AM12);
479 Done = true;
480 break;
481 }
482 }
483 }
484 }
485 if (!Done && MatchAddress(Addr, AM12, /* is12Bit */ true))
486 return false;
487
488 // Check, whether we can match stuff using 20-bit displacements
489 if (!Done && !MatchAddress(Addr, AM20, /* is12Bit */ false))
490 if (AM12.Disp == 0 && AM20.Disp != 0)
491 return false;
492
Chris Lattner893e1c92009-08-23 06:49:22 +0000493 DEBUG(errs() << "MatchAddress (final): "; AM12.dump());
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000494
Owen Andersone50ed302009-08-10 22:56:29 +0000495 EVT VT = Addr.getValueType();
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000496 if (AM12.BaseType == SystemZRRIAddressMode::RegBase) {
497 if (!AM12.Base.Reg.getNode())
498 AM12.Base.Reg = CurDAG->getRegister(0, VT);
499 }
500
501 if (!AM12.IndexReg.getNode())
502 AM12.IndexReg = CurDAG->getRegister(0, VT);
503
504 getAddressOperands(AM12, Base, Disp, Index);
505
506 return true;
507}
508
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000509/// Returns true if the address can be represented by a base register plus
510/// index register plus a signed 20-bit displacement [base + idx + imm].
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000511bool SystemZDAGToDAGISel::SelectAddrRRI20(SDNode *Op, SDValue Addr,
Anton Korobeynikovc4368a12009-07-16 13:48:42 +0000512 SDValue &Base, SDValue &Disp, SDValue &Index) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000513 SystemZRRIAddressMode AM;
514 bool Done = false;
515
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000516 if (!Addr.hasOneUse()) {
517 unsigned Opcode = Addr.getOpcode();
518 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
519 // If we are able to fold N into addressing mode, then we'll allow it even
520 // if N has multiple uses. In general, addressing computation is used as
521 // addresses by all of its uses. But watch out for CopyToReg uses, that
522 // means the address computation is liveout. It will be computed by a LA
523 // so we want to avoid computing the address twice.
524 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
525 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
526 if (UI->getOpcode() == ISD::CopyToReg) {
527 MatchAddressBase(Addr, AM);
528 Done = true;
529 break;
530 }
531 }
532 }
533 }
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000534 if (!Done && MatchAddress(Addr, AM, /* is12Bit */ false))
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000535 return false;
536
Chris Lattner893e1c92009-08-23 06:49:22 +0000537 DEBUG(errs() << "MatchAddress (final): "; AM.dump());
Anton Korobeynikov32407402009-07-16 13:48:23 +0000538
Owen Andersone50ed302009-08-10 22:56:29 +0000539 EVT VT = Addr.getValueType();
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000540 if (AM.BaseType == SystemZRRIAddressMode::RegBase) {
541 if (!AM.Base.Reg.getNode())
542 AM.Base.Reg = CurDAG->getRegister(0, VT);
543 }
544
545 if (!AM.IndexReg.getNode())
546 AM.IndexReg = CurDAG->getRegister(0, VT);
547
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000548 getAddressOperands(AM, Base, Disp, Index);
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000549
550 return true;
551}
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000552
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000553/// SelectLAAddr - it calls SelectAddr and determines if the maximal addressing
554/// mode it matches can be cost effectively emitted as an LA/LAY instruction.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000555bool SystemZDAGToDAGISel::SelectLAAddr(SDNode *Op, SDValue Addr,
Anton Korobeynikovc4368a12009-07-16 13:48:42 +0000556 SDValue &Base, SDValue &Disp, SDValue &Index) {
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000557 SystemZRRIAddressMode AM;
558
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000559 if (MatchAddress(Addr, AM, false))
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000560 return false;
561
Owen Andersone50ed302009-08-10 22:56:29 +0000562 EVT VT = Addr.getValueType();
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000563 unsigned Complexity = 0;
564 if (AM.BaseType == SystemZRRIAddressMode::RegBase)
565 if (AM.Base.Reg.getNode())
566 Complexity = 1;
567 else
568 AM.Base.Reg = CurDAG->getRegister(0, VT);
569 else if (AM.BaseType == SystemZRRIAddressMode::FrameIndexBase)
570 Complexity = 4;
571
572 if (AM.IndexReg.getNode())
573 Complexity += 1;
574 else
575 AM.IndexReg = CurDAG->getRegister(0, VT);
576
577 if (AM.Disp && (AM.Base.Reg.getNode() || AM.IndexReg.getNode()))
578 Complexity += 1;
579
580 if (Complexity > 2) {
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000581 getAddressOperands(AM, Base, Disp, Index);
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000582 return true;
583 }
584
585 return false;
586}
587
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000588bool SystemZDAGToDAGISel::TryFoldLoad(SDNode *P, SDValue N,
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000589 SDValue &Base, SDValue &Disp, SDValue &Index) {
590 if (ISD::isNON_EXTLoad(N.getNode()) &&
Evan Cheng014bf212010-02-15 19:41:07 +0000591 IsLegalToFold(N, P, P))
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000592 return SelectAddrRRI20(P, N.getOperand(1), Base, Disp, Index);
593 return false;
594}
595
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000596SDNode *SystemZDAGToDAGISel::Select(SDNode *Node) {
Owen Andersone50ed302009-08-10 22:56:29 +0000597 EVT NVT = Node->getValueType(0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000598 DebugLoc dl = Node->getDebugLoc();
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000599 unsigned Opcode = Node->getOpcode();
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000600
601 // Dump information about the Node being selected
Chris Lattner7c306da2010-03-02 06:34:30 +0000602 DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000603
604 // If we have a custom node, we already have selected!
605 if (Node->isMachineOpcode()) {
Chris Lattner7c306da2010-03-02 06:34:30 +0000606 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000607 return NULL; // Already selected.
608 }
609
610 switch (Opcode) {
611 default: break;
612 case ISD::SDIVREM: {
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000613 unsigned Opc, MOpc;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000614 SDValue N0 = Node->getOperand(0);
615 SDValue N1 = Node->getOperand(1);
616
Owen Andersone50ed302009-08-10 22:56:29 +0000617 EVT ResVT;
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000618 bool is32Bit = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000619 switch (NVT.getSimpleVT().SimpleTy) {
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000620 default: assert(0 && "Unsupported VT!");
621 case MVT::i32:
622 Opc = SystemZ::SDIVREM32r; MOpc = SystemZ::SDIVREM32m;
623 ResVT = MVT::v2i64;
624 is32Bit = true;
625 break;
626 case MVT::i64:
627 Opc = SystemZ::SDIVREM64r; MOpc = SystemZ::SDIVREM64m;
628 ResVT = MVT::v2i64;
629 break;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000630 }
631
632 SDValue Tmp0, Tmp1, Tmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000633 bool foldedLoad = TryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000634
635 // Prepare the dividend
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000636 SDNode *Dividend;
637 if (is32Bit)
Dan Gohman602b0c82009-09-25 18:54:59 +0000638 Dividend = CurDAG->getMachineNode(SystemZ::MOVSX64rr32, dl, MVT::i64, N0);
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000639 else
640 Dividend = N0.getNode();
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000641
642 // Insert prepared dividend into suitable 'subreg'
Chris Lattner518bb532010-02-09 19:54:29 +0000643 SDNode *Tmp = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
Dan Gohman602b0c82009-09-25 18:54:59 +0000644 dl, ResVT);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000645 Dividend =
Chris Lattner518bb532010-02-09 19:54:29 +0000646 CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl, ResVT,
Dan Gohman602b0c82009-09-25 18:54:59 +0000647 SDValue(Tmp, 0), SDValue(Dividend, 0),
648 CurDAG->getTargetConstant(subreg_odd, MVT::i32));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000649
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000650 SDNode *Result;
651 SDValue DivVal = SDValue(Dividend, 0);
652 if (foldedLoad) {
653 SDValue Ops[] = { DivVal, Tmp0, Tmp1, Tmp2, N1.getOperand(0) };
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000654 Result = CurDAG->getMachineNode(MOpc, dl, ResVT, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +0000655 Ops, array_lengthof(Ops));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000656 // Update the chain.
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000657 ReplaceUses(N1.getValue(1), SDValue(Result, 1));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000658 } else {
Dan Gohman602b0c82009-09-25 18:54:59 +0000659 Result = CurDAG->getMachineNode(Opc, dl, ResVT, SDValue(Dividend, 0), N1);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000660 }
661
662 // Copy the division (odd subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000663 if (!SDValue(Node, 0).use_empty()) {
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000664 unsigned SubRegIdx = (is32Bit ? subreg_odd32 : subreg_odd);
Chris Lattner518bb532010-02-09 19:54:29 +0000665 SDNode *Div = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000666 dl, NVT,
667 SDValue(Result, 0),
668 CurDAG->getTargetConstant(SubRegIdx,
669 MVT::i32));
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000670
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000671 ReplaceUses(SDValue(Node, 0), SDValue(Div, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000672 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000673 }
674
675 // Copy the remainder (even subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000676 if (!SDValue(Node, 1).use_empty()) {
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000677 unsigned SubRegIdx = (is32Bit ? subreg_even32 : subreg_even);
Chris Lattner518bb532010-02-09 19:54:29 +0000678 SDNode *Rem = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000679 dl, NVT,
680 SDValue(Result, 0),
681 CurDAG->getTargetConstant(SubRegIdx,
682 MVT::i32));
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000683
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000684 ReplaceUses(SDValue(Node, 1), SDValue(Rem, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000685 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000686 }
687
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000688 return NULL;
689 }
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000690 case ISD::UDIVREM: {
691 unsigned Opc, MOpc, ClrOpc;
692 SDValue N0 = Node->getOperand(0);
693 SDValue N1 = Node->getOperand(1);
Owen Andersone50ed302009-08-10 22:56:29 +0000694 EVT ResVT;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000695
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000696 bool is32Bit = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000697 switch (NVT.getSimpleVT().SimpleTy) {
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000698 default: assert(0 && "Unsupported VT!");
699 case MVT::i32:
700 Opc = SystemZ::UDIVREM32r; MOpc = SystemZ::UDIVREM32m;
701 ClrOpc = SystemZ::MOV64Pr0_even;
702 ResVT = MVT::v2i32;
703 is32Bit = true;
704 break;
705 case MVT::i64:
706 Opc = SystemZ::UDIVREM64r; MOpc = SystemZ::UDIVREM64m;
707 ClrOpc = SystemZ::MOV128r0_even;
708 ResVT = MVT::v2i64;
709 break;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000710 }
711
712 SDValue Tmp0, Tmp1, Tmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000713 bool foldedLoad = TryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000714
715 // Prepare the dividend
716 SDNode *Dividend = N0.getNode();
717
718 // Insert prepared dividend into suitable 'subreg'
Chris Lattner518bb532010-02-09 19:54:29 +0000719 SDNode *Tmp = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
Dan Gohman602b0c82009-09-25 18:54:59 +0000720 dl, ResVT);
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000721 {
722 unsigned SubRegIdx = (is32Bit ? subreg_odd32 : subreg_odd);
723 Dividend =
Chris Lattner518bb532010-02-09 19:54:29 +0000724 CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl, ResVT,
Dan Gohman602b0c82009-09-25 18:54:59 +0000725 SDValue(Tmp, 0), SDValue(Dividend, 0),
726 CurDAG->getTargetConstant(SubRegIdx, MVT::i32));
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000727 }
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000728
Anton Korobeynikove3a7f7a2009-07-16 14:14:54 +0000729 // Zero out even subreg
Dan Gohman602b0c82009-09-25 18:54:59 +0000730 Dividend = CurDAG->getMachineNode(ClrOpc, dl, ResVT, SDValue(Dividend, 0));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000731
732 SDValue DivVal = SDValue(Dividend, 0);
733 SDNode *Result;
734 if (foldedLoad) {
735 SDValue Ops[] = { DivVal, Tmp0, Tmp1, Tmp2, N1.getOperand(0) };
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000736 Result = CurDAG->getMachineNode(MOpc, dl, ResVT, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +0000737 Ops, array_lengthof(Ops));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000738 // Update the chain.
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000739 ReplaceUses(N1.getValue(1), SDValue(Result, 1));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000740 } else {
Dan Gohman602b0c82009-09-25 18:54:59 +0000741 Result = CurDAG->getMachineNode(Opc, dl, ResVT, DivVal, N1);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000742 }
743
744 // Copy the division (odd subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000745 if (!SDValue(Node, 0).use_empty()) {
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000746 unsigned SubRegIdx = (is32Bit ? subreg_odd32 : subreg_odd);
Chris Lattner518bb532010-02-09 19:54:29 +0000747 SDNode *Div = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000748 dl, NVT,
749 SDValue(Result, 0),
750 CurDAG->getTargetConstant(SubRegIdx,
751 MVT::i32));
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000752 ReplaceUses(SDValue(Node, 0), SDValue(Div, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000753 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000754 }
755
756 // Copy the remainder (even subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000757 if (!SDValue(Node, 1).use_empty()) {
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000758 unsigned SubRegIdx = (is32Bit ? subreg_even32 : subreg_even);
Chris Lattner518bb532010-02-09 19:54:29 +0000759 SDNode *Rem = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000760 dl, NVT,
761 SDValue(Result, 0),
762 CurDAG->getTargetConstant(SubRegIdx,
763 MVT::i32));
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000764 ReplaceUses(SDValue(Node, 1), SDValue(Rem, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000765 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000766 }
767
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000768 return NULL;
769 }
770 }
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000771
772 // Select the default instruction
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000773 SDNode *ResNode = SelectCode(Node);
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000774
Chris Lattner7c306da2010-03-02 06:34:30 +0000775 DEBUG(errs() << "=> ";
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000776 if (ResNode == NULL || ResNode == Node)
777 Node->dump(CurDAG);
Chris Lattner893e1c92009-08-23 06:49:22 +0000778 else
779 ResNode->dump(CurDAG);
780 errs() << "\n";
781 );
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000782 return ResNode;
783}