diff options
| author | Pete Cooper <peter_cooper@apple.com> | 2015-11-18 22:17:24 +0000 |
|---|---|---|
| committer | Pete Cooper <peter_cooper@apple.com> | 2015-11-18 22:17:24 +0000 |
| commit | 72bc23ef02bad3873d3572b2be529404a461d449 (patch) | |
| tree | f1a47c225592be2aa94fdcaf411d1d5f51a7c193 /llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp | |
| parent | b035bd03e4db325de2380ea9263e10de5b9be3b6 (diff) | |
| download | bcm5719-llvm-72bc23ef02bad3873d3572b2be529404a461d449.tar.gz bcm5719-llvm-72bc23ef02bad3873d3572b2be529404a461d449.zip | |
Change memcpy/memset/memmove to have dest and source alignments.
Note, this was reviewed (and more details are in) http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20151109/312083.html
These intrinsics currently have an explicit alignment argument which is
required to be a constant integer. It represents the alignment of the
source and dest, and so must be the minimum of those.
This change allows source and dest to each have their own alignments
by using the alignment attribute on their arguments. The alignment
argument itself is removed.
There are a few places in the code for which the code needs to be
checked by an expert as to whether using only src/dest alignment is
safe. For those places, they currently take the minimum of src/dest
alignments which matches the current behaviour.
For example, code which used to read:
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 500, i32 8, i1 false)
will now read:
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 8 %dest, i8* align 8 %src, i32 500, i1 false)
For out of tree owners, I was able to strip alignment from calls using sed by replacing:
(call.*llvm\.memset.*)i32\ [0-9]*\,\ i1 false\)
with:
$1i1 false)
and similarly for memmove and memcpy.
I then added back in alignment to test cases which needed it.
A similar commit will be made to clang which actually has many differences in alignment as now
IRBuilder can generate different source/dest alignments on calls.
In IRBuilder itself, a new argument was added. Instead of calling:
CreateMemCpy(Dst, Src, getInt64(Size), DstAlign, /* isVolatile */ false)
you now call
CreateMemCpy(Dst, Src, getInt64(Size), DstAlign, SrcAlign, /* isVolatile */ false)
There is a temporary class (IntegerAlignment) which takes the source alignment and rejects
implicit conversion from bool. This is to prevent isVolatile here from passing its default
parameter to the source alignment.
Note, changes in future can now be made to codegen. I didn't change anything here, but this
change should enable better memcpy code sequences.
Reviewed by Hal Finkel.
llvm-svn: 253511
Diffstat (limited to 'llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp index 114d22ddf2e..679e241d971 100644 --- a/llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp +++ b/llvm/lib/Transforms/Scalar/ScalarReplAggregates.cpp @@ -716,7 +716,7 @@ void ConvertToScalarInfo::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, SrcPtr = Builder.CreateBitCast(SrcPtr, AIPTy); LoadInst *SrcVal = Builder.CreateLoad(SrcPtr, "srcval"); - SrcVal->setAlignment(MTI->getAlignment()); + SrcVal->setAlignment(MTI->getSrcAlignment()); Builder.CreateStore(SrcVal, NewAI); } else if (GetUnderlyingObject(MTI->getDest(), DL, 0) != OrigAI) { // Src must be OrigAI, change this to be a load from NewAI then a store @@ -733,7 +733,7 @@ void ConvertToScalarInfo::ConvertUsesToScalar(Value *Ptr, AllocaInst *NewAI, Value *DstPtr = Builder.CreateBitCast(MTI->getDest(), AIPTy); StoreInst *NewStore = Builder.CreateStore(SrcVal, DstPtr); - NewStore->setAlignment(MTI->getAlignment()); + NewStore->setAlignment(MTI->getDestAlignment()); } else { // Noop transfer. Src == Dst } @@ -2182,7 +2182,8 @@ SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *Inst, // that doesn't have anything to do with the alloca that we are promoting. For // memset, this Value* stays null. Value *OtherPtr = nullptr; - unsigned MemAlignment = MI->getAlignment(); + unsigned DestMemAlignment = MI->getDestAlignment(); + unsigned SrcMemAlignment = 0; if (MemTransferInst *MTI = dyn_cast<MemTransferInst>(MI)) { // memmove/memcopy if (Inst == MTI->getRawDest()) OtherPtr = MTI->getRawSource(); @@ -2190,6 +2191,7 @@ SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *Inst, assert(Inst == MTI->getRawSource()); OtherPtr = MTI->getRawDest(); } + SrcMemAlignment = MTI->getSrcAlignment(); } // If there is an other pointer, we want to convert it to the same pointer @@ -2235,7 +2237,8 @@ SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *Inst, for (unsigned i = 0, e = NewElts.size(); i != e; ++i) { // If this is a memcpy/memmove, emit a GEP of the other element address. Value *OtherElt = nullptr; - unsigned OtherEltAlign = MemAlignment; + unsigned OtherDestEltAlign = DestMemAlignment; + unsigned OtherSrcEltAlign = SrcMemAlignment; if (OtherPtr) { Value *Idx[2] = { Zero, @@ -2258,7 +2261,8 @@ SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *Inst, // mem intrinsic and the alignment of the element. If the alignment of // the memcpy (f.e.) is 32 but the element is at a 4-byte offset, then the // known alignment is just 4 bytes. - OtherEltAlign = (unsigned)MinAlign(OtherEltAlign, EltOffset); + OtherDestEltAlign = (unsigned)MinAlign(OtherDestEltAlign, EltOffset); + OtherSrcEltAlign = (unsigned)MinAlign(OtherSrcEltAlign, EltOffset); } Value *EltPtr = NewElts[i]; @@ -2269,12 +2273,13 @@ SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *Inst, if (isa<MemTransferInst>(MI)) { if (SROADest) { // From Other to Alloca. - Value *Elt = new LoadInst(OtherElt, "tmp", false, OtherEltAlign, MI); + Value *Elt = new LoadInst(OtherElt, "tmp", false, + OtherSrcEltAlign, MI); new StoreInst(Elt, EltPtr, MI); } else { // From Alloca to Other. Value *Elt = new LoadInst(EltPtr, "tmp", MI); - new StoreInst(Elt, OtherElt, false, OtherEltAlign, MI); + new StoreInst(Elt, OtherElt, false, OtherDestEltAlign, MI); } continue; } @@ -2337,9 +2342,11 @@ SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *Inst, Value *Src = SROADest ? OtherElt : EltPtr; // Src ptr if (isa<MemCpyInst>(MI)) - Builder.CreateMemCpy(Dst, Src, EltSize, OtherEltAlign,MI->isVolatile()); + Builder.CreateMemCpy(Dst, Src, EltSize, OtherDestEltAlign, + OtherSrcEltAlign, MI->isVolatile()); else - Builder.CreateMemMove(Dst, Src, EltSize,OtherEltAlign,MI->isVolatile()); + Builder.CreateMemMove(Dst, Src, EltSize, OtherDestEltAlign, + OtherSrcEltAlign, MI->isVolatile()); } } DeadInsts.push_back(MI); |

