This patch checks for the reordering cost on the target, for each store,
using `avoid_store_forwarding_reorder_cost_p` before applying the
transformation.

It, also, updates the x86_64 testcases to set `asf-default-cost-value=1`,
in order for the transformations to be applied.

gcc/ChangeLog:

        * avoid-store-forwarding.cc (process_store_forwarding):
        Call `avoid_store_forwarding_reorder_cost_p` for each store
        instruction in the store-load sequence.

gcc/testsuite/ChangeLog:

        * gcc.target/x86_64/abi/callabi/avoid-store-forwarding-1.c:
        Add --param asf-default-cost-value=1.
        * gcc.target/x86_64/abi/callabi/avoid-store-forwarding-2.c: Likewise.

Signed-off-by: Konstantinos Eleftheriou <[email protected]>
---

(no changes since v1)

 gcc/avoid-store-forwarding.cc                    | 16 ++++++++++++++--
 .../abi/callabi/avoid-store-forwarding-1.c       |  2 +-
 .../abi/callabi/avoid-store-forwarding-2.c       |  2 +-
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/gcc/avoid-store-forwarding.cc b/gcc/avoid-store-forwarding.cc
index 78ed736e0a3e..c940b4ad98de 100644
--- a/gcc/avoid-store-forwarding.cc
+++ b/gcc/avoid-store-forwarding.cc
@@ -264,6 +264,17 @@ process_store_forwarding (vec<store_fwd_info> &stores, 
rtx_insn *load_insn,
   /* Check if we can emit bit insert instructions for all forwarded stores.  */
   FOR_EACH_VEC_ELT (stores, i, it)
     {
+      /* First check if it's profitable for the target to rearrange the store.
+        If it's not, we can't continue with the tranformation.  */
+      if (!targetm.avoid_store_forwarding_reorder_cost_p (
+         GET_MODE (it->store_mem), load_mem_mode, it->offset))
+       {
+         if (dump_file)
+           fprintf (dump_file, "Not transformed due to target decision on "
+                               "the store/load reordering.\n");
+         return false;
+       }
+
       it->mov_reg = gen_reg_rtx (GET_MODE (it->store_mem));
       rtx_insn *insns = NULL;
 
@@ -351,12 +362,13 @@ process_store_forwarding (vec<store_fwd_info> &stores, 
rtx_insn *load_insn,
     total_cost -= insn_cost (load_insn, true);
 
   /* Let the target decide if transforming this store forwarding instance is
-     profitable.  */
+     profitable based on the cost of the newly generated instructions.  */
   if (!targetm.avoid_store_forwarding_p (stores, load_mem, total_cost,
                                         load_elim))
     {
       if (dump_file)
-       fprintf (dump_file, "Not transformed due to target decision.\n");
+       fprintf (dump_file, "Not transformed due to target decision on the "
+                           "cost of the generated instructions.\n");
 
       return false;
     }
diff --git 
a/gcc/testsuite/gcc.target/x86_64/abi/callabi/avoid-store-forwarding-1.c 
b/gcc/testsuite/gcc.target/x86_64/abi/callabi/avoid-store-forwarding-1.c
index d94bcf136ace..8005d210b5f7 100644
--- a/gcc/testsuite/gcc.target/x86_64/abi/callabi/avoid-store-forwarding-1.c
+++ b/gcc/testsuite/gcc.target/x86_64/abi/callabi/avoid-store-forwarding-1.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -favoid-store-forwarding" } */
+/* { dg-options "-O2 -favoid-store-forwarding --param 
asf-default-cost-value=1" } */
 
 typedef union {
     char arr_8[8];
diff --git 
a/gcc/testsuite/gcc.target/x86_64/abi/callabi/avoid-store-forwarding-2.c 
b/gcc/testsuite/gcc.target/x86_64/abi/callabi/avoid-store-forwarding-2.c
index b958612173bd..36c88e27c20f 100644
--- a/gcc/testsuite/gcc.target/x86_64/abi/callabi/avoid-store-forwarding-2.c
+++ b/gcc/testsuite/gcc.target/x86_64/abi/callabi/avoid-store-forwarding-2.c
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -favoid-store-forwarding 
-fdump-rtl-avoid_store_forwarding" } */
+/* { dg-options "-O2 -favoid-store-forwarding 
-fdump-rtl-avoid_store_forwarding --param asf-default-cost-value=1" } */
 
 typedef union {
     char arr_8[8];
-- 
2.50.1

Reply via email to