From e914c11a99833c265aef1256fdd113129d4b8a0d Mon Sep 17 00:00:00 2001 From: James Greenhalgh Date: Thu, 21 Jul 2016 15:37:50 +0000 Subject: [PATCH] [Patch 1/2 ifcvt costs] New target hook: max_noce_ifcvt_seq_cost gcc/ * target.def (max_noce_ifcvt_seq_cost): New. * doc/tm.texi.in (TARGET_MAX_NOCE_IFCVT_SEQ_COST): Document it. * doc/tm.texi: Regenerate. * targhooks.h (default_max_noce_ifcvt_seq_cost): New. * targhooks.c (default_max_noce_ifcvt_seq_cost): New. * params.def (PARAM_MAX_RTL_IF_CONVERSION_PREDICTABLE_COST): New. (PARAM_MAX_RTL_IF_CONVERSION_UNPREDICTABLE_COST): Likewise. * doc/invoke.texi: Document new params. From-SVN: r238593 --- gcc/ChangeLog | 11 +++++++++++ gcc/doc/invoke.texi | 11 +++++++++++ gcc/doc/tm.texi | 20 ++++++++++++++++++++ gcc/doc/tm.texi.in | 2 ++ gcc/params.def | 14 ++++++++++++++ gcc/target.def | 24 ++++++++++++++++++++++++ gcc/targhooks.c | 22 ++++++++++++++++++++++ gcc/targhooks.h | 2 ++ 8 files changed, 106 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 39b3690852a..3aebf5c3b9c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2016-07-21 James Greenhalgh + + * target.def (max_noce_ifcvt_seq_cost): New. + * doc/tm.texi.in (TARGET_MAX_NOCE_IFCVT_SEQ_COST): Document it. + * doc/tm.texi: Regenerate. + * targhooks.h (default_max_noce_ifcvt_seq_cost): New. + * targhooks.c (default_max_noce_ifcvt_seq_cost): New. + * params.def (PARAM_MAX_RTL_IF_CONVERSION_PREDICTABLE_COST): New. + (PARAM_MAX_RTL_IF_CONVERSION_UNPREDICTABLE_COST): Likewise. + * doc/invoke.texi: Document new params. + 2016-07-21 Richard Biener PR tree-optimization/71947 diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 4435f5491ed..9e039869cc6 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -8869,6 +8869,17 @@ considered for if-conversion. The default is 10, though the compiler will also use other heuristics to decide whether if-conversion is likely to be profitable. +@item max-rtl-if-conversion-predictable-cost +@item max-rtl-if-conversion-unpredictable-cost +RTL if-conversion will try to remove conditional branches around a block +and replace them with conditionally executed instructions. These parameters +give the maximum permissible cost for the sequence that would be generated +by if-conversion depending on whether the branch is statically determined +to be predictable or not. The units for this parameter are the same as +those for the GCC internal seq_cost metric. The compiler will try to +provide a reasonable default for this parameter using the BRANCH_COST +target macro. + @item max-crossjump-edges The maximum number of incoming edges to consider for cross-jumping. The algorithm used by @option{-fcrossjumping} is @math{O(N^2)} in diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 160ced1d284..83bd9abe40c 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -6526,6 +6526,26 @@ should probably only be given to addresses with different numbers of registers on machines with lots of registers. @end deftypefn +@deftypefn {Target Hook} {unsigned int} TARGET_MAX_NOCE_IFCVT_SEQ_COST (edge @var{e}) +This hook returns a value in the same units as @code{TARGET_RTX_COSTS}, +giving the maximum acceptable cost for a sequence generated by the RTL +if-conversion pass when conditional execution is not available. +The RTL if-conversion pass attempts to convert conditional operations +that would require a branch to a series of unconditional operations and +@code{mov@var{mode}cc} insns. This hook returns the maximum cost of the +unconditional instructions and the @code{mov@var{mode}cc} insns. +RTL if-conversion is cancelled if the cost of the converted sequence +is greater than the value returned by this hook. + +@code{e} is the edge between the basic block containing the conditional +branch to the basic block which would be executed if the condition +were true. + +The default implementation of this hook uses the +@code{max-rtl-if-conversion-[un]predictable} parameters if they are set, +and uses a multiple of @code{BRANCH_COST} otherwise. +@end deftypefn + @deftypefn {Target Hook} bool TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P (void) This predicate controls the use of the eager delay slot filler to disallow speculatively executed instructions being placed in delay slots. Targets diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 6a114961e27..a72c3d8ab10 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -4762,6 +4762,8 @@ Define this macro if a non-short-circuit operation produced by @hook TARGET_ADDRESS_COST +@hook TARGET_MAX_NOCE_IFCVT_SEQ_COST + @hook TARGET_NO_SPECULATION_IN_DELAY_SLOTS_P @node Scheduling diff --git a/gcc/params.def b/gcc/params.def index b86d592d81d..166032e7fb0 100644 --- a/gcc/params.def +++ b/gcc/params.def @@ -1222,6 +1222,20 @@ DEFPARAM (PARAM_MAX_RTL_IF_CONVERSION_INSNS, "if-conversion.", 10, 0, 99) +DEFPARAM (PARAM_MAX_RTL_IF_CONVERSION_PREDICTABLE_COST, + "max-rtl-if-conversion-predictable-cost", + "Maximum permissible cost for the sequence that would be " + "generated by the RTL if-conversion pass for a branch that " + "is considered predictable.", + 20, 0, 200) + +DEFPARAM (PARAM_MAX_RTL_IF_CONVERSION_UNPREDICTABLE_COST, + "max-rtl-if-conversion-unpredictable-cost", + "Maximum permissible cost for the sequence that would be " + "generated by the RTL if-conversion pass for a branch that " + "is considered unpredictable.", + 40, 0, 200) + DEFPARAM (PARAM_HSA_GEN_DEBUG_STORES, "hsa-gen-debug-stores", "Level of hsa debug stores verbosity", diff --git a/gcc/target.def b/gcc/target.def index 4a849227de4..27f9ac247ed 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -3586,6 +3586,30 @@ registers on machines with lots of registers.", int, (rtx address, machine_mode mode, addr_space_t as, bool speed), default_address_cost) +/* Give a cost, in RTX Costs units, for an edge. Like BRANCH_COST, but with + well defined units. */ +DEFHOOK +(max_noce_ifcvt_seq_cost, + "This hook returns a value in the same units as @code{TARGET_RTX_COSTS},\n\ +giving the maximum acceptable cost for a sequence generated by the RTL\n\ +if-conversion pass when conditional execution is not available.\n\ +The RTL if-conversion pass attempts to convert conditional operations\n\ +that would require a branch to a series of unconditional operations and\n\ +@code{mov@var{mode}cc} insns. This hook returns the maximum cost of the\n\ +unconditional instructions and the @code{mov@var{mode}cc} insns.\n\ +RTL if-conversion is cancelled if the cost of the converted sequence\n\ +is greater than the value returned by this hook.\n\ +\n\ +@code{e} is the edge between the basic block containing the conditional\n\ +branch to the basic block which would be executed if the condition\n\ +were true.\n\ +\n\ +The default implementation of this hook uses the\n\ +@code{max-rtl-if-conversion-[un]predictable} parameters if they are set,\n\ +and uses a multiple of @code{BRANCH_COST} otherwise.", +unsigned int, (edge e), +default_max_noce_ifcvt_seq_cost) + /* Permit speculative instructions in delay slots during delayed-branch scheduling. */ DEFHOOK diff --git a/gcc/targhooks.c b/gcc/targhooks.c index 65055b4b443..69037c1ca0f 100644 --- a/gcc/targhooks.c +++ b/gcc/targhooks.c @@ -74,6 +74,8 @@ along with GCC; see the file COPYING3. If not see #include "intl.h" #include "opts.h" #include "gimplify.h" +#include "predict.h" +#include "params.h" bool @@ -1986,4 +1988,24 @@ default_optab_supported_p (int, machine_mode, machine_mode, optimization_type) return true; } +/* Default implementation of TARGET_MAX_NOCE_IFCVT_SEQ_COST. */ + +unsigned int +default_max_noce_ifcvt_seq_cost (edge e) +{ + bool predictable_p = predictable_edge_p (e); + + enum compiler_param param + = (predictable_p + ? PARAM_MAX_RTL_IF_CONVERSION_PREDICTABLE_COST + : PARAM_MAX_RTL_IF_CONVERSION_UNPREDICTABLE_COST); + + /* If we have a parameter set, use that, otherwise take a guess using + BRANCH_COST. */ + if (global_options_set.x_param_values[param]) + return PARAM_VALUE (param); + else + return BRANCH_COST (true, predictable_p) * COSTS_N_INSNS (3); +} + #include "gt-targhooks.h" diff --git a/gcc/targhooks.h b/gcc/targhooks.h index bcec7a3027e..2e7ca72a871 100644 --- a/gcc/targhooks.h +++ b/gcc/targhooks.h @@ -256,4 +256,6 @@ extern void default_setup_incoming_vararg_bounds (cumulative_args_t ca ATTRIBUTE extern bool default_optab_supported_p (int, machine_mode, machine_mode, optimization_type); +extern unsigned int default_max_noce_ifcvt_seq_cost (edge); + #endif /* GCC_TARGHOOKS_H */ -- 2.30.2