summaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO/ConstantMerge.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-10-29 06:01:26 +0000
committerChris Lattner <sabre@nondot.org>2003-10-29 06:01:26 +0000
commit6ace4daa57c23f7dbd4534a3c6401af9609c4af7 (patch)
tree3067db4488797923e3647620f9eb2f969f27c0ca /lib/Transforms/IPO/ConstantMerge.cpp
parent851e07490c9db664aad27f66148ce336c136a818 (diff)
downloadllvm-6ace4daa57c23f7dbd4534a3c6401af9609c4af7.tar.gz
llvm-6ace4daa57c23f7dbd4534a3c6401af9609c4af7.tar.bz2
llvm-6ace4daa57c23f7dbd4534a3c6401af9609c4af7.tar.xz
Fix bug: ConstantMerge/2003-10-28-MergeExternalConstants.ll & PR64
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9579 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO/ConstantMerge.cpp')
-rw-r--r--lib/Transforms/IPO/ConstantMerge.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/Transforms/IPO/ConstantMerge.cpp b/lib/Transforms/IPO/ConstantMerge.cpp
index e353a45546..a4526820e6 100644
--- a/lib/Transforms/IPO/ConstantMerge.cpp
+++ b/lib/Transforms/IPO/ConstantMerge.cpp
@@ -52,16 +52,27 @@ bool ConstantMerge::run(Module &M) {
if (I == CMap.end()) { // Nope, add it to the map
CMap.insert(I, std::make_pair(Init, GV));
- } else { // Yup, this is a duplicate!
+ } else if (GV->hasInternalLinkage()) { // Yup, this is a duplicate!
// Make all uses of the duplicate constant use the canonical version...
GV->replaceAllUsesWith(I->second);
-
+
// Delete the global value from the module... and back up iterator to
// not skip the next global...
GV = --M.getGlobalList().erase(GV);
++NumMerged;
MadeChanges = true;
+ } else if (I->second->hasInternalLinkage()) {
+ // Make all uses of the duplicate constant use the canonical version...
+ I->second->replaceAllUsesWith(GV);
+
+ // Delete the global value from the module... and back up iterator to
+ // not skip the next global...
+ M.getGlobalList().erase(I->second);
+ I->second = GV;
+
+ ++NumMerged;
+ MadeChanges = true;
}
}