public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] [rtl/cprop_hardreg] Don't propagate for a more expensive reg-reg move.
@ 2022-01-25  1:31 liuhongt
  2022-01-28 17:54 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: liuhongt @ 2022-01-25  1:31 UTC (permalink / raw)
  To: gcc-patches

For i386, it enables optimization like:

        vmovd   %xmm0, %edx
-       vmovd   %xmm0, %eax
+       movl    %edx, %eax

Bootstrapped and regtested on CLX for both
x86_64-pc-linux-gnu{-m32,} and
x86_64-pc-linux-gnu{-m32\ -march=native,\ -march=native}

Ok for trunk?

gcc/ChangeLog:

	PR rtl-optimization/104059
	* regcprop.cc (copyprop_hardreg_forward_1): Don't propagate
	for a more expensive reg-reg move.

gcc/testsuite/ChangeLog:

	* gcc.target/i386/pr104059.c: New test.
---
 gcc/regcprop.cc                          | 17 ++++++++++++++++-
 gcc/testsuite/gcc.target/i386/pr104059.c | 22 ++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr104059.c

diff --git a/gcc/regcprop.cc b/gcc/regcprop.cc
index 1a9bcf0a1ad..858896b82c6 100644
--- a/gcc/regcprop.cc
+++ b/gcc/regcprop.cc
@@ -891,6 +891,7 @@ copyprop_hardreg_forward_1 (basic_block bb, struct value_data *vd)
       if (set && REG_P (SET_SRC (set)))
 	{
 	  rtx src = SET_SRC (set);
+	  rtx dest = SET_DEST (set);
 	  unsigned int regno = REGNO (src);
 	  machine_mode mode = GET_MODE (src);
 	  unsigned int i;
@@ -914,7 +915,7 @@ copyprop_hardreg_forward_1 (basic_block bb, struct value_data *vd)
 
 	  /* If the destination is also a register, try to find a source
 	     register in the same class.  */
-	  if (REG_P (SET_DEST (set)))
+	  if (REG_P (dest))
 	    {
 	      new_rtx = find_oldest_value_reg (REGNO_REG_CLASS (regno),
 					       src, vd);
@@ -942,6 +943,20 @@ copyprop_hardreg_forward_1 (basic_block bb, struct value_data *vd)
 				       mode, i, regno);
 	      if (new_rtx != NULL_RTX)
 		{
+		  /* Don't propagate for a more expensive reg-reg move.  */
+		  if (REG_P (dest))
+		    {
+		      enum reg_class from = REGNO_REG_CLASS (regno);
+		      enum reg_class to = REGNO_REG_CLASS (REGNO (dest));
+		      enum reg_class new_from = REGNO_REG_CLASS (i);
+		      unsigned int original_cost
+			= targetm.register_move_cost (mode, from, to);
+		      unsigned int after_cost
+			= targetm.register_move_cost (mode, new_from, to);
+		      if (after_cost > original_cost)
+			goto no_move_special_case;
+		    }
+
 		  if (validate_change (insn, &SET_SRC (set), new_rtx, 0))
 		    {
 		      ORIGINAL_REGNO (new_rtx) = ORIGINAL_REGNO (src);
diff --git a/gcc/testsuite/gcc.target/i386/pr104059.c b/gcc/testsuite/gcc.target/i386/pr104059.c
new file mode 100644
index 00000000000..4815fa38d21
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr104059.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-mavx2 -O2 -fdump-rtl-cprop_hardreg-details" } */
+/* { dg-final { scan-rtl-dump-not {replaced reg [0-9]* with [0-9]*} "cprop_hardreg" } } */
+
+#include<stdint.h>
+int test (uint8_t *p, uint32_t t[1][1], int n) {
+
+  int sum = 0;
+  uint32_t a0;
+  for (int i = 0; i < 4; i++, p++)
+    t[i][0] = p[0];
+
+  for (int i = 0; i < 4; i++) {
+    {
+      int t0 = t[0][i] + t[0][i];
+      a0 = t0;
+    };
+    sum += a0;
+  }
+  return (((uint16_t)sum) + ((uint32_t)sum >> 16)) >> 1;
+}
+
-- 
2.18.1


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

* Re: [PATCH] [rtl/cprop_hardreg] Don't propagate for a more expensive reg-reg move.
  2022-01-25  1:31 [PATCH] [rtl/cprop_hardreg] Don't propagate for a more expensive reg-reg move liuhongt
@ 2022-01-28 17:54 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2022-01-28 17:54 UTC (permalink / raw)
  To: liuhongt, gcc-patches



On 1/24/2022 6:31 PM, liuhongt via Gcc-patches wrote:
> For i386, it enables optimization like:
>
>          vmovd   %xmm0, %edx
> -       vmovd   %xmm0, %eax
> +       movl    %edx, %eax
>
> Bootstrapped and regtested on CLX for both
> x86_64-pc-linux-gnu{-m32,} and
> x86_64-pc-linux-gnu{-m32\ -march=native,\ -march=native}
>
> Ok for trunk?
>
> gcc/ChangeLog:
>
> 	PR rtl-optimization/104059
> 	* regcprop.cc (copyprop_hardreg_forward_1): Don't propagate
> 	for a more expensive reg-reg move.
>
> gcc/testsuite/ChangeLog:
>
> 	* gcc.target/i386/pr104059.c: New test.
OK
jeff


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

end of thread, other threads:[~2022-01-28 17:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-25  1:31 [PATCH] [rtl/cprop_hardreg] Don't propagate for a more expensive reg-reg move liuhongt
2022-01-28 17:54 ` Jeff Law

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