public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [x86_64 PATCH] Two minor tweaks to ix86_expand_move.
@ 2023-06-16 16:27 Roger Sayle
  2023-06-17 13:15 ` Uros Bizjak
  0 siblings, 1 reply; 2+ messages in thread
From: Roger Sayle @ 2023-06-16 16:27 UTC (permalink / raw)
  To: gcc-patches; +Cc: 'Uros Bizjak'

[-- Attachment #1: Type: text/plain, Size: 1995 bytes --]


This patch splits out two (independent) minor changes to i386-expand.cc's
ix86_expand_move from a larger patch, given that it's better to review
and commit these independent pieces separately from a more complex patch.

The first change is to test for CONST_WIDE_INT_P before calling
ix86_convert_const_wide_int_to_broadcast.  Whilst stepping through
this function in gdb, I was surprised that the code was continually
jumping into this function with operands that obviously weren't
appropriate.

The second change is to generalize the optimization for efficiently
moving a TImode value to V1TImode (via V2DImode), to cover all 128-bit
vector modes.

Hence for the test case:

typedef unsigned long uv2di __attribute__ ((__vector_size__ (16)));
uv2di foo2(__int128 x) { return (uv2di)x; }

we'd previously move via memory with:

foo2:   movq    %rdi, -24(%rsp)
        movq    %rsi, -16(%rsp)
        movdqa  -24(%rsp), %xmm0
        ret

with this patch we now generate with -O2 (the same as V1TImode):

foo2:   movq    %rdi, %xmm0
        movq    %rsi, %xmm1
        punpcklqdq      %xmm1, %xmm0
        ret

and with -O2 -msse4 the even better:

foo2:   movq    %rdi, %xmm0
        pinsrq  $1, %rsi, %xmm0
        ret

The new test case is unimaginatively called sse2-v1ti-mov-2.c given
the original test case just for V1TI mode was called sse2-v1ti-mov-1.c.

This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
and make -k check, both with and without --target_board=unix{-m32}
with no new failures.  Ok for mainline?


2023-06-16  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
        * config/i386/i386-expand.cc (ix86_expand_move): Check that OP1 is
        CONST_WIDE_INT_P before calling ix86_convert_wide_int_to_broadcast.
        Generalize special case for converting TImode to V1TImode to handle
        all 128-bit vector conversions.

gcc/testsuite/ChangeLog
        * gcc.target/i386/sse2-v1ti-mov-2.c: New test case.


Thanks in advance,
Roger
--


[-- Attachment #2: patchvm.txt --]
[-- Type: text/plain, Size: 2345 bytes --]

diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index def060a..6a28b67 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -521,7 +521,8 @@ ix86_expand_move (machine_mode mode, rtx operands[])
 		  return;
 		}
 	    }
-	  else if (GET_MODE_SIZE (mode) >= 16)
+	  else if (CONST_WIDE_INT_P (op1)
+		   && GET_MODE_SIZE (mode) >= 16)
 	    {
 	      rtx tmp = ix86_convert_const_wide_int_to_broadcast
 		(GET_MODE (op0), op1);
@@ -696,8 +697,9 @@ ix86_expand_vector_move (machine_mode mode, rtx operands[])
       return;
     }
 
-  /* Special case TImode to V1TImode conversions, via V2DI.  */
-  if (mode == V1TImode
+  /* Special case TImode to 128-bit vector conversions via V2DI.  */
+  if (VECTOR_MODE_P (mode)
+      && GET_MODE_SIZE (mode) == 16
       && SUBREG_P (op1)
       && GET_MODE (SUBREG_REG (op1)) == TImode
       && TARGET_64BIT && TARGET_SSE
@@ -709,7 +711,7 @@ ix86_expand_vector_move (machine_mode mode, rtx operands[])
       emit_move_insn (lo, gen_lowpart (DImode, SUBREG_REG (op1)));
       emit_move_insn (hi, gen_highpart (DImode, SUBREG_REG (op1)));
       emit_insn (gen_vec_concatv2di (tmp, lo, hi));
-      emit_move_insn (op0, gen_lowpart (V1TImode, tmp));
+      emit_move_insn (op0, gen_lowpart (mode, tmp));
       return;
     }
 
diff --git a/gcc/testsuite/gcc.target/i386/sse2-v1ti-mov-2.c b/gcc/testsuite/gcc.target/i386/sse2-v1ti-mov-2.c
new file mode 100644
index 0000000..7e89085
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/sse2-v1ti-mov-2.c
@@ -0,0 +1,16 @@
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-O2 -msse2" } */
+
+typedef unsigned __int128 uv1ti __attribute__ ((__vector_size__ (16)));
+typedef unsigned long uv2di __attribute__ ((__vector_size__ (16)));
+typedef unsigned int uv4si __attribute__ ((__vector_size__ (16)));
+typedef unsigned short uv8hi __attribute__ ((__vector_size__ (16)));
+typedef unsigned char uv16qi __attribute__ ((__vector_size__ (16)));
+
+uv1ti foo1(__int128 x) { return (uv1ti)x; }
+uv2di foo2(__int128 x) { return (uv2di)x; }
+uv4si foo4(__int128 x) { return (uv4si)x; }
+uv8hi foo8(__int128 x) { return (uv8hi)x; }
+uv16qi foo16(__int128 x) { return (uv16qi)x; }
+
+/* { dg-final { scan-assembler-not "%\[er\]sp" } } */

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

* Re: [x86_64 PATCH] Two minor tweaks to ix86_expand_move.
  2023-06-16 16:27 [x86_64 PATCH] Two minor tweaks to ix86_expand_move Roger Sayle
@ 2023-06-17 13:15 ` Uros Bizjak
  0 siblings, 0 replies; 2+ messages in thread
