public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v1] LoongArch: Set default alignment for functions jumps and loops [PR112919].
@ 2024-04-02  7:03 Lulu Cheng
  2024-04-06  9:53 ` Xi Ruoyao
  0 siblings, 1 reply; 3+ messages in thread
From: Lulu Cheng @ 2024-04-02  7:03 UTC (permalink / raw)
  To: gcc-patches; +Cc: mark, xry111, i, xuchenghua, Lulu Cheng

Xi Ruoyao set the alignment rules under LA464 in commit r14-1839,
but the macro ASM_OUTPUT_ALIGN_WITH_NOP was removed in R14-4674,
which affected the alignment rules.

So I set different aligns on LA464 and LA664 again to test the
performance of spec2006, and modify the alignment based on the test
results.

gcc/ChangeLog:

	PR target/112919
	* config/loongarch/loongarch-def.cc (la664_align): Newly defined
	function that sets alignment rules under the LA664 microarchitecture.
	* config/loongarch/loongarch-opts.cc
	(loongarch_target_option_override): If not optimizing for size, set
	the default alignment to what the target wants.
	* config/loongarch/loongarch-tune.h (struct loongarch_align): Add
	new member variables jump and loop.
---
 gcc/config/loongarch/loongarch-def.cc  | 11 ++++++++---
 gcc/config/loongarch/loongarch-opts.cc | 19 +++++++++++++------
 gcc/config/loongarch/loongarch-tune.h  | 22 +++++++++++++++-------
 3 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/gcc/config/loongarch/loongarch-def.cc b/gcc/config/loongarch/loongarch-def.cc
index e8c129ce643..63a8f108f4e 100644
--- a/gcc/config/loongarch/loongarch-def.cc
+++ b/gcc/config/loongarch/loongarch-def.cc
@@ -81,14 +81,19 @@ array_tune<loongarch_cache> loongarch_cpu_cache =
 
 static inline loongarch_align la464_align ()
 {
-  return loongarch_align ().function_ ("32").label_ ("16");
+  return loongarch_align ().function_ ("32").loop_ ("16").jump_ ("16");
+}
+
+static inline loongarch_align la664_align ()
+{
+  return loongarch_align ().function_ ("8").loop_ ("8").jump_ ("32");
 }
 
 array_tune<loongarch_align> loongarch_cpu_align =
   array_tune<loongarch_align> ()
-    .set (CPU_LOONGARCH64, la464_align ())
+    .set (CPU_LOONGARCH64, la664_align ())
     .set (CPU_LA464, la464_align ())
-    .set (CPU_LA664, la464_align ());
+    .set (CPU_LA664, la664_align ());
 
 /* Default RTX cost initializer.  */
 loongarch_rtx_cost_data::loongarch_rtx_cost_data ()
diff --git a/gcc/config/loongarch/loongarch-opts.cc b/gcc/config/loongarch/loongarch-opts.cc
index 2a6fc41b247..7b21cc311a8 100644
--- a/gcc/config/loongarch/loongarch-opts.cc
+++ b/gcc/config/loongarch/loongarch-opts.cc
@@ -922,13 +922,20 @@ loongarch_target_option_override (struct loongarch_target *target,
 {
   loongarch_update_gcc_opt_status (target, opts, opts_set);
 
-  /* alignments */
-  if (opts->x_flag_align_functions && !opts->x_str_align_functions)
-    opts->x_str_align_functions
-      = loongarch_cpu_align[target->cpu_tune].function;
+  /* If not optimizing for size, set the default
+     alignment to what the target wants.  */
+  if (!opts->x_optimize_size)
+    {
+      if (opts->x_flag_align_functions && !opts->x_str_align_functions)
+	opts->x_str_align_functions
+	  = loongarch_cpu_align[target->cpu_tune].function;
+
+      if (opts->x_flag_align_loops && !opts->x_str_align_loops)
+	opts->x_str_align_loops = loongarch_cpu_align[target->cpu_tune].loop;
 
-  if (opts->x_flag_align_labels && !opts->x_str_align_labels)
-    opts->x_str_align_labels = loongarch_cpu_align[target->cpu_tune].label;
+      if (opts->x_flag_align_jumps && !opts->x_str_align_jumps)
+	opts->x_str_align_jumps = loongarch_cpu_align[target->cpu_tune].jump;
+    }
 
   /* Set up parameters to be used in prefetching algorithm.  */
   int simultaneous_prefetches
diff --git a/gcc/config/loongarch/loongarch-tune.h b/gcc/config/loongarch/loongarch-tune.h
index 72b75f6de3f..3974edf9a90 100644
--- a/gcc/config/loongarch/loongarch-tune.h
+++ b/gcc/config/loongarch/loongarch-tune.h
@@ -162,14 +162,16 @@ struct loongarch_cache {
   }
 };
 
-/* Alignment for functions and labels for best performance.  For new uarchs
-   the value should be measured via benchmarking.  See the documentation for
-   -falign-functions and -falign-labels in invoke.texi for the format.  */
+/* Alignment for functions loops and jumps for best performance.  For new
+   uarchs the value should be measured via benchmarking.  See the documentation
+   for -falign-functions -falign-loops and -falign-jumps in invoke.texi for the
+   format.  */
 struct loongarch_align {
   const char *function;	/* default value for -falign-functions */
-  const char *label;	/* default value for -falign-labels */
+  const char *loop;	/* default value for -falign-loops */
+  const char *jump;	/* default value for -falign-jumps */
 
-  loongarch_align () : function (nullptr), label (nullptr) {}
+  loongarch_align () : function (nullptr), loop (nullptr), jump (nullptr) {}
 
   loongarch_align function_ (const char *_function)
   {
@@ -177,9 +179,15 @@ struct loongarch_align {
     return *this;
   }
 
-  loongarch_align label_ (const char *_label)
+  loongarch_align loop_ (const char *_loop)
   {
-    label = _label;
+    loop = _loop;
+    return *this;
+  }
+
+  loongarch_align jump_ (const char *_jump)
+  {
+    jump = _jump;
     return *this;
   }
 };
-- 
2.39.3


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

* Re: [PATCH v1] LoongArch: Set default alignment for functions jumps and loops [PR112919].
  2024-04-02  7:03 [PATCH v1] LoongArch: Set default alignment for functions jumps and loops [PR112919] Lulu Cheng
@ 2024-04-06  9:53 ` Xi Ruoyao
  2024-04-08  1:04   ` Lulu Cheng
  0 siblings, 1 reply; 3+ messages in thread
From: Xi Ruoyao @ 2024-04-06  9:53 UTC (permalink / raw)
  To: Lulu Cheng, gcc-patches; +Cc: mark, i, xuchenghua

On Tue, 2024-04-02 at 15:03 +0800, Lulu Cheng wrote:
> +/* Alignment for functions loops and jumps for best performance.  For new
> +   uarchs the value should be measured via benchmarking.  See the documentation
> +   for -falign-functions -falign-loops and -falign-jumps in invoke.texi for the
                           ^             ^

Better have two commas here.

Otherwise it should be OK.

> +   format.  */

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

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

* Re:[pushed] [PATCH v1] LoongArch: Set default alignment for functions jumps and loops [PR112919].
  2024-04-06  9:53 ` Xi Ruoyao
@ 2024-04-08  1:04   ` Lulu Cheng
  0 siblings, 0 replies; 3+ messages in thread
From: Lulu Cheng @ 2024-04-08  1:04 UTC (permalink / raw)
  To: Xi Ruoyao, gcc-patches; +Cc: mark, i, xuchenghua


在 2024/4/6 下午5:53, Xi Ruoyao 写道:
> On Tue, 2024-04-02 at 15:03 +0800, Lulu Cheng wrote:
>> +/* Alignment for functions loops and jumps for best performance.  For new
>> +   uarchs the value should be measured via benchmarking.  See the documentation
>> +   for -falign-functions -falign-loops and -falign-jumps in invoke.texi for the
>                             ^             ^
>
> Better have two commas here.
>
> Otherwise it should be OK.
>
>> +   format.  */
Modify the annotation information and pushed to r14-9824.


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

end of thread, other threads:[~2024-04-08  1:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-02  7:03 [PATCH v1] LoongArch: Set default alignment for functions jumps and loops [PR112919] Lulu Cheng
2024-04-06  9:53 ` Xi Ruoyao
2024-04-08  1:04   ` Lulu Cheng

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).