]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LoongArch: Adjust the cost of ADDRESS_REG_REG.
authorLulu Cheng <chenglulu@loongson.cn>
Tue, 10 Dec 2024 12:59:22 +0000 (20:59 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Fri, 14 Feb 2025 07:55:29 +0000 (15:55 +0800)
After changing this cost from 1 to 3, the performance of spec2006
401 473 416 465 482 can be improved by about 2% on LA664.

Add option '-maddr-reg-reg-cost='.

gcc/ChangeLog:

* config/loongarch/genopts/loongarch.opt.in: Add
option '-maddr-reg-reg-cost='.
* config/loongarch/loongarch-def.cc
(loongarch_rtx_cost_data::loongarch_rtx_cost_data): Initialize
addr_reg_reg_cost to 3.
* config/loongarch/loongarch-opts.cc
(loongarch_target_option_override): If '-maddr-reg-reg-cost='
is not used, set it to the initial value.
* config/loongarch/loongarch-tune.h
(struct loongarch_rtx_cost_data): Add the member
addr_reg_reg_cost and its assignment function to the structure
loongarch_rtx_cost_data.
* config/loongarch/loongarch.cc (loongarch_address_insns):
Use la_addr_reg_reg_cost to set the cost of ADDRESS_REG_REG.
* config/loongarch/loongarch.opt: Regenerate.
* config/loongarch/loongarch.opt.urls: Regenerate.
* doc/invoke.texi: Add description of '-maddr-reg-reg-cost='.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/const-double-zero-stx.c: Add
'-maddr-reg-reg-cost=1'.
* gcc.target/loongarch/stack-check-alloca-1.c: Likewise.

gcc/config/loongarch/genopts/loongarch.opt.in
gcc/config/loongarch/loongarch-def.cc
gcc/config/loongarch/loongarch-opts.cc
gcc/config/loongarch/loongarch-tune.h
gcc/config/loongarch/loongarch.cc
gcc/config/loongarch/loongarch.opt
gcc/config/loongarch/loongarch.opt.urls
gcc/doc/invoke.texi
gcc/testsuite/gcc.target/loongarch/const-double-zero-stx.c
gcc/testsuite/gcc.target/loongarch/stack-check-alloca-1.c

index 8c292c8600d0f8fba04abb98e931fce73035a2e3..39c1545e5408b6394497ecacf29c31269367ec89 100644 (file)
@@ -177,6 +177,10 @@ mbranch-cost=
 Target RejectNegative Joined UInteger Var(la_branch_cost) Save
 -mbranch-cost=COST     Set the cost of branches to roughly COST instructions.
 
+maddr-reg-reg-cost=
+Target RejectNegative Joined UInteger Var(la_addr_reg_reg_cost) Save
+-maddr-reg-reg-cost=COST  Set the cost of ADDRESS_REG_REG to the value calculated by COST.
+
 mcheck-zero-division
 Target Mask(CHECK_ZERO_DIV) Save
 Trap on integer divide by zero.
index b0271eb3b9adf79f6dd6b490696314ea4b880217..5f235a04ef2fc263d645354d34f61c6f27b4f5c5 100644 (file)
@@ -136,6 +136,7 @@ loongarch_rtx_cost_data::loongarch_rtx_cost_data ()
     movcf2gr (COSTS_N_INSNS (7)),
     movgr2cf (COSTS_N_INSNS (15)),
     branch_cost (6),
+    addr_reg_reg_cost (3),
     memory_latency (4) {}
 
 /* The following properties cannot be looked up directly using "cpucfg".
index 36342cc93731ebc54b7b8c3d2d984b5bb983fac9..c2a63f75fc24a4710aa5c2eed65edb42547a61b5 100644 (file)
@@ -1010,6 +1010,9 @@ loongarch_target_option_override (struct loongarch_target *target,
   if (!opts_set->x_la_branch_cost)
     opts->x_la_branch_cost = loongarch_cost->branch_cost;
 
+  if (!opts_set->x_la_addr_reg_reg_cost)
+    opts->x_la_addr_reg_reg_cost = loongarch_cost->addr_reg_reg_cost;
+
   /* other stuff */
   if (ABI_LP64_P (target->abi.base))
     opts->x_flag_pcc_struct_return = 0;
index e69173ebf79ee28f4fa39217c828edc5d48aa39b..f7819fe7678331a2f928dd611f06322ebd1884de 100644 (file)
@@ -38,6 +38,7 @@ struct loongarch_rtx_cost_data
   unsigned short movcf2gr;
   unsigned short movgr2cf;
   unsigned short branch_cost;
+  unsigned short addr_reg_reg_cost;
   unsigned short memory_latency;
 
   /* Default RTX cost initializer, implemented in loongarch-def.cc.  */
@@ -115,6 +116,12 @@ struct loongarch_rtx_cost_data
     return *this;
   }
 
