This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch: Flags to enable/disable scheduling heuristics


Shobaki, Ghassan wrote:
This patch introduces flags to enable/disable each of the seven heuristics used to reorder instruction in the scheduler. By default, all flags are enabled and the current GCC behavior remains unchanged. Disabling one or more heuristics can be useful for both performance tuning and debugging.

On some platforms some heuristics may degrade the performance of some applications. So, it will be good to have the option of disabling them for better performance. I have seen a case where disabling one heuristic improves the performance of an application by 4%. Also, when a heuristic does not help improve performance, it will be good to have the option to disable it to avoid unnecessary reordering of instructions. It is generally believed that the original program order should be maintained as much as possible. For example, on the AMD platform, the dependent-count heuristic (last heuristic) does not improve performance but causes an undesirable reordering of instructions. So, in this case it helps to have the option to disable it whenever it causes trouble.

I think having the options is a good idea. It could be also very useful for milepost project.
The patch bootstrapped successfully on an AMD Barcelona machine.

Is this patch OK for trunk check in?

The patch is ok with the following minor changes (see below). You could also describe the options in more details (what the heuristics mean) because invoke.texi document is mostly for compiler users not for GCC developers. But you can do it as a separate patch if you want.

Thanks for the patch.
Changelog Entry:

2009-07-08 Ghassan Shobaki <ghassan.shobaki@amd.com>

* haifa-sched.c (rank_for_schedule): Introduced flags to enable/disable individual scheduling heuristics.
* common.opt Introduced flags to enable/disable
Absent ':' after common.opt.
individual heuristics in the scheduler
Missed period.

* doc/invoke.texi Introduced flags to enable/disable
Ditto after doc/invoke.texi
individual heuristics in the scheduler


