Skip to content

[X86] Speed up checking clobbered FP/BP #102365

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
Aug 8, 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
10 changes: 10 additions & 0 deletions llvm/lib/Target/X86/X86FrameLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4458,6 +4458,16 @@ void X86FrameLowering::spillFPBP(MachineFunction &MF) const {
FP = TRI->getFrameRegister(MF);
if (TRI->hasBasePointer(MF))
BP = TRI->getBaseRegister();

// Currently only inline asm and function call can clobbers fp/bp. So we can
// do some quick test and return early.
if (!MF.hasInlineAsm()) {
X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>();
if (!X86FI->getFPClobberedByCall())
FP = 0;
if (!X86FI->getBPClobberedByCall())
BP = 0;
}
if (!FP && !BP)
return;

Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Target/X86/X86ISelLoweringCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2450,6 +2450,11 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
}();
assert(Mask && "Missing call preserved mask for calling convention");

if (MachineOperand::clobbersPhysReg(Mask, RegInfo->getFrameRegister(MF)))
X86Info->setFPClobberedByCall(true);
if (MachineOperand::clobbersPhysReg(Mask, RegInfo->getBaseRegister()))
X86Info->setBPClobberedByCall(true);

// If this is an invoke in a 32-bit function using a funclet-based
// personality, assume the function clobbers all registers. If an exception
// is thrown, the runtime will not restore CSRs.
Expand Down
10 changes: 10 additions & 0 deletions llvm/lib/Target/X86/X86MachineFunctionInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ class X86MachineFunctionInfo : public MachineFunctionInfo {
SmallVector<size_t, 0> PreallocatedStackSizes;
SmallVector<SmallVector<size_t, 4>, 0> PreallocatedArgOffsets;

// True if a function clobbers FP/BP according to its calling convention.
bool FPClobberedByCall = false;
bool BPClobberedByCall = false;

private:
/// ForwardedMustTailRegParms - A list of virtual and physical registers
/// that must be forwarded to every musttail call.
Expand Down Expand Up @@ -328,6 +332,12 @@ class X86MachineFunctionInfo : public MachineFunctionInfo {
assert(!PreallocatedArgOffsets[Id].empty() && "arg offsets not set");
return PreallocatedArgOffsets[Id];
}

bool getFPClobberedByCall() const { return FPClobberedByCall; }
void setFPClobberedByCall(bool C) { FPClobberedByCall = C; }

bool getBPClobberedByCall() const { return BPClobberedByCall; }
void setBPClobberedByCall(bool C) { BPClobberedByCall = C; }
};

} // End llvm namespace
Expand Down
Loading