xref: /llvm-project/bolt/test/X86/tail-duplication-complex.s (revision 11791ae7b0b05b8bd8d806331ff51da618912cf8)
1# REQUIRES: system-linux
2
3# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \
4# RUN:   %s -o %t.o
5# RUN: link_fdata %s %t.o %t.fdata
6# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
7
8# RUN: llvm-bolt %t.exe --data %t.fdata --print-finalized \
9# RUN:    --tail-duplication=moderate --tail-duplication-minimum-offset=1 \
10# RUN:    -o %t.out | FileCheck %s
11
12# FDATA: 1 main f 1 main 19 0 10
13# FDATA: 1 main f 1 main 11 0 13
14# FDATA: 1 main 17 1 main 3c 0 10
15# FDATA: 1 main 39 1 main 3c 0 10
16
17# CHECK: tail duplication modified 1 ({{.*}}%) functions; duplicated 1 blocks ({{.*}} bytes) responsible for {{.*}} dynamic executions ({{.*}} of all block executions)
18# CHECK: BB Layout   : .LBB00, .Ltmp0, .Ltail-dup0, .Ltmp1, .Ltmp2
19
20## This is the C++ code fed to Clang
21## int fib(int term) {
22##   if (term <= 1)
23##     return term;
24##   return fib(term-1) + fib(term-2);
25## }
26
27    .text
28    .globl main
29    .type main, %function
30    .size main, .Lend-main
31main:
32    push   %rbp
33    mov    %rsp,%rbp
34    sub    $0x10,%rsp
35    mov    %edi,-0x8(%rbp)
36    cmpl   $0x1,-0x8(%rbp)
37    jg     .BB1
38.BB0:
39    mov    -0x8(%rbp),%eax
40    mov    %eax,-0x4(%rbp)
41    jmp   .BB2
42.BB1:
43    mov    -0x8(%rbp),%edi
44    sub    $0x1,%edi
45    call   main
46    mov    %eax,-0xc(%rbp)
47    mov    -0x8(%rbp),%edi
48    sub    $0x2,%edi
49    call   main
50    mov    %eax,%ecx
51    mov    -0xc(%rbp),%eax
52    add    %ecx,%eax
53    mov    %eax,-0x4(%rbp)
54.BB2:
55    mov    -0x4(%rbp),%eax
56    add    $0x10,%rsp
57    pop    %rbp
58    retq
59    nopl   0x0(%rax)
60.Lend:
61