mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-14 14:24:05 +00:00
instcombine: Migrate memcpy optimizations
This patch migrates the memcpy optimizations from the simplify-libcalls pass into the instcombine library call simplifier. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167686 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -959,6 +959,25 @@ struct MemCmpOpt : public LibCallOptimization {
|
||||
}
|
||||
};
|
||||
|
||||
struct MemCpyOpt : 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;
|
||||
|
||||
// memcpy(x, y, n) -> llvm.memcpy(x, y, n, 1)
|
||||
B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(1),
|
||||
CI->getArgOperand(2), 1);
|
||||
return CI->getArgOperand(0);
|
||||
}
|
||||
};
|
||||
|
||||
} // End anonymous namespace.
|
||||
|
||||
namespace llvm {
|
||||
@ -996,6 +1015,7 @@ class LibCallSimplifierImpl {
|
||||
|
||||
// Memory library call optimizations.
|
||||
MemCmpOpt MemCmp;
|
||||
MemCpyOpt MemCpy;
|
||||
|
||||
void initOptimizations();
|
||||
void addOpt(LibFunc::Func F, LibCallOptimization* Opt);
|
||||
@ -1045,6 +1065,7 @@ void LibCallSimplifierImpl::initOptimizations() {
|
||||
|
||||
// Memory library call optimizations.
|
||||
addOpt(LibFunc::memcmp, &MemCmp);
|
||||
addOpt(LibFunc::memcpy, &MemCpy);
|
||||
}
|
||||
|
||||
Value *LibCallSimplifierImpl::optimizeCall(CallInst *CI) {
|
||||
|
Reference in New Issue
Block a user