[PATCH] D37790: ThinLTOBitcodeWriter: Drop dead constant users before checking whether globals have no users.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 20:59:45 PDT 2017


pcc created this revision.
Herald added subscribers: hiraditya, eraman, inglorion, mehdi_amini.

With this change we can avoid promotion more often.


https://reviews.llvm.org/D37790

Files:
  llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
  llvm/test/Transforms/ThinLTOBitcodeWriter/split-internal3.ll


Index: llvm/test/Transforms/ThinLTOBitcodeWriter/split-internal3.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/ThinLTOBitcodeWriter/split-internal3.ll
@@ -0,0 +1,12 @@
+; RUN: opt -thinlto-bc -o %t %s
+; RUN: llvm-modextract -b -n 0 -o %t0 %t
+; RUN: llvm-modextract -b -n 1 -o %t1 %t
+; RUN: llvm-dis -o - %t0 | FileCheck --check-prefix=M0 %s
+; RUN: llvm-dis -o - %t1 | FileCheck --check-prefix=M1 %s
+
+; M0-NOT: @"g2$
+; M1: @g2 = internal
+ at g1 = global i8* bitcast (i8** @g2 to i8*), !type !0
+ at g2 = internal global i8* null, !type !0
+
+!0 = !{i32 0, !"typeid"}
Index: llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
===================================================================
--- llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -41,8 +41,13 @@
 
     auto Name = ExportGV.getName();
     GlobalValue *ImportGV = ImportM.getNamedValue(Name);
-    if ((!ImportGV || ImportGV->use_empty()) && !PromoteExtra.count(&ExportGV))
-      continue;
+    if (!PromoteExtra.count(&ExportGV)) {
+      if (!ImportGV)
+        continue;
+      ImportGV->removeDeadConstantUsers();
+      if (ImportGV->use_empty())
+        continue;
+    }
 
     std::string NewName = (Name + ModuleId).str();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37790.114963.patch
Type: text/x-patch
Size: 1320 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170913/a7bcd2dc/attachment.bin>


More information about the llvm-commits mailing list