]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Adjust rtx_cost for MEM to enable more simplication
authorliuhongt <hongtao.liu@intel.com>
Fri, 19 Apr 2024 02:39:53 +0000 (10:39 +0800)
committerliuhongt <hongtao.liu@intel.com>
Thu, 6 Jun 2024 00:35:40 +0000 (08:35 +0800)
For CONST_VECTOR_DUPLICATE_P in constant_pool, it is just broadcast or
variants in ix86_vector_duplicate_simode_const.
Adjust the cost to COSTS_N_INSNS (2) + speed which should be a little
bit larger than broadcast.

gcc/ChangeLog:
PR target/114428
* config/i386/i386.cc (ix86_rtx_costs): Adjust cost for
CONST_VECTOR_DUPLICATE_P in constant_pool.
* config/i386/i386-expand.cc (ix86_broadcast_from_constant):
Remove static.
* config/i386/i386-protos.h (ix86_broadcast_from_constant):
Declare.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr114428.c: New test.

gcc/config/i386/i386-expand.cc
gcc/config/i386/i386-protos.h
gcc/config/i386/i386.cc
gcc/testsuite/gcc.target/i386/pr114428.c [new file with mode: 0644]

index 215a998fc26b2f06a3fc70fe9b305db8c1197274..56d29c15f9a5cc11233c7c65fd76557b7d3cd5c4 100644 (file)
@@ -588,7 +588,7 @@ ix86_expand_move (machine_mode mode, rtx operands[])
 
 /* OP is a memref of CONST_VECTOR, return scalar constant mem
    if CONST_VECTOR is a vec_duplicate, else return NULL.  */
-static rtx
+rtx
 ix86_broadcast_from_constant (machine_mode mode, rtx op)
 {
   int nunits = GET_MODE_NUNITS (mode);
index dbc861fb1eaad0414a158639a7d19946903ccca3..907127692009f902b93be0547450703930672803 100644 (file)
@@ -107,6 +107,7 @@ extern void ix86_expand_clear (rtx);
 extern void ix86_expand_move (machine_mode, rtx[]);
 extern void ix86_expand_vector_move (machine_mode, rtx[]);
 extern void ix86_expand_vector_move_misalign (machine_mode, rtx[]);
+extern rtx ix86_broadcast_from_constant (machine_mode, rtx);
 extern rtx ix86_fixup_binary_operands (enum rtx_code, machine_mode,
                                       rtx[], bool = false);
 extern void ix86_fixup_binary_operands_no_copy (enum rtx_code, machine_mode,
index 271da127a89c94419e312b03ed990e4b69b38ce6..a9d62c84c528dabff7b54cbc09824c5dc4da0b1a 100644 (file)
@@ -22191,6 +22191,19 @@ ix86_rtx_costs (rtx x, machine_mode mode, int outer_code_i, int opno,
       return true;
 
     case MEM:
+      /* CONST_VECTOR_DUPLICATE_P in constant_pool is just broadcast.
+        or variants in ix86_vector_duplicate_simode_const.  */
+
+      if (GET_MODE_SIZE (mode) >= 16
+         && VECTOR_MODE_P (mode)
+         && SYMBOL_REF_P (XEXP (x, 0))
+         && CONSTANT_POOL_ADDRESS_P (XEXP (x, 0))
+         && ix86_broadcast_from_constant (mode, x))
+       {
+         *total = COSTS_N_INSNS (2) + speed;
+         return true;
+       }
+
       /* An insn that accesses memory is slightly more expensive
          than one that does not.  */
       if (speed)
diff --git a/gcc/testsuite/gcc.target/i386/pr114428.c b/gcc/testsuite/gcc.target/i386/pr114428.c
new file mode 100644 (file)
index 0000000..bbbc5a0
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-march=x86-64-v3 -mno-avx512f -O2" } */
+/* { dg-final { scan-assembler-not "vpsra[dw]" } } */
+
+void
+foo2 (char* __restrict a, short* b)
+{
+  for (int i = 0; i != 32; i++)
+    a[i] = b[i] >> (short)8;
+}
+
+void
+foo3 (char* __restrict a, short* b)
+{
+  for (int i = 0; i != 16; i++)
+    a[i] = b[i] >> (short)8;
+}
+