This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] sel-sched: fix zero-usefulness case in sel_rank_for_schedule (PR 83513)
- From: Alexander Monakov <amonakov at ispras dot ru>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Andrey Belevantsev <abel at ispras dot ru>
- Date: Mon, 25 Dec 2017 19:47:18 +0300 (MSK)
- Subject: [PATCH] sel-sched: fix zero-usefulness case in sel_rank_for_schedule (PR 83513)
- Authentication-results: sourceware.org; auth=none
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;