[llvm] r337973 - [GlobalMerge] Handle llvm.compiler.used correctly.

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 25 15:03:35 PDT 2018


Author: efriedma
Date: Wed Jul 25 15:03:35 2018
New Revision: 337973

URL: http://llvm.org/viewvc/llvm-project?rev=337973&view=rev
Log:
[GlobalMerge] Handle llvm.compiler.used correctly.

Reuse the handling for llvm.used, and don't transform such globals.

Fixes a failure on the asan buildbot caused by my previous commit.


Added:
    llvm/trunk/test/Transforms/GlobalMerge/used.ll
Modified:
    llvm/trunk/lib/CodeGen/GlobalMerge.cpp

Modified: llvm/trunk/lib/CodeGen/GlobalMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalMerge.cpp?rev=337973&r1=337972&r2=337973&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalMerge.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalMerge.cpp Wed Jul 25 15:03:35 2018
@@ -177,7 +177,7 @@ namespace {
     void setMustKeepGlobalVariables(Module &M);
 
     /// Collect every variables marked as "used"
-    void collectUsedGlobalVariables(Module &M);
+    void collectUsedGlobalVariables(Module &M, StringRef Name);
 
     /// Keep track of the GlobalVariable that must not be merged away
     SmallPtrSet<const GlobalVariable *, 16> MustKeepGlobalVariables;
@@ -558,9 +558,9 @@ bool GlobalMerge::doMerge(const SmallVec
   return Changed;
 }
 
-void GlobalMerge::collectUsedGlobalVariables(Module &M) {
+void GlobalMerge::collectUsedGlobalVariables(Module &M, StringRef Name) {
   // Extract global variables from llvm.used array
-  const GlobalVariable *GV = M.getGlobalVariable("llvm.used");
+  const GlobalVariable *GV = M.getGlobalVariable(Name);
   if (!GV || !GV->hasInitializer()) return;
 
   // Should be an array of 'i8*'.
@@ -573,7 +573,8 @@ void GlobalMerge::collectUsedGlobalVaria
 }
 
 void GlobalMerge::setMustKeepGlobalVariables(Module &M) {
-  collectUsedGlobalVariables(M);
+  collectUsedGlobalVariables(M, "llvm.used");
+  collectUsedGlobalVariables(M, "llvm.compiler.used");
 
   for (Function &F : M) {
     for (BasicBlock &BB : F) {

Added: llvm/trunk/test/Transforms/GlobalMerge/used.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalMerge/used.ll?rev=337973&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/GlobalMerge/used.ll (added)
+++ llvm/trunk/test/Transforms/GlobalMerge/used.ll Wed Jul 25 15:03:35 2018
@@ -0,0 +1,29 @@
+; RUN: opt -global-merge -global-merge-max-offset=100 -S -o - %s | FileCheck %s
+
+target datalayout = "e-p:64:64"
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK: @_MergedGlobals = private global <{ i32, i32 }> <{ i32 3, i32 3 }>, align 4
+
+ at a = internal global i32 1
+
+ at b = internal global i32 2
+
+ at c = internal global i32 3
+
+ at d = internal global i32 3
+
+ at llvm.used = appending global [1 x i8*] [i8* bitcast (i32* @a to i8*)], section "llvm.metadata"
+ at llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (i32* @b to i8*)], section "llvm.metadata"
+
+define void @use() {
+  ; CHECK: load i32, i32* @a
+  %x = load i32, i32* @a
+  ; CHECK: load i32, i32* @b
+  %y = load i32, i32* @b
+  ; CHECK: load i32, i32* getelementptr inbounds (<{ i32, i32 }>, <{ i32, i32 }>* @_MergedGlobals, i32 0, i32 0)
+  %z1 = load i32, i32* @c
+  ; CHECK: load i32, i32* getelementptr inbounds (<{ i32, i32 }>, <{ i32, i32 }>* @_MergedGlobals, i32 0, i32 1)
+  %z2 = load i32, i32* @d
+  ret void
+}




More information about the llvm-commits mailing list