diff options
author | Chris Lattner <sabre@nondot.org> | 2004-12-11 02:53:57 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-12-11 02:53:57 +0000 |
commit | 0417feba293f58e90a7f959a4f85120dfcbda8d7 (patch) | |
tree | f21ae6b9e100a9b2071a3d91c08b592a589479ae /lib/Transforms | |
parent | 1fce09125cb46c91407668ca29915c450a482811 (diff) |
Fix a bug where we could delete dead invoke instructions with uses.
In functions where we fully constant prop the return value, replace all
ret instructions with 'ret undef'.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18786 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/Scalar/SCCP.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index f6be510fb0..602f432aba 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -172,6 +172,13 @@ public: return ValueState; } + /// getTrackedFunctionRetVals - Get the inferred return value map. + /// + const hash_map<Function*, LatticeVal> &getTrackedFunctionRetVals() { + return TrackedFunctionRetVals; + } + + private: // markConstant - Make a value be marked as "constant". If the value // is not already a constant, add it to the instruction work list so that @@ -1138,6 +1145,8 @@ bool IPSCCP::runOnModule(Module &M) { if (Succ->begin() != Succ->end() && isa<PHINode>(Succ->begin())) TI->getSuccessor(i)->removePredecessor(BB); } + if (!TI->use_empty()) + TI->replaceAllUsesWith(UndefValue::get(TI->getType())); BB->getInstList().erase(TI); } else { @@ -1183,5 +1192,22 @@ bool IPSCCP::runOnModule(Module &M) { F->getBasicBlockList().erase(DeadBB); } } + + // If we inferred constant or undef return values for a function, we replaced + // all call uses with the inferred value. This means we don't need to bother + // actually returning anything from the function. Replace all return + // instructions with return undef. + const hash_map<Function*, LatticeVal> &RV =Solver.getTrackedFunctionRetVals(); + for (hash_map<Function*, LatticeVal>::const_iterator I = RV.begin(), + E = RV.end(); I != E; ++I) + if (!I->second.isOverdefined() && + I->first->getReturnType() != Type::VoidTy) { + Function *F = I->first; + for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) + if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) + if (!isa<UndefValue>(RI->getOperand(0))) + RI->setOperand(0, UndefValue::get(F->getReturnType())); + } + return MadeChanges; } |