[PATCH] RISC-V: Fix a typo in zce to zcf implication
zce must imply zcf but this rule was corrupted after refactoring in this commit: 9e12010b5e724277ea44c300630802f464407d8d gcc/ChangeLog: * common/config/riscv/riscv-common.cc: fix zce to zcf implication. Signed-off-by: Yuriy Kolerov --- gcc/common/config/riscv/riscv-common.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index 5038f0eb959..b34409adf39 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -213,7 +213,7 @@ static const riscv_implied_info_t riscv_implied_info[] = {"zcmp", "zca"}, {"zcmt", "zca"}, {"zcmt", "zicsr"}, - {"zcf", "f", + {"zce", "zcf", [] (const riscv_subset_list *subset_list) -> bool { return subset_list->xlen () == 32 && subset_list->lookup ("f"); -- 2.34.1
Re: [PATCH] RISC-V: Fix a typo in zce to zcf implication
Hi Robin, Sure, I will do everything you listed shortly, and I will apply a second version of the patch. Regards, Yuriy Kolerov Regards, Yuriy Kolerov From: Robin Dapp Sent: Monday, January 20, 2025 4:02:36 PM To: Yuriy Kolerov ; gcc-patches@gcc.gnu.org Cc: Artemiy Volkov ; Robin Dapp Subject: Re: [PATCH] RISC-V: Fix a typo in zce to zcf implication > zce must imply zcf but this rule was corrupted after > refactoring in this commit: > > 9e12010b5e724277ea44c300630802f464407d8d > > gcc/ChangeLog: > >* common/config/riscv/riscv-common.cc: fix zce to zcf >implication. Thanks, looks reasonable but please add a test case as it's clearly a regression. Ideally open a bug as well and reference the PR. Also, please specify how and what you tested. -- Regards Robin
[PATCH v2] RISC-V: Fix a typo in zce to zcf implication
zce must imply zcf but this rule was corrupted after refactoring in 9e12010b5e724277ea. This may be observed ater generating an .s file from any source code file with -mriscv-attribute -march=rv32if_zce -mabi=ilp32 -S options. A full march will be presented in arch attribute: rv32i2p1_f2p2_zicsr2p0_zca1p0_zcb1p0_zce1p0_zcmp1p0_zcmt1p0 As you see, zcf is not presented here though f_zce pair is passed in -march. According to The RISC-V Instruction Set Manual: Specifying Zce on RV32 with F includes Zca, Zcb, Zcmp, Zcmt and Zcf. PR target/118906 gcc/ChangeLog: * common/config/riscv/riscv-common.cc: fix zce to zcf implication. gcc/testsuite/ChangeLog: * gcc.target/riscv/attribute-zce-1.c: New test. * gcc.target/riscv/attribute-zce-2.c: New test. * gcc.target/riscv/attribute-zce-3.c: New test. * gcc.target/riscv/attribute-zce-4.c: New test. Signed-off-by: Yuriy Kolerov --- gcc/common/config/riscv/riscv-common.cc | 2 +- gcc/testsuite/gcc.target/riscv/attribute-zce-1.c | 6 ++ gcc/testsuite/gcc.target/riscv/attribute-zce-2.c | 6 ++ gcc/testsuite/gcc.target/riscv/attribute-zce-3.c | 6 ++ gcc/testsuite/gcc.target/riscv/attribute-zce-4.c | 6 ++ 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-zce-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-zce-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-zce-3.c create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-zce-4.c diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index 5038f0eb959..b34409adf39 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -213,7 +213,7 @@ static const riscv_implied_info_t riscv_implied_info[] = {"zcmp", "zca"}, {"zcmt", "zca"}, {"zcmt", "zicsr"}, - {"zcf", "f", + {"zce", "zcf", [] (const riscv_subset_list *subset_list) -> bool { return subset_list->xlen () == 32 && subset_list->lookup ("f"); diff --git a/gcc/testsuite/gcc.target/riscv/attribute-zce-1.c b/gcc/testsuite/gcc.target/riscv/attribute-zce-1.c new file mode 100644 index 000..e477414d4d5 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/attribute-zce-1.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +/* { dg-options "-mriscv-attribute -march=rv32i_zce -mabi=ilp32" } */ + +void foo(){} + +/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p1_zicsr2p0_zca1p0_zcb1p0_zce1p0_zcmp1p0_zcmt1p0\"" } } */ diff --git a/gcc/testsuite/gcc.target/riscv/attribute-zce-2.c b/gcc/testsuite/gcc.target/riscv/attribute-zce-2.c new file mode 100644 index 000..7008eb5ea1f --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/attribute-zce-2.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +/* { dg-options "-mriscv-attribute -march=rv32if_zce -mabi=ilp32" } */ + +void foo(){} + +/* { dg-final { scan-assembler ".attribute arch, \"rv32i2p1_f2p2_zicsr2p0_zca1p0_zcb1p0_zce1p0_zcf1p0_zcmp1p0_zcmt1p0\"" } } */ diff --git a/gcc/testsuite/gcc.target/riscv/attribute-zce-3.c b/gcc/testsuite/gcc.target/riscv/attribute-zce-3.c new file mode 100644 index 000..89ebaaf4063 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/attribute-zce-3.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +/* { dg-options "-mriscv-attribute -march=rv64i_zce -mabi=lp64" } */ + +void foo(){} + +/* { dg-final { scan-assembler ".attribute arch, \"rv64i2p1_zicsr2p0_zca1p0_zcb1p0_zce1p0_zcmp1p0_zcmt1p0\"" } } */ diff --git a/gcc/testsuite/gcc.target/riscv/attribute-zce-4.c b/gcc/testsuite/gcc.target/riscv/attribute-zce-4.c new file mode 100644 index 000..cacbcaac35f --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/attribute-zce-4.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +/* { dg-options "-mriscv-attribute -march=rv64if_zce -mabi=lp64" } */ + +void foo(){} + +/* { dg-final { scan-assembler ".attribute arch, \"rv64i2p1_f2p2_zicsr2p0_zca1p0_zcb1p0_zce1p0_zcmp1p0_zcmt1p0\"" } } */ -- 2.34.1
RE: [PATCH v2] RISC-V: Fix a typo in zce to zcf implication
Hi Jeff, That check is performed in a lambda function: {"zce", "zcf", [] (const riscv_subset_list *subset_list) -> bool { return subset_list->xlen () == 32 && subset_list->lookup ("f"); }}, The typo was in a rule itself: {"zcf", "f", ... So, with this fix zcf in implied by zce if this condition is passed: subset_list->xlen () == 32 && subset_list->lookup ("f") Before 9e12010b5e724277ea this rule was implemented in this code: if (subset_list->lookup ("zce") != NULL && subset_list->m_xlen == 32 && subset_list->lookup ("f") != NULL && subset_list->lookup ("zcf") == NULL) subset_list->add ("zcf", false); But it was accidentally refactored in a wrong way. Regards, Yuriy Kolerov -Original Message- From: Jeff Law Sent: Tuesday, February 25, 2025 4:46 PM To: Yuriy Kolerov ; gcc-patches@gcc.gnu.org Cc: Artemiy Volkov Subject: Re: [PATCH v2] RISC-V: Fix a typo in zce to zcf implication On 2/24/25 3:22 AM, Yuriy Kolerov wrote: > zce must imply zcf but this rule was corrupted after refactoring in > 9e12010b5e724277ea. This may be observed ater generating an .s file > from any source code file with -mriscv-attribute -march=rv32if_zce > -mabi=ilp32 -S options. A full march will be presented in arch > attribute: > > rv32i2p1_f2p2_zicsr2p0_zca1p0_zcb1p0_zce1p0_zcmp1p0_zcmt1p0 > > As you see, zcf is not presented here though f_zce pair is passed in > -march. According to The RISC-V Instruction Set Manual: > > Specifying Zce on RV32 with F includes Zca, Zcb, Zcmp, > Zcmt and Zcf. > > PR target/118906 > > gcc/ChangeLog: > > * common/config/riscv/riscv-common.cc: fix zce to zcf > implication. > > gcc/testsuite/ChangeLog: > > * gcc.target/riscv/attribute-zce-1.c: New test. > * gcc.target/riscv/attribute-zce-2.c: New test. > * gcc.target/riscv/attribute-zce-3.c: New test. > * gcc.target/riscv/attribute-zce-4.c: New test. I'm not 100% sure this is implementation is correct. My understanding is that zce implies zcf iff rv32 and f are also enabled. So don't you need to verify that rv32 and f are enabled? Or is that done elsewhere? Though it looks like the other cases zce -> {zca, zcb, zcmp, zcmp} don't have that check. It feels like I'm missing something in how all this works. Kito, you know this stuff better than I, thoughts? Jeff
[PATCH] RISC-V: Imply C from Zca whenever possible [PR119122]
GCC must imply C extension from Zca extension when it's possible. It's necessary for achieving compatibility between different march strings which in fact may be the same. E.g., if rv32ic multilib configuration is presented in GCC, then GCC will not choose this configuration for linking if -march=rv32i_zca is passed. Here is a more practical example. From RISC-V Instruction Set Manual: Therefore common ISA strings can be updated as follows to include the relevant Zc extensions, for example: - RV32IMC becomes RV32IM_Zce - RV32IMCF becomes RV32IMF_Zce With current implication rules this will not work well if rv32imc configuration is presented and a user passes -march=rv32im_zce. This is how we can check this with a simple empty test.c source file: $ riscv64-unknown-elf-gcc -march=rv32ic -mabi=ilp32 -mriscv-attribute -S test.c $ grep "attribute arch" test.s .attribute arch, "rv32i2p1_c2p0_zca1p0" $ riscv64-unknown-elf-gcc -march=rv32i_zce -mabi=ilp32 -mriscv-attribute -S test.c $ grep "attribute arch" test.s .attribute arch, "rv32i2p1_zicsr2p0_zca1p0_zcb1p0_zce1p0_zcmp1p0_zcmt1p0" According to current GCC these march strings are incompatible: the first one contains c2p0 and the second on doesn't. To introduce such implication rule we need to carefully cover all possible combinations with these extensions: zca, zcf, zcd, F and D. According to the same manual: As C defines the same instructions as Zca, Zcf and Zcd, the rule is that: - C always implies Zca - C+F implies Zcf (RV32 only) - C+D implies Zcd Here is a full list of cases: 1. rv32i_zca implies C. 2. rv32if_zca_zcf implies C. 3. rv32ifd_zca_zcf_zcd implies C. 4. rv64i_zca implies C. 5. rv64ifd_zca_zcd implies C. PR target/119122 gcc/ChangeLog: * common/config/riscv/riscv-common.cc: add a rule for Zca to C implication. gcc/testsuite/ChangeLog: * gcc.target/riscv/arch-25.c: Fix dg-error expectation. * gcc.target/riscv/attribute-c-1.c: New test. * gcc.target/riscv/attribute-c-2.c: New test. * gcc.target/riscv/attribute-c-3.c: New test. * gcc.target/riscv/attribute-c-4.c: New test. * gcc.target/riscv/attribute-c-5.c: New test. * gcc.target/riscv/attribute-c-6.c: New test. * gcc.target/riscv/attribute-c-7.c: New test. * gcc.target/riscv/attribute-c-8.c: New test. * gcc.target/riscv/attribute-zce-1.c: Update Zce tests. * gcc.target/riscv/attribute-zce-2.c: Likewise. * gcc.target/riscv/attribute-zce-3.c: Likewise * gcc.target/riscv/attribute-zce-4.c: Likewise. Signed-off-by: Yuriy Kolerov --- gcc/common/config/riscv/riscv-common.cc | 31 +++ gcc/testsuite/gcc.target/riscv/arch-25.c | 2 +- .../gcc.target/riscv/attribute-c-1.c | 6 .../gcc.target/riscv/attribute-c-2.c | 6 .../gcc.target/riscv/attribute-c-3.c | 6 .../gcc.target/riscv/attribute-c-4.c | 6 .../gcc.target/riscv/attribute-c-5.c | 6 .../gcc.target/riscv/attribute-c-6.c | 6 .../gcc.target/riscv/attribute-c-7.c | 6 .../gcc.target/riscv/attribute-c-8.c | 6 .../gcc.target/riscv/attribute-zce-1.c| 2 +- .../gcc.target/riscv/attribute-zce-2.c| 2 +- .../gcc.target/riscv/attribute-zce-3.c| 2 +- .../gcc.target/riscv/attribute-zce-4.c| 2 +- 14 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-c-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-c-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-c-3.c create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-c-4.c create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-c-5.c create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-c-6.c create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-c-7.c create mode 100644 gcc/testsuite/gcc.target/riscv/attribute-c-8.c diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index b34409adf39..15df22d5377 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -218,6 +218,37 @@ static const riscv_implied_info_t riscv_implied_info[] = { return subset_list->xlen () == 32 && subset_list->lookup ("f"); }}, + {"zca", "c", + [] (const riscv_subset_list *subset_list) -> bool + { + /* For RV32 Zca implies C for one of these combinations of + extensions: Zca, F_Zca_Zcf and FD_Zca_Zcf_Zcd. */ + if (subset_list->xlen () == 32) + { +if (subset_list->lookup ("d")) + return subset_list->lookup ("zcf") && s