]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LoongArch: Set default alignment for functions and labels with -mtune
authorXi Ruoyao <xry111@xry111.site>
Wed, 14 Jun 2023 00:24:05 +0000 (08:24 +0800)
committerXi Ruoyao <xry111@xry111.site>
Thu, 15 Jun 2023 07:40:43 +0000 (15:40 +0800)
The LA464 micro-architecture is sensitive to alignment of code.  The
Loongson team has benchmarked various combinations of function, the
results [1] show that 16-byte label alignment together with 32-byte
function alignment gives best results in terms of SPEC score.

Add a mtune-based table-driven mechanism to set the default of
-falign-{functions,labels}.  As LA464 is the first (and the only for
now) uarch supported by GCC, the same setting is also used for
the "generic" -mtune=loongarch64.  In the future we may set different
settings for LA{2,3,6}64 once we add the support for them.

Bootstrapped and regtested on loongarch64-linux-gnu.  Ok for trunk?

gcc/ChangeLog:

* config/loongarch/loongarch-tune.h (loongarch_align): New
struct.
* config/loongarch/loongarch-def.h (loongarch_cpu_align): New
array.
* config/loongarch/loongarch-def.c (loongarch_cpu_align): Define
the array.
* config/loongarch/loongarch.cc
(loongarch_option_override_internal): Set the value of
-falign-functions= if -falign-functions is enabled but no value
is given.  Likewise for -falign-labels=.

gcc/config/loongarch/loongarch-def.c
gcc/config/loongarch/loongarch-def.h
gcc/config/loongarch/loongarch-tune.h
gcc/config/loongarch/loongarch.cc

index fc4ebbefede6e4233e4f404729e21363f541e080..6729c857f7c4b75c23f1f5d53ca42aba3c835c22 100644 (file)
@@ -72,6 +72,18 @@ loongarch_cpu_cache[N_TUNE_TYPES] = {
   },
 };
 
+struct loongarch_align
+loongarch_cpu_align[N_TUNE_TYPES] = {
+  [CPU_LOONGARCH64] = {
+    .function = "32",
+    .label = "16",
+  },
+  [CPU_LA464] = {
+    .function = "32",
+    .label = "16",
+  },
+};
+
 /* The following properties cannot be looked up directly using "cpucfg".
  So it is necessary to provide a default value for "unknown native"
  tune targets (i.e. -mtune=native while PRID does not correspond to
index 778b14099568de2d947e307292c89ad299f3b9e6..fb8bb88eb52ff7d3f50a03e97750839e01055703 100644 (file)
@@ -144,6 +144,7 @@ extern int loongarch_cpu_issue_rate[];
 extern int loongarch_cpu_multipass_dfa_lookahead[];
 
 extern struct loongarch_cache loongarch_cpu_cache[];
+extern struct loongarch_align loongarch_cpu_align[];
 extern struct loongarch_rtx_cost_data loongarch_cpu_rtx_cost_data[];
 
 #ifdef __cplusplus
index ba31c4f08c30708c7743c01441517c07e4a2c951..5c03262daffa6fab7301d240e438676653f1261e 100644 (file)
@@ -48,4 +48,12 @@ struct loongarch_cache {
     int simultaneous_prefetches; /* number of parallel prefetch */
 };
 
+/* 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.  */
+struct loongarch_align {
+  const char *function;        /* default value for -falign-functions */
+  const char *label;   /* default value for -falign-labels */
+};
+
 #endif /* LOONGARCH_TUNE_H */
index eb73d11b869dcee70cf74b321554dafef4c80ef0..5b8b93eb24b2941b8b8cd351bea7d8d7c871aafc 100644 (file)
@@ -6249,6 +6249,12 @@ loongarch_option_override_internal (struct gcc_options *opts)
       && !opts->x_optimize_size)
     opts->x_flag_prefetch_loop_arrays = 1;
 
+  if (opts->x_flag_align_functions && !opts->x_str_align_functions)
+    opts->x_str_align_functions = loongarch_cpu_align[LARCH_ACTUAL_TUNE].function;
+
+  if (opts->x_flag_align_labels && !opts->x_str_align_labels)
+    opts->x_str_align_labels = loongarch_cpu_align[LARCH_ACTUAL_TUNE].label;
+
   if (TARGET_DIRECT_EXTERN_ACCESS && flag_shlib)
     error ("%qs cannot be used for compiling a shared library",
           "-mdirect-extern-access");