[PATCH] D127591: [X86] Emit .cfi_restore after popping callee-saved-registers if no red zone
Sihoon Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 12 02:47:22 PDT 2022
silee created this revision.
silee added reviewers: craig.topper, thegameg.
Herald added subscribers: jsji, StephenFan, pengfei, hiraditya.
Herald added a project: All.
silee requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
We discovered the bug <https://github.com/llvm/llvm-project/issues/55993>
If the function has no red zone, cfi of the popped callee-saved-registers should be invalidated with .cfi_restore instruction.
This commit will emit .cfi_restore instruction after popping callee-saved-registers if no red zone.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D127591
Files:
llvm/lib/Target/X86/X86FrameLowering.cpp
Index: llvm/lib/Target/X86/X86FrameLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86FrameLowering.cpp
+++ llvm/lib/Target/X86/X86FrameLowering.cpp
@@ -2166,6 +2166,9 @@
void X86FrameLowering::emitEpilogue(MachineFunction &MF,
MachineBasicBlock &MBB) const {
const MachineFrameInfo &MFI = MF.getFrameInfo();
+ MachineModuleInfo &MMI = MF.getMMI();
+ const MCRegisterInfo *MRI = MMI.getContext().getRegisterInfo();
+ const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
X86MachineFunctionInfo *X86FI = MF.getInfo<X86MachineFunctionInfo>();
MachineBasicBlock::iterator Terminator = MBB.getFirstTerminator();
MachineBasicBlock::iterator MBBI = Terminator;
@@ -2337,7 +2340,7 @@
if (NeedsWin64CFI && MF.hasWinCFI())
BuildMI(MBB, MBBI, DL, TII.get(X86::SEH_Epilogue));
- if (!HasFP && NeedsDwarfCFI) {
+ if (NeedsDwarfCFI) {
MBBI = FirstCSPop;
int64_t Offset = -CSSize - SlotSize;
// Mark callee-saved pop instruction.
@@ -2346,7 +2349,22 @@
MachineBasicBlock::iterator PI = MBBI;
unsigned Opc = PI->getOpcode();
++MBBI;
- if (Opc == X86::POP32r || Opc == X86::POP64r) {
+ if (Opc == X86::POP32r || Opc == X86::POP64r)
+ continue;
+ if (!has128ByteRedZone(MF)) {
+ Register Reg = PI->getOperand(0).getReg();
+ // Check if the poped register is callee-saved register.
+ if (std::find_if(CSI.begin(), CSI.end(),
+ [&Reg](const CalleeSavedInfo &I) -> bool {
+ return Reg == I.getReg();
+ }) != CSI.end()) {
+ unsigned DwarfReg = MRI->getDwarfRegNum(Reg, true);
+ BuildCFI(MBB, MBBI, DL,
+ MCCFIInstruction::createRestore(nullptr, DwarfReg),
+ MachineInstr::FrameDestroy);
+ }
+ }
+ if (!HasFP) {
Offset += SlotSize;
BuildCFI(MBB, MBBI, DL,
MCCFIInstruction::cfiDefCfaOffset(nullptr, -Offset),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127591.436201.patch
Type: text/x-patch
Size: 2083 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220612/c3d34106/attachment.bin>
More information about the llvm-commits
mailing list