Skip to content
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

[X86] Recognize POP/ADD/SUB modifying rsp in getSPAdjust. #114265

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
31 changes: 29 additions & 2 deletions llvm/lib/Target/X86/X86InstrInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,13 @@ int X86InstrInfo::getSPAdjust(const MachineInstr &MI) const {
return -(I->getOperand(1).getImm());
}

// Currently handle only PUSHes we can reasonably expect to see
// in call sequences
// Handle other opcodes we reasonably expect to see in call
// sequences. Note this may include spill/restore of FP/BP.
switch (MI.getOpcode()) {
default:
assert(!(MI.modifiesRegister(X86::RSP, &RI) ||
MI.getDesc().hasImplicitDefOfPhysReg(X86::RSP)) &&
"Unhandled opcode in getSPAdjust");
return 0;
case X86::PUSH32r:
case X86::PUSH32rmm:
Expand All @@ -467,6 +470,30 @@ int X86InstrInfo::getSPAdjust(const MachineInstr &MI) const {
case X86::PUSH64rmr:
case X86::PUSH64i32:
return 8;
case X86::POP32r:
case X86::POP32rmm:
case X86::POP32rmr:
return -4;
case X86::POP64r:
case X86::POP64rmm:
case X86::POP64rmr:
return -8;
// FIXME: (implement and) use isAddImmediate in the
// default case instead of the following ADD/SUB cases.
case X86::ADD32ri:
case X86::ADD32ri8:
case X86::ADD64ri32:
if (MI.getOperand(0).getReg() == X86::RSP &&
MI.getOperand(1).getReg() == X86::RSP)
return -MI.getOperand(2).getImm();
return 0;
case X86::SUB32ri:
case X86::SUB32ri8:
case X86::SUB64ri32:
if (MI.getOperand(0).getReg() == X86::RSP &&
MI.getOperand(1).getReg() == X86::RSP)
return MI.getOperand(2).getImm();
return 0;
}
}

Expand Down
Loading