Page MenuHomePhabricator

[RISCV] Set CostPerUse for registers

Authored by sabuasal on May 17 2018, 4:40 PM.



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.

Diff Detail


Event Timeline

sabuasal created this revision.May 17 2018, 4:40 PM
asb added a comment.May 18 2018, 1:00 AM

Thanks Sameer. With an explanatory comment in 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.

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.

sabuasal updated this revision to Diff 147589.May 18 2018, 2:28 PM
sabuasal retitled this revision from [RISCV] [WIP] patch for setting CostPer use in registers. to [RISCV] Set CostPerUse for registers.
sabuasal edited the summary of this revision. (Show Details)

Added descriptive comments for rationale behind setting the CostPerUse property.

sabuasal updated this revision to Diff 147591.May 18 2018, 2:28 PM

is this good to merge?

asb accepted this revision.May 23 2018, 2:04 PM

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.

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.

This revision is now accepted and ready to land.May 23 2018, 2:04 PM
sabuasal updated this revision to Diff 148286.May 23 2018, 2:31 PM

Updated the comment.

I also experimented with leaving the X2 out, I didn't see any changes.

This revision was automatically updated to reflect the committed changes.