[BOLT][TEST] Imported small tests

Summary:
Imported small internal tests:
- jmp_optimization.test
- jmpjmp.test
- jump_table_footprint_reduction.test
- jump_table_reference.test

(cherry picked from FBD31483122)
This commit is contained in:
Amir Ayupov 2021-10-06 16:20:00 -07:00 committed by Maksim Panchenko
parent 92e306de0c
commit c74e5bfee3
10 changed files with 262 additions and 0 deletions

View File

@ -0,0 +1,7 @@
int g();
int main() {
int x = g();
int y = x*x;
return y;
}

View File

@ -0,0 +1,3 @@
int f() {
return 0;
}

View File

@ -0,0 +1,3 @@
int f();
int g() { return f(); }

View File

@ -0,0 +1,36 @@
.text
.globl main
.type main, %function
main:
# FDATA: 0 [unknown] 0 1 main 0 0 0
.cfi_startproc
.LBB06:
callq testfunc
retq
.cfi_endproc
.size main, .-main
.globl testfunc
.type testfunc, %function
testfunc:
# FDATA: 0 [unknown] 0 1 testfunc 0 0 0
.cfi_startproc
.LBB07:
.LBB07_br: jmp .Ltmp6
# FDATA: 1 testfunc #.LBB07_br# 1 testfunc #.Ltmp6# 0 0
.LFT1:
.LFT1_br: jmp .Ltmp7
# FDATA: 1 testfunc #.LFT1_br# 1 testfunc #.Ltmp7# 0 0
.Ltmp6:
.Ltmp6_br: jmp .Ltmp8
# FDATA: 1 testfunc #.Ltmp6_br# 1 testfunc #.Ltmp8# 0 0
.Ltmp7:
# FDATA: 1 testfunc #.Ltmp7_br# 1 testfunc #.Ltmp8# 0 0
.Ltmp8:
retq
.cfi_endproc
.size testfunc, .-testfunc

View File

@ -0,0 +1,120 @@
.text
.globl main
.type main, %function
main:
# FDATA: 0 [unknown] 0 1 main 0 0 1
.cfi_startproc
LBB00:
subq $0x8, %rsp
.cfi_def_cfa_offset 16
movl $Input, %esi
movl $SYMBOLat0x4006c4, %edi
xorl %eax, %eax
movl $0x0, Input(%rip)
callq scanf@PLT
movl Input(%rip), %edx
movl $0xf4240, %eax
LBB00_br: movl %edx, %esi
# FDATA: 1 main #LBB00_br# 1 main #Ltmp9# 0 0
Ltmp9:
cmpl $0x8, %edx
Ltmp9_br: ja Ltmp0
# FDATA: 1 main #Ltmp9_br# 1 main #Ltmp0# 0 0
# FDATA: 1 main #Ltmp9_br# 1 main #LFT0# 0 40
LFT0:
movl %edx, %ecx
LFT0_br: jmpq *"JUMP_TABLE/main.0"(,%rcx,8)
# FDATA: 1 main #LFT0_br# 1 main #Ltmp8# 0 0
# FDATA: 1 main #LFT0_br# 1 main #Ltmp7# 0 0
# FDATA: 1 main #LFT0_br# 1 main #Ltmp3# 0 0
# FDATA: 1 main #LFT0_br# 1 main #Ltmp2# 0 40
# FDATA: 1 main #LFT0_br# 1 main #Ltmp1# 0 0
# FDATA: 1 main #LFT0_br# 1 main #Ltmp5# 0 0
# FDATA: 1 main #LFT0_br# 1 main #Ltmp4# 0 0
# FDATA: 1 main #LFT0_br# 1 main #Ltmp6# 0 0
# FDATA: 1 main #LFT0_br# 1 main #Ltmp0# 0 0
Ltmp8:
Ltmp8_br: addl $0xa, %esi
# FDATA: 1 main #Ltmp8_br# 1 main #Ltmp10# 0 0
Ltmp10:
subl $0x1, %eax
Ltmp10_br: jne Ltmp9
# FDATA: 1 main #Ltmp10_br# 1 main #Ltmp9# 0 45
# FDATA: 1 main #Ltmp10_br# 1 main #LFT1# 0 0
LFT1:
movl $SYMBOLat0x4006c7, %edi
xorl %eax, %eax
movl %esi, Value(%rip)
callq printf@PLT
xorl %eax, %eax
addq $0x8, %rsp
.cfi_def_cfa_offset 8
retq
.cfi_def_cfa %rsp, 16
Ltmp7:
addl $0x9, %esi
Ltmp7_br: jmp Ltmp10
# FDATA: 1 main #Ltmp7_br# 1 main #Ltmp10# 0 0
Ltmp3:
addl $0x5, %esi
Ltmp3_br: jmp Ltmp10
# FDATA: 1 main #Ltmp3_br# 1 main #Ltmp10# 0 0
Ltmp2:
addl $0x4, %esi
Ltmp2_br: jmp Ltmp10
# FDATA: 1 main #Ltmp2_br# 1 main #Ltmp10# 0 43
Ltmp1:
addl $0x3, %esi
Ltmp1_br: jmp Ltmp10
# FDATA: 1 main #Ltmp1_br# 1 main #Ltmp10# 0 0
Ltmp5:
addl $0x7, %esi
Ltmp5_br: jmp Ltmp10
# FDATA: 1 main #Ltmp5_br# 1 main #Ltmp10# 0 0
Ltmp4:
addl $0x6, %esi
Ltmp4_br: jmp Ltmp10
# FDATA: 1 main #Ltmp4_br# 1 main #Ltmp10# 0 0
Ltmp6:
addl $0x8, %esi
Ltmp6_br: jmp Ltmp10
# FDATA: 1 main #Ltmp6_br# 1 main #Ltmp10# 0 0
Ltmp0:
addl $0x2, %esi
Ltmp0_br: jmp Ltmp10
# FDATA: 1 main #Ltmp0_br# 1 main #Ltmp10# 0 0
.cfi_endproc
.size main, .-main
# Jump tables
.section .rodata
"JUMP_TABLE/main.0":
.quad Ltmp0
.quad Ltmp1
.quad Ltmp2
.quad Ltmp3
.quad Ltmp4
.quad Ltmp5
.quad Ltmp6
.quad Ltmp7
.quad Ltmp8
# BinaryData
"SYMBOLat0x4006c4":
"SYMBOLat0x4006c7":
.section .bss
"Value":
"Input":

View File

@ -0,0 +1,35 @@
.text
.globl main
.type main, %function
main:
.cfi_startproc
cmpq $0x3, %rdi
jae .L4
cmpq $0x1, %rdi
jne .Ldo_jump
jmpq *jt+8
.Ldo_jump:
jmpq *jt(,%rdi,8)
.L1:
movq $0x1, %rax
jmp .L5
.L2:
movq $0x0, %rax
jmp .L5
.L3:
movq $0x2, %rax
jmp .L5
.L4:
mov $0x3, %rax
.L5:
retq
.cfi_endproc
.section .rodata
.align 16
.globl jt
jt:
.quad .L1
.quad .L2
.quad .L3

View File

@ -0,0 +1,10 @@
# Tests the optimization of functions that just do a tail call in the beginning.
RUN: %clang -O2 %S/Inputs/jmp_opt{,2,3}.cpp -o %t
RUN: llvm-bolt -inline-small-functions %t -o %t.bolt
RUN: llvm-objdump -d %t.bolt --print-imm-hex | FileCheck %s
CHECK: <main>:
CHECK-NOT: call
CHECK: xorl %eax, %eax
CHECK: retq

26
bolt/test/X86/jmpjmp.test Normal file
View File

@ -0,0 +1,26 @@
# Verifies that llvm-bolt allocates two consecutive jumps in two separate basic
# blocks.
RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %S/Inputs/jmpjmp.s -o %t.o
RUN: %clang %cflags %t.o -o %t.exe
RUN: llvm-bolt %t.exe -o /dev/null -print-cfg 2>&1 | FileCheck %s
CHECK: Binary Function "testfunc"
CHECK: State : CFG constructed
CHECK: Section : .text
CHECK: IsSimple : 1
CHECK: BB Count : 4
CHECK: }
CHECK: .LBB{{.*}}
CHECK: {{.*}}: jmp .Ltmp{{.*}}
CHECK: Successors: .Ltmp{{.*}}
CHECK: .LFT{{.*}}
CHECK: {{.*}}: jmp .Ltmp{{.*}}
CHECK: Successors: .Ltmp{{.*}}
CHECK: .Ltmp{{.*}}
CHECK: Predecessors: .LBB{{.*}}
CHECK: {{.*}}: jmp .Ltmp{{.*}}
CHECK: Successors: .Ltmp{{.*}}
CHECK: .Ltmp{{.*}}
CHECK: Predecessors: .LFT{{.*}}, .Ltmp{{.*}}
CHECK: {{.*}}: retq

View File

@ -0,0 +1,16 @@
# Checks that jump table footprint reduction optimization is reducing entry
# sizes.
RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \
RUN: %S/Inputs/jump_table_footprint_reduction.s -o %t.o
RUN: link_fdata %S/Inputs/jump_table_footprint_reduction.s %t.o %t.fdata
RUN: llvm-strip --strip-unneeded %t.o
RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
RUN: llvm-bolt %t.exe -data %t.fdata -o /dev/null \
RUN: -jump-tables=move -jt-footprint-reduction -assume-abi -relocs \
RUN: | FileCheck %s
CHECK: 100.00% of dynamic JT entries were reduced.
CHECK: 1 of 1 jump tables affected.
CHECK: 1 of 1 indirect jumps to JTs affected.
CHECK: 36 bytes saved.

View File

@ -0,0 +1,6 @@
# Verifies that BOLT detects fixed destination of indirect jump
RUN: %clang %cflags %S/Inputs/jump_table_reference.s -Wl,-q -o %t
RUN: llvm-bolt %t -relocs -o /dev/null 2>&1 | FileCheck %s
CHECK: BOLT-INFO: fixed indirect branch detected in main