https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83459

Alexander Monakov <amonakov at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |82407

--- Comment #2 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
I agree with the analysis. Insns where INSN_BB (i) != target_bb correspond to
(likely speculative) insns outside of current basic block, so for
SCHED_PRESSURE_MODEL we definitely want to sort them _after_ insns from
target_bb. When both insns are outside of current bb we can defer to next
tiebreakers.

The following (completely untested) patch implements this change. I can run it
through a bootstrap/regtest cycle if it looks reasonable:

diff --git a/gcc/haifa-sched.c b/gcc/haifa-sched.c
index 549e8961411..f169d57a634 100644
--- a/gcc/haifa-sched.c
+++ b/gcc/haifa-sched.c
@@ -2783,12 +2783,20 @@ rank_for_schedule (const void *x, const void *y)
     }

   /* Prefer instructions that occur earlier in the model schedule.  */
-  if (sched_pressure == SCHED_PRESSURE_MODEL
-      && INSN_BB (tmp) == target_bb && INSN_BB (tmp2) == target_bb)
+  if (sched_pressure == SCHED_PRESSURE_MODEL)
     {
-      diff = model_index (tmp) - model_index (tmp2);
-      gcc_assert (diff != 0);
-      return rfs_result (RFS_PRESSURE_INDEX, diff, tmp, tmp2);
+      if (INSN_BB (tmp) == target_bb)
+       {
+         if (INSN_BB (tmp2) == target_bb)
+           {
+             diff = model_index (tmp) - model_index (tmp2);
+             gcc_assert (diff != 0);
+             return rfs_result (RFS_PRESSURE_INDEX, diff, tmp, tmp2);
+           }
+         return rfs_result (RFS_PRESSURE_INDEX, -1, tmp, tmp2);
+       }
+      if (INSN_BB (tmp2) == target_bb)
+       return rfs_result (RFS_PRESSURE_INDEX, 1, tmp, tmp2);
     }

   /* Prefer the insn which has more later insns that depend on it.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82407
[Bug 82407] [meta-bug] qsort_chk fallout tracking

Reply via email to