[llvm] r319494 - ThinLTOBitcodeWriter: Try harder to discard unused references to the merged module.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 30 15:05:52 PST 2017


Author: pcc
Date: Thu Nov 30 15:05:52 2017
New Revision: 319494

URL: http://llvm.org/viewvc/llvm-project?rev=319494&view=rev
Log:
ThinLTOBitcodeWriter: Try harder to discard unused references to the merged module.

If the thin module has no references to an internal global in the
merged module, we need to make sure to preserve that property if the
global is a member of a comdat group, as otherwise promotion can end
up adding global symbols to the comdat, which is not allowed.

This situation can arise if the external global in the thin module
has dead constant users, which would cause use_empty() to return
false and would cause us to try to promote it. To prevent this from
happening, discard the dead constant users before asking whether a
global is empty.

Differential Revision: https://reviews.llvm.org/D40593

Modified:
    llvm/trunk/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
    llvm/trunk/test/Transforms/ThinLTOBitcodeWriter/filter-alias.ll

Modified: llvm/trunk/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp?rev=319494&r1=319493&r2=319494&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp Thu Nov 30 15:05:52 2017
@@ -40,9 +40,17 @@ void promoteInternals(Module &ExportM, M
       continue;
 
     auto Name = ExportGV.getName();
-    GlobalValue *ImportGV = ImportM.getNamedValue(Name);
-    if ((!ImportGV || ImportGV->use_empty()) && !PromoteExtra.count(&ExportGV))
-      continue;
+    GlobalValue *ImportGV = nullptr;
+    if (!PromoteExtra.count(&ExportGV)) {
+      ImportGV = ImportM.getNamedValue(Name);
+      if (!ImportGV)
+        continue;
+      ImportGV->removeDeadConstantUsers();
+      if (ImportGV->use_empty()) {
+        ImportGV->eraseFromParent();
+        continue;
+      }
+    }
 
     std::string NewName = (Name + ModuleId).str();
 

Modified: llvm/trunk/test/Transforms/ThinLTOBitcodeWriter/filter-alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ThinLTOBitcodeWriter/filter-alias.ll?rev=319494&r1=319493&r2=319494&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ThinLTOBitcodeWriter/filter-alias.ll (original)
+++ llvm/trunk/test/Transforms/ThinLTOBitcodeWriter/filter-alias.ll Thu Nov 30 15:05:52 2017
@@ -1,7 +1,9 @@
 ; RUN: opt -thinlto-bc -o %t %s
 ; RUN: llvm-modextract -n 0 -o - %t | llvm-dis | FileCheck --check-prefix=CHECK0 %s
 ; RUN: llvm-modextract -n 1 -o - %t | llvm-dis | FileCheck --check-prefix=CHECK1 %s
+; CHECK0-NOT: @{{.*}}anon{{.*}}=
 ; CHECK0: @al = external global i8*
+; CHECK0-NOT: @{{.*}}anon{{.*}}=
 ; CHECK1: @al = unnamed_addr alias i8*,
 
 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"




More information about the llvm-commits mailing list