[PATCH] sel-sched: fix zero-usefulness case in sel_rank_for_schedule (PR 83513)
Hello, we need the following follow-up fix for priority comparison in sel_rank_for_schedule as demonstrated by PR 83513. Checked on x86_64 by running a bootstrap and also checking for no regressions in make -k check-gcc RUNTESTFLAGS="--target_board=unix/-fselective-scheduling/-fschedule-insns" OK to apply? PR rtl-optimization/83513 * sel-sched.c (sel_rank_for_schedule): Order by non-zero usefulness before priority comparison. diff --git a/gcc/sel-sched.c b/gcc/sel-sched.c index c1be0136551..be3813717ba 100644 --- a/gcc/sel-sched.c +++ b/gcc/sel-sched.c @@ -3396,17 +3396,22 @@ sel_rank_for_schedule (const void *x, const void *y) else if (control_flow_insn_p (tmp2_insn) && !control_flow_insn_p (tmp_insn)) return 1; + /* Prefer an expr with non-zero usefulness. */ + int u1 = EXPR_USEFULNESS (tmp), u2 = EXPR_USEFULNESS (tmp2); + + if (u1 == 0) +{ + if (u2 == 0) +u1 = u2 = 1; + else +return 1; +} + else if (u2 == 0) +return -1; + /* Prefer an expr with greater priority. */ - if (EXPR_USEFULNESS (tmp) != 0 || EXPR_USEFULNESS (tmp2) != 0) -{ - int p2 = EXPR_PRIORITY (tmp2) + EXPR_PRIORITY_ADJ (tmp2), - p1 = EXPR_PRIORITY (tmp) + EXPR_PRIORITY_ADJ (tmp); - - val = p2 * EXPR_USEFULNESS (tmp2) - p1 * EXPR_USEFULNESS (tmp); -} - else -val = EXPR_PRIORITY (tmp2) - EXPR_PRIORITY (tmp) - + EXPR_PRIORITY_ADJ (tmp2) - EXPR_PRIORITY_ADJ (tmp); + val = (u2 * (EXPR_PRIORITY (tmp2) + EXPR_PRIORITY_ADJ (tmp2)) + - u1 * (EXPR_PRIORITY (tmp) + EXPR_PRIORITY_ADJ (tmp))); if (val) return val;
Re: [PATCH] sel-sched: fix zero-usefulness case in sel_rank_for_schedule (PR 83513)
On 25.12.2017 19:47, Alexander Monakov wrote: Hello, we need the following follow-up fix for priority comparison in sel_rank_for_schedule as demonstrated by PR 83513. Checked on x86_64 by running a bootstrap and also checking for no regressions in make -k check-gcc RUNTESTFLAGS="--target_board=unix/-fselective-scheduling/-fschedule-insns" OK to apply? Yes. Andrey PR rtl-optimization/83513 * sel-sched.c (sel_rank_for_schedule): Order by non-zero usefulness before priority comparison. diff --git a/gcc/sel-sched.c b/gcc/sel-sched.c index c1be0136551..be3813717ba 100644 --- a/gcc/sel-sched.c +++ b/gcc/sel-sched.c @@ -3396,17 +3396,22 @@ sel_rank_for_schedule (const void *x, const void *y) else if (control_flow_insn_p (tmp2_insn) && !control_flow_insn_p (tmp_insn)) return 1; + /* Prefer an expr with non-zero usefulness. */ + int u1 = EXPR_USEFULNESS (tmp), u2 = EXPR_USEFULNESS (tmp2); + + if (u1 == 0) +{ + if (u2 == 0) +u1 = u2 = 1; + else +return 1; +} + else if (u2 == 0) +return -1; + /* Prefer an expr with greater priority. */ - if (EXPR_USEFULNESS (tmp) != 0 || EXPR_USEFULNESS (tmp2) != 0) -{ - int p2 = EXPR_PRIORITY (tmp2) + EXPR_PRIORITY_ADJ (tmp2), - p1 = EXPR_PRIORITY (tmp) + EXPR_PRIORITY_ADJ (tmp); - - val = p2 * EXPR_USEFULNESS (tmp2) - p1 * EXPR_USEFULNESS (tmp); -} - else -val = EXPR_PRIORITY (tmp2) - EXPR_PRIORITY (tmp) - + EXPR_PRIORITY_ADJ (tmp2) - EXPR_PRIORITY_ADJ (tmp); + val = (u2 * (EXPR_PRIORITY (tmp2) + EXPR_PRIORITY_ADJ (tmp2)) + - u1 * (EXPR_PRIORITY (tmp) + EXPR_PRIORITY_ADJ (tmp))); if (val) return val;