public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PR91598] Improve autoprefetcher heuristic in haifa-sched.c
@ 2019-08-29 16:43 Maxim Kuvyrkov
  2019-08-29 17:34 ` Richard Biener
  0 siblings, 1 reply; 9+ messages in thread
From: Maxim Kuvyrkov @ 2019-08-29 16:43 UTC (permalink / raw)
  To: GCC Patches; +Cc: Alexander Monakov, Wilco Dijkstra

[-- Attachment #1: Type: text/plain, Size: 1860 bytes --]

Hi,

This patch tweaks autoprefetcher heuristic in scheduler to better group memory loads and stores together.

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

There are two separate changes, both related to instruction scheduler, that cause the regression.  The first change in r253235 is responsible for 70% of the regression.
===
    haifa-sched: fix autopref_rank_for_schedule qsort comparator
    
            * haifa-sched.c (autopref_rank_for_schedule): Order 'irrelevant' insns
            first, always call autopref_rank_data otherwise.
    
    
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253235 138bc75d-0d04-0410-961f-82ee72b054a4
===

After this change instead of
r1 = [rb + 0]
r2 = [rb + 8]
r3 = [rb + 16]
r4 = <math with r1>
r5 = <math with r2>
r6 = <math with r3>

we get
r1 = [rb + 0]
<math with r1>
r2 = [rb + 8]
<math with r2>
r3 = [rb + 16]
<math with r3>

which, apparently, cortex-a53 autoprefetcher doesn't recognize.  This schedule happens because r2= load gets lower priority than the "irrelevant" <math with r1> due to the above patch.

If we think about it, the fact that "r1 = [rb + 0]" can be scheduled means that true dependencies of all similar base+offset loads are resolved.  Therefore, for autoprefetcher-friendly schedule we should prioritize memory reads before "irrelevant" instructions.

On the other hand, following similar logic, we want to delay memory stores as much as possible to start scheduling them only after all potential producers are scheduled.  I.e., for autoprefetcher-friendly schedule we should prioritize "irrelevant" instructions before memory writes.

Obvious patch to implement the above is attached.  It brings 70% of regressed performance on this testcase back.

OK to commit?

Regards,

--
Maxim Kuvyrkov
www.linaro.org



[-- Attachment #2: 0001-Improve-autoprefetcher-heuristic-partly-fix-regressi.patch --]
[-- Type: application/octet-stream, Size: 1381 bytes --]

From f6b4647a72bc798f9b1be7bd487417229d5773a4 Mon Sep 17 00:00:00 2001
From: Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org>
Date: Thu, 29 Aug 2019 15:21:36 +0000
Subject: [PATCH 1/3] Improve autoprefetcher heuristic (partly fix regression
 in PR91598)

	PR rtl-optimization/91598
	* haifa-sched.c (autopref_rank_for_schedule): Prioritize "irrelevant"
	insns after memory reads and before memory writes.

Change-Id: Ie9dd3664c652760ca605fcb3fe53190429870ded
---
 gcc/haifa-sched.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/gcc/haifa-sched.c b/gcc/haifa-sched.c
index 5025aae421d6..1bb968776f40 100644
--- a/gcc/haifa-sched.c
+++ b/gcc/haifa-sched.c
@@ -5675,9 +5675,16 @@ autopref_rank_for_schedule (const rtx_insn *insn1, const rtx_insn *insn2)
       int irrel2 = data2->status == AUTOPREF_MULTIPASS_DATA_IRRELEVANT;
 
       if (!irrel1 && !irrel2)
+	/* Sort memory references from lowest offset to the largest.  */
 	r = data1->offset - data2->offset;
-      else
+      else if (write)
+	/* Schedule "irrelevant" insns before memory stores to resolve
+	   as many producer dependencies of stores as possible.  */
 	r = irrel2 - irrel1;
+      else
+	/* Schedule "irrelevant" insns after memory reads to avoid breaking
+	   memory read sequences.  */
+	r = irrel1 - irrel2;
     }
 
   return r;
-- 
2.17.1


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

end of thread, other threads:[~2021-08-17  9:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-29 16:43 [PR91598] Improve autoprefetcher heuristic in haifa-sched.c Maxim Kuvyrkov
2019-08-29 17:34 ` Richard Biener
2019-08-29 17:36   ` Maxim Kuvyrkov
2019-08-29 18:18     ` Alexander Monakov
2019-08-29 20:41       ` Wilco Dijkstra
2019-08-30  7:42       ` Richard Biener
     [not found]     ` <VI1PR0801MB2127C0534510021E6A4BBE0583A20@VI1PR0801MB2127.eurprd08.prod.outlook.com>
2019-08-29 18:18       ` Wilco Dijkstra
2019-09-03 16:55       ` Wilco Dijkstra
2021-08-17  9: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).