Set CostPerUse higher for registers that are not used in the compressed
instruction set. This will influence the greedy register allocator to reduce
the use of registers that can't be encoded in 16 bit instructions. This
affects register allocation even when compressed instruction isn't targeted,
we see no major negative codegen impact.
Details
Diff Detail
Event Timeline
Thanks Sameer. With an explanatory comment in RISCVRegisterInfo.td this looks good to me.
When playing with this I left X0 with 0 CostPerUse despite the fact X0 isn't in GPRC, on the basis that discouraging the use of X0 seems like a poor strategy and is more likely to lead to undesirable codegen decisions when not optimising for codesize.
SP (X2) also has a CostPerUse=1 here. Although it's not in GPRC, there are of course specialised compressed instructions for stack load/store and addition meaning there's a good argument for leaving it with CostPerUse = 0. Given SP isn't allocatable anyway, there may be little/no impact either way.
lib/Target/RISCV/RISCVRegisterInfo.td | ||
---|---|---|
39 ↗ | (On Diff #147410) | It would be worth adding a comment here to explain the motivation for setting CostPerUse and maybe saying that although it affects register allocation even when the compressed instruction set isn't targeted, we see no major negative codegen impact. |
I tried leaving X2 with CostPerUse = 0 just to see if there were any cases where it could affect codegen. I wasn't able to generate any for the inputs I threw at it.
This looks good to me, but see my suggestion about tweaking the comment slightly.
lib/Target/RISCV/RISCVRegisterInfo.td | ||
---|---|---|
41 ↗ | (On Diff #147591) | How about "CostPerUse is set higher for registers that may not be compressible as they are not part of GPRC, the most restrictive register class used by the compressed instruction set." A number of compressed instructions of course can access a wider range of registers, so this is a pessimistic choice. |
Updated the comment.
I also experimented with leaving the X2 out, I didn't see any changes.