2010-04-16 23:04:22 +00:00
|
|
|
//===-- X86SelectionDAGInfo.cpp - X86 SelectionDAG Info -------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the X86SelectionDAGInfo class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-06-06 23:26:43 +00:00
|
|
|
#include "X86InstrInfo.h"
|
|
|
|
#include "X86ISelLowering.h"
|
|
|
|
#include "X86RegisterInfo.h"
|
|
|
|
#include "X86Subtarget.h"
|
|
|
|
#include "X86SelectionDAGInfo.h"
|
2010-05-11 17:31:57 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
2014-06-06 23:26:43 +00:00
|
|
|
#include "llvm/Target/TargetLowering.h"
|
|
|
|
|
2010-04-16 23:04:22 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 02:41:26 +00:00
|
|
|
#define DEBUG_TYPE "x86-selectiondag-info"
|
|
|
|
|
2014-06-06 23:26:43 +00:00
|
|
|
X86SelectionDAGInfo::X86SelectionDAGInfo(const DataLayout &DL)
|
|
|
|
: TargetSelectionDAGInfo(&DL) {}
|
2010-04-16 23:04:22 +00:00
|
|
|
|
2014-06-06 23:26:43 +00:00
|
|
|
X86SelectionDAGInfo::~X86SelectionDAGInfo() {}
|
2010-05-11 17:31:57 +00:00
|
|
|
|
2014-08-29 20:50:31 +00:00
|
|
|
bool X86SelectionDAGInfo::isBaseRegConflictPossible(
|
|
|
|
SelectionDAG &DAG, ArrayRef<unsigned> ClobberSet) const {
|
|
|
|
// We cannot use TRI->hasBasePointer() until *after* we select all basic
|
|
|
|
// blocks. Legalization may introduce new stack temporaries with large
|
|
|
|
// alignment requirements. Fall back to generic code if there are any
|
|
|
|
// dynamic stack adjustments (hopefully rare) and the base pointer would
|
|
|
|
// conflict if we had to use it.
|
|
|
|
MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();
|
|
|
|
if (!MFI->hasVarSizedObjects() && !MFI->hasInlineAsmWithSPAdjust())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const X86RegisterInfo *TRI = static_cast<const X86RegisterInfo *>(
|
|
|
|
DAG.getSubtarget().getRegisterInfo());
|
|
|
|
unsigned BaseReg = TRI->getBaseRegister();
|
|
|
|
for (unsigned R : ClobberSet)
|
|
|
|
if (BaseReg == R)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-05-11 17:31:57 +00:00
|
|
|
SDValue
|
2013-05-25 02:42:55 +00:00
|
|
|
X86SelectionDAGInfo::EmitTargetCodeForMemset(SelectionDAG &DAG, SDLoc dl,
|
2010-05-11 17:31:57 +00:00
|
|
|
SDValue Chain,
|
|
|
|
SDValue Dst, SDValue Src,
|
|
|
|
SDValue Size, unsigned Align,
|
|
|
|
bool isVolatile,
|
2010-09-21 05:40:29 +00:00
|
|
|
MachinePointerInfo DstPtrInfo) const {
|
2010-05-11 17:31:57 +00:00
|
|
|
ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
|
2015-02-02 17:38:43 +00:00
|
|
|
const X86Subtarget &Subtarget =
|
|
|
|
DAG.getMachineFunction().getSubtarget<X86Subtarget>();
|
2010-05-11 17:31:57 +00:00
|
|
|
|
2014-08-29 20:50:31 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// If the base register might conflict with our physical registers, bail out.
|
2015-03-07 17:41:00 +00:00
|
|
|
const unsigned ClobberSet[] = {X86::RCX, X86::RAX, X86::RDI,
|
|
|
|
X86::ECX, X86::EAX, X86::EDI};
|
2014-08-29 20:50:31 +00:00
|
|
|
assert(!isBaseRegConflictPossible(DAG, ClobberSet));
|
|
|
|
#endif
|
|
|
|
|
2010-09-21 05:43:34 +00:00
|
|
|
// If to a segment-relative address space, use the default lowering.
|
|
|
|
if (DstPtrInfo.getAddrSpace() >= 256)
|
|
|
|
return SDValue();
|
2012-08-01 18:39:17 +00:00
|
|
|
|
2010-05-11 17:31:57 +00:00
|
|
|
// If not DWORD aligned or size is more than the threshold, call the library.
|
|
|
|
// The libc version is likely to be faster for these cases. It can use the
|
|
|
|
// address value and run time information about the CPU.
|
2014-06-06 23:26:43 +00:00
|
|
|
if ((Align & 3) != 0 || !ConstantSize ||
|
|
|
|
ConstantSize->getZExtValue() > Subtarget.getMaxInlineSizeThreshold()) {
|
2010-05-11 17:31:57 +00:00
|
|
|
// Check to see if there is a specialized entry-point for memory zeroing.
|
|
|
|
ConstantSDNode *V = dyn_cast<ConstantSDNode>(Src);
|
|
|
|
|
|
|
|
if (const char *bzeroEntry = V &&
|
2014-06-06 23:26:43 +00:00
|
|
|
V->isNullValue() ? Subtarget.getBZeroEntry() : nullptr) {
|
|
|
|
EVT IntPtr = DAG.getTargetLoweringInfo().getPointerTy();
|
2012-11-01 08:07:29 +00:00
|
|
|
Type *IntPtrTy = getDataLayout()->getIntPtrType(*DAG.getContext());
|
2010-05-11 17:31:57 +00:00
|
|
|
TargetLowering::ArgListTy Args;
|
|
|
|
TargetLowering::ArgListEntry Entry;
|
|
|
|
Entry.Node = Dst;
|
|
|
|
Entry.Ty = IntPtrTy;
|
|
|
|
Args.push_back(Entry);
|
|
|
|
Entry.Node = Size;
|
|
|
|
Args.push_back(Entry);
|
2014-05-17 21:50:17 +00:00
|
|
|
|
|
|
|
TargetLowering::CallLoweringInfo CLI(DAG);
|
|
|
|
CLI.setDebugLoc(dl).setChain(Chain)
|
|
|
|
.setCallee(CallingConv::C, Type::getVoidTy(*DAG.getContext()),
|
2014-07-01 22:01:54 +00:00
|
|
|
DAG.getExternalSymbol(bzeroEntry, IntPtr), std::move(Args),
|
|
|
|
0)
|
2014-05-17 21:50:17 +00:00
|
|
|
.setDiscardResult();
|
|
|
|
|
2014-06-06 23:26:43 +00:00
|
|
|
std::pair<SDValue,SDValue> CallResult = DAG.getTargetLoweringInfo().LowerCallTo(CLI);
|
2010-05-11 17:31:57 +00:00
|
|
|
return CallResult.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise have the target-independent code call memset.
|
|
|
|
return SDValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t SizeVal = ConstantSize->getZExtValue();
|
2014-04-25 05:30:21 +00:00
|
|
|
SDValue InFlag;
|
2010-05-11 17:31:57 +00:00
|
|
|
EVT AVT;
|
|
|
|
SDValue Count;
|
|
|
|
ConstantSDNode *ValC = dyn_cast<ConstantSDNode>(Src);
|
|
|
|
unsigned BytesLeft = 0;
|
|
|
|
bool TwoRepStos = false;
|
|
|
|
if (ValC) {
|
|
|
|
unsigned ValReg;
|
|
|
|
uint64_t Val = ValC->getZExtValue() & 255;
|
|
|
|
|
|
|
|
// If the value is a constant, then we can potentially use larger sets.
|
|
|
|
switch (Align & 3) {
|
|
|
|
case 2: // WORD aligned
|
|
|
|
AVT = MVT::i16;
|
|
|
|
ValReg = X86::AX;
|
|
|
|
Val = (Val << 8) | Val;
|
|
|
|
break;
|
|
|
|
case 0: // DWORD aligned
|
|
|
|
AVT = MVT::i32;
|
|
|
|
ValReg = X86::EAX;
|
|
|
|
Val = (Val << 8) | Val;
|
|
|
|
Val = (Val << 16) | Val;
|
2014-06-06 23:26:43 +00:00
|
|
|
if (Subtarget.is64Bit() && ((Align & 0x7) == 0)) { // QWORD aligned
|
2010-05-11 17:31:57 +00:00
|
|
|
AVT = MVT::i64;
|
|
|
|
ValReg = X86::RAX;
|
|
|
|
Val = (Val << 32) | Val;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: // Byte aligned
|
|
|
|
AVT = MVT::i8;
|
|
|
|
ValReg = X86::AL;
|
2015-04-28 14:05:47 +00:00
|
|
|
Count = DAG.getIntPtrConstant(SizeVal, dl);
|
2010-05-11 17:31:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (AVT.bitsGT(MVT::i8)) {
|
|
|
|
unsigned UBytes = AVT.getSizeInBits() / 8;
|
2015-04-28 14:05:47 +00:00
|
|
|
Count = DAG.getIntPtrConstant(SizeVal / UBytes, dl);
|
2010-05-11 17:31:57 +00:00
|
|
|
BytesLeft = SizeVal % UBytes;
|
|
|
|
}
|
|
|
|
|
2015-04-28 14:05:47 +00:00
|
|
|
Chain = DAG.getCopyToReg(Chain, dl, ValReg, DAG.getConstant(Val, dl, AVT),
|
2010-05-11 17:31:57 +00:00
|
|
|
InFlag);
|
|
|
|
InFlag = Chain.getValue(1);
|
|
|
|
} else {
|
|
|
|
AVT = MVT::i8;
|
2015-04-28 14:05:47 +00:00
|
|
|
Count = DAG.getIntPtrConstant(SizeVal, dl);
|
2010-05-11 17:31:57 +00:00
|
|
|
Chain = DAG.getCopyToReg(Chain, dl, X86::AL, Src, InFlag);
|
|
|
|
InFlag = Chain.getValue(1);
|
|
|
|
}
|
|
|
|
|
2014-06-06 23:26:43 +00:00
|
|
|
Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RCX : X86::ECX,
|
|
|
|
Count, InFlag);
|
2010-05-11 17:31:57 +00:00
|
|
|
InFlag = Chain.getValue(1);
|
2014-06-06 23:26:43 +00:00
|
|
|
Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RDI : X86::EDI,
|
|
|
|
Dst, InFlag);
|
2010-05-11 17:31:57 +00:00
|
|
|
InFlag = Chain.getValue(1);
|
|
|
|
|
2010-12-21 02:38:05 +00:00
|
|
|
SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Glue);
|
2010-05-11 17:31:57 +00:00
|
|
|
SDValue Ops[] = { Chain, DAG.getValueType(AVT), InFlag };
|
2014-04-26 18:35:24 +00:00
|
|
|
Chain = DAG.getNode(X86ISD::REP_STOS, dl, Tys, Ops);
|
2010-05-11 17:31:57 +00:00
|
|
|
|
|
|
|
if (TwoRepStos) {
|
|
|
|
InFlag = Chain.getValue(1);
|
|
|
|
Count = Size;
|
|
|
|
EVT CVT = Count.getValueType();
|
|
|
|
SDValue Left = DAG.getNode(ISD::AND, dl, CVT, Count,
|
2015-04-28 14:05:47 +00:00
|
|
|
DAG.getConstant((AVT == MVT::i64) ? 7 : 3, dl,
|
|
|
|
CVT));
|
2010-05-11 17:31:57 +00:00
|
|
|
Chain = DAG.getCopyToReg(Chain, dl, (CVT == MVT::i64) ? X86::RCX :
|
|
|
|
X86::ECX,
|
|
|
|
Left, InFlag);
|
|
|
|
InFlag = Chain.getValue(1);
|
2010-12-21 02:38:05 +00:00
|
|
|
Tys = DAG.getVTList(MVT::Other, MVT::Glue);
|
2010-05-11 17:31:57 +00:00
|
|
|
SDValue Ops[] = { Chain, DAG.getValueType(MVT::i8), InFlag };
|
2014-04-26 18:35:24 +00:00
|
|
|
Chain = DAG.getNode(X86ISD::REP_STOS, dl, Tys, Ops);
|
2010-05-11 17:31:57 +00:00
|
|
|
} else if (BytesLeft) {
|
|
|
|
// Handle the last 1 - 7 bytes.
|
|
|
|
unsigned Offset = SizeVal - BytesLeft;
|
|
|
|
EVT AddrVT = Dst.getValueType();
|
|
|
|
EVT SizeVT = Size.getValueType();
|
|
|
|
|
|
|
|
Chain = DAG.getMemset(Chain, dl,
|
|
|
|
DAG.getNode(ISD::ADD, dl, AddrVT, Dst,
|
2015-04-28 14:05:47 +00:00
|
|
|
DAG.getConstant(Offset, dl, AddrVT)),
|
2010-05-11 17:31:57 +00:00
|
|
|
Src,
|
2015-04-28 14:05:47 +00:00
|
|
|
DAG.getConstant(BytesLeft, dl, SizeVT),
|
2015-04-13 17:16:45 +00:00
|
|
|
Align, isVolatile, false,
|
|
|
|
DstPtrInfo.getWithOffset(Offset));
|
2010-05-11 17:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Use a Tokenfactor, as in memcpy, instead of a single chain.
|
|
|
|
return Chain;
|
|
|
|
}
|
|
|
|
|
2015-02-02 17:38:43 +00:00
|
|
|
SDValue X86SelectionDAGInfo::EmitTargetCodeForMemcpy(
|
|
|
|
SelectionDAG &DAG, SDLoc dl, SDValue Chain, SDValue Dst, SDValue Src,
|
|
|
|
SDValue Size, unsigned Align, bool isVolatile, bool AlwaysInline,
|
|
|
|
MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
|
2011-04-15 05:18:47 +00:00
|
|
|
// This requires the copy size to be a constant, preferably
|
2010-05-11 17:31:57 +00:00
|
|
|
// within a subtarget-specific limit.
|
|
|
|
ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
|
2015-02-02 17:38:43 +00:00
|
|
|
const X86Subtarget &Subtarget =
|
|
|
|
DAG.getMachineFunction().getSubtarget<X86Subtarget>();
|
2010-05-11 17:31:57 +00:00
|
|
|
if (!ConstantSize)
|
|
|
|
return SDValue();
|
|
|
|
uint64_t SizeVal = ConstantSize->getZExtValue();
|
2014-06-06 23:26:43 +00:00
|
|
|
if (!AlwaysInline && SizeVal > Subtarget.getMaxInlineSizeThreshold())
|
2010-05-11 17:31:57 +00:00
|
|
|
return SDValue();
|
|
|
|
|
2010-11-04 21:16:46 +00:00
|
|
|
/// If not DWORD aligned, it is more efficient to call the library. However
|
|
|
|
/// if calling the library is not allowed (AlwaysInline), then soldier on as
|
|
|
|
/// the code generated here is better than the long load-store sequence we
|
|
|
|
/// would otherwise get.
|
|
|
|
if (!AlwaysInline && (Align & 3) != 0)
|
2010-05-11 17:31:57 +00:00
|
|
|
return SDValue();
|
|
|
|
|
2010-09-21 05:43:34 +00:00
|
|
|
// If to a segment-relative address space, use the default lowering.
|
|
|
|
if (DstPtrInfo.getAddrSpace() >= 256 ||
|
|
|
|
SrcPtrInfo.getAddrSpace() >= 256)
|
|
|
|
return SDValue();
|
2010-11-04 21:16:46 +00:00
|
|
|
|
2014-08-29 20:50:31 +00:00
|
|
|
// If the base register might conflict with our physical registers, bail out.
|
2015-03-07 17:41:00 +00:00
|
|
|
const unsigned ClobberSet[] = {X86::RCX, X86::RSI, X86::RDI,
|
|
|
|
X86::ECX, X86::ESI, X86::EDI};
|
2014-08-29 20:50:31 +00:00
|
|
|
if (isBaseRegConflictPossible(DAG, ClobberSet))
|
Revert "X86 memcpy lowering: use "rep movs" even when esi is used as base pointer" (r204174)
> For functions where esi is used as base pointer, we would previously fall ba
> from lowering memcpy with "rep movs" because that clobbers esi.
>
> With this patch, we just store esi in another physical register, and restore
> it afterwards. This adds a little bit of register preassure, but the more
> efficient memcpy should be worth it.
>
> Differential Revision: http://llvm-reviews.chandlerc.com/D2968
This didn't work. I was ending up with code like this:
lea edi,[esi+38h]
mov ecx,0Fh
mov edx,esi
mov esi,ebx
rep movs dword ptr es:[edi],dword ptr [esi]
lea ecx,[esi+74h] <-- Ooops, we're now using esi before restoring it from edx.
add ebx,3Ch
mov esi,edx
I guess if we want to do this we need stronger glue or something, or doing the expansion
much later.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204829 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-26 16:30:54 +00:00
|
|
|
return SDValue();
|
2013-02-13 13:40:35 +00:00
|
|
|
|
2010-11-04 21:16:46 +00:00
|
|
|
MVT AVT;
|
|
|
|
if (Align & 1)
|
|
|
|
AVT = MVT::i8;
|
|
|
|
else if (Align & 2)
|
|
|
|
AVT = MVT::i16;
|
|
|
|
else if (Align & 4)
|
|
|
|
// DWORD aligned
|
|
|
|
AVT = MVT::i32;
|
|
|
|
else
|
|
|
|
// QWORD aligned
|
2014-06-06 23:26:43 +00:00
|
|
|
AVT = Subtarget.is64Bit() ? MVT::i64 : MVT::i32;
|
2010-05-11 17:31:57 +00:00
|
|
|
|
|
|
|
unsigned UBytes = AVT.getSizeInBits() / 8;
|
|
|
|
unsigned CountVal = SizeVal / UBytes;
|
2015-04-28 14:05:47 +00:00
|
|
|
SDValue Count = DAG.getIntPtrConstant(CountVal, dl);
|
2010-05-11 17:31:57 +00:00
|
|
|
unsigned BytesLeft = SizeVal % UBytes;
|
|
|
|
|
2014-04-25 05:30:21 +00:00
|
|
|
SDValue InFlag;
|
2014-06-06 23:26:43 +00:00
|
|
|
Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RCX :
|
2010-05-11 17:31:57 +00:00
|
|
|
X86::ECX,
|
Revert "X86 memcpy lowering: use "rep movs" even when esi is used as base pointer" (r204174)
> For functions where esi is used as base pointer, we would previously fall ba
> from lowering memcpy with "rep movs" because that clobbers esi.
>
> With this patch, we just store esi in another physical register, and restore
> it afterwards. This adds a little bit of register preassure, but the more
> efficient memcpy should be worth it.
>
> Differential Revision: http://llvm-reviews.chandlerc.com/D2968
This didn't work. I was ending up with code like this:
lea edi,[esi+38h]
mov ecx,0Fh
mov edx,esi
mov esi,ebx
rep movs dword ptr es:[edi],dword ptr [esi]
lea ecx,[esi+74h] <-- Ooops, we're now using esi before restoring it from edx.
add ebx,3Ch
mov esi,edx
I guess if we want to do this we need stronger glue or something, or doing the expansion
much later.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204829 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-26 16:30:54 +00:00
|
|
|
Count, InFlag);
|
|
|
|
InFlag = Chain.getValue(1);
|
2014-06-06 23:26:43 +00:00
|
|
|
Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RDI :
|
2010-05-11 17:31:57 +00:00
|
|
|
X86::EDI,
|
Revert "X86 memcpy lowering: use "rep movs" even when esi is used as base pointer" (r204174)
> For functions where esi is used as base pointer, we would previously fall ba
> from lowering memcpy with "rep movs" because that clobbers esi.
>
> With this patch, we just store esi in another physical register, and restore
> it afterwards. This adds a little bit of register preassure, but the more
> efficient memcpy should be worth it.
>
> Differential Revision: http://llvm-reviews.chandlerc.com/D2968
This didn't work. I was ending up with code like this:
lea edi,[esi+38h]
mov ecx,0Fh
mov edx,esi
mov esi,ebx
rep movs dword ptr es:[edi],dword ptr [esi]
lea ecx,[esi+74h] <-- Ooops, we're now using esi before restoring it from edx.
add ebx,3Ch
mov esi,edx
I guess if we want to do this we need stronger glue or something, or doing the expansion
much later.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204829 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-26 16:30:54 +00:00
|
|
|
Dst, InFlag);
|
|
|
|
InFlag = Chain.getValue(1);
|
2014-06-06 23:26:43 +00:00
|
|
|
Chain = DAG.getCopyToReg(Chain, dl, Subtarget.is64Bit() ? X86::RSI :
|
2010-05-11 17:31:57 +00:00
|
|
|
X86::ESI,
|
Revert "X86 memcpy lowering: use "rep movs" even when esi is used as base pointer" (r204174)
> For functions where esi is used as base pointer, we would previously fall ba
> from lowering memcpy with "rep movs" because that clobbers esi.
>
> With this patch, we just store esi in another physical register, and restore
> it afterwards. This adds a little bit of register preassure, but the more
> efficient memcpy should be worth it.
>
> Differential Revision: http://llvm-reviews.chandlerc.com/D2968
This didn't work. I was ending up with code like this:
lea edi,[esi+38h]
mov ecx,0Fh
mov edx,esi
mov esi,ebx
rep movs dword ptr es:[edi],dword ptr [esi]
lea ecx,[esi+74h] <-- Ooops, we're now using esi before restoring it from edx.
add ebx,3Ch
mov esi,edx
I guess if we want to do this we need stronger glue or something, or doing the expansion
much later.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204829 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-26 16:30:54 +00:00
|
|
|
Src, InFlag);
|
|
|
|
InFlag = Chain.getValue(1);
|
2010-05-11 17:31:57 +00:00
|
|
|
|
2010-12-21 02:38:05 +00:00
|
|
|
SDVTList Tys = DAG.getVTList(MVT::Other, MVT::Glue);
|
Revert "X86 memcpy lowering: use "rep movs" even when esi is used as base pointer" (r204174)
> For functions where esi is used as base pointer, we would previously fall ba
> from lowering memcpy with "rep movs" because that clobbers esi.
>
> With this patch, we just store esi in another physical register, and restore
> it afterwards. This adds a little bit of register preassure, but the more
> efficient memcpy should be worth it.
>
> Differential Revision: http://llvm-reviews.chandlerc.com/D2968
This didn't work. I was ending up with code like this:
lea edi,[esi+38h]
mov ecx,0Fh
mov edx,esi
mov esi,ebx
rep movs dword ptr es:[edi],dword ptr [esi]
lea ecx,[esi+74h] <-- Ooops, we're now using esi before restoring it from edx.
add ebx,3Ch
mov esi,edx
I guess if we want to do this we need stronger glue or something, or doing the expansion
much later.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204829 91177308-0d34-0410-b5e6-96231b3b80d8
2014-03-26 16:30:54 +00:00
|
|
|
SDValue Ops[] = { Chain, DAG.getValueType(AVT), InFlag };
|
2014-04-26 18:35:24 +00:00
|
|
|
SDValue RepMovs = DAG.getNode(X86ISD::REP_MOVS, dl, Tys, Ops);
|
2010-05-11 17:31:57 +00:00
|
|
|
|
|
|
|
SmallVector<SDValue, 4> Results;
|
|
|
|
Results.push_back(RepMovs);
|
|
|
|
if (BytesLeft) {
|
|
|
|
// Handle the last 1 - 7 bytes.
|
|
|
|
unsigned Offset = SizeVal - BytesLeft;
|
|
|
|
EVT DstVT = Dst.getValueType();
|
|
|
|
EVT SrcVT = Src.getValueType();
|
|
|
|
EVT SizeVT = Size.getValueType();
|
|
|
|
Results.push_back(DAG.getMemcpy(Chain, dl,
|
|
|
|
DAG.getNode(ISD::ADD, dl, DstVT, Dst,
|
2015-04-28 14:05:47 +00:00
|
|
|
DAG.getConstant(Offset, dl,
|
|
|
|
DstVT)),
|
2010-05-11 17:31:57 +00:00
|
|
|
DAG.getNode(ISD::ADD, dl, SrcVT, Src,
|
2015-04-28 14:05:47 +00:00
|
|
|
DAG.getConstant(Offset, dl,
|
|
|
|
SrcVT)),
|
|
|
|
DAG.getConstant(BytesLeft, dl, SizeVT),
|
2015-04-13 17:16:45 +00:00
|
|
|
Align, isVolatile, AlwaysInline, false,
|
2010-09-21 05:40:29 +00:00
|
|
|
DstPtrInfo.getWithOffset(Offset),
|
|
|
|
SrcPtrInfo.getWithOffset(Offset)));
|
2010-05-11 17:31:57 +00:00
|
|
|
}
|
|
|
|
|
2014-04-26 18:35:24 +00:00
|
|
|
return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Results);
|
2010-05-11 17:31:57 +00:00
|
|
|
}
|