From: Uros Bizjak @ 2023-06-17 13:15 UTC (permalink / raw)
  To: Roger Sayle; +Cc: gcc-patches

On Fri, Jun 16, 2023 at 6:27 PM Roger Sayle <roger@nextmovesoftware.com> wrote:
>
>
> This patch splits out two (independent) minor changes to i386-expand.cc's
> ix86_expand_move from a larger patch, given that it's better to review
> and commit these independent pieces separately from a more complex patch.
>
> The first change is to test for CONST_WIDE_INT_P before calling
> ix86_convert_const_wide_int_to_broadcast.  Whilst stepping through
> this function in gdb, I was surprised that the code was continually
> jumping into this function with operands that obviously weren't
> appropriate.
>
> The second change is to generalize the optimization for efficiently
> moving a TImode value to V1TImode (via V2DImode), to cover all 128-bit
> vector modes.
>
> Hence for the test case:
>
> typedef unsigned long uv2di __attribute__ ((__vector_size__ (16)));
> uv2di foo2(__int128 x) { return (uv2di)x; }
>
> we'd previously move via memory with:
>
> foo2:   movq    %rdi, -24(%rsp)
>         movq    %rsi, -16(%rsp)
>         movdqa  -24(%rsp), %xmm0
>         ret
>
> with this patch we now generate with -O2 (the same as V1TImode):
>
> foo2:   movq    %rdi, %xmm0
>         movq    %rsi, %xmm1
>         punpcklqdq      %xmm1, %xmm0
>         ret
>
> and with -O2 -msse4 the even better:
>
> foo2:   movq    %rdi, %xmm0
>         pinsrq  $1, %rsi, %xmm0
>         ret
>
> The new test case is unimaginatively called sse2-v1ti-mov-2.c given
> the original test case just for V1TI mode was called sse2-v1ti-mov-1.c.
>
> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
> and make -k check, both with and without --target_board=unix{-m32}
> with no new failures.  Ok for mainline?
>
>
> 2023-06-16  Roger Sayle  <roger@nextmovesoftware.com>
>
> gcc/ChangeLog
>         * config/i386/i386-expand.cc (ix86_expand_move): Check that OP1 is
>         CONST_WIDE_INT_P before calling ix86_convert_wide_int_to_broadcast.
>         Generalize special case for converting TImode to V1TImode to handle
>         all 128-bit vector conversions.
>
> gcc/testsuite/ChangeLog
>         * gcc.target/i386/sse2-v1ti-mov-2.c: New test case.

OK.

Thanks,
Uros.

>
> Thanks in advance,
> Roger
> --
>

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

end of thread, other threads:[~2023-06-17 13:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-16 16:27 [x86_64 PATCH] Two minor tweaks to ix86_expand_move Roger Sayle
2023-06-17 13:15 ` Uros Bizjak

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