Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===- X86ISelDAGToDAG.cpp - A DAG pattern matching inst selector for X86 -===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines a DAG pattern matching instruction selector for X86, |
| 11 | // converting from a legalized dag to a X86 dag. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #define DEBUG_TYPE "x86-isel" |
| 16 | #include "X86.h" |
| 17 | #include "X86InstrBuilder.h" |
| 18 | #include "X86ISelLowering.h" |
Evan Cheng | 0729ccf | 2008-01-05 00:41:47 +0000 | [diff] [blame] | 19 | #include "X86MachineFunctionInfo.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 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" |
Chris Lattner | 1b98919 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/SelectionDAGISel.h" |
| 34 | #include "llvm/Target/TargetMachine.h" |
Evan Cheng | 13559d6 | 2008-09-26 23:41:32 +0000 | [diff] [blame] | 35 | #include "llvm/Target/TargetOptions.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 36 | #include "llvm/Support/Compiler.h" |
| 37 | #include "llvm/Support/Debug.h" |
| 38 | #include "llvm/Support/MathExtras.h" |
Dale Johannesen | c501c08 | 2008-08-11 23:46:25 +0000 | [diff] [blame] | 39 | #include "llvm/Support/Streams.h" |
Evan Cheng | 656269e | 2008-04-25 08:22:20 +0000 | [diff] [blame] | 40 | #include "llvm/ADT/SmallPtrSet.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 41 | #include "llvm/ADT/Statistic.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 42 | using namespace llvm; |
| 43 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 44 | STATISTIC(NumLoadMoved, "Number of loads moved below TokenFactor"); |
| 45 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 46 | //===----------------------------------------------------------------------===// |
| 47 | // Pattern Matcher Implementation |
| 48 | //===----------------------------------------------------------------------===// |
| 49 | |
| 50 | namespace { |
| 51 | /// X86ISelAddressMode - This corresponds to X86AddressMode, but uses |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 52 | /// SDValue's instead of register numbers for the leaves of the matched |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 53 | /// tree. |
| 54 | struct X86ISelAddressMode { |
| 55 | enum { |
| 56 | RegBase, |
| 57 | FrameIndexBase |
| 58 | } BaseType; |
| 59 | |
| 60 | struct { // This is really a union, discriminated by BaseType! |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 61 | SDValue Reg; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 62 | int FrameIndex; |
| 63 | } Base; |
| 64 | |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 65 | bool isRIPRel; // RIP as base? |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 66 | unsigned Scale; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 67 | SDValue IndexReg; |
Dan Gohman | 0bd76b7 | 2008-11-11 15:52:29 +0000 | [diff] [blame] | 68 | int32_t Disp; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 69 | GlobalValue *GV; |
| 70 | Constant *CP; |
| 71 | const char *ES; |
| 72 | int JT; |
| 73 | unsigned Align; // CP alignment. |
| 74 | |
| 75 | X86ISelAddressMode() |
| 76 | : BaseType(RegBase), isRIPRel(false), Scale(1), IndexReg(), Disp(0), |
| 77 | GV(0), CP(0), ES(0), JT(-1), Align(0) { |
| 78 | } |
Dan Gohman | 245791b | 2009-02-07 00:43:41 +0000 | [diff] [blame] | 79 | |
| 80 | bool hasSymbolicDisplacement() const { |
| 81 | return GV != 0 || CP != 0 || ES != 0 || JT != -1; |
| 82 | } |
| 83 | |
Dale Johannesen | c501c08 | 2008-08-11 23:46:25 +0000 | [diff] [blame] | 84 | void dump() { |
| 85 | cerr << "X86ISelAddressMode " << this << "\n"; |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 86 | cerr << "Base.Reg "; |
| 87 | if (Base.Reg.getNode() != 0) Base.Reg.getNode()->dump(); |
| 88 | else cerr << "nul"; |
Dale Johannesen | c501c08 | 2008-08-11 23:46:25 +0000 | [diff] [blame] | 89 | cerr << " Base.FrameIndex " << Base.FrameIndex << "\n"; |
| 90 | cerr << "isRIPRel " << isRIPRel << " Scale" << Scale << "\n"; |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 91 | cerr << "IndexReg "; |
| 92 | if (IndexReg.getNode() != 0) IndexReg.getNode()->dump(); |
| 93 | else cerr << "nul"; |
Dale Johannesen | c501c08 | 2008-08-11 23:46:25 +0000 | [diff] [blame] | 94 | cerr << " Disp " << Disp << "\n"; |
| 95 | cerr << "GV "; if (GV) GV->dump(); |
| 96 | else cerr << "nul"; |
| 97 | cerr << " CP "; if (CP) CP->dump(); |
| 98 | else cerr << "nul"; |
| 99 | cerr << "\n"; |
| 100 | cerr << "ES "; if (ES) cerr << ES; else cerr << "nul"; |
| 101 | cerr << " JT" << JT << " Align" << Align << "\n"; |
| 102 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 103 | }; |
| 104 | } |
| 105 | |
| 106 | namespace { |
| 107 | //===--------------------------------------------------------------------===// |
| 108 | /// ISel - X86 specific code to select X86 machine instructions for |
| 109 | /// SelectionDAG operations. |
| 110 | /// |
| 111 | class VISIBILITY_HIDDEN X86DAGToDAGISel : public SelectionDAGISel { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 112 | /// TM - Keep a reference to X86TargetMachine. |
| 113 | /// |
| 114 | X86TargetMachine &TM; |
| 115 | |
| 116 | /// X86Lowering - This object fully describes how to lower LLVM code to an |
| 117 | /// X86-specific SelectionDAG. |
Dan Gohman | f2b2957 | 2008-10-03 16:55:19 +0000 | [diff] [blame] | 118 | X86TargetLowering &X86Lowering; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 119 | |
| 120 | /// Subtarget - Keep a pointer to the X86Subtarget around so that we can |
| 121 | /// make the right decision when generating code for different targets. |
| 122 | const X86Subtarget *Subtarget; |
| 123 | |
Evan Cheng | 34fd4f3 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 124 | /// CurBB - Current BB being isel'd. |
| 125 | /// |
| 126 | MachineBasicBlock *CurBB; |
| 127 | |
Evan Cheng | 13559d6 | 2008-09-26 23:41:32 +0000 | [diff] [blame] | 128 | /// OptForSize - If true, selector should try to optimize for code size |
| 129 | /// instead of performance. |
| 130 | bool OptForSize; |
| 131 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 132 | public: |
| 133 | X86DAGToDAGISel(X86TargetMachine &tm, bool fast) |
Dan Gohman | 96eb47a | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 134 | : SelectionDAGISel(tm, fast), |
Dan Gohman | 61ad864 | 2008-10-03 16:17:33 +0000 | [diff] [blame] | 135 | TM(tm), X86Lowering(*TM.getTargetLowering()), |
Evan Cheng | 13559d6 | 2008-09-26 23:41:32 +0000 | [diff] [blame] | 136 | Subtarget(&TM.getSubtarget<X86Subtarget>()), |
Devang Patel | 93698d9 | 2008-10-01 23:18:38 +0000 | [diff] [blame] | 137 | OptForSize(false) {} |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 138 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 139 | virtual const char *getPassName() const { |
| 140 | return "X86 DAG->DAG Instruction Selection"; |
| 141 | } |
| 142 | |
Evan Cheng | 34fd4f3 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 143 | /// InstructionSelect - This callback is invoked by |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 144 | /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 145 | virtual void InstructionSelect(); |
Evan Cheng | 34fd4f3 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 146 | |
Anton Korobeynikov | 34ef31e | 2007-09-25 21:52:30 +0000 | [diff] [blame] | 147 | virtual void EmitFunctionEntryCode(Function &Fn, MachineFunction &MF); |
| 148 | |
Evan Cheng | 5a42455 | 2008-11-27 00:49:46 +0000 | [diff] [blame] | 149 | virtual |
| 150 | bool IsLegalAndProfitableToFold(SDNode *N, SDNode *U, SDNode *Root) const; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 151 | |
| 152 | // Include the pieces autogenerated from the target description. |
| 153 | #include "X86GenDAGISel.inc" |
| 154 | |
| 155 | private: |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 156 | SDNode *Select(SDValue N); |
Dale Johannesen | f160d80 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 157 | SDNode *SelectAtomic64(SDNode *Node, unsigned Opc); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 158 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 159 | bool MatchAddress(SDValue N, X86ISelAddressMode &AM, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 160 | bool isRoot = true, unsigned Depth = 0); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 161 | bool MatchAddressBase(SDValue N, X86ISelAddressMode &AM, |
Dan Gohman | a60c1b3 | 2007-08-13 20:03:06 +0000 | [diff] [blame] | 162 | bool isRoot, unsigned Depth); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 163 | bool SelectAddr(SDValue Op, SDValue N, SDValue &Base, |
| 164 | SDValue &Scale, SDValue &Index, SDValue &Disp); |
| 165 | bool SelectLEAAddr(SDValue Op, SDValue N, SDValue &Base, |
| 166 | SDValue &Scale, SDValue &Index, SDValue &Disp); |
| 167 | bool SelectScalarSSELoad(SDValue Op, SDValue Pred, |
| 168 | SDValue N, SDValue &Base, SDValue &Scale, |
| 169 | SDValue &Index, SDValue &Disp, |
| 170 | SDValue &InChain, SDValue &OutChain); |
| 171 | bool TryFoldLoad(SDValue P, SDValue N, |
| 172 | SDValue &Base, SDValue &Scale, |
| 173 | SDValue &Index, SDValue &Disp); |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 174 | void PreprocessForRMW(); |
| 175 | void PreprocessForFPConvert(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 176 | |
| 177 | /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for |
| 178 | /// inline asm expressions. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 179 | virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 180 | char ConstraintCode, |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 181 | std::vector<SDValue> &OutOps); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 182 | |
Anton Korobeynikov | 34ef31e | 2007-09-25 21:52:30 +0000 | [diff] [blame] | 183 | void EmitSpecialCodeForMain(MachineBasicBlock *BB, MachineFrameInfo *MFI); |
| 184 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 185 | inline void getAddressOperands(X86ISelAddressMode &AM, SDValue &Base, |
| 186 | SDValue &Scale, SDValue &Index, |
| 187 | SDValue &Disp) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 188 | Base = (AM.BaseType == X86ISelAddressMode::FrameIndexBase) ? |
| 189 | CurDAG->getTargetFrameIndex(AM.Base.FrameIndex, TLI.getPointerTy()) : |
| 190 | AM.Base.Reg; |
| 191 | Scale = getI8Imm(AM.Scale); |
| 192 | Index = AM.IndexReg; |
| 193 | // These are 32-bit even in 64-bit mode since RIP relative offset |
| 194 | // is 32-bit. |
| 195 | if (AM.GV) |
| 196 | Disp = CurDAG->getTargetGlobalAddress(AM.GV, MVT::i32, AM.Disp); |
| 197 | else if (AM.CP) |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 198 | Disp = CurDAG->getTargetConstantPool(AM.CP, MVT::i32, |
| 199 | AM.Align, AM.Disp); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 200 | else if (AM.ES) |
Bill Wendling | fef0605 | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 201 | Disp = CurDAG->getTargetExternalSymbol(AM.ES, MVT::i32); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 202 | else if (AM.JT != -1) |
| 203 | Disp = CurDAG->getTargetJumpTable(AM.JT, MVT::i32); |
| 204 | else |
Dan Gohman | 0bd76b7 | 2008-11-11 15:52:29 +0000 | [diff] [blame] | 205 | Disp = CurDAG->getTargetConstant(AM.Disp, MVT::i32); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /// getI8Imm - Return a target constant with the specified value, of type |
| 209 | /// i8. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 210 | inline SDValue getI8Imm(unsigned Imm) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 211 | return CurDAG->getTargetConstant(Imm, MVT::i8); |
| 212 | } |
| 213 | |
| 214 | /// getI16Imm - Return a target constant with the specified value, of type |
| 215 | /// i16. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 216 | inline SDValue getI16Imm(unsigned Imm) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 217 | return CurDAG->getTargetConstant(Imm, MVT::i16); |
| 218 | } |
| 219 | |
| 220 | /// getI32Imm - Return a target constant with the specified value, of type |
| 221 | /// i32. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 222 | inline SDValue getI32Imm(unsigned Imm) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 223 | return CurDAG->getTargetConstant(Imm, MVT::i32); |
| 224 | } |
| 225 | |
Dan Gohman | b60482f | 2008-09-23 18:22:58 +0000 | [diff] [blame] | 226 | /// getGlobalBaseReg - Return an SDNode that returns the value of |
| 227 | /// the global base register. Output instructions required to |
| 228 | /// initialize the global base register, if necessary. |
| 229 | /// |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 230 | SDNode *getGlobalBaseReg(); |
| 231 | |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 232 | /// getTruncateTo8Bit - return an SDNode that implements a subreg based |
| 233 | /// truncate of the specified operand to i8. This can be done with tablegen, |
| 234 | /// except that this code uses MVT::Flag in a tricky way that happens to |
| 235 | /// improve scheduling in some cases. |
| 236 | SDNode *getTruncateTo8Bit(SDValue N0); |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 237 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 238 | #ifndef NDEBUG |
| 239 | unsigned Indent; |
| 240 | #endif |
| 241 | }; |
| 242 | } |
| 243 | |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 244 | /// findFlagUse - Return use of MVT::Flag value produced by the specified |
| 245 | /// SDNode. |
Evan Cheng | 656269e | 2008-04-25 08:22:20 +0000 | [diff] [blame] | 246 | /// |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 247 | static SDNode *findFlagUse(SDNode *N) { |
| 248 | unsigned FlagResNo = N->getNumValues()-1; |
| 249 | for (SDNode::use_iterator I = N->use_begin(), E = N->use_end(); I != E; ++I) { |
Dan Gohman | 13f24a7 | 2009-01-27 02:37:43 +0000 | [diff] [blame] | 250 | SDUse &Use = I.getUse(); |
| 251 | if (Use.getResNo() == FlagResNo) |
| 252 | return Use.getUser(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 253 | } |
| 254 | return NULL; |
| 255 | } |
| 256 | |
djg | 4b21095 | 2009-01-27 19:04:30 +0000 | [diff] [blame] | 257 | /// findNonImmUse - Return true if "Use" is a non-immediate use of "Def". |
| 258 | /// This function recursively traverses up the operand chain, ignoring |
| 259 | /// certain nodes. |
| 260 | static bool findNonImmUse(SDNode *Use, SDNode* Def, SDNode *ImmedUse, |
| 261 | SDNode *Root, |
Evan Cheng | 656269e | 2008-04-25 08:22:20 +0000 | [diff] [blame] | 262 | SmallPtrSet<SDNode*, 16> &Visited) { |
djg | 4b21095 | 2009-01-27 19:04:30 +0000 | [diff] [blame] | 263 | if (Use->getNodeId() < Def->getNodeId() || |
Evan Cheng | 656269e | 2008-04-25 08:22:20 +0000 | [diff] [blame] | 264 | !Visited.insert(Use)) |
djg | 4b21095 | 2009-01-27 19:04:30 +0000 | [diff] [blame] | 265 | return false; |
| 266 | |
| 267 | for (unsigned i = 0, e = Use->getNumOperands(); i != e; ++i) { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 268 | SDNode *N = Use->getOperand(i).getNode(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 269 | if (N == Def) { |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame] | 270 | if (Use == ImmedUse || Use == Root) |
Evan Cheng | 9ea310c | 2008-04-25 08:55:28 +0000 | [diff] [blame] | 271 | continue; // We are not looking for immediate use. |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame] | 272 | assert(N != Root); |
djg | 4b21095 | 2009-01-27 19:04:30 +0000 | [diff] [blame] | 273 | return true; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 274 | } |
Evan Cheng | 656269e | 2008-04-25 08:22:20 +0000 | [diff] [blame] | 275 | |
| 276 | // Traverse up the operand chain. |
djg | 4b21095 | 2009-01-27 19:04:30 +0000 | [diff] [blame] | 277 | if (findNonImmUse(N, Def, ImmedUse, Root, Visited)) |
| 278 | return true; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 279 | } |
djg | 4b21095 | 2009-01-27 19:04:30 +0000 | [diff] [blame] | 280 | return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /// isNonImmUse - Start searching from Root up the DAG to check is Def can |
| 284 | /// be reached. Return true if that's the case. However, ignore direct uses |
| 285 | /// by ImmedUse (which would be U in the example illustrated in |
Evan Cheng | 5a42455 | 2008-11-27 00:49:46 +0000 | [diff] [blame] | 286 | /// IsLegalAndProfitableToFold) and by Root (which can happen in the store |
| 287 | /// case). |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 288 | /// FIXME: to be really generic, we should allow direct use by any node |
| 289 | /// that is being folded. But realisticly since we only fold loads which |
| 290 | /// have one non-chain use, we only need to watch out for load/op/store |
| 291 | /// and load/op/cmp case where the root (store / cmp) may reach the load via |
| 292 | /// its chain operand. |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame] | 293 | static inline bool isNonImmUse(SDNode *Root, SDNode *Def, SDNode *ImmedUse) { |
Evan Cheng | 656269e | 2008-04-25 08:22:20 +0000 | [diff] [blame] | 294 | SmallPtrSet<SDNode*, 16> Visited; |
djg | 4b21095 | 2009-01-27 19:04:30 +0000 | [diff] [blame] | 295 | return findNonImmUse(Root, Def, ImmedUse, Root, Visited); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | |
Evan Cheng | 5a42455 | 2008-11-27 00:49:46 +0000 | [diff] [blame] | 299 | bool X86DAGToDAGISel::IsLegalAndProfitableToFold(SDNode *N, SDNode *U, |
| 300 | SDNode *Root) const { |
Dan Gohman | a29efcf | 2008-08-13 19:55:00 +0000 | [diff] [blame] | 301 | if (Fast) return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 302 | |
Evan Cheng | 5a42455 | 2008-11-27 00:49:46 +0000 | [diff] [blame] | 303 | if (U == Root) |
| 304 | switch (U->getOpcode()) { |
| 305 | default: break; |
| 306 | case ISD::ADD: |
| 307 | case ISD::ADDC: |
| 308 | case ISD::ADDE: |
| 309 | case ISD::AND: |
| 310 | case ISD::OR: |
| 311 | case ISD::XOR: { |
| 312 | // If the other operand is a 8-bit immediate we should fold the immediate |
| 313 | // instead. This reduces code size. |
| 314 | // e.g. |
| 315 | // movl 4(%esp), %eax |
| 316 | // addl $4, %eax |
| 317 | // vs. |
| 318 | // movl $4, %eax |
| 319 | // addl 4(%esp), %eax |
| 320 | // The former is 2 bytes shorter. In case where the increment is 1, then |
| 321 | // the saving can be 4 bytes (by using incl %eax). |
| 322 | ConstantSDNode *Imm = dyn_cast<ConstantSDNode>(U->getOperand(1)); |
| 323 | if (Imm) { |
| 324 | if (U->getValueType(0) == MVT::i64) { |
| 325 | if ((int32_t)Imm->getZExtValue() == (int64_t)Imm->getZExtValue()) |
| 326 | return false; |
| 327 | } else { |
| 328 | if ((int8_t)Imm->getZExtValue() == (int64_t)Imm->getZExtValue()) |
| 329 | return false; |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame] | 335 | // If Root use can somehow reach N through a path that that doesn't contain |
| 336 | // U then folding N would create a cycle. e.g. In the following |
| 337 | // diagram, Root can reach N through X. If N is folded into into Root, then |
| 338 | // X is both a predecessor and a successor of U. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 339 | // |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame] | 340 | // [N*] // |
| 341 | // ^ ^ // |
| 342 | // / \ // |
| 343 | // [U*] [X]? // |
| 344 | // ^ ^ // |
| 345 | // \ / // |
| 346 | // \ / // |
| 347 | // [Root*] // |
| 348 | // |
| 349 | // * indicates nodes to be folded together. |
| 350 | // |
| 351 | // If Root produces a flag, then it gets (even more) interesting. Since it |
| 352 | // will be "glued" together with its flag use in the scheduler, we need to |
| 353 | // check if it might reach N. |
| 354 | // |
| 355 | // [N*] // |
| 356 | // ^ ^ // |
| 357 | // / \ // |
| 358 | // [U*] [X]? // |
| 359 | // ^ ^ // |
| 360 | // \ \ // |
| 361 | // \ | // |
| 362 | // [Root*] | // |
| 363 | // ^ | // |
| 364 | // f | // |
| 365 | // | / // |
| 366 | // [Y] / // |
| 367 | // ^ / // |
| 368 | // f / // |
| 369 | // | / // |
| 370 | // [FU] // |
| 371 | // |
| 372 | // If FU (flag use) indirectly reaches N (the load), and Root folds N |
| 373 | // (call it Fold), then X is a predecessor of FU and a successor of |
| 374 | // Fold. But since Fold and FU are flagged together, this will create |
| 375 | // a cycle in the scheduling graph. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 376 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 377 | MVT VT = Root->getValueType(Root->getNumValues()-1); |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame] | 378 | while (VT == MVT::Flag) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 379 | SDNode *FU = findFlagUse(Root); |
| 380 | if (FU == NULL) |
| 381 | break; |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame] | 382 | Root = FU; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 383 | VT = Root->getValueType(Root->getNumValues()-1); |
| 384 | } |
| 385 | |
Dan Gohman | 602d44a | 2008-09-17 01:39:10 +0000 | [diff] [blame] | 386 | return !isNonImmUse(Root, N, U); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | /// MoveBelowTokenFactor - Replace TokenFactor operand with load's chain operand |
| 390 | /// and move load below the TokenFactor. Replace store's chain operand with |
| 391 | /// load's chain result. |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 392 | static void MoveBelowTokenFactor(SelectionDAG *CurDAG, SDValue Load, |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 393 | SDValue Store, SDValue TF) { |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 394 | SmallVector<SDValue, 4> Ops; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 395 | for (unsigned i = 0, e = TF.getNode()->getNumOperands(); i != e; ++i) |
| 396 | if (Load.getNode() == TF.getOperand(i).getNode()) |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 397 | Ops.push_back(Load.getOperand(0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 398 | else |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 399 | Ops.push_back(TF.getOperand(i)); |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 400 | CurDAG->UpdateNodeOperands(TF, &Ops[0], Ops.size()); |
| 401 | CurDAG->UpdateNodeOperands(Load, TF, Load.getOperand(1), Load.getOperand(2)); |
| 402 | CurDAG->UpdateNodeOperands(Store, Load.getValue(1), Store.getOperand(1), |
| 403 | Store.getOperand(2), Store.getOperand(3)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Evan Cheng | 2b2a701 | 2008-05-23 21:23:16 +0000 | [diff] [blame] | 406 | /// isRMWLoad - Return true if N is a load that's part of RMW sub-DAG. |
| 407 | /// |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 408 | static bool isRMWLoad(SDValue N, SDValue Chain, SDValue Address, |
| 409 | SDValue &Load) { |
Evan Cheng | 2b2a701 | 2008-05-23 21:23:16 +0000 | [diff] [blame] | 410 | if (N.getOpcode() == ISD::BIT_CONVERT) |
| 411 | N = N.getOperand(0); |
| 412 | |
| 413 | LoadSDNode *LD = dyn_cast<LoadSDNode>(N); |
| 414 | if (!LD || LD->isVolatile()) |
| 415 | return false; |
| 416 | if (LD->getAddressingMode() != ISD::UNINDEXED) |
| 417 | return false; |
| 418 | |
| 419 | ISD::LoadExtType ExtType = LD->getExtensionType(); |
| 420 | if (ExtType != ISD::NON_EXTLOAD && ExtType != ISD::EXTLOAD) |
| 421 | return false; |
| 422 | |
| 423 | if (N.hasOneUse() && |
| 424 | N.getOperand(1) == Address && |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 425 | N.getNode()->isOperandOf(Chain.getNode())) { |
Evan Cheng | 2b2a701 | 2008-05-23 21:23:16 +0000 | [diff] [blame] | 426 | Load = N; |
| 427 | return true; |
| 428 | } |
| 429 | return false; |
| 430 | } |
| 431 | |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 432 | /// MoveBelowCallSeqStart - Replace CALLSEQ_START operand with load's chain |
| 433 | /// operand and move load below the call's chain operand. |
| 434 | static void MoveBelowCallSeqStart(SelectionDAG *CurDAG, SDValue Load, |
evancheng | cd6d72b | 2009-01-26 18:43:34 +0000 | [diff] [blame] | 435 | SDValue Call, SDValue CallSeqStart) { |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 436 | SmallVector<SDValue, 8> Ops; |
evancheng | cd6d72b | 2009-01-26 18:43:34 +0000 | [diff] [blame] | 437 | SDValue Chain = CallSeqStart.getOperand(0); |
| 438 | if (Chain.getNode() == Load.getNode()) |
| 439 | Ops.push_back(Load.getOperand(0)); |
| 440 | else { |
| 441 | assert(Chain.getOpcode() == ISD::TokenFactor && |
| 442 | "Unexpected CallSeqStart chain operand"); |
| 443 | for (unsigned i = 0, e = Chain.getNumOperands(); i != e; ++i) |
| 444 | if (Chain.getOperand(i).getNode() == Load.getNode()) |
| 445 | Ops.push_back(Load.getOperand(0)); |
| 446 | else |
| 447 | Ops.push_back(Chain.getOperand(i)); |
| 448 | SDValue NewChain = |
Dale Johannesen | 913ba76 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 449 | CurDAG->getNode(ISD::TokenFactor, Load.getDebugLoc(), |
| 450 | MVT::Other, &Ops[0], Ops.size()); |
evancheng | cd6d72b | 2009-01-26 18:43:34 +0000 | [diff] [blame] | 451 | Ops.clear(); |
| 452 | Ops.push_back(NewChain); |
| 453 | } |
| 454 | for (unsigned i = 1, e = CallSeqStart.getNumOperands(); i != e; ++i) |
| 455 | Ops.push_back(CallSeqStart.getOperand(i)); |
| 456 | CurDAG->UpdateNodeOperands(CallSeqStart, &Ops[0], Ops.size()); |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 457 | CurDAG->UpdateNodeOperands(Load, Call.getOperand(0), |
| 458 | Load.getOperand(1), Load.getOperand(2)); |
| 459 | Ops.clear(); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 460 | Ops.push_back(SDValue(Load.getNode(), 1)); |
| 461 | for (unsigned i = 1, e = Call.getNode()->getNumOperands(); i != e; ++i) |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 462 | Ops.push_back(Call.getOperand(i)); |
| 463 | CurDAG->UpdateNodeOperands(Call, &Ops[0], Ops.size()); |
| 464 | } |
| 465 | |
| 466 | /// isCalleeLoad - Return true if call address is a load and it can be |
| 467 | /// moved below CALLSEQ_START and the chains leading up to the call. |
| 468 | /// Return the CALLSEQ_START by reference as a second output. |
| 469 | static bool isCalleeLoad(SDValue Callee, SDValue &Chain) { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 470 | if (Callee.getNode() == Chain.getNode() || !Callee.hasOneUse()) |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 471 | return false; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 472 | LoadSDNode *LD = dyn_cast<LoadSDNode>(Callee.getNode()); |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 473 | if (!LD || |
| 474 | LD->isVolatile() || |
| 475 | LD->getAddressingMode() != ISD::UNINDEXED || |
| 476 | LD->getExtensionType() != ISD::NON_EXTLOAD) |
| 477 | return false; |
| 478 | |
| 479 | // Now let's find the callseq_start. |
| 480 | while (Chain.getOpcode() != ISD::CALLSEQ_START) { |
| 481 | if (!Chain.hasOneUse()) |
| 482 | return false; |
| 483 | Chain = Chain.getOperand(0); |
| 484 | } |
evancheng | cd6d72b | 2009-01-26 18:43:34 +0000 | [diff] [blame] | 485 | |
| 486 | if (Chain.getOperand(0).getNode() == Callee.getNode()) |
| 487 | return true; |
| 488 | if (Chain.getOperand(0).getOpcode() == ISD::TokenFactor && |
| 489 | Callee.getValue(1).isOperandOf(Chain.getOperand(0).getNode())) |
| 490 | return true; |
| 491 | return false; |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 495 | /// PreprocessForRMW - Preprocess the DAG to make instruction selection better. |
| 496 | /// This is only run if not in -fast mode (aka -O0). |
| 497 | /// This allows the instruction selector to pick more read-modify-write |
| 498 | /// instructions. This is a common case: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 499 | /// |
| 500 | /// [Load chain] |
| 501 | /// ^ |
| 502 | /// | |
| 503 | /// [Load] |
| 504 | /// ^ ^ |
| 505 | /// | | |
| 506 | /// / \- |
| 507 | /// / | |
| 508 | /// [TokenFactor] [Op] |
| 509 | /// ^ ^ |
| 510 | /// | | |
| 511 | /// \ / |
| 512 | /// \ / |
| 513 | /// [Store] |
| 514 | /// |
| 515 | /// The fact the store's chain operand != load's chain will prevent the |
| 516 | /// (store (op (load))) instruction from being selected. We can transform it to: |
| 517 | /// |
| 518 | /// [Load chain] |
| 519 | /// ^ |
| 520 | /// | |
| 521 | /// [TokenFactor] |
| 522 | /// ^ |
| 523 | /// | |
| 524 | /// [Load] |
| 525 | /// ^ ^ |
| 526 | /// | | |
| 527 | /// | \- |
| 528 | /// | | |
| 529 | /// | [Op] |
| 530 | /// | ^ |
| 531 | /// | | |
| 532 | /// \ / |
| 533 | /// \ / |
| 534 | /// [Store] |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 535 | void X86DAGToDAGISel::PreprocessForRMW() { |
| 536 | for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(), |
| 537 | E = CurDAG->allnodes_end(); I != E; ++I) { |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 538 | if (I->getOpcode() == X86ISD::CALL) { |
| 539 | /// Also try moving call address load from outside callseq_start to just |
| 540 | /// before the call to allow it to be folded. |
| 541 | /// |
| 542 | /// [Load chain] |
| 543 | /// ^ |
| 544 | /// | |
| 545 | /// [Load] |
| 546 | /// ^ ^ |
| 547 | /// | | |
| 548 | /// / \-- |
| 549 | /// / | |
| 550 | ///[CALLSEQ_START] | |
| 551 | /// ^ | |
| 552 | /// | | |
| 553 | /// [LOAD/C2Reg] | |
| 554 | /// | | |
| 555 | /// \ / |
| 556 | /// \ / |
| 557 | /// [CALL] |
| 558 | SDValue Chain = I->getOperand(0); |
| 559 | SDValue Load = I->getOperand(1); |
| 560 | if (!isCalleeLoad(Load, Chain)) |
| 561 | continue; |
| 562 | MoveBelowCallSeqStart(CurDAG, Load, SDValue(I, 0), Chain); |
| 563 | ++NumLoadMoved; |
| 564 | continue; |
| 565 | } |
| 566 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 567 | if (!ISD::isNON_TRUNCStore(I)) |
| 568 | continue; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 569 | SDValue Chain = I->getOperand(0); |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 570 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 571 | if (Chain.getNode()->getOpcode() != ISD::TokenFactor) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 572 | continue; |
| 573 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 574 | SDValue N1 = I->getOperand(1); |
| 575 | SDValue N2 = I->getOperand(2); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 576 | if ((N1.getValueType().isFloatingPoint() && |
| 577 | !N1.getValueType().isVector()) || |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 578 | !N1.hasOneUse()) |
| 579 | continue; |
| 580 | |
| 581 | bool RModW = false; |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 582 | SDValue Load; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 583 | unsigned Opcode = N1.getNode()->getOpcode(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 584 | switch (Opcode) { |
Evan Cheng | 98cfaf8 | 2008-08-25 21:27:18 +0000 | [diff] [blame] | 585 | case ISD::ADD: |
| 586 | case ISD::MUL: |
| 587 | case ISD::AND: |
| 588 | case ISD::OR: |
| 589 | case ISD::XOR: |
| 590 | case ISD::ADDC: |
| 591 | case ISD::ADDE: |
| 592 | case ISD::VECTOR_SHUFFLE: { |
| 593 | SDValue N10 = N1.getOperand(0); |
| 594 | SDValue N11 = N1.getOperand(1); |
| 595 | RModW = isRMWLoad(N10, Chain, N2, Load); |
| 596 | if (!RModW) |
| 597 | RModW = isRMWLoad(N11, Chain, N2, Load); |
| 598 | break; |
| 599 | } |
| 600 | case ISD::SUB: |
| 601 | case ISD::SHL: |
| 602 | case ISD::SRA: |
| 603 | case ISD::SRL: |
| 604 | case ISD::ROTL: |
| 605 | case ISD::ROTR: |
| 606 | case ISD::SUBC: |
| 607 | case ISD::SUBE: |
| 608 | case X86ISD::SHLD: |
| 609 | case X86ISD::SHRD: { |
| 610 | SDValue N10 = N1.getOperand(0); |
| 611 | RModW = isRMWLoad(N10, Chain, N2, Load); |
| 612 | break; |
| 613 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | if (RModW) { |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 617 | MoveBelowTokenFactor(CurDAG, Load, SDValue(I, 0), Chain); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 618 | ++NumLoadMoved; |
| 619 | } |
| 620 | } |
| 621 | } |
| 622 | |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 623 | |
| 624 | /// PreprocessForFPConvert - Walk over the dag lowering fpround and fpextend |
| 625 | /// nodes that target the FP stack to be store and load to the stack. This is a |
| 626 | /// gross hack. We would like to simply mark these as being illegal, but when |
| 627 | /// we do that, legalize produces these when it expands calls, then expands |
| 628 | /// these in the same legalize pass. We would like dag combine to be able to |
| 629 | /// hack on these between the call expansion and the node legalization. As such |
| 630 | /// this pass basically does "really late" legalization of these inline with the |
| 631 | /// X86 isel pass. |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 632 | void X86DAGToDAGISel::PreprocessForFPConvert() { |
| 633 | for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(), |
| 634 | E = CurDAG->allnodes_end(); I != E; ) { |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 635 | SDNode *N = I++; // Preincrement iterator to avoid invalidation issues. |
| 636 | if (N->getOpcode() != ISD::FP_ROUND && N->getOpcode() != ISD::FP_EXTEND) |
| 637 | continue; |
| 638 | |
| 639 | // If the source and destination are SSE registers, then this is a legal |
| 640 | // conversion that should not be lowered. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 641 | MVT SrcVT = N->getOperand(0).getValueType(); |
| 642 | MVT DstVT = N->getValueType(0); |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 643 | bool SrcIsSSE = X86Lowering.isScalarFPTypeInSSEReg(SrcVT); |
| 644 | bool DstIsSSE = X86Lowering.isScalarFPTypeInSSEReg(DstVT); |
| 645 | if (SrcIsSSE && DstIsSSE) |
| 646 | continue; |
| 647 | |
Chris Lattner | 5d294e5 | 2008-03-09 07:05:32 +0000 | [diff] [blame] | 648 | if (!SrcIsSSE && !DstIsSSE) { |
| 649 | // If this is an FPStack extension, it is a noop. |
| 650 | if (N->getOpcode() == ISD::FP_EXTEND) |
| 651 | continue; |
| 652 | // If this is a value-preserving FPStack truncation, it is a noop. |
| 653 | if (N->getConstantOperandVal(1)) |
| 654 | continue; |
| 655 | } |
| 656 | |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 657 | // Here we could have an FP stack truncation or an FPStack <-> SSE convert. |
| 658 | // FPStack has extload and truncstore. SSE can fold direct loads into other |
| 659 | // operations. Based on this, decide what we want to do. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 660 | MVT MemVT; |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 661 | if (N->getOpcode() == ISD::FP_ROUND) |
| 662 | MemVT = DstVT; // FP_ROUND must use DstVT, we can't do a 'trunc load'. |
| 663 | else |
| 664 | MemVT = SrcIsSSE ? SrcVT : DstVT; |
| 665 | |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 666 | SDValue MemTmp = CurDAG->CreateStackTemporary(MemVT); |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 667 | DebugLoc dl = N->getDebugLoc(); |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 668 | |
| 669 | // FIXME: optimize the case where the src/dest is a load or store? |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 670 | SDValue Store = CurDAG->getTruncStore(CurDAG->getEntryNode(), dl, |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 671 | N->getOperand(0), |
| 672 | MemTmp, NULL, 0, MemVT); |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 673 | SDValue Result = CurDAG->getExtLoad(ISD::EXTLOAD, dl, DstVT, Store, MemTmp, |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 674 | NULL, 0, MemVT); |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 675 | |
| 676 | // We're about to replace all uses of the FP_ROUND/FP_EXTEND with the |
| 677 | // extload we created. This will cause general havok on the dag because |
| 678 | // anything below the conversion could be folded into other existing nodes. |
| 679 | // To avoid invalidating 'I', back it up to the convert node. |
| 680 | --I; |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 681 | CurDAG->ReplaceAllUsesOfValueWith(SDValue(N, 0), Result); |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 682 | |
| 683 | // Now that we did that, the node is dead. Increment the iterator to the |
| 684 | // next node to process, then delete N. |
| 685 | ++I; |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 686 | CurDAG->DeleteNode(N); |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 687 | } |
| 688 | } |
| 689 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 690 | /// InstructionSelectBasicBlock - This callback is invoked by SelectionDAGISel |
| 691 | /// when it has created a SelectionDAG for us to codegen. |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 692 | void X86DAGToDAGISel::InstructionSelect() { |
Evan Cheng | 34fd4f3 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 693 | CurBB = BB; // BB can change as result of isel. |
Devang Patel | 78eba02 | 2008-10-06 18:03:39 +0000 | [diff] [blame] | 694 | const Function *F = CurDAG->getMachineFunction().getFunction(); |
| 695 | OptForSize = F->hasFnAttr(Attribute::OptimizeForSize); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 696 | |
Evan Cheng | 34fd4f3 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 697 | DEBUG(BB->dump()); |
Dan Gohman | a29efcf | 2008-08-13 19:55:00 +0000 | [diff] [blame] | 698 | if (!Fast) |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 699 | PreprocessForRMW(); |
Chris Lattner | dec9cb5 | 2008-01-24 08:07:48 +0000 | [diff] [blame] | 700 | |
| 701 | // FIXME: This should only happen when not -fast. |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 702 | PreprocessForFPConvert(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 703 | |
| 704 | // Codegen the basic block. |
| 705 | #ifndef NDEBUG |
| 706 | DOUT << "===== Instruction selection begins:\n"; |
| 707 | Indent = 0; |
| 708 | #endif |
David Greene | 932618b | 2008-10-27 21:56:29 +0000 | [diff] [blame] | 709 | SelectRoot(*CurDAG); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 710 | #ifndef NDEBUG |
| 711 | DOUT << "===== Instruction selection ends:\n"; |
| 712 | #endif |
| 713 | |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 714 | CurDAG->RemoveDeadNodes(); |
Evan Cheng | 34fd4f3 | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 715 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 716 | |
Anton Korobeynikov | 34ef31e | 2007-09-25 21:52:30 +0000 | [diff] [blame] | 717 | /// EmitSpecialCodeForMain - Emit any code that needs to be executed only in |
| 718 | /// the main function. |
| 719 | void X86DAGToDAGISel::EmitSpecialCodeForMain(MachineBasicBlock *BB, |
| 720 | MachineFrameInfo *MFI) { |
| 721 | const TargetInstrInfo *TII = TM.getInstrInfo(); |
| 722 | if (Subtarget->isTargetCygMing()) |
Dale Johannesen | 960bfbd | 2009-02-13 02:33:27 +0000 | [diff] [blame] | 723 | BuildMI(BB, DebugLoc::getUnknownLoc(), |
| 724 | TII->get(X86::CALLpcrel32)).addExternalSymbol("__main"); |
Anton Korobeynikov | 34ef31e | 2007-09-25 21:52:30 +0000 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | void X86DAGToDAGISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) { |
| 728 | // If this is main, emit special code for main. |
| 729 | MachineBasicBlock *BB = MF.begin(); |
| 730 | if (Fn.hasExternalLinkage() && Fn.getName() == "main") |
| 731 | EmitSpecialCodeForMain(BB, MF.getFrameInfo()); |
| 732 | } |
| 733 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 734 | /// MatchAddress - Add the specified node to the specified addressing mode, |
| 735 | /// returning true if it cannot be done. This just pattern matches for the |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 736 | /// addressing mode. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 737 | bool X86DAGToDAGISel::MatchAddress(SDValue N, X86ISelAddressMode &AM, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 738 | bool isRoot, unsigned Depth) { |
Dan Gohman | 36322c7 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 739 | bool is64Bit = Subtarget->is64Bit(); |
Dale Johannesen | 2dbdb0e | 2009-02-07 19:59:05 +0000 | [diff] [blame] | 740 | DebugLoc dl = N.getDebugLoc(); |
Evan Cheng | 7f250d6 | 2008-09-24 00:05:32 +0000 | [diff] [blame] | 741 | DOUT << "MatchAddress: "; DEBUG(AM.dump()); |
Dan Gohman | a60c1b3 | 2007-08-13 20:03:06 +0000 | [diff] [blame] | 742 | // Limit recursion. |
| 743 | if (Depth > 5) |
| 744 | return MatchAddressBase(N, AM, isRoot, Depth); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 745 | |
| 746 | // RIP relative addressing: %rip + 32-bit displacement! |
| 747 | if (AM.isRIPRel) { |
| 748 | if (!AM.ES && AM.JT != -1 && N.getOpcode() == ISD::Constant) { |
Dan Gohman | 0bd76b7 | 2008-11-11 15:52:29 +0000 | [diff] [blame] | 749 | uint64_t Val = cast<ConstantSDNode>(N)->getSExtValue(); |
Dan Gohman | 36322c7 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 750 | if (!is64Bit || isInt32(AM.Disp + Val)) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 751 | AM.Disp += Val; |
| 752 | return false; |
| 753 | } |
| 754 | } |
| 755 | return true; |
| 756 | } |
| 757 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 758 | switch (N.getOpcode()) { |
| 759 | default: break; |
| 760 | case ISD::Constant: { |
Dan Gohman | 0bd76b7 | 2008-11-11 15:52:29 +0000 | [diff] [blame] | 761 | uint64_t Val = cast<ConstantSDNode>(N)->getSExtValue(); |
Dan Gohman | 36322c7 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 762 | if (!is64Bit || isInt32(AM.Disp + Val)) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 763 | AM.Disp += Val; |
| 764 | return false; |
| 765 | } |
| 766 | break; |
| 767 | } |
| 768 | |
| 769 | case X86ISD::Wrapper: { |
Dan Gohman | 36322c7 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 770 | DOUT << "Wrapper: 64bit " << is64Bit; |
| 771 | DOUT << " AM "; DEBUG(AM.dump()); DOUT << "\n"; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 772 | // Under X86-64 non-small code model, GV (and friends) are 64-bits. |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 773 | // Also, base and index reg must be 0 in order to use rip as base. |
| 774 | if (is64Bit && (TM.getCodeModel() != CodeModel::Small || |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 775 | AM.Base.Reg.getNode() || AM.IndexReg.getNode())) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 776 | break; |
Dan Gohman | 245791b | 2009-02-07 00:43:41 +0000 | [diff] [blame] | 777 | if (AM.hasSymbolicDisplacement()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 778 | break; |
| 779 | // If value is available in a register both base and index components have |
| 780 | // been picked, we can't fit the result available in the register in the |
| 781 | // addressing mode. Duplicate GlobalAddress or ConstantPool as displacement. |
Dan Gohman | cc3df85 | 2008-11-05 04:14:16 +0000 | [diff] [blame] | 782 | { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 783 | SDValue N0 = N.getOperand(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 784 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(N0)) { |
Dan Gohman | 0bd76b7 | 2008-11-11 15:52:29 +0000 | [diff] [blame] | 785 | uint64_t Offset = G->getOffset(); |
| 786 | if (!is64Bit || isInt32(AM.Disp + Offset)) { |
Dan Gohman | 36322c7 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 787 | GlobalValue *GV = G->getGlobal(); |
| 788 | AM.GV = GV; |
Dan Gohman | 0bd76b7 | 2008-11-11 15:52:29 +0000 | [diff] [blame] | 789 | AM.Disp += Offset; |
Dan Gohman | 36322c7 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 790 | AM.isRIPRel = TM.symbolicAddressesAreRIPRel(); |
| 791 | return false; |
| 792 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 793 | } else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(N0)) { |
Dan Gohman | 0bd76b7 | 2008-11-11 15:52:29 +0000 | [diff] [blame] | 794 | uint64_t Offset = CP->getOffset(); |
| 795 | if (!is64Bit || isInt32(AM.Disp + Offset)) { |
Dan Gohman | 36322c7 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 796 | AM.CP = CP->getConstVal(); |
| 797 | AM.Align = CP->getAlignment(); |
Dan Gohman | 0bd76b7 | 2008-11-11 15:52:29 +0000 | [diff] [blame] | 798 | AM.Disp += Offset; |
Dan Gohman | 36322c7 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 799 | AM.isRIPRel = TM.symbolicAddressesAreRIPRel(); |
| 800 | return false; |
| 801 | } |
Bill Wendling | fef0605 | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 802 | } else if (ExternalSymbolSDNode *S =dyn_cast<ExternalSymbolSDNode>(N0)) { |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 803 | AM.ES = S->getSymbol(); |
Dan Gohman | c641336 | 2008-09-26 19:15:30 +0000 | [diff] [blame] | 804 | AM.isRIPRel = TM.symbolicAddressesAreRIPRel(); |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 805 | return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 806 | } else if (JumpTableSDNode *J = dyn_cast<JumpTableSDNode>(N0)) { |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 807 | AM.JT = J->getIndex(); |
Dan Gohman | c641336 | 2008-09-26 19:15:30 +0000 | [diff] [blame] | 808 | AM.isRIPRel = TM.symbolicAddressesAreRIPRel(); |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 809 | return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 810 | } |
| 811 | } |
| 812 | break; |
| 813 | } |
| 814 | |
| 815 | case ISD::FrameIndex: |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 816 | if (AM.BaseType == X86ISelAddressMode::RegBase |
| 817 | && AM.Base.Reg.getNode() == 0) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 818 | AM.BaseType = X86ISelAddressMode::FrameIndexBase; |
| 819 | AM.Base.FrameIndex = cast<FrameIndexSDNode>(N)->getIndex(); |
| 820 | return false; |
| 821 | } |
| 822 | break; |
| 823 | |
| 824 | case ISD::SHL: |
Dan Gohman | cc3df85 | 2008-11-05 04:14:16 +0000 | [diff] [blame] | 825 | if (AM.IndexReg.getNode() != 0 || AM.Scale != 1 || AM.isRIPRel) |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 826 | break; |
| 827 | |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 828 | if (ConstantSDNode |
| 829 | *CN = dyn_cast<ConstantSDNode>(N.getNode()->getOperand(1))) { |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 830 | unsigned Val = CN->getZExtValue(); |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 831 | if (Val == 1 || Val == 2 || Val == 3) { |
| 832 | AM.Scale = 1 << Val; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 833 | SDValue ShVal = N.getNode()->getOperand(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 834 | |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 835 | // Okay, we know that we have a scale by now. However, if the scaled |
| 836 | // value is an add of something and a constant, we can fold the |
| 837 | // constant into the disp field here. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 838 | if (ShVal.getNode()->getOpcode() == ISD::ADD && ShVal.hasOneUse() && |
| 839 | isa<ConstantSDNode>(ShVal.getNode()->getOperand(1))) { |
| 840 | AM.IndexReg = ShVal.getNode()->getOperand(0); |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 841 | ConstantSDNode *AddVal = |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 842 | cast<ConstantSDNode>(ShVal.getNode()->getOperand(1)); |
Evan Cheng | 2ed6f34 | 2009-01-17 07:09:27 +0000 | [diff] [blame] | 843 | uint64_t Disp = AM.Disp + (AddVal->getSExtValue() << Val); |
Dan Gohman | 36322c7 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 844 | if (!is64Bit || isInt32(Disp)) |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 845 | AM.Disp = Disp; |
| 846 | else |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 847 | AM.IndexReg = ShVal; |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 848 | } else { |
| 849 | AM.IndexReg = ShVal; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 850 | } |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 851 | return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 852 | } |
| 853 | break; |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 854 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 855 | |
Dan Gohman | 35b9922 | 2007-10-22 20:22:24 +0000 | [diff] [blame] | 856 | case ISD::SMUL_LOHI: |
| 857 | case ISD::UMUL_LOHI: |
| 858 | // A mul_lohi where we need the low part can be folded as a plain multiply. |
Gabor Greif | 46bf547 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 859 | if (N.getResNo() != 0) break; |
Dan Gohman | 35b9922 | 2007-10-22 20:22:24 +0000 | [diff] [blame] | 860 | // FALL THROUGH |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 861 | case ISD::MUL: |
| 862 | // X*[3,5,9] -> X+X*[2,4,8] |
Dan Gohman | cc3df85 | 2008-11-05 04:14:16 +0000 | [diff] [blame] | 863 | if (AM.BaseType == X86ISelAddressMode::RegBase && |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 864 | AM.Base.Reg.getNode() == 0 && |
| 865 | AM.IndexReg.getNode() == 0 && |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 866 | !AM.isRIPRel) { |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 867 | if (ConstantSDNode |
| 868 | *CN = dyn_cast<ConstantSDNode>(N.getNode()->getOperand(1))) |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 869 | if (CN->getZExtValue() == 3 || CN->getZExtValue() == 5 || |
| 870 | CN->getZExtValue() == 9) { |
| 871 | AM.Scale = unsigned(CN->getZExtValue())-1; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 872 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 873 | SDValue MulVal = N.getNode()->getOperand(0); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 874 | SDValue Reg; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 875 | |
| 876 | // Okay, we know that we have a scale by now. However, if the scaled |
| 877 | // value is an add of something and a constant, we can fold the |
| 878 | // constant into the disp field here. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 879 | if (MulVal.getNode()->getOpcode() == ISD::ADD && MulVal.hasOneUse() && |
| 880 | isa<ConstantSDNode>(MulVal.getNode()->getOperand(1))) { |
| 881 | Reg = MulVal.getNode()->getOperand(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 882 | ConstantSDNode *AddVal = |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 883 | cast<ConstantSDNode>(MulVal.getNode()->getOperand(1)); |
Evan Cheng | 2ed6f34 | 2009-01-17 07:09:27 +0000 | [diff] [blame] | 884 | uint64_t Disp = AM.Disp + AddVal->getSExtValue() * |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 885 | CN->getZExtValue(); |
Dan Gohman | 36322c7 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 886 | if (!is64Bit || isInt32(Disp)) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 887 | AM.Disp = Disp; |
| 888 | else |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 889 | Reg = N.getNode()->getOperand(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 890 | } else { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 891 | Reg = N.getNode()->getOperand(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | AM.IndexReg = AM.Base.Reg = Reg; |
| 895 | return false; |
| 896 | } |
| 897 | } |
| 898 | break; |
| 899 | |
Evan Cheng | 2ed6f34 | 2009-01-17 07:09:27 +0000 | [diff] [blame] | 900 | case ISD::ADD: { |
| 901 | X86ISelAddressMode Backup = AM; |
| 902 | if (!MatchAddress(N.getNode()->getOperand(0), AM, false, Depth+1) && |
| 903 | !MatchAddress(N.getNode()->getOperand(1), AM, false, Depth+1)) |
| 904 | return false; |
| 905 | AM = Backup; |
| 906 | if (!MatchAddress(N.getNode()->getOperand(1), AM, false, Depth+1) && |
| 907 | !MatchAddress(N.getNode()->getOperand(0), AM, false, Depth+1)) |
| 908 | return false; |
| 909 | AM = Backup; |
Dan Gohman | 3ae9248 | 2009-03-13 02:25:09 +0000 | [diff] [blame] | 910 | |
| 911 | // If we couldn't fold both operands into the address at the same time, |
| 912 | // see if we can just put each operand into a register and fold at least |
| 913 | // the add. |
| 914 | if (AM.BaseType == X86ISelAddressMode::RegBase && |
| 915 | !AM.Base.Reg.getNode() && |
| 916 | !AM.IndexReg.getNode() && |
| 917 | !AM.isRIPRel) { |
| 918 | AM.Base.Reg = N.getNode()->getOperand(0); |
| 919 | AM.IndexReg = N.getNode()->getOperand(1); |
| 920 | AM.Scale = 1; |
| 921 | return false; |
| 922 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 923 | break; |
Evan Cheng | 2ed6f34 | 2009-01-17 07:09:27 +0000 | [diff] [blame] | 924 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 925 | |
| 926 | case ISD::OR: |
| 927 | // Handle "X | C" as "X + C" iff X is known to have C bits clear. |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 928 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N.getOperand(1))) { |
| 929 | X86ISelAddressMode Backup = AM; |
Dan Gohman | 0bd76b7 | 2008-11-11 15:52:29 +0000 | [diff] [blame] | 930 | uint64_t Offset = CN->getSExtValue(); |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 931 | // Start with the LHS as an addr mode. |
| 932 | if (!MatchAddress(N.getOperand(0), AM, false) && |
| 933 | // Address could not have picked a GV address for the displacement. |
| 934 | AM.GV == NULL && |
| 935 | // On x86-64, the resultant disp must fit in 32-bits. |
Dan Gohman | 0bd76b7 | 2008-11-11 15:52:29 +0000 | [diff] [blame] | 936 | (!is64Bit || isInt32(AM.Disp + Offset)) && |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 937 | // Check to see if the LHS & C is zero. |
Dan Gohman | 07961cd | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 938 | CurDAG->MaskedValueIsZero(N.getOperand(0), CN->getAPIntValue())) { |
Dan Gohman | 0bd76b7 | 2008-11-11 15:52:29 +0000 | [diff] [blame] | 939 | AM.Disp += Offset; |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 940 | return false; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 941 | } |
Chris Lattner | 7f06edd | 2007-12-08 07:22:58 +0000 | [diff] [blame] | 942 | AM = Backup; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 943 | } |
| 944 | break; |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 945 | |
| 946 | case ISD::AND: { |
| 947 | // Handle "(x << C1) & C2" as "(X & (C2>>C1)) << C1" if safe and if this |
| 948 | // allows us to fold the shift into this addressing mode. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 949 | SDValue Shift = N.getOperand(0); |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 950 | if (Shift.getOpcode() != ISD::SHL) break; |
Dan Gohman | cc3df85 | 2008-11-05 04:14:16 +0000 | [diff] [blame] | 951 | |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 952 | // Scale must not be used already. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 953 | if (AM.IndexReg.getNode() != 0 || AM.Scale != 1) break; |
Evan Cheng | 3b5a127 | 2008-02-07 08:53:49 +0000 | [diff] [blame] | 954 | |
| 955 | // Not when RIP is used as the base. |
| 956 | if (AM.isRIPRel) break; |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 957 | |
| 958 | ConstantSDNode *C2 = dyn_cast<ConstantSDNode>(N.getOperand(1)); |
| 959 | ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(Shift.getOperand(1)); |
| 960 | if (!C1 || !C2) break; |
| 961 | |
| 962 | // Not likely to be profitable if either the AND or SHIFT node has more |
| 963 | // than one use (unless all uses are for address computation). Besides, |
| 964 | // isel mechanism requires their node ids to be reused. |
| 965 | if (!N.hasOneUse() || !Shift.hasOneUse()) |
| 966 | break; |
| 967 | |
| 968 | // Verify that the shift amount is something we can fold. |
Dan Gohman | faeb4a3 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 969 | unsigned ShiftCst = C1->getZExtValue(); |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 970 | if (ShiftCst != 1 && ShiftCst != 2 && ShiftCst != 3) |
| 971 | break; |
| 972 | |
| 973 | // Get the new AND mask, this folds to a constant. |
Dan Gohman | cc3df85 | 2008-11-05 04:14:16 +0000 | [diff] [blame] | 974 | SDValue X = Shift.getOperand(0); |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 975 | SDValue NewANDMask = CurDAG->getNode(ISD::SRL, dl, N.getValueType(), |
Evan Cheng | 07d091a | 2008-10-14 17:15:39 +0000 | [diff] [blame] | 976 | SDValue(C2, 0), SDValue(C1, 0)); |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 977 | SDValue NewAND = CurDAG->getNode(ISD::AND, dl, N.getValueType(), X, |
| 978 | NewANDMask); |
| 979 | SDValue NewSHIFT = CurDAG->getNode(ISD::SHL, dl, N.getValueType(), |
Dan Gohman | 3666f47 | 2008-10-13 20:52:04 +0000 | [diff] [blame] | 980 | NewAND, SDValue(C1, 0)); |
Dan Gohman | cc3df85 | 2008-11-05 04:14:16 +0000 | [diff] [blame] | 981 | |
| 982 | // Insert the new nodes into the topological ordering. |
| 983 | if (C1->getNodeId() > X.getNode()->getNodeId()) { |
| 984 | CurDAG->RepositionNode(X.getNode(), C1); |
| 985 | C1->setNodeId(X.getNode()->getNodeId()); |
| 986 | } |
| 987 | if (NewANDMask.getNode()->getNodeId() == -1 || |
| 988 | NewANDMask.getNode()->getNodeId() > X.getNode()->getNodeId()) { |
| 989 | CurDAG->RepositionNode(X.getNode(), NewANDMask.getNode()); |
| 990 | NewANDMask.getNode()->setNodeId(X.getNode()->getNodeId()); |
| 991 | } |
| 992 | if (NewAND.getNode()->getNodeId() == -1 || |
| 993 | NewAND.getNode()->getNodeId() > Shift.getNode()->getNodeId()) { |
| 994 | CurDAG->RepositionNode(Shift.getNode(), NewAND.getNode()); |
| 995 | NewAND.getNode()->setNodeId(Shift.getNode()->getNodeId()); |
| 996 | } |
| 997 | if (NewSHIFT.getNode()->getNodeId() == -1 || |
| 998 | NewSHIFT.getNode()->getNodeId() > N.getNode()->getNodeId()) { |
| 999 | CurDAG->RepositionNode(N.getNode(), NewSHIFT.getNode()); |
| 1000 | NewSHIFT.getNode()->setNodeId(N.getNode()->getNodeId()); |
| 1001 | } |
| 1002 | |
Dan Gohman | 3666f47 | 2008-10-13 20:52:04 +0000 | [diff] [blame] | 1003 | CurDAG->ReplaceAllUsesWith(N, NewSHIFT); |
Evan Cheng | f2abee7 | 2007-12-13 00:43:27 +0000 | [diff] [blame] | 1004 | |
| 1005 | AM.Scale = 1 << ShiftCst; |
| 1006 | AM.IndexReg = NewAND; |
| 1007 | return false; |
| 1008 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
Dan Gohman | a60c1b3 | 2007-08-13 20:03:06 +0000 | [diff] [blame] | 1011 | return MatchAddressBase(N, AM, isRoot, Depth); |
| 1012 | } |
| 1013 | |
| 1014 | /// MatchAddressBase - Helper for MatchAddress. Add the specified node to the |
| 1015 | /// specified addressing mode without any further recursion. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1016 | bool X86DAGToDAGISel::MatchAddressBase(SDValue N, X86ISelAddressMode &AM, |
Dan Gohman | a60c1b3 | 2007-08-13 20:03:06 +0000 | [diff] [blame] | 1017 | bool isRoot, unsigned Depth) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1018 | // Is the base register already occupied? |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1019 | if (AM.BaseType != X86ISelAddressMode::RegBase || AM.Base.Reg.getNode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1020 | // If so, check to see if the scale index register is set. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1021 | if (AM.IndexReg.getNode() == 0 && !AM.isRIPRel) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1022 | AM.IndexReg = N; |
| 1023 | AM.Scale = 1; |
| 1024 | return false; |
| 1025 | } |
| 1026 | |
| 1027 | // Otherwise, we cannot select it. |
| 1028 | return true; |
| 1029 | } |
| 1030 | |
| 1031 | // Default, generate it as a register. |
| 1032 | AM.BaseType = X86ISelAddressMode::RegBase; |
| 1033 | AM.Base.Reg = N; |
| 1034 | return false; |
| 1035 | } |
| 1036 | |
| 1037 | /// SelectAddr - returns true if it is able pattern match an addressing mode. |
| 1038 | /// It returns the operands which make up the maximal addressing mode it can |
| 1039 | /// match by reference. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1040 | bool X86DAGToDAGISel::SelectAddr(SDValue Op, SDValue N, SDValue &Base, |
| 1041 | SDValue &Scale, SDValue &Index, |
| 1042 | SDValue &Disp) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1043 | X86ISelAddressMode AM; |
| 1044 | if (MatchAddress(N, AM)) |
| 1045 | return false; |
| 1046 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1047 | MVT VT = N.getValueType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1048 | if (AM.BaseType == X86ISelAddressMode::RegBase) { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1049 | if (!AM.Base.Reg.getNode()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1050 | AM.Base.Reg = CurDAG->getRegister(0, VT); |
| 1051 | } |
| 1052 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1053 | if (!AM.IndexReg.getNode()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1054 | AM.IndexReg = CurDAG->getRegister(0, VT); |
| 1055 | |
| 1056 | getAddressOperands(AM, Base, Scale, Index, Disp); |
| 1057 | return true; |
| 1058 | } |
| 1059 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1060 | /// SelectScalarSSELoad - Match a scalar SSE load. In particular, we want to |
| 1061 | /// match a load whose top elements are either undef or zeros. The load flavor |
| 1062 | /// is derived from the type of N, which is either v4f32 or v2f64. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1063 | bool X86DAGToDAGISel::SelectScalarSSELoad(SDValue Op, SDValue Pred, |
| 1064 | SDValue N, SDValue &Base, |
| 1065 | SDValue &Scale, SDValue &Index, |
| 1066 | SDValue &Disp, SDValue &InChain, |
| 1067 | SDValue &OutChain) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1068 | if (N.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 1069 | InChain = N.getOperand(0).getValue(1); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1070 | if (ISD::isNON_EXTLoad(InChain.getNode()) && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1071 | InChain.getValue(0).hasOneUse() && |
| 1072 | N.hasOneUse() && |
Evan Cheng | 5a42455 | 2008-11-27 00:49:46 +0000 | [diff] [blame] | 1073 | IsLegalAndProfitableToFold(N.getNode(), Pred.getNode(), Op.getNode())) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1074 | LoadSDNode *LD = cast<LoadSDNode>(InChain); |
| 1075 | if (!SelectAddr(Op, LD->getBasePtr(), Base, Scale, Index, Disp)) |
| 1076 | return false; |
| 1077 | OutChain = LD->getChain(); |
| 1078 | return true; |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | // Also handle the case where we explicitly require zeros in the top |
| 1083 | // elements. This is a vector shuffle from the zero vector. |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1084 | if (N.getOpcode() == X86ISD::VZEXT_MOVL && N.getNode()->hasOneUse() && |
Chris Lattner | e6aa386 | 2007-11-25 00:24:49 +0000 | [diff] [blame] | 1085 | // Check to see if the top elements are all zeros (or bitcast of zeros). |
Evan Cheng | 40ee6e5 | 2008-05-08 00:57:18 +0000 | [diff] [blame] | 1086 | N.getOperand(0).getOpcode() == ISD::SCALAR_TO_VECTOR && |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1087 | N.getOperand(0).getNode()->hasOneUse() && |
| 1088 | ISD::isNON_EXTLoad(N.getOperand(0).getOperand(0).getNode()) && |
Evan Cheng | 40ee6e5 | 2008-05-08 00:57:18 +0000 | [diff] [blame] | 1089 | N.getOperand(0).getOperand(0).hasOneUse()) { |
| 1090 | // Okay, this is a zero extending load. Fold it. |
| 1091 | LoadSDNode *LD = cast<LoadSDNode>(N.getOperand(0).getOperand(0)); |
| 1092 | if (!SelectAddr(Op, LD->getBasePtr(), Base, Scale, Index, Disp)) |
| 1093 | return false; |
| 1094 | OutChain = LD->getChain(); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1095 | InChain = SDValue(LD, 1); |
Evan Cheng | 40ee6e5 | 2008-05-08 00:57:18 +0000 | [diff] [blame] | 1096 | return true; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1097 | } |
| 1098 | return false; |
| 1099 | } |
| 1100 | |
| 1101 | |
| 1102 | /// SelectLEAAddr - it calls SelectAddr and determines if the maximal addressing |
| 1103 | /// mode it matches can be cost effectively emitted as an LEA instruction. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1104 | bool X86DAGToDAGISel::SelectLEAAddr(SDValue Op, SDValue N, |
| 1105 | SDValue &Base, SDValue &Scale, |
| 1106 | SDValue &Index, SDValue &Disp) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1107 | X86ISelAddressMode AM; |
| 1108 | if (MatchAddress(N, AM)) |
| 1109 | return false; |
| 1110 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1111 | MVT VT = N.getValueType(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1112 | unsigned Complexity = 0; |
| 1113 | if (AM.BaseType == X86ISelAddressMode::RegBase) |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1114 | if (AM.Base.Reg.getNode()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1115 | Complexity = 1; |
| 1116 | else |
| 1117 | AM.Base.Reg = CurDAG->getRegister(0, VT); |
| 1118 | else if (AM.BaseType == X86ISelAddressMode::FrameIndexBase) |
| 1119 | Complexity = 4; |
| 1120 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1121 | if (AM.IndexReg.getNode()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1122 | Complexity++; |
| 1123 | else |
| 1124 | AM.IndexReg = CurDAG->getRegister(0, VT); |
| 1125 | |
| 1126 | // Don't match just leal(,%reg,2). It's cheaper to do addl %reg, %reg, or with |
| 1127 | // a simple shift. |
| 1128 | if (AM.Scale > 1) |
| 1129 | Complexity++; |
| 1130 | |
| 1131 | // FIXME: We are artificially lowering the criteria to turn ADD %reg, $GA |
| 1132 | // to a LEA. This is determined with some expermentation but is by no means |
| 1133 | // optimal (especially for code size consideration). LEA is nice because of |
| 1134 | // its three-address nature. Tweak the cost function again when we can run |
| 1135 | // convertToThreeAddress() at register allocation time. |
Dan Gohman | 245791b | 2009-02-07 00:43:41 +0000 | [diff] [blame] | 1136 | if (AM.hasSymbolicDisplacement()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1137 | // For X86-64, we should always use lea to materialize RIP relative |
| 1138 | // addresses. |
| 1139 | if (Subtarget->is64Bit()) |
| 1140 | Complexity = 4; |
| 1141 | else |
| 1142 | Complexity += 2; |
| 1143 | } |
| 1144 | |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1145 | if (AM.Disp && (AM.Base.Reg.getNode() || AM.IndexReg.getNode())) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1146 | Complexity++; |
| 1147 | |
| 1148 | if (Complexity > 2) { |
| 1149 | getAddressOperands(AM, Base, Scale, Index, Disp); |
| 1150 | return true; |
| 1151 | } |
| 1152 | return false; |
| 1153 | } |
| 1154 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1155 | bool X86DAGToDAGISel::TryFoldLoad(SDValue P, SDValue N, |
| 1156 | SDValue &Base, SDValue &Scale, |
| 1157 | SDValue &Index, SDValue &Disp) { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1158 | if (ISD::isNON_EXTLoad(N.getNode()) && |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1159 | N.hasOneUse() && |
Evan Cheng | 5a42455 | 2008-11-27 00:49:46 +0000 | [diff] [blame] | 1160 | IsLegalAndProfitableToFold(N.getNode(), P.getNode(), P.getNode())) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1161 | return SelectAddr(P, N.getOperand(1), Base, Scale, Index, Disp); |
| 1162 | return false; |
| 1163 | } |
| 1164 | |
Dan Gohman | b60482f | 2008-09-23 18:22:58 +0000 | [diff] [blame] | 1165 | /// getGlobalBaseReg - Return an SDNode that returns the value of |
| 1166 | /// the global base register. Output instructions required to |
| 1167 | /// initialize the global base register, if necessary. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1168 | /// |
| 1169 | SDNode *X86DAGToDAGISel::getGlobalBaseReg() { |
Dan Gohman | 882ab73 | 2008-09-30 00:58:23 +0000 | [diff] [blame] | 1170 | MachineFunction *MF = CurBB->getParent(); |
| 1171 | unsigned GlobalBaseReg = TM.getInstrInfo()->getGlobalBaseReg(MF); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1172 | return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).getNode(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | static SDNode *FindCallStartFromCall(SDNode *Node) { |
| 1176 | if (Node->getOpcode() == ISD::CALLSEQ_START) return Node; |
| 1177 | assert(Node->getOperand(0).getValueType() == MVT::Other && |
| 1178 | "Node doesn't have a token chain argument!"); |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1179 | return FindCallStartFromCall(Node->getOperand(0).getNode()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1182 | /// getTruncateTo8Bit - return an SDNode that implements a subreg based |
| 1183 | /// truncate of the specified operand to i8. This can be done with tablegen, |
| 1184 | /// except that this code uses MVT::Flag in a tricky way that happens to |
| 1185 | /// improve scheduling in some cases. |
| 1186 | SDNode *X86DAGToDAGISel::getTruncateTo8Bit(SDValue N0) { |
| 1187 | assert(!Subtarget->is64Bit() && |
| 1188 | "getTruncateTo8Bit is only needed on x86-32!"); |
| 1189 | SDValue SRIdx = CurDAG->getTargetConstant(1, MVT::i32); // SubRegSet 1 |
Dale Johannesen | 2dbdb0e | 2009-02-07 19:59:05 +0000 | [diff] [blame] | 1190 | DebugLoc dl = N0.getDebugLoc(); |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1191 | |
| 1192 | // Ensure that the source register has an 8-bit subreg on 32-bit targets |
| 1193 | unsigned Opc; |
| 1194 | MVT N0VT = N0.getValueType(); |
| 1195 | switch (N0VT.getSimpleVT()) { |
| 1196 | default: assert(0 && "Unknown truncate!"); |
| 1197 | case MVT::i16: |
| 1198 | Opc = X86::MOV16to16_; |
| 1199 | break; |
| 1200 | case MVT::i32: |
| 1201 | Opc = X86::MOV32to32_; |
| 1202 | break; |
| 1203 | } |
| 1204 | |
| 1205 | // The use of MVT::Flag here is not strictly accurate, but it helps |
| 1206 | // scheduling in some cases. |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1207 | N0 = SDValue(CurDAG->getTargetNode(Opc, dl, N0VT, MVT::Flag, N0), 0); |
| 1208 | return CurDAG->getTargetNode(X86::EXTRACT_SUBREG, dl, |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1209 | MVT::i8, N0, SRIdx, N0.getValue(1)); |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
Dale Johannesen | f160d80 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 1212 | SDNode *X86DAGToDAGISel::SelectAtomic64(SDNode *Node, unsigned Opc) { |
| 1213 | SDValue Chain = Node->getOperand(0); |
| 1214 | SDValue In1 = Node->getOperand(1); |
| 1215 | SDValue In2L = Node->getOperand(2); |
| 1216 | SDValue In2H = Node->getOperand(3); |
| 1217 | SDValue Tmp0, Tmp1, Tmp2, Tmp3; |
| 1218 | if (!SelectAddr(In1, In1, Tmp0, Tmp1, Tmp2, Tmp3)) |
| 1219 | return NULL; |
Dale Johannesen | 44eb537 | 2008-10-03 19:41:08 +0000 | [diff] [blame] | 1220 | SDValue LSI = Node->getOperand(4); // MemOperand |
Dale Johannesen | f160d80 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 1221 | const SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, In2L, In2H, LSI, Chain }; |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1222 | return CurDAG->getTargetNode(Opc, Node->getDebugLoc(), |
| 1223 | MVT::i32, MVT::i32, MVT::Other, Ops, 8); |
Dale Johannesen | f160d80 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 1224 | } |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 1225 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1226 | SDNode *X86DAGToDAGISel::Select(SDValue N) { |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1227 | SDNode *Node = N.getNode(); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1228 | MVT NVT = Node->getValueType(0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1229 | unsigned Opc, MOpc; |
| 1230 | unsigned Opcode = Node->getOpcode(); |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1231 | DebugLoc dl = Node->getDebugLoc(); |
| 1232 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1233 | #ifndef NDEBUG |
| 1234 | DOUT << std::string(Indent, ' ') << "Selecting: "; |
| 1235 | DEBUG(Node->dump(CurDAG)); |
| 1236 | DOUT << "\n"; |
| 1237 | Indent += 2; |
| 1238 | #endif |
| 1239 | |
Dan Gohman | bd68c79 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 1240 | if (Node->isMachineOpcode()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1241 | #ifndef NDEBUG |
| 1242 | DOUT << std::string(Indent-2, ' ') << "== "; |
| 1243 | DEBUG(Node->dump(CurDAG)); |
| 1244 | DOUT << "\n"; |
| 1245 | Indent -= 2; |
| 1246 | #endif |
| 1247 | return NULL; // Already selected. |
| 1248 | } |
| 1249 | |
| 1250 | switch (Opcode) { |
| 1251 | default: break; |
| 1252 | case X86ISD::GlobalBaseReg: |
| 1253 | return getGlobalBaseReg(); |
| 1254 | |
Dale Johannesen | f160d80 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 1255 | case X86ISD::ATOMOR64_DAG: |
| 1256 | return SelectAtomic64(Node, X86::ATOMOR6432); |
| 1257 | case X86ISD::ATOMXOR64_DAG: |
| 1258 | return SelectAtomic64(Node, X86::ATOMXOR6432); |
| 1259 | case X86ISD::ATOMADD64_DAG: |
| 1260 | return SelectAtomic64(Node, X86::ATOMADD6432); |
| 1261 | case X86ISD::ATOMSUB64_DAG: |
| 1262 | return SelectAtomic64(Node, X86::ATOMSUB6432); |
| 1263 | case X86ISD::ATOMNAND64_DAG: |
| 1264 | return SelectAtomic64(Node, X86::ATOMNAND6432); |
| 1265 | case X86ISD::ATOMAND64_DAG: |
| 1266 | return SelectAtomic64(Node, X86::ATOMAND6432); |
Dale Johannesen | 51c58ee | 2008-10-03 22:25:52 +0000 | [diff] [blame] | 1267 | case X86ISD::ATOMSWAP64_DAG: |
| 1268 | return SelectAtomic64(Node, X86::ATOMSWAP6432); |
Dale Johannesen | f160d80 | 2008-10-02 18:53:47 +0000 | [diff] [blame] | 1269 | |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1270 | case ISD::SMUL_LOHI: |
| 1271 | case ISD::UMUL_LOHI: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1272 | SDValue N0 = Node->getOperand(0); |
| 1273 | SDValue N1 = Node->getOperand(1); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1274 | |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1275 | bool isSigned = Opcode == ISD::SMUL_LOHI; |
| 1276 | if (!isSigned) |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1277 | switch (NVT.getSimpleVT()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1278 | default: assert(0 && "Unsupported VT!"); |
| 1279 | case MVT::i8: Opc = X86::MUL8r; MOpc = X86::MUL8m; break; |
| 1280 | case MVT::i16: Opc = X86::MUL16r; MOpc = X86::MUL16m; break; |
| 1281 | case MVT::i32: Opc = X86::MUL32r; MOpc = X86::MUL32m; break; |
| 1282 | case MVT::i64: Opc = X86::MUL64r; MOpc = X86::MUL64m; break; |
| 1283 | } |
| 1284 | else |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1285 | switch (NVT.getSimpleVT()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1286 | default: assert(0 && "Unsupported VT!"); |
| 1287 | case MVT::i8: Opc = X86::IMUL8r; MOpc = X86::IMUL8m; break; |
| 1288 | case MVT::i16: Opc = X86::IMUL16r; MOpc = X86::IMUL16m; break; |
| 1289 | case MVT::i32: Opc = X86::IMUL32r; MOpc = X86::IMUL32m; break; |
| 1290 | case MVT::i64: Opc = X86::IMUL64r; MOpc = X86::IMUL64m; break; |
| 1291 | } |
| 1292 | |
| 1293 | unsigned LoReg, HiReg; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1294 | switch (NVT.getSimpleVT()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1295 | default: assert(0 && "Unsupported VT!"); |
| 1296 | case MVT::i8: LoReg = X86::AL; HiReg = X86::AH; break; |
| 1297 | case MVT::i16: LoReg = X86::AX; HiReg = X86::DX; break; |
| 1298 | case MVT::i32: LoReg = X86::EAX; HiReg = X86::EDX; break; |
| 1299 | case MVT::i64: LoReg = X86::RAX; HiReg = X86::RDX; break; |
| 1300 | } |
| 1301 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1302 | SDValue Tmp0, Tmp1, Tmp2, Tmp3; |
Evan Cheng | 508fe8b | 2007-08-02 05:48:35 +0000 | [diff] [blame] | 1303 | bool foldedLoad = TryFoldLoad(N, N1, Tmp0, Tmp1, Tmp2, Tmp3); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1304 | // multiplty is commmutative |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1305 | if (!foldedLoad) { |
| 1306 | foldedLoad = TryFoldLoad(N, N0, Tmp0, Tmp1, Tmp2, Tmp3); |
Evan Cheng | 508fe8b | 2007-08-02 05:48:35 +0000 | [diff] [blame] | 1307 | if (foldedLoad) |
| 1308 | std::swap(N0, N1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
Dale Johannesen | bbd9ceb | 2009-02-04 00:33:20 +0000 | [diff] [blame] | 1311 | SDValue InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, LoReg, |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1312 | N0, SDValue()).getValue(1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1313 | |
| 1314 | if (foldedLoad) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1315 | SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, N1.getOperand(0), InFlag }; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1316 | SDNode *CNode = |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1317 | CurDAG->getTargetNode(MOpc, dl, MVT::Other, MVT::Flag, Ops, 6); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1318 | InFlag = SDValue(CNode, 1); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1319 | // Update the chain. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1320 | ReplaceUses(N1.getValue(1), SDValue(CNode, 0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1321 | } else { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1322 | InFlag = |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1323 | SDValue(CurDAG->getTargetNode(Opc, dl, MVT::Flag, N1, InFlag), 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1326 | // Copy the low half of the result, if it is needed. |
| 1327 | if (!N.getValue(0).use_empty()) { |
Dale Johannesen | bbd9ceb | 2009-02-04 00:33:20 +0000 | [diff] [blame] | 1328 | SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1329 | LoReg, NVT, InFlag); |
| 1330 | InFlag = Result.getValue(2); |
| 1331 | ReplaceUses(N.getValue(0), Result); |
| 1332 | #ifndef NDEBUG |
| 1333 | DOUT << std::string(Indent-2, ' ') << "=> "; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1334 | DEBUG(Result.getNode()->dump(CurDAG)); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1335 | DOUT << "\n"; |
| 1336 | #endif |
Evan Cheng | 6f0f0dd | 2007-08-09 21:59:35 +0000 | [diff] [blame] | 1337 | } |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1338 | // Copy the high half of the result, if it is needed. |
| 1339 | if (!N.getValue(1).use_empty()) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1340 | SDValue Result; |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1341 | if (HiReg == X86::AH && Subtarget->is64Bit()) { |
| 1342 | // Prevent use of AH in a REX instruction by referencing AX instead. |
| 1343 | // Shift it down 8 bits. |
Dale Johannesen | bbd9ceb | 2009-02-04 00:33:20 +0000 | [diff] [blame] | 1344 | Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1345 | X86::AX, MVT::i16, InFlag); |
| 1346 | InFlag = Result.getValue(2); |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1347 | Result = SDValue(CurDAG->getTargetNode(X86::SHR16ri, dl, MVT::i16, |
| 1348 | Result, |
Gabor Greif | e9f7f58 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 1349 | CurDAG->getTargetConstant(8, MVT::i8)), 0); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1350 | // Then truncate it down to i8. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1351 | SDValue SRIdx = CurDAG->getTargetConstant(1, MVT::i32); // SubRegSet 1 |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1352 | Result = SDValue(CurDAG->getTargetNode(X86::EXTRACT_SUBREG, dl, |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1353 | MVT::i8, Result, SRIdx), 0); |
| 1354 | } else { |
Dale Johannesen | bbd9ceb | 2009-02-04 00:33:20 +0000 | [diff] [blame] | 1355 | Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1356 | HiReg, NVT, InFlag); |
| 1357 | InFlag = Result.getValue(2); |
| 1358 | } |
| 1359 | ReplaceUses(N.getValue(1), Result); |
| 1360 | #ifndef NDEBUG |
| 1361 | DOUT << std::string(Indent-2, ' ') << "=> "; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1362 | DEBUG(Result.getNode()->dump(CurDAG)); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1363 | DOUT << "\n"; |
| 1364 | #endif |
| 1365 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1366 | |
| 1367 | #ifndef NDEBUG |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1368 | Indent -= 2; |
| 1369 | #endif |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1370 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1371 | return NULL; |
| 1372 | } |
| 1373 | |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1374 | case ISD::SDIVREM: |
| 1375 | case ISD::UDIVREM: { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1376 | SDValue N0 = Node->getOperand(0); |
| 1377 | SDValue N1 = Node->getOperand(1); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1378 | |
| 1379 | bool isSigned = Opcode == ISD::SDIVREM; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1380 | if (!isSigned) |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1381 | switch (NVT.getSimpleVT()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1382 | default: assert(0 && "Unsupported VT!"); |
| 1383 | case MVT::i8: Opc = X86::DIV8r; MOpc = X86::DIV8m; break; |
| 1384 | case MVT::i16: Opc = X86::DIV16r; MOpc = X86::DIV16m; break; |
| 1385 | case MVT::i32: Opc = X86::DIV32r; MOpc = X86::DIV32m; break; |
| 1386 | case MVT::i64: Opc = X86::DIV64r; MOpc = X86::DIV64m; break; |
| 1387 | } |
| 1388 | else |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1389 | switch (NVT.getSimpleVT()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1390 | default: assert(0 && "Unsupported VT!"); |
| 1391 | case MVT::i8: Opc = X86::IDIV8r; MOpc = X86::IDIV8m; break; |
| 1392 | case MVT::i16: Opc = X86::IDIV16r; MOpc = X86::IDIV16m; break; |
| 1393 | case MVT::i32: Opc = X86::IDIV32r; MOpc = X86::IDIV32m; break; |
| 1394 | case MVT::i64: Opc = X86::IDIV64r; MOpc = X86::IDIV64m; break; |
| 1395 | } |
| 1396 | |
| 1397 | unsigned LoReg, HiReg; |
| 1398 | unsigned ClrOpcode, SExtOpcode; |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1399 | switch (NVT.getSimpleVT()) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1400 | default: assert(0 && "Unsupported VT!"); |
| 1401 | case MVT::i8: |
| 1402 | LoReg = X86::AL; HiReg = X86::AH; |
| 1403 | ClrOpcode = 0; |
| 1404 | SExtOpcode = X86::CBW; |
| 1405 | break; |
| 1406 | case MVT::i16: |
| 1407 | LoReg = X86::AX; HiReg = X86::DX; |
| 1408 | ClrOpcode = X86::MOV16r0; |
| 1409 | SExtOpcode = X86::CWD; |
| 1410 | break; |
| 1411 | case MVT::i32: |
| 1412 | LoReg = X86::EAX; HiReg = X86::EDX; |
| 1413 | ClrOpcode = X86::MOV32r0; |
| 1414 | SExtOpcode = X86::CDQ; |
| 1415 | break; |
| 1416 | case MVT::i64: |
| 1417 | LoReg = X86::RAX; HiReg = X86::RDX; |
| 1418 | ClrOpcode = X86::MOV64r0; |
| 1419 | SExtOpcode = X86::CQO; |
| 1420 | break; |
| 1421 | } |
| 1422 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1423 | SDValue Tmp0, Tmp1, Tmp2, Tmp3; |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1424 | bool foldedLoad = TryFoldLoad(N, N1, Tmp0, Tmp1, Tmp2, Tmp3); |
Dan Gohman | 7bbd920 | 2009-01-21 14:50:16 +0000 | [diff] [blame] | 1425 | bool signBitIsZero = CurDAG->SignBitIsZero(N0); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1426 | |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1427 | SDValue InFlag; |
Dan Gohman | 7bbd920 | 2009-01-21 14:50:16 +0000 | [diff] [blame] | 1428 | if (NVT == MVT::i8 && (!isSigned || signBitIsZero)) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1429 | // Special case for div8, just use a move with zero extension to AX to |
| 1430 | // clear the upper 8 bits (AH). |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1431 | SDValue Tmp0, Tmp1, Tmp2, Tmp3, Move, Chain; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1432 | if (TryFoldLoad(N, N0, Tmp0, Tmp1, Tmp2, Tmp3)) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1433 | SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, N0.getOperand(0) }; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1434 | Move = |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1435 | SDValue(CurDAG->getTargetNode(X86::MOVZX16rm8, dl, MVT::i16, |
| 1436 | MVT::Other, Ops, 5), 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1437 | Chain = Move.getValue(1); |
| 1438 | ReplaceUses(N0.getValue(1), Chain); |
| 1439 | } else { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1440 | Move = |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1441 | SDValue(CurDAG->getTargetNode(X86::MOVZX16rr8, dl, MVT::i16, N0),0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1442 | Chain = CurDAG->getEntryNode(); |
| 1443 | } |
Dale Johannesen | bbd9ceb | 2009-02-04 00:33:20 +0000 | [diff] [blame] | 1444 | Chain = CurDAG->getCopyToReg(Chain, dl, X86::AX, Move, SDValue()); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1445 | InFlag = Chain.getValue(1); |
| 1446 | } else { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1447 | InFlag = |
Dale Johannesen | bbd9ceb | 2009-02-04 00:33:20 +0000 | [diff] [blame] | 1448 | CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1449 | LoReg, N0, SDValue()).getValue(1); |
Dan Gohman | 7bbd920 | 2009-01-21 14:50:16 +0000 | [diff] [blame] | 1450 | if (isSigned && !signBitIsZero) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1451 | // Sign extend the low part into the high part. |
| 1452 | InFlag = |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1453 | SDValue(CurDAG->getTargetNode(SExtOpcode, dl, MVT::Flag, InFlag),0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1454 | } else { |
| 1455 | // Zero out the high part, effectively zero extending the input. |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1456 | SDValue ClrNode = SDValue(CurDAG->getTargetNode(ClrOpcode, dl, NVT), |
| 1457 | 0); |
Dale Johannesen | bbd9ceb | 2009-02-04 00:33:20 +0000 | [diff] [blame] | 1458 | InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, HiReg, |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1459 | ClrNode, InFlag).getValue(1); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1460 | } |
| 1461 | } |
| 1462 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1463 | if (foldedLoad) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1464 | SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, N1.getOperand(0), InFlag }; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1465 | SDNode *CNode = |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1466 | CurDAG->getTargetNode(MOpc, dl, MVT::Other, MVT::Flag, Ops, 6); |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1467 | InFlag = SDValue(CNode, 1); |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1468 | // Update the chain. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1469 | ReplaceUses(N1.getValue(1), SDValue(CNode, 0)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1470 | } else { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1471 | InFlag = |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1472 | SDValue(CurDAG->getTargetNode(Opc, dl, MVT::Flag, N1, InFlag), 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1473 | } |
| 1474 | |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1475 | // Copy the division (low) result, if it is needed. |
| 1476 | if (!N.getValue(0).use_empty()) { |
Dale Johannesen | bbd9ceb | 2009-02-04 00:33:20 +0000 | [diff] [blame] | 1477 | SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1478 | LoReg, NVT, InFlag); |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1479 | InFlag = Result.getValue(2); |
| 1480 | ReplaceUses(N.getValue(0), Result); |
| 1481 | #ifndef NDEBUG |
| 1482 | DOUT << std::string(Indent-2, ' ') << "=> "; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1483 | DEBUG(Result.getNode()->dump(CurDAG)); |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1484 | DOUT << "\n"; |
| 1485 | #endif |
Evan Cheng | 6f0f0dd | 2007-08-09 21:59:35 +0000 | [diff] [blame] | 1486 | } |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1487 | // Copy the remainder (high) result, if it is needed. |
| 1488 | if (!N.getValue(1).use_empty()) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1489 | SDValue Result; |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1490 | if (HiReg == X86::AH && Subtarget->is64Bit()) { |
| 1491 | // Prevent use of AH in a REX instruction by referencing AX instead. |
| 1492 | // Shift it down 8 bits. |
Dale Johannesen | bbd9ceb | 2009-02-04 00:33:20 +0000 | [diff] [blame] | 1493 | Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1494 | X86::AX, MVT::i16, InFlag); |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1495 | InFlag = Result.getValue(2); |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1496 | Result = SDValue(CurDAG->getTargetNode(X86::SHR16ri, dl, MVT::i16, |
| 1497 | Result, |
| 1498 | CurDAG->getTargetConstant(8, MVT::i8)), |
| 1499 | 0); |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1500 | // Then truncate it down to i8. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1501 | SDValue SRIdx = CurDAG->getTargetConstant(1, MVT::i32); // SubRegSet 1 |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1502 | Result = SDValue(CurDAG->getTargetNode(X86::EXTRACT_SUBREG, dl, |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1503 | MVT::i8, Result, SRIdx), 0); |
| 1504 | } else { |
Dale Johannesen | bbd9ceb | 2009-02-04 00:33:20 +0000 | [diff] [blame] | 1505 | Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, |
Dan Gohman | 5a19955 | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1506 | HiReg, NVT, InFlag); |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1507 | InFlag = Result.getValue(2); |
| 1508 | } |
| 1509 | ReplaceUses(N.getValue(1), Result); |
| 1510 | #ifndef NDEBUG |
| 1511 | DOUT << std::string(Indent-2, ' ') << "=> "; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1512 | DEBUG(Result.getNode()->dump(CurDAG)); |
Dan Gohman | 242a5ba | 2007-09-25 18:23:27 +0000 | [diff] [blame] | 1513 | DOUT << "\n"; |
| 1514 | #endif |
| 1515 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1516 | |
| 1517 | #ifndef NDEBUG |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1518 | Indent -= 2; |
| 1519 | #endif |
| 1520 | |
| 1521 | return NULL; |
| 1522 | } |
Christopher Lamb | 422213d | 2007-08-10 22:22:41 +0000 | [diff] [blame] | 1523 | |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 1524 | case ISD::SIGN_EXTEND_INREG: { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1525 | MVT SVT = cast<VTSDNode>(Node->getOperand(1))->getVT(); |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1526 | if (SVT == MVT::i8 && !Subtarget->is64Bit()) { |
| 1527 | SDValue N0 = Node->getOperand(0); |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 1528 | |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1529 | SDValue TruncOp = SDValue(getTruncateTo8Bit(N0), 0); |
| 1530 | unsigned Opc = 0; |
| 1531 | switch (NVT.getSimpleVT()) { |
| 1532 | default: assert(0 && "Unknown sign_extend_inreg!"); |
| 1533 | case MVT::i16: |
| 1534 | Opc = X86::MOVSX16rr8; |
| 1535 | break; |
| 1536 | case MVT::i32: |
| 1537 | Opc = X86::MOVSX32rr8; |
| 1538 | break; |
| 1539 | } |
| 1540 | |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1541 | SDNode *ResNode = CurDAG->getTargetNode(Opc, dl, NVT, TruncOp); |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 1542 | |
| 1543 | #ifndef NDEBUG |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1544 | DOUT << std::string(Indent-2, ' ') << "=> "; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1545 | DEBUG(TruncOp.getNode()->dump(CurDAG)); |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1546 | DOUT << "\n"; |
| 1547 | DOUT << std::string(Indent-2, ' ') << "=> "; |
| 1548 | DEBUG(ResNode->dump(CurDAG)); |
| 1549 | DOUT << "\n"; |
| 1550 | Indent -= 2; |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 1551 | #endif |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1552 | return ResNode; |
| 1553 | } |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 1554 | break; |
| 1555 | } |
| 1556 | |
| 1557 | case ISD::TRUNCATE: { |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1558 | if (NVT == MVT::i8 && !Subtarget->is64Bit()) { |
| 1559 | SDValue Input = Node->getOperand(0); |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1560 | SDNode *ResNode = getTruncateTo8Bit(Input); |
Christopher Lamb | 0a7c866 | 2007-08-10 21:48:46 +0000 | [diff] [blame] | 1561 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1562 | #ifndef NDEBUG |
| 1563 | DOUT << std::string(Indent-2, ' ') << "=> "; |
| 1564 | DEBUG(ResNode->dump(CurDAG)); |
| 1565 | DOUT << "\n"; |
| 1566 | Indent -= 2; |
| 1567 | #endif |
Dan Gohman | dd612bb | 2008-08-20 21:27:32 +0000 | [diff] [blame] | 1568 | return ResNode; |
| 1569 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1570 | break; |
| 1571 | } |
Evan Cheng | d4cebcd | 2008-06-17 02:01:22 +0000 | [diff] [blame] | 1572 | |
| 1573 | case ISD::DECLARE: { |
| 1574 | // Handle DECLARE nodes here because the second operand may have been |
| 1575 | // wrapped in X86ISD::Wrapper. |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1576 | SDValue Chain = Node->getOperand(0); |
| 1577 | SDValue N1 = Node->getOperand(1); |
| 1578 | SDValue N2 = Node->getOperand(2); |
Evan Cheng | 417bc00 | 2008-12-10 21:49:05 +0000 | [diff] [blame] | 1579 | FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(N1); |
Chris Lattner | ef6a819 | 2009-02-12 17:33:11 +0000 | [diff] [blame] | 1580 | |
| 1581 | // FIXME: We need to handle this for VLAs. |
| 1582 | if (!FINode) { |
| 1583 | ReplaceUses(N.getValue(0), Chain); |
| 1584 | return NULL; |
| 1585 | } |
| 1586 | |
Evan Cheng | 651e144 | 2008-06-18 02:48:27 +0000 | [diff] [blame] | 1587 | if (N2.getOpcode() == ISD::ADD && |
| 1588 | N2.getOperand(0).getOpcode() == X86ISD::GlobalBaseReg) |
| 1589 | N2 = N2.getOperand(1); |
Chris Lattner | ef6a819 | 2009-02-12 17:33:11 +0000 | [diff] [blame] | 1590 | |
| 1591 | // If N2 is not Wrapper(decriptor) then the llvm.declare is mangled |
| 1592 | // somehow, just ignore it. |
| 1593 | if (N2.getOpcode() != X86ISD::Wrapper) { |
| 1594 | ReplaceUses(N.getValue(0), Chain); |
| 1595 | return NULL; |
| 1596 | } |
Evan Cheng | f3ecd1a | 2009-01-10 03:33:22 +0000 | [diff] [blame] | 1597 | GlobalAddressSDNode *GVNode = |
| 1598 | dyn_cast<GlobalAddressSDNode>(N2.getOperand(0)); |
Chris Lattner | ef6a819 | 2009-02-12 17:33:11 +0000 | [diff] [blame] | 1599 | if (GVNode == 0) { |
| 1600 | ReplaceUses(N.getValue(0), Chain); |
| 1601 | return NULL; |
| 1602 | } |
Evan Cheng | 417bc00 | 2008-12-10 21:49:05 +0000 | [diff] [blame] | 1603 | SDValue Tmp1 = CurDAG->getTargetFrameIndex(FINode->getIndex(), |
| 1604 | TLI.getPointerTy()); |
| 1605 | SDValue Tmp2 = CurDAG->getTargetGlobalAddress(GVNode->getGlobal(), |
| 1606 | TLI.getPointerTy()); |
| 1607 | SDValue Ops[] = { Tmp1, Tmp2, Chain }; |
Dale Johannesen | 59b5a5c | 2009-02-03 21:48:12 +0000 | [diff] [blame] | 1608 | return CurDAG->getTargetNode(TargetInstrInfo::DECLARE, dl, |
Evan Cheng | 417bc00 | 2008-12-10 21:49:05 +0000 | [diff] [blame] | 1609 | MVT::Other, Ops, 3); |
Evan Cheng | d4cebcd | 2008-06-17 02:01:22 +0000 | [diff] [blame] | 1610 | } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | SDNode *ResNode = SelectCode(N); |
| 1614 | |
| 1615 | #ifndef NDEBUG |
| 1616 | DOUT << std::string(Indent-2, ' ') << "=> "; |
Gabor Greif | 1c80d11 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1617 | if (ResNode == NULL || ResNode == N.getNode()) |
| 1618 | DEBUG(N.getNode()->dump(CurDAG)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1619 | else |
| 1620 | DEBUG(ResNode->dump(CurDAG)); |
| 1621 | DOUT << "\n"; |
| 1622 | Indent -= 2; |
| 1623 | #endif |
| 1624 | |
| 1625 | return ResNode; |
| 1626 | } |
| 1627 | |
| 1628 | bool X86DAGToDAGISel:: |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1629 | SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode, |
Dan Gohman | 14a6644 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 1630 | std::vector<SDValue> &OutOps) { |
Dan Gohman | 8181bd1 | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1631 | SDValue Op0, Op1, Op2, Op3; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1632 | switch (ConstraintCode) { |
| 1633 | case 'o': // offsetable ?? |
| 1634 | case 'v': // not offsetable ?? |
| 1635 | default: return true; |
| 1636 | case 'm': // memory |
| 1637 | if (!SelectAddr(Op, Op, Op0, Op1, Op2, Op3)) |
| 1638 | return true; |
| 1639 | break; |
| 1640 | } |
| 1641 | |
| 1642 | OutOps.push_back(Op0); |
| 1643 | OutOps.push_back(Op1); |
| 1644 | OutOps.push_back(Op2); |
| 1645 | OutOps.push_back(Op3); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1646 | return false; |
| 1647 | } |
| 1648 | |
| 1649 | /// createX86ISelDag - This pass converts a legalized DAG into a |
| 1650 | /// X86-specific DAG, ready for instruction scheduling. |
| 1651 | /// |
| 1652 | FunctionPass *llvm::createX86ISelDag(X86TargetMachine &TM, bool Fast) { |
| 1653 | return new X86DAGToDAGISel(TM, Fast); |
| 1654 | } |