instcombine: Migrate memmove optimizations

This patch migrates the memmove optimizations from the simplify-libcalls
pass into the instcombine library call simplifier.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167687 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Meador Inge
2012-11-11 06:22:40 +00:00
parent 11b04b40f2
commit d7cb600514
5 changed files with 56 additions and 36 deletions

View File

@ -978,6 +978,25 @@ struct MemCpyOpt : public LibCallOptimization {
}
};
struct MemMoveOpt : public LibCallOptimization {
virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
// These optimizations require DataLayout.
if (!TD) return 0;
FunctionType *FT = Callee->getFunctionType();
if (FT->getNumParams() != 3 || FT->getReturnType() != FT->getParamType(0) ||
!FT->getParamType(0)->isPointerTy() ||
!FT->getParamType(1)->isPointerTy() ||
FT->getParamType(2) != TD->getIntPtrType(*Context))
return 0;
// memmove(x, y, n) -> llvm.memmove(x, y, n, 1)
B.CreateMemMove(CI->getArgOperand(0), CI->getArgOperand(1),
CI->getArgOperand(2), 1);
return CI->getArgOperand(0);
}
};
} // End anonymous namespace.
namespace llvm {
@ -1016,6 +1035,7 @@ class LibCallSimplifierImpl {
// Memory library call optimizations.
MemCmpOpt MemCmp;
MemCpyOpt MemCpy;
MemMoveOpt MemMove;
void initOptimizations();
void addOpt(LibFunc::Func F, LibCallOptimization* Opt);
@ -1066,6 +1086,7 @@ void LibCallSimplifierImpl::initOptimizations() {
// Memory library call optimizations.
addOpt(LibFunc::memcmp, &MemCmp);
addOpt(LibFunc::memcpy, &MemCpy);
addOpt(LibFunc::memmove, &MemMove);
}
Value *LibCallSimplifierImpl::optimizeCall(CallInst *CI) {