[llvm] [X86][GlobalISel] Support StructRet arguments (PR #96629)

Evgenii Kudriashov via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 25 08:01:59 PDT 2024


e-kud wrote:

> Does this cover the implicit sret case? Can you add a test that hits that condition?

@arsenm, the implicit case was supported earlier. There is already a test for it with `ret <32 x float> zeroinitializer`. Do we want more tests with structures?

> Is this really X86 specific or does it belong into CallLowering.cpp?

@qcolombet hmm, interesting. This is ABI dependent and according to SelectionDAG comments

| Target | ABI comment |
|--------|--------|
| X86 | All x86 ABIs require that for returning structs by value we copy the sret argument into %rax/%eax (depending on ABI) for the return |
| Sparc | If the function returns a struct, copy the SRetReturnReg to I0 |
| MSP430 | No comment. Looks like we must return a reference |
| Mips | The mips ABIs for returning structs by value requires that we copy the sret argument into $v0 for the return |
| M68k | ABI require that for returning structs by value we copy the sret argument into %D0 for the return | 
| Lanai | The Lanai ABI for returning structs by value requires that we copy the sret argument into rv for the return |
| AArch64 | Windows AArch64 ABIs require that for returning structs by value we copy the sret argument into X0 for the return |

Also each of these targets implements `getSRetReturnReg` that is not in the base class of `MachineFunctionInfo`.

So to generalize this approach:
1) We need to extract `{get,set}SRetReturnReg` into `MachineFunctionInfo`
2) We need a target hook something like `getSRetReturnReg` so `IRTranslator` is able to generate a copy instruction.
3) We need to be sure that adding a register to `RET` instruction is common among these targets. Or we need another hook to update `RET` instruction according to calling convention.
4) Some code aside `lowerFormalArguments` to call `setSRetReturnReg` when `StructRet` argument is present.

Looks like keeping it in target code is simpler.


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


More information about the llvm-commits mailing list