Skip to content

Commit 63c3148

Browse files
[llvm-exegesis] Fix stack pointer register restoration
9eb80ab changed the method for stack pointer restoration to fix segmentation faults. However, I made a mistake in the patch and swapped a != for a ==, which caused an arbitrary register (the first one specified) to get restored rather than the stack pointer specifically. This patch fixes that issue and adds test coverage to prevent regression.
1 parent 2205d23 commit 63c3148

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

llvm/test/tools/llvm-exegesis/X86/latency/subprocess-preserved-registers.s

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,48 @@
77

88
# LLVM-EXEGESIS-DEFREG RAX 3
99
# LLVM-EXEGESIS-DEFREG RCX 5
10-
# LLVM-EXEGESIS-DEFREG RDI 7
11-
# LLVM-EXEGESIS-DEFREG RSI B
12-
# LLVM-EXEGESIS-DEFREG R11 D
10+
# LLVM-EXEGESIS-DEFREG RDX 7
11+
# LLVM-EXEGESIS-DEFREG RBX B
12+
# LLVM-EXEGESIS-DEFREG RSI D
13+
# LLVM-EXEGESIS-DEFREG RDI 11
14+
# LLVM-EXEGESIS-DEFREG RSP 13
15+
# LLVM-EXEGESIS-DEFREG RBP 17
16+
# LLVM-EXEGESIS-DEFREG R8 1D
17+
# LLVM-EXEGESIS-DEFREG R9 1F
18+
# LLVM-EXEGESIS-DEFREG R10 29
19+
# LLVM-EXEGESIS-DEFREG R11 2B
20+
# LLVM-EXEGESIS-DEFREG R12 2F
21+
# LLVM-EXEGESIS-DEFREG R13 35
1322
# LLVM-EXEGESIS-DEFREG R14 127
1423
# LLVM-EXEGESIS-DEFREG R15 0
1524

1625
cmpq $0x3, %rax
1726
cmovneq %r14, %r15
1827
cmpq $0x5, %rcx
1928
cmovneq %r14, %r15
20-
cmpq $0x7, %rdi
29+
cmpq $0x7, %rdx
2130
cmovneq %r14, %r15
22-
cmpq $0xB, %rsi
31+
cmpq $0xB, %rbx
2332
cmovneq %r14, %r15
24-
cmpq $0xD, %r11
33+
cmpq $0xD, %rsi
34+
cmovneq %r14, %r15
35+
cmpq $0x11, %rdi
36+
cmovneq %r14, %r15
37+
cmpq $0x13, %rsp
38+
cmovneq %r14, %r15
39+
cmpq $0x17, %rbp
40+
cmovneq %r14, %r15
41+
cmpq $0x1d, %r8
42+
cmovneq %r14, %r15
43+
cmpq $0x1f, %r9
44+
cmovneq %r14, %r15
45+
cmpq $0x29, %r10
46+
cmovneq %r14, %r15
47+
cmpq $0x2b, %r11
48+
cmovneq %r14, %r15
49+
cmpq $0x2f, %r12
50+
cmovneq %r14, %r15
51+
cmpq $0x35, %r13
2552
cmovneq %r14, %r15
2653

2754
movq $60, %rax

llvm/tools/llvm-exegesis/lib/Assembler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static bool generateSnippetSetupCode(
9797
// Load in the stack register now as we're done using it elsewhere
9898
// and need to set the value in preparation for executing the
9999
// snippet.
100-
if (RV.Register == StackPointerRegister)
100+
if (RV.Register != StackPointerRegister)
101101
continue;
102102
const auto SetRegisterCode = ET.setRegTo(*MSI, RV.Register, RV.Value);
103103
if (SetRegisterCode.empty())

0 commit comments

Comments
 (0)