This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Use GPRNoX0 for source register to WriteSysReg/SwapSysReg pseudo instructions.
AbandonedPublic

Authored by craig.topper on Sep 1 2021, 11:00 AM.

Details

Summary

Having X0 as a source of a CSRRW means don't write the register. To
write a 0, you should use CSRRWI instead. ISel normally takes care of
this. To further guarantee this I've merged the classes so we must
have isel patterns for imm 0 if we have the register operation.

It is possible that a X0 is an operand of a select that feeds the CSR
write pseudo instruction. The select will be expanded to control flow
and phis which later be turned into copies. This can allow register
coalescing to coalesce the X0 into a CSR write pseudo instruction. By
using GPRNoX0 the coalescing should be prevented.

We don't yet have any uses of these pseudo instructions that I know of
so I can't test this. I'm extrapolating from a similar issue we found
on vsetvli for vector instructions. That's a much larger bug to fix.

Diff Detail

Event Timeline

craig.topper created this revision.Sep 1 2021, 11:00 AM
craig.topper requested review of this revision.Sep 1 2021, 11:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2021, 11:00 AM
Herald added a subscriber: MaskRay. · View Herald Transcript
jrtc27 requested changes to this revision.EditedSep 1 2021, 11:10 AM

It's only CSRRS/CSRRC (and their immediate counterparts) that special-case a zero source (whereas it's only CSRRW (and its immediate counterpart) that special-cases a zero destination). So the existing code is fine AFAICT.

This revision now requires changes to proceed.Sep 1 2021, 11:10 AM
craig.topper abandoned this revision.Sep 1 2021, 11:34 AM

It's only CSRRS/CSRRC (and their immediate counterparts) that special-case a zero source (whereas it's only CSRRW (and its immediate counterpart) that special-cases a zero destination). So the existing code is fine AFAICT.

Oops. You're right, I misread the table. Thanks. I'll go back to trying to fix vsetvli.