forked from OSchip/llvm-project
Move the object size intrinsic optimization to inst-combine and make
it work for any integer size return type. llvm-svn: 92853
This commit is contained in:
parent
746012a6c1
commit
2cdb806fd8
|
@ -632,6 +632,18 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
||||||
return EraseInstFromFunction(CI);
|
return EraseInstFromFunction(CI);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case Intrinsic::objectsize: {
|
||||||
|
ConstantInt *Const = dyn_cast<ConstantInt>(II->getOperand(2));
|
||||||
|
|
||||||
|
if (!Const) return 0;
|
||||||
|
|
||||||
|
const Type *Ty = CI.getType();
|
||||||
|
|
||||||
|
if (Const->getZExtValue() == 0)
|
||||||
|
return ReplaceInstUsesWith(CI, Constant::getAllOnesValue(Ty));
|
||||||
|
else
|
||||||
|
return ReplaceInstUsesWith(CI, ConstantInt::get(Ty, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return visitCallSite(II);
|
return visitCallSite(II);
|
||||||
|
|
|
@ -1094,27 +1094,6 @@ struct MemSetOpt : public LibCallOptimization {
|
||||||
// Object Size Checking Optimizations
|
// Object Size Checking Optimizations
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
//===---------------------------------------===//
|
|
||||||
// 'object size'
|
|
||||||
namespace {
|
|
||||||
struct SizeOpt : public LibCallOptimization {
|
|
||||||
virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
|
|
||||||
// TODO: We can do more with this, but delaying to here should be no change
|
|
||||||
// in behavior.
|
|
||||||
ConstantInt *Const = dyn_cast<ConstantInt>(CI->getOperand(2));
|
|
||||||
|
|
||||||
if (!Const) return 0;
|
|
||||||
|
|
||||||
const Type *Ty = Callee->getFunctionType()->getReturnType();
|
|
||||||
|
|
||||||
if (Const->getZExtValue() == 0)
|
|
||||||
return Constant::getAllOnesValue(Ty);
|
|
||||||
else
|
|
||||||
return ConstantInt::get(Ty, 0);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
//===---------------------------------------===//
|
//===---------------------------------------===//
|
||||||
// 'memcpy_chk' Optimizations
|
// 'memcpy_chk' Optimizations
|
||||||
|
|
||||||
|
@ -1745,7 +1724,6 @@ namespace {
|
||||||
FWriteOpt FWrite; FPutsOpt FPuts; FPrintFOpt FPrintF;
|
FWriteOpt FWrite; FPutsOpt FPuts; FPrintFOpt FPrintF;
|
||||||
|
|
||||||
// Object Size Checking
|
// Object Size Checking
|
||||||
SizeOpt ObjectSize;
|
|
||||||
MemCpyChkOpt MemCpyChk; MemSetChkOpt MemSetChk; MemMoveChkOpt MemMoveChk;
|
MemCpyChkOpt MemCpyChk; MemSetChkOpt MemSetChk; MemMoveChkOpt MemMoveChk;
|
||||||
|
|
||||||
bool Modified; // This is only used by doInitialization.
|
bool Modified; // This is only used by doInitialization.
|
||||||
|
@ -1855,8 +1833,6 @@ void SimplifyLibCalls::InitOptimizations() {
|
||||||
Optimizations["fprintf"] = &FPrintF;
|
Optimizations["fprintf"] = &FPrintF;
|
||||||
|
|
||||||
// Object Size Checking
|
// Object Size Checking
|
||||||
Optimizations["llvm.objectsize.i32"] = &ObjectSize;
|
|
||||||
Optimizations["llvm.objectsize.i64"] = &ObjectSize;
|
|
||||||
Optimizations["__memcpy_chk"] = &MemCpyChk;
|
Optimizations["__memcpy_chk"] = &MemCpyChk;
|
||||||
Optimizations["__memset_chk"] = &MemSetChk;
|
Optimizations["__memset_chk"] = &MemSetChk;
|
||||||
Optimizations["__memmove_chk"] = &MemMoveChk;
|
Optimizations["__memmove_chk"] = &MemMoveChk;
|
||||||
|
|
Loading…
Reference in New Issue