1; REQUIRES: x86
2; RUN: llvm-as -o %T/comdat-main.lto.obj %s
3; RUN: llvm-as -o %T/comdat1.lto.obj %S/Inputs/lto-comdat1.ll
4; RUN: llvm-as -o %T/comdat2.lto.obj %S/Inputs/lto-comdat2.ll
5; RUN: rm -f %T/comdat.lto.lib
6; RUN: llvm-ar cru %T/comdat.lto.lib %T/comdat1.lto.obj %T/comdat2.lto.obj
7
8; RUN: llc -filetype=obj -o %T/comdat-main.obj %s
9; RUN: llc -filetype=obj -o %T/comdat1.obj %S/Inputs/lto-comdat1.ll
10; RUN: llc -filetype=obj -o %T/comdat2.obj %S/Inputs/lto-comdat2.ll
11; RUN: rm -f %T/comdat.lib
12; RUN: llvm-ar cru %T/comdat.lib %T/comdat1.obj %T/comdat2.obj
13
14; Check that, when we use an LTO main with LTO objects, we optimize away all
15; of f1, f2, and comdat.
16; RUN: lld-link /out:%T/comdat-main.exe /entry:main /subsystem:console %T/comdat-main.lto.obj %T/comdat1.lto.obj %T/comdat2.lto.obj
17; RUN: llvm-readobj --file-headers %T/comdat-main.exe | FileCheck -check-prefix=HEADERS-11 %s
18; RUN: llvm-objdump -d %T/comdat-main.exe | FileCheck --check-prefix=TEXT-11 %s
19; RUN: lld-link /out:%T/comdat-main.exe /entry:main /subsystem:console %T/comdat-main.lto.obj %T/comdat.lto.lib
20; RUN: llvm-readobj --file-headers %T/comdat-main.exe | FileCheck -check-prefix=HEADERS-11 %s
21; RUN: llvm-objdump -d %T/comdat-main.exe | FileCheck --check-prefix=TEXT-11 %s
22
23; Check that, when we use a non-LTO main with LTO objects, we pick the comdat
24; implementation in LTO, elide calls to it from inside LTO, and retain the
25; call to comdat from main.
26; RUN: lld-link /out:%T/comdat-main.exe /entry:main /subsystem:console %T/comdat-main.obj %T/comdat1.lto.obj %T/comdat2.lto.obj
27; RUN: llvm-readobj --file-headers %T/comdat-main.exe | FileCheck -check-prefix=HEADERS-01 %s
28; RUN: llvm-objdump -d %T/comdat-main.exe | FileCheck --check-prefix=TEXT-01 %s
29; RUN: lld-link /out:%T/comdat-main.exe /entry:main /subsystem:console %T/comdat-main.obj %T/comdat.lto.lib
30; RUN: llvm-readobj --file-headers %T/comdat-main.exe | FileCheck -check-prefix=HEADERS-01 %s
31; RUN: llvm-objdump -d %T/comdat-main.exe | FileCheck --check-prefix=TEXT-01 %s
32
33; Check that, when we use an LTO main with non-LTO objects, we pick the comdat
34; implementation in LTO, elide the call to it from inside LTO, and keep the
35; calls to comdat from the non-LTO objects.
36; RUN: lld-link /out:%T/comdat-main.exe /entry:main /subsystem:console %T/comdat-main.lto.obj %T/comdat1.obj %T/comdat2.obj
37; RUN: llvm-readobj --file-headers %T/comdat-main.exe | FileCheck -check-prefix=HEADERS-10 %s
38; RUN: llvm-objdump -d %T/comdat-main.exe | FileCheck --check-prefix=TEXT-10 %s
39; RUN: lld-link /out:%T/comdat-main.exe /entry:main /subsystem:console %T/comdat-main.lto.obj %T/comdat.lib
40; RUN: llvm-readobj --file-headers %T/comdat-main.exe | FileCheck -check-prefix=HEADERS-10 %s
41; RUN: llvm-objdump -d %T/comdat-main.exe | FileCheck --check-prefix=TEXT-10 %s
42
43; HEADERS-11: AddressOfEntryPoint: 0x1000
44; TEXT-11: Disassembly of section .text:
45; TEXT-11-EMPTY:
46; TEXT-11-NEXT: <.text>:
47; TEXT-11-NEXT: xorl	%eax, %eax
48; TEXT-11-NEXT: retq
49
50; HEADERS-01: AddressOfEntryPoint: 0x1000
51; TEXT-01: Disassembly of section .text:
52; TEXT-01-EMPTY:
53; TEXT-01-NEXT: <.text>:
54; TEXT-01-NEXT: subq	$40, %rsp
55; TEXT-01-NEXT: callq	0x140001020
56; TEXT-01-NEXT: callq	0x140001020
57; TEXT-01-NEXT: callq	0x140001020
58; TEXT-01-NEXT: xorl	%eax, %eax
59; TEXT-01-NEXT: addq	$40, %rsp
60; TEXT-01: retq
61; TEXT-01-NOT: callq
62; TEXT-01: retq
63; TEXT-01: int3
64; TEXT-01: int3
65; TEXT-01: int3
66; TEXT-01-NOT: {{.}}
67
68; HEADERS-10: AddressOfEntryPoint: 0x1020
69; TEXT-10: Disassembly of section .text:
70; TEXT-10-EMPTY:
71; TEXT-10-NEXT: <.text>:
72; TEXT-10-NEXT: subq	$40, %rsp
73; TEXT-10-NEXT: callq	0x140001040
74; TEXT-10-NEXT: nop
75; TEXT-10-NEXT: addq	$40, %rsp
76; TEXT-10-NEXT: retq
77; TEXT-10-NEXT: int3
78; TEXT-10-NEXT: subq	$40, %rsp
79; TEXT-10-NEXT: callq	0x140001040
80; TEXT-10-NEXT: nop
81; TEXT-10-NEXT: addq	$40, %rsp
82; TEXT-10-NEXT: retq
83; TEXT-10-NEXT: int3
84; TEXT-10-NEXT: subq	$40, %rsp
85; TEXT-10-NEXT: callq	0x140001000
86; TEXT-10-NEXT: callq	0x140001010
87; TEXT-10-NEXT: xorl	%eax, %eax
88; TEXT-10-NEXT: addq	$40, %rsp
89; TEXT-10-NEXT: retq
90; TEXT-10-NOT: callq
91; TEXT-10: retq
92; TEXT-10-NOT: {{.}}
93
94target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
95target triple = "x86_64-pc-windows-msvc"
96
97$comdat = comdat any
98
99define i32 @main() {
100  call void @f1()
101  call void @f2()
102  call void @comdat()
103  ret i32 0
104}
105
106define linkonce_odr void @comdat() comdat {
107  ret void
108}
109
110declare void @f1()
111declare void @f2()
112