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