From 999ad881ea60fcfce06706091a5f1ce9de6799a6 Mon Sep 17 00:00:00 2001 From: Alexander Monakov Date: Tue, 26 Dec 2017 17:34:33 +0300 Subject: [PATCH] sel-sched: fix zero-usefulness case in sel_rank_for_schedule (PR 83513) PR rtl-optimization/83513 * sel-sched.c (sel_rank_for_schedule): Order by non-zero usefulness before priority comparison. From-SVN: r256001 --- gcc/ChangeLog | 6 ++++++ gcc/sel-sched.c | 23 ++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 22c8ea3f881..2df0a20bbc4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-12-26 Alexander Monakov + + PR rtl-optimization/83513 + * sel-sched.c (sel_rank_for_schedule): Order by non-zero usefulness + before priority comparison. + 2017-12-25 Jakub Jelinek PR target/83488 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 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); + /* Prefer an expr with non-zero usefulness. */ + int u1 = EXPR_USEFULNESS (tmp), u2 = EXPR_USEFULNESS (tmp2); - val = p2 * EXPR_USEFULNESS (tmp2) - p1 * EXPR_USEFULNESS (tmp); + if (u1 == 0) + { + if (u2 == 0) + u1 = u2 = 1; + else + return 1; } - else - val = EXPR_PRIORITY (tmp2) - EXPR_PRIORITY (tmp) - + EXPR_PRIORITY_ADJ (tmp2) - EXPR_PRIORITY_ADJ (tmp); + else if (u2 == 0) + return -1; + + /* Prefer an expr with greater priority. */ + val = (u2 * (EXPR_PRIORITY (tmp2) + EXPR_PRIORITY_ADJ (tmp2)) + - u1 * (EXPR_PRIORITY (tmp) + EXPR_PRIORITY_ADJ (tmp))); if (val) return val; -- 2.30.2