Missed period.
Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi (revision 149312)
+++ doc/invoke.texi (working copy)
@@ -364,6 +364,10 @@ Objective-C and Objective-C++ Dialects}.
-frounding-math -fsched2-use-superblocks @gol
-fsched2-use-traces -fsched-spec-load -fsched-spec-load-dangerous @gol
-fsched-stalled-insns-dep[=@var{n}] -fsched-stalled-insns[=@var{n}] @gol
+-fsched-group-heuristic -fsched-critical-path-heuristic @gol
+-fsched-spec-insn-heuristic -fsched-reg-pressure-heuristic @gol
+-fsched-rank-heuristic -fsched-last-insn-heuristic @gol
+-fsched-dep-count-heuristic @gol
-fschedule-insns -fschedule-insns2 -fsection-anchors @gol
-fselective-scheduling -fselective-scheduling2 @gol
-fsel-sched-pipelining -fsel-sched-pipelining-outer-loops @gol
@@ -6222,6 +6226,49 @@ results from the algorithm.
This only makes sense when scheduling after register allocation, i.e.@: with
@option{-fschedule-insns2} or at @option{-O2} or higher.
+@item -fsched-group-heuristic
+@opindex fsched-group-heuristic
+Enable the group heuristic in the scheduler. This is enabled by default
+when scheduling is enabled, i.e.@: with @option{-fschedule-insns} +or @option{-fschedule-insns2} or at @option{-O2} or higher.
+
+@item -fsched-critical-path-heuristic
+@opindex fsched-critical-path-heuristic
+Enable the critical-path heuristic in the scheduler. This is enabled +by default when scheduling is enabled, i.e.@: with @option{-fschedule-insns} +or @option{-fschedule-insns2} or at @option{-O2} or higher.
+
+@item -fsched-spec-insn-heuristic
+@opindex fsched-spec-insn-heuristic
+Enable the speculative instruction heuristic in the scheduler. This is +enabled by default when scheduling is enabled, i.e.@: with +@option{-fschedule-insns} or @option{-fschedule-insns2} or +at @option{-O2} or higher.
+
+@item -fsched-reg-pressure-heuristic
+@opindex fsched-reg-pressure-heuristic
+Enable the register pressure heuristic in the scheduler. This only makes +sense when scheduling before register allocation, i.e.@: +with @option{-fschedule-insns} or at @option{-O2} or higher.
+
+@item -fsched-rank-heuristic
+@opindex fsched-rank-heuristic
+Enable the rank heuristic in the scheduler. This is enabled by default +when scheduling is enabled, i.e.@: with @option{-fschedule-insns} +or @option{-fschedule-insns2} or at @option{-O2} or higher.
+
+@item -fsched-last-insn-heuristic
+@opindex fsched-last-insn-heuristic
+Enable the last-instruction heuristic in the scheduler. This is enabled +by default when scheduling is enabled, i.e.@: with @option{-fschedule-insns} +or @option{-fschedule-insns2} or at @option{-O2} or higher.
+
+@item -fsched-dep-count-heuristic
+@opindex fsched-dep-count-heuristic
+Enable the dependent-count heuristic in the scheduler. This is enabled +by default when scheduling is enabled, i.e.@: with @option{-fschedule-insns} +or @option{-fschedule-insns2} or at @option{-O2} or higher.
+
@item -fsched2-use-traces
@opindex fsched2-use-traces
Use @option{-fsched2-use-superblocks} algorithm when scheduling after register
Index: haifa-sched.c
===================================================================
--- haifa-sched.c (revision 149312)
+++ haifa-sched.c (working copy)
@@ -890,8 +890,9 @@ rank_for_schedule (const void *x, const int val, priority_val, weight_val, info_val;
/* The insn in a schedule group should be issued the first. */
- if (SCHED_GROUP_P (tmp) != SCHED_GROUP_P (tmp2))
- return SCHED_GROUP_P (tmp2) ? 1 : -1;
+ if (flag_sched_group_heuristic)
+ if (SCHED_GROUP_P (tmp) != SCHED_GROUP_P (tmp2))
I think you should use one if-stmt.
+ return SCHED_GROUP_P (tmp2) ? 1 : -1;
/* Make sure that priority of TMP and TMP2 are initialized. */
gcc_assert (INSN_PRIORITY_KNOWN (tmp) && INSN_PRIORITY_KNOWN (tmp2));
@@ -899,11 +900,12 @@ rank_for_schedule (const void *x, const /* Prefer insn with higher priority. */
priority_val = INSN_PRIORITY (tmp2) - INSN_PRIORITY (tmp);
- if (priority_val)
- return priority_val;
+ if (flag_sched_critical_path_heuristic)
+ if (priority_val)
+ return priority_val;
Ditto.
/* Prefer speculative insn with greater dependencies weakness. */
- if (spec_info)
+ if (flag_sched_spec_insn_heuristic && spec_info)
{
ds_t ds1, ds2;
dw_t dw1, dw2;
@@ -927,16 +929,17 @@ rank_for_schedule (const void *x, const }
/* Prefer an insn with smaller contribution to registers-pressure. */
- if (!reload_completed &&
+ if (flag_sched_reg_pressure_heuristic && !reload_completed &&
(weight_val = INSN_REG_WEIGHT (tmp) - INSN_REG_WEIGHT (tmp2)))
return weight_val;
info_val = (*current_sched_info->rank) (tmp, tmp2);
- if (info_val)
- return info_val;
+ if(flag_sched_rank_heuristic)
+ if (info_val)
Ditto.
+ return info_val;
/* Compare insns based on their relation to the last-scheduled-insn. */
- if (INSN_P (last_scheduled_insn))
+ if (flag_sched_last_insn_heuristic && INSN_P (last_scheduled_insn))
{
dep_t dep1;
dep_t dep2;
@@ -977,7 +980,7 @@ rank_for_schedule (const void *x, const val = (sd_lists_size (tmp2, SD_LIST_FORW)
- sd_lists_size (tmp, SD_LIST_FORW));
- if (val != 0)
+ if (flag_sched_dep_count_heuristic && val != 0)
return val;
/* If insns are equally good, sort by INSN_LUID (original insn order),
Index: common.opt
===================================================================
--- common.opt (revision 149312)
+++ common.opt (working copy)
@@ -1056,6 +1056,34 @@ fsched-stalled-insns-dep=
Common RejectNegative Joined UInteger
-fsched-stalled-insns-dep=<number> Set dependence distance checking in premature scheduling of queued insns
+fsched-group-heuristic
+Common Report Var(flag_sched_group_heuristic) Init(1) Optimization
+Enable the group heuristic in the scheduler
+
+fsched-critical-path-heuristic
+Common Report Var(flag_sched_critical_path_heuristic) Init(1) Optimization
+Enable the critical path heuristic in the scheduler
+
+fsched-spec-insn-heuristic
+Common Report Var(flag_sched_spec_insn_heuristic) Init(1) Optimization
+Enable the speculative instruction heuristic in the scheduler
+
+fsched-reg-pressure-heuristic
+Common Report Var(flag_sched_reg_pressure_heuristic) Init(1) Optimization
+Enable the register pressure heuristic in the scheduler
+
+fsched-rank-heuristic
+Common Report Var(flag_sched_rank_heuristic) Init(1) Optimization
+Enable the rank heuristic in the scheduler
+
+fsched-last-insn-heuristic
+Common Report Var(flag_sched_last_insn_heuristic) Init(1) Optimization
+Enable the last instruction heuristic in the scheduler
+
+fsched-dep-count-heuristic
+Common Report Var(flag_sched_dep_count_heuristic) Init(1) Optimization
+Enable the dependent count heuristic in the scheduler
+
fsection-anchors
Common Report Var(flag_section_anchors) Optimization
Access data in the same section from shared anchor points


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]