From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7863) id 55E4538582B1; Tue, 25 Oct 2022 08:44:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 55E4538582B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666687463; bh=8hPuWy+E/LhfKJgLJga3BgI8tiqvBzzku8nRGNmjsLg=; h=From:To:Subject:Date:From; b=odQqPTBOjw7wRiMNsERCVSlgMVIy7S+Ew/a1cM8bNKR+iK2UdY1HKS8DNZqU0xR2K KQElXCC/BGjX5Wbq4qQxzueh991veOJIhiJmPsjtscbGfDTDmByk0lo1GEG1n0R1EA wieTMvZOPKkGhDYhVJvbbz7jslQSNNA2GLj9GXrA= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: YunQiang Su To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3479] MIPS: Not trigger error for pre-R6 and -mcompact-branches=always X-Act-Checkin: gcc X-Git-Author: YunQiang Su X-Git-Refname: refs/heads/master X-Git-Oldrev: 7d888535f7ab80e9b08a633bfd774a923b311cde X-Git-Newrev: 4479f1dc79fc4f1b5e0fed209df35f405bc94589 Message-Id: <20221025084423.55E4538582B1@sourceware.org> Date: Tue, 25 Oct 2022 08:44:23 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4479f1dc79fc4f1b5e0fed209df35f405bc94589 commit r13-3479-g4479f1dc79fc4f1b5e0fed209df35f405bc94589 Author: YunQiang Su Date: Sat May 8 05:45:53 2021 -0400 MIPS: Not trigger error for pre-R6 and -mcompact-branches=always For MIPSr6, we may wish to use compact-branches only. Currently, we have to use `always' option, while it is mark as conflict with pre-R6. cc1: error: unsupported combination: ‘mips32r2’ -mcompact-branches=always Just ignore -mcompact-branches=always for pre-R6. This patch also defines __mips_compact_branches_never __mips_compact_branches_always __mips_compact_branches_optimal predefined macros gcc/ChangeLog: * config/mips/mips.cc (mips_option_override): not trigger error for compact-branches=always for pre-R6. * config/mips/mips.h (TARGET_RTP_PIC): not trigger error for compact-branches=always for pre-R6. (TARGET_CB_NEVER): Likewise. (TARGET_CB_ALWAYS): Likewise. (struct mips_cpu_info): define macros for compact branch policy. * doc/invoke.texi: Document "always" with pre-R6. gcc/testsuite/ChangeLog: * gcc.target/mips/compact-branches-1.c: add isa_rev>=6. * gcc.target/mips/mips.exp: don't add -mipsXXr6 option for -mcompact-branches=always. It is usable for pre-R6 now. * gcc.target/mips/compact-branches-8.c: New test. * gcc.target/mips/compact-branches-9.c: New test. Diff: --- gcc/config/mips/mips.cc | 8 +------- gcc/config/mips/mips.h | 22 ++++++++++++++-------- gcc/doc/invoke.texi | 10 ++++++---- gcc/testsuite/gcc.target/mips/compact-branches-1.c | 2 +- gcc/testsuite/gcc.target/mips/compact-branches-8.c | 10 ++++++++++ gcc/testsuite/gcc.target/mips/compact-branches-9.c | 10 ++++++++++ gcc/testsuite/gcc.target/mips/mips.exp | 4 +--- 7 files changed, 43 insertions(+), 23 deletions(-) diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc index 387376b3df8..699ea6cc128 100644 --- a/gcc/config/mips/mips.cc +++ b/gcc/config/mips/mips.cc @@ -20277,13 +20277,7 @@ mips_option_override (void) target_flags |= MASK_ODD_SPREG; } - if (!ISA_HAS_COMPACT_BRANCHES && mips_cb == MIPS_CB_ALWAYS) - { - error ("unsupported combination: %qs%s %s", - mips_arch_info->name, TARGET_MICROMIPS ? " -mmicromips" : "", - "-mcompact-branches=always"); - } - else if (!ISA_HAS_DELAY_SLOTS && mips_cb == MIPS_CB_NEVER) + if (!ISA_HAS_DELAY_SLOTS && mips_cb == MIPS_CB_NEVER) { error ("unsupported combination: %qs%s %s", mips_arch_info->name, TARGET_MICROMIPS ? " -mmicromips" : "", diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h index fe7f5b274b9..ed058b5db5f 100644 --- a/gcc/config/mips/mips.h +++ b/gcc/config/mips/mips.h @@ -120,11 +120,9 @@ struct mips_cpu_info { #define TARGET_RTP_PIC (TARGET_VXWORKS_RTP && flag_pic) /* Compact branches must not be used if the user either selects the - 'never' policy or the 'optimal' policy on a core that lacks + 'never' policy or the 'optimal' / 'always' policy on a core that lacks compact branch instructions. */ -#define TARGET_CB_NEVER (mips_cb == MIPS_CB_NEVER \ - || (mips_cb == MIPS_CB_OPTIMAL \ - && !ISA_HAS_COMPACT_BRANCHES)) +#define TARGET_CB_NEVER (mips_cb == MIPS_CB_NEVER || !ISA_HAS_COMPACT_BRANCHES) /* Compact branches may be used if the user either selects the 'always' policy or the 'optimal' policy on a core that supports @@ -134,10 +132,11 @@ struct mips_cpu_info { && ISA_HAS_COMPACT_BRANCHES)) /* Compact branches must always be generated if the user selects - the 'always' policy or the 'optimal' policy om a core that - lacks delay slot branch instructions. */ -#define TARGET_CB_ALWAYS (mips_cb == MIPS_CB_ALWAYS \ - || (mips_cb == MIPS_CB_OPTIMAL \ + the 'always' policy on a core support compact branches, + or the 'optimal' policy on a core that lacks delay slot branch instructions. */ +#define TARGET_CB_ALWAYS ((mips_cb == MIPS_CB_ALWAYS \ + && ISA_HAS_COMPACT_BRANCHES) \ + || (mips_cb == MIPS_CB_OPTIMAL \ && !ISA_HAS_DELAY_SLOTS)) /* Special handling for JRC that exists in microMIPSR3 as well as R6 @@ -677,6 +676,13 @@ struct mips_cpu_info { builtin_define ("__mips_no_lxc1_sxc1"); \ if (!ISA_HAS_UNFUSED_MADD4 && !ISA_HAS_FUSED_MADD4) \ builtin_define ("__mips_no_madd4"); \ + \ + if (TARGET_CB_NEVER) \ + builtin_define ("__mips_compact_branches_never"); \ + else if (TARGET_CB_ALWAYS) \ + builtin_define ("__mips_compact_branches_always"); \ + else \ + builtin_define ("__mips_compact_branches_optimal"); \ } \ while (0) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index d49c1374d06..64f77e8367a 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -27091,11 +27091,13 @@ The @option{-mcompact-branches=never} option ensures that compact branch instructions will never be generated. The @option{-mcompact-branches=always} option ensures that a compact -branch instruction will be generated if available. If a compact branch -instruction is not available, a delay slot form of the branch will be -used instead. +branch instruction will be generated if available for MIPS Release 6 onwards. +If a compact branch instruction is not available (or pre-R6), +a delay slot form of the branch will be used instead. -This option is supported from MIPS Release 6 onwards. +If it is used for MIPS16/microMIPS targets, it will be just ignored now. +The behaviour for MIPS16/microMIPS may change in future, +since they do have some compact branch instructions. The @option{-mcompact-branches=optimal} option will cause a delay slot branch to be used if one is available in the current ISA and the delay diff --git a/gcc/testsuite/gcc.target/mips/compact-branches-1.c b/gcc/testsuite/gcc.target/mips/compact-branches-1.c index 9c7365e2659..6b8e1978d87 100644 --- a/gcc/testsuite/gcc.target/mips/compact-branches-1.c +++ b/gcc/testsuite/gcc.target/mips/compact-branches-1.c @@ -1,4 +1,4 @@ -/* { dg-options "-mcompact-branches=always -mno-micromips" } */ +/* { dg-options "-mcompact-branches=always -mno-micromips isa_rev>=6" } */ int glob; void diff --git a/gcc/testsuite/gcc.target/mips/compact-branches-8.c b/gcc/testsuite/gcc.target/mips/compact-branches-8.c new file mode 100644 index 00000000000..1290cedf4b5 --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/compact-branches-8.c @@ -0,0 +1,10 @@ +/* { dg-options "-mno-abicalls -mcompact-branches=always isa_rev<=5" } */ +void bar (int); + +void +foo () +{ + bar (1); +} + +/* { dg-final { scan-assembler "\t(j|jal)\t" } } */ diff --git a/gcc/testsuite/gcc.target/mips/compact-branches-9.c b/gcc/testsuite/gcc.target/mips/compact-branches-9.c new file mode 100644 index 00000000000..4b23bf456d1 --- /dev/null +++ b/gcc/testsuite/gcc.target/mips/compact-branches-9.c @@ -0,0 +1,10 @@ +/* { dg-options "-mno-abicalls -fno-PIC -mcompact-branches=always isa_rev>=6" } */ +void bar (int); + +void +foo () +{ + bar (1); +} + +/* { dg-final { scan-assembler "\t(bc|balc)\t" } } */ diff --git a/gcc/testsuite/gcc.target/mips/mips.exp b/gcc/testsuite/gcc.target/mips/mips.exp index 42a0dbb6202..c89626a50fa 100644 --- a/gcc/testsuite/gcc.target/mips/mips.exp +++ b/gcc/testsuite/gcc.target/mips/mips.exp @@ -1167,10 +1167,8 @@ proc mips-dg-options { args } { # We need a revision 6 or better ISA for: # # - When the LSA instruction is required - # - When only using compact branches if { $isa_rev < 6 - && ([mips_have_test_option_p options "HAS_LSA"] - || [mips_have_test_option_p options "-mcompact-branches=always"]) } { + && ([mips_have_test_option_p options "HAS_LSA"]) } { if { $gp_size == 32 } { mips_make_test_option options "-mips32r6" } else {