Skip to content

[X86] Don't save/restore fp/bp around terminator #106462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions llvm/lib/Target/X86/X86FrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4502,8 +4502,9 @@ void X86FrameLowering::spillFPBP(MachineFunction &MF) const {
bool InsideEHLabels = false;
auto MI = MBB.rbegin(), ME = MBB.rend();
auto TermMI = MBB.getFirstTerminator();
if (TermMI != MBB.begin())
MI = *(std::prev(TermMI));
if (TermMI == MBB.begin())
continue;
MI = *(std::prev(TermMI));

while (MI != ME) {
// Skip frame setup/destroy instructions.
Expand Down
43 changes: 43 additions & 0 deletions llvm/test/CodeGen/X86/clobber_frame_ptr.ll
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,46 @@ entry:
call void @llvm.eh.sjlj.longjmp(ptr @buf)
unreachable
}

declare ghccc void @tail()

; We should not save/restore fp/bp around terminator.
define ghccc void @test5() {
; CHECK-LABEL: test5:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rbp
; CHECK-NEXT: .cfi_def_cfa_offset 16
; CHECK-NEXT: .cfi_offset %rbp, -16
; CHECK-NEXT: movq %rsp, %rbp
; CHECK-NEXT: .cfi_def_cfa_register %rbp
; CHECK-NEXT: andq $-8, %rsp
; CHECK-NEXT: xorl %eax, %eax
; CHECK-NEXT: testb %al, %al
; CHECK-NEXT: jne .LBB3_2
; CHECK-NEXT: # %bb.1: # %then
; CHECK-NEXT: movq $0, (%rax)
; CHECK-NEXT: movq %rbp, %rsp
; CHECK-NEXT: popq %rbp
; CHECK-NEXT: .cfi_def_cfa %rsp, 8
; CHECK-NEXT: retq
; CHECK-NEXT: .LBB3_2: # %else
; CHECK-NEXT: .cfi_def_cfa %rbp, 16
; CHECK-NEXT: movq %rbp, %rsp
; CHECK-NEXT: popq %rbp
; CHECK-NEXT: .cfi_def_cfa %rsp, 8
; CHECK-NEXT: jmp tail@PLT # TAILCALL
entry:
br i1 undef, label %then, label %else

then:
store i64 0, ptr undef
br label %exit

else:
musttail call ghccc void @tail()
ret void

exit:
ret void
}

Loading