This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add Zce extension.
ClosedPublic

Authored by craig.topper on Jun 26 2023, 12:49 AM.

Details

Summary

According to the spec, Zce is an alias for Zca, Zcb, Zcmp, and Zcmt.
If F is enabled on RV32 it also includes Zcf.

This patch adds the Zce and the implication rule which unfortunately
requires custom handling for adding Zcf.

I've also made all the Zc* extensions imply Zca.

I've also added an error for Zcf without RV32.

Diff Detail

Event Timeline

craig.topper created this revision.Jun 26 2023, 12:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 26 2023, 12:49 AM
craig.topper requested review of this revision.Jun 26 2023, 12:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 26 2023, 12:49 AM
asb added a comment.Jun 26 2023, 10:38 AM

Looking at the PDF, the behaviour I feel is slightly unclear is for RV64 with F and with Zce. You've chosing in this patch to allow it but to just not include zcf, though by my first reading of the spec I probably would have errored on the basis that "Specifying Zce with F includes Zca, Zcb, Zcmp, Zcmt and Zcf" and Zcf on RV64 is of course illegal. I think we have some leeway in how we handle this, but do you happen to know if GCC does something similar?

Looking at the PDF, the behaviour I feel is slightly unclear is for RV64 with F and with Zce. You've chosing in this patch to allow it but to just not include zcf, though by my first reading of the spec I probably would have errored on the basis that "Specifying Zce with F includes Zca, Zcb, Zcmp, Zcmt and Zcf" and Zcf on RV64 is of course illegal. I think we have some leeway in how we handle this, but do you happen to know if GCC does something similar?

I don't know what gcc does. I tried godbolt with "compile to binary" enabled. binutils rejected all of the Zc* extensions.

@Nelson1225 can you provide any information about what binutils does or will do?

What does that mean for .option arch, +zce, +f with -march=rv32i? Should that result in Zcf being present or not? My guess is binutils's dodgy implementation (which only considers implications at the end, so .option arch, foo, bar is not just shorthand for .option arch, foo; .option arch, bar as it should be in a sane world) says yes but we say no.

What does that mean for .option arch, +zce, +f with -march=rv32i? Should that result in Zcf being present or not? My guess is binutils's dodgy implementation (which only considers implications at the end, so .option arch, foo, bar is not just shorthand for .option arch, foo; .option arch, bar as it should be in a sane world) says yes but we say no.

The easiest fix for that is probably to factor Zce directly into the tablegen predicates?

Add Zce to the Zcf instruction predicate.

I'm going to pre-commit the splitting compress-float.ll and will rebase.

Looking at the PDF, the behaviour I feel is slightly unclear is for RV64 with F and with Zce. You've chosing in this patch to allow it but to just not include zcf, though by my first reading of the spec I probably would have errored on the basis that "Specifying Zce with F includes Zca, Zcb, Zcmp, Zcmt and Zcf" and Zcf on RV64 is of course illegal. I think we have some leeway in how we handle this, but do you happen to know if GCC does something similar?

I don't know what gcc does. I tried godbolt with "compile to binary" enabled. binutils rejected all of the Zc* extensions.

@Nelson1225 can you provide any information about what binutils does or will do?

I filed https://github.com/riscv/riscv-code-size-reduction/issues/221 to get this clarified.

Ping. I think the spec has been updated now, but the pdf has not been generated.

asb accepted this revision.Jul 13 2023, 7:22 AM

This LGTM. The remaining weirdness is that zcf doesn't imply F and zcd doesn't imply D. But what is implemented here matches the current spec, and can be updated again if https://github.com/riscv/riscv-code-size-reduction/pull/224 is approved.

This revision is now accepted and ready to land.Jul 13 2023, 7:22 AM
This revision was landed with ongoing or failed builds.Jul 13 2023, 12:22 PM
This revision was automatically updated to reflect the committed changes.