Skip to content

Commit

Permalink
[BOLT][TEST] Import small tests
Browse files Browse the repository at this point in the history
Summary: Imported small internal tests.

(cherry picked from FBD32405870)
  • Loading branch information
aaupov authored and maksfb committed Nov 12, 2021
1 parent 7ea61da commit 1d0a276
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bolt/test/X86/Inputs/order.txt
@@ -0,0 +1,5 @@
_start
main
_a
_b
_f
12 changes: 12 additions & 0 deletions bolt/test/X86/Inputs/shorten_mov.s
@@ -0,0 +1,12 @@
.text
.globl foo
.type foo, @function
foo:
movabs $0x1111,%rax
movabs $0x1111,%rax
movabs $0x11112222,%rax
movabs $0x111112222,%rax
movabs $0xffffffffffffffff,%rax
movabs $0x7fffffffffffffff,%rax
ret
.size foo, .-foo
17 changes: 17 additions & 0 deletions bolt/test/X86/Inputs/tailcall_traps.s
@@ -0,0 +1,17 @@
.globl main
main:

.globl foo
foo:
.cfi_startproc
jmpq *%rax
.cfi_endproc

.globl bar
bar:
.cfi_startproc
jmp moo
.cfi_endproc

.globl moo
moo:
85 changes: 85 additions & 0 deletions bolt/test/X86/Inputs/unreachable.s
@@ -0,0 +1,85 @@
.globl bar
bar:
movq $0, (%rbp)
movl $4, %edi
call __cxa_allocate_exception
movl $0, (%rax)
movl $0, %edx
movl $_ZTIi, %esi
movq %rax, %rdi
call __cxa_throw
movq $17, 8

.globl foo
foo:
.LFB1:
.cfi_startproc
.cfi_personality 0x3,__gxx_personality_v0
.cfi_lsda 0x3,.LLSDA1
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $24, %rsp
movq %rdi, -24(%rbp)
incq -24(%rbp)
jmp .L1
decq (%rbp)
.L1: incq -24(%rbp)
cmpq $2,-24(%rbp)
jne .L3
jmp .L4
decq (%rbp)
.L3: incq -24(%rbp)
.L4: incq -24(%rbp)
movq -24(%rbp), %rax
movq %rax, %rdi
.LEHB0:
call bar
.LEHE0:
movq %rax, %rbx
.L5:
movq %rbx, %rax
jmp .L8
.L7:
movq %rax, %rdi
call __cxa_begin_catch
incq -24(%rbp)
jmp .LP1
decq (%rbp)
.LP1: incq -24(%rbp)
cmpq $2,-24(%rbp)
jne .LP2
jmp .LP3
decq (%rbp)
.LP2: incq -24(%rbp)
.LP3: incq -24(%rbp)
movq -24(%rbp), %rbx
.LEHB1:
call __cxa_end_catch
.LEHE1:
jmp .L5
.L8:
movq -8(%rbp), %rbx
leave
.cfi_endproc

.section .gcc_except_table,"a",@progbits
.LLSDA1:
.byte 0xff
.byte 0x3
.uleb128 .LLSDATT1-.LLSDATTD1
.LLSDATTD1:
.byte 0x1
.uleb128 .LLSDACSE1-.LLSDACSB1
.LLSDACSB1:
.uleb128 .LEHB0-.LFB1
.uleb128 .LEHE0-.LEHB0
.uleb128 .L7-.LFB1
.uleb128 0x1
.LLSDACSE1:
.LLSDATT1:
.text
.globl main, function
main:
.cfi_startproc
.cfi_endproc
44 changes: 44 additions & 0 deletions bolt/test/X86/Inputs/user-order.S
@@ -0,0 +1,44 @@
.type _a, @function
_a:
.cfi_startproc
test %edx, %edx
.cfi_endproc

.globl _b
.type _b, @function
_b:
.cfi_startproc
jnz a
.cfi_endproc

.globl _f
.type _f, @function
_f:
.cfi_startproc
mov %rdx, %rcx
a:
mov 0, %r9

.globl _e
.type _e, @function
_e:

.globl _d
.type _d, @function
_d:

.globl _c
.type _c, @function
_c:
movdqu 0, %xmm3
.cfi_endproc

.globl main
.type main, @function
main:
nop

.globl _start
.type _start, @function
_start:
jmp main
14 changes: 14 additions & 0 deletions bolt/test/X86/shorten-mov.test
@@ -0,0 +1,14 @@
# Test that 64 bit movq instructions with immediate operands
# that fit in 32 bits are shortened.

RUN: %clang %p/Inputs/asm_main.c %p/Inputs/shorten_mov.s -o %t.exe
RUN: llvm-bolt %t.exe -peepholes=shorten -o %t
RUN: llvm-objdump -d %t --print-imm-hex | FileCheck %s

CHECK: <foo>:
CHECK-NEXT: 48 c7 c0 11 11 00 00 movq $0x1111, %rax
CHECK-NEXT: 48 c7 c0 11 11 00 00 movq $0x1111, %rax
CHECK-NEXT: 48 c7 c0 22 22 11 11 movq $0x11112222, %rax
CHECK-NEXT: 48 b8 22 22 11 11 01 00 00 00 movabsq $0x111112222, %rax
CHECK-NEXT: 48 c7 c0 ff ff ff ff movq $-0x1, %rax
CHECK-NEXT: 48 b8 ff ff ff ff ff ff ff 7f movabsq $0x7fffffffffffffff, %rax
17 changes: 17 additions & 0 deletions bolt/test/X86/symtab-secondary-entries.test
@@ -0,0 +1,17 @@
# Check that secondary entry points are updated correctly in the ELF symtab

RUN: %clang %p/Inputs/user-order.S -Wl,-q -o %t.exe -nostdlib
RUN: llvm-bolt %t.exe -o %t -reorder-functions=user \
RUN: -function-order=%p/Inputs/order.txt

RUN: llvm-readelf -Ws %t | cut -d':' -f2- | sort -u | FileCheck %s

CHECK: [[#]] FUNC GLOBAL DEFAULT [[#NDX:]] _start
CHECK: [[#]] FUNC GLOBAL DEFAULT [[#NDX]] main
CHECK: [[#]] FUNC LOCAL DEFAULT [[#NDX]] _a
CHECK: [[#]] FUNC GLOBAL DEFAULT [[#NDX]] _b
CHECK: [[#]] FUNC GLOBAL DEFAULT [[#NDX]] _f
# The following are all secondary entries of _f
CHECK: 0 FUNC GLOBAL DEFAULT [[#NDX]] _c
CHECK: 0 FUNC GLOBAL DEFAULT [[#NDX]] _d
CHECK: 0 FUNC GLOBAL DEFAULT [[#NDX]] _e
14 changes: 14 additions & 0 deletions bolt/test/X86/tailcall-traps.test
@@ -0,0 +1,14 @@
# Tests the peephole that adds trap instructions following indirect tail calls.

RUN: %clang %p/Inputs/tailcall_traps.s -o %t.exe
RUN: llvm-bolt %t.exe -o %t -peepholes=tailcall-traps \
RUN: -print-peepholes -funcs=foo,bar 2>&1 | FileCheck %s

CHECK: Binary Function "foo"
CHECK: jmpl *%rax # TAILCALL
CHECK: ud2
CHECK: End of Function "foo"

CHECK: Binary Function "bar"
CHECK: jmp moo # TAILCALL
CHECK: End of Function "bar"
46 changes: 46 additions & 0 deletions bolt/test/X86/unreachable.test
@@ -0,0 +1,46 @@
# Check unreachable code elimination

RUN: %clangxx %p/Inputs/unreachable.s -o %t.exe
RUN: llvm-bolt %t.exe -o %t \
RUN: -reorder-blocks=none -split-functions=1 -eliminate-unreachable \
RUN: -funcs=foo -use-gnu-stack -print-cfg -print-finalized \
RUN: | FileCheck %s --check-prefix=BOLT
RUN: llvm-objdump -d %t --print-imm-hex --disassemble-symbols=foo \
RUN: --no-show-raw-insn | FileCheck %s

BOLT: BB Layout : .LBB{{.*}}, .LFT{{.*}}, .Ltmp{{.*}}, .LFT{{.*}}, .Ltmp{{.*}}, .Ltmp{{.*}}, .Ltmp{{.*}}, .LLP{{.*}}, .LFT{{.*}}, .Ltmp{{.*}}, .LFT{{.*}}, .Ltmp{{.*}}, .Ltmp{{.*}}, .Ltmp{{.*}}
BOLT: BOLT-INFO: UCE removed 4 blocks and 16 bytes of code.
BOLT: BB Layout : .LBB{{.*}}, .Ltmp{{.*}}, .Ltmp{{.*}}, .Ltmp{{.*}}, .Ltmp{{.*}}, .LLP{{.*}}, .Ltmp{{.*}}, .Ltmp{{.*}}, .Ltmp{{.*}}, .Ltmp{{.*}}

CHECK: <foo>:
CHECK-NEXT: pushq %rbp
CHECK-NEXT: movq %rsp, %rbp
CHECK-NEXT: pushq %rbx
CHECK-NEXT: subq $0x18, %rsp
CHECK-NEXT: movq %rdi, -0x18(%rbp)
CHECK-NEXT: incq -0x18(%rbp)
CHECK-NEXT: incq -0x18(%rbp)
CHECK-NEXT: cmpq $0x2, -0x18(%rbp)
CHECK-NEXT: je 0x[[#%x,JMP1:]]
CHECK-NEXT: incq -0x18(%rbp)
CHECK-NEXT: [[#JMP1]]: incq -0x18(%rbp)
CHECK-NEXT: movq -0x18(%rbp), %rax
CHECK-NEXT: movq %rax, %rdi
CHECK-NEXT: callq {{.*}} <bar>
CHECK-NEXT: movq %rax, %rbx
CHECK-NEXT: [[#%x,JMP3:]]: movq %rbx, %rax
CHECK-NEXT: jmp {{.*}}
CHECK-NEXT: movq %rax, %rdi
CHECK-NEXT: callq {{.*}} <__cxa_begin_catch@plt>
CHECK-NEXT: incq -0x18(%rbp)
CHECK-NEXT: incq -0x18(%rbp)
CHECK-NEXT: cmpq $0x2, -0x18(%rbp)
CHECK-NEXT: je 0x[[#%x,JMP2:]]
CHECK-NEXT: incq -0x18(%rbp)
CHECK-NEXT: [[#JMP2]]: incq -0x18(%rbp)
CHECK-NEXT: movq -0x18(%rbp), %rbx
CHECK-NEXT: callq {{.*}} <__cxa_end_catch@plt>
CHECK-NEXT: jmp 0x[[#JMP3]]
CHECK-NEXT: movq -0x8(%rbp), %rbx
CHECK-NEXT: leave
CHECK-NEXT: retq

0 comments on commit 1d0a276

Please sign in to comment.