+  loongarch_rtx_cost_data addr_reg_reg_cost_ (unsigned short _addr_reg_reg_cost)
+  {
+    addr_reg_reg_cost = _addr_reg_reg_cost;
+    return *this;
+  }
+
   loongarch_rtx_cost_data memory_latency_ (unsigned short _memory_latency)
   {
     memory_latency = _memory_latency;
index e9978370e8c956474cc1b5ddded852d4ae1e59af..495b62309d616bd4c682959468bd39344d54d12c 100644 (file)
@@ -2383,7 +2383,7 @@ loongarch_address_insns (rtx x, machine_mode mode, bool might_split_p)
        return factor;
 
       case ADDRESS_REG_REG:
-       return factor;
+       return factor * la_addr_reg_reg_cost;
 
       case ADDRESS_CONST_INT:
        return lsx_p ? 0 : factor;
index b5a5e3f8f032051db57e2ddcdfbe4edb2df9b37f..4d85cf5a80459b6b31bc2851e51a42edcfef86c9 100644 (file)
@@ -185,6 +185,10 @@ mbranch-cost=
 Target RejectNegative Joined UInteger Var(la_branch_cost) Save
 -mbranch-cost=COST     Set the cost of branches to roughly COST instructions.
 
+maddr-reg-reg-cost=
+Target RejectNegative Joined UInteger Var(la_addr_reg_reg_cost) Save
+-maddr-reg-reg-cost=COST  Set the cost of ADDRESS_REG_REG to the value calculated by COST.
+
 mcheck-zero-division
 Target Mask(CHECK_ZERO_DIV) Save
 Trap on integer divide by zero.
index 571c504e61d74849074214f60951207dfcc36cf0..5f644f6c31521f06062d8ff8c5a55250fd07f014 100644 (file)
@@ -27,6 +27,9 @@ UrlSuffix(gcc/LoongArch-Options.html#index-mabi-2)
 mbranch-cost=
 UrlSuffix(gcc/LoongArch-Options.html#index-mbranch-cost-2)
 
+maddr-reg-reg-cost=
+UrlSuffix(gcc/LoongArch-Options.html#index-maddr-reg-reg-cost)
+
 mcheck-zero-division
 UrlSuffix(gcc/LoongArch-Options.html#index-mcheck-zero-division)
 
index e78810ab4b3fba7ce20f08a50afd4c7b8b5b2e1b..d1d633beb4bb4f1e8f340ae587c0b550563ae6d2 100644 (file)
@@ -1078,7 +1078,8 @@ Objective-C and Objective-C++ Dialects}.
 @gccoptlist{-march=@var{arch-type}  -mtune=@var{tune-type} -mabi=@var{base-abi-type}
 -mfpu=@var{fpu-type} -msimd=@var{simd-type}
 -msoft-float -msingle-float -mdouble-float -mlsx -mno-lsx -mlasx -mno-lasx
--mbranch-cost=@var{n}  -mcheck-zero-division -mno-check-zero-division
+-mbranch-cost=@var{n} -maddr-reg-reg-cost=@var{n}  -mcheck-zero-division
+-mno-check-zero-division
 -mcond-move-int  -mno-cond-move-int
 -mcond-move-float  -mno-cond-move-float
 -memcpy  -mno-memcpy -mstrict-align -mno-strict-align -G @var{num}
@@ -27684,6 +27685,10 @@ they appear on the GCC driver's command line, deriving the final / canonicalized
 @item -mbranch-cost=@var{n}
 Set the cost of branches to roughly @var{n} instructions.
 
+@opindex maddr-reg-reg-cost
+@item -maddr-reg-reg-cost=@var{n}
+Set the cost of ADDRESS_REG_REG to the value calculated by @var{n}.
+
 @opindex mcheck-zero-division
 @item -mcheck-zero-division
 @itemx -mno-check-zero-divison
index 8fb04be8ff5dd98aa36bcfc9f991ef53bd104643..fd1bb49ff2c8fde4a97c7769c97a9115947deadc 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2" } */
+/* { dg-options "-O2 -maddr-reg-reg-cost=1" } */
 /* { dg-final { scan-assembler-times {stx\..\t\$r0} 2 } } */
 
 extern float arr_f[];
index 6ee589c4b3da63ac44cdce4f6baeb9f8d76e656d..6168461b2222dfaa38253ce77f6bb916a3dcd43d 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fstack-clash-protection --param stack-clash-protection-guard-size=16" } */
+/* { dg-options "-O2 -fstack-clash-protection --param stack-clash-protection-guard-size=16 -maddr-reg-reg-cost=1" } */
 /* { dg-require-effective-target supports_stack_clash_protection } */
 /* { dg-require-effective-target alloca } */
 /* { dg-skip-if "" { *-*-* } { "-fstack-check" } { "" } } */