Skip to content

Commit 0718c1a

Browse files
[llvm-exegesis] Fix preservation of RDI in subprocess mode (#72458)
I made a typo at some point while doing the subprocess implementation, trying to pop RIP from the stack. For whatever reason, this ends up as popq %rax after being JITed, which means we aren't properly preserving the value of %rdi. Regression test added. This fixes #72188.
1 parent f4e3fb5 commit 0718c1a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# REQUIRES: exegesis-can-execute-x86_64
2+
3+
# RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mode=latency -snippets-file=%s -execution-mode=subprocess | FileCheck %s
4+
5+
# See comment in ./subprocess-abnormal-exit-code.s on the transient
6+
# PTRACE_ATTACH failure.
7+
# ALLOW_RETRIES: 2
8+
9+
# Check that the value of the registers preserved in subprocess mode while
10+
# making the ioctl system call are actually preserved correctly.
11+
12+
# LLVM-EXEGESIS-DEFREG RAX 11
13+
# LLVM-EXEGESIS-DEFREG RDI 13
14+
# LLVM-EXEGESIS-DEFREG RSI 17
15+
# LLVM-EXEGESIS-DEFREG R13 0
16+
# LLVM-EXEGESIS-DEFREG R12 127
17+
18+
cmpq $0x11, %rax
19+
cmovneq %r12, %r13
20+
cmpq $0x13, %rdi
21+
cmovneq %r12, %r13
22+
cmpq $0x17, %rsi
23+
cmovneq %r12, %r13
24+
25+
movq $60, %rax
26+
movq %r13, %rdi
27+
syscall
28+
29+
# CHECK-NOT: error: 'Child benchmarking process exited with non-zero exit code: Child process returned with unknown exit code'
30+

llvm/tools/llvm-exegesis/lib/X86/Target.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ ExegesisX86Target::configurePerfCounter(long Request, bool SaveRegisters) const
12051205
if(SaveRegisters) {
12061206
// Restore RAX, RDI, and RSI, in reverse order.
12071207
generateRegisterStackPop(X86::RSI, ConfigurePerfCounterCode);
1208-
generateRegisterStackPop(X86::RIP, ConfigurePerfCounterCode);
1208+
generateRegisterStackPop(X86::RDI, ConfigurePerfCounterCode);
12091209
generateRegisterStackPop(X86::RAX, ConfigurePerfCounterCode);
12101210
}
12111211
return ConfigurePerfCounterCode;

0 commit comments

Comments
 (0)