[llvm] [RISCV][WIP] Let RA do the CSR saves. (PR #90819)

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 20 03:25:03 PDT 2024


qcolombet wrote:

Hi @mgudim 

> At this point I just want to understand if I should continue with this approach or not. If "yes", I'll investigate the degradation on xz, figure out what goes wrong if function unwinds and add tests.

The approach is not crazy at all!
In fact, I believe LLVM current approach is the crazy one :).
I believe you will have a bunch of regressions as it stands though. Up to you to pursue.
Since you're doing that only for 1 target and not all of them, you may have an easier time to track and fix the regression (as opposed to changing RA for all targets at once.)

FWIW, I believe the whole CSR distinction in LLVM is wrong and the proper way to handle them would be to issue parallel copies in the entry block and exit blocks right during ISel (at the very beginning).
In a sense what you are doing is reproducing exactly that, although you do not use parallel copies.

As you saw, this change in representation creates regression because the CSR distinction is baked left and right in the backend. So we can fix them as we find them, but there'll be a long tail.

One remark, since you're not using parallel copies, you're creating artificial interferences and that can have a cascading effect. (See below.) Even if you were to use parallel copies (in LLVM that would be bundles of copies) that wouldn't work out-of-the-box either since this constructs is not a first class citizen.

The TL;DR is you're testing the RA heuristic in ways that has not been exercised and some things will get better, some things will get worse.

Example of issue with CSR using sequential copies
```
v1 = COPY csr1
v2 = COPY csr2
v3 = COPY csr3
```

If for some reason `csr3` gets used for something else, you are at the mercy of the RA ordering for the coalescing. I.e., worst case, you may end up with:
```
some_reg = COPY csr1
csr1 = COPY csr2
csr2 = COPY csr3
```
instead of
```
csr1 = COPY csr1 # no-op
csr2 = COPY csr2 # no-op
some_reg = COPY csr3
```

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


More information about the llvm-commits mailing list