[X86] Don't use rbp when it's reserved#146638
Merged
Conversation
Member
|
@llvm/pr-subscribers-backend-x86 Author: Brandt Bucher (brandtbucher) ChangesThis fixes the x86 backend to properly reserve Disassembly of the new test case before: pushq %rbp
pushq %rbx
pushq %rax
movl %esi, %ebx
movl %edi, %ebp
callq bar@<!-- -->PLT
movl %ebp, %edi
movl %ebx, %esi
callq bar@<!-- -->PLT
addq $8, %rsp
popq %rbx
popq %rbp
retq...and after ( pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movl %edi, %r14d
callq bar@<!-- -->PLT
movl %r14d, %edi
movl %ebx, %esi
callq bar@<!-- -->PLT
addq $8, %rsp
popq %rbx
popq %r14
retqFixes #117178. Full diff: https://github.com/llvm/llvm-project/pull/146638.diff 2 Files Affected:
diff --git a/llvm/lib/Target/X86/X86RegisterInfo.cpp b/llvm/lib/Target/X86/X86RegisterInfo.cpp
index 9adac067aace8..83b11eede829e 100644
--- a/llvm/lib/Target/X86/X86RegisterInfo.cpp
+++ b/llvm/lib/Target/X86/X86RegisterInfo.cpp
@@ -562,7 +562,7 @@ BitVector X86RegisterInfo::getReservedRegs(const MachineFunction &MF) const {
Reserved.set(SubReg);
// Set the frame-pointer register and its aliases as reserved if needed.
- if (TFI->hasFP(MF)) {
+ if (TFI->hasFP(MF) || MF.getTarget().Options.FramePointerIsReserved(MF)) {
if (MF.getInfo<X86MachineFunctionInfo>()->getFPClobberedByInvoke())
MF.getContext().reportError(
SMLoc(),
diff --git a/llvm/test/CodeGen/X86/frame-pointer-reserved.ll b/llvm/test/CodeGen/X86/frame-pointer-reserved.ll
new file mode 100644
index 0000000000000..bf5887fe50508
--- /dev/null
+++ b/llvm/test/CodeGen/X86/frame-pointer-reserved.ll
@@ -0,0 +1,25 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown | FileCheck %s
+
+declare void @bar(i32, i32)
+
+define void @foo(i32 %0, i32 %1) nounwind "frame-pointer"="reserved" {
+; CHECK-LABEL: foo:
+; CHECK: # %bb.0:
+; CHECK-NEXT: pushq %r14
+; CHECK-NEXT: pushq %rbx
+; CHECK-NEXT: pushq %rax
+; CHECK-NEXT: movl %esi, %ebx
+; CHECK-NEXT: movl %edi, %r14d
+; CHECK-NEXT: callq bar@PLT
+; CHECK-NEXT: movl %r14d, %edi
+; CHECK-NEXT: movl %ebx, %esi
+; CHECK-NEXT: callq bar@PLT
+; CHECK-NEXT: addq $8, %rsp
+; CHECK-NEXT: popq %rbx
+; CHECK-NEXT: popq %r14
+; CHECK-NEXT: retq
+ call void @bar(i32 %0, i32 %1)
+ call void @bar(i32 %0, i32 %1)
+ ret void
+}
|
RKSimon
approved these changes
Jul 7, 2025
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/207/builds/3511 Here is the relevant piece of the build log for the reference |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes the x86 backend to properly reserve
rbpwhen theframe-pointer=reservedoption is used. Currently, this option is ignored.Disassembly of the new test case before:
...and after (
r14is used as scratch space in place ofrbp):Fixes #117178.