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.
(TARGET_MAX_NOCE_IFCVT_SEQ_COST): Define hook.
gcc/testsuite/
* gcc.target/mips/branch-cost-1.c: Disable for -Os.
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]>
---
v4: Fix the formatting and remove the conversion_profitable_hook.
gcc/config/mips/mips.cc | 34 +++++++++++++++++++
gcc/testsuite/gcc.target/mips/branch-cost-1.c | 2 +-
2 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
index 80828ed20af..9d7c86fffca 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"
@@ -4796,6 +4797,12 @@ mips_rtx_costs (rtx x, machine_mode mode, int outer_code,
}
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,30 @@ 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);
+}
+
/* define TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY */
/* The MIPS function start is implemented in the prologue function.
@@ -23687,6 +23718,9 @@ 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_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