[BOLT][TEST] Imported small tests

Summary:
Imported small internal tests:
- keep_aranges.test
- layout_heuristic.test
- line_number.test
- block_reordering.test
- branch_data.test
- reader.test

(cherry picked from FBD31486371)
This commit is contained in:
Amir Ayupov 2021-10-07 13:38:58 -07:00 committed by Maksim Panchenko
parent c74e5bfee3
commit d41b4e6e2d
10 changed files with 230 additions and 0 deletions

View File

@ -0,0 +1,19 @@
1 main 451 1 SolveCubic 0 0 151
1 main 489 1 main 46a 0 27
1 main 4ad 1 main 428 0 135
1 main 4cb 1 main 410 2 19
1 main 4e9 1 main 3fa 0 1
1 main 521 1 usqrt 0 0 168
1 main 543 1 main 519 0 179
1 main 55c 1 usqrt 0 0 31
1 main 57f 1 main 554 0 34
1 main 5d6 1 main 58f 0 1001
1 main 62d 1 main 5e6 0 22
1 SolveCubic 82 1 SolveCubic 130 2 4
1 SolveCubic 107 1 SolveCubic 111 0 89
1 SolveCubic 12c 1 main 456 0 87
1 SolveCubic 2a6 1 main 456 0 5
1 usqrt 30 1 usqrt 39 171 2886
1 usqrt 3d 1 usqrt 10 33 4711
1 usqrt 42 1 main 526 0 73
1 usqrt 42 1 main 561 0 19

View File

@ -0,0 +1,6 @@
#include <stdio.h>
int baz() {
return 0;
}

View File

@ -0,0 +1,14 @@
// Test identical code folding handling.
#include <stdio.h>
int foo() {
return 0;
}
int bar() {
return 0;
}
int main() {
return foo();
}

View File

@ -0,0 +1,25 @@
int f() {
// This will be removed by BOLT but they make sure we have some extra space
// to insert branches and don't run out of space when rewritting the function.
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
int x = 0xBEEF;
if (x & 0x32) {
x++;
} else {
--x;
}
return x;
}
int g() {
return f() + 1;
}
int main() {
int q = g() * f();
return 0;
}

View File

@ -0,0 +1,49 @@
# Tests whether llvm-bolt is able to reorder blocks and fix branches
# according to the new function layout.
RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe
RUN: llvm-bolt %t.exe -o /dev/null -data %p/Inputs/blarge.fdata \
RUN: -reorder-blocks=normal -print-finalized 2>&1 | FileCheck %s \
RUN: -check-prefix=CHECK
CHECK: Binary Function "usqrt"
CHECK: BB Layout : .LBB{{.*}}, .Ltmp{{.*}}, .Ltmp{{.*}}, .LFT{{.*}}, .LFT{{.*}}
CHECK: .LBB{{.*}}
CHECK: Exec Count : 199
CHECK: {{.*}}: movl $0x20, %r8d
CHECK: {{.*}}: xorl %eax, %eax
CHECK: {{.*}}: xorl %edx, %edx
CHECK: {{.*}}: jmp .Ltmp{{.*}}
CHECK: Successors: .Ltmp{{.*}} (mispreds: 0, count: 0)
CHECK: .Ltmp{{.*}}
CHECK: Exec Count : 4711
CHECK: Predecessors: .Ltmp{{.*}}, .LFT{{.*}}
CHECK: {{.*}}: subl $0x1, %r8d
CHECK: {{.*}}: je .LFT{{.*}}
CHECK: Successors: .LFT{{.*}} (mispreds: 0, count: 0), .Ltmp{{.*}} (mispreds: 33, count: 4711)
CHECK: .Ltmp{{.*}}
CHECK: Exec Count : 4711
CHECK: Predecessors: .Ltmp{{.*}}, .LBB{{.*}}
CHECK: {{.*}}: movq %rdi, %rcx
CHECK: {{.*}}: addq %rax, %rax
CHECK: {{.*}}: shlq $0x2, %rdi
CHECK: {{.*}}: andl $0xc0000000, %ecx
CHECK: {{.*}}: shrq $0x1e, %rcx
CHECK: {{.*}}: leaq (%rcx,%rdx,4), %rdx
CHECK: {{.*}}: leaq 0x1(%rax,%rax), %rcx
CHECK: {{.*}}: cmpq %rcx, %rdx
CHECK: {{.*}}: jb .Ltmp{{.*}}
CHECK: Successors: .Ltmp{{.*}} (mispreds: 171, count: 2886), .LFT{{.*}} (mispreds: 0, count: 0)
CHECK: .LFT{{.*}}
CHECK: Exec Count : 0
CHECK: Predecessors: .Ltmp{{.*}}
CHECK: {{.*}}: subq %rcx, %rdx
CHECK: {{.*}}: addq $0x1, %rax
CHECK: {{.*}}: jmp .Ltmp{{.*}}
CHECK: Successors: .Ltmp{{.*}} (mispreds: 0, count: 0)
CHECK: .LFT{{.*}}
CHECK: Exec Count : 0
CHECK: Predecessors: .Ltmp{{.*}}
CHECK: {{.*}}: movq %rax, (%rsi)
CHECK: {{.*}}: retq

View File

@ -0,0 +1,55 @@
# Checks that llvm-bolt is able to read data generated by perf2bolt and update
# the CFG edges accordingly with absolute number of branches and mispredictions.
# Also checks that llvm-bolt disassembler and CFG builder is working properly.
RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe
RUN: llvm-bolt %t.exe -o /dev/null -data %p/Inputs/blarge.fdata -print-cfg
CHECK: Binary Function "usqrt"
CHECK: State : CFG constructed
CHECK: Address : 0x401170
CHECK: Size : 0x43
CHECK: MaxSize : 0x50
CHECK: Offset : 0x1170
CHECK: Section : .text
CHECK: IsSimple : 1
CHECK: BB Count : 5
CHECK: Exec Count : 199
CHECK: }
CHECK: .LBB{{.*}}
CHECK: Exec Count : 199
CHECK: {{.*}}: movl $0x20, %r8d
CHECK: {{.*}}: xorl %eax, %eax
CHECK: {{.*}}: xorl %edx, %edx
CHECK: Successors: .Ltmp{{.*}} (mispreds: 0, count: 0)
CHECK: .Ltmp{{.*}}
CHECK: Exec Count : 4711
CHECK: Predecessors: .Ltmp{{.*}}, .LBB{{.*}}
CHECK: {{.*}}: movq %rdi, %rcx
CHECK: {{.*}}: addq %rax, %rax
CHECK: {{.*}}: shlq $0x2, %rdi
CHECK: {{.*}}: andl $0xc0000000, %ecx
CHECK: {{.*}}: shrq $0x1e, %rcx
CHECK: {{.*}}: leaq (%rcx,%rdx,4), %rdx
CHECK: {{.*}}: leaq 0x1(%rax,%rax), %rcx
CHECK: {{.*}}: cmpq %rcx, %rdx
CHECK: {{.*}}: jb .Ltmp{{.*}}
CHECK: Successors: .Ltmp{{.*}} (mispreds: 171, count: 2886), .LFT{{.*}} (mispreds: 0, count: 0)
CHECK: .LFT{{.*}}
CHECK: Exec Count : 0
CHECK: Predecessors: .Ltmp{{.*}}
CHECK: {{.*}}: subq %rcx, %rdx
CHECK: {{.*}}: addq $0x1, %rax
CHECK: Successors: .Ltmp{{.*}} (mispreds: 0, count: 0)
CHECK: .Ltmp{{.*}}
CHECK: Exec Count : 4711
CHECK: Predecessors: .Ltmp{{.*}}, .LFT{{.*}}
CHECK: {{.*}}: subl $0x1, %r8d
CHECK: {{.*}}: jne .Ltmp{{.*}}
CHECK: Successors: .Ltmp{{.*}} (mispreds: 33, count: 4711), .LFT{{.*}} (mispreds: 0, count: 0)
CHECK: .LFT{{.*}}
CHECK: Exec Count : 0
CHECK: Predecessors: .Ltmp{{.*}}
CHECK: {{.*}}: movq %rax, (%rsi)
CHECK: {{.*}}: retq
CHECK: End of Function "usqrt"

View File

@ -0,0 +1,8 @@
# Check that BOLT generates .debug_aranges section for an input
# where it was removed when .gdb_index was generated.
RUN: %clang %S/Inputs/icf_baz.c %S/Inputs/icf_main.c -Wl,--icf=all,--gdb-index \
RUN: -g -o %t.exe -fuse-ld=ld.lld
RUN: llvm-bolt %t.exe -o %t -update-debug-sections -keep-aranges
RUN: llvm-dwarfdump -debug-aranges %t | FileCheck %s
CHECK: Address Range Header: length = {{.*}}, version = 0x0002, cu_offset = 0x00000000, addr_size = 0x08, seg_size = 0x00

View File

@ -0,0 +1,27 @@
# Checks that llvm-bolt is able to read data generated by perf2bolt, update the
# CFG edges accordingly with absolute number of branches and mispredictions,
# infer fallthrough branch info and reorder basic blocks using a greedy
# heuristic, or find the optimal solution if the function is small enough.
# Also checks that llvm-bolt disassembler and CFG builder is working properly.
RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe
RUN: llvm-bolt %t.exe -o /dev/null -data %p/Inputs/blarge.fdata \
RUN: -reorder-blocks=normal -print-cfg -print-reordered \
RUN: -funcs=main,SolveCubic,usqrt -sequential-disassembly 2>&1 | FileCheck %s
# Original order
CHECK: Binary Function "main"
CHECK: BB Layout : .LBB00, .Ltmp1, .Ltmp0, .Ltmp3, .Ltmp2, .Ltmp5, .Ltmp4, .Ltmp7, .Ltmp6, .Ltmp9, .Ltmp8, .Ltmp11, .Ltmp10, .Ltmp13, .Ltmp12, .Ltmp15, .Ltmp14, .Ltmp21, .Ltmp20, .Ltmp19, .Ltmp18, .Ltmp17, .Ltmp16, .LFT0, .LFT1, .LFT2, .LFT3, .Ltmp22, .LFT4, .Ltmp23, .LFT5, .Ltmp24, .LFT6, .Ltmp25, .LFT7
CHECK: Binary Function "SolveCubic"
CHECK: BB Layout : .LBB01, .LFT8, .LFT9, .Ltmp33, .LFT10, .Ltmp28, .Ltmp26, .LFT11, .Ltmp37, .Ltmp36, .Ltmp35, .Ltmp34, .Ltmp27, .Ltmp32, .Ltmp31, .Ltmp30, .Ltmp29
CHECK: Binary Function "usqrt"
CHECK: BB Layout : .LBB02, .Ltmp39, .LFT12, .Ltmp38, .LFT13
# New order
CHECK: Binary Function "main"
CHECK: BB Layout : .LBB00, .Ltmp1, .Ltmp0, .Ltmp3, .Ltmp2, .Ltmp5, .Ltmp4, .Ltmp7, .Ltmp6, .Ltmp9, .Ltmp8, .Ltmp11, .Ltmp10, .Ltmp13, .Ltmp12, .Ltmp15, .Ltmp14, .Ltmp21, .Ltmp16, .Ltmp18, .Ltmp17, .LFT0, .Ltmp19, .LFT1, .Ltmp20, .LFT2, .LFT3, .Ltmp22, .LFT4, .Ltmp23, .LFT5, .Ltmp24, .LFT6, .Ltmp25, .LFT7
CHECK: Binary Function "SolveCubic"
CHECK: BB Layout : .LBB01, .Ltmp26, .LFT11, .Ltmp37, .Ltmp36, .Ltmp35, .Ltmp34, .LFT8, .LFT9, .Ltmp33, .Ltmp28, .LFT10, .Ltmp27, .Ltmp32, .Ltmp31, .Ltmp30, .Ltmp29
CHECK: Binary Function "usqrt"
CHECK: BB Layout : .LBB02, .Ltmp38, .Ltmp39, .LFT12, .LFT13

View File

@ -0,0 +1,17 @@
# Verifies that the extraction of DWARF line number information is correct.
RUN: %clangxx %S/Inputs/linenumber.cpp -g -o %t
RUN: llvm-bolt %t -o /dev/null -print-reordered -update-debug-sections \
RUN: -print-debug-info -reorder-blocks=reverse -sequential-disassembly 2>&1 \
RUN: | FileCheck %s
# Local variable in f()
CHECK: movl $0xbeef, -0x4(%rbp) # debug line {{.*}}linenumber.cpp:9
# Checks that a branch instruction that is inserted by BOLT does not have
# debug line info associated with it.
CHECK-NOT: jmp .LFT0 # debug line {{.*}}linenumber.cpp:1
# Call to f() in g()
CHECK: callq _Z1fv{{.*}} # debug line {{.*}}linenumber.cpp:19
# Calls to g() and f() in main
CHECK: callq _Z1gv{{.*}} # debug line {{.*}}linenumber.cpp:23
CHECK: callq _Z1fv{{.*}} # debug line {{.*}}linenumber.cpp:23

10
bolt/test/X86/reader.test Normal file
View File

@ -0,0 +1,10 @@
# This script checks that DataReader in llvm-bolt is reading data correctly
RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe
RUN: llvm-bolt %t.exe -o /dev/null -data %p/Inputs/blarge.fdata --dump-data \
RUN: 2>&1 | sort | FileCheck %s -check-prefix=CHECK
CHECK: main 1105 SolveCubic 0 0 151
CHECK: main 1161 main 1130 0 27
CHECK: main 1313 usqrt 0 0 168
CHECK: main 1494 main 1423 0 1001