diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index c7f71a6d500..d959a223cac 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -2403,18 +2403,19 @@ static bool EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB, UndefValue::get(Ty), AI->getName())); InstResult = AllocaTmps.back(); - } else if (CallInst *CI = dyn_cast(CurInst)) { + } else if (isa(CurInst) || isa(CurInst)) { + CallSite CS(CurInst); // Debug info can safely be ignored here. - if (isa(CI)) { + if (isa(CS.getInstruction())) { ++CurInst; continue; } // Cannot handle inline asm. - if (isa(CI->getCalledValue())) return false; + if (isa(CS.getCalledValue())) return false; - if (MemSetInst *MSI = dyn_cast(CI)) { + if (MemSetInst *MSI = dyn_cast(CS.getInstruction())) { if (MSI->isVolatile()) return false; Constant *Ptr = getVal(Values, MSI->getDest()); Constant *Val = getVal(Values, MSI->getValue()); @@ -2430,13 +2431,12 @@ static bool EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB, // Resolve function pointers. Function *Callee = dyn_cast(getVal(Values, - CI->getCalledValue())); - if (!Callee) return false; // Cannot resolve. + CS.getCalledValue())); + if (!Callee || Callee->mayBeOverridden()) + return false; // Cannot resolve. SmallVector Formals; - CallSite CS(CI); - for (User::op_iterator i = CS.arg_begin(), e = CS.arg_end(); - i != e; ++i) + for (User::op_iterator i = CS.arg_begin(), e = CS.arg_end(); i != e; ++i) Formals.push_back(getVal(Values, *i)); if (Callee->isDeclaration()) { @@ -2457,6 +2457,11 @@ static bool EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB, TLI)) return false; InstResult = RetVal; + + if (InvokeInst *II = dyn_cast(CurInst)) { + NextBB = II->getNormalDest(); + return true; + } } } else if (isa(CurInst)) { if (BranchInst *BI = dyn_cast(CurInst)) {