mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
instcombine: Migrate memset optimizations
This patch migrates the memset optimizations from the simplify-libcalls pass into the instcombine library call simplifier. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167689 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -997,6 +997,25 @@ struct MemMoveOpt : public LibCallOptimization {
|
||||
}
|
||||
};
|
||||
|
||||
struct MemSetOpt : 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)->isIntegerTy() ||
|
||||
FT->getParamType(2) != TD->getIntPtrType(*Context))
|
||||
return 0;
|
||||
|
||||
// memset(p, v, n) -> llvm.memset(p, v, n, 1)
|
||||
Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(), false);
|
||||
B.CreateMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), 1);
|
||||
return CI->getArgOperand(0);
|
||||
}
|
||||
};
|
||||
|
||||
} // End anonymous namespace.
|
||||
|
||||
namespace llvm {
|
||||
@@ -1036,6 +1055,7 @@ class LibCallSimplifierImpl {
|
||||
MemCmpOpt MemCmp;
|
||||
MemCpyOpt MemCpy;
|
||||
MemMoveOpt MemMove;
|
||||
MemSetOpt MemSet;
|
||||
|
||||
void initOptimizations();
|
||||
void addOpt(LibFunc::Func F, LibCallOptimization* Opt);
|
||||
@@ -1087,6 +1107,7 @@ void LibCallSimplifierImpl::initOptimizations() {
|
||||
addOpt(LibFunc::memcmp, &MemCmp);
|
||||
addOpt(LibFunc::memcpy, &MemCpy);
|
||||
addOpt(LibFunc::memmove, &MemMove);
|
||||
addOpt(LibFunc::memset, &MemSet);
|
||||
}
|
||||
|
||||
Value *LibCallSimplifierImpl::optimizeCall(CallInst *CI) {
|
||||
|
Reference in New Issue
Block a user