[GlobalMerge] Don't merge dllexport globals

Merging such globals loses the dllexport attribute. Add a test
to check that normal globals still are merged.

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

llvm-svn: 323307
This commit is contained in:
Martin Storsjo 2018-01-24 06:40:04 +00:00
parent ae21466138
commit e8248f2e10
3 changed files with 32 additions and 1 deletions

View File

@ -577,7 +577,8 @@ bool GlobalMerge::doInitialization(Module &M) {
for (auto &GV : M.globals()) {
// Merge is safe for "normal" internal or external globals only
if (GV.isDeclaration() || GV.isThreadLocal() ||
GV.hasSection() || GV.hasImplicitSection())
GV.hasSection() || GV.hasImplicitSection() ||
GV.hasDLLExportStorageClass())
continue;
// It's not safe to merge globals that may be preempted

View File

@ -0,0 +1,15 @@
; RUN: llc < %s -mtriple=thumbv7-win32 -arm-global-merge | FileCheck %s
@x = global i32 0, align 4
@y = dllexport global i32 0, align 4
define void @f1(i32 %a1, i32 %a2) {
; CHECK: f1:
; CHECK: movw [[REG1:r[0-9]+]], :lower16:x
; CHECK: movt [[REG1]], :upper16:x
store i32 %a1, i32* @x, align 4
store i32 %a2, i32* @y, align 4
ret void
}
; CHECK-NOT: .L_MergedGlobals

View File

@ -3,6 +3,7 @@
; RUN: llc < %s -mtriple=arm-eabi -arm-global-merge -global-merge-on-external=false | FileCheck %s --check-prefixes=CHECK,CHECK-NO-MERGE
; RUN: llc < %s -mtriple=arm-macho -arm-global-merge | FileCheck %s --check-prefixes=CHECK,CHECK-NO-MERGE
; RUN: llc < %s -mtriple=arm-eabi -arm-global-merge -relocation-model=pic | FileCheck %s --check-prefixes=CHECK,CHECK-NO-MERGE
; RUN: llc < %s -mtriple=thumbv7-win32 -arm-global-merge | FileCheck %s --check-prefixes=CHECK-WIN32
@x = global i32 0, align 4
@y = global i32 0, align 4
@ -14,6 +15,9 @@ define void @f1(i32 %a1, i32 %a2) {
;CHECK: [[LABEL1]]:
;CHECK-MERGE: .long .L_MergedGlobals
;CHECK-NO-MERGE: .long {{_?x}}
;CHECK-WIN32: f1:
;CHECK-WIN32: movw [[REG1:r[0-9]+]], :lower16:.L_MergedGlobals
;CHECK-WIN32: movt [[REG1]], :upper16:.L_MergedGlobals
store i32 %a1, i32* @x, align 4
store i32 %a2, i32* @y, align 4
ret void
@ -25,6 +29,9 @@ define void @g1(i32 %a1, i32 %a2) {
;CHECK: [[LABEL2]]:
;CHECK-MERGE: .long .L_MergedGlobals
;CHECK-NO-MERGE: .long {{_?y}}
;CHECK-WIN32: g1:
;CHECK-WIN32: movw [[REG2:r[0-9]+]], :lower16:.L_MergedGlobals
;CHECK-WIN32: movt [[REG2]], :upper16:.L_MergedGlobals
store i32 %a1, i32* @y, align 4
store i32 %a2, i32* @z, align 4
ret void
@ -35,6 +42,7 @@ define void @g1(i32 %a1, i32 %a2) {
;CHECK-MERGE: .type .L_MergedGlobals,%object
;CHECK-MERGE: .local .L_MergedGlobals
;CHECK-MERGE: .comm .L_MergedGlobals,12,4
;CHECK-WIN32: .lcomm .L_MergedGlobals,12,4
;CHECK-MERGE: .globl x
;CHECK-MERGE: x = .L_MergedGlobals
@ -45,3 +53,10 @@ define void @g1(i32 %a1, i32 %a2) {
;CHECK-MERGE: .globl z
;CHECK-MERGE: z = .L_MergedGlobals+8
;CHECK-MERGE: .size z, 4
;CHECK-WIN32: .globl x
;CHECK-WIN32: x = .L_MergedGlobals
;CHECK-WIN32: .globl y
;CHECK-WIN32: y = .L_MergedGlobals+4
;CHECK-WIN32: .globl z
;CHECK-WIN32: z = .L_MergedGlobals+8