summaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Scalar/MemCpyOptimizer.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2008-06-01 22:26:26 +0000
committerOwen Anderson <resistor@mac.com>2008-06-01 22:26:26 +0000
commit009e4f760969e3530cc2641a9599e646a20580c2 (patch)
treeaa5f76c5e74254032f78bc925e045f2d96b49c50 /lib/Transforms/Scalar/MemCpyOptimizer.cpp
parent19d4d12ee0e31505c3d776c29e3ad0b6c17cda67 (diff)
downloadexternal_llvm-009e4f760969e3530cc2641a9599e646a20580c2.zip
external_llvm-009e4f760969e3530cc2641a9599e646a20580c2.tar.gz
external_llvm-009e4f760969e3530cc2641a9599e646a20580c2.tar.bz2
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); git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51850 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/MemCpyOptimizer.cpp')
-rw-r--r--lib/Transforms/Scalar/MemCpyOptimizer.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index c599928..18f5f0c 100644
--- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -554,10 +554,17 @@ bool MemCpyOpt::performCallSlotOptzn(MemCpyInst *cpy, CallInst *C) {
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 @@ bool MemCpyOpt::performCallSlotOptzn(MemCpyInst *cpy, CallInst *C) {
// 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)