Skip to content

Commit 7e5fe69

Browse files
authored
[X86] Speed up checking clobbered FP/BP (#102365)
Most functions don't clobber frame register and base pointer. They are usually caused by inline asm and function call. So we can record if a function call clobber FP/BP at lowering phase, and later we can check the recorded information and return early.
1 parent 7a4fc74 commit 7e5fe69

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

llvm/lib/Target/X86/X86FrameLowering.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4458,6 +4458,16 @@ void X86FrameLowering::spillFPBP(MachineFunction &MF) const {
44584458
FP = TRI->getFrameRegister(MF);
44594459
if (TRI->hasBasePointer(MF))
44604460
BP = TRI->getBaseRegister();
4461+
4462+
// Currently only inline asm and function call can clobbers fp/bp. So we can
4463+
// do some quick test and return early.
4464+
if (!MF.hasInlineAsm()) {
4465+
X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>();
4466+
if (!X86FI->getFPClobberedByCall())
4467+
FP = 0;
4468+
if (!X86FI->getBPClobberedByCall())
4469+
BP = 0;
4470+
}
44614471
if (!FP && !BP)
44624472
return;
44634473

llvm/lib/Target/X86/X86ISelLoweringCall.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,6 +2450,11 @@ X86TargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
24502450
}();
24512451
assert(Mask && "Missing call preserved mask for calling convention");
24522452

2453+
if (MachineOperand::clobbersPhysReg(Mask, RegInfo->getFrameRegister(MF)))
2454+
X86Info->setFPClobberedByCall(true);
2455+
if (MachineOperand::clobbersPhysReg(Mask, RegInfo->getBaseRegister()))
2456+
X86Info->setBPClobberedByCall(true);
2457+
24532458
// If this is an invoke in a 32-bit function using a funclet-based
24542459
// personality, assume the function clobbers all registers. If an exception
24552460
// is thrown, the runtime will not restore CSRs.

llvm/lib/Target/X86/X86MachineFunctionInfo.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ class X86MachineFunctionInfo : public MachineFunctionInfo {
170170
SmallVector<size_t, 0> PreallocatedStackSizes;
171171
SmallVector<SmallVector<size_t, 4>, 0> PreallocatedArgOffsets;
172172

173+
// True if a function clobbers FP/BP according to its calling convention.
174+
bool FPClobberedByCall = false;
175+
bool BPClobberedByCall = false;
176+
173177
private:
174178
/// ForwardedMustTailRegParms - A list of virtual and physical registers
175179
/// that must be forwarded to every musttail call.
@@ -328,6 +332,12 @@ class X86MachineFunctionInfo : public MachineFunctionInfo {
328332
assert(!PreallocatedArgOffsets[Id].empty() && "arg offsets not set");
329333
return PreallocatedArgOffsets[Id];
330334
}
335+
336+
bool getFPClobberedByCall() const { return FPClobberedByCall; }
337+
void setFPClobberedByCall(bool C) { FPClobberedByCall = C; }
338+
339+
bool getBPClobberedByCall() const { return BPClobberedByCall; }
340+
void setBPClobberedByCall(bool C) { BPClobberedByCall = C; }
331341
};
332342

333343
} // End llvm namespace

0 commit comments

Comments
 (0)