This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Don't include X1 in the X0_PD register pair
ClosedPublic

Authored by asb on Jun 28 2023, 7:04 AM.

Details

Summary

Zdinx on RV32 defines the D instructions as taking even register pairs, and specifies that if using X0 when as a destination then X1 won't be written, and if using X0 as a source then the value is still all 0s (i.e. X1 isn't read). Therefore, it's incorrect to model X0_PD as having X1 as a subregister. This will also be the case for register pairs in Zacas and the P extension (and this patch takes the same approach as D95588 does).

This patch introduces a dummy register that is solely used as a subreg alongside X0 in X0_PD. An earlier version of the patch had a minor effect on register allocation in some tests, which is now avoided by:

  1. Adding RISCV::DUMMY_REG_PAIR_WITH_X0 to RISCVRegisterInfo::getReservedRegs
  2. Defining a new register class that includes DUMMY_REG_PAIR_WITH_X0

Diff Detail

Event Timeline

asb created this revision.Jun 28 2023, 7:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2023, 7:04 AM
asb requested review of this revision.Jun 28 2023, 7:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2023, 7:04 AM

I don't have any better ideas. The test change is kind of weird.

asb added a subscriber: MatzeB.Jul 12 2023, 7:31 AM

I don't have any better ideas. The test change is kind of weird.

From tracing through, I think (at least from looking for the likely divergence in a -debug trace) the issue is a change in the regPressureSetLimit for GPRs (going from 28 to 29). The PGPR regpressure limit goes from 14 to 13 and GPRC_with_PGPR changes name to PGPR_with_GPRC and goes from 20 to 19.

@MatzeB does this sound like a possible bug in the register pressure code (or indeed, us doing something wrong), or is this just expected change when altering the register set?

Do we need to reserve the new register in RISCVRegisterInfo::getReservedRegs?

asb added a comment.Jul 12 2023, 9:28 AM

Do we need to reserve the new register in RISCVRegisterInfo::getReservedRegs?

Good suggestion. We might need to, but unfortunately that has no impact on the changed test case.

Do we need to reserve the new register in RISCVRegisterInfo::getReservedRegs?

Good suggestion. We might need to, but unfortunately that has no impact on the changed test case.

Marking the register reserved and adding this to RISCVRegisterInfo.td recovers the tests.

def GPRAll : GPRRegisterClass<(add GPR, DUMMY_REG_PAIR_WITH_X0)>;
asb updated this revision to Diff 542013.Jul 19 2023, 7:21 AM
asb edited the summary of this revision. (Show Details)

Updated to incorporate suggested fixes from @craig.topper that means unwanted codegen changes are avoided.

This revision is now accepted and ready to land.Jul 19 2023, 10:31 AM
This revision was automatically updated to reflect the committed changes.