xref: /llvm-project/llvm/test/Transforms/Internalize/comdat.ll (revision 36df3fd67b3a897bc50e36786f9b6cc239fb9f08)
1a11faeedSBjorn Pettersson; RUN: opt < %s -mtriple=x86_64 -passes=internalize -internalize-public-api-list main -internalize-public-api-list c1 -internalize-public-api-list c2 \
238dbdde7SFangrui Song; RUN:   -internalize-public-api-list c3 -internalize-public-api-list c4 -S | FileCheck %s --check-prefixes=CHECK,NODUP
3a11faeedSBjorn Pettersson; RUN: opt < %s -mtriple=x86_64-windows -passes=internalize -internalize-public-api-list main -internalize-public-api-list c1 -internalize-public-api-list c2 \
438dbdde7SFangrui Song; RUN:   -internalize-public-api-list c3 -internalize-public-api-list c4 -S | FileCheck %s --check-prefixes=CHECK,NODUP
5a11faeedSBjorn Pettersson; RUN: opt < %s -mtriple=wasm32 -passes=internalize -internalize-public-api-list main -internalize-public-api-list c1 -internalize-public-api-list c2 \
638dbdde7SFangrui Song; RUN:   -internalize-public-api-list c3 -internalize-public-api-list c4 -S | FileCheck %s --check-prefixes=CHECK,WASM
7cee313d2SEric Christopher
8cee313d2SEric Christopher$c1 = comdat any
9cee313d2SEric Christopher$c2 = comdat any
10cee313d2SEric Christopher$c3 = comdat any
11cee313d2SEric Christopher$c4 = comdat any
12b426b45dSFangrui Song$c5 = comdat any
13b426b45dSFangrui Song
1438dbdde7SFangrui Song; CHECK: $c1 = comdat any
1538dbdde7SFangrui Song
1639248779SFangrui Song;; wasm doesn't support nodeduplicate.
1739248779SFangrui Song; NODUP: $c2 = comdat nodeduplicate
1838dbdde7SFangrui Song; WASM:  $c2 = comdat any
1938dbdde7SFangrui Song
2038dbdde7SFangrui Song; CHECK: $c3 = comdat any
2138dbdde7SFangrui Song; CHECK: $c4 = comdat any
22cee313d2SEric Christopher
23cee313d2SEric Christopher; CHECK: @c1_c = global i32 0, comdat($c1)
24cee313d2SEric Christopher@c1_c = global i32 0, comdat($c1)
25cee313d2SEric Christopher
26b426b45dSFangrui Song;; $c2 has more than one member. Keep the comdat.
2738dbdde7SFangrui Song; CHECK: @c2_b = internal global i32 0, comdat($c2)
28cee313d2SEric Christopher@c2_b = global i32 0, comdat($c2)
29cee313d2SEric Christopher
30cee313d2SEric Christopher; CHECK: @c3 = global i32 0, comdat{{$}}
31cee313d2SEric Christopher@c3 = global i32 0, comdat
32cee313d2SEric Christopher
33cee313d2SEric Christopher; CHECK: @c4_a = internal global i32 0, comdat($c4)
34cee313d2SEric Christopher@c4_a = internal global i32 0, comdat($c4)
35cee313d2SEric Christopher
36*36df3fd6SNikita Popov; CHECK: @c1_d = alias i32, ptr @c1_c
37*36df3fd6SNikita Popov@c1_d = alias i32, ptr @c1_c
38cee313d2SEric Christopher
39*36df3fd6SNikita Popov; CHECK: @c2_c = internal alias i32, ptr @c2_b
40*36df3fd6SNikita Popov@c2_c = alias i32, ptr @c2_b
41cee313d2SEric Christopher
42*36df3fd6SNikita Popov; CHECK: @c4 = alias i32, ptr @c4_a
43*36df3fd6SNikita Popov@c4 = alias i32, ptr @c4_a
44cee313d2SEric Christopher
45cee313d2SEric Christopher; CHECK: define void @c1() comdat {
46cee313d2SEric Christopherdefine void @c1() comdat {
47cee313d2SEric Christopher  ret void
48cee313d2SEric Christopher}
49cee313d2SEric Christopher
50cee313d2SEric Christopher; CHECK: define void @c1_a() comdat($c1) {
51cee313d2SEric Christopherdefine void @c1_a() comdat($c1) {
52cee313d2SEric Christopher  ret void
53cee313d2SEric Christopher}
54cee313d2SEric Christopher
5538dbdde7SFangrui Song; CHECK: define internal void @c2() comdat {
56cee313d2SEric Christopherdefine internal void @c2() comdat {
57cee313d2SEric Christopher  ret void
58cee313d2SEric Christopher}
59cee313d2SEric Christopher
6038dbdde7SFangrui Song; CHECK: define internal void @c2_a() comdat($c2) {
61cee313d2SEric Christopherdefine void @c2_a() comdat($c2) {
62cee313d2SEric Christopher  ret void
63cee313d2SEric Christopher}
64cee313d2SEric Christopher
65cee313d2SEric Christopher; CHECK: define void @c3_a() comdat($c3) {
66cee313d2SEric Christopherdefine void @c3_a() comdat($c3) {
67cee313d2SEric Christopher  ret void
68cee313d2SEric Christopher}
69b426b45dSFangrui Song
70b426b45dSFangrui Song;; There is only one member in the comdat. Delete the comdat as a size optimization.
71b426b45dSFangrui Song; CHECK: define internal void @c5() {
72b426b45dSFangrui Songdefine void @c5() comdat($c5) {
73b426b45dSFangrui Song  ret void
74b426b45dSFangrui Song}
75b426b45dSFangrui Song
76b426b45dSFangrui Song;; Add a non-comdat symbol to ensure the module ID is not empty so that we can
77b426b45dSFangrui Song;; create unique comdat names.
78b426b45dSFangrui Songdefine void @main() {
79b426b45dSFangrui Song  ret void
80b426b45dSFangrui Song}
81