diff --git a/bolt/test/X86/Inputs/avx512.c b/bolt/test/X86/Inputs/avx512.c new file mode 100644 index 000000000000..719037968423 --- /dev/null +++ b/bolt/test/X86/Inputs/avx512.c @@ -0,0 +1,15 @@ +#include + +void use_avx512() { + printf("after first entry\n"); + asm (".byte 0x62, 0xe2, 0xf5, 0x70, 0x2c, 0xda"); + asm ("secondary_entry:"); + printf("after secondary entry\n"); +} + +int main() { + printf("about to use avx-512 instruction...\n"); + use_avx512(); + + return 0; +} diff --git a/bolt/test/X86/Inputs/switch_statement.cpp b/bolt/test/X86/Inputs/switch_statement.cpp new file mode 100644 index 000000000000..dc2321eadfdc --- /dev/null +++ b/bolt/test/X86/Inputs/switch_statement.cpp @@ -0,0 +1,29 @@ +#include + +int inc(int x) { + switch (x) { + case 0: puts("0"); return 1; + case 1: puts("1"); return 2; + case 2: puts("2"); return 3; + case 3: puts("3"); return 4; + case 4: puts("4"); return 5; + case 5: puts("5"); return 6; + default: return x + 1; + } +} + +int inc_dup(int x) { + switch (x) { + case 0: puts("0"); return 1; + case 1: puts("1"); return 2; + case 2: puts("2"); return 3; + case 3: puts("3"); return 4; + case 4: puts("4"); return 5; + case 5: puts("5"); return 6; + default: return x + 1; + } +} + +int main() { + return inc(5) - 2*inc_dup(2); +} diff --git a/bolt/test/X86/R_X86_64_64.pic.lld.cpp b/bolt/test/X86/R_X86_64_64.pic.lld.cpp new file mode 100644 index 000000000000..9afd957bdced --- /dev/null +++ b/bolt/test/X86/R_X86_64_64.pic.lld.cpp @@ -0,0 +1,15 @@ +/* + * Check that we don't assert on a duplicate static relocation added by lld + * against _Z6myfuncv. The same address has a dynamic relocation against it. + * + * RUN: %clang -fPIC -shared %s -o %t.so -Wl,-q -fuse-ld=ld.lld + * RUN: llvm-bolt %t.so -o %t.so.bolt -relocs + */ + +unsigned long long myfunc(); + +unsigned long long (*myglobal)() = myfunc; + +unsigned long long myfunc() { + return reinterpret_cast(myglobal); +} diff --git a/bolt/test/X86/avx512_trap.test b/bolt/test/X86/avx512_trap.test new file mode 100644 index 000000000000..b8e288fff023 --- /dev/null +++ b/bolt/test/X86/avx512_trap.test @@ -0,0 +1,19 @@ +# Check that BOLT inserts trap instruction at entry to functions that use AVX-512. +# Check that AVX-512 instruction is updated correctly when -trap-avx512=0 is passed. + +RUN: %clang %S/Inputs/avx512.c -o %t -Wl,-q,-znow +RUN: llvm-bolt %t -trap-avx512=1 -o %t.bolt 2>&1 | FileCheck %s && \ +RUN: llvm-objdump -d --disassemble-symbols=use_avx512 %t.bolt | FileCheck %s --check-prefix=CHECK-DIS +RUN: llvm-bolt %t -trap-avx512=0 -o %t.bolt && \ +RUN: llvm-objdump -d --disassemble-symbols=use_avx512 %t.bolt | FileCheck %s --check-prefix=CHECK-DIS-NO-TRAP + +CHECK: BOLT-WARNING: 1 function will trap on entry + +# Check that we have two ud2 instructions - one per entry. +CHECK-DIS: use_avx512 +CHECK-DIS-NEXT: ud2 +CHECK-DIS-NEXT: ud2 + +# Check that we generate correct AVX-512 +CHECK-DIS-NO-TRAP: use_avx512 +CHECK-DIS-NO-TRAP: 62 e2 f5 70 2c da vscalefpd diff --git a/bolt/test/X86/bad_exe.test b/bolt/test/X86/bad_exe.test new file mode 100644 index 000000000000..467007dc4c1a --- /dev/null +++ b/bolt/test/X86/bad_exe.test @@ -0,0 +1,7 @@ +# Check that llvm-bolt rejects input that is not a valid ELF executable +# bzip2.debuginfo is the result of running "objcopy --only-keep-debug". +RUN: %clang %S/Inputs/switch_statement.cpp -g -o %t +RUN: llvm-objcopy --only-keep-debug %t %t.debuginfo +RUN: not llvm-bolt %t.debuginfo -o /dev/null |& FileCheck %s + +CHECK: input binary is not a valid ELF executable diff --git a/bolt/test/X86/bolt_info.test b/bolt/test/X86/bolt_info.test new file mode 100644 index 000000000000..6ec614660ebe --- /dev/null +++ b/bolt/test/X86/bolt_info.test @@ -0,0 +1,7 @@ +# Check that the .bolt_info section is generated properly. +RUN: %clang %S/Inputs/switch_statement.cpp -o %t +RUN: llvm-bolt %t -o %t.bolt && \ +RUN: llvm-objdump -s -j .note.bolt_info %t.bolt | grep -v "file format" | \ +RUN: cut -c 44- | tr -d '\n' | FileCheck %s + +CHECK: BOLT revision: {{.*}}, command line: {{.*}}llvm-bolt {{.*}}/bolt_info.test.tmp -o {{.*}}/bolt_info.test.tmp.bolt