aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-10-10 16:47:33 +0000
committerChris Lattner <sabre@nondot.org>2004-10-10 16:47:33 +0000
commitc4d81b0388dff9f38e1387bb223cc7b514c06d01 (patch)
tree412e4166f23812eef912be34f73b170e1922fafe
parentba31f8098f339acd272b5de195f3f525c17dd8e6 (diff)
Implement GlobalOpt/deadglobal-2.llx, deletion of globals that are only
stored to, but are stored at variable indexes. This occurs at least in 176.gcc, but probably others, and we should handle it for completeness. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16876 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index 7c0c322512..3a58afdc26 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -259,6 +259,17 @@ static bool CleanupConstantGlobalUsers(Value *V, Constant *Init) {
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(U)) {
if (Constant *SubInit = TraverseGEPInitializer(GEP, Init))
Changed |= CleanupConstantGlobalUsers(GEP, SubInit);
+ else {
+ // If this GEP has variable indexes, we should still be able to delete
+ // any stores through it.
+ for (Value::use_iterator GUI = GEP->use_begin(), E = GEP->use_end();
+ GUI != E;)
+ if (StoreInst *SI = dyn_cast<StoreInst>(*GUI++)) {
+ SI->getParent()->getInstList().erase(SI);
+ Changed = true;
+ }
+ }
+
if (GEP->use_empty()) {
GEP->getParent()->getInstList().erase(GEP);
Changed = true;