blob: 75d563b9c4d5acf77aaf1c8ace717ac42d4d05c2 [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"
Anton Korobeynikov4403b932009-07-16 13:27:25 +000015#include "SystemZTargetMachine.h"
16#include "llvm/DerivedTypes.h"
17#include "llvm/Function.h"
18#include "llvm/Intrinsics.h"
19#include "llvm/CallingConv.h"
20#include "llvm/Constants.h"
21#include "llvm/CodeGen/MachineFrameInfo.h"
22#include "llvm/CodeGen/MachineFunction.h"
23#include "llvm/CodeGen/MachineInstrBuilder.h"
24#include "llvm/CodeGen/MachineRegisterInfo.h"
25#include "llvm/CodeGen/SelectionDAG.h"
26#include "llvm/CodeGen/SelectionDAGISel.h"
27#include "llvm/Target/TargetLowering.h"
28#include "llvm/Support/Compiler.h"
29#include "llvm/Support/Debug.h"
Anton Korobeynikov7df84622009-07-16 14:36:52 +000030#include "llvm/Support/raw_ostream.h"
Anton Korobeynikov4403b932009-07-16 13:27:25 +000031using namespace llvm;
32
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +000033static const unsigned subreg_even32 = 1;
34static const unsigned subreg_odd32 = 2;
35static const unsigned subreg_even = 3;
36static const unsigned subreg_odd = 4;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +000037
Anton Korobeynikov3360da92009-07-16 13:44:00 +000038namespace {
39 /// SystemZRRIAddressMode - This corresponds to rriaddr, but uses SDValue's
40 /// instead of register numbers for the leaves of the matched tree.
41 struct SystemZRRIAddressMode {
42 enum {
43 RegBase,
44 FrameIndexBase
45 } BaseType;
46
47 struct { // This is really a union, discriminated by BaseType!
48 SDValue Reg;
49 int FrameIndex;
50 } Base;
51
52 SDValue IndexReg;
Anton Korobeynikov32407402009-07-16 13:48:23 +000053 int64_t Disp;
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000054 bool isRI;
Anton Korobeynikov3360da92009-07-16 13:44:00 +000055
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000056 SystemZRRIAddressMode(bool RI = false)
57 : BaseType(RegBase), IndexReg(), Disp(0), isRI(RI) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +000058 }
59
60 void dump() {
Chris Lattner4437ae22009-08-23 07:05:07 +000061 errs() << "SystemZRRIAddressMode " << this << '\n';
Anton Korobeynikov3360da92009-07-16 13:44:00 +000062 if (BaseType == RegBase) {
Chris Lattner4437ae22009-08-23 07:05:07 +000063 errs() << "Base.Reg ";
64 if (Base.Reg.getNode() != 0)
65 Base.Reg.getNode()->dump();
66 else
67 errs() << "nul";
68 errs() << '\n';
Anton Korobeynikov3360da92009-07-16 13:44:00 +000069 } else {
Chris Lattner4437ae22009-08-23 07:05:07 +000070 errs() << " Base.FrameIndex " << Base.FrameIndex << '\n';
Anton Korobeynikov3360da92009-07-16 13:44:00 +000071 }
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000072 if (!isRI) {
Chris Lattner4437ae22009-08-23 07:05:07 +000073 errs() << "IndexReg ";
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000074 if (IndexReg.getNode() != 0) IndexReg.getNode()->dump();
Chris Lattner4437ae22009-08-23 07:05:07 +000075 else errs() << "nul";
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000076 }
Chris Lattner4437ae22009-08-23 07:05:07 +000077 errs() << " Disp " << Disp << '\n';
Anton Korobeynikov3360da92009-07-16 13:44:00 +000078 }
79 };
80}
81
Anton Korobeynikov4403b932009-07-16 13:27:25 +000082/// SystemZDAGToDAGISel - SystemZ specific code to select SystemZ machine
83/// instructions for SelectionDAG operations.
84///
85namespace {
86 class SystemZDAGToDAGISel : public SelectionDAGISel {
Dan Gohmand858e902010-04-17 15:26:15 +000087 const SystemZTargetLowering &Lowering;
Anton Korobeynikov4403b932009-07-16 13:27:25 +000088 const SystemZSubtarget &Subtarget;
89
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000090 void getAddressOperandsRI(const SystemZRRIAddressMode &AM,
91 SDValue &Base, SDValue &Disp);
Anton Korobeynikov720e3b02009-07-16 14:09:35 +000092 void getAddressOperands(const SystemZRRIAddressMode &AM,
93 SDValue &Base, SDValue &Disp,
94 SDValue &Index);
95
Anton Korobeynikov4403b932009-07-16 13:27:25 +000096 public:
97 SystemZDAGToDAGISel(SystemZTargetMachine &TM, CodeGenOpt::Level OptLevel)
98 : SelectionDAGISel(TM, OptLevel),
99 Lowering(*TM.getTargetLowering()),
100 Subtarget(*TM.getSubtargetImpl()) { }
101
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000102 virtual const char *getPassName() const {
103 return "SystemZ DAG->DAG Pattern Instruction Selection";
104 }
105
Anton Korobeynikovb6831cb2009-07-16 14:26:38 +0000106 /// getI8Imm - Return a target constant with the specified value, of type
107 /// i8.
108 inline SDValue getI8Imm(uint64_t Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000109 return CurDAG->getTargetConstant(Imm, MVT::i8);
Anton Korobeynikovb6831cb2009-07-16 14:26:38 +0000110 }
111
Anton Korobeynikov89edcd02009-07-16 13:33:57 +0000112 /// getI16Imm - Return a target constant with the specified value, of type
113 /// i16.
114 inline SDValue getI16Imm(uint64_t Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000115 return CurDAG->getTargetConstant(Imm, MVT::i16);
Anton Korobeynikov89edcd02009-07-16 13:33:57 +0000116 }
117
Anton Korobeynikovda308c92009-07-16 13:34:50 +0000118 /// getI32Imm - Return a target constant with the specified value, of type
119 /// i32.
120 inline SDValue getI32Imm(uint64_t Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000121 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikovda308c92009-07-16 13:34:50 +0000122 }
123
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000124 // Include the pieces autogenerated from the target description.
Anton Korobeynikov89edcd02009-07-16 13:33:57 +0000125 #include "SystemZGenDAGISel.inc"
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000126
127 private:
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000128 bool SelectAddrRI12Only(SDNode *Op, SDValue& Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000129 SDValue &Base, SDValue &Disp);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000130 bool SelectAddrRI12(SDNode *Op, SDValue& Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000131 SDValue &Base, SDValue &Disp,
132 bool is12BitOnly = false);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000133 bool SelectAddrRI(SDNode *Op, SDValue& Addr,
Anton Korobeynikov9e4816e2009-07-16 13:43:18 +0000134 SDValue &Base, SDValue &Disp);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000135 bool SelectAddrRRI12(SDNode *Op, SDValue Addr,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000136 SDValue &Base, SDValue &Disp, SDValue &Index);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000137 bool SelectAddrRRI20(SDNode *Op, SDValue Addr,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000138 SDValue &Base, SDValue &Disp, SDValue &Index);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000139 bool SelectLAAddr(SDNode *Op, SDValue Addr,
Anton Korobeynikovc4368a12009-07-16 13:48:42 +0000140 SDValue &Base, SDValue &Disp, SDValue &Index);
141
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000142 SDNode *Select(SDNode *Node);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000143
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000144 bool TryFoldLoad(SDNode *P, SDValue N,
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000145 SDValue &Base, SDValue &Disp, SDValue &Index);
146
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000147 bool MatchAddress(SDValue N, SystemZRRIAddressMode &AM,
148 bool is12Bit, unsigned Depth = 0);
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000149 bool MatchAddressBase(SDValue N, SystemZRRIAddressMode &AM);
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000150 bool MatchAddressRI(SDValue N, SystemZRRIAddressMode &AM,
151 bool is12Bit);
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000152 };
153} // end anonymous namespace
154
155/// createSystemZISelDag - This pass converts a legalized DAG into a
156/// SystemZ-specific DAG, ready for instruction scheduling.
157///
158FunctionPass *llvm::createSystemZISelDag(SystemZTargetMachine &TM,
159 CodeGenOpt::Level OptLevel) {
160 return new SystemZDAGToDAGISel(TM, OptLevel);
161}
162
Anton Korobeynikov9e4816e2009-07-16 13:43:18 +0000163/// isImmSExt20 - This method tests to see if the node is either a 32-bit
164/// or 64-bit immediate, and if the value can be accurately represented as a
165/// sign extension from a 20-bit value. If so, this returns true and the
166/// immediate.
Anton Korobeynikov32407402009-07-16 13:48:23 +0000167static bool isImmSExt20(int64_t Val, int64_t &Imm) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000168 if (Val >= -524288 && Val <= 524287) {
Anton Korobeynikov32407402009-07-16 13:48:23 +0000169 Imm = Val;
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000170 return true;
171 }
172 return false;
173}
174
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000175/// isImmZExt12 - This method tests to see if the node is either a 32-bit
Anton Korobeynikov3166a9a2009-07-16 14:03:41 +0000176/// or 64-bit immediate, and if the value can be accurately represented as a
177/// zero extension from a 12-bit value. If so, this returns true and the
178/// immediate.
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000179static bool isImmZExt12(int64_t Val, int64_t &Imm) {
180 if (Val >= 0 && Val <= 0xFFF) {
Anton Korobeynikov3166a9a2009-07-16 14:03:41 +0000181 Imm = Val;
182 return true;
183 }
Anton Korobeynikov3166a9a2009-07-16 14:03:41 +0000184 return false;
185}
186
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000187/// MatchAddress - Add the specified node to the specified addressing mode,
188/// returning true if it cannot be done. This just pattern matches for the
189/// addressing mode.
190bool SystemZDAGToDAGISel::MatchAddress(SDValue N, SystemZRRIAddressMode &AM,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000191 bool is12Bit, unsigned Depth) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000192 DebugLoc dl = N.getDebugLoc();
Chris Lattner893e1c92009-08-23 06:49:22 +0000193 DEBUG(errs() << "MatchAddress: "; AM.dump());
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000194 // Limit recursion.
195 if (Depth > 5)
196 return MatchAddressBase(N, AM);
197
Anton Korobeynikovdc289552009-07-16 13:44:30 +0000198 // FIXME: We can perform better here. If we have something like
199 // (shift (add A, imm), N), we can try to reassociate stuff and fold shift of
200 // imm into addressing mode.
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000201 switch (N.getOpcode()) {
202 default: break;
203 case ISD::Constant: {
Anton Korobeynikov32407402009-07-16 13:48:23 +0000204 int64_t Val = cast<ConstantSDNode>(N)->getSExtValue();
Daniel Dunbar19c29f52009-07-17 02:19:26 +0000205 int64_t Imm = 0;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000206 bool Match = (is12Bit ?
207 isImmZExt12(AM.Disp + Val, Imm) :
208 isImmSExt20(AM.Disp + Val, Imm));
209 if (Match) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000210 AM.Disp = Imm;
211 return false;
212 }
213 break;
214 }
215
216 case ISD::FrameIndex:
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000217 if (AM.BaseType == SystemZRRIAddressMode::RegBase &&
218 AM.Base.Reg.getNode() == 0) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000219 AM.BaseType = SystemZRRIAddressMode::FrameIndexBase;
220 AM.Base.FrameIndex = cast<FrameIndexSDNode>(N)->getIndex();
221 return false;
222 }
223 break;
224
225 case ISD::SUB: {
226 // Given A-B, if A can be completely folded into the address and
227 // the index field with the index field unused, use -B as the index.
228 // This is a win if a has multiple parts that can be folded into
229 // the address. Also, this saves a mov if the base register has
230 // other uses, since it avoids a two-address sub instruction, however
231 // it costs an additional mov if the index register has other uses.
232
233 // Test if the LHS of the sub can be folded.
234 SystemZRRIAddressMode Backup = AM;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000235 if (MatchAddress(N.getNode()->getOperand(0), AM, is12Bit, Depth+1)) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000236 AM = Backup;
237 break;
238 }
239 // Test if the index field is free for use.
Anton Korobeynikov54681ec2009-07-16 14:31:14 +0000240 if (AM.IndexReg.getNode() || AM.isRI) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000241 AM = Backup;
242 break;
243 }
244
245 // If the base is a register with multiple uses, this transformation may
246 // save a mov. Otherwise it's probably better not to do it.
247 if (AM.BaseType == SystemZRRIAddressMode::RegBase &&
248 (!AM.Base.Reg.getNode() || AM.Base.Reg.getNode()->hasOneUse())) {
249 AM = Backup;
250 break;
251 }
252
253 // Ok, the transformation is legal and appears profitable. Go for it.
254 SDValue RHS = N.getNode()->getOperand(1);
255 SDValue Zero = CurDAG->getConstant(0, N.getValueType());
256 SDValue Neg = CurDAG->getNode(ISD::SUB, dl, N.getValueType(), Zero, RHS);
257 AM.IndexReg = Neg;
258
259 // Insert the new nodes into the topological ordering.
260 if (Zero.getNode()->getNodeId() == -1 ||
261 Zero.getNode()->getNodeId() > N.getNode()->getNodeId()) {
262 CurDAG->RepositionNode(N.getNode(), Zero.getNode());
263 Zero.getNode()->setNodeId(N.getNode()->getNodeId());
264 }
265 if (Neg.getNode()->getNodeId() == -1 ||
266 Neg.getNode()->getNodeId() > N.getNode()->getNodeId()) {
267 CurDAG->RepositionNode(N.getNode(), Neg.getNode());
268 Neg.getNode()->setNodeId(N.getNode()->getNodeId());
269 }
270 return false;
271 }
272
273 case ISD::ADD: {
274 SystemZRRIAddressMode Backup = AM;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000275 if (!MatchAddress(N.getNode()->getOperand(0), AM, is12Bit, Depth+1) &&
276 !MatchAddress(N.getNode()->getOperand(1), AM, is12Bit, Depth+1))
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000277 return false;
278 AM = Backup;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000279 if (!MatchAddress(N.getNode()->getOperand(1), AM, is12Bit, Depth+1) &&
280 !MatchAddress(N.getNode()->getOperand(0), AM, is12Bit, Depth+1))
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000281 return false;
282 AM = Backup;
283
284 // If we couldn't fold both operands into the address at the same time,
285 // see if we can just put each operand into a register and fold at least
286 // the add.
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000287 if (!AM.isRI &&
288 AM.BaseType == SystemZRRIAddressMode::RegBase &&
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000289 !AM.Base.Reg.getNode() && !AM.IndexReg.getNode()) {
290 AM.Base.Reg = N.getNode()->getOperand(0);
291 AM.IndexReg = N.getNode()->getOperand(1);
292 return false;
293 }
294 break;
295 }
296
297 case ISD::OR:
298 // Handle "X | C" as "X + C" iff X is known to have C bits clear.
299 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
300 SystemZRRIAddressMode Backup = AM;
Anton Korobeynikov32407402009-07-16 13:48:23 +0000301 int64_t Offset = CN->getSExtValue();
Daniel Dunbar19c29f52009-07-17 02:19:26 +0000302 int64_t Imm = 0;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000303 bool MatchOffset = (is12Bit ?
304 isImmZExt12(AM.Disp + Offset, Imm) :
305 isImmSExt20(AM.Disp + Offset, Imm));
306 // The resultant disp must fit in 12 or 20-bits.
307 if (MatchOffset &&
308 // LHS should be an addr mode.
309 !MatchAddress(N.getOperand(0), AM, is12Bit, Depth+1) &&
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000310 // Check to see if the LHS & C is zero.
311 CurDAG->MaskedValueIsZero(N.getOperand(0), CN->getAPIntValue())) {
312 AM.Disp = Imm;
313 return false;
314 }
315 AM = Backup;
316 }
317 break;
318 }
319
320 return MatchAddressBase(N, AM);
321}
322
323/// MatchAddressBase - Helper for MatchAddress. Add the specified node to the
324/// specified addressing mode without any further recursion.
325bool SystemZDAGToDAGISel::MatchAddressBase(SDValue N,
326 SystemZRRIAddressMode &AM) {
327 // Is the base register already occupied?
328 if (AM.BaseType != SystemZRRIAddressMode::RegBase || AM.Base.Reg.getNode()) {
Anton Korobeynikov46567602009-07-16 14:10:35 +0000329 // If so, check to see if the index register is set.
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000330 if (AM.IndexReg.getNode() == 0 && !AM.isRI) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000331 AM.IndexReg = N;
332 return false;
333 }
334
335 // Otherwise, we cannot select it.
336 return true;
337 }
338
339 // Default, generate it as a register.
340 AM.BaseType = SystemZRRIAddressMode::RegBase;
341 AM.Base.Reg = N;
342 return false;
343}
344
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000345void SystemZDAGToDAGISel::getAddressOperandsRI(const SystemZRRIAddressMode &AM,
346 SDValue &Base, SDValue &Disp) {
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000347 if (AM.BaseType == SystemZRRIAddressMode::RegBase)
348 Base = AM.Base.Reg;
349 else
350 Base = CurDAG->getTargetFrameIndex(AM.Base.FrameIndex, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000351 Disp = CurDAG->getTargetConstant(AM.Disp, MVT::i64);
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000352}
353
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000354void SystemZDAGToDAGISel::getAddressOperands(const SystemZRRIAddressMode &AM,
355 SDValue &Base, SDValue &Disp,
356 SDValue &Index) {
357 getAddressOperandsRI(AM, Base, Disp);
358 Index = AM.IndexReg;
359}
360
361/// Returns true if the address can be represented by a base register plus
362/// an unsigned 12-bit displacement [r+imm].
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000363bool SystemZDAGToDAGISel::SelectAddrRI12Only(SDNode *Op, SDValue& Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000364 SDValue &Base, SDValue &Disp) {
365 return SelectAddrRI12(Op, Addr, Base, Disp, /*is12BitOnly*/true);
366}
367
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000368bool SystemZDAGToDAGISel::SelectAddrRI12(SDNode *Op, SDValue& Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000369 SDValue &Base, SDValue &Disp,
370 bool is12BitOnly) {
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000371 SystemZRRIAddressMode AM20(/*isRI*/true), AM12(/*isRI*/true);
372 bool Done = false;
373
374 if (!Addr.hasOneUse()) {
375 unsigned Opcode = Addr.getOpcode();
376 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
377 // If we are able to fold N into addressing mode, then we'll allow it even
378 // if N has multiple uses. In general, addressing computation is used as
379 // addresses by all of its uses. But watch out for CopyToReg uses, that
380 // means the address computation is liveout. It will be computed by a LA
381 // so we want to avoid computing the address twice.
382 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
383 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
384 if (UI->getOpcode() == ISD::CopyToReg) {
385 MatchAddressBase(Addr, AM12);
386 Done = true;
387 break;
388 }
389 }
390 }
391 }
392 if (!Done && MatchAddress(Addr, AM12, /* is12Bit */ true))
393 return false;
394
395 // Check, whether we can match stuff using 20-bit displacements
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000396 if (!Done && !is12BitOnly &&
397 !MatchAddress(Addr, AM20, /* is12Bit */ false))
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000398 if (AM12.Disp == 0 && AM20.Disp != 0)
399 return false;
400
Chris Lattner893e1c92009-08-23 06:49:22 +0000401 DEBUG(errs() << "MatchAddress (final): "; AM12.dump());
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000402
Owen Andersone50ed302009-08-10 22:56:29 +0000403 EVT VT = Addr.getValueType();
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000404 if (AM12.BaseType == SystemZRRIAddressMode::RegBase) {
405 if (!AM12.Base.Reg.getNode())
406 AM12.Base.Reg = CurDAG->getRegister(0, VT);
407 }
408
409 assert(AM12.IndexReg.getNode() == 0 && "Invalid reg-imm address mode!");
410
411 getAddressOperandsRI(AM12, Base, Disp);
412
413 return true;
414}
415
416/// Returns true if the address can be represented by a base register plus
417/// a signed 20-bit displacement [r+imm].
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000418bool SystemZDAGToDAGISel::SelectAddrRI(SDNode *Op, SDValue& Addr,
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000419 SDValue &Base, SDValue &Disp) {
420 SystemZRRIAddressMode AM(/*isRI*/true);
421 bool Done = false;
422
423 if (!Addr.hasOneUse()) {
424 unsigned Opcode = Addr.getOpcode();
425 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
426 // If we are able to fold N into addressing mode, then we'll allow it even
427 // if N has multiple uses. In general, addressing computation is used as
428 // addresses by all of its uses. But watch out for CopyToReg uses, that
429 // means the address computation is liveout. It will be computed by a LA
430 // so we want to avoid computing the address twice.
431 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
432 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
433 if (UI->getOpcode() == ISD::CopyToReg) {
434 MatchAddressBase(Addr, AM);
435 Done = true;
436 break;
437 }
438 }
439 }
440 }
441 if (!Done && MatchAddress(Addr, AM, /* is12Bit */ false))
442 return false;
443
Chris Lattner893e1c92009-08-23 06:49:22 +0000444 DEBUG(errs() << "MatchAddress (final): "; AM.dump());
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000445
Owen Andersone50ed302009-08-10 22:56:29 +0000446 EVT VT = Addr.getValueType();
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000447 if (AM.BaseType == SystemZRRIAddressMode::RegBase) {
448 if (!AM.Base.Reg.getNode())
449 AM.Base.Reg = CurDAG->getRegister(0, VT);
450 }
451
452 assert(AM.IndexReg.getNode() == 0 && "Invalid reg-imm address mode!");
453
454 getAddressOperandsRI(AM, Base, Disp);
455
456 return true;
457}
458
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000459/// Returns true if the address can be represented by a base register plus
460/// index register plus an unsigned 12-bit displacement [base + idx + imm].
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000461bool SystemZDAGToDAGISel::SelectAddrRRI12(SDNode *Op, SDValue Addr,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000462 SDValue &Base, SDValue &Disp, SDValue &Index) {
Anton Korobeynikov46567602009-07-16 14:10:35 +0000463 SystemZRRIAddressMode AM20, AM12;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000464 bool Done = false;
465
466 if (!Addr.hasOneUse()) {
467 unsigned Opcode = Addr.getOpcode();
468 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
469 // If we are able to fold N into addressing mode, then we'll allow it even
470 // if N has multiple uses. In general, addressing computation is used as
471 // addresses by all of its uses. But watch out for CopyToReg uses, that
472 // means the address computation is liveout. It will be computed by a LA
473 // so we want to avoid computing the address twice.
474 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
475 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
476 if (UI->getOpcode() == ISD::CopyToReg) {
477 MatchAddressBase(Addr, AM12);
478 Done = true;
479 break;
480 }
481 }
482 }
483 }
484 if (!Done && MatchAddress(Addr, AM12, /* is12Bit */ true))
485 return false;
486
487 // Check, whether we can match stuff using 20-bit displacements
488 if (!Done && !MatchAddress(Addr, AM20, /* is12Bit */ false))
489 if (AM12.Disp == 0 && AM20.Disp != 0)
490 return false;
491
Chris Lattner893e1c92009-08-23 06:49:22 +0000492 DEBUG(errs() << "MatchAddress (final): "; AM12.dump());
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000493
Owen Andersone50ed302009-08-10 22:56:29 +0000494 EVT VT = Addr.getValueType();
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000495 if (AM12.BaseType == SystemZRRIAddressMode::RegBase) {
496 if (!AM12.Base.Reg.getNode())
497 AM12.Base.Reg = CurDAG->getRegister(0, VT);
498 }
499
500 if (!AM12.IndexReg.getNode())
501 AM12.IndexReg = CurDAG->getRegister(0, VT);
502
503 getAddressOperands(AM12, Base, Disp, Index);
504
505 return true;
506}
507
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000508/// Returns true if the address can be represented by a base register plus
509/// index register plus a signed 20-bit displacement [base + idx + imm].
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000510bool SystemZDAGToDAGISel::SelectAddrRRI20(SDNode *Op, SDValue Addr,
Anton Korobeynikovc4368a12009-07-16 13:48:42 +0000511 SDValue &Base, SDValue &Disp, SDValue &Index) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000512 SystemZRRIAddressMode AM;
513 bool Done = false;
514
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000515 if (!Addr.hasOneUse()) {
516 unsigned Opcode = Addr.getOpcode();
517 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
518 // If we are able to fold N into addressing mode, then we'll allow it even
519 // if N has multiple uses. In general, addressing computation is used as
520 // addresses by all of its uses. But watch out for CopyToReg uses, that
521 // means the address computation is liveout. It will be computed by a LA
522 // so we want to avoid computing the address twice.
523 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
524 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
525 if (UI->getOpcode() == ISD::CopyToReg) {
526 MatchAddressBase(Addr, AM);
527 Done = true;
528 break;
529 }
530 }
531 }
532 }
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000533 if (!Done && MatchAddress(Addr, AM, /* is12Bit */ false))
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000534 return false;
535
Chris Lattner893e1c92009-08-23 06:49:22 +0000536 DEBUG(errs() << "MatchAddress (final): "; AM.dump());
Anton Korobeynikov32407402009-07-16 13:48:23 +0000537
Owen Andersone50ed302009-08-10 22:56:29 +0000538 EVT VT = Addr.getValueType();
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000539 if (AM.BaseType == SystemZRRIAddressMode::RegBase) {
540 if (!AM.Base.Reg.getNode())
541 AM.Base.Reg = CurDAG->getRegister(0, VT);
542 }
543
544 if (!AM.IndexReg.getNode())
545 AM.IndexReg = CurDAG->getRegister(0, VT);
546
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000547 getAddressOperands(AM, Base, Disp, Index);
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000548
549 return true;
550}
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000551
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000552/// SelectLAAddr - it calls SelectAddr and determines if the maximal addressing
553/// mode it matches can be cost effectively emitted as an LA/LAY instruction.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000554bool SystemZDAGToDAGISel::SelectLAAddr(SDNode *Op, SDValue Addr,
Anton Korobeynikovc4368a12009-07-16 13:48:42 +0000555 SDValue &Base, SDValue &Disp, SDValue &Index) {
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000556 SystemZRRIAddressMode AM;
557
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000558 if (MatchAddress(Addr, AM, false))
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000559 return false;
560
Owen Andersone50ed302009-08-10 22:56:29 +0000561 EVT VT = Addr.getValueType();
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000562 unsigned Complexity = 0;
563 if (AM.BaseType == SystemZRRIAddressMode::RegBase)
564 if (AM.Base.Reg.getNode())
565 Complexity = 1;
566 else
567 AM.Base.Reg = CurDAG->getRegister(0, VT);
568 else if (AM.BaseType == SystemZRRIAddressMode::FrameIndexBase)
569 Complexity = 4;
570
571 if (AM.IndexReg.getNode())
572 Complexity += 1;
573 else
574 AM.IndexReg = CurDAG->getRegister(0, VT);
575
576 if (AM.Disp && (AM.Base.Reg.getNode() || AM.IndexReg.getNode()))
577 Complexity += 1;
578
579 if (Complexity > 2) {
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000580 getAddressOperands(AM, Base, Disp, Index);
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000581 return true;
582 }
583
584 return false;
585}
586
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000587bool SystemZDAGToDAGISel::TryFoldLoad(SDNode *P, SDValue N,
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000588 SDValue &Base, SDValue &Disp, SDValue &Index) {
589 if (ISD::isNON_EXTLoad(N.getNode()) &&
Dan Gohmand858e902010-04-17 15:26:15 +0000590 IsLegalToFold(N, P, P, OptLevel))
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000591 return SelectAddrRRI20(P, N.getOperand(1), Base, Disp, Index);
592 return false;
593}
594
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000595SDNode *SystemZDAGToDAGISel::Select(SDNode *Node) {
Owen Andersone50ed302009-08-10 22:56:29 +0000596 EVT NVT = Node->getValueType(0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000597 DebugLoc dl = Node->getDebugLoc();
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000598 unsigned Opcode = Node->getOpcode();
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000599
600 // Dump information about the Node being selected
Chris Lattner7c306da2010-03-02 06:34:30 +0000601 DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000602
603 // If we have a custom node, we already have selected!
604 if (Node->isMachineOpcode()) {
Chris Lattner7c306da2010-03-02 06:34:30 +0000605 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000606 return NULL; // Already selected.
607 }
608
609 switch (Opcode) {
610 default: break;
611 case ISD::SDIVREM: {
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000612 unsigned Opc, MOpc;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000613 SDValue N0 = Node->getOperand(0);
614 SDValue N1 = Node->getOperand(1);
615
Owen Andersone50ed302009-08-10 22:56:29 +0000616 EVT ResVT;
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000617 bool is32Bit = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000618 switch (NVT.getSimpleVT().SimpleTy) {
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000619 default: assert(0 && "Unsupported VT!");
620 case MVT::i32:
621 Opc = SystemZ::SDIVREM32r; MOpc = SystemZ::SDIVREM32m;
622 ResVT = MVT::v2i64;
623 is32Bit = true;
624 break;
625 case MVT::i64:
626 Opc = SystemZ::SDIVREM64r; MOpc = SystemZ::SDIVREM64m;
627 ResVT = MVT::v2i64;
628 break;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000629 }
630
631 SDValue Tmp0, Tmp1, Tmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000632 bool foldedLoad = TryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000633
634 // Prepare the dividend
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000635 SDNode *Dividend;
636 if (is32Bit)
Dan Gohman602b0c82009-09-25 18:54:59 +0000637 Dividend = CurDAG->getMachineNode(SystemZ::MOVSX64rr32, dl, MVT::i64, N0);
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000638 else
639 Dividend = N0.getNode();
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000640
641 // Insert prepared dividend into suitable 'subreg'
Chris Lattner518bb532010-02-09 19:54:29 +0000642 SDNode *Tmp = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
Dan Gohman602b0c82009-09-25 18:54:59 +0000643 dl, ResVT);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000644 Dividend =
Chris Lattner518bb532010-02-09 19:54:29 +0000645 CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl, ResVT,
Dan Gohman602b0c82009-09-25 18:54:59 +0000646 SDValue(Tmp, 0), SDValue(Dividend, 0),
647 CurDAG->getTargetConstant(subreg_odd, MVT::i32));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000648
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000649 SDNode *Result;
650 SDValue DivVal = SDValue(Dividend, 0);
651 if (foldedLoad) {
652 SDValue Ops[] = { DivVal, Tmp0, Tmp1, Tmp2, N1.getOperand(0) };
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000653 Result = CurDAG->getMachineNode(MOpc, dl, ResVT, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +0000654 Ops, array_lengthof(Ops));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000655 // Update the chain.
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000656 ReplaceUses(N1.getValue(1), SDValue(Result, 1));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000657 } else {
Dan Gohman602b0c82009-09-25 18:54:59 +0000658 Result = CurDAG->getMachineNode(Opc, dl, ResVT, SDValue(Dividend, 0), N1);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000659 }
660
661 // Copy the division (odd subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000662 if (!SDValue(Node, 0).use_empty()) {
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000663 unsigned SubRegIdx = (is32Bit ? subreg_odd32 : subreg_odd);
Chris Lattner518bb532010-02-09 19:54:29 +0000664 SDNode *Div = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000665 dl, NVT,
666 SDValue(Result, 0),
667 CurDAG->getTargetConstant(SubRegIdx,
668 MVT::i32));
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000669
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000670 ReplaceUses(SDValue(Node, 0), SDValue(Div, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000671 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000672 }
673
674 // Copy the remainder (even subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000675 if (!SDValue(Node, 1).use_empty()) {
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000676 unsigned SubRegIdx = (is32Bit ? subreg_even32 : subreg_even);
Chris Lattner518bb532010-02-09 19:54:29 +0000677 SDNode *Rem = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000678 dl, NVT,
679 SDValue(Result, 0),
680 CurDAG->getTargetConstant(SubRegIdx,
681 MVT::i32));
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000682
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000683 ReplaceUses(SDValue(Node, 1), SDValue(Rem, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000684 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000685 }
686
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000687 return NULL;
688 }
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000689 case ISD::UDIVREM: {
690 unsigned Opc, MOpc, ClrOpc;
691 SDValue N0 = Node->getOperand(0);
692 SDValue N1 = Node->getOperand(1);
Owen Andersone50ed302009-08-10 22:56:29 +0000693 EVT ResVT;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000694
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000695 bool is32Bit = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000696 switch (NVT.getSimpleVT().SimpleTy) {
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000697 default: assert(0 && "Unsupported VT!");
698 case MVT::i32:
699 Opc = SystemZ::UDIVREM32r; MOpc = SystemZ::UDIVREM32m;
700 ClrOpc = SystemZ::MOV64Pr0_even;
701 ResVT = MVT::v2i32;
702 is32Bit = true;
703 break;
704 case MVT::i64:
705 Opc = SystemZ::UDIVREM64r; MOpc = SystemZ::UDIVREM64m;
706 ClrOpc = SystemZ::MOV128r0_even;
707 ResVT = MVT::v2i64;
708 break;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000709 }
710
711 SDValue Tmp0, Tmp1, Tmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000712 bool foldedLoad = TryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000713
714 // Prepare the dividend
715 SDNode *Dividend = N0.getNode();
716
717 // Insert prepared dividend into suitable 'subreg'
Chris Lattner518bb532010-02-09 19:54:29 +0000718 SDNode *Tmp = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
Dan Gohman602b0c82009-09-25 18:54:59 +0000719 dl, ResVT);
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000720 {
721 unsigned SubRegIdx = (is32Bit ? subreg_odd32 : subreg_odd);
722 Dividend =
Chris Lattner518bb532010-02-09 19:54:29 +0000723 CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl, ResVT,
Dan Gohman602b0c82009-09-25 18:54:59 +0000724 SDValue(Tmp, 0), SDValue(Dividend, 0),
725 CurDAG->getTargetConstant(SubRegIdx, MVT::i32));
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000726 }
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000727
Anton Korobeynikove3a7f7a2009-07-16 14:14:54 +0000728 // Zero out even subreg
Dan Gohman602b0c82009-09-25 18:54:59 +0000729 Dividend = CurDAG->getMachineNode(ClrOpc, dl, ResVT, SDValue(Dividend, 0));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000730
731 SDValue DivVal = SDValue(Dividend, 0);
732 SDNode *Result;
733 if (foldedLoad) {
734 SDValue Ops[] = { DivVal, Tmp0, Tmp1, Tmp2, N1.getOperand(0) };
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000735 Result = CurDAG->getMachineNode(MOpc, dl, ResVT, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +0000736 Ops, array_lengthof(Ops));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000737 // Update the chain.
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000738 ReplaceUses(N1.getValue(1), SDValue(Result, 1));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000739 } else {
Dan Gohman602b0c82009-09-25 18:54:59 +0000740 Result = CurDAG->getMachineNode(Opc, dl, ResVT, DivVal, N1);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000741 }
742
743 // Copy the division (odd subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000744 if (!SDValue(Node, 0).use_empty()) {
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000745 unsigned SubRegIdx = (is32Bit ? subreg_odd32 : subreg_odd);
Chris Lattner518bb532010-02-09 19:54:29 +0000746 SDNode *Div = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000747 dl, NVT,
748 SDValue(Result, 0),
749 CurDAG->getTargetConstant(SubRegIdx,
750 MVT::i32));
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000751 ReplaceUses(SDValue(Node, 0), SDValue(Div, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000752 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000753 }
754
755 // Copy the remainder (even subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000756 if (!SDValue(Node, 1).use_empty()) {
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000757 unsigned SubRegIdx = (is32Bit ? subreg_even32 : subreg_even);
Chris Lattner518bb532010-02-09 19:54:29 +0000758 SDNode *Rem = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000759 dl, NVT,
760 SDValue(Result, 0),
761 CurDAG->getTargetConstant(SubRegIdx,
762 MVT::i32));
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000763 ReplaceUses(SDValue(Node, 1), SDValue(Rem, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000764 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000765 }
766
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000767 return NULL;
768 }
769 }
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000770
771 // Select the default instruction
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000772 SDNode *ResNode = SelectCode(Node);
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000773
Chris Lattner7c306da2010-03-02 06:34:30 +0000774 DEBUG(errs() << "=> ";
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000775 if (ResNode == NULL || ResNode == Node)
776 Node->dump(CurDAG);
Chris Lattner893e1c92009-08-23 06:49:22 +0000777 else
778 ResNode->dump(CurDAG);
779 errs() << "\n";
780 );
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000781 return ResNode;
782}