[RISCV] Avoid scalar outgoing argumetns overwriting vector frame objects.
authorHsiangkai Wang <kai.wang@sifive.com>
Thu, 3 Jun 2021 15:45:49 +0000 (23:45 +0800)
committerHsiangkai Wang <kai.wang@sifive.com>
Fri, 11 Jun 2021 04:26:29 +0000 (12:26 +0800)
commit643b6407faf460915679f304420cfbee87c47734
tree0e56397b3bec2b474f28dec523a851e00d3ecf6a
parent54418c5a355eda7ff77a221c692ee90944c25196
[RISCV] Avoid scalar outgoing argumetns overwriting vector frame objects.

When using FP to access stack objects, the scalable stack objects will
be put at the lower end of the frame. It looks like

```
|-------------------|  <-- FP
| callee-saved regs |
|-------------------|
| scalar local vars |
|-------------------|
| RVV local vars    |
|-------------------|  <-- SP
```

If there are scalar arguments that need to pass through memory and there
are vector objects on the stack using FP to access. The outgoing scalar
arguments will overwrite the vector objects. It looks like

```
|-------------------|  <-- FP
| callee-saved regs |
|-------------------|
| scalar local vars |
|-------------------|         |-------------------|
| RVV local vars    |         | outgoing args     | <- outgoing arguments
|-------------------|  <-- SP |-------------------|    overwrite from here.
```

In this patch, we reserve the stack for the outgoing arguments before
function calls if using FP to access and there are scalable vector frame
objects. It looks like

```
|-------------------|  <-- FP
| callee-saved regs |
|-------------------|
| scalar local vars |
|-------------------|
| RVV local vars    |
|-------------------|
| outgoing args     |
|-------------------|  <-- SP
```

Differential Revision: https://reviews.llvm.org/D103622
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
llvm/test/CodeGen/RISCV/rvv/rvv-out-arguments.ll