[llvm-commits] [llvm] r51850 - in /llvm/trunk: lib/Transforms/Scalar/MemCpyOptimizer.cpp test/Transforms/MemCpyOpt/2008-06-01-MemCpy-MemMove.ll
Owen Anderson
resistor at mac.com
Sun Jun 1 15:26:26 PDT 2008
Author: resistor
Date: Sun Jun 1 17:26:26 2008
New Revision: 51850
URL: http://llvm.org/viewvc/llvm-project?rev=51850&view=rev
Log:
Fix two issues that Eli Friedman pointed out, where would misoptimized code like:
char a[200];
init(a, a+200);
OR
int a[200];
char* b = (char*)a;
char* c = (char*)a;
foo(b, c);
Modified:
llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
llvm/trunk/test/Transforms/MemCpyOpt/2008-06-01-MemCpy-MemMove.ll
Modified: llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp?rev=51850&r1=51849&r2=51850&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp Sun Jun 1 17:26:26 2008
@@ -554,10 +554,17 @@
User* UI = srcUseList.back();
srcUseList.pop_back();
- if (isa<GetElementPtrInst>(UI) || isa<BitCastInst>(UI)) {
+ if (isa<BitCastInst>(UI)) {
for (User::use_iterator I = UI->use_begin(), E = UI->use_end();
I != E; ++I)
srcUseList.push_back(*I);
+ } else if (GetElementPtrInst* G = dyn_cast<GetElementPtrInst>(UI)) {
+ if (G->hasAllZeroIndices())
+ for (User::use_iterator I = UI->use_begin(), E = UI->use_end();
+ I != E; ++I)
+ srcUseList.push_back(*I);
+ else
+ return false;
} else if (UI != C && UI != cpy) {
return false;
}
@@ -582,12 +589,16 @@
// All the checks have passed, so do the transformation.
bool changedArgument = false;
for (unsigned i = 0; i < CS.arg_size(); ++i)
- if (CS.getArgument(i) == cpySrc) {
+ if (CS.getArgument(i)->stripPointerCasts() == cpySrc) {
if (cpySrc->getType() != cpyDest->getType())
cpyDest = CastInst::CreatePointerCast(cpyDest, cpySrc->getType(),
cpyDest->getName(), C);
changedArgument = true;
- CS.setArgument(i, cpyDest);
+ if (CS.getArgument(i)->getType() != cpyDest->getType())
+ CS.setArgument(i, CastInst::CreatePointerCast(cpyDest,
+ CS.getArgument(i)->getType(), cpyDest->getName(), C));
+ else
+ CS.setArgument(i, cpyDest);
}
if (!changedArgument)
Modified: llvm/trunk/test/Transforms/MemCpyOpt/2008-06-01-MemCpy-MemMove.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/MemCpyOpt/2008-06-01-MemCpy-MemMove.ll?rev=51850&r1=51849&r2=51850&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/MemCpyOpt/2008-06-01-MemCpy-MemMove.ll (original)
+++ llvm/trunk/test/Transforms/MemCpyOpt/2008-06-01-MemCpy-MemMove.ll Sun Jun 1 17:26:26 2008
@@ -1,4 +1,4 @@
-; RUN: llvm-as < %s | opt -memcpyopt | llvm-dis | grep {call.*memcpy.*}
+; RUN: llvm-as < %s | opt -memcpyopt | llvm-dis | grep {call.*memmove.*arg1.*}
; PR2401
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
More information about the llvm-commits
mailing list