From 456861c11559bd2cc2a1cffdb0037c1a6f97e289 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 22 Dec 2006 23:14:42 +0000 Subject: [PATCH] add a simple fast-path for dead allocas llvm-svn: 32750 --- lib/Transforms/Scalar/ScalarReplAggregates.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp index 160128eba1d..a92592b8166 100644 --- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp +++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp @@ -139,6 +139,13 @@ bool SROA::performScalarRepl(Function &F) { AllocationInst *AI = WorkList.back(); WorkList.pop_back(); + // Handle dead allocas trivially. These can be formed by SROA'ing arrays + // with unused elements. + if (AI->use_empty()) { + AI->eraseFromParent(); + continue; + } + // If we can turn this aggregate value (potentially with casts) into a // simple scalar value that can be mem2reg'd into a register value. bool IsNotTrivial = false; @@ -232,7 +239,7 @@ bool SROA::performScalarRepl(Function &F) { } // Finally, delete the Alloca instruction - AI->getParent()->getInstList().erase(AI); + AI->eraseFromParent(); NumReplaced++; }