diff options
author | Chris Lattner <sabre@nondot.org> | 2010-12-01 01:24:55 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-12-01 01:24:55 +0000 |
commit | b5a3196f809e8edb2e9fef09de1de3d382cb852f (patch) | |
tree | a21ccee8f5ab344189679d1574d631c74e8efcc4 | |
parent | 76f4e1038878e1944bb3e32e8183ce8b973bc61b (diff) | |
download | llvm-b5a3196f809e8edb2e9fef09de1de3d382cb852f.tar.gz llvm-b5a3196f809e8edb2e9fef09de1de3d382cb852f.tar.bz2 llvm-b5a3196f809e8edb2e9fef09de1de3d382cb852f.tar.xz |
fix a bozo bug I introduced in r119930, causing a miscompile of
20040709-1.c from the gcc testsuite. I was using the size of a
pointer instead of the pointee. This fixes rdar://8713376
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120519 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/MemCpyOptimizer.cpp | 3 | ||||
-rw-r--r-- | test/Transforms/MemCpyOpt/memcpy.ll | 23 |
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp index 087f022fe9..5d867e7154 100644 --- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -814,7 +814,8 @@ bool MemCpyOpt::processByValArgument(CallSite CS, unsigned ArgNo) { // Find out what feeds this byval argument. Value *ByValArg = CS.getArgument(ArgNo); - uint64_t ByValSize = TD->getTypeAllocSize(ByValArg->getType()); + const Type *ByValTy =cast<PointerType>(ByValArg->getType())->getElementType(); + uint64_t ByValSize = TD->getTypeAllocSize(ByValTy); MemDepResult DepInfo = MD->getPointerDependencyFrom(AliasAnalysis::Location(ByValArg, ByValSize), true, CS.getInstruction(), diff --git a/test/Transforms/MemCpyOpt/memcpy.ll b/test/Transforms/MemCpyOpt/memcpy.ll index 7309319c46..16b80a628a 100644 --- a/test/Transforms/MemCpyOpt/memcpy.ll +++ b/test/Transforms/MemCpyOpt/memcpy.ll @@ -77,3 +77,26 @@ define void @test4(i8 *%P) { declare void @test4a(i8* byval align 1) declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind + +%struct.S = type { i128, [4 x i8]} + +@sS = external global %struct.S, align 16 + +declare void @test5a(%struct.S* byval align 16) nounwind ssp + +declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind + +; rdar://8713376 - This memcpy can't be eliminated. +define i32 @test5(i32 %x) nounwind ssp { +entry: + %y = alloca %struct.S, align 16 + %tmp = bitcast %struct.S* %y to i8* + call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp, i8* bitcast (%struct.S* @sS to i8*), i64 32, i32 16, i1 false) + %a = getelementptr %struct.S* %y, i64 0, i32 1, i64 0 + store i8 4, i8* %a + call void @test5a(%struct.S* byval align 16 %y) + ret i32 0 + ; CHECK: @test5( + ; CHECK: store i8 4 + ; CHECK: call void @test5a(%struct.S* byval align 16 %y) +} |