diff --git a/lib/Transforms/LevelRaise.cpp b/lib/Transforms/LevelRaise.cpp index 50ed60c9037..2e9d8c2f8c8 100644 --- a/lib/Transforms/LevelRaise.cpp +++ b/lib/Transforms/LevelRaise.cpp @@ -504,8 +504,18 @@ bool RPR::PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) { PointerType *NewPFunTy = PointerType::get(NewFT); // Create a new cast, inserting it right before the function call... - CastInst *NewCast = new CastInst(CI->getCalledValue(), NewPFunTy, - CI->getCalledValue()->getName()+"_c",CI); + Value *NewCast; + Constant *ConstantCallSrc = 0; + if (Constant *CS = dyn_cast(CI->getCalledValue())) + ConstantCallSrc = CS; + else if (GlobalValue *GV = dyn_cast(CI->getCalledValue())) + ConstantCallSrc = ConstantPointerRef::get(GV); + + if (ConstantCallSrc) + NewCast = ConstantExpr::getCast(ConstantCallSrc, NewPFunTy); + else + NewCast = new CastInst(CI->getCalledValue(), NewPFunTy, + CI->getCalledValue()->getName()+"_c",CI); // Create a new call instruction... CallInst *NewCall = new CallInst(NewCast,