Add a gain of COSTS_N_INSNS (1) for pxor with TImode memory since it
reduces one memory access vs 2 x xorq with DImode memory.

gcc/

PR target/127020
* config/i386/i386-features.cc
(timode_scalar_chain::compute_convert_gain): Add gain of
COSTS_N_INSNS (1) for pxor with TImode memory.

gcc/testsuite/

PR target/127020
* gcc.target/i386/sse2-stv-3.c: Adjusted.

-- 
H.J.
From 79224b30f21cc55783f091411079619bf364e151 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <[email protected]>
Date: Tue, 25 Aug 2026 04:13:54 +0800
Subject: [PATCH] x86-64: Increase gain for pxor with TImode memory

Add a gain of COSTS_N_INSNS (1) for pxor with TImode memory since it
reduces one memory access vs 2 x xorq with DImode memory.

gcc/

	PR target/127020
	* config/i386/i386-features.cc
	(timode_scalar_chain::compute_convert_gain): Add gain of
	COSTS_N_INSNS (1) for pxor with TImode memory.

gcc/testsuite/

	PR target/127020
	* gcc.target/i386/sse2-stv-3.c: Adjusted.

Signed-off-by: H.J. Lu <[email protected]>
---
 gcc/config/i386/i386-features.cc           | 7 ++++++-
 gcc/testsuite/gcc.target/i386/sse2-stv-3.c | 8 ++++----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/gcc/config/i386/i386-features.cc b/gcc/config/i386/i386-features.cc
index eb5f82e42cb..824ebfeec9d 100644
--- a/gcc/config/i386/i386-features.cc
+++ b/gcc/config/i386/i386-features.cc
@@ -1745,7 +1745,12 @@ timode_scalar_chain::compute_convert_gain ()
 	      break;
 	    }
 	  if (!MEM_P (dst))
-	    igain = COSTS_N_INSNS (1);
+	    {
+	      igain = COSTS_N_INSNS (1);
+	      if (MEM_P (XEXP (src, 1)))
+		/* 2 x xorq vs pxor.  */
+		igain += COSTS_N_INSNS (1);
+	    }
 	  if (CONST_SCALAR_INT_P (XEXP (src, 1)))
 	    igain += timode_immed_const_gain (XEXP (src, 1), bb);
 	  break;
diff --git a/gcc/testsuite/gcc.target/i386/sse2-stv-3.c b/gcc/testsuite/gcc.target/i386/sse2-stv-3.c
index 0a638013aed..9f3210a9adb 100644
--- a/gcc/testsuite/gcc.target/i386/sse2-stv-3.c
+++ b/gcc/testsuite/gcc.target/i386/sse2-stv-3.c
@@ -25,7 +25,7 @@ void foo_fun()
   z = (fun() ^ a ^ b ^ c);
 }
 
-/* { dg-final { scan-assembler-times "punpcklqdq" 2 } } */
-/* { dg-final { scan-assembler-times "movhlps" 1 } } */
-/* { dg-final { scan-assembler-times "pxor" 9 } } */
-/* { dg-final { scan-assembler-times "xorq" 8 } } */
+/* { dg-final { scan-assembler-times "punpcklqdq" 3 } } */
+/* { dg-final { scan-assembler-times "movhlps" 2 } } */
+/* { dg-final { scan-assembler-times "pxor" 13 } } */
+/* { dg-final { scan-assembler-not "xorq" } } */
-- 
2.55.0

Reply via email to