xref: /llvm-project/bolt/test/X86/shrinkwrapping-do-not-pessimize.s (revision 11791ae7b0b05b8bd8d806331ff51da618912cf8)
1## This checks that shrink wrapping does not pessimize a CFG pattern where two
2## blocks can be proved to have the same execution count but, because of profile
3## inaccuricies, we could move saves into the second block. We can prove two
4## blocks have the same frequency when B post-dominate A and A dominates B and
5## are at the same loop nesting level. This would be a pessimization because
6## shrink wrapping is unlikely to be able to cleanly move PUSH instructions,
7## inserting additional store instructions.
8
9# REQUIRES: system-linux
10
11# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \
12# RUN:   %s -o %t.o
13# RUN: link_fdata %s %t.o %t.fdata
14# RUN: llvm-strip --strip-unneeded %t.o
15# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -nostdlib
16# RUN: llvm-bolt -relocs %t.exe -o %t.out -data %t.fdata \
17# RUN:     -frame-opt=all -equalize-bb-counts | FileCheck %s
18
19## Here we create a CFG pattern with two blocks A and B belonging to the same
20## equivalency class as defined by dominance relations and having in theory
21## the same frequency. But we tweak edge counts from profile to make block A
22## hotter than block B.
23  .globl _start
24  .type _start, %function
25_start:
26  .cfi_startproc
27## Hot prologue
28# FDATA: 0 [unknown] 0 1 _start 0 0 10
29  push  %rbp
30  mov   %rsp, %rbp
31  push  %rbx
32  push  %r14
33  subq  $0x20, %rsp
34b:  je  end_if_1
35# FDATA: 1 _start #b# 1 _start #end_if_1# 0 1
36if_false:
37  movq rel(%rip), %rdi  # Add this to create a relocation and run bolt w/ relocs
38c:  jmp end_if_1
39## Reduce frequency from 9 to 1 to simulate an inaccurate profile
40# FDATA: 1 _start #c# 1 _start #end_if_1# 0 1
41end_if_1:
42  # first uses of R14 and RBX appear at this point, possible move point for SW
43  mov %r14, %rdi
44  mov %rbx, %rdi
45  leaq -0x20(%rbp), %r14
46  movq -0x20(%rbp), %rdi
47  addq  $0x20, %rsp
48  pop %r14
49  pop %rbx
50  pop %rbp
51  ret
52  .cfi_endproc
53  .size _start, .-_start
54
55  .data
56rel:  .quad _start
57
58# CHECK:   BOLT-INFO: Shrink wrapping moved 0 spills inserting load/stores and 0 spills inserting push/pops
59