diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index dc6d497bd00..3ca03b3c1d9 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -750,7 +750,7 @@ void SCCPSolver::visitInsertValueInst(InsertValueInst &IVI) { Value *Val = IVI.getOperand(1); // If the operand to the getresult is an undef, the result is undef. - if (isa(Aggr)) + if (isa(Aggr) && isa(Val)) return; // Currently only handle single-index insertvalues. @@ -758,6 +758,23 @@ void SCCPSolver::visitInsertValueInst(InsertValueInst &IVI) { markOverdefined(&IVI); return; } + + // Currently only handle insertvalue instructions that are in a single-use + // chain that builds up a return value. + for (const InsertValueInst *TmpIVI = &IVI; ; ) { + if (!TmpIVI->hasOneUse()) { + markOverdefined(&IVI); + return; + } + const Value *V = *TmpIVI->use_begin(); + if (isa(V)) + break; + TmpIVI = dyn_cast(V); + if (!TmpIVI) { + markOverdefined(&IVI); + return; + } + } // See if we are tracking the result of the callee. Function *F = IVI.getParent()->getParent();