[llvm] [SystemZ] Eliminate call sequence instructions early. (PR #77812)

Jonas Paulsson via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 12 09:38:27 PST 2024


JonPsson1 wrote:

> > Do we need to support the inline-asm alignstack attribute? In that case we need to do a similar handling of INLINEASM[_BR] instructions to set the adjustsStack flag. My understanding is however that the stack is always aligned at 8 bytes and therefore this is not needed...?
> 
> I don't think this flag currently causes any special action on Z. (But it would be good to try a few test cases to verify that!) However, if and when that might change in the future, it wouldn't be good if the generic infrastructure around the flag is somehow broken ...

My simple test case shows that this flag actually has an effect:

```
define i64 @f1() {
  %val = call i64 asm alignstack "blah $0 $1", "=r,a" (i8 1)
  ret i64 %val
}
```
SelectionDAGISel (.cpp:674) actually checks for this attribute with MI.isStackAligningInlineAsm() and sets the HasCalls flag. So regardless of the AdjustsStack flag, the HasCall flag causes the reg save area to be created in the prolog, with or w/out this patch.

I wonder why not the AdjustsStack is not set here directly instead of searching for it in PEI... Does not HasCalls always imply AdjustsStack?

The only place the AdjustsStack flag is used in SystemZFrameLowering is  in isXPLeafCandidate(), but there HasCalls has been checked before already, so it wouldn't matter in this case.

PEI uses adjustsStack() if target returns false from targetHandlesStackFrameRounding() to round up the stack frame size to meet the stack alignment. I wonder if we could return true here instead as on ELF it seems SP is always aligned properly to 8 bytes, and in XPLINK there seems to be a rounding to 64 bytes which would cover the 32 byte stack alignment.

> 
> As a more general question, would we be the first platform to not use the adjuststack pseudos, or is there precedent? If the latter, how are they handling this issue?

I saw that R600 is already doing this, and in PEI::calculateCallFrameInfo() there is already:
```
  // Early exit for targets which have no call frame setup/destroy pseudo
  // instructions.
  if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u)
    return;
```

Not sure really what that GPU is doing, but it seems very different from X86/SystemZ.




https://github.com/llvm/llvm-project/pull/77812


More information about the llvm-commits mailing list