Dan Gohman | 9becddd | 2010-04-16 23:04:22 +0000 | [diff] [blame] | 1 | //===-- X86SelectionDAGInfo.cpp - X86 SelectionDAG Info -------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the X86SelectionDAGInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 14 | #include "X86SelectionDAGInfo.h" |
Eric Christopher | e5add68 | 2014-06-06 23:26:43 +0000 | [diff] [blame] | 15 | #include "X86ISelLowering.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 16 | #include "X86InstrInfo.h" |
Eric Christopher | e5add68 | 2014-06-06 23:26:43 +0000 | [diff] [blame] | 17 | #include "X86RegisterInfo.h" |
| 18 | #include "X86Subtarget.h" |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/SelectionDAG.h" |
David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/TargetLowering.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 21 | #include "llvm/IR/DerivedTypes.h" |
Eric Christopher | e5add68 | 2014-06-06 23:26:43 +0000 | [diff] [blame] | 22 | |
Dan Gohman | 9becddd | 2010-04-16 23:04:22 +0000 | [diff] [blame] | 23 | using namespace llvm; |
| 24 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 25 | #define DEBUG_TYPE "x86-selectiondag-info" |
| 26 | |
Reid Kleckner | ab99e24 | 2014-08-29 20:50:31 +0000 | [diff] [blame] | 27 | bool X86SelectionDAGInfo::isBaseRegConflictPossible( |
Craig Topper | cf65c62 | 2016-03-02 04:42:31 +0000 | [diff] [blame] | 28 | SelectionDAG &DAG, ArrayRef<MCPhysReg> ClobberSet) const { |
Reid Kleckner | ab99e24 | 2014-08-29 20:50:31 +0000 | [diff] [blame] | 29 | // We cannot use TRI->hasBasePointer() until *after* we select all basic |
| 30 | // blocks. Legalization may introduce new stack temporaries with large |
| 31 | // alignment requirements. Fall back to generic code if there are any |
| 32 | // dynamic stack adjustments (hopefully rare) and the base pointer would |
| 33 | // conflict if we had to use it. |
Matthias Braun | 941a705 | 2016-07-28 18:40:00 +0000 | [diff] [blame] | 34 | MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo(); |
| 35 | if (!MFI.hasVarSizedObjects() && !MFI.hasOpaqueSPAdjustment()) |
Reid Kleckner | ab99e24 | 2014-08-29 20:50:31 +0000 | [diff] [blame] | 36 | return false; |
| 37 | |
| 38 | const X86RegisterInfo *TRI = static_cast<const X86RegisterInfo *>( |
| 39 | DAG.getSubtarget().getRegisterInfo()); |
| 40 | unsigned BaseReg = TRI->getBaseRegister(); |
| 41 | for (unsigned R : ClobberSet) |
| 42 | if (BaseReg == R) |
| 43 | return true; |
| 44 | return false; |
| 45 | } |
| 46 | |
Clement Courbet | 5f0ab9e | 2017-04-28 07:56:31 +0000 | [diff] [blame] | 47 | namespace { |
| 48 | |
| 49 | // Represents a cover of a buffer of Size bytes with Count() blocks of type AVT |
| 50 | // (of size UBytes() bytes), as well as how many bytes remain (BytesLeft() is |
| 51 | // always smaller than the block size). |
| 52 | struct RepMovsRepeats { |
| 53 | RepMovsRepeats(uint64_t Size) : Size(Size) {} |
| 54 | |
| 55 | uint64_t Count() const { return Size / UBytes(); } |
| 56 | uint64_t BytesLeft() const { return Size % UBytes(); } |
| 57 | uint64_t UBytes() const { return AVT.getSizeInBits() / 8; } |
| 58 | |
| 59 | const uint64_t Size; |
| 60 | MVT AVT = MVT::i8; |
| 61 | }; |
| 62 | |
| 63 | } // namespace |
| 64 | |
Sanjay Patel | 1640c54 | 2015-12-04 17:51:55 +0000 | [diff] [blame] | 65 | SDValue X86SelectionDAGInfo::EmitTargetCodeForMemset( |
Clement Courbet | 7b0ec39 | 2017-04-27 07:22:30 +0000 | [diff] [blame] | 66 | SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Val, |
Sanjay Patel | 1640c54 | 2015-12-04 17:51:55 +0000 | [diff] [blame] | 67 | SDValue Size, unsigned Align, bool isVolatile, |
| 68 | MachinePointerInfo DstPtrInfo) const { |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 69 | ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size); |
Eric Christopher | 05b8197 | 2015-02-02 17:38:43 +0000 | [diff] [blame] | 70 | const X86Subtarget &Subtarget = |
| 71 | DAG.getMachineFunction().getSubtarget<X86Subtarget>(); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 72 | |
Reid Kleckner | ab99e24 | 2014-08-29 20:50:31 +0000 | [diff] [blame] | 73 | #ifndef NDEBUG |
| 74 | // If the base register might conflict with our physical registers, bail out. |
Craig Topper | cf65c62 | 2016-03-02 04:42:31 +0000 | [diff] [blame] | 75 | const MCPhysReg ClobberSet[] = {X86::RCX, X86::RAX, X86::RDI, |
| 76 | X86::ECX, X86::EAX, X86::EDI}; |
Reid Kleckner | ab99e24 | 2014-08-29 20:50:31 +0000 | [diff] [blame] | 77 | assert(!isBaseRegConflictPossible(DAG, ClobberSet)); |
| 78 | #endif |
| 79 | |
Chris Lattner | 4470c2b | 2010-09-21 05:43:34 +0000 | [diff] [blame] | 80 | // If to a segment-relative address space, use the default lowering. |
| 81 | if (DstPtrInfo.getAddrSpace() >= 256) |
| 82 | return SDValue(); |
Chad Rosier | 24c19d2 | 2012-08-01 18:39:17 +0000 | [diff] [blame] | 83 | |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 84 | // If not DWORD aligned or size is more than the threshold, call the library. |
| 85 | // The libc version is likely to be faster for these cases. It can use the |
| 86 | // address value and run time information about the CPU. |
Eric Christopher | e5add68 | 2014-06-06 23:26:43 +0000 | [diff] [blame] | 87 | if ((Align & 3) != 0 || !ConstantSize || |
| 88 | ConstantSize->getZExtValue() > Subtarget.getMaxInlineSizeThreshold()) { |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 89 | // Check to see if there is a specialized entry-point for memory zeroing. |
Clement Courbet | 7b0ec39 | 2017-04-27 07:22:30 +0000 | [diff] [blame] | 90 | ConstantSDNode *ValC = dyn_cast<ConstantSDNode>(Val); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 91 | |
Matthias Braun | a92cecf | 2017-12-18 23:14:28 +0000 | [diff] [blame] | 92 | if (const char *bzeroName = (ValC && ValC->isNullValue()) |
| 93 | ? DAG.getTargetLoweringInfo().getLibcallName(RTLIB::BZERO) |
| 94 | : nullptr) { |
Sanjay Patel | 1640c54 | 2015-12-04 17:51:55 +0000 | [diff] [blame] | 95 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 96 | EVT IntPtr = TLI.getPointerTy(DAG.getDataLayout()); |
Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 97 | Type *IntPtrTy = DAG.getDataLayout().getIntPtrType(*DAG.getContext()); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 98 | TargetLowering::ArgListTy Args; |
| 99 | TargetLowering::ArgListEntry Entry; |
| 100 | Entry.Node = Dst; |
| 101 | Entry.Ty = IntPtrTy; |
| 102 | Args.push_back(Entry); |
| 103 | Entry.Node = Size; |
| 104 | Args.push_back(Entry); |
Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 105 | |
| 106 | TargetLowering::CallLoweringInfo CLI(DAG); |
Nirav Dave | 6de2c77 | 2017-03-18 00:43:57 +0000 | [diff] [blame] | 107 | CLI.setDebugLoc(dl) |
| 108 | .setChain(Chain) |
Nirav Dave | ac6081c | 2017-03-18 00:44:07 +0000 | [diff] [blame] | 109 | .setLibCallee(CallingConv::C, Type::getVoidTy(*DAG.getContext()), |
Matthias Braun | a92cecf | 2017-12-18 23:14:28 +0000 | [diff] [blame] | 110 | DAG.getExternalSymbol(bzeroName, IntPtr), |
Nirav Dave | ac6081c | 2017-03-18 00:44:07 +0000 | [diff] [blame] | 111 | std::move(Args)) |
Nirav Dave | 6de2c77 | 2017-03-18 00:43:57 +0000 | [diff] [blame] | 112 | .setDiscardResult(); |
Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 113 | |
Sanjay Patel | 1640c54 | 2015-12-04 17:51:55 +0000 | [diff] [blame] | 114 | std::pair<SDValue,SDValue> CallResult = TLI.LowerCallTo(CLI); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 115 | return CallResult.second; |
| 116 | } |
| 117 | |
| 118 | // Otherwise have the target-independent code call memset. |
| 119 | return SDValue(); |
| 120 | } |
| 121 | |
| 122 | uint64_t SizeVal = ConstantSize->getZExtValue(); |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 123 | SDValue InFlag; |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 124 | EVT AVT; |
| 125 | SDValue Count; |
Clement Courbet | 7b0ec39 | 2017-04-27 07:22:30 +0000 | [diff] [blame] | 126 | ConstantSDNode *ValC = dyn_cast<ConstantSDNode>(Val); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 127 | unsigned BytesLeft = 0; |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 128 | if (ValC) { |
| 129 | unsigned ValReg; |
| 130 | uint64_t Val = ValC->getZExtValue() & 255; |
| 131 | |
| 132 | // If the value is a constant, then we can potentially use larger sets. |
| 133 | switch (Align & 3) { |
| 134 | case 2: // WORD aligned |
| 135 | AVT = MVT::i16; |
| 136 | ValReg = X86::AX; |
| 137 | Val = (Val << 8) | Val; |
| 138 | break; |
| 139 | case 0: // DWORD aligned |
| 140 | AVT = MVT::i32; |
| 141 | ValReg = X86::EAX; |
| 142 | Val = (Val << 8) | Val; |
| 143 | Val = (Val << 16) | Val; |
Eric Christopher | e5add68 | 2014-06-06 23:26:43 +0000 | [diff] [blame] | 144 | if (Subtarget.is64Bit() && ((Align & 0x7) == 0)) { // QWORD aligned |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 145 | AVT = MVT::i64; |
| 146 | ValReg = X86::RAX; |
| 147 | Val = (Val << 32) | Val; |
| 148 | } |
| 149 | break; |
| 150 | default: // Byte aligned |
| 151 | AVT = MVT::i8; |
| 152 | ValReg = X86::AL; |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 153 | Count = DAG.getIntPtrConstant(SizeVal, dl); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 154 | break; |
| 155 | } |
| 156 | |
| 157 | if (AVT.bitsGT(MVT::i8)) { |
| 158 | unsigned UBytes = AVT.getSizeInBits() / 8; |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 159 | Count = DAG.getIntPtrConstant(SizeVal / UBytes, dl); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 160 | BytesLeft = SizeVal % UBytes; |
| 161 | } |
| 162 | |
Sanjay Patel | 1640c54 | 2015-12-04 17:51:55 +0000 | [diff] [blame] | 163 | Chain = DAG.getCopyToReg(Chain, dl, ValReg, DAG.getConstant(Val, dl, AVT), |
| 164 | InFlag); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 165 | InFlag = Chain.getValue(1); |
| 166 | } else { |
| 167 | AVT = MVT::i8; |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 168 | Count = DAG.getIntPtrConstant(SizeVal, dl); |
Clement Courbet | 7b0ec39 | 2017-04-27 07:22:30 +0000 | [diff] [blame] | 169 | Chain = DAG.getCopyToReg(Chain, dl, X86::AL, Val, InFlag); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 170 | InFlag = Chain.getValue(1); |
| 171 | } |
| 172 | |
Eric Christopher | e5add68 | 2014-06-06 23:26:43 +0000 | [diff] [blame] | 173 | Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RCX : X86::ECX, |
| 174 | Count, InFlag); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 175 | InFlag = Chain.getValue(1); |
Eric Christopher | e5add68 | 2014-06-06 23:26:43 +0000 | [diff] [blame] | 176 | Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RDI : X86::EDI, |
| 177 | Dst, InFlag); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 178 | InFlag = Chain.getValue(1); |
| 179 | |
Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 180 | SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Glue); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 181 | SDValue Ops[] = { Chain, DAG.getValueType(AVT), InFlag }; |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 182 | Chain = DAG.getNode(X86ISD::REP_STOS, dl, Tys, Ops); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 183 | |
Clement Courbet | 8177fee | 2017-04-21 07:40:59 +0000 | [diff] [blame] | 184 | if (BytesLeft) { |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 185 | // Handle the last 1 - 7 bytes. |
| 186 | unsigned Offset = SizeVal - BytesLeft; |
| 187 | EVT AddrVT = Dst.getValueType(); |
| 188 | EVT SizeVT = Size.getValueType(); |
| 189 | |
| 190 | Chain = DAG.getMemset(Chain, dl, |
| 191 | DAG.getNode(ISD::ADD, dl, AddrVT, Dst, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 192 | DAG.getConstant(Offset, dl, AddrVT)), |
Clement Courbet | 7b0ec39 | 2017-04-27 07:22:30 +0000 | [diff] [blame] | 193 | Val, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 194 | DAG.getConstant(BytesLeft, dl, SizeVT), |
Krzysztof Parzyszek | a46c36b | 2015-04-13 17:16:45 +0000 | [diff] [blame] | 195 | Align, isVolatile, false, |
| 196 | DstPtrInfo.getWithOffset(Offset)); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | // TODO: Use a Tokenfactor, as in memcpy, instead of a single chain. |
| 200 | return Chain; |
| 201 | } |
| 202 | |
Eric Christopher | 05b8197 | 2015-02-02 17:38:43 +0000 | [diff] [blame] | 203 | SDValue X86SelectionDAGInfo::EmitTargetCodeForMemcpy( |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 204 | SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src, |
Eric Christopher | 05b8197 | 2015-02-02 17:38:43 +0000 | [diff] [blame] | 205 | SDValue Size, unsigned Align, bool isVolatile, bool AlwaysInline, |
| 206 | MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const { |
Chris Lattner | 0ab5e2c | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 207 | // This requires the copy size to be a constant, preferably |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 208 | // within a subtarget-specific limit. |
| 209 | ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size); |
Eric Christopher | 05b8197 | 2015-02-02 17:38:43 +0000 | [diff] [blame] | 210 | const X86Subtarget &Subtarget = |
| 211 | DAG.getMachineFunction().getSubtarget<X86Subtarget>(); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 212 | if (!ConstantSize) |
| 213 | return SDValue(); |
Clement Courbet | 5f0ab9e | 2017-04-28 07:56:31 +0000 | [diff] [blame] | 214 | RepMovsRepeats Repeats(ConstantSize->getZExtValue()); |
| 215 | if (!AlwaysInline && Repeats.Size > Subtarget.getMaxInlineSizeThreshold()) |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 216 | return SDValue(); |
| 217 | |
Duncan Sands | 9851231 | 2010-11-04 21:16:46 +0000 | [diff] [blame] | 218 | /// If not DWORD aligned, it is more efficient to call the library. However |
| 219 | /// if calling the library is not allowed (AlwaysInline), then soldier on as |
| 220 | /// the code generated here is better than the long load-store sequence we |
| 221 | /// would otherwise get. |
| 222 | if (!AlwaysInline && (Align & 3) != 0) |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 223 | return SDValue(); |
| 224 | |
Chris Lattner | 4470c2b | 2010-09-21 05:43:34 +0000 | [diff] [blame] | 225 | // If to a segment-relative address space, use the default lowering. |
| 226 | if (DstPtrInfo.getAddrSpace() >= 256 || |
| 227 | SrcPtrInfo.getAddrSpace() >= 256) |
| 228 | return SDValue(); |
Duncan Sands | 9851231 | 2010-11-04 21:16:46 +0000 | [diff] [blame] | 229 | |
Reid Kleckner | ab99e24 | 2014-08-29 20:50:31 +0000 | [diff] [blame] | 230 | // If the base register might conflict with our physical registers, bail out. |
Craig Topper | cf65c62 | 2016-03-02 04:42:31 +0000 | [diff] [blame] | 231 | const MCPhysReg ClobberSet[] = {X86::RCX, X86::RSI, X86::RDI, |
| 232 | X86::ECX, X86::ESI, X86::EDI}; |
Reid Kleckner | ab99e24 | 2014-08-29 20:50:31 +0000 | [diff] [blame] | 233 | if (isBaseRegConflictPossible(DAG, ClobberSet)) |
Hans Wennborg | d683a22 | 2014-03-26 16:30:54 +0000 | [diff] [blame] | 234 | return SDValue(); |
Benjamin Kramer | 8e2637e | 2013-02-13 13:40:35 +0000 | [diff] [blame] | 235 | |
Clement Courbet | 5f0ab9e | 2017-04-28 07:56:31 +0000 | [diff] [blame] | 236 | // If the target has enhanced REPMOVSB, then it's at least as fast to use |
| 237 | // REP MOVSB instead of REP MOVS{W,D,Q}, and it avoids having to handle |
| 238 | // BytesLeft. |
| 239 | if (!Subtarget.hasERMSB() && !(Align & 1)) { |
| 240 | if (Align & 2) |
| 241 | // WORD aligned |
| 242 | Repeats.AVT = MVT::i16; |
| 243 | else if (Align & 4) |
| 244 | // DWORD aligned |
| 245 | Repeats.AVT = MVT::i32; |
| 246 | else |
| 247 | // QWORD aligned |
| 248 | Repeats.AVT = Subtarget.is64Bit() ? MVT::i64 : MVT::i32; |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 249 | |
Clement Courbet | 5f0ab9e | 2017-04-28 07:56:31 +0000 | [diff] [blame] | 250 | if (Repeats.BytesLeft() > 0 && |
Matthias Braun | f1caa28 | 2017-12-15 22:22:58 +0000 | [diff] [blame] | 251 | DAG.getMachineFunction().getFunction().optForMinSize()) { |
Clement Courbet | 5f0ab9e | 2017-04-28 07:56:31 +0000 | [diff] [blame] | 252 | // When agressively optimizing for size, avoid generating the code to |
| 253 | // handle BytesLeft. |
| 254 | Repeats.AVT = MVT::i8; |
| 255 | } |
Clement Courbet | d5f6182 | 2017-04-21 09:20:55 +0000 | [diff] [blame] | 256 | } |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 257 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 258 | SDValue InFlag; |
Sanjay Patel | 1640c54 | 2015-12-04 17:51:55 +0000 | [diff] [blame] | 259 | Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RCX : X86::ECX, |
Clement Courbet | 5f0ab9e | 2017-04-28 07:56:31 +0000 | [diff] [blame] | 260 | DAG.getIntPtrConstant(Repeats.Count(), dl), InFlag); |
Hans Wennborg | d683a22 | 2014-03-26 16:30:54 +0000 | [diff] [blame] | 261 | InFlag = Chain.getValue(1); |
Sanjay Patel | 1640c54 | 2015-12-04 17:51:55 +0000 | [diff] [blame] | 262 | Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RDI : X86::EDI, |
| 263 | Dst, InFlag); |
Hans Wennborg | d683a22 | 2014-03-26 16:30:54 +0000 | [diff] [blame] | 264 | InFlag = Chain.getValue(1); |
Sanjay Patel | 1640c54 | 2015-12-04 17:51:55 +0000 | [diff] [blame] | 265 | Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RSI : X86::ESI, |
| 266 | Src, InFlag); |
Hans Wennborg | d683a22 | 2014-03-26 16:30:54 +0000 | [diff] [blame] | 267 | InFlag = Chain.getValue(1); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 268 | |
Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 269 | SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Glue); |
Clement Courbet | 5f0ab9e | 2017-04-28 07:56:31 +0000 | [diff] [blame] | 270 | SDValue Ops[] = { Chain, DAG.getValueType(Repeats.AVT), InFlag }; |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 271 | SDValue RepMovs = DAG.getNode(X86ISD::REP_MOVS, dl, Tys, Ops); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 272 | |
| 273 | SmallVector<SDValue, 4> Results; |
| 274 | Results.push_back(RepMovs); |
Clement Courbet | 5f0ab9e | 2017-04-28 07:56:31 +0000 | [diff] [blame] | 275 | if (Repeats.BytesLeft()) { |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 276 | // Handle the last 1 - 7 bytes. |
Clement Courbet | 5f0ab9e | 2017-04-28 07:56:31 +0000 | [diff] [blame] | 277 | unsigned Offset = Repeats.Size - Repeats.BytesLeft(); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 278 | EVT DstVT = Dst.getValueType(); |
| 279 | EVT SrcVT = Src.getValueType(); |
| 280 | EVT SizeVT = Size.getValueType(); |
| 281 | Results.push_back(DAG.getMemcpy(Chain, dl, |
| 282 | DAG.getNode(ISD::ADD, dl, DstVT, Dst, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 283 | DAG.getConstant(Offset, dl, |
| 284 | DstVT)), |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 285 | DAG.getNode(ISD::ADD, dl, SrcVT, Src, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 286 | DAG.getConstant(Offset, dl, |
| 287 | SrcVT)), |
Clement Courbet | 5f0ab9e | 2017-04-28 07:56:31 +0000 | [diff] [blame] | 288 | DAG.getConstant(Repeats.BytesLeft(), dl, |
Clement Courbet | d5f6182 | 2017-04-21 09:20:55 +0000 | [diff] [blame] | 289 | SizeVT), |
Krzysztof Parzyszek | a46c36b | 2015-04-13 17:16:45 +0000 | [diff] [blame] | 290 | Align, isVolatile, AlwaysInline, false, |
Chris Lattner | 2510de2 | 2010-09-21 05:40:29 +0000 | [diff] [blame] | 291 | DstPtrInfo.getWithOffset(Offset), |
| 292 | SrcPtrInfo.getWithOffset(Offset))); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 295 | return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Results); |
Dan Gohman | bb919df | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 296 | } |