Skip to content

Commit 543500a

Browse files
Add a test for deduplication.
1 parent 64f6c57 commit 543500a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

lld/test/COFF/common-dedup.ll

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; REQUIRES: x86
2+
; RUN: split-file %s %t.dir
3+
; RUN: llc %t.dir/t1.ll -o %t.t1.obj --filetype=obj
4+
; RUN: llc %t.dir/t2.ll -o %t.t2.obj --filetype=obj
5+
; RUN: lld-link %t.t1.obj %t.t2.obj -entry:main -out:%t.exe
6+
; RUN: llvm-readobj --section-headers %t.exe | FileCheck %s
7+
8+
; Make sure that the data section contains just one copy of @a, not two.
9+
; CHECK: Name: .data
10+
; CHECK-NEXT: VirtualSize: 0x1000
11+
12+
;--- t1.ll
13+
target triple = "x86_64-pc-windows-msvc"
14+
@a = common global [4096 x i8] zeroinitializer
15+
16+
define i32 @usea() {
17+
%ref_common = load i32, ptr @a
18+
ret i32 %ref_common
19+
}
20+
21+
;--- t2.ll
22+
target triple = "x86_64-pc-windows-msvc"
23+
@a = common global [4096 x i8] zeroinitializer
24+
25+
define i32 @useb() {
26+
%ref_common = load i32, ptr @a
27+
ret i32 %ref_common
28+
}
29+
30+
declare i32 @usea()
31+
32+
define dso_local i32 @main() local_unnamed_addr {
33+
entry:
34+
%a = tail call i32 @usea()
35+
%b = tail call i32 @useb()
36+
%add = add nsw i32 %a, %b
37+
ret i32 %add
38+
}

0 commit comments

Comments
 (0)