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.

llvm-svn: 16876
This commit is contained in:
Chris Lattner 2004-10-10 16:47:33 +00:00
parent 924ce79136
commit a0e769cc81
1 changed files with 11 additions and 0 deletions

View File

@ -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;