Skip to content

[X86] Refine speed up checking clobbered FP/BP to make IPRA work. #109246

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

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 7 additions & 2 deletions llvm/lib/Target/X86/X86FrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4495,7 +4495,10 @@ void X86FrameLowering::spillFPBP(MachineFunction &MF) const {

// Currently only inline asm and function call can clobbers fp/bp. So we can
// do some quick test and return early.
if (!MF.hasInlineAsm()) {
// And when IPRA is on, callee may also clobber fp/bp.
// FIXME: setF/BPClobberedByCall(true) in RegUsageInfoPropagation::setRegMask
// so we don't need the condition of IPRA here.
if (!MF.hasInlineAsm() && !MF.getTarget().Options.EnableIPRA) {
X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>();
if (!X86FI->getFPClobberedByCall())
FP = 0;
Expand Down Expand Up @@ -4567,7 +4570,9 @@ void X86FrameLowering::spillFPBP(MachineFunction &MF) const {

// If the bp is clobbered by a call, we should save and restore outside of
// the frame setup instructions.
if (KillMI->isCall() && DefMI != ME) {
// When IPRA is enabled, we could skip this step.
if (KillMI->isCall() && DefMI != ME &&
!MF.getTarget().Options.EnableIPRA) {
auto FrameSetup = std::next(DefMI);
// Look for frame setup instruction toward the start of the BB.
// If we reach another call instruction, it means no frame setup
Expand Down
37 changes: 37 additions & 0 deletions llvm/test/CodeGen/X86/ipra-local-linkage-2.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc -enable-ipra < %s | FileCheck %s

target triple = "x86_64--"

define internal void @foo() norecurse {
; CHECK-LABEL: foo:
; CHECK: # %bb.0:
; CHECK-NEXT: #APP
; CHECK-NEXT: xorl %ebp, %ebp
; CHECK-NEXT: #NO_APP
; CHECK-NEXT: retq
call void asm sideeffect "xor %ebp, %ebp", "~{ebp}"()
ret void
}

define void @bar(i32 %X) "frame-pointer"="all" nounwind {
; When $rbp is clobbered by foo() and IPRA is enabled, $rbp should be spill/reload before/after call foo
; CHECK-LABEL: bar:
; CHECK: # %bb.0:
; CHECK-NEXT: pushq %rbp
; CHECK-NEXT: movq %rsp, %rbp
; CHECK-NEXT: subq $16, %rsp
; CHECK-NEXT: pushq %rbp
; CHECK-NEXT: pushq %rax
; CHECK-NEXT: callq foo
; CHECK-NEXT: addq $8, %rsp
; CHECK-NEXT: popq %rbp
; CHECK-NEXT: movl $5, -4(%rbp)
; CHECK-NEXT: addq $16, %rsp
; CHECK-NEXT: popq %rbp
; CHECK-NEXT: retq
call void @foo()
%addr = alloca i32, align 4
store i32 5, ptr %addr, align 4
ret void
}
Loading