Skip to content

Commit 67be07e

Browse files
committed
Minimize the test case for better comprehension
1 parent c7a9a17 commit 67be07e

File tree

1 file changed

+16
-51
lines changed

1 file changed

+16
-51
lines changed
Lines changed: 16 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
// Test how BOLT handles indirect branch sequence of instructions in
22
// AArch64MCPlus builder.
3-
// This test checks the pattern where there is no shift amount after add
4-
// instruction. The pattern come from libc, it can be reproduced with
5-
// a 'static' built binary.
3+
4+
// clang-format off
5+
6+
// REQUIRES: system-linux
7+
// RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
8+
// RUN: %clang %cflags --target=aarch64-unknown-linux %t.o -o %t.exe -Wl,-q
9+
// RUN: llvm-bolt %t.exe -o %t.bolt --print-cfg \
10+
// RUN: -v=1 2>&1 | FileCheck %s
11+
12+
// Pattern 1: there is no shift amount after the 'add' instruction.
613
//
714
// adr x6, 0x219fb0 <sigall_set+0x88>
815
// add x6, x6, x14, lsl #2
916
// ldr w7, [x6]
1017
// add x6, x6, w7, sxtw => no shift amount
1118
// br x6
1219
//
13-
// It also tests another case where there is no adrp/add pair.
14-
// The pattern also come from libc, and it only represents in the binary
15-
// if the lld linker is used to create the static binary.
16-
// It doesn't occur with GCC ld linker.
20+
21+
// Pattern 2: nop/adr pair is used in place of adrp/add
1722
//
1823
// nop => nop/adr instead of adrp/add
1924
// adr x13, 0x215a18 <_nl_value_type_LC_COLLATE+0x50>
@@ -22,89 +27,49 @@
2227
// add x13, x12, w13, sxth #2
2328
// br x13
2429

25-
// clang-format off
26-
27-
// REQUIRES: system-linux
28-
// RUN: llvm-mc -filetype=obj -triple aarch64-unknown-unknown %s -o %t.o
29-
// RUN: %clang %cflags --target=aarch64-unknown-linux %t.o -o %t.exe -Wl,-q
30-
// RUN: llvm-bolt %t.exe -o %t.bolt --print-cfg \
31-
// RUN: -v=1 2>&1 | FileCheck %s
32-
33-
// CHECK: BOLT-WARNING: Failed to match indirect branch: nop/adr instead of adrp/add
34-
// CHECK: BOLT-WARNING: Failed to match indirect branch: ShiftVAL != 2
35-
36-
3730
.section .text
3831
.align 4
3932
.globl _start
4033
.type _start, %function
4134
_start:
42-
bl bar
43-
bl end
35+
mov w1, #1
36+
bl bar
4437
mov x0, #4
4538
mov w8, #93
4639
svc #0
4740

4841
bar:
49-
mov w1, #3
50-
cmp x1, #0
51-
b.eq end
5242
nop
5343
adr x3, jump_table
5444
ldrh w3, [x3, x1, lsl #1]
5545
adr x1, .case0
5646
add x3, x1, w3, sxth #2
5747
br x3
48+
// CHECK: BOLT-WARNING: Failed to match indirect branch: nop/adr instead of adrp/add
5849
.case0:
5950
mov w0, #1
6051
ret
6152
.case1:
62-
mov w0, #2
63-
ret
64-
.case3:
65-
mov w0, #3
66-
ret
67-
.case4:
68-
nop
6953
mov x1, #0
7054
adr x3, datatable
7155
add x3, x3, x1, lsl #2
7256
ldr w2, [x3]
7357
add x3, x3, w2, sxtw
7458
br x3
75-
nop
76-
mov w0, #4
77-
ret
78-
.case7:
79-
mov w0, #4
80-
ret
81-
59+
// CHECK: BOLT-WARNING: Failed to match indirect branch: ShiftVAL != 2
8260
foo1:
8361
ret
84-
8562
foo2:
86-
add w0, w0, #3
8763
ret
88-
8964
foo3:
90-
add w0, w0, #3
9165
ret
9266

93-
end:
94-
add x0, x0, #99
95-
ret
96-
9767
.section .rodata,"a",@progbits
9868
jump_table:
9969
.hword (.case0-.case0)>>2
10070
.hword (.case1-.case0)>>2
101-
.hword (.case3-.case0)>>2
102-
.hword (.case4-.case0)>>2
103-
.hword (.case7-.case0)>>2
104-
10571

10672
datatable:
10773
.word foo1-datatable
10874
.word foo2-datatable
10975
.word foo3-datatable
110-
.word 20

0 commit comments

Comments
 (0)