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
It make some trouble for distributions to make -mcompact-branches=always
default for R6 only.
The new added `prefer' option:
just ignored by pre-R6 target.
do the same as `always' for R6+.
---
gcc/config/mips/mips-opts.h | 3 ++-
gcc/config/mips/mips.h | 6 ++++--
gcc/config/mips/mips.opt | 3 +++
gcc/doc/invoke.texi | 6 ++++++
gcc/testsuite/gcc.target/mips/compact-branches-8.c | 10 ++++++++++
gcc/testsuite/gcc.target/mips/compact-branches-9.c | 10 ++++++++++
6 files changed, 35 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/mips/compact-branches-8.c
create mode 100644 gcc/testsuite/gcc.target/mips/compact-branches-9.c
diff --git a/gcc/config/mips/mips-opts.h b/gcc/config/mips/mips-opts.h
index 6214849f3e1..f3804b9722b 100644
--- a/gcc/config/mips/mips-opts.h
+++ b/gcc/config/mips/mips-opts.h
@@ -51,6 +51,7 @@ enum mips_r10k_cache_barrier_setting {
enum mips_cb_setting {
MIPS_CB_NEVER,
MIPS_CB_OPTIMAL,
- MIPS_CB_ALWAYS
+ MIPS_CB_ALWAYS,
+ MIPS_CB_PREFER
};
#endif
diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h
index b4a60a55d80..f8762fe6638 100644
--- a/gcc/config/mips/mips.h
+++ b/gcc/config/mips/mips.h
@@ -106,20 +106,22 @@ struct mips_cpu_info {
'never' policy or the 'optimal' policy on a core that lacks
compact branch instructions. */
#define TARGET_CB_NEVER (mips_cb == MIPS_CB_NEVER \
- || (mips_cb == MIPS_CB_OPTIMAL \
+ || ((mips_cb == MIPS_CB_OPTIMAL || mips_cb ==
MIPS_CB_PREFER) \
&& !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
compact branch instructions. */
#define TARGET_CB_MAYBE (TARGET_CB_ALWAYS \
- || (mips_cb == MIPS_CB_OPTIMAL \
+ || ((mips_cb == MIPS_CB_OPTIMAL || mips_cb ==
MIPS_CB_PREFER) \
&& 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_PREFER \
+ && ISA_HAS_COMPACT_BRANCHES) \
|| (mips_cb == MIPS_CB_OPTIMAL \
&& !ISA_HAS_DELAY_SLOTS))
diff --git a/gcc/config/mips/mips.opt b/gcc/config/mips/mips.opt
index 6af8037e9bd..f2d7550e36c 100644
--- a/gcc/config/mips/mips.opt
+++ b/gcc/config/mips/mips.opt
@@ -464,6 +464,9 @@ Enum(mips_cb_setting) String(optimal) Value(MIPS_CB_OPTIMAL)
EnumValue
Enum(mips_cb_setting) String(always) Value(MIPS_CB_ALWAYS)
+EnumValue
+Enum(mips_cb_setting) String(prefer) Value(MIPS_CB_PREFER)
+
mloongson-mmi
Target Mask(LOONGSON_MMI)
Use Loongson MultiMedia extensions Instructions (MMI) instructions.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 3751bc3ac7c..9493c508d5b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -25199,9 +25199,11 @@ and MIPS64 architectures specifically deprecate their
use.
@item -mcompact-branches=never
@itemx -mcompact-branches=optimal
@itemx -mcompact-branches=always
+@itemx -mcompact-branches=prefer
@opindex mcompact-branches=never
@opindex mcompact-branches=optimal
@opindex mcompact-branches=always
+@opindex mcompact-branches=prefer
These options control which form of branches will be generated. The
default is @option{-mcompact-branches=optimal}.
@@ -25215,6 +25217,10 @@ used instead.
This option is supported from MIPS Release 6 onwards.
+The @option{-mcompact-branches=prefer} option is same with
+@option{-mcompact-branches=always} for MIPS Release 6 onwards, and
+is same with @option{-mcompact-branches=never} for pre-R6.
+
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
slot is successfully filled. If the delay slot is not filled, a compact
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..72ffcb49cfc
--- /dev/null
+++ b/gcc/testsuite/gcc.target/mips/compact-branches-8.c
@@ -0,0 +1,10 @@
+/* { dg-options "-mno-abicalls -mcompact-branches=prefer 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..7a46b53d3e4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/mips/compact-branches-9.c
@@ -0,0 +1,10 @@
+/* { dg-options "-mno-abicalls -fno-PIC -mcompact-branches=prefer isa_rev>=6"
} */
+void bar (int);
+
+void
+foo ()
+{
+ bar (1);
+}
+
+/* { dg-final { scan-assembler "\t(bc|balc)\t" } } */
--
2.20.1