Fix bug: ConstantMerge/2003-10-28-MergeExternalConstants.ll & PR64
authorChris Lattner <sabre@nondot.org>
Wed, 29 Oct 2003 06:01:26 +0000 (06:01 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 29 Oct 2003 06:01:26 +0000 (06:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9579 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/ConstantMerge.cpp

index e353a455467bc53887f2b653b0c2aaab96ca34eb..a4526820e61af4a8c075395521a1a7ad93d6c457 100644 (file)
@@ -52,14 +52,25 @@ 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;
       }