public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR84068: Fix sort order of SCHED_PRESSURE_MODEL
@ 2018-01-31 13:20 Wilco Dijkstra
  2018-01-31 13:33 ` Alexander Monakov
  2018-01-31 13:44 ` Richard Sandiford
  0 siblings, 2 replies; 11+ messages in thread
From: Wilco Dijkstra @ 2018-01-31 13:20 UTC (permalink / raw)
  To: GCC Patches; +Cc: nd

The comparison order for SCHED_PRESSURE_MODEL is incorrect.  If either
instruction is not in target_bb, the ordering is not well defined.  To fix
this, give all instructions in target_bb the highest priority and sort all
other instructions behind it.  This way instructions in target_bb will be
sorted using the pressure model, and instructions outside it will use
RFS_DEP_COUNT and/or RFS_TIE for their order.

Bootstrap OK on AArch64, OK for commit?

ChangeLog:
2018-01-31  Wilco Dijkstra  <wdijkstr@arm.com>

	PR rlt-optimization/84068
	* haifa-sched.c (rank_for_schedule): Fix SCHED_PRESSURE_MODEL sorting.

	PR rlt-optimization/84068
	* gcc.dg/pr84068.c: New test.
--

diff --git a/gcc/haifa-sched.c b/gcc/haifa-sched.c
index ebdec46bf04f1ba07e8b70607602a3bc9e7ec7de..2c9dd87426930ee99b2a4c0950cadea96f9553bc 100644
--- a/gcc/haifa-sched.c
+++ b/gcc/haifa-sched.c
@@ -2783,12 +2783,18 @@ 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 && 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);
+	}
+      else if (INSN_BB (tmp) == target_bb)
+	return rfs_result (RFS_PRESSURE_INDEX, -1, tmp, tmp2);
+      else 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.
diff --git a/gcc/testsuite/gcc.dg/pr84068.c b/gcc/testsuite/gcc.dg/pr84068.c
new file mode 100644
index 0000000000000000000000000000000000000000..13110d84455f20edfc50f09efe4074721bd6a7d0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr84068.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-sched-critical-path-heuristic -fno-sched-rank-heuristic --param=max-sched-extend-regions-iters=5 --param sched-pressure-algorithm=2" } */
+
+#ifdef __SIZEOF_INT128__
+typedef __int128 largeint;
+#else
+typedef long long largeint;
+#endif
+
+largeint a;
+int b;
+
+largeint
+foo (char d, short e, int f)
+{
+  b = __builtin_sub_overflow_p (b, 1, (unsigned long)0);
+  return a + f;
+}

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-02-07 17:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-31 13:20 [PATCH] PR84068: Fix sort order of SCHED_PRESSURE_MODEL Wilco Dijkstra
2018-01-31 13:33 ` Alexander Monakov
2018-02-07 17:10   ` Alexander Monakov
2018-01-31 13:44 ` Richard Sandiford
2018-01-31 14:43   ` Wilco Dijkstra
2018-01-31 15:01     ` Maxim Kuvyrkov
2018-01-31 15:07       ` Richard Sandiford
2018-02-01 16:01         ` Wilco Dijkstra
2018-02-01 17:16           ` Richard Sandiford
2018-02-02 16:40             ` Wilco Dijkstra
2018-02-07 16:43               ` Maxim Kuvyrkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).