Skip to content

Commit 499c3fc

Browse files
committed
Minimize the test case for better comprehension
1 parent e72ceab commit 499c3fc

File tree

1 file changed

+46
-73
lines changed

1 file changed

+46
-73
lines changed
Lines changed: 46 additions & 73 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 --strict\
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,57 @@
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
44-
mov x0, #4
45-
mov w8, #93
46-
svc #0
35+
bl test1
36+
bl test2
37+
// mov x0, #4
38+
// mov w8, #93
39+
// svc #0
4740

48-
bar:
49-
mov w1, #3
50-
cmp x1, #0
51-
b.eq end
52-
nop
53-
adr x3, jump_table
54-
ldrh w3, [x3, x1, lsl #1]
55-
adr x1, .case0
56-
add x3, x1, w3, sxth #2
57-
br x3
58-
.case0:
59-
mov w0, #1
60-
ret
61-
.case1:
62-
mov w0, #2
63-
ret
64-
.case3:
65-
mov w0, #3
66-
ret
67-
.case4:
68-
nop
41+
// Pattern 1
42+
// CHECK: BOLT-WARNING: Failed to match indirect branch: ShiftVAL != 2
43+
.globl test1
44+
.type test1, %function
45+
test1:
6946
mov x1, #0
7047
adr x3, datatable
7148
add x3, x3, x1, lsl #2
7249
ldr w2, [x3]
7350
add x3, x3, w2, sxtw
7451
br x3
75-
nop
76-
mov w0, #4
77-
ret
78-
.case7:
79-
mov w0, #4
80-
ret
81-
82-
foo1:
52+
test1_0:
8353
ret
84-
85-
foo2:
86-
add w0, w0, #3
54+
test1_1:
8755
ret
88-
89-
foo3:
90-
add w0, w0, #3
56+
test1_2:
9157
ret
9258

93-
end:
94-
add x0, x0, #99
59+
// Pattern 2
60+
// CHECK: BOLT-WARNING: Failed to match indirect branch: nop/adr instead of adrp/add
61+
.globl test2
62+
.type test2, %function
63+
test2:
64+
nop
65+
adr x3, jump_table
66+
ldrh w3, [x3, x1, lsl #1]
67+
adr x1, test2_0
68+
add x3, x1, w3, sxth #2
69+
br x3
70+
test2_0:
71+
ret
72+
test2_1:
9573
ret
9674

9775
.section .rodata,"a",@progbits
98-
jump_table:
99-
.hword (.case0-.case0)>>2
100-
.hword (.case1-.case0)>>2
101-
.hword (.case3-.case0)>>2
102-
.hword (.case4-.case0)>>2
103-
.hword (.case7-.case0)>>2
104-
105-
10676
datatable:
107-
.word foo1-datatable
108-
.word foo2-datatable
109-
.word foo3-datatable
110-
.word 20
77+
.word test1_0-datatable
78+
.word test1_1-datatable
79+
.word test1_2-datatable
80+
81+
jump_table:
82+
.hword (test2_0-test2_0)>>2
83+
.hword (test2_1-test2_0)>>2

0 commit comments

Comments
 (0)