blob: 2186ff1fed54b5db4a77c1068c757aee9150fb93 [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:
Chris Lattner52a261b2010-09-21 20:31:19 +0000123 bool SelectAddrRI12Only(SDValue& Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000124 SDValue &Base, SDValue &Disp);
Chris Lattner52a261b2010-09-21 20:31:19 +0000125 bool SelectAddrRI12(SDValue& Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000126 SDValue &Base, SDValue &Disp,
127 bool is12BitOnly = false);
Chris Lattner52a261b2010-09-21 20:31:19 +0000128 bool SelectAddrRI(SDValue& Addr, SDValue &Base, SDValue &Disp);
129 bool SelectAddrRRI12(SDValue Addr,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000130 SDValue &Base, SDValue &Disp, SDValue &Index);
Chris Lattner52a261b2010-09-21 20:31:19 +0000131 bool SelectAddrRRI20(SDValue Addr,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000132 SDValue &Base, SDValue &Disp, SDValue &Index);
Chris Lattner52a261b2010-09-21 20:31:19 +0000133 bool SelectLAAddr(SDValue Addr,
Anton Korobeynikovc4368a12009-07-16 13:48:42 +0000134 SDValue &Base, SDValue &Disp, SDValue &Index);
135
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000136 SDNode *Select(SDNode *Node);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000137
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000138 bool TryFoldLoad(SDNode *P, SDValue N,
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000139 SDValue &Base, SDValue &Disp, SDValue &Index);
140
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000141 bool MatchAddress(SDValue N, SystemZRRIAddressMode &AM,
142 bool is12Bit, unsigned Depth = 0);
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000143 bool MatchAddressBase(SDValue N, SystemZRRIAddressMode &AM);
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000144 };
145} // end anonymous namespace
146
147/// createSystemZISelDag - This pass converts a legalized DAG into a
148/// SystemZ-specific DAG, ready for instruction scheduling.
149///
150FunctionPass *llvm::createSystemZISelDag(SystemZTargetMachine &TM,
151 CodeGenOpt::Level OptLevel) {
152 return new SystemZDAGToDAGISel(TM, OptLevel);
153}
154
Anton Korobeynikov9e4816e2009-07-16 13:43:18 +0000155/// isImmSExt20 - This method tests to see if the node is either a 32-bit
156/// or 64-bit immediate, and if the value can be accurately represented as a
157/// sign extension from a 20-bit value. If so, this returns true and the
158/// immediate.
Anton Korobeynikov32407402009-07-16 13:48:23 +0000159static bool isImmSExt20(int64_t Val, int64_t &Imm) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000160 if (Val >= -524288 && Val <= 524287) {
Anton Korobeynikov32407402009-07-16 13:48:23 +0000161 Imm = Val;
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000162 return true;
163 }
164 return false;
165}
166
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000167/// isImmZExt12 - This method tests to see if the node is either a 32-bit
Anton Korobeynikov3166a9a2009-07-16 14:03:41 +0000168/// or 64-bit immediate, and if the value can be accurately represented as a
169/// zero extension from a 12-bit value. If so, this returns true and the
170/// immediate.
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000171static bool isImmZExt12(int64_t Val, int64_t &Imm) {
172 if (Val >= 0 && Val <= 0xFFF) {
Anton Korobeynikov3166a9a2009-07-16 14:03:41 +0000173 Imm = Val;
174 return true;
175 }
Anton Korobeynikov3166a9a2009-07-16 14:03:41 +0000176 return false;
177}
178
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000179/// MatchAddress - Add the specified node to the specified addressing mode,
180/// returning true if it cannot be done. This just pattern matches for the
181/// addressing mode.
182bool SystemZDAGToDAGISel::MatchAddress(SDValue N, SystemZRRIAddressMode &AM,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000183 bool is12Bit, unsigned Depth) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000184 DebugLoc dl = N.getDebugLoc();
Chris Lattner893e1c92009-08-23 06:49:22 +0000185 DEBUG(errs() << "MatchAddress: "; AM.dump());
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000186 // Limit recursion.
187 if (Depth > 5)
188 return MatchAddressBase(N, AM);
189
Anton Korobeynikovdc289552009-07-16 13:44:30 +0000190 // FIXME: We can perform better here. If we have something like
191 // (shift (add A, imm), N), we can try to reassociate stuff and fold shift of
192 // imm into addressing mode.
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000193 switch (N.getOpcode()) {
194 default: break;
195 case ISD::Constant: {
Anton Korobeynikov32407402009-07-16 13:48:23 +0000196 int64_t Val = cast<ConstantSDNode>(N)->getSExtValue();
Daniel Dunbar19c29f52009-07-17 02:19:26 +0000197 int64_t Imm = 0;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000198 bool Match = (is12Bit ?
199 isImmZExt12(AM.Disp + Val, Imm) :
200 isImmSExt20(AM.Disp + Val, Imm));
201 if (Match) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000202 AM.Disp = Imm;
203 return false;
204 }
205 break;
206 }
207
208 case ISD::FrameIndex:
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000209 if (AM.BaseType == SystemZRRIAddressMode::RegBase &&
210 AM.Base.Reg.getNode() == 0) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000211 AM.BaseType = SystemZRRIAddressMode::FrameIndexBase;
212 AM.Base.FrameIndex = cast<FrameIndexSDNode>(N)->getIndex();
213 return false;
214 }
215 break;
216
217 case ISD::SUB: {
218 // Given A-B, if A can be completely folded into the address and
219 // the index field with the index field unused, use -B as the index.
220 // This is a win if a has multiple parts that can be folded into
221 // the address. Also, this saves a mov if the base register has
222 // other uses, since it avoids a two-address sub instruction, however
223 // it costs an additional mov if the index register has other uses.
224
225 // Test if the LHS of the sub can be folded.
226 SystemZRRIAddressMode Backup = AM;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000227 if (MatchAddress(N.getNode()->getOperand(0), AM, is12Bit, Depth+1)) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000228 AM = Backup;
229 break;
230 }
231 // Test if the index field is free for use.
Anton Korobeynikov54681ec2009-07-16 14:31:14 +0000232 if (AM.IndexReg.getNode() || AM.isRI) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000233 AM = Backup;
234 break;
235 }
236
237 // If the base is a register with multiple uses, this transformation may
238 // save a mov. Otherwise it's probably better not to do it.
239 if (AM.BaseType == SystemZRRIAddressMode::RegBase &&
240 (!AM.Base.Reg.getNode() || AM.Base.Reg.getNode()->hasOneUse())) {
241 AM = Backup;
242 break;
243 }
244
245 // Ok, the transformation is legal and appears profitable. Go for it.
246 SDValue RHS = N.getNode()->getOperand(1);
247 SDValue Zero = CurDAG->getConstant(0, N.getValueType());
248 SDValue Neg = CurDAG->getNode(ISD::SUB, dl, N.getValueType(), Zero, RHS);
249 AM.IndexReg = Neg;
250
251 // Insert the new nodes into the topological ordering.
252 if (Zero.getNode()->getNodeId() == -1 ||
253 Zero.getNode()->getNodeId() > N.getNode()->getNodeId()) {
254 CurDAG->RepositionNode(N.getNode(), Zero.getNode());
255 Zero.getNode()->setNodeId(N.getNode()->getNodeId());
256 }
257 if (Neg.getNode()->getNodeId() == -1 ||
258 Neg.getNode()->getNodeId() > N.getNode()->getNodeId()) {
259 CurDAG->RepositionNode(N.getNode(), Neg.getNode());
260 Neg.getNode()->setNodeId(N.getNode()->getNodeId());
261 }
262 return false;
263 }
264
265 case ISD::ADD: {
266 SystemZRRIAddressMode Backup = AM;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000267 if (!MatchAddress(N.getNode()->getOperand(0), AM, is12Bit, Depth+1) &&
268 !MatchAddress(N.getNode()->getOperand(1), AM, is12Bit, Depth+1))
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000269 return false;
270 AM = Backup;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000271 if (!MatchAddress(N.getNode()->getOperand(1), AM, is12Bit, Depth+1) &&
272 !MatchAddress(N.getNode()->getOperand(0), AM, is12Bit, Depth+1))
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000273 return false;
274 AM = Backup;
275
276 // If we couldn't fold both operands into the address at the same time,
277 // see if we can just put each operand into a register and fold at least
278 // the add.
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000279 if (!AM.isRI &&
280 AM.BaseType == SystemZRRIAddressMode::RegBase &&
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000281 !AM.Base.Reg.getNode() && !AM.IndexReg.getNode()) {
282 AM.Base.Reg = N.getNode()->getOperand(0);
283 AM.IndexReg = N.getNode()->getOperand(1);
284 return false;
285 }
286 break;
287 }
288
289 case ISD::OR:
290 // Handle "X | C" as "X + C" iff X is known to have C bits clear.
291 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
292 SystemZRRIAddressMode Backup = AM;
Anton Korobeynikov32407402009-07-16 13:48:23 +0000293 int64_t Offset = CN->getSExtValue();
Daniel Dunbar19c29f52009-07-17 02:19:26 +0000294 int64_t Imm = 0;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000295 bool MatchOffset = (is12Bit ?
296 isImmZExt12(AM.Disp + Offset, Imm) :
297 isImmSExt20(AM.Disp + Offset, Imm));
298 // The resultant disp must fit in 12 or 20-bits.
299 if (MatchOffset &&
300 // LHS should be an addr mode.
301 !MatchAddress(N.getOperand(0), AM, is12Bit, Depth+1) &&
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000302 // Check to see if the LHS & C is zero.
303 CurDAG->MaskedValueIsZero(N.getOperand(0), CN->getAPIntValue())) {
304 AM.Disp = Imm;
305 return false;
306 }
307 AM = Backup;
308 }
309 break;
310 }
311
312 return MatchAddressBase(N, AM);
313}
314
315/// MatchAddressBase - Helper for MatchAddress. Add the specified node to the
316/// specified addressing mode without any further recursion.
317bool SystemZDAGToDAGISel::MatchAddressBase(SDValue N,
318 SystemZRRIAddressMode &AM) {
319 // Is the base register already occupied?
320 if (AM.BaseType != SystemZRRIAddressMode::RegBase || AM.Base.Reg.getNode()) {
Anton Korobeynikov46567602009-07-16 14:10:35 +0000321 // If so, check to see if the index register is set.
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000322 if (AM.IndexReg.getNode() == 0 && !AM.isRI) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000323 AM.IndexReg = N;
324 return false;
325 }
326
327 // Otherwise, we cannot select it.
328 return true;
329 }
330
331 // Default, generate it as a register.
332 AM.BaseType = SystemZRRIAddressMode::RegBase;
333 AM.Base.Reg = N;
334 return false;
335}
336
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000337void SystemZDAGToDAGISel::getAddressOperandsRI(const SystemZRRIAddressMode &AM,
338 SDValue &Base, SDValue &Disp) {
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000339 if (AM.BaseType == SystemZRRIAddressMode::RegBase)
340 Base = AM.Base.Reg;
341 else
342 Base = CurDAG->getTargetFrameIndex(AM.Base.FrameIndex, TLI.getPointerTy());
Owen Anderson825b72b2009-08-11 20:47:22 +0000343 Disp = CurDAG->getTargetConstant(AM.Disp, MVT::i64);
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000344}
345
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000346void SystemZDAGToDAGISel::getAddressOperands(const SystemZRRIAddressMode &AM,
347 SDValue &Base, SDValue &Disp,
348 SDValue &Index) {
349 getAddressOperandsRI(AM, Base, Disp);
350 Index = AM.IndexReg;
351}
352
353/// Returns true if the address can be represented by a base register plus
354/// an unsigned 12-bit displacement [r+imm].
Chris Lattner52a261b2010-09-21 20:31:19 +0000355bool SystemZDAGToDAGISel::SelectAddrRI12Only(SDValue &Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000356 SDValue &Base, SDValue &Disp) {
Chris Lattner52a261b2010-09-21 20:31:19 +0000357 return SelectAddrRI12(Addr, Base, Disp, /*is12BitOnly*/true);
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000358}
359
Chris Lattner52a261b2010-09-21 20:31:19 +0000360bool SystemZDAGToDAGISel::SelectAddrRI12(SDValue &Addr,
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000361 SDValue &Base, SDValue &Disp,
362 bool is12BitOnly) {
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000363 SystemZRRIAddressMode AM20(/*isRI*/true), AM12(/*isRI*/true);
364 bool Done = false;
365
366 if (!Addr.hasOneUse()) {
367 unsigned Opcode = Addr.getOpcode();
368 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
369 // If we are able to fold N into addressing mode, then we'll allow it even
370 // if N has multiple uses. In general, addressing computation is used as
371 // addresses by all of its uses. But watch out for CopyToReg uses, that
372 // means the address computation is liveout. It will be computed by a LA
373 // so we want to avoid computing the address twice.
374 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
375 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
376 if (UI->getOpcode() == ISD::CopyToReg) {
377 MatchAddressBase(Addr, AM12);
378 Done = true;
379 break;
380 }
381 }
382 }
383 }
384 if (!Done && MatchAddress(Addr, AM12, /* is12Bit */ true))
385 return false;
386
387 // Check, whether we can match stuff using 20-bit displacements
Anton Korobeynikov014d4632009-07-16 14:13:24 +0000388 if (!Done && !is12BitOnly &&
389 !MatchAddress(Addr, AM20, /* is12Bit */ false))
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000390 if (AM12.Disp == 0 && AM20.Disp != 0)
391 return false;
392
Chris Lattner893e1c92009-08-23 06:49:22 +0000393 DEBUG(errs() << "MatchAddress (final): "; AM12.dump());
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000394
Owen Andersone50ed302009-08-10 22:56:29 +0000395 EVT VT = Addr.getValueType();
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000396 if (AM12.BaseType == SystemZRRIAddressMode::RegBase) {
397 if (!AM12.Base.Reg.getNode())
398 AM12.Base.Reg = CurDAG->getRegister(0, VT);
399 }
400
401 assert(AM12.IndexReg.getNode() == 0 && "Invalid reg-imm address mode!");
402
403 getAddressOperandsRI(AM12, Base, Disp);
404
405 return true;
406}
407
408/// Returns true if the address can be represented by a base register plus
409/// a signed 20-bit displacement [r+imm].
Chris Lattner52a261b2010-09-21 20:31:19 +0000410bool SystemZDAGToDAGISel::SelectAddrRI(SDValue& Addr,
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000411 SDValue &Base, SDValue &Disp) {
412 SystemZRRIAddressMode AM(/*isRI*/true);
413 bool Done = false;
414
415 if (!Addr.hasOneUse()) {
416 unsigned Opcode = Addr.getOpcode();
417 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
418 // If we are able to fold N into addressing mode, then we'll allow it even
419 // if N has multiple uses. In general, addressing computation is used as
420 // addresses by all of its uses. But watch out for CopyToReg uses, that
421 // means the address computation is liveout. It will be computed by a LA
422 // so we want to avoid computing the address twice.
423 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
424 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
425 if (UI->getOpcode() == ISD::CopyToReg) {
426 MatchAddressBase(Addr, AM);
427 Done = true;
428 break;
429 }
430 }
431 }
432 }
433 if (!Done && MatchAddress(Addr, AM, /* is12Bit */ false))
434 return false;
435
Chris Lattner893e1c92009-08-23 06:49:22 +0000436 DEBUG(errs() << "MatchAddress (final): "; AM.dump());
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000437
Owen Andersone50ed302009-08-10 22:56:29 +0000438 EVT VT = Addr.getValueType();
Anton Korobeynikov1ed1e3e2009-07-16 14:10:17 +0000439 if (AM.BaseType == SystemZRRIAddressMode::RegBase) {
440 if (!AM.Base.Reg.getNode())
441 AM.Base.Reg = CurDAG->getRegister(0, VT);
442 }
443
444 assert(AM.IndexReg.getNode() == 0 && "Invalid reg-imm address mode!");
445
446 getAddressOperandsRI(AM, Base, Disp);
447
448 return true;
449}
450
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000451/// Returns true if the address can be represented by a base register plus
452/// index register plus an unsigned 12-bit displacement [base + idx + imm].
Chris Lattner52a261b2010-09-21 20:31:19 +0000453bool SystemZDAGToDAGISel::SelectAddrRRI12(SDValue Addr,
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000454 SDValue &Base, SDValue &Disp, SDValue &Index) {
Anton Korobeynikov46567602009-07-16 14:10:35 +0000455 SystemZRRIAddressMode AM20, AM12;
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000456 bool Done = false;
457
458 if (!Addr.hasOneUse()) {
459 unsigned Opcode = Addr.getOpcode();
460 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
461 // If we are able to fold N into addressing mode, then we'll allow it even
462 // if N has multiple uses. In general, addressing computation is used as
463 // addresses by all of its uses. But watch out for CopyToReg uses, that
464 // means the address computation is liveout. It will be computed by a LA
465 // so we want to avoid computing the address twice.
466 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
467 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
468 if (UI->getOpcode() == ISD::CopyToReg) {
469 MatchAddressBase(Addr, AM12);
470 Done = true;
471 break;
472 }
473 }
474 }
475 }
476 if (!Done && MatchAddress(Addr, AM12, /* is12Bit */ true))
477 return false;
478
479 // Check, whether we can match stuff using 20-bit displacements
480 if (!Done && !MatchAddress(Addr, AM20, /* is12Bit */ false))
481 if (AM12.Disp == 0 && AM20.Disp != 0)
482 return false;
483
Chris Lattner893e1c92009-08-23 06:49:22 +0000484 DEBUG(errs() << "MatchAddress (final): "; AM12.dump());
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000485
Owen Andersone50ed302009-08-10 22:56:29 +0000486 EVT VT = Addr.getValueType();
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000487 if (AM12.BaseType == SystemZRRIAddressMode::RegBase) {
488 if (!AM12.Base.Reg.getNode())
489 AM12.Base.Reg = CurDAG->getRegister(0, VT);
490 }
491
492 if (!AM12.IndexReg.getNode())
493 AM12.IndexReg = CurDAG->getRegister(0, VT);
494
495 getAddressOperands(AM12, Base, Disp, Index);
496
497 return true;
498}
499
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000500/// Returns true if the address can be represented by a base register plus
501/// index register plus a signed 20-bit displacement [base + idx + imm].
Chris Lattner52a261b2010-09-21 20:31:19 +0000502bool SystemZDAGToDAGISel::SelectAddrRRI20(SDValue Addr,
Anton Korobeynikovc4368a12009-07-16 13:48:42 +0000503 SDValue &Base, SDValue &Disp, SDValue &Index) {
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000504 SystemZRRIAddressMode AM;
505 bool Done = false;
506
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000507 if (!Addr.hasOneUse()) {
508 unsigned Opcode = Addr.getOpcode();
509 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex) {
510 // If we are able to fold N into addressing mode, then we'll allow it even
511 // if N has multiple uses. In general, addressing computation is used as
512 // addresses by all of its uses. But watch out for CopyToReg uses, that
513 // means the address computation is liveout. It will be computed by a LA
514 // so we want to avoid computing the address twice.
515 for (SDNode::use_iterator UI = Addr.getNode()->use_begin(),
516 UE = Addr.getNode()->use_end(); UI != UE; ++UI) {
517 if (UI->getOpcode() == ISD::CopyToReg) {
518 MatchAddressBase(Addr, AM);
519 Done = true;
520 break;
521 }
522 }
523 }
524 }
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000525 if (!Done && MatchAddress(Addr, AM, /* is12Bit */ false))
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000526 return false;
527
Chris Lattner893e1c92009-08-23 06:49:22 +0000528 DEBUG(errs() << "MatchAddress (final): "; AM.dump());
Anton Korobeynikov32407402009-07-16 13:48:23 +0000529
Owen Andersone50ed302009-08-10 22:56:29 +0000530 EVT VT = Addr.getValueType();
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000531 if (AM.BaseType == SystemZRRIAddressMode::RegBase) {
532 if (!AM.Base.Reg.getNode())
533 AM.Base.Reg = CurDAG->getRegister(0, VT);
534 }
535
536 if (!AM.IndexReg.getNode())
537 AM.IndexReg = CurDAG->getRegister(0, VT);
538
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000539 getAddressOperands(AM, Base, Disp, Index);
Anton Korobeynikov3360da92009-07-16 13:44:00 +0000540
541 return true;
542}
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000543
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000544/// SelectLAAddr - it calls SelectAddr and determines if the maximal addressing
545/// mode it matches can be cost effectively emitted as an LA/LAY instruction.
Chris Lattner52a261b2010-09-21 20:31:19 +0000546bool SystemZDAGToDAGISel::SelectLAAddr(SDValue Addr,
Anton Korobeynikovc4368a12009-07-16 13:48:42 +0000547 SDValue &Base, SDValue &Disp, SDValue &Index) {
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000548 SystemZRRIAddressMode AM;
549
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000550 if (MatchAddress(Addr, AM, false))
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000551 return false;
552
Owen Andersone50ed302009-08-10 22:56:29 +0000553 EVT VT = Addr.getValueType();
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000554 unsigned Complexity = 0;
555 if (AM.BaseType == SystemZRRIAddressMode::RegBase)
556 if (AM.Base.Reg.getNode())
557 Complexity = 1;
558 else
559 AM.Base.Reg = CurDAG->getRegister(0, VT);
560 else if (AM.BaseType == SystemZRRIAddressMode::FrameIndexBase)
561 Complexity = 4;
562
563 if (AM.IndexReg.getNode())
564 Complexity += 1;
565 else
566 AM.IndexReg = CurDAG->getRegister(0, VT);
567
568 if (AM.Disp && (AM.Base.Reg.getNode() || AM.IndexReg.getNode()))
569 Complexity += 1;
570
571 if (Complexity > 2) {
Anton Korobeynikov720e3b02009-07-16 14:09:35 +0000572 getAddressOperands(AM, Base, Disp, Index);
Anton Korobeynikov711d5b62009-07-16 13:47:59 +0000573 return true;
574 }
575
576 return false;
577}
578
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000579bool SystemZDAGToDAGISel::TryFoldLoad(SDNode *P, SDValue N,
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000580 SDValue &Base, SDValue &Disp, SDValue &Index) {
581 if (ISD::isNON_EXTLoad(N.getNode()) &&
Dan Gohmand858e902010-04-17 15:26:15 +0000582 IsLegalToFold(N, P, P, OptLevel))
Chris Lattner52a261b2010-09-21 20:31:19 +0000583 return SelectAddrRRI20(N.getOperand(1), Base, Disp, Index);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000584 return false;
585}
586
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000587SDNode *SystemZDAGToDAGISel::Select(SDNode *Node) {
Owen Andersone50ed302009-08-10 22:56:29 +0000588 EVT NVT = Node->getValueType(0);
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000589 DebugLoc dl = Node->getDebugLoc();
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000590 unsigned Opcode = Node->getOpcode();
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000591
592 // Dump information about the Node being selected
Chris Lattner7c306da2010-03-02 06:34:30 +0000593 DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000594
595 // If we have a custom node, we already have selected!
596 if (Node->isMachineOpcode()) {
Chris Lattner7c306da2010-03-02 06:34:30 +0000597 DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000598 return NULL; // Already selected.
599 }
600
601 switch (Opcode) {
602 default: break;
603 case ISD::SDIVREM: {
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000604 unsigned Opc, MOpc;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000605 SDValue N0 = Node->getOperand(0);
606 SDValue N1 = Node->getOperand(1);
607
Owen Andersone50ed302009-08-10 22:56:29 +0000608 EVT ResVT;
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000609 bool is32Bit = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000610 switch (NVT.getSimpleVT().SimpleTy) {
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000611 default: assert(0 && "Unsupported VT!");
612 case MVT::i32:
613 Opc = SystemZ::SDIVREM32r; MOpc = SystemZ::SDIVREM32m;
614 ResVT = MVT::v2i64;
615 is32Bit = true;
616 break;
617 case MVT::i64:
618 Opc = SystemZ::SDIVREM64r; MOpc = SystemZ::SDIVREM64m;
619 ResVT = MVT::v2i64;
620 break;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000621 }
622
623 SDValue Tmp0, Tmp1, Tmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000624 bool foldedLoad = TryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000625
626 // Prepare the dividend
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000627 SDNode *Dividend;
628 if (is32Bit)
Dan Gohman602b0c82009-09-25 18:54:59 +0000629 Dividend = CurDAG->getMachineNode(SystemZ::MOVSX64rr32, dl, MVT::i64, N0);
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000630 else
631 Dividend = N0.getNode();
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000632
633 // Insert prepared dividend into suitable 'subreg'
Chris Lattner518bb532010-02-09 19:54:29 +0000634 SDNode *Tmp = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
Dan Gohman602b0c82009-09-25 18:54:59 +0000635 dl, ResVT);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000636 Dividend =
Chris Lattner518bb532010-02-09 19:54:29 +0000637 CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl, ResVT,
Dan Gohman602b0c82009-09-25 18:54:59 +0000638 SDValue(Tmp, 0), SDValue(Dividend, 0),
Jakob Stoklund Olesenc159fba2010-05-25 17:04:18 +0000639 CurDAG->getTargetConstant(SystemZ::subreg_odd, MVT::i32));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000640
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000641 SDNode *Result;
642 SDValue DivVal = SDValue(Dividend, 0);
643 if (foldedLoad) {
644 SDValue Ops[] = { DivVal, Tmp0, Tmp1, Tmp2, N1.getOperand(0) };
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000645 Result = CurDAG->getMachineNode(MOpc, dl, ResVT, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +0000646 Ops, array_lengthof(Ops));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000647 // Update the chain.
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000648 ReplaceUses(N1.getValue(1), SDValue(Result, 1));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000649 } else {
Dan Gohman602b0c82009-09-25 18:54:59 +0000650 Result = CurDAG->getMachineNode(Opc, dl, ResVT, SDValue(Dividend, 0), N1);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000651 }
652
653 // Copy the division (odd subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000654 if (!SDValue(Node, 0).use_empty()) {
Jakob Stoklund Olesenc159fba2010-05-25 17:04:18 +0000655 unsigned SubRegIdx = (is32Bit ?
656 SystemZ::subreg_odd32 : SystemZ::subreg_odd);
Chris Lattner518bb532010-02-09 19:54:29 +0000657 SDNode *Div = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000658 dl, NVT,
659 SDValue(Result, 0),
660 CurDAG->getTargetConstant(SubRegIdx,
661 MVT::i32));
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000662
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000663 ReplaceUses(SDValue(Node, 0), SDValue(Div, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000664 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000665 }
666
667 // Copy the remainder (even subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000668 if (!SDValue(Node, 1).use_empty()) {
Jakob Stoklund Olesenc159fba2010-05-25 17:04:18 +0000669 unsigned SubRegIdx = (is32Bit ?
Jakob Stoklund Olesen05ce4892010-05-28 23:48:29 +0000670 SystemZ::subreg_32bit : SystemZ::subreg_even);
Chris Lattner518bb532010-02-09 19:54:29 +0000671 SDNode *Rem = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000672 dl, NVT,
673 SDValue(Result, 0),
674 CurDAG->getTargetConstant(SubRegIdx,
675 MVT::i32));
Anton Korobeynikov09e39002009-07-16 14:17:52 +0000676
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000677 ReplaceUses(SDValue(Node, 1), SDValue(Rem, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000678 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000679 }
680
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000681 return NULL;
682 }
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000683 case ISD::UDIVREM: {
684 unsigned Opc, MOpc, ClrOpc;
685 SDValue N0 = Node->getOperand(0);
686 SDValue N1 = Node->getOperand(1);
Owen Andersone50ed302009-08-10 22:56:29 +0000687 EVT ResVT;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000688
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000689 bool is32Bit = false;
Owen Anderson825b72b2009-08-11 20:47:22 +0000690 switch (NVT.getSimpleVT().SimpleTy) {
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000691 default: assert(0 && "Unsupported VT!");
692 case MVT::i32:
693 Opc = SystemZ::UDIVREM32r; MOpc = SystemZ::UDIVREM32m;
694 ClrOpc = SystemZ::MOV64Pr0_even;
695 ResVT = MVT::v2i32;
696 is32Bit = true;
697 break;
698 case MVT::i64:
699 Opc = SystemZ::UDIVREM64r; MOpc = SystemZ::UDIVREM64m;
700 ClrOpc = SystemZ::MOV128r0_even;
701 ResVT = MVT::v2i64;
702 break;
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000703 }
704
705 SDValue Tmp0, Tmp1, Tmp2;
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000706 bool foldedLoad = TryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000707
708 // Prepare the dividend
709 SDNode *Dividend = N0.getNode();
710
711 // Insert prepared dividend into suitable 'subreg'
Chris Lattner518bb532010-02-09 19:54:29 +0000712 SDNode *Tmp = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
Dan Gohman602b0c82009-09-25 18:54:59 +0000713 dl, ResVT);
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000714 {
Jakob Stoklund Olesenc159fba2010-05-25 17:04:18 +0000715 unsigned SubRegIdx = (is32Bit ?
716 SystemZ::subreg_odd32 : SystemZ::subreg_odd);
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000717 Dividend =
Chris Lattner518bb532010-02-09 19:54:29 +0000718 CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, dl, ResVT,
Dan Gohman602b0c82009-09-25 18:54:59 +0000719 SDValue(Tmp, 0), SDValue(Dividend, 0),
720 CurDAG->getTargetConstant(SubRegIdx, MVT::i32));
Anton Korobeynikov8bd0db72009-07-16 14:18:17 +0000721 }
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000722
Anton Korobeynikove3a7f7a2009-07-16 14:14:54 +0000723 // Zero out even subreg
Dan Gohman602b0c82009-09-25 18:54:59 +0000724 Dividend = CurDAG->getMachineNode(ClrOpc, dl, ResVT, SDValue(Dividend, 0));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000725
726 SDValue DivVal = SDValue(Dividend, 0);
727 SDNode *Result;
728 if (foldedLoad) {
729 SDValue Ops[] = { DivVal, Tmp0, Tmp1, Tmp2, N1.getOperand(0) };
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000730 Result = CurDAG->getMachineNode(MOpc, dl, ResVT, MVT::Other,
Dan Gohman602b0c82009-09-25 18:54:59 +0000731 Ops, array_lengthof(Ops));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000732 // Update the chain.
Anton Korobeynikov39784e12010-01-04 10:31:54 +0000733 ReplaceUses(N1.getValue(1), SDValue(Result, 1));
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000734 } else {
Dan Gohman602b0c82009-09-25 18:54:59 +0000735 Result = CurDAG->getMachineNode(Opc, dl, ResVT, DivVal, N1);
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000736 }
737
738 // Copy the division (odd subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000739 if (!SDValue(Node, 0).use_empty()) {
Jakob Stoklund Olesenc159fba2010-05-25 17:04:18 +0000740 unsigned SubRegIdx = (is32Bit ?
741 SystemZ::subreg_odd32 : SystemZ::subreg_odd);
Chris Lattner518bb532010-02-09 19:54:29 +0000742 SDNode *Div = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000743 dl, NVT,
744 SDValue(Result, 0),
745 CurDAG->getTargetConstant(SubRegIdx,
746 MVT::i32));
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000747 ReplaceUses(SDValue(Node, 0), SDValue(Div, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000748 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000749 }
750
751 // Copy the remainder (even subreg) result, if it is needed.
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000752 if (!SDValue(Node, 1).use_empty()) {
Jakob Stoklund Olesenc159fba2010-05-25 17:04:18 +0000753 unsigned SubRegIdx = (is32Bit ?
Jakob Stoklund Olesen05ce4892010-05-28 23:48:29 +0000754 SystemZ::subreg_32bit : SystemZ::subreg_even);
Chris Lattner518bb532010-02-09 19:54:29 +0000755 SDNode *Rem = CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG,
Dan Gohman602b0c82009-09-25 18:54:59 +0000756 dl, NVT,
757 SDValue(Result, 0),
758 CurDAG->getTargetConstant(SubRegIdx,
759 MVT::i32));
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000760 ReplaceUses(SDValue(Node, 1), SDValue(Rem, 0));
Chris Lattner7c306da2010-03-02 06:34:30 +0000761 DEBUG(errs() << "=> "; Result->dump(CurDAG); errs() << "\n");
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000762 }
763
Anton Korobeynikov0a42d2b2009-07-16 14:14:33 +0000764 return NULL;
765 }
766 }
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000767
768 // Select the default instruction
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000769 SDNode *ResNode = SelectCode(Node);
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000770
Chris Lattner7c306da2010-03-02 06:34:30 +0000771 DEBUG(errs() << "=> ";
Dan Gohmaneeb3a002010-01-05 01:24:18 +0000772 if (ResNode == NULL || ResNode == Node)
773 Node->dump(CurDAG);
Chris Lattner893e1c92009-08-23 06:49:22 +0000774 else
775 ResNode->dump(CurDAG);
776 errs() << "\n";
777 );
Anton Korobeynikov4403b932009-07-16 13:27:25 +0000778 return ResNode;
779}