It tunes ifcvt parameters so that we get if-conversion in more cases.
gcc/
* config/mips/mips.cc (mips_rtx_costs): Reduce cost of
if_then_else pattern.
(mips_max_noce_ifcvt_seq_cost): New function. Decrease
maximum permissible cost for the unconditional sequence which
should be generated during if-conversion (for all non-r6
targets). This disables if-conversion for non-r6 targets in
branch-cost-1.c test.
(mips_noce_conversion_profitable_p): New function.
(TARGET_MAX_NOCE_IFCVT_SEQ_COST): Define hook.
(TARGET_NOCE_CONVERSION_PROFITABLE_P): Define hook.
gcc/testsuite/
* gcc.target/mips/branch-cost-1.c: Disable for -Os.
Cherry-picked 1d1ac2a7bdbb6a1ab1a90bfcd9fa6e8a96dcb316
and 8f596d9c4336e8f6e0a01fa22634989eda7d51da
from https://github.com/MIPS/gcc
Signed-off-by: Dragan Mladjenovic <[email protected]>
Signed-off-by: Mihailo Stojanovic <[email protected]>
Signed-off-by: Faraz Shahbazker <[email protected]>
Signed-off-by: Aleksandar Rakic <[email protected]>
Signed-off-by: Radosav Krunic <[email protected]>
---
Hi Jie,
Thank you for your review. The mips_noce_conversion_profitable_p was
refactored as suggested here
https://gcc.gnu.org/pipermail/gcc-patches/2026-June/720617.html.
Also, it was tested on ifcvt-related test cases 'mips-ps-type-2.c
movcc-3.c mips16e2-cmov.c branch-cost-1.c'(suggested commits) and
no regressions were found.
Best regards,
Radosav
gcc/config/mips/mips.cc | 56 +++++++++++++++++++
gcc/testsuite/gcc.target/mips/branch-cost-1.c | 2 +-
2 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
index 277ec419826..81a41b8ee3a 100644
--- a/gcc/config/mips/mips.cc
+++ b/gcc/config/mips/mips.cc
@@ -67,6 +67,7 @@ along with GCC; see the file COPYING3. If not see
#include "rtl-iter.h"
#include "flags.h"
#include "opts.h"
+#include "ifcvt.h"
/* This file should be included last. */
#include "target-def.h"
@@ -4795,6 +4796,12 @@ mips_rtx_costs (rtx x, machine_mode mode, int outer_code,
break;
}
return false;
+
+ case IF_THEN_ELSE:
+ if (reg_or_0_operand (XEXP (x, 1), VOIDmode)
+ || reg_or_0_operand (XEXP (x, 2), VOIDmode))
+ *total = 0;
+ return false;
default:
return false;
@@ -23359,6 +23366,49 @@ mips_bit_clear_p (enum machine_mode mode, unsigned
HOST_WIDE_INT m)
return false;
}
+
+/* Implement TARGET_MAX_NOCE_IFCVT_SEQ_COST. */
+
+static unsigned int
+mips_max_noce_ifcvt_seq_cost (edge e)
+{
+ bool predictable_p = predictable_edge_p (e);
+
+ /* If we have a parameter set, use that, otherwise take a guess using
+ BRANCH_COST. */
+ if (predictable_p)
+ {
+ if (OPTION_SET_P (param_max_rtl_if_conversion_predictable_cost))
+ return param_max_rtl_if_conversion_predictable_cost;
+ }
+ else
+ {
+ if (OPTION_SET_P (param_max_rtl_if_conversion_unpredictable_cost))
+ return param_max_rtl_if_conversion_unpredictable_cost;
+ }
+
+ return BRANCH_COST (true, predictable_p)
+ * COSTS_N_INSNS (mips_isa_rev == 6 ? 4 : 3);
+}
+
+/* Return true if SEQ is a good candidate as a replacement for the
+ if-convertible sequence described in IF_INFO. */
+
+static bool
+mips_noce_conversion_profitable_p (rtx_insn *seq, struct noce_if_info *if_info)
+{
+ struct noce_if_info mips_if_info = *if_info;
+
+ for (rtx_insn *insn = seq; insn; insn = NEXT_INSN (insn))
+ {
+ /* Compensate target-specific costs by incrementing original_cost
+ (mips_if_info.original_cost) and max_seq_costif
(mips_if_info.ax_seq_costif) */
+ break;
+ }
+
+ return default_noce_conversion_profitable_p(seq, &mips_if_info);
+}
+
/* define TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY */
/* The MIPS function start is implemented in the prologue function.
@@ -23687,6 +23737,12 @@ mips_print_patchable_function_entry (FILE *file
ATTRIBUTE_UNUSED,
#undef TARGET_DOCUMENTATION_NAME
#define TARGET_DOCUMENTATION_NAME "MIPS"
+#undef TARGET_MAX_NOCE_IFCVT_SEQ_COST
+#define TARGET_MAX_NOCE_IFCVT_SEQ_COST mips_max_noce_ifcvt_seq_cost
+
+#undef TARGET_NOCE_CONVERSION_PROFITABLE_P
+#define TARGET_NOCE_CONVERSION_PROFITABLE_P mips_noce_conversion_profitable_p
+
#undef TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY
#define TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY \
mips_print_patchable_function_entry
diff --git a/gcc/testsuite/gcc.target/mips/branch-cost-1.c
b/gcc/testsuite/gcc.target/mips/branch-cost-1.c
index 7f7ebbe5fc9..006a29a7361 100644
--- a/gcc/testsuite/gcc.target/mips/branch-cost-1.c
+++ b/gcc/testsuite/gcc.target/mips/branch-cost-1.c
@@ -1,5 +1,5 @@
/* { dg-options "-mbranch-cost=1 (HAS_MOVN)" } */
-/* { dg-skip-if "code quality test" { *-*-* } { "-O0" } { "" } } */
+/* { dg-skip-if "code quality test" { *-*-* } { "-O0" "-Os" } { "" } } */
NOMIPS16 int
foo (int x, int y, int z, int k)
{
--
2.43.0