This is an archive of the discontinued LLVM Phabricator instance.

X86, PEI, WIP: Convert to backwards frame index elimination
Needs ReviewPublic

Authored by foad on Jun 8 2023, 8:55 AM.

Details

Summary

Add support for call sequences to the backwards implementation of frame
index elimination and convert X86 to use it.

The goal is to convert all targets to backwards frame index elimination
and backwards register scavenging, which is preferred because it does
not rely on accurate kill flags.

X86 does not actually scavenge registers during frame index elimination
but doing the conversion is useful for flushing out problems in the call
sequence handling.

Diff Detail

Event Timeline

foad created this revision.Jun 8 2023, 8:55 AM
foad requested review of this revision.Jun 8 2023, 8:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2023, 8:55 AM

This is WIP. Some codegen tests fail. I need help on a couple of X86 things please:

  1. X86InstrInfo::getSPAdjust gets information about the stack adjustment of a CALL by searching for the following ADJCALLSTACKUP. That doesn't work if you're processing the basic block backwards, since the ADJCALLSTACKUP will already have been eliminated. Can I somehow put the information in the preceding ADJCALLSTACKDOWN instead? I see that both opcodes take two immediate values but I have not found good documentation on what they mean.
  1. When PEI::replaceFrameIndicesBackward(MachineFunction &) processes a basic block that ends with a return, it assumes that SPAdj is 0 at the end of the block. I think it needs to account for return instructions like "RET 4", which move SP by 4, but currently PEI only calls getSPAdjust on instructions which are "frame setup" or "frame destroy" or part of a call sequence - and RET is none of those things. Is there a clean way to handle this?
llvm/lib/Target/X86/X86InstrInfo.cpp
427

I now think that this is just wrong, since operand(1) of ADJCALLSTACKDOWN is a completely different thing from operand(1) of ADJCALLSTACKUP.

foad updated this revision to Diff 546773.Aug 3 2023, 2:43 AM

Rebase.