mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-21 03:32:29 +00:00
Make memcpyopt TBAA-aware.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121944 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ad3ea3d85f
commit
387f28aff4
lib
test/Analysis/TypeBasedAliasAnalysis
@ -219,8 +219,11 @@ AliasAnalysis::getLocationForSource(const MemTransferInst *MTI) {
|
||||
if (ConstantInt *C = dyn_cast<ConstantInt>(MTI->getLength()))
|
||||
Size = C->getValue().getZExtValue();
|
||||
|
||||
// FIXME: Can memcpy/memmove have TBAA tags?
|
||||
return Location(MTI->getRawSource(), Size, 0);
|
||||
// memcpy/memmove can have TBAA tags. For memcpy, they apply
|
||||
// to both the source and the destination.
|
||||
MDNode *TBAATag = MTI->getMetadata(LLVMContext::MD_tbaa);
|
||||
|
||||
return Location(MTI->getRawSource(), Size, TBAATag);
|
||||
}
|
||||
|
||||
AliasAnalysis::Location
|
||||
@ -228,9 +231,12 @@ AliasAnalysis::getLocationForDest(const MemIntrinsic *MTI) {
|
||||
uint64_t Size = UnknownSize;
|
||||
if (ConstantInt *C = dyn_cast<ConstantInt>(MTI->getLength()))
|
||||
Size = C->getValue().getZExtValue();
|
||||
|
||||
// memcpy/memmove can have TBAA tags. For memcpy, they apply
|
||||
// to both the source and the destination.
|
||||
MDNode *TBAATag = MTI->getMetadata(LLVMContext::MD_tbaa);
|
||||
|
||||
// FIXME: Can memcpy/memmove have TBAA tags?
|
||||
return Location(MTI->getRawDest(), Size, 0);
|
||||
return Location(MTI->getRawDest(), Size, TBAATag);
|
||||
}
|
||||
|
||||
|
||||
|
@ -688,10 +688,6 @@ bool MemCpyOpt::processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep,
|
||||
ConstantInt *C1 = dyn_cast<ConstantInt>(MDep->getLength());
|
||||
if (!C1) return false;
|
||||
|
||||
uint64_t DepSize = C1->getValue().getZExtValue();
|
||||
if (DepSize < MSize)
|
||||
return false;
|
||||
|
||||
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
||||
|
||||
// Verify that the copied-from memory doesn't change in between the two
|
||||
@ -716,7 +712,8 @@ bool MemCpyOpt::processMemCpyMemCpyDependence(MemCpyInst *M, MemCpyInst *MDep,
|
||||
// source and dest might overlap. We still want to eliminate the intermediate
|
||||
// value, but we have to generate a memmove instead of memcpy.
|
||||
Intrinsic::ID ResultFn = Intrinsic::memcpy;
|
||||
if (!AA.isNoAlias(M->getRawDest(), MSize, MDep->getRawSource(), DepSize))
|
||||
if (AA.alias(AA.getLocationForDest(M), AA.getLocationForSource(MDep)) !=
|
||||
AliasAnalysis::NoAlias)
|
||||
ResultFn = Intrinsic::memmove;
|
||||
|
||||
// If all checks passed, then we can transform M.
|
||||
@ -795,14 +792,9 @@ bool MemCpyOpt::processMemCpy(MemCpyInst *M) {
|
||||
bool MemCpyOpt::processMemMove(MemMoveInst *M) {
|
||||
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
||||
|
||||
// If the memmove is a constant size, use it for the alias query, this allows
|
||||
// us to optimize things like: memmove(P, P+64, 64);
|
||||
uint64_t MemMoveSize = AliasAnalysis::UnknownSize;
|
||||
if (ConstantInt *Len = dyn_cast<ConstantInt>(M->getLength()))
|
||||
MemMoveSize = Len->getZExtValue();
|
||||
|
||||
// See if the pointers alias.
|
||||
if (AA.alias(M->getRawDest(), MemMoveSize, M->getRawSource(), MemMoveSize) !=
|
||||
if (AA.alias(AA.getLocationForDest(M),
|
||||
AA.getLocationForSource(M)) !=
|
||||
AliasAnalysis::NoAlias)
|
||||
return false;
|
||||
|
||||
|
23
test/Analysis/TypeBasedAliasAnalysis/memcpyopt.ll
Normal file
23
test/Analysis/TypeBasedAliasAnalysis/memcpyopt.ll
Normal file
@ -0,0 +1,23 @@
|
||||
; RUN: opt -S -tbaa -basicaa -memcpyopt -instcombine < %s | FileCheck %s
|
||||
|
||||
target datalayout = "e-p:64:64:64"
|
||||
|
||||
; The second memcpy is redundant and can be deleted. There's an intervening store, but
|
||||
; it has a TBAA tag which declares that it is unrelated.
|
||||
|
||||
; CHECK: @foo
|
||||
; CHECK-NEXT: tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %p, i8* %q, i64 16, i32 1, i1 false), !tbaa !0
|
||||
; CHECK-NEXT: store i8 2, i8* %s, align 1, !tbaa !2
|
||||
; CHECK-NEXT: ret void
|
||||
define void @foo(i8* nocapture %p, i8* nocapture %q, i8* nocapture %s) nounwind {
|
||||
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %p, i8* %q, i64 16, i32 1, i1 false), !tbaa !2
|
||||
store i8 2, i8* %s, align 1, !tbaa !1
|
||||
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %q, i8* %p, i64 16, i32 1, i1 false), !tbaa !2
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
|
||||
|
||||
!0 = metadata !{metadata !"tbaa root", null}
|
||||
!1 = metadata !{metadata !"A", metadata !0}
|
||||
!2 = metadata !{metadata !"B", metadata !0}
|
Loading…
x
Reference in New Issue
Block a user