Move the object size intrinsic optimization to inst-combine and make

it work for any integer size return type.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92853 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Christopher 2010-01-06 20:04:44 +00:00
parent 54eb4c2991
commit 130063207d
2 changed files with 12 additions and 24 deletions

View File

@ -632,6 +632,18 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
return EraseInstFromFunction(CI);
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);

View File

@ -1094,27 +1094,6 @@ struct MemSetOpt : public LibCallOptimization {
// 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
@ -1745,7 +1724,6 @@ namespace {
FWriteOpt FWrite; FPutsOpt FPuts; FPrintFOpt FPrintF;
// Object Size Checking
SizeOpt ObjectSize;
MemCpyChkOpt MemCpyChk; MemSetChkOpt MemSetChk; MemMoveChkOpt MemMoveChk;
bool Modified; // This is only used by doInitialization.
@ -1855,8 +1833,6 @@ void SimplifyLibCalls::InitOptimizations() {
Optimizations["fprintf"] = &FPrintF;
// Object Size Checking
Optimizations["llvm.objectsize.i32"] = &ObjectSize;
Optimizations["llvm.objectsize.i64"] = &ObjectSize;
Optimizations["__memcpy_chk"] = &MemCpyChk;
Optimizations["__memset_chk"] = &MemSetChk;
Optimizations["__memmove_chk"] = &MemMoveChk;