diff --git a/lib/Transforms/InstCombine/InstCombineCalls.cpp b/lib/Transforms/InstCombine/InstCombineCalls.cpp index 6aacf5dd0ef..e34360087c6 100644 --- a/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -632,6 +632,18 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { return EraseInstFromFunction(CI); break; } + case Intrinsic::objectsize: { + ConstantInt *Const = dyn_cast(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); diff --git a/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/lib/Transforms/Scalar/SimplifyLibCalls.cpp index c67c9cf03f2..9183f3aac1f 100644 --- a/lib/Transforms/Scalar/SimplifyLibCalls.cpp +++ b/lib/Transforms/Scalar/SimplifyLibCalls.cpp @@ -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(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;