1 //===- X86ISelDAGToDAG.cpp - A DAG pattern matching inst selector for X86 -===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a DAG pattern matching instruction selector for X86,
11 // converting from a legalized dag to a X86 dag.
13 //===----------------------------------------------------------------------===//
15 #define DEBUG_TYPE "x86-isel"
17 #include "X86InstrBuilder.h"
18 #include "X86ISelLowering.h"
19 #include "X86MachineFunctionInfo.h"
20 #include "X86RegisterInfo.h"
21 #include "X86Subtarget.h"
22 #include "X86TargetMachine.h"
23 #include "llvm/GlobalValue.h"
24 #include "llvm/Instructions.h"
25 #include "llvm/Intrinsics.h"
26 #include "llvm/Support/CFG.h"
27 #include "llvm/Type.h"
28 #include "llvm/CodeGen/MachineConstantPool.h"
29 #include "llvm/CodeGen/MachineFunction.h"
30 #include "llvm/CodeGen/MachineFrameInfo.h"
31 #include "llvm/CodeGen/MachineInstrBuilder.h"
32 #include "llvm/CodeGen/MachineRegisterInfo.h"
33 #include "llvm/CodeGen/SelectionDAGISel.h"
34 #include "llvm/Target/TargetMachine.h"
35 #include "llvm/Target/TargetOptions.h"
36 #include "llvm/Support/Compiler.h"
37 #include "llvm/Support/Debug.h"
38 #include "llvm/Support/ErrorHandling.h"
39 #include "llvm/Support/MathExtras.h"
40 #include "llvm/Support/Streams.h"
41 #include "llvm/Support/raw_ostream.h"
42 #include "llvm/ADT/SmallPtrSet.h"
43 #include "llvm/ADT/Statistic.h"
46 #include "llvm/Support/CommandLine.h"
47 static cl::opt<bool> AvoidDupAddrCompute("x86-avoid-dup-address", cl::Hidden);
49 STATISTIC(NumLoadMoved, "Number of loads moved below TokenFactor");
51 //===----------------------------------------------------------------------===//
52 // Pattern Matcher Implementation
53 //===----------------------------------------------------------------------===//
56 /// X86ISelAddressMode - This corresponds to X86AddressMode, but uses
57 /// SDValue's instead of register numbers for the leaves of the matched
59 struct X86ISelAddressMode {
65 struct { // This is really a union, discriminated by BaseType!
78 unsigned Align; // CP alignment.
79 unsigned char SymbolFlags; // X86II::MO_*
82 : BaseType(RegBase), Scale(1), IndexReg(), Disp(0),
83 Segment(), GV(0), CP(0), ES(0), JT(-1), Align(0), SymbolFlags(0) {
86 bool hasSymbolicDisplacement() const {
87 return GV != 0 || CP != 0 || ES != 0 || JT != -1;
90 bool hasBaseOrIndexReg() const {
91 return IndexReg.getNode() != 0 || Base.Reg.getNode() != 0;
94 /// isRIPRelative - Return true if this addressing mode is already RIP
96 bool isRIPRelative() const {
97 if (BaseType != RegBase) return false;
98 if (RegisterSDNode *RegNode =
99 dyn_cast_or_null<RegisterSDNode>(Base.Reg.getNode()))
100 return RegNode->getReg() == X86::RIP;
104 void setBaseReg(SDValue Reg) {
110 cerr << "X86ISelAddressMode " << this << "\n";
112 if (Base.Reg.getNode() != 0) Base.Reg.getNode()->dump();
114 cerr << " Base.FrameIndex " << Base.FrameIndex << "\n";
115 cerr << " Scale" << Scale << "\n";
117 if (IndexReg.getNode() != 0) IndexReg.getNode()->dump();
119 cerr << " Disp " << Disp << "\n";
120 cerr << "GV "; if (GV) GV->dump();
122 cerr << " CP "; if (CP) CP->dump();
125 cerr << "ES "; if (ES) cerr << ES; else cerr << "nul";
126 cerr << " JT" << JT << " Align" << Align << "\n";
132 //===--------------------------------------------------------------------===//
133 /// ISel - X86 specific code to select X86 machine instructions for
134 /// SelectionDAG operations.
136 class VISIBILITY_HIDDEN X86DAGToDAGISel : public SelectionDAGISel {
137 /// X86Lowering - This object fully describes how to lower LLVM code to an
138 /// X86-specific SelectionDAG.
139 X86TargetLowering &X86Lowering;
141 /// Subtarget - Keep a pointer to the X86Subtarget around so that we can
142 /// make the right decision when generating code for different targets.
143 const X86Subtarget *Subtarget;
145 /// CurBB - Current BB being isel'd.
147 MachineBasicBlock *CurBB;
149 /// OptForSize - If true, selector should try to optimize for code size
150 /// instead of performance.
154 explicit X86DAGToDAGISel(X86TargetMachine &tm, CodeGenOpt::Level OptLevel)
155 : SelectionDAGISel(tm, OptLevel),
156 X86Lowering(*tm.getTargetLowering()),
157 Subtarget(&tm.getSubtarget<X86Subtarget>()),
160 virtual const char *getPassName() const {
161 return "X86 DAG->DAG Instruction Selection";
164 /// InstructionSelect - This callback is invoked by
165 /// SelectionDAGISel when it has created a SelectionDAG for us to codegen.
166 virtual void InstructionSelect();
168 virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF);
171 bool IsLegalAndProfitableToFold(SDNode *N, SDNode *U, SDNode *Root) const;
173 // Include the pieces autogenerated from the target description.
174 #include "X86GenDAGISel.inc"
177 SDNode *Select(SDValue N);
178 SDNode *SelectAtomic64(SDNode *Node, unsigned Opc);
179 SDNode *SelectAtomicLoadAdd(SDNode *Node, MVT NVT);
181 bool MatchSegmentBaseAddress(SDValue N, X86ISelAddressMode &AM);
182 bool MatchLoad(SDValue N, X86ISelAddressMode &AM);
183 bool MatchWrapper(SDValue N, X86ISelAddressMode &AM);
184 bool MatchAddress(SDValue N, X86ISelAddressMode &AM);
185 bool MatchAddressRecursively(SDValue N, X86ISelAddressMode &AM,
187 bool MatchAddressBase(SDValue N, X86ISelAddressMode &AM);
188 bool SelectAddr(SDValue Op, SDValue N, SDValue &Base,
189 SDValue &Scale, SDValue &Index, SDValue &Disp,
191 bool SelectLEAAddr(SDValue Op, SDValue N, SDValue &Base,
192 SDValue &Scale, SDValue &Index, SDValue &Disp);
193 bool SelectTLSADDRAddr(SDValue Op, SDValue N, SDValue &Base,
194 SDValue &Scale, SDValue &Index, SDValue &Disp);
195 bool SelectScalarSSELoad(SDValue Op, SDValue Pred,
196 SDValue N, SDValue &Base, SDValue &Scale,
197 SDValue &Index, SDValue &Disp,
199 SDValue &InChain, SDValue &OutChain);
200 bool TryFoldLoad(SDValue P, SDValue N,
201 SDValue &Base, SDValue &Scale,
202 SDValue &Index, SDValue &Disp,
204 void PreprocessForRMW();
205 void PreprocessForFPConvert();
207 /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
208 /// inline asm expressions.
209 virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
211 std::vector<SDValue> &OutOps);
213 void EmitSpecialCodeForMain(MachineBasicBlock *BB, MachineFrameInfo *MFI);
215 inline void getAddressOperands(X86ISelAddressMode &AM, SDValue &Base,
216 SDValue &Scale, SDValue &Index,
217 SDValue &Disp, SDValue &Segment) {
218 Base = (AM.BaseType == X86ISelAddressMode::FrameIndexBase) ?
219 CurDAG->getTargetFrameIndex(AM.Base.FrameIndex, TLI.getPointerTy()) :
221 Scale = getI8Imm(AM.Scale);
223 // These are 32-bit even in 64-bit mode since RIP relative offset
226 Disp = CurDAG->getTargetGlobalAddress(AM.GV, MVT::i32, AM.Disp,
229 Disp = CurDAG->getTargetConstantPool(AM.CP, MVT::i32,
230 AM.Align, AM.Disp, AM.SymbolFlags);
232 Disp = CurDAG->getTargetExternalSymbol(AM.ES, MVT::i32, AM.SymbolFlags);
233 else if (AM.JT != -1)
234 Disp = CurDAG->getTargetJumpTable(AM.JT, MVT::i32, AM.SymbolFlags);
236 Disp = CurDAG->getTargetConstant(AM.Disp, MVT::i32);
238 if (AM.Segment.getNode())
239 Segment = AM.Segment;
241 Segment = CurDAG->getRegister(0, MVT::i32);
244 /// getI8Imm - Return a target constant with the specified value, of type
246 inline SDValue getI8Imm(unsigned Imm) {
247 return CurDAG->getTargetConstant(Imm, MVT::i8);
250 /// getI16Imm - Return a target constant with the specified value, of type
252 inline SDValue getI16Imm(unsigned Imm) {
253 return CurDAG->getTargetConstant(Imm, MVT::i16);
256 /// getI32Imm - Return a target constant with the specified value, of type
258 inline SDValue getI32Imm(unsigned Imm) {
259 return CurDAG->getTargetConstant(Imm, MVT::i32);
262 /// getGlobalBaseReg - Return an SDNode that returns the value of
263 /// the global base register. Output instructions required to
264 /// initialize the global base register, if necessary.
266 SDNode *getGlobalBaseReg();
268 /// getTargetMachine - Return a reference to the TargetMachine, casted
269 /// to the target-specific type.
270 const X86TargetMachine &getTargetMachine() {
271 return static_cast<const X86TargetMachine &>(TM);
274 /// getInstrInfo - Return a reference to the TargetInstrInfo, casted
275 /// to the target-specific type.
276 const X86InstrInfo *getInstrInfo() {
277 return getTargetMachine().getInstrInfo();
287 bool X86DAGToDAGISel::IsLegalAndProfitableToFold(SDNode *N, SDNode *U,
288 SDNode *Root) const {
289 if (OptLevel == CodeGenOpt::None) return false;
292 switch (U->getOpcode()) {
300 SDValue Op1 = U->getOperand(1);
302 // If the other operand is a 8-bit immediate we should fold the immediate
303 // instead. This reduces code size.
305 // movl 4(%esp), %eax
309 // addl 4(%esp), %eax
310 // The former is 2 bytes shorter. In case where the increment is 1, then
311 // the saving can be 4 bytes (by using incl %eax).
312 if (ConstantSDNode *Imm = dyn_cast<ConstantSDNode>(Op1))
313 if (Imm->getAPIntValue().isSignedIntN(8))
316 // If the other operand is a TLS address, we should fold it instead.
319 // leal i@NTPOFF(%eax), %eax
321 // movl $i@NTPOFF, %eax
323 // if the block also has an access to a second TLS address this will save
325 // FIXME: This is probably also true for non TLS addresses.
326 if (Op1.getOpcode() == X86ISD::Wrapper) {
327 SDValue Val = Op1.getOperand(0);
328 if (Val.getOpcode() == ISD::TargetGlobalTLSAddress)
334 // Proceed to 'generic' cycle finder code
335 return SelectionDAGISel::IsLegalAndProfitableToFold(N, U, Root);
338 /// MoveBelowTokenFactor - Replace TokenFactor operand with load's chain operand
339 /// and move load below the TokenFactor. Replace store's chain operand with
340 /// load's chain result.
341 static void MoveBelowTokenFactor(SelectionDAG *CurDAG, SDValue Load,
342 SDValue Store, SDValue TF) {
343 SmallVector<SDValue, 4> Ops;
344 for (unsigned i = 0, e = TF.getNode()->getNumOperands(); i != e; ++i)
345 if (Load.getNode() == TF.getOperand(i).getNode())
346 Ops.push_back(Load.getOperand(0));
348 Ops.push_back(TF.getOperand(i));
349 CurDAG->UpdateNodeOperands(TF, &Ops[0], Ops.size());
350 CurDAG->UpdateNodeOperands(Load, TF, Load.getOperand(1), Load.getOperand(2));
351 CurDAG->UpdateNodeOperands(Store, Load.getValue(1), Store.getOperand(1),
352 Store.getOperand(2), Store.getOperand(3));
355 /// isRMWLoad - Return true if N is a load that's part of RMW sub-DAG.
357 static bool isRMWLoad(SDValue N, SDValue Chain, SDValue Address,
359 if (N.getOpcode() == ISD::BIT_CONVERT)
362 LoadSDNode *LD = dyn_cast<LoadSDNode>(N);
363 if (!LD || LD->isVolatile())
365 if (LD->getAddressingMode() != ISD::UNINDEXED)
368 ISD::LoadExtType ExtType = LD->getExtensionType();
369 if (ExtType != ISD::NON_EXTLOAD && ExtType != ISD::EXTLOAD)
373 N.getOperand(1) == Address &&
374 N.getNode()->isOperandOf(Chain.getNode())) {
381 /// MoveBelowCallSeqStart - Replace CALLSEQ_START operand with load's chain
382 /// operand and move load below the call's chain operand.
383 static void MoveBelowCallSeqStart(SelectionDAG *CurDAG, SDValue Load,
384 SDValue Call, SDValue CallSeqStart) {
385 SmallVector<SDValue, 8> Ops;
386 SDValue Chain = CallSeqStart.getOperand(0);
387 if (Chain.getNode() == Load.getNode())
388 Ops.push_back(Load.getOperand(0));
390 assert(Chain.getOpcode() == ISD::TokenFactor &&
391 "Unexpected CallSeqStart chain operand");
392 for (unsigned i = 0, e = Chain.getNumOperands(); i != e; ++i)
393 if (Chain.getOperand(i).getNode() == Load.getNode())
394 Ops.push_back(Load.getOperand(0));
396 Ops.push_back(Chain.getOperand(i));
398 CurDAG->getNode(ISD::TokenFactor, Load.getDebugLoc(),
399 MVT::Other, &Ops[0], Ops.size());
401 Ops.push_back(NewChain);
403 for (unsigned i = 1, e = CallSeqStart.getNumOperands(); i != e; ++i)
404 Ops.push_back(CallSeqStart.getOperand(i));
405 CurDAG->UpdateNodeOperands(CallSeqStart, &Ops[0], Ops.size());
406 CurDAG->UpdateNodeOperands(Load, Call.getOperand(0),
407 Load.getOperand(1), Load.getOperand(2));
409 Ops.push_back(SDValue(Load.getNode(), 1));
410 for (unsigned i = 1, e = Call.getNode()->getNumOperands(); i != e; ++i)
411 Ops.push_back(Call.getOperand(i));
412 CurDAG->UpdateNodeOperands(Call, &Ops[0], Ops.size());
415 /// isCalleeLoad - Return true if call address is a load and it can be
416 /// moved below CALLSEQ_START and the chains leading up to the call.
417 /// Return the CALLSEQ_START by reference as a second output.
418 static bool isCalleeLoad(SDValue Callee, SDValue &Chain) {
419 if (Callee.getNode() == Chain.getNode() || !Callee.hasOneUse())
421 LoadSDNode *LD = dyn_cast<LoadSDNode>(Callee.getNode());
424 LD->getAddressingMode() != ISD::UNINDEXED ||
425 LD->getExtensionType() != ISD::NON_EXTLOAD)
428 // Now let's find the callseq_start.
429 while (Chain.getOpcode() != ISD::CALLSEQ_START) {
430 if (!Chain.hasOneUse())
432 Chain = Chain.getOperand(0);
435 if (Chain.getOperand(0).getNode() == Callee.getNode())
437 if (Chain.getOperand(0).getOpcode() == ISD::TokenFactor &&
438 Callee.getValue(1).isOperandOf(Chain.getOperand(0).getNode()))
444 /// PreprocessForRMW - Preprocess the DAG to make instruction selection better.
445 /// This is only run if not in -O0 mode.
446 /// This allows the instruction selector to pick more read-modify-write
447 /// instructions. This is a common case:
457 /// [TokenFactor] [Op]
464 /// The fact the store's chain operand != load's chain will prevent the
465 /// (store (op (load))) instruction from being selected. We can transform it to:
484 void X86DAGToDAGISel::PreprocessForRMW() {
485 for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
486 E = CurDAG->allnodes_end(); I != E; ++I) {
487 if (I->getOpcode() == X86ISD::CALL) {
488 /// Also try moving call address load from outside callseq_start to just
489 /// before the call to allow it to be folded.
507 SDValue Chain = I->getOperand(0);
508 SDValue Load = I->getOperand(1);
509 if (!isCalleeLoad(Load, Chain))
511 MoveBelowCallSeqStart(CurDAG, Load, SDValue(I, 0), Chain);
516 if (!ISD::isNON_TRUNCStore(I))
518 SDValue Chain = I->getOperand(0);
520 if (Chain.getNode()->getOpcode() != ISD::TokenFactor)
523 SDValue N1 = I->getOperand(1);
524 SDValue N2 = I->getOperand(2);
525 if ((N1.getValueType().isFloatingPoint() &&
526 !N1.getValueType().isVector()) ||
532 unsigned Opcode = N1.getNode()->getOpcode();
541 case ISD::VECTOR_SHUFFLE: {
542 SDValue N10 = N1.getOperand(0);
543 SDValue N11 = N1.getOperand(1);
544 RModW = isRMWLoad(N10, Chain, N2, Load);
546 RModW = isRMWLoad(N11, Chain, N2, Load);
559 SDValue N10 = N1.getOperand(0);
560 RModW = isRMWLoad(N10, Chain, N2, Load);
566 MoveBelowTokenFactor(CurDAG, Load, SDValue(I, 0), Chain);
573 /// PreprocessForFPConvert - Walk over the dag lowering fpround and fpextend
574 /// nodes that target the FP stack to be store and load to the stack. This is a
575 /// gross hack. We would like to simply mark these as being illegal, but when
576 /// we do that, legalize produces these when it expands calls, then expands
577 /// these in the same legalize pass. We would like dag combine to be able to
578 /// hack on these between the call expansion and the node legalization. As such
579 /// this pass basically does "really late" legalization of these inline with the
581 void X86DAGToDAGISel::PreprocessForFPConvert() {
582 for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
583 E = CurDAG->allnodes_end(); I != E; ) {
584 SDNode *N = I++; // Preincrement iterator to avoid invalidation issues.
585 if (N->getOpcode() != ISD::FP_ROUND && N->getOpcode() != ISD::FP_EXTEND)
588 // If the source and destination are SSE registers, then this is a legal
589 // conversion that should not be lowered.
590 MVT SrcVT = N->getOperand(0).getValueType();
591 MVT DstVT = N->getValueType(0);
592 bool SrcIsSSE = X86Lowering.isScalarFPTypeInSSEReg(SrcVT);
593 bool DstIsSSE = X86Lowering.isScalarFPTypeInSSEReg(DstVT);
594 if (SrcIsSSE && DstIsSSE)
597 if (!SrcIsSSE && !DstIsSSE) {
598 // If this is an FPStack extension, it is a noop.
599 if (N->getOpcode() == ISD::FP_EXTEND)
601 // If this is a value-preserving FPStack truncation, it is a noop.
602 if (N->getConstantOperandVal(1))
606 // Here we could have an FP stack truncation or an FPStack <-> SSE convert.
607 // FPStack has extload and truncstore. SSE can fold direct loads into other
608 // operations. Based on this, decide what we want to do.
610 if (N->getOpcode() == ISD::FP_ROUND)
611 MemVT = DstVT; // FP_ROUND must use DstVT, we can't do a 'trunc load'.
613 MemVT = SrcIsSSE ? SrcVT : DstVT;
615 SDValue MemTmp = CurDAG->CreateStackTemporary(MemVT);
616 DebugLoc dl = N->getDebugLoc();
618 // FIXME: optimize the case where the src/dest is a load or store?
619 SDValue Store = CurDAG->getTruncStore(CurDAG->getEntryNode(), dl,
621 MemTmp, NULL, 0, MemVT);
622 SDValue Result = CurDAG->getExtLoad(ISD::EXTLOAD, dl, DstVT, Store, MemTmp,
625 // We're about to replace all uses of the FP_ROUND/FP_EXTEND with the
626 // extload we created. This will cause general havok on the dag because
627 // anything below the conversion could be folded into other existing nodes.
628 // To avoid invalidating 'I', back it up to the convert node.
630 CurDAG->ReplaceAllUsesOfValueWith(SDValue(N, 0), Result);
632 // Now that we did that, the node is dead. Increment the iterator to the
633 // next node to process, then delete N.
635 CurDAG->DeleteNode(N);
639 /// InstructionSelectBasicBlock - This callback is invoked by SelectionDAGISel
640 /// when it has created a SelectionDAG for us to codegen.
641 void X86DAGToDAGISel::InstructionSelect() {
642 CurBB = BB; // BB can change as result of isel.
643 const Function *F = CurDAG->getMachineFunction().getFunction();
644 OptForSize = F->hasFnAttr(Attribute::OptimizeForSize);
647 if (OptLevel != CodeGenOpt::None)
650 // FIXME: This should only happen when not compiled with -O0.
651 PreprocessForFPConvert();
653 // Codegen the basic block.
655 DOUT << "===== Instruction selection begins:\n";
660 DOUT << "===== Instruction selection ends:\n";
663 CurDAG->RemoveDeadNodes();
666 /// EmitSpecialCodeForMain - Emit any code that needs to be executed only in
667 /// the main function.
668 void X86DAGToDAGISel::EmitSpecialCodeForMain(MachineBasicBlock *BB,
669 MachineFrameInfo *MFI) {
670 const TargetInstrInfo *TII = TM.getInstrInfo();
671 if (Subtarget->isTargetCygMing())
672 BuildMI(BB, DebugLoc::getUnknownLoc(),
673 TII->get(X86::CALLpcrel32)).addExternalSymbol("__main");
676 void X86DAGToDAGISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {
677 // If this is main, emit special code for main.
678 MachineBasicBlock *BB = MF.begin();
679 if (Fn.hasExternalLinkage() && Fn.getName() == "main")
680 EmitSpecialCodeForMain(BB, MF.getFrameInfo());
684 bool X86DAGToDAGISel::MatchSegmentBaseAddress(SDValue N,
685 X86ISelAddressMode &AM) {
686 assert(N.getOpcode() == X86ISD::SegmentBaseAddress);
687 SDValue Segment = N.getOperand(0);
689 if (AM.Segment.getNode() == 0) {
690 AM.Segment = Segment;
697 bool X86DAGToDAGISel::MatchLoad(SDValue N, X86ISelAddressMode &AM) {
698 // This optimization is valid because the GNU TLS model defines that
699 // gs:0 (or fs:0 on X86-64) contains its own address.
700 // For more information see http://people.redhat.com/drepper/tls.pdf
702 SDValue Address = N.getOperand(1);
703 if (Address.getOpcode() == X86ISD::SegmentBaseAddress &&
704 !MatchSegmentBaseAddress (Address, AM))
710 /// MatchWrapper - Try to match X86ISD::Wrapper and X86ISD::WrapperRIP nodes
711 /// into an addressing mode. These wrap things that will resolve down into a
712 /// symbol reference. If no match is possible, this returns true, otherwise it
714 bool X86DAGToDAGISel::MatchWrapper(SDValue N, X86ISelAddressMode &AM) {
715 // If the addressing mode already has a symbol as the displacement, we can
716 // never match another symbol.
717 if (AM.hasSymbolicDisplacement())
720 SDValue N0 = N.getOperand(0);
722 // Handle X86-64 rip-relative addresses. We check this before checking direct
723 // folding because RIP is preferable to non-RIP accesses.
724 if (Subtarget->is64Bit() &&
725 // Under X86-64 non-small code model, GV (and friends) are 64-bits, so
726 // they cannot be folded into immediate fields.
727 // FIXME: This can be improved for kernel and other models?
728 TM.getCodeModel() == CodeModel::Small &&
730 // Base and index reg must be 0 in order to use %rip as base and lowering
732 !AM.hasBaseOrIndexReg() && N.getOpcode() == X86ISD::WrapperRIP) {
734 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(N0)) {
735 int64_t Offset = AM.Disp + G->getOffset();
736 if (!isInt32(Offset)) return true;
737 AM.GV = G->getGlobal();
739 AM.SymbolFlags = G->getTargetFlags();
740 } else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(N0)) {
741 int64_t Offset = AM.Disp + CP->getOffset();
742 if (!isInt32(Offset)) return true;
743 AM.CP = CP->getConstVal();
744 AM.Align = CP->getAlignment();
746 AM.SymbolFlags = CP->getTargetFlags();
747 } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(N0)) {
748 AM.ES = S->getSymbol();
749 AM.SymbolFlags = S->getTargetFlags();
751 JumpTableSDNode *J = cast<JumpTableSDNode>(N0);
752 AM.JT = J->getIndex();
753 AM.SymbolFlags = J->getTargetFlags();
756 if (N.getOpcode() == X86ISD::WrapperRIP)
757 AM.setBaseReg(CurDAG->getRegister(X86::RIP, MVT::i64));
761 // Handle the case when globals fit in our immediate field: This is true for
762 // X86-32 always and X86-64 when in -static -mcmodel=small mode. In 64-bit
763 // mode, this results in a non-RIP-relative computation.
764 if (!Subtarget->is64Bit() ||
765 (TM.getCodeModel() == CodeModel::Small &&
766 TM.getRelocationModel() == Reloc::Static)) {
767 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(N0)) {
768 AM.GV = G->getGlobal();
769 AM.Disp += G->getOffset();
770 AM.SymbolFlags = G->getTargetFlags();
771 } else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(N0)) {
772 AM.CP = CP->getConstVal();
773 AM.Align = CP->getAlignment();
774 AM.Disp += CP->getOffset();
775 AM.SymbolFlags = CP->getTargetFlags();
776 } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(N0)) {
777 AM.ES = S->getSymbol();
778 AM.SymbolFlags = S->getTargetFlags();
780 JumpTableSDNode *J = cast<JumpTableSDNode>(N0);
781 AM.JT = J->getIndex();
782 AM.SymbolFlags = J->getTargetFlags();
790 /// MatchAddress - Add the specified node to the specified addressing mode,
791 /// returning true if it cannot be done. This just pattern matches for the
793 bool X86DAGToDAGISel::MatchAddress(SDValue N, X86ISelAddressMode &AM) {
794 if (MatchAddressRecursively(N, AM, 0))
797 // Post-processing: Convert lea(,%reg,2) to lea(%reg,%reg), which has
798 // a smaller encoding and avoids a scaled-index.
800 AM.BaseType == X86ISelAddressMode::RegBase &&
801 AM.Base.Reg.getNode() == 0) {
802 AM.Base.Reg = AM.IndexReg;
809 bool X86DAGToDAGISel::MatchAddressRecursively(SDValue N, X86ISelAddressMode &AM,
811 bool is64Bit = Subtarget->is64Bit();
812 DebugLoc dl = N.getDebugLoc();
813 DOUT << "MatchAddress: "; DEBUG(AM.dump());
816 return MatchAddressBase(N, AM);
818 // If this is already a %rip relative address, we can only merge immediates
819 // into it. Instead of handling this in every case, we handle it here.
820 // RIP relative addressing: %rip + 32-bit displacement!
821 if (AM.isRIPRelative()) {
822 // FIXME: JumpTable and ExternalSymbol address currently don't like
823 // displacements. It isn't very important, but this should be fixed for
825 if (!AM.ES && AM.JT != -1) return true;
827 if (ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(N)) {
828 int64_t Val = AM.Disp + Cst->getSExtValue();
837 switch (N.getOpcode()) {
839 case ISD::Constant: {
840 uint64_t Val = cast<ConstantSDNode>(N)->getSExtValue();
841 if (!is64Bit || isInt32(AM.Disp + Val)) {
848 case X86ISD::SegmentBaseAddress:
849 if (!MatchSegmentBaseAddress(N, AM))
853 case X86ISD::Wrapper:
854 case X86ISD::WrapperRIP:
855 if (!MatchWrapper(N, AM))
860 if (!MatchLoad(N, AM))
864 case ISD::FrameIndex:
865 if (AM.BaseType == X86ISelAddressMode::RegBase
866 && AM.Base.Reg.getNode() == 0) {
867 AM.BaseType = X86ISelAddressMode::FrameIndexBase;
868 AM.Base.FrameIndex = cast<FrameIndexSDNode>(N)->getIndex();
874 if (AM.IndexReg.getNode() != 0 || AM.Scale != 1)
878 *CN = dyn_cast<ConstantSDNode>(N.getNode()->getOperand(1))) {
879 unsigned Val = CN->getZExtValue();
880 // Note that we handle x<<1 as (,x,2) rather than (x,x) here so
881 // that the base operand remains free for further matching. If
882 // the base doesn't end up getting used, a post-processing step
883 // in MatchAddress turns (,x,2) into (x,x), which is cheaper.
884 if (Val == 1 || Val == 2 || Val == 3) {
886 SDValue ShVal = N.getNode()->getOperand(0);
888 // Okay, we know that we have a scale by now. However, if the scaled
889 // value is an add of something and a constant, we can fold the
890 // constant into the disp field here.
891 if (ShVal.getNode()->getOpcode() == ISD::ADD && ShVal.hasOneUse() &&
892 isa<ConstantSDNode>(ShVal.getNode()->getOperand(1))) {
893 AM.IndexReg = ShVal.getNode()->getOperand(0);
894 ConstantSDNode *AddVal =
895 cast<ConstantSDNode>(ShVal.getNode()->getOperand(1));
896 uint64_t Disp = AM.Disp + (AddVal->getSExtValue() << Val);
897 if (!is64Bit || isInt32(Disp))
911 // A mul_lohi where we need the low part can be folded as a plain multiply.
912 if (N.getResNo() != 0) break;
915 case X86ISD::MUL_IMM:
916 // X*[3,5,9] -> X+X*[2,4,8]
917 if (AM.BaseType == X86ISelAddressMode::RegBase &&
918 AM.Base.Reg.getNode() == 0 &&
919 AM.IndexReg.getNode() == 0) {
921 *CN = dyn_cast<ConstantSDNode>(N.getNode()->getOperand(1)))
922 if (CN->getZExtValue() == 3 || CN->getZExtValue() == 5 ||
923 CN->getZExtValue() == 9) {
924 AM.Scale = unsigned(CN->getZExtValue())-1;
926 SDValue MulVal = N.getNode()->getOperand(0);
929 // Okay, we know that we have a scale by now. However, if the scaled
930 // value is an add of something and a constant, we can fold the
931 // constant into the disp field here.
932 if (MulVal.getNode()->getOpcode() == ISD::ADD && MulVal.hasOneUse() &&
933 isa<ConstantSDNode>(MulVal.getNode()->getOperand(1))) {
934 Reg = MulVal.getNode()->getOperand(0);
935 ConstantSDNode *AddVal =
936 cast<ConstantSDNode>(MulVal.getNode()->getOperand(1));
937 uint64_t Disp = AM.Disp + AddVal->getSExtValue() *
939 if (!is64Bit || isInt32(Disp))
942 Reg = N.getNode()->getOperand(0);
944 Reg = N.getNode()->getOperand(0);
947 AM.IndexReg = AM.Base.Reg = Reg;
954 // Given A-B, if A can be completely folded into the address and
955 // the index field with the index field unused, use -B as the index.
956 // This is a win if a has multiple parts that can be folded into
957 // the address. Also, this saves a mov if the base register has
958 // other uses, since it avoids a two-address sub instruction, however
959 // it costs an additional mov if the index register has other uses.
961 // Test if the LHS of the sub can be folded.
962 X86ISelAddressMode Backup = AM;
963 if (MatchAddressRecursively(N.getNode()->getOperand(0), AM, Depth+1)) {
967 // Test if the index field is free for use.
968 if (AM.IndexReg.getNode() || AM.isRIPRelative()) {
973 SDValue RHS = N.getNode()->getOperand(1);
974 // If the RHS involves a register with multiple uses, this
975 // transformation incurs an extra mov, due to the neg instruction
976 // clobbering its operand.
977 if (!RHS.getNode()->hasOneUse() ||
978 RHS.getNode()->getOpcode() == ISD::CopyFromReg ||
979 RHS.getNode()->getOpcode() == ISD::TRUNCATE ||
980 RHS.getNode()->getOpcode() == ISD::ANY_EXTEND ||
981 (RHS.getNode()->getOpcode() == ISD::ZERO_EXTEND &&
982 RHS.getNode()->getOperand(0).getValueType() == MVT::i32))
984 // If the base is a register with multiple uses, this
985 // transformation may save a mov.
986 if ((AM.BaseType == X86ISelAddressMode::RegBase &&
987 AM.Base.Reg.getNode() &&
988 !AM.Base.Reg.getNode()->hasOneUse()) ||
989 AM.BaseType == X86ISelAddressMode::FrameIndexBase)
991 // If the folded LHS was interesting, this transformation saves
992 // address arithmetic.
993 if ((AM.hasSymbolicDisplacement() && !Backup.hasSymbolicDisplacement()) +
994 ((AM.Disp != 0) && (Backup.Disp == 0)) +
995 (AM.Segment.getNode() && !Backup.Segment.getNode()) >= 2)
997 // If it doesn't look like it may be an overall win, don't do it.
1003 // Ok, the transformation is legal and appears profitable. Go for it.
1004 SDValue Zero = CurDAG->getConstant(0, N.getValueType());
1005 SDValue Neg = CurDAG->getNode(ISD::SUB, dl, N.getValueType(), Zero, RHS);
1009 // Insert the new nodes into the topological ordering.
1010 if (Zero.getNode()->getNodeId() == -1 ||
1011 Zero.getNode()->getNodeId() > N.getNode()->getNodeId()) {
1012 CurDAG->RepositionNode(N.getNode(), Zero.getNode());
1013 Zero.getNode()->setNodeId(N.getNode()->getNodeId());
1015 if (Neg.getNode()->getNodeId() == -1 ||
1016 Neg.getNode()->getNodeId() > N.getNode()->getNodeId()) {
1017 CurDAG->RepositionNode(N.getNode(), Neg.getNode());
1018 Neg.getNode()->setNodeId(N.getNode()->getNodeId());
1024 X86ISelAddressMode Backup = AM;
1025 if (!MatchAddressRecursively(N.getNode()->getOperand(0), AM, Depth+1) &&
1026 !MatchAddressRecursively(N.getNode()->getOperand(1), AM, Depth+1))
1029 if (!MatchAddressRecursively(N.getNode()->getOperand(1), AM, Depth+1) &&
1030 !MatchAddressRecursively(N.getNode()->getOperand(0), AM, Depth+1))
1034 // If we couldn't fold both operands into the address at the same time,
1035 // see if we can just put each operand into a register and fold at least
1037 if (AM.BaseType == X86ISelAddressMode::RegBase &&
1038 !AM.Base.Reg.getNode() &&
1039 !AM.IndexReg.getNode()) {
1040 AM.Base.Reg = N.getNode()->getOperand(0);
1041 AM.IndexReg = N.getNode()->getOperand(1);
1049 // Handle "X | C" as "X + C" iff X is known to have C bits clear.
1050 if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) {
1051 X86ISelAddressMode Backup = AM;
1052 uint64_t Offset = CN->getSExtValue();
1053 // Start with the LHS as an addr mode.
1054 if (!MatchAddressRecursively(N.getOperand(0), AM, Depth+1) &&
1055 // Address could not have picked a GV address for the displacement.
1057 // On x86-64, the resultant disp must fit in 32-bits.
1058 (!is64Bit || isInt32(AM.Disp + Offset)) &&
1059 // Check to see if the LHS & C is zero.
1060 CurDAG->MaskedValueIsZero(N.getOperand(0), CN->getAPIntValue())) {
1069 // Perform some heroic transforms on an and of a constant-count shift
1070 // with a constant to enable use of the scaled offset field.
1072 SDValue Shift = N.getOperand(0);
1073 if (Shift.getNumOperands() != 2) break;
1075 // Scale must not be used already.
1076 if (AM.IndexReg.getNode() != 0 || AM.Scale != 1) break;
1078 SDValue X = Shift.getOperand(0);
1079 ConstantSDNode *C2 = dyn_cast<ConstantSDNode>(N.getOperand(1));
1080 ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(Shift.getOperand(1));
1081 if (!C1 || !C2) break;
1083 // Handle "(X >> (8-C1)) & C2" as "(X >> 8) & 0xff)" if safe. This
1084 // allows us to convert the shift and and into an h-register extract and
1086 if (Shift.getOpcode() == ISD::SRL && Shift.hasOneUse()) {
1087 unsigned ScaleLog = 8 - C1->getZExtValue();
1088 if (ScaleLog > 0 && ScaleLog < 4 &&
1089 C2->getZExtValue() == (UINT64_C(0xff) << ScaleLog)) {
1090 SDValue Eight = CurDAG->getConstant(8, MVT::i8);
1091 SDValue Mask = CurDAG->getConstant(0xff, N.getValueType());
1092 SDValue Srl = CurDAG->getNode(ISD::SRL, dl, N.getValueType(),
1094 SDValue And = CurDAG->getNode(ISD::AND, dl, N.getValueType(),
1096 SDValue ShlCount = CurDAG->getConstant(ScaleLog, MVT::i8);
1097 SDValue Shl = CurDAG->getNode(ISD::SHL, dl, N.getValueType(),
1100 // Insert the new nodes into the topological ordering.
1101 if (Eight.getNode()->getNodeId() == -1 ||
1102 Eight.getNode()->getNodeId() > X.getNode()->getNodeId()) {
1103 CurDAG->RepositionNode(X.getNode(), Eight.getNode());
1104 Eight.getNode()->setNodeId(X.getNode()->getNodeId());
1106 if (Mask.getNode()->getNodeId() == -1 ||
1107 Mask.getNode()->getNodeId() > X.getNode()->getNodeId()) {
1108 CurDAG->RepositionNode(X.getNode(), Mask.getNode());
1109 Mask.getNode()->setNodeId(X.getNode()->getNodeId());
1111 if (Srl.getNode()->getNodeId() == -1 ||
1112 Srl.getNode()->getNodeId() > Shift.getNode()->getNodeId()) {
1113 CurDAG->RepositionNode(Shift.getNode(), Srl.getNode());
1114 Srl.getNode()->setNodeId(Shift.getNode()->getNodeId());
1116 if (And.getNode()->getNodeId() == -1 ||
1117 And.getNode()->getNodeId() > N.getNode()->getNodeId()) {
1118 CurDAG->RepositionNode(N.getNode(), And.getNode());
1119 And.getNode()->setNodeId(N.getNode()->getNodeId());
1121 if (ShlCount.getNode()->getNodeId() == -1 ||
1122 ShlCount.getNode()->getNodeId() > X.getNode()->getNodeId()) {
1123 CurDAG->RepositionNode(X.getNode(), ShlCount.getNode());
1124 ShlCount.getNode()->setNodeId(N.getNode()->getNodeId());
1126 if (Shl.getNode()->getNodeId() == -1 ||
1127 Shl.getNode()->getNodeId() > N.getNode()->getNodeId()) {
1128 CurDAG->RepositionNode(N.getNode(), Shl.getNode());
1129 Shl.getNode()->setNodeId(N.getNode()->getNodeId());
1131 CurDAG->ReplaceAllUsesWith(N, Shl);
1133 AM.Scale = (1 << ScaleLog);
1138 // Handle "(X << C1) & C2" as "(X & (C2>>C1)) << C1" if safe and if this
1139 // allows us to fold the shift into this addressing mode.
1140 if (Shift.getOpcode() != ISD::SHL) break;
1142 // Not likely to be profitable if either the AND or SHIFT node has more
1143 // than one use (unless all uses are for address computation). Besides,
1144 // isel mechanism requires their node ids to be reused.
1145 if (!N.hasOneUse() || !Shift.hasOneUse())
1148 // Verify that the shift amount is something we can fold.
1149 unsigned ShiftCst = C1->getZExtValue();
1150 if (ShiftCst != 1 && ShiftCst != 2 && ShiftCst != 3)
1153 // Get the new AND mask, this folds to a constant.
1154 SDValue NewANDMask = CurDAG->getNode(ISD::SRL, dl, N.getValueType(),
1155 SDValue(C2, 0), SDValue(C1, 0));
1156 SDValue NewAND = CurDAG->getNode(ISD::AND, dl, N.getValueType(), X,
1158 SDValue NewSHIFT = CurDAG->getNode(ISD::SHL, dl, N.getValueType(),
1159 NewAND, SDValue(C1, 0));
1161 // Insert the new nodes into the topological ordering.
1162 if (C1->getNodeId() > X.getNode()->getNodeId()) {
1163 CurDAG->RepositionNode(X.getNode(), C1);
1164 C1->setNodeId(X.getNode()->getNodeId());
1166 if (NewANDMask.getNode()->getNodeId() == -1 ||
1167 NewANDMask.getNode()->getNodeId() > X.getNode()->getNodeId()) {
1168 CurDAG->RepositionNode(X.getNode(), NewANDMask.getNode());
1169 NewANDMask.getNode()->setNodeId(X.getNode()->getNodeId());
1171 if (NewAND.getNode()->getNodeId() == -1 ||
1172 NewAND.getNode()->getNodeId() > Shift.getNode()->getNodeId()) {
1173 CurDAG->RepositionNode(Shift.getNode(), NewAND.getNode());
1174 NewAND.getNode()->setNodeId(Shift.getNode()->getNodeId());
1176 if (NewSHIFT.getNode()->getNodeId() == -1 ||
1177 NewSHIFT.getNode()->getNodeId() > N.getNode()->getNodeId()) {
1178 CurDAG->RepositionNode(N.getNode(), NewSHIFT.getNode());
1179 NewSHIFT.getNode()->setNodeId(N.getNode()->getNodeId());
1182 CurDAG->ReplaceAllUsesWith(N, NewSHIFT);
1184 AM.Scale = 1 << ShiftCst;
1185 AM.IndexReg = NewAND;
1190 return MatchAddressBase(N, AM);
1193 /// MatchAddressBase - Helper for MatchAddress. Add the specified node to the
1194 /// specified addressing mode without any further recursion.
1195 bool X86DAGToDAGISel::MatchAddressBase(SDValue N, X86ISelAddressMode &AM) {
1196 // Is the base register already occupied?
1197 if (AM.BaseType != X86ISelAddressMode::RegBase || AM.Base.Reg.getNode()) {
1198 // If so, check to see if the scale index register is set.
1199 if (AM.IndexReg.getNode() == 0) {
1205 // Otherwise, we cannot select it.
1209 // Default, generate it as a register.
1210 AM.BaseType = X86ISelAddressMode::RegBase;
1215 /// SelectAddr - returns true if it is able pattern match an addressing mode.
1216 /// It returns the operands which make up the maximal addressing mode it can
1217 /// match by reference.
1218 bool X86DAGToDAGISel::SelectAddr(SDValue Op, SDValue N, SDValue &Base,
1219 SDValue &Scale, SDValue &Index,
1220 SDValue &Disp, SDValue &Segment) {
1221 X86ISelAddressMode AM;
1223 if (AvoidDupAddrCompute && !N.hasOneUse()) {
1224 unsigned Opcode = N.getOpcode();
1225 if (Opcode != ISD::Constant && Opcode != ISD::FrameIndex &&
1226 Opcode != X86ISD::Wrapper && Opcode != X86ISD::WrapperRIP) {
1227 // If we are able to fold N into addressing mode, then we'll allow it even
1228 // if N has multiple uses. In general, addressing computation is used as
1229 // addresses by all of its uses. But watch out for CopyToReg uses, that
1230 // means the address computation is liveout. It will be computed by a LEA
1231 // so we want to avoid computing the address twice.
1232 for (SDNode::use_iterator UI = N.getNode()->use_begin(),
1233 UE = N.getNode()->use_end(); UI != UE; ++UI) {
1234 if (UI->getOpcode() == ISD::CopyToReg) {
1235 MatchAddressBase(N, AM);
1243 if (!Done && MatchAddress(N, AM))
1246 MVT VT = N.getValueType();
1247 if (AM.BaseType == X86ISelAddressMode::RegBase) {
1248 if (!AM.Base.Reg.getNode())
1249 AM.Base.Reg = CurDAG->getRegister(0, VT);
1252 if (!AM.IndexReg.getNode())
1253 AM.IndexReg = CurDAG->getRegister(0, VT);
1255 getAddressOperands(AM, Base, Scale, Index, Disp, Segment);
1259 /// SelectScalarSSELoad - Match a scalar SSE load. In particular, we want to
1260 /// match a load whose top elements are either undef or zeros. The load flavor
1261 /// is derived from the type of N, which is either v4f32 or v2f64.
1262 bool X86DAGToDAGISel::SelectScalarSSELoad(SDValue Op, SDValue Pred,
1263 SDValue N, SDValue &Base,
1264 SDValue &Scale, SDValue &Index,
1265 SDValue &Disp, SDValue &Segment,
1267 SDValue &OutChain) {
1268 if (N.getOpcode() == ISD::SCALAR_TO_VECTOR) {
1269 InChain = N.getOperand(0).getValue(1);
1270 if (ISD::isNON_EXTLoad(InChain.getNode()) &&
1271 InChain.getValue(0).hasOneUse() &&
1273 IsLegalAndProfitableToFold(N.getNode(), Pred.getNode(), Op.getNode())) {
1274 LoadSDNode *LD = cast<LoadSDNode>(InChain);
1275 if (!SelectAddr(Op, LD->getBasePtr(), Base, Scale, Index, Disp, Segment))
1277 OutChain = LD->getChain();
1282 // Also handle the case where we explicitly require zeros in the top
1283 // elements. This is a vector shuffle from the zero vector.
1284 if (N.getOpcode() == X86ISD::VZEXT_MOVL && N.getNode()->hasOneUse() &&
1285 // Check to see if the top elements are all zeros (or bitcast of zeros).
1286 N.getOperand(0).getOpcode() == ISD::SCALAR_TO_VECTOR &&
1287 N.getOperand(0).getNode()->hasOneUse() &&
1288 ISD::isNON_EXTLoad(N.getOperand(0).getOperand(0).getNode()) &&
1289 N.getOperand(0).getOperand(0).hasOneUse()) {
1290 // Okay, this is a zero extending load. Fold it.
1291 LoadSDNode *LD = cast<LoadSDNode>(N.getOperand(0).getOperand(0));
1292 if (!SelectAddr(Op, LD->getBasePtr(), Base, Scale, Index, Disp, Segment))
1294 OutChain = LD->getChain();
1295 InChain = SDValue(LD, 1);
1302 /// SelectLEAAddr - it calls SelectAddr and determines if the maximal addressing
1303 /// mode it matches can be cost effectively emitted as an LEA instruction.
1304 bool X86DAGToDAGISel::SelectLEAAddr(SDValue Op, SDValue N,
1305 SDValue &Base, SDValue &Scale,
1306 SDValue &Index, SDValue &Disp) {
1307 X86ISelAddressMode AM;
1309 // Set AM.Segment to prevent MatchAddress from using one. LEA doesn't support
1311 SDValue Copy = AM.Segment;
1312 SDValue T = CurDAG->getRegister(0, MVT::i32);
1314 if (MatchAddress(N, AM))
1316 assert (T == AM.Segment);
1319 MVT VT = N.getValueType();
1320 unsigned Complexity = 0;
1321 if (AM.BaseType == X86ISelAddressMode::RegBase)
1322 if (AM.Base.Reg.getNode())
1325 AM.Base.Reg = CurDAG->getRegister(0, VT);
1326 else if (AM.BaseType == X86ISelAddressMode::FrameIndexBase)
1329 if (AM.IndexReg.getNode())
1332 AM.IndexReg = CurDAG->getRegister(0, VT);
1334 // Don't match just leal(,%reg,2). It's cheaper to do addl %reg, %reg, or with
1339 // FIXME: We are artificially lowering the criteria to turn ADD %reg, $GA
1340 // to a LEA. This is determined with some expermentation but is by no means
1341 // optimal (especially for code size consideration). LEA is nice because of
1342 // its three-address nature. Tweak the cost function again when we can run
1343 // convertToThreeAddress() at register allocation time.
1344 if (AM.hasSymbolicDisplacement()) {
1345 // For X86-64, we should always use lea to materialize RIP relative
1347 if (Subtarget->is64Bit())
1353 if (AM.Disp && (AM.Base.Reg.getNode() || AM.IndexReg.getNode()))
1356 // If it isn't worth using an LEA, reject it.
1357 if (Complexity <= 2)
1361 getAddressOperands(AM, Base, Scale, Index, Disp, Segment);
1365 /// SelectTLSADDRAddr - This is only run on TargetGlobalTLSAddress nodes.
1366 bool X86DAGToDAGISel::SelectTLSADDRAddr(SDValue Op, SDValue N, SDValue &Base,
1367 SDValue &Scale, SDValue &Index,
1369 assert(Op.getOpcode() == X86ISD::TLSADDR);
1370 assert(N.getOpcode() == ISD::TargetGlobalTLSAddress);
1371 const GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(N);
1373 X86ISelAddressMode AM;
1374 AM.GV = GA->getGlobal();
1375 AM.Disp += GA->getOffset();
1376 AM.Base.Reg = CurDAG->getRegister(0, N.getValueType());
1377 AM.SymbolFlags = GA->getTargetFlags();
1379 if (N.getValueType() == MVT::i32) {
1381 AM.IndexReg = CurDAG->getRegister(X86::EBX, MVT::i32);
1383 AM.IndexReg = CurDAG->getRegister(0, MVT::i64);
1387 getAddressOperands(AM, Base, Scale, Index, Disp, Segment);
1392 bool X86DAGToDAGISel::TryFoldLoad(SDValue P, SDValue N,
1393 SDValue &Base, SDValue &Scale,
1394 SDValue &Index, SDValue &Disp,
1396 if (ISD::isNON_EXTLoad(N.getNode()) &&
1398 IsLegalAndProfitableToFold(N.getNode(), P.getNode(), P.getNode()))
1399 return SelectAddr(P, N.getOperand(1), Base, Scale, Index, Disp, Segment);
1403 /// getGlobalBaseReg - Return an SDNode that returns the value of
1404 /// the global base register. Output instructions required to
1405 /// initialize the global base register, if necessary.
1407 SDNode *X86DAGToDAGISel::getGlobalBaseReg() {
1408 MachineFunction *MF = CurBB->getParent();
1409 unsigned GlobalBaseReg = getInstrInfo()->getGlobalBaseReg(MF);
1410 return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).getNode();
1413 static SDNode *FindCallStartFromCall(SDNode *Node) {
1414 if (Node->getOpcode() == ISD::CALLSEQ_START) return Node;
1415 assert(Node->getOperand(0).getValueType() == MVT::Other &&
1416 "Node doesn't have a token chain argument!");
1417 return FindCallStartFromCall(Node->getOperand(0).getNode());
1420 SDNode *X86DAGToDAGISel::SelectAtomic64(SDNode *Node, unsigned Opc) {
1421 SDValue Chain = Node->getOperand(0);
1422 SDValue In1 = Node->getOperand(1);
1423 SDValue In2L = Node->getOperand(2);
1424 SDValue In2H = Node->getOperand(3);
1425 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
1426 if (!SelectAddr(In1, In1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4))
1428 SDValue LSI = Node->getOperand(4); // MemOperand
1429 const SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, In2L, In2H, LSI, Chain};
1430 return CurDAG->getTargetNode(Opc, Node->getDebugLoc(),
1431 MVT::i32, MVT::i32, MVT::Other, Ops,
1432 array_lengthof(Ops));
1435 SDNode *X86DAGToDAGISel::SelectAtomicLoadAdd(SDNode *Node, MVT NVT) {
1436 if (Node->hasAnyUseOfValue(0))
1439 // Optimize common patterns for __sync_add_and_fetch and
1440 // __sync_sub_and_fetch where the result is not used. This allows us
1441 // to use "lock" version of add, sub, inc, dec instructions.
1442 // FIXME: Do not use special instructions but instead add the "lock"
1443 // prefix to the target node somehow. The extra information will then be
1444 // transferred to machine instruction and it denotes the prefix.
1445 SDValue Chain = Node->getOperand(0);
1446 SDValue Ptr = Node->getOperand(1);
1447 SDValue Val = Node->getOperand(2);
1448 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
1449 if (!SelectAddr(Ptr, Ptr, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4))
1452 bool isInc = false, isDec = false, isSub = false, isCN = false;
1453 ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Val);
1456 int64_t CNVal = CN->getSExtValue();
1459 else if (CNVal == -1)
1461 else if (CNVal >= 0)
1462 Val = CurDAG->getTargetConstant(CNVal, NVT);
1465 Val = CurDAG->getTargetConstant(-CNVal, NVT);
1467 } else if (Val.hasOneUse() &&
1468 Val.getOpcode() == ISD::SUB &&
1469 X86::isZeroNode(Val.getOperand(0))) {
1471 Val = Val.getOperand(1);
1475 switch (NVT.getSimpleVT()) {
1479 Opc = X86::LOCK_INC8m;
1481 Opc = X86::LOCK_DEC8m;
1484 Opc = X86::LOCK_SUB8mi;
1486 Opc = X86::LOCK_SUB8mr;
1489 Opc = X86::LOCK_ADD8mi;
1491 Opc = X86::LOCK_ADD8mr;
1496 Opc = X86::LOCK_INC16m;
1498 Opc = X86::LOCK_DEC16m;
1501 if (Predicate_i16immSExt8(Val.getNode()))
1502 Opc = X86::LOCK_SUB16mi8;
1504 Opc = X86::LOCK_SUB16mi;
1506 Opc = X86::LOCK_SUB16mr;
1509 if (Predicate_i16immSExt8(Val.getNode()))
1510 Opc = X86::LOCK_ADD16mi8;
1512 Opc = X86::LOCK_ADD16mi;
1514 Opc = X86::LOCK_ADD16mr;
1519 Opc = X86::LOCK_INC32m;
1521 Opc = X86::LOCK_DEC32m;
1524 if (Predicate_i32immSExt8(Val.getNode()))
1525 Opc = X86::LOCK_SUB32mi8;
1527 Opc = X86::LOCK_SUB32mi;
1529 Opc = X86::LOCK_SUB32mr;
1532 if (Predicate_i32immSExt8(Val.getNode()))
1533 Opc = X86::LOCK_ADD32mi8;
1535 Opc = X86::LOCK_ADD32mi;
1537 Opc = X86::LOCK_ADD32mr;
1542 Opc = X86::LOCK_INC64m;
1544 Opc = X86::LOCK_DEC64m;
1546 Opc = X86::LOCK_SUB64mr;
1548 if (Predicate_i64immSExt8(Val.getNode()))
1549 Opc = X86::LOCK_SUB64mi8;
1550 else if (Predicate_i64immSExt32(Val.getNode()))
1551 Opc = X86::LOCK_SUB64mi32;
1554 Opc = X86::LOCK_ADD64mr;
1556 if (Predicate_i64immSExt8(Val.getNode()))
1557 Opc = X86::LOCK_ADD64mi8;
1558 else if (Predicate_i64immSExt32(Val.getNode()))
1559 Opc = X86::LOCK_ADD64mi32;
1565 DebugLoc dl = Node->getDebugLoc();
1566 SDValue Undef = SDValue(CurDAG->getTargetNode(TargetInstrInfo::IMPLICIT_DEF,
1568 SDValue MemOp = CurDAG->getMemOperand(cast<MemSDNode>(Node)->getMemOperand());
1569 if (isInc || isDec) {
1570 SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, MemOp, Chain };
1571 SDValue Ret = SDValue(CurDAG->getTargetNode(Opc, dl, MVT::Other, Ops, 7), 0);
1572 SDValue RetVals[] = { Undef, Ret };
1573 return CurDAG->getMergeValues(RetVals, 2, dl).getNode();
1575 SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, Val, MemOp, Chain };
1576 SDValue Ret = SDValue(CurDAG->getTargetNode(Opc, dl, MVT::Other, Ops, 8), 0);
1577 SDValue RetVals[] = { Undef, Ret };
1578 return CurDAG->getMergeValues(RetVals, 2, dl).getNode();
1582 SDNode *X86DAGToDAGISel::Select(SDValue N) {
1583 SDNode *Node = N.getNode();
1584 MVT NVT = Node->getValueType(0);
1586 unsigned Opcode = Node->getOpcode();
1587 DebugLoc dl = Node->getDebugLoc();
1590 DOUT << std::string(Indent, ' ') << "Selecting: ";
1591 DEBUG(Node->dump(CurDAG));
1596 if (Node->isMachineOpcode()) {
1598 DOUT << std::string(Indent-2, ' ') << "== ";
1599 DEBUG(Node->dump(CurDAG));
1603 return NULL; // Already selected.
1608 case X86ISD::GlobalBaseReg:
1609 return getGlobalBaseReg();
1611 case X86ISD::ATOMOR64_DAG:
1612 return SelectAtomic64(Node, X86::ATOMOR6432);
1613 case X86ISD::ATOMXOR64_DAG:
1614 return SelectAtomic64(Node, X86::ATOMXOR6432);
1615 case X86ISD::ATOMADD64_DAG:
1616 return SelectAtomic64(Node, X86::ATOMADD6432);
1617 case X86ISD::ATOMSUB64_DAG:
1618 return SelectAtomic64(Node, X86::ATOMSUB6432);
1619 case X86ISD::ATOMNAND64_DAG:
1620 return SelectAtomic64(Node, X86::ATOMNAND6432);
1621 case X86ISD::ATOMAND64_DAG:
1622 return SelectAtomic64(Node, X86::ATOMAND6432);
1623 case X86ISD::ATOMSWAP64_DAG:
1624 return SelectAtomic64(Node, X86::ATOMSWAP6432);
1626 case ISD::ATOMIC_LOAD_ADD: {
1627 SDNode *RetVal = SelectAtomicLoadAdd(Node, NVT);
1633 case ISD::SMUL_LOHI:
1634 case ISD::UMUL_LOHI: {
1635 SDValue N0 = Node->getOperand(0);
1636 SDValue N1 = Node->getOperand(1);
1638 bool isSigned = Opcode == ISD::SMUL_LOHI;
1640 switch (NVT.getSimpleVT()) {
1641 default: llvm_unreachable("Unsupported VT!");
1642 case MVT::i8: Opc = X86::MUL8r; MOpc = X86::MUL8m; break;
1643 case MVT::i16: Opc = X86::MUL16r; MOpc = X86::MUL16m; break;
1644 case MVT::i32: Opc = X86::MUL32r; MOpc = X86::MUL32m; break;
1645 case MVT::i64: Opc = X86::MUL64r; MOpc = X86::MUL64m; break;
1648 switch (NVT.getSimpleVT()) {
1649 default: llvm_unreachable("Unsupported VT!");
1650 case MVT::i8: Opc = X86::IMUL8r; MOpc = X86::IMUL8m; break;
1651 case MVT::i16: Opc = X86::IMUL16r; MOpc = X86::IMUL16m; break;
1652 case MVT::i32: Opc = X86::IMUL32r; MOpc = X86::IMUL32m; break;
1653 case MVT::i64: Opc = X86::IMUL64r; MOpc = X86::IMUL64m; break;
1656 unsigned LoReg, HiReg;
1657 switch (NVT.getSimpleVT()) {
1658 default: llvm_unreachable("Unsupported VT!");
1659 case MVT::i8: LoReg = X86::AL; HiReg = X86::AH; break;
1660 case MVT::i16: LoReg = X86::AX; HiReg = X86::DX; break;
1661 case MVT::i32: LoReg = X86::EAX; HiReg = X86::EDX; break;
1662 case MVT::i64: LoReg = X86::RAX; HiReg = X86::RDX; break;
1665 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
1666 bool foldedLoad = TryFoldLoad(N, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
1667 // multiplty is commmutative
1669 foldedLoad = TryFoldLoad(N, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
1674 SDValue InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, LoReg,
1675 N0, SDValue()).getValue(1);
1678 SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, N1.getOperand(0),
1681 CurDAG->getTargetNode(MOpc, dl, MVT::Other, MVT::Flag, Ops,
1682 array_lengthof(Ops));
1683 InFlag = SDValue(CNode, 1);
1684 // Update the chain.
1685 ReplaceUses(N1.getValue(1), SDValue(CNode, 0));
1688 SDValue(CurDAG->getTargetNode(Opc, dl, MVT::Flag, N1, InFlag), 0);
1691 // Copy the low half of the result, if it is needed.
1692 if (!N.getValue(0).use_empty()) {
1693 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
1694 LoReg, NVT, InFlag);
1695 InFlag = Result.getValue(2);
1696 ReplaceUses(N.getValue(0), Result);
1698 DOUT << std::string(Indent-2, ' ') << "=> ";
1699 DEBUG(Result.getNode()->dump(CurDAG));
1703 // Copy the high half of the result, if it is needed.
1704 if (!N.getValue(1).use_empty()) {
1706 if (HiReg == X86::AH && Subtarget->is64Bit()) {
1707 // Prevent use of AH in a REX instruction by referencing AX instead.
1708 // Shift it down 8 bits.
1709 Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
1710 X86::AX, MVT::i16, InFlag);
1711 InFlag = Result.getValue(2);
1712 Result = SDValue(CurDAG->getTargetNode(X86::SHR16ri, dl, MVT::i16,
1714 CurDAG->getTargetConstant(8, MVT::i8)), 0);
1715 // Then truncate it down to i8.
1716 SDValue SRIdx = CurDAG->getTargetConstant(X86::SUBREG_8BIT, MVT::i32);
1717 Result = SDValue(CurDAG->getTargetNode(X86::EXTRACT_SUBREG, dl,
1718 MVT::i8, Result, SRIdx), 0);
1720 Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
1721 HiReg, NVT, InFlag);
1722 InFlag = Result.getValue(2);
1724 ReplaceUses(N.getValue(1), Result);
1726 DOUT << std::string(Indent-2, ' ') << "=> ";
1727 DEBUG(Result.getNode()->dump(CurDAG));
1740 case ISD::UDIVREM: {
1741 SDValue N0 = Node->getOperand(0);
1742 SDValue N1 = Node->getOperand(1);
1744 bool isSigned = Opcode == ISD::SDIVREM;
1746 switch (NVT.getSimpleVT()) {
1747 default: llvm_unreachable("Unsupported VT!");
1748 case MVT::i8: Opc = X86::DIV8r; MOpc = X86::DIV8m; break;
1749 case MVT::i16: Opc = X86::DIV16r; MOpc = X86::DIV16m; break;
1750 case MVT::i32: Opc = X86::DIV32r; MOpc = X86::DIV32m; break;
1751 case MVT::i64: Opc = X86::DIV64r; MOpc = X86::DIV64m; break;
1754 switch (NVT.getSimpleVT()) {
1755 default: llvm_unreachable("Unsupported VT!");
1756 case MVT::i8: Opc = X86::IDIV8r; MOpc = X86::IDIV8m; break;
1757 case MVT::i16: Opc = X86::IDIV16r; MOpc = X86::IDIV16m; break;
1758 case MVT::i32: Opc = X86::IDIV32r; MOpc = X86::IDIV32m; break;
1759 case MVT::i64: Opc = X86::IDIV64r; MOpc = X86::IDIV64m; break;
1762 unsigned LoReg, HiReg;
1763 unsigned ClrOpcode, SExtOpcode;
1764 switch (NVT.getSimpleVT()) {
1765 default: llvm_unreachable("Unsupported VT!");
1767 LoReg = X86::AL; HiReg = X86::AH;
1769 SExtOpcode = X86::CBW;
1772 LoReg = X86::AX; HiReg = X86::DX;
1773 ClrOpcode = X86::MOV16r0;
1774 SExtOpcode = X86::CWD;
1777 LoReg = X86::EAX; HiReg = X86::EDX;
1778 ClrOpcode = X86::MOV32r0;
1779 SExtOpcode = X86::CDQ;
1782 LoReg = X86::RAX; HiReg = X86::RDX;
1783 ClrOpcode = ~0U; // NOT USED.
1784 SExtOpcode = X86::CQO;
1788 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
1789 bool foldedLoad = TryFoldLoad(N, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
1790 bool signBitIsZero = CurDAG->SignBitIsZero(N0);
1793 if (NVT == MVT::i8 && (!isSigned || signBitIsZero)) {
1794 // Special case for div8, just use a move with zero extension to AX to
1795 // clear the upper 8 bits (AH).
1796 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, Move, Chain;
1797 if (TryFoldLoad(N, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
1798 SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, N0.getOperand(0) };
1800 SDValue(CurDAG->getTargetNode(X86::MOVZX16rm8, dl, MVT::i16,
1802 array_lengthof(Ops)), 0);
1803 Chain = Move.getValue(1);
1804 ReplaceUses(N0.getValue(1), Chain);
1807 SDValue(CurDAG->getTargetNode(X86::MOVZX16rr8, dl, MVT::i16, N0),0);
1808 Chain = CurDAG->getEntryNode();
1810 Chain = CurDAG->getCopyToReg(Chain, dl, X86::AX, Move, SDValue());
1811 InFlag = Chain.getValue(1);
1814 CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl,
1815 LoReg, N0, SDValue()).getValue(1);
1816 if (isSigned && !signBitIsZero) {
1817 // Sign extend the low part into the high part.
1819 SDValue(CurDAG->getTargetNode(SExtOpcode, dl, MVT::Flag, InFlag),0);
1821 // Zero out the high part, effectively zero extending the input.
1824 if (NVT.getSimpleVT() == MVT::i64) {
1825 ClrNode = SDValue(CurDAG->getTargetNode(X86::MOV32r0, dl, MVT::i32),
1827 // We just did a 32-bit clear, insert it into a 64-bit register to
1828 // clear the whole 64-bit reg.
1830 SDValue(CurDAG->getTargetNode(TargetInstrInfo::IMPLICIT_DEF,
1833 CurDAG->getTargetConstant(X86::SUBREG_32BIT, MVT::i32);
1835 SDValue(CurDAG->getTargetNode(TargetInstrInfo::INSERT_SUBREG, dl,
1836 MVT::i64, Undef, ClrNode, SubRegNo),
1839 ClrNode = SDValue(CurDAG->getTargetNode(ClrOpcode, dl, NVT), 0);
1842 InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, HiReg,
1843 ClrNode, InFlag).getValue(1);
1848 SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, N1.getOperand(0),
1851 CurDAG->getTargetNode(MOpc, dl, MVT::Other, MVT::Flag, Ops,
1852 array_lengthof(Ops));
1853 InFlag = SDValue(CNode, 1);
1854 // Update the chain.
1855 ReplaceUses(N1.getValue(1), SDValue(CNode, 0));
1858 SDValue(CurDAG->getTargetNode(Opc, dl, MVT::Flag, N1, InFlag), 0);
1861 // Copy the division (low) result, if it is needed.
1862 if (!N.getValue(0).use_empty()) {
1863 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
1864 LoReg, NVT, InFlag);
1865 InFlag = Result.getValue(2);
1866 ReplaceUses(N.getValue(0), Result);
1868 DOUT << std::string(Indent-2, ' ') << "=> ";
1869 DEBUG(Result.getNode()->dump(CurDAG));
1873 // Copy the remainder (high) result, if it is needed.
1874 if (!N.getValue(1).use_empty()) {
1876 if (HiReg == X86::AH && Subtarget->is64Bit()) {
1877 // Prevent use of AH in a REX instruction by referencing AX instead.
1878 // Shift it down 8 bits.
1879 Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
1880 X86::AX, MVT::i16, InFlag);
1881 InFlag = Result.getValue(2);
1882 Result = SDValue(CurDAG->getTargetNode(X86::SHR16ri, dl, MVT::i16,
1884 CurDAG->getTargetConstant(8, MVT::i8)),
1886 // Then truncate it down to i8.
1887 SDValue SRIdx = CurDAG->getTargetConstant(X86::SUBREG_8BIT, MVT::i32);
1888 Result = SDValue(CurDAG->getTargetNode(X86::EXTRACT_SUBREG, dl,
1889 MVT::i8, Result, SRIdx), 0);
1891 Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
1892 HiReg, NVT, InFlag);
1893 InFlag = Result.getValue(2);
1895 ReplaceUses(N.getValue(1), Result);
1897 DOUT << std::string(Indent-2, ' ') << "=> ";
1898 DEBUG(Result.getNode()->dump(CurDAG));
1910 case ISD::DECLARE: {
1911 // Handle DECLARE nodes here because the second operand may have been
1912 // wrapped in X86ISD::Wrapper.
1913 SDValue Chain = Node->getOperand(0);
1914 SDValue N1 = Node->getOperand(1);
1915 SDValue N2 = Node->getOperand(2);
1916 FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(N1);
1918 // FIXME: We need to handle this for VLAs.
1920 ReplaceUses(N.getValue(0), Chain);
1924 if (N2.getOpcode() == ISD::ADD &&
1925 N2.getOperand(0).getOpcode() == X86ISD::GlobalBaseReg)
1926 N2 = N2.getOperand(1);
1928 // If N2 is not Wrapper(decriptor) then the llvm.declare is mangled
1929 // somehow, just ignore it.
1930 if (N2.getOpcode() != X86ISD::Wrapper &&
1931 N2.getOpcode() != X86ISD::WrapperRIP) {
1932 ReplaceUses(N.getValue(0), Chain);
1935 GlobalAddressSDNode *GVNode =
1936 dyn_cast<GlobalAddressSDNode>(N2.getOperand(0));
1938 ReplaceUses(N.getValue(0), Chain);
1941 SDValue Tmp1 = CurDAG->getTargetFrameIndex(FINode->getIndex(),
1942 TLI.getPointerTy());
1943 SDValue Tmp2 = CurDAG->getTargetGlobalAddress(GVNode->getGlobal(),
1944 TLI.getPointerTy());
1945 SDValue Ops[] = { Tmp1, Tmp2, Chain };
1946 return CurDAG->getTargetNode(TargetInstrInfo::DECLARE, dl,
1948 array_lengthof(Ops));
1952 SDNode *ResNode = SelectCode(N);
1955 DOUT << std::string(Indent-2, ' ') << "=> ";
1956 if (ResNode == NULL || ResNode == N.getNode())
1957 DEBUG(N.getNode()->dump(CurDAG));
1959 DEBUG(ResNode->dump(CurDAG));
1967 bool X86DAGToDAGISel::
1968 SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
1969 std::vector<SDValue> &OutOps) {
1970 SDValue Op0, Op1, Op2, Op3, Op4;
1971 switch (ConstraintCode) {
1972 case 'o': // offsetable ??
1973 case 'v': // not offsetable ??
1974 default: return true;
1976 if (!SelectAddr(Op, Op, Op0, Op1, Op2, Op3, Op4))
1981 OutOps.push_back(Op0);
1982 OutOps.push_back(Op1);
1983 OutOps.push_back(Op2);
1984 OutOps.push_back(Op3);
1985 OutOps.push_back(Op4);
1989 /// createX86ISelDag - This pass converts a legalized DAG into a
1990 /// X86-specific DAG, ready for instruction scheduling.
1992 FunctionPass *llvm::createX86ISelDag(X86TargetMachine &TM,
1993 llvm::CodeGenOpt::Level OptLevel) {
1994 return new X86DAGToDAGISel(TM, OptLevel);