Skip to content

Commit d5c1d73

Browse files
authored
[ELF] Making cdsort default for function reordering (#68638)
CDSort function reordering outperforms the existing default heuristic ( hfsort/C^3) in terms of the performance of generated binaries while being (almost) as fast. Thus, the suggestion is to change the default. The speedup is up to 1.5% perf for large front-end binaries, and can be moderate/neutral for "small" benchmarks. High-level **perf impact** on two selected binaries: clang-10 binary (built with LTO+AutoFDO/CSSPGO): wins on top of C^3 in [0.3%..0.8%] rocksDB-8 binary (built with LTO+CSSPGO): wins on top of C^3 in [0.8%..1.5%] More detailed measurements on the clang binary is at [here](https://reviews.llvm.org/D152834#4445042)
1 parent fc654b4 commit d5c1d73

8 files changed

+12
-18
lines changed

lld/ELF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ static void ltoValidateAllVtablesHaveTypeInfos(opt::InputArgList &args) {
10951095
}
10961096

10971097
static CGProfileSortKind getCGProfileSortKind(opt::InputArgList &args) {
1098-
StringRef s = args.getLastArgValue(OPT_call_graph_profile_sort, "hfsort");
1098+
StringRef s = args.getLastArgValue(OPT_call_graph_profile_sort, "cdsort");
10991099
if (s == "hfsort")
11001100
return CGProfileSortKind::Hfsort;
11011101
if (s == "cdsort")

lld/docs/ld.lld.1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ may be:
128128
.It Cm none
129129
Ignore call graph profile.
130130
.It Cm hfsort
131-
Use hfsort (default).
131+
Use hfsort.
132132
.It Cm cdsort
133-
Use cdsort.
133+
Use cdsort (default).
134134
.El
135135
.Pp
136136
.It Fl -color-diagnostics Ns = Ns Ar value

lld/test/ELF/cgprofile-bad-clusters.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# RUN: echo "F G 6" >> %t.call_graph
1111
# RUN: echo "G H 5" >> %t.call_graph
1212
# RUN: echo "H I 4" >> %t.call_graph
13-
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t2
13+
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph --call-graph-profile-sort=hfsort -o %t2
1414
# RUN: llvm-readobj --symbols %t2 | FileCheck %s
1515

1616
.section .text.A,"ax",@progbits

lld/test/ELF/cgprofile-icf.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
# RUN: echo "A B 100" > %t.call_graph
66
# RUN: echo "A C 40" >> %t.call_graph
77
# RUN: echo "C D 61" >> %t.call_graph
8-
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t.out -icf=all
8+
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph --call-graph-profile-sort=hfsort -o %t.out -icf=all
99
# RUN: llvm-readobj --symbols %t.out | FileCheck %s
10-
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t2.out
10+
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph --call-graph-profile-sort=hfsort -o %t2.out
1111
# RUN: llvm-readobj --symbols %t2.out | FileCheck %s --check-prefix=NOICF
1212

1313
.section .text.D,"ax",@progbits

lld/test/ELF/cgprofile-print.s

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# RUN: echo "B C 50" >> %t.call_graph
66
# RUN: echo "C D 40" >> %t.call_graph
77
# RUN: echo "D B 10" >> %t.call_graph
8-
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t2 --print-symbol-order=%t3
8+
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t2 --call-graph-profile-sort=hfsort --print-symbol-order=%t3
99
# RUN: FileCheck %s --input-file %t3
1010

1111
# CHECK: B
@@ -32,6 +32,3 @@ C:
3232
.globl D
3333
D:
3434
nop
35-
36-
37-

lld/test/ELF/cgprofile-rela.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# REQUIRES: x86
44

55
# RUN: yaml2obj %s -o %t.o
6-
# RUN: ld.lld %t.o -o %t
6+
# RUN: ld.lld --call-graph-profile-sort=hfsort %t.o -o %t
77
# RUN: llvm-nm --no-sort %t | FileCheck %s
88
# RUN: ld.lld --no-call-graph-profile-sort %t.o -o %t
99
# RUN: llvm-nm --no-sort %t | FileCheck %s --check-prefix=NO-CG

lld/test/ELF/cgprofile-reproduce.s

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# RUN: echo "B C 50" >> %t.call_graph
66
# RUN: echo "C D 40" >> %t.call_graph
77
# RUN: echo "D B 10" >> %t.call_graph
8-
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t2 --print-symbol-order=%t3
8+
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t2 --call-graph-profile-sort=hfsort --print-symbol-order=%t3
99
# RUN: ld.lld -e A %t --symbol-ordering-file %t3 -o %t2
1010
# RUN: llvm-readobj --symbols %t2 | FileCheck %s
1111

@@ -37,6 +37,3 @@ C:
3737
.globl D
3838
D:
3939
nop
40-
41-
42-

lld/test/ELF/cgprofile-txt.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
# RUN: echo "TooManyPreds10 TooManyPreds 11" >> %t.call_graph
2727
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph --call-graph-profile-sort=hfsort -o %t2
2828
# RUN: llvm-readobj --symbols %t2 | FileCheck %s
29-
## --call-graph-profile-sort=hfsort is the default.
30-
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t2b
31-
# RUN: cmp %t2 %t2b
3229

3330
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph --call-graph-profile-sort=cdsort -o %t2
3431
# RUN: llvm-readobj --symbols %t2 | FileCheck %s --check-prefix=CDSORT
32+
## --call-graph-profile-sort=cdsort is the default.
33+
# RUN: ld.lld -e A %t --call-graph-ordering-file %t.call_graph -o %t2b
34+
# RUN: cmp %t2 %t2b
3535

3636
# RUN: not ld.lld -e A %t --call-graph-ordering-file %t.call_graph --call-graph-profile-sort=sort \
3737
# RUN: -o /dev/null 2>&1 | FileCheck %s --check-prefix=UNKNOWN

0 commit comments

Comments
 (0)