From: Nick Lewycky Date: Sun, 16 Oct 2011 20:13:32 +0000 (+0000) Subject: When looking for dependencies on the src pointer, scan the src pointer. Scanning X-Git-Tag: android-x86-6.0-r1~928^2~202 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=36c7e6c36cce7896b762e79a75b9a29e6a39d48c;p=android-x86%2Fexternal-llvm.git When looking for dependencies on the src pointer, scan the src pointer. Scanning on the memcpy call will pull up other unrelated stuff. Fixes PR11142. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142150 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp index eeb8931446d..298d6927497 100644 --- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -806,21 +806,26 @@ bool MemCpyOpt::processMemCpy(MemCpyInst *M) { // a) memcpy-memcpy xform which exposes redundance for DSE. // b) call-memcpy xform for return slot optimization. MemDepResult DepInfo = MD->getDependency(M); - if (!DepInfo.isClobber()) - return false; - - if (MemCpyInst *MDep = dyn_cast(DepInfo.getInst())) - return processMemCpyMemCpyDependence(M, MDep, CopySize->getZExtValue()); - - if (CallInst *C = dyn_cast(DepInfo.getInst())) { - if (performCallSlotOptzn(M, M->getDest(), M->getSource(), - CopySize->getZExtValue(), C)) { - MD->removeInstruction(M); - M->eraseFromParent(); - return true; + if (DepInfo.isClobber()) { + if (CallInst *C = dyn_cast(DepInfo.getInst())) { + if (performCallSlotOptzn(M, M->getDest(), M->getSource(), + CopySize->getZExtValue(), C)) { + MD->removeInstruction(M); + M->eraseFromParent(); + return true; + } } } + AliasAnalysis &AA = getAnalysis(); + AliasAnalysis::Location SrcLoc = AA.getLocationForSource(M); + MemDepResult SrcDepInfo = MD->getPointerDependencyFrom(SrcLoc, true, + M, M->getParent()); + if (SrcDepInfo.isClobber()) { + if (MemCpyInst *MDep = dyn_cast(SrcDepInfo.getInst())) + return processMemCpyMemCpyDependence(M, MDep, CopySize->getZExtValue()); + } + return false; } diff --git a/test/Transforms/MemCpyOpt/memcpy.ll b/test/Transforms/MemCpyOpt/memcpy.ll index 71d4d4e8a11..e828e4419fe 100644 --- a/test/Transforms/MemCpyOpt/memcpy.ll +++ b/test/Transforms/MemCpyOpt/memcpy.ll @@ -59,7 +59,7 @@ define void @test3(%0* noalias sret %agg.result) nounwind { call void @llvm.memcpy.p0i8.p0i8.i32(i8* %agg.result2, i8* %x.01, i32 32, i32 16, i1 false) ret void ; CHECK: @test3 -; CHECK-NEXT: %agg.result2 = bitcast +; CHECK-NEXT: %agg.result1 = bitcast ; CHECK-NEXT: call void @llvm.memcpy ; CHECK-NEXT: ret void } @@ -130,3 +130,21 @@ declare i32 @g(%struct.p* byval align 8) declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind +; PR11142 - When looking for a memcpy-memcpy dependency, don't get stuck on +; instructions between the memcpy's that only affect the destination pointer. +@test8.str = internal constant [7 x i8] c"ABCDEF\00" + +define void @test8() { +; CHECK: test8 + %A = tail call i8* @malloc(i32 10) + %B = getelementptr inbounds i8* %A, i64 2 + tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* %B, i8* getelementptr inbounds ([7 x i8]* @test8.str, i64 0, i64 0), i32 7, i32 1, i1 false) +; CHECK: tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* %D, i8* getelementptr + %C = tail call i8* @malloc(i32 10) + %D = getelementptr inbounds i8* %C, i64 2 + tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* %D, i8* %B, i32 7, i32 1, i1 false) +; CHECK: tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* %D, i8* getelementptr + ret void +} + +declare noalias i8* @malloc(i32)