blob: a1eb6b379b854c735bee181dd6fa13d9d4b9cf4f [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 Korobeynikov3360da92009-07-16 13:44:00 +000033namespace {
34 /// SystemZRRIAddressMode - This corresponds to rriaddr, but uses SDValue's
35 /// instead of register numbers for the leaves of the matched tree.
36 struct SystemZRRIAddressMode {
37 enum {
38 RegBase,
39 FrameIndexBase
40 } BaseType;
41
42 struct { // This is really a union, discriminated by BaseType!
43 SDValue Reg;
44 int FrameIndex;
45 } Base;
46
47 SDValue IndexReg;
Anton Korobeynikov32407402009-07-16 13:48:23 +000048 int64_t Disp;
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000049 bool isRI;
Anton Korobeynikov3360da92009-07-16 13:44:00 +000050
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000051 SystemZRRIAddressMode(bool RI = false)
52 : BaseType(RegBase), IndexReg(), Disp(0), isRI(RI) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +000053 }
54
55 void dump() {
Chris Lattner4437ae22009-08-23 07:05:07 +000056 errs() << "SystemZRRIAddressMode " << this << '\n';
Anton Korobeynikov3360da92009-07-16 13:44:00 +000057 if (BaseType == RegBase) {
Chris Lattner4437ae22009-08-23 07:05:07 +000058 errs() << "Base.Reg ";
59 if (Base.Reg.getNode() != 0)
60 Base.Reg.getNode()->dump();
61 else
62 errs() << "nul";
63 errs() << '\n';
Anton Korobeynikov3360da92009-07-16 13:44:00 +000064 } else {
Chris Lattner4437ae22009-08-23 07:05:07 +000065 errs() << " Base.FrameIndex " << Base.FrameIndex << '\n';
Anton Korobeynikov3360da92009-07-16 13:44:00 +000066 }
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000067 if (!isRI) {
Chris Lattner4437ae22009-08-23 07:05:07 +000068 errs() << "IndexReg ";
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000069 if (IndexReg.getNode() != 0) IndexReg.getNode()->dump();
Chris Lattner4437ae22009-08-23 07:05:07 +000070 else errs() << "nul";
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000071 }
Chris Lattner4437ae22009-08-23 07:05:07 +000072 errs() << " Disp " << Disp << '\n';
Anton Korobeynikov3360da92009-07-16 13:44:00 +000073 }
74 };
75}
76
Anton Korobeynikov4403b932009-07-16 13:27:25 +000077/// SystemZDAGToDAGISel - SystemZ specific code to select SystemZ machine
78/// instructions for SelectionDAG operations.
79///
80namespace {
81 class SystemZDAGToDAGISel : public SelectionDAGISel {
Dan Gohmand858e902010-04-17 15:26:15 +000082 const SystemZTargetLowering &Lowering;
Anton Korobeynikov4403b932009-07-16 13:27:25 +000083 const SystemZSubtarget &Subtarget;
84
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +000085 void getAddressOperandsRI(const SystemZRRIAddressMode &AM,
86 SDValue &Base, SDValue &Disp);
Anton Korobeynikov720e3b02009-07-16 14:09:35 +000087 void getAddressOperands(const SystemZRRIAddressMode &AM,
88 SDValue &Base, SDValue &Disp,
89 SDValue &Index);
90
Anton Korobeynikov4403b932009-07-16 13:27:25 +000091 public:
92 SystemZDAGToDAGISel(SystemZTargetMachine &TM, CodeGenOpt::Level OptLevel)
93 : SelectionDAGISel(TM, OptLevel),
94 Lowering(*TM.getTargetLowering()),
95 Subtarget(*TM.getSubtargetImpl()) { }
96
Anton Korobeynikov4403b932009-07-16 13:27:25 +000097 virtual const char *getPassName() const {
98 return "SystemZ DAG->DAG Pattern Instruction Selection";
99 }
100
Anton Korobeynikovb6831cb2009-07-16 14:26:38 +0000101 /// getI8Imm - Return a target constant with the specified value, of type
102 /// i8.
103 inline SDValue getI8Imm(uint64_t Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000104 return CurDAG->getTargetConstant(Imm, MVT::i8);
Anton Korobeynikovb6831cb2009-07-16 14:26:38 +0000105 }
106
Anton Korobeynikov89edcd02009-07-16 13:33:57 +0000107 /// getI16Imm - Return a target constant with the specified value, of type
108 /// i16.
109 inline SDValue getI16Imm(uint64_t Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000110 return CurDAG->getTargetConstant(Imm, MVT::i16);
Anton Korobeynikov89edcd02009-07-16 13:33:57 +0000111 }
112
Anton Korobeynikovda308c92009-07-16 13:34:50 +0000113 /// getI32Imm - Return a target constant with the specified value, of type
114 /// i32.
115 inline SDValue getI32Imm(uint64_t Imm) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000116 return CurDAG->getTargetConstant(Imm, MVT::i32);
Anton Korobeynikovda308c92009-07-16 13:34:50 +0000117 }
118
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000119 // Include the pieces autogenerated from the target description.
Anton Korobeynikov89edcd02009-07-16 13:33:57 +0000120 #include "SystemZGenDAGISel.inc"
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000121
122 private:
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000123 bool SelectAddrRI12Only(SDNode *Op, SDValue& Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000124 SDValue &Base, SDValue &Disp);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000125 bool SelectAddrRI12(SDNode *Op, SDValue& Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000126 SDValue &Base, SDValue &Disp,
127 bool is12BitOnly = false);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000128 bool SelectAddrRI(SDNode *Op, SDValue& Addr,
Anton Korobeynikov9e4816e2009-07-16 13:43:18 +0000129 SDValue &Base, SDValue &Disp);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000130 bool SelectAddrRRI12(SDNode *Op, SDValue Addr,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000131 SDValue &Base, SDValue &Disp, SDValue &Index);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000132 bool SelectAddrRRI20(SDNode *Op, SDValue Addr,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000133 SDValue &Base, SDValue &Disp, SDValue &Index);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000134 bool SelectLAAddr(SDNode *Op, SDValue Addr,
Anton Korobeynikovc4368a12009-07-16 13:48:42 +0000135 SDValue &Base, SDValue &Disp, SDValue &Index);
136
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000137 SDNode *Select(SDNode *Node);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000138
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000139 bool TryFoldLoad(SDNode *P, SDValue N,
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000140 SDValue &Base, SDValue &Disp, SDValue &Index);
141
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000142 bool MatchAddress(SDValue N, SystemZRRIAddressMode &AM,
143 bool is12Bit, unsigned Depth = 0);
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000144 bool MatchAddressBase(SDValue N, SystemZRRIAddressMode &AM);
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000145 };
146} // end anonymous namespace
147
148/// createSystemZISelDag - This pass converts a legalized DAG into a
149/// SystemZ-specific DAG, ready for instruction scheduling.
150///
151FunctionPass *llvm::createSystemZISelDag(SystemZTargetMachine &TM,
152 CodeGenOpt::Level OptLevel) {
153 return new SystemZDAGToDAGISel(TM, OptLevel);
154}
155
Anton Korobeynikov9e4816e2009-07-16 13:43:18 +0000156/// isImmSExt20 - This method tests to see if the node is either a 32-bit
157/// or 64-bit immediate, and if the value can be accurately represented as a
158/// sign extension from a 20-bit value. If so, this returns true and the
159/// immediate.
Anton Korobeynikov32407402009-07-16 13:48:23 +0000160static bool isImmSExt20(int64_t Val, int64_t &Imm) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000161 if (Val >= -524288 && Val <= 524287) {
Anton Korobeynikov32407402009-07-16 13:48:23 +0000162 Imm = Val;
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000163 return true;
164 }
165 return false;
166}
167
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000168/// isImmZExt12 - This method tests to see if the node is either a 32-bit
Anton Korobeynikov3166a9a2009-07-16 14:03:41 +0000169/// or 64-bit immediate, and if the value can be accurately represented as a
170/// zero extension from a 12-bit value. If so, this returns true and the
171/// immediate.
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000172static bool isImmZExt12(int64_t Val, int64_t &Imm) {
173 if (Val >= 0 && Val <= 0xFFF) {
Anton Korobeynikov3166a9a2009-07-16 14:03:41 +0000174 Imm = Val;
175 return true;
176 }
Anton Korobeynikov3166a9a2009-07-16 14:03:41 +0000177 return false;
178}
179
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000180/// MatchAddress - Add the specified node to the specified addressing mode,
181/// returning true if it cannot be done. This just pattern matches for the
182/// addressing mode.
183bool SystemZDAGToDAGISel::MatchAddress(SDValue N, SystemZRRIAddressMode &AM,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000184 bool is12Bit, unsigned Depth) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000185 DebugLoc dl = N.getDebugLoc();
Chris Lattner893e1c92009-08-23 06:49:22 +0000186 DEBUG(errs() << "MatchAddress: "; AM.dump());
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000187 // Limit recursion.
188 if (Depth > 5)
189 return MatchAddressBase(N, AM);
190
Anton Korobeynikovdc289552009-07-16 13:44:30 +0000191 // FIXME: We can perform better here. If we have something like
192 // (shift (add A, imm), N), we can try to reassociate stuff and fold shift of
193 // imm into addressing mode.
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000194 switch (N.getOpcode()) {
195 default: break;
196 case ISD::Constant: {
Anton Korobeynikov32407402009-07-16 13:48:23 +0000197 int64_t Val = cast<ConstantSDNode>(N)->getSExtValue();
Daniel Dunbar19c29f52009-07-17 02:19:26 +0000198 int64_t Imm = 0;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000199 bool Match = (is12Bit ?
200 isImmZExt12(AM.Disp + Val, Imm) :
201 isImmSExt20(AM.Disp + Val, Imm));
202 if (Match) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000203 AM.Disp = Imm;
204 return false;
205 }
206 break;
207 }
208
209 case ISD::FrameIndex:
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000210 if (AM.BaseType == SystemZRRIAddressMode::RegBase &&
211 AM.Base.Reg.getNode() == 0) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000212 AM.BaseType = SystemZRRIAddressMode::FrameIndexBase;
213 AM.Base.FrameIndex = cast<FrameIndexSDNode>(N)->getIndex();
214 return false;
215 }
216 break;
217
218 case ISD::SUB: {
219 // Given A-B, if A can be completely folded into the address and
220 // the index field with the index field unused, use -B as the index.
221 // This is a win if a has multiple parts that can be folded into
222 // the address. Also, this saves a mov if the base register has
223 // other uses, since it avoids a two-address sub instruction, however
224 // it costs an additional mov if the index register has other uses.
225
226 // Test if the LHS of the sub can be folded.
227 SystemZRRIAddressMode Backup = AM;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000228 if (MatchAddress(N.getNode()->getOperand(0), AM, is12Bit, Depth+1)) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000229 AM = Backup;
230 break;
231 }
232 // Test if the index field is free for use.
Anton Korobeynikov54681ec2009-07-16 14:31:14 +0000233 if (AM.IndexReg.getNode() || AM.isRI) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000234 AM = Backup;
235 break;
236 }
237
238 // If the base is a register with multiple uses, this transformation may
239 // save a mov. Otherwise it's probably better not to do it.
240 if (AM.BaseType == SystemZRRIAddressMode::RegBase &&
241 (!AM.Base.Reg.getNode() || AM.Base.Reg.getNode()->hasOneUse())) {
242 AM = Backup;
243 break;
244 }
245
246 // Ok, the transformation is legal and appears profitable. Go for it.
247 SDValue RHS = N.getNode()->getOperand(1);
248 SDValue Zero = CurDAG->getConstant(0, N.getValueType());
249 SDValue Neg = CurDAG->getNode(ISD::SUB, dl, N.getValueType(), Zero, RHS);
250 AM.IndexReg = Neg;
251
252 // Insert the new nodes into the topological ordering.
253 if (Zero.getNode()->getNodeId() == -1 ||
254 Zero.getNode()->getNodeId() > N.getNode()->getNodeId()) {
255 CurDAG->RepositionNode(N.getNode(), Zero.getNode());
256 Zero.getNode()->setNodeId(N.getNode()->getNodeId());
257 }
258 if (Neg.getNode()->getNodeId() == -1 ||
259 Neg.getNode()->getNodeId() > N.getNode()->getNodeId()) {
260 CurDAG->RepositionNode(N.getNode(), Neg.getNode());
261 Neg.getNode()->setNodeId(N.getNode()->getNodeId());
262 }
263 return false;
264 }
265
266 case ISD::ADD: {
267 SystemZRRIAddressMode Backup = AM;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000268 if (!MatchAddress(N.getNode()->getOperand(0), AM, is12Bit, Depth+1) &&
269 !MatchAddress(N.getNode()->getOperand(1), AM, is12Bit, Depth+1))
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000270 return false;
271 AM = Backup;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000272 if (!MatchAddress(N.getNode()->getOperand(1), AM, is12Bit, Depth+1) &&
273 !MatchAddress(N.getNode()->getOperand(0), AM, is12Bit, Depth+1))
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000274 return false;
275 AM = Backup;
276
277 // If we couldn't fold both operands into the address at the same time,
278 // see if we can just put each operand into a register and fold at least
279 // the add.
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000280 if (!AM.isRI &&
281 AM.BaseType == SystemZRRIAddressMode::RegBase &&
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000282 !AM.Base.Reg.getNode() && !AM.IndexReg.getNode()) {
283 AM.Base.Reg = N.getNode()->getOperand(0);
284 AM.IndexReg = N.getNode()->getOperand(1);
285 return false;
286 }
287 break;
288 }
289
290 case ISD::OR:
291 // Handle "X | C" as "X + C" iff X is known to have C bits clear.
292 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
293 SystemZRRIAddressMode Backup = AM;
Anton Korobeynikov32407402009-07-16 13:48:23 +0000294 int64_t Offset = CN->getSExtValue();
Daniel Dunbar19c29f52009-07-17 02:19:26 +0000295 int64_t Imm = 0;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000296 bool MatchOffset = (is12Bit ?
297 isImmZExt12(AM.Disp + Offset, Imm) :
298 isImmSExt20(AM.Disp + Offset, Imm));
299 // The resultant disp must fit in 12 or 20-bits.
300 if (MatchOffset &&
301 // LHS should be an addr mode.
302 !MatchAddress(N.getOperand(0), AM, is12Bit, Depth+1) &&
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000303 // Check to see if the LHS & C is zero.
304 CurDAG->MaskedValueIsZero(N.getOperand(0), CN->getAPIntValue())) {
305 AM.Disp = Imm;
306 return false;
307 }
308 AM = Backup;
309 }
310 break;
311 }
312
313 return MatchAddressBase(N, AM);
314}
315
316/// MatchAddressBase - Helper for MatchAddress. Add the specified node to the
317/// specified addressing mode without any further recursion.
318bool SystemZDAGToDAGISel::MatchAddressBase(SDValue N,
319 SystemZRRIAddressMode &AM) {
320 // Is the base register already occupied?
321 if (AM.BaseType != SystemZRRIAddressMode::RegBase || AM.Base.Reg.getNode()) {
Anton Korobeynikov46567602009-07-16 14:10:35 +0000322 // If so, check to see if the index register is set.
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000323 if (AM.IndexReg.getNode() == 0 && !AM.isRI) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000324 AM.IndexReg = N;
325 return false;
326 }
327
328 // Otherwise, we cannot select it.
329 return true;
330 }
331
332 // Default, generate it as a register.
333 AM.BaseType = SystemZRRIAddressMode::RegBase;
334 AM.Base.Reg = N;
335 return false;
336}
337
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000338void SystemZDAGToDAGISel::getAddressOperandsRI(const SystemZRRIAddressMode &AM,
339 SDValue &Base, SDValue &Disp) {
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000340 if (AM.BaseType == SystemZRRIAddressMode::RegBase)
341 Base = AM.Base.Reg;
342 else
343 Base = CurDAG->getTargetFrameIndex(AM.Base.FrameIndex, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000344 Disp = CurDAG->getTargetConstant(AM.Disp, MVT::i64);
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000345}
346
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000347void SystemZDAGToDAGISel::getAddressOperands(const SystemZRRIAddressMode &AM,
348 SDValue &Base, SDValue &Disp,
349 SDValue &Index) {
350 getAddressOperandsRI(AM, Base, Disp);
351 Index = AM.IndexReg;
352}
353
354/// Returns true if the address can be represented by a base register plus
355/// an unsigned 12-bit displacement [r+imm].
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000356bool SystemZDAGToDAGISel::SelectAddrRI12Only(SDNode *Op, SDValue& Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000357 SDValue &Base, SDValue &Disp) {
358 return SelectAddrRI12(Op, Addr, Base, Disp, /*is12BitOnly*/true);
359}
360
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000361bool SystemZDAGToDAGISel::SelectAddrRI12(SDNode *Op, SDValue& Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000362 SDValue &Base, SDValue &Disp,
363 bool is12BitOnly) {
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000364 SystemZRRIAddressMode AM20(/*isRI*/true), AM12(/*isRI*/true);
365 bool Done = false;
366
367 if (!Addr.hasOneUse()) {
368 unsigned Opcode = Addr.getOpcode();
369 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
370 // If we are able to fold N into addressing mode, then we'll allow it even
371 // if N has multiple uses. In general, addressing computation is used as
372 // addresses by all of its uses. But watch out for CopyToReg uses, that
373 // means the address computation is liveout. It will be computed by a LA
374 // so we want to avoid computing the address twice.
375 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
376 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
377 if (UI->getOpcode() == ISD::CopyToReg) {
378 MatchAddressBase(Addr, AM12);
379 Done = true;
380 break;
381 }
382 }
383 }
384 }
385 if (!Done && MatchAddress(Addr, AM12, /* is12Bit */ true))
386 return false;
387
388 // Check, whether we can match stuff using 20-bit displacements
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000389 if (!Done && !is12BitOnly &&
390 !MatchAddress(Addr, AM20, /* is12Bit */ false))
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000391 if (AM12.Disp == 0 && AM20.Disp != 0)
392 return false;
393
Chris Lattner893e1c92009-08-23 06:49:22 +0000394 DEBUG(errs() << "MatchAddress (final): "; AM12.dump());
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000395
Owen Andersone50ed302009-08-10 22:56:29 +0000396 EVT VT = Addr.getValueType();
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000397 if (AM12.BaseType == SystemZRRIAddressMode::RegBase) {
398 if (!AM12.Base.Reg.getNode())
399 AM12.Base.Reg = CurDAG->getRegister(0, VT);
400 }
401
402 assert(AM12.IndexReg.getNode() == 0 && "Invalid reg-imm address mode!");
403
404 getAddressOperandsRI(AM12, Base, Disp);
405
406 return true;
407}
408
409/// Returns true if the address can be represented by a base register plus
410/// a signed 20-bit displacement [r+imm].
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000411bool SystemZDAGToDAGISel::SelectAddrRI(SDNode *Op, SDValue& Addr,
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000412 SDValue &Base, SDValue &Disp) {
413 SystemZRRIAddressMode AM(/*isRI*/true);
414 bool Done = false;
415
416 if (!Addr.hasOneUse()) {
417 unsigned Opcode = Addr.getOpcode();
418 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
419 // If we are able to fold N into addressing mode, then we'll allow it even
420 // if N has multiple uses. In general, addressing computation is used as
421 // addresses by all of its uses. But watch out for CopyToReg uses, that
422 // means the address computation is liveout. It will be computed by a LA
423 // so we want to avoid computing the address twice.
424 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
425 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
426 if (UI->getOpcode() == ISD::CopyToReg) {
427 MatchAddressBase(Addr, AM);
428 Done = true;
429 break;
430 }
431 }
432 }
433 }
434 if (!Done && MatchAddress(Addr, AM, /* is12Bit */ false))
435 return false;
436
Chris Lattner893e1c92009-08-23 06:49:22 +0000437 DEBUG(errs() << "MatchAddress (final): "; AM.dump());
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000438
Owen Andersone50ed302009-08-10 22:56:29 +0000439 EVT VT = Addr.getValueType();
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000440 if (AM.BaseType == SystemZRRIAddressMode::RegBase) {
441 if (!AM.Base.Reg.getNode())
442 AM.Base.Reg = CurDAG->getRegister(0, VT);
443 }
444
445 assert(AM.IndexReg.getNode() == 0 && "Invalid reg-imm address mode!");
446
447 getAddressOperandsRI(AM, Base, Disp);
448
449 return true;
450}
451
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000452/// Returns true if the address can be represented by a base register plus
453/// index register plus an unsigned 12-bit displacement [base + idx + imm].
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000454bool SystemZDAGToDAGISel::SelectAddrRRI12(SDNode *Op, SDValue Addr,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000455 SDValue &Base, SDValue &Disp, SDValue &Index) {
Anton Korobeynikov46567602009-07-16 14:10:35 +0000456 SystemZRRIAddressMode AM20, AM12;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000457 bool Done = false;
458
459 if (!Addr.hasOneUse()) {
460 unsigned Opcode = Addr.getOpcode();
461 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
462 // If we are able to fold N into addressing mode, then we'll allow it even
463 // if N has multiple uses. In general, addressing computation is used as
464 // addresses by all of its uses. But watch out for CopyToReg uses, that
465 // means the address computation is liveout. It will be computed by a LA
466 // so we want to avoid computing the address twice.
467 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
468 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
469 if (UI->getOpcode() == ISD::CopyToReg) {
470 MatchAddressBase(Addr, AM12);
471 Done = true;
472 break;
473 }
474 }
475 }
476 }
477 if (!Done && MatchAddress(Addr, AM12, /* is12Bit */ true))
478 return false;
479
480 // Check, whether we can match stuff using 20-bit displacements
481 if (!Done && !MatchAddress(Addr, AM20, /* is12Bit */ false))
482 if (AM12.Disp == 0 && AM20.Disp != 0)
483 return false;
484
Chris Lattner893e1c92009-08-23 06:49:22 +0000485 DEBUG(errs() << "MatchAddress (final): "; AM12.dump());
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000486
Owen Andersone50ed302009-08-10 22:56:29 +0000487 EVT VT = Addr.getValueType();
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000488 if (AM12.BaseType == SystemZRRIAddressMode::RegBase) {
489 if (!AM12.Base.Reg.getNode())
490 AM12.Base.Reg = CurDAG->getRegister(0, VT);
491 }
492
493 if (!AM12.IndexReg.getNode())
494 AM12.IndexReg = CurDAG->getRegister(0, VT);
495
496 getAddressOperands(AM12, Base, Disp, Index);
497
498 return true;
499}
500
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000501/// Returns true if the address can be represented by a base register plus
502/// index register plus a signed 20-bit displacement [base + idx + imm].
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000503bool SystemZDAGToDAGISel::SelectAddrRRI20(SDNode *Op, SDValue Addr,
Anton Korobeynikovc4368a12009-07-16 13:48:42 +0000504 SDValue &Base, SDValue &Disp, SDValue &Index) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000505 SystemZRRIAddressMode AM;
506 bool Done = false;
507
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000508 if (!Addr.hasOneUse()) {
509 unsigned Opcode = Addr.getOpcode();
510 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
511 // If we are able to fold N into addressing mode, then we'll allow it even
512 // if N has multiple uses. In general, addressing computation is used as
513 // addresses by all of its uses. But watch out for CopyToReg uses, that
514 // means the address computation is liveout. It will be computed by a LA
515 // so we want to avoid computing the address twice.
516 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
517 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
518 if (UI->getOpcode() == ISD::CopyToReg) {
519 MatchAddressBase(Addr, AM);
520 Done = true;
521 break;
522 }
523 }
524 }
525 }
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000526 if (!Done && MatchAddress(Addr, AM, /* is12Bit */ false))
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000527 return false;
528
Chris Lattner893e1c92009-08-23 06:49:22 +0000529 DEBUG(errs() << "MatchAddress (final): "; AM.dump());
Anton Korobeynikov32407402009-07-16 13:48:23 +0000530
Owen Andersone50ed302009-08-10 22:56:29 +0000531 EVT VT = Addr.getValueType();
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000532 if (AM.BaseType == SystemZRRIAddressMode::RegBase) {
533 if (!AM.Base.Reg.getNode())
534 AM.Base.Reg = CurDAG->getRegister(0, VT);
535 }
536
537 if (!AM.IndexReg.getNode())
538 AM.IndexReg = CurDAG->getRegister(0, VT);
539
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000540 getAddressOperands(AM, Base, Disp, Index);
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000541
542 return true;
543}
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000544
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000545/// SelectLAAddr - it calls SelectAddr and determines if the maximal addressing
546/// mode it matches can be cost effectively emitted as an LA/LAY instruction.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000547bool SystemZDAGToDAGISel::SelectLAAddr(SDNode *Op, SDValue Addr,
Anton Korobeynikovc4368a12009-07-16 13:48:42 +0000548 SDValue &Base, SDValue &Disp, SDValue &Index) {
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000549 SystemZRRIAddressMode AM;
550
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000551 if (MatchAddress(Addr, AM, false))
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000552 return false;
553
Owen Andersone50ed302009-08-10 22:56:29 +0000554 EVT VT = Addr.getValueType();
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000555 unsigned Complexity = 0;
556 if (AM.BaseType == SystemZRRIAddressMode::RegBase)
557 if (AM.Base.Reg.getNode())
558 Complexity = 1;
559 else
560 AM.Base.Reg = CurDAG->getRegister(0, VT);
561 else if (AM.BaseType == SystemZRRIAddressMode::FrameIndexBase)
562 Complexity = 4;
563
564 if (AM.IndexReg.getNode())
565 Complexity += 1;
566 else
567 AM.IndexReg = CurDAG->getRegister(0, VT);
568
569 if (AM.Disp && (AM.Base.Reg.getNode() || AM.IndexReg.getNode()))
570 Complexity += 1;
571
572 if (Complexity > 2) {
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000573 getAddressOperands(AM, Base, Disp, Index);
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000574 return true;
575 }
576
577 return false;
578}
579
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000580bool SystemZDAGToDAGISel::TryFoldLoad(SDNode *P, SDValue N,
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000581 SDValue &Base, SDValue &Disp, SDValue &Index) {
582 if (ISD::isNON_EXTLoad(N.getNode()) &&
Dan Gohmand858e902010-04-17 15:26:15 +0000583 IsLegalToFold(N, P, P, OptLevel))
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000584 return SelectAddrRRI20(P, N.getOperand(1), Base, Disp, Index);
585 return false;
586}
587
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000588SDNode *SystemZDAGToDAGISel::Select(SDNode *Node) {
Owen Andersone50ed302009-08-10 22:56:29 +0000589 EVT NVT = Node->getValueType(0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000590 DebugLoc dl = Node->getDebugLoc();
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000591 unsigned Opcode = Node->getOpcode();
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000592
593 // Dump information about the Node being selected
Chris Lattner7c306da2010-03-02 06:34:30 +0000594 DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000595
596 // If we have a custom node, we already have selected!
597 if (Node->isMachineOpcode()) {
Chris Lattner7c306da2010-03-02 06:34:30 +0000598 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000599 return NULL; // Already selected.
600 }
601
602 switch (Opcode) {
603 default: break;
604 case ISD::SDIVREM: {
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000605 unsigned Opc, MOpc;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000606 SDValue N0 = Node->getOperand(0);
607 SDValue N1 = Node->getOperand(1);
608
Owen Andersone50ed302009-08-10 22:56:29 +0000609 EVT ResVT;
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000610 bool is32Bit = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000611 switch (NVT.getSimpleVT().SimpleTy) {
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000612 default: assert(0 && "Unsupported VT!");
613 case MVT::i32:
614 Opc = SystemZ::SDIVREM32r; MOpc = SystemZ::SDIVREM32m;
615 ResVT = MVT::v2i64;
616 is32Bit = true;
617 break;
618 case MVT::i64:
619 Opc = SystemZ::SDIVREM64r; MOpc = SystemZ::SDIVREM64m;
620 ResVT = MVT::v2i64;
621 break;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000622 }
623
624 SDValue Tmp0, Tmp1, Tmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000625 bool foldedLoad = TryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000626
627 // Prepare the dividend
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000628 SDNode *Dividend;
629 if (is32Bit)
Dan Gohman602b0c82009-09-25 18:54:59 +0000630 Dividend = CurDAG->getMachineNode(SystemZ::MOVSX64rr32, dl, MVT::i64, N0);
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000631 else
632 Dividend = N0.getNode();
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000633
634 // Insert prepared dividend into suitable 'subreg'
Chris Lattner518bb532010-02-09 19:54:29 +0000635 SDNode *Tmp = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
Dan Gohman602b0c82009-09-25 18:54:59 +0000636 dl, ResVT);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000637 Dividend =
Chris Lattner518bb532010-02-09 19:54:29 +0000638 CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl, ResVT,
Dan Gohman602b0c82009-09-25 18:54:59 +0000639 SDValue(Tmp, 0), SDValue(Dividend, 0),
Jakob Stoklund Olesenc159fba2010-05-25 17:04:18 +0000640 CurDAG->getTargetConstant(SystemZ::subreg_odd, MVT::i32));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000641
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000642 SDNode *Result;
643 SDValue DivVal = SDValue(Dividend, 0);
644 if (foldedLoad) {
645 SDValue Ops[] = { DivVal, Tmp0, Tmp1, Tmp2, N1.getOperand(0) };
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000646 Result = CurDAG->getMachineNode(MOpc, dl, ResVT, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +0000647 Ops, array_lengthof(Ops));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000648 // Update the chain.
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000649 ReplaceUses(N1.getValue(1), SDValue(Result, 1));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000650 } else {
Dan Gohman602b0c82009-09-25 18:54:59 +0000651 Result = CurDAG->getMachineNode(Opc, dl, ResVT, SDValue(Dividend, 0), N1);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000652 }
653
654 // Copy the division (odd subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000655 if (!SDValue(Node, 0).use_empty()) {
Jakob Stoklund Olesenc159fba2010-05-25 17:04:18 +0000656 unsigned SubRegIdx = (is32Bit ?
657 SystemZ::subreg_odd32 : SystemZ::subreg_odd);
Chris Lattner518bb532010-02-09 19:54:29 +0000658 SDNode *Div = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000659 dl, NVT,
660 SDValue(Result, 0),
661 CurDAG->getTargetConstant(SubRegIdx,
662 MVT::i32));
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000663
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000664 ReplaceUses(SDValue(Node, 0), SDValue(Div, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000665 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000666 }
667
668 // Copy the remainder (even subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000669 if (!SDValue(Node, 1).use_empty()) {
Jakob Stoklund Olesenc159fba2010-05-25 17:04:18 +0000670 unsigned SubRegIdx = (is32Bit ?
Jakob Stoklund Olesen05ce4892010-05-28 23:48:29 +0000671 SystemZ::subreg_32bit : SystemZ::subreg_even);
Chris Lattner518bb532010-02-09 19:54:29 +0000672 SDNode *Rem = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000673 dl, NVT,
674 SDValue(Result, 0),
675 CurDAG->getTargetConstant(SubRegIdx,
676 MVT::i32));
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000677
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000678 ReplaceUses(SDValue(Node, 1), SDValue(Rem, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000679 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000680 }
681
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000682 return NULL;
683 }
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000684 case ISD::UDIVREM: {
685 unsigned Opc, MOpc, ClrOpc;
686 SDValue N0 = Node->getOperand(0);
687 SDValue N1 = Node->getOperand(1);
Owen Andersone50ed302009-08-10 22:56:29 +0000688 EVT ResVT;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000689
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000690 bool is32Bit = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000691 switch (NVT.getSimpleVT().SimpleTy) {
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000692 default: assert(0 && "Unsupported VT!");
693 case MVT::i32:
694 Opc = SystemZ::UDIVREM32r; MOpc = SystemZ::UDIVREM32m;
695 ClrOpc = SystemZ::MOV64Pr0_even;
696 ResVT = MVT::v2i32;
697 is32Bit = true;
698 break;
699 case MVT::i64:
700 Opc = SystemZ::UDIVREM64r; MOpc = SystemZ::UDIVREM64m;
701 ClrOpc = SystemZ::MOV128r0_even;
702 ResVT = MVT::v2i64;
703 break;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000704 }
705
706 SDValue Tmp0, Tmp1, Tmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000707 bool foldedLoad = TryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000708
709 // Prepare the dividend
710 SDNode *Dividend = N0.getNode();
711
712 // Insert prepared dividend into suitable 'subreg'
Chris Lattner518bb532010-02-09 19:54:29 +0000713 SDNode *Tmp = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
Dan Gohman602b0c82009-09-25 18:54:59 +0000714 dl, ResVT);
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000715 {
Jakob Stoklund Olesenc159fba2010-05-25 17:04:18 +0000716 unsigned SubRegIdx = (is32Bit ?
717 SystemZ::subreg_odd32 : SystemZ::subreg_odd);
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000718 Dividend =
Chris Lattner518bb532010-02-09 19:54:29 +0000719 CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl, ResVT,
Dan Gohman602b0c82009-09-25 18:54:59 +0000720 SDValue(Tmp, 0), SDValue(Dividend, 0),
721 CurDAG->getTargetConstant(SubRegIdx, MVT::i32));
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000722 }
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000723
Anton Korobeynikove3a7f7a2009-07-16 14:14:54 +0000724 // Zero out even subreg
Dan Gohman602b0c82009-09-25 18:54:59 +0000725 Dividend = CurDAG->getMachineNode(ClrOpc, dl, ResVT, SDValue(Dividend, 0));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000726
727 SDValue DivVal = SDValue(Dividend, 0);
728 SDNode *Result;
729 if (foldedLoad) {
730 SDValue Ops[] = { DivVal, Tmp0, Tmp1, Tmp2, N1.getOperand(0) };
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000731 Result = CurDAG->getMachineNode(MOpc, dl, ResVT, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +0000732 Ops, array_lengthof(Ops));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000733 // Update the chain.
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000734 ReplaceUses(N1.getValue(1), SDValue(Result, 1));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000735 } else {
Dan Gohman602b0c82009-09-25 18:54:59 +0000736 Result = CurDAG->getMachineNode(Opc, dl, ResVT, DivVal, N1);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000737 }
738
739 // Copy the division (odd subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000740 if (!SDValue(Node, 0).use_empty()) {
Jakob Stoklund Olesenc159fba2010-05-25 17:04:18 +0000741 unsigned SubRegIdx = (is32Bit ?
742 SystemZ::subreg_odd32 : SystemZ::subreg_odd);
Chris Lattner518bb532010-02-09 19:54:29 +0000743 SDNode *Div = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000744 dl, NVT,
745 SDValue(Result, 0),
746 CurDAG->getTargetConstant(SubRegIdx,
747 MVT::i32));
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000748 ReplaceUses(SDValue(Node, 0), SDValue(Div, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000749 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000750 }
751
752 // Copy the remainder (even subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000753 if (!SDValue(Node, 1).use_empty()) {
Jakob Stoklund Olesenc159fba2010-05-25 17:04:18 +0000754 unsigned SubRegIdx = (is32Bit ?
Jakob Stoklund Olesen05ce4892010-05-28 23:48:29 +0000755 SystemZ::subreg_32bit : SystemZ::subreg_even);
Chris Lattner518bb532010-02-09 19:54:29 +0000756 SDNode *Rem = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000757 dl, NVT,
758 SDValue(Result, 0),
759 CurDAG->getTargetConstant(SubRegIdx,
760 MVT::i32));
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000761 ReplaceUses(SDValue(Node, 1), SDValue(Rem, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000762 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000763 }
764
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000765 return NULL;
766 }
767 }
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000768
769 // Select the default instruction
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000770 SDNode *ResNode = SelectCode(Node);
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000771
Chris Lattner7c306da2010-03-02 06:34:30 +0000772 DEBUG(errs() << "=> ";
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000773 if (ResNode == NULL || ResNode == Node)
774 Node->dump(CurDAG);
Chris Lattner893e1c92009-08-23 06:49:22 +0000775 else
776 ResNode->dump(CurDAG);
777 errs() << "\n";
778 );
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000779 return ResNode;
780}