diff options
| author | Chris Lattner <sabre@nondot.org> | 2005-10-24 06:22:12 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2005-10-24 06:22:12 +0000 |
| commit | ac87beb03accfa782685d54fcc6fd164934f5c70 (patch) | |
| tree | 92295297d2d24e00558b7d754b70d75c1810c938 /llvm/lib/Transforms | |
| parent | 216be91817e5171845ff7b6c733962fed9d73964 (diff) | |
| download | bcm5719-llvm-ac87beb03accfa782685d54fcc6fd164934f5c70.tar.gz bcm5719-llvm-ac87beb03accfa782685d54fcc6fd164934f5c70.zip | |
Before promoting a malloc type, remove dead uses. This makes instcombine
more effective at promoting these allocations, catching them earlier in the
compile process.
llvm-svn: 23959
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 4c6b6a82d7d..09fee7cc4bd 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -3769,6 +3769,26 @@ Instruction *InstCombiner::PromoteCastOfAllocation(CastInst &CI, const PointerType *PTy = dyn_cast<PointerType>(CI.getType()); if (AI.isArrayAllocation() || !PTy) return 0; + // Remove any uses of AI that are dead. + assert(!CI.use_empty() && "Dead instructions should be removed earlier!"); + std::vector<Instruction*> DeadUsers; + for (Value::use_iterator UI = AI.use_begin(), E = AI.use_end(); UI != E; ) { + Instruction *User = cast<Instruction>(*UI++); + if (isInstructionTriviallyDead(User)) { + while (UI != E && *UI == User) + ++UI; // If this instruction uses AI more than once, don't break UI. + + // Add operands to the worklist. + AddUsesToWorkList(*User); + ++NumDeadInst; + DEBUG(std::cerr << "IC: DCE: " << *User); + + User->eraseFromParent(); + removeFromWorkList(User); + } + } + + // Finally, if the instruction now has one use, delete it. if (!AI.hasOneUse()) return 0; // Get the type really allocated and the type casted to. |

