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