1# This reproduces a bug with shrink wrapping when moving 2# load instructions in-between the lock prefix and another 3# instruction (where the lock prefix applies). 4 5# REQUIRES: system-linux 6 7# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \ 8# RUN: %s -o %t.o 9# RUN: link_fdata %s %t.o %t.fdata 10# Delete our BB symbols so BOLT doesn't mark them as entry points 11# RUN: llvm-strip --strip-unneeded %t.o 12# RUN: %clang %cflags -no-pie %t.o -o %t.exe -Wl,-q 13 14# RUN: llvm-bolt %t.exe --relocs=1 --frame-opt=all --print-fop \ 15# RUN: --print-only=main --data %t.fdata -o %t.out | FileCheck %s 16 17# RUN: %t.out 1 18 19# CHECK: BOLT-INFO: Shrink wrapping moved 1 spills inserting load/stores and 0 spills inserting push/pops 20 21 .text 22 .globl main 23 .type main, %function 24 .p2align 4 25main: 26# FDATA: 0 [unknown] 0 1 main 0 0 510 27 pushq %rbp 28 movq %rsp, %rbp 29 pushq %rbx # We save rbx here, but there is an 30 # opportunity to move it to .LBB2 31 subq $0x18, %rsp 32 cmpl $0x2, %edi 33.J1: 34 jb .BBend 35# FDATA: 1 main #.J1# 1 main #.BB2# 0 10 36# FDATA: 1 main #.J1# 1 main #.BBend# 0 500 37.BB2: 38 movq $2, %rbx # Use rbx in a cold block. Save rbx will be moved 39 # just before this instruction. 40 xorq %rax, %rax 41 movb mystring, %al 42 addq %rbx, %rax 43 movb %al, mystring 44 leaq mystring, %rdi 45 callq puts 46 lock add %r12,0x0(%rsp) # Put a lock in an unrelated instruction at the 47 # dom. frontier where the restore will be moved to 48 # We should not put the restore in-between the 49 # lock and add! We typically avoid putting a 50 # restore in the last BB instruction, but since 51 # lock in llvm MC lib is considered a 52 # separate instruction, we may mistakenly 53 # put the restore just between these two. 54 55.BBend: 56 addq $0x18, %rsp 57 pop %rbx # Restore should be moved 58 xorq %rax, %rax 59 leaveq 60 retq 61 .size main, .-main 62 63 .data 64mystring: .asciz "0 is rbx mod 10 contents in decimal\n" 65