diff mbox series

store-merging: Match bswap64 on 32-bit targets with bswapsi2 [PR114319]

Message ID ZfF/NB1cbzey5Our@tucnak
State New
Headers show
Series store-merging: Match bswap64 on 32-bit targets with bswapsi2 [PR114319] | expand

Commit Message

Jakub Jelinek March 13, 2024, 10:25 a.m. UTC
Hi!

gimple-ssa-store-merging.cc tests bswap_optab in 3 different places,
in 2 of them it has special exception for double-word bswap using pair
of word-mode bswap optabs, but in the last one it doesn't.

The following patch changes even the last spot.
We don't handle 128-bit bswaps in the passes at all, because currently we
just use uint64_t to represent the byte reshuffling (we'd need to use
offset_int or something like that instead) and we don't have
__builtin_bswap128 nor type-generic __builtin_bswap, so there is nothing
for 64-bit targets there.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2024-03-13  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/114319
	* gimple-ssa-store-merging.cc
	(imm_store_chain_info::try_coalesce_bswap): For 32-bit targets
	allow matching __builtin_bswap64 if there is bswapsi2 optab.

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


	Jakub

Comments

Richard Biener March 13, 2024, 12:08 p.m. UTC | #1
On Wed, 13 Mar 2024, Jakub Jelinek wrote:

> Hi!
> 
> gimple-ssa-store-merging.cc tests bswap_optab in 3 different places,
> in 2 of them it has special exception for double-word bswap using pair
> of word-mode bswap optabs, but in the last one it doesn't.
> 
> The following patch changes even the last spot.
> We don't handle 128-bit bswaps in the passes at all, because currently we
> just use uint64_t to represent the byte reshuffling (we'd need to use
> offset_int or something like that instead) and we don't have
> __builtin_bswap128 nor type-generic __builtin_bswap, so there is nothing
> for 64-bit targets there.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Thanks,
Richard.

> 2024-03-13  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR middle-end/114319
> 	* gimple-ssa-store-merging.cc
> 	(imm_store_chain_info::try_coalesce_bswap): For 32-bit targets
> 	allow matching __builtin_bswap64 if there is bswapsi2 optab.
> 
> 	* gcc.target/i386/pr114319.c: New test.
> 
> --- gcc/gimple-ssa-store-merging.cc.jj	2024-01-03 11:51:29.449760086 +0100
> +++ gcc/gimple-ssa-store-merging.cc	2024-03-12 23:51:30.740236577 +0100
> @@ -3051,7 +3051,10 @@ imm_store_chain_info::try_coalesce_bswap
>  	return false;
>        case 64:
>  	if (builtin_decl_explicit_p (BUILT_IN_BSWAP64)
> -	    && optab_handler (bswap_optab, DImode) != CODE_FOR_nothing)
> +	    && (optab_handler (bswap_optab, DImode) != CODE_FOR_nothing
> +		|| (word_mode == SImode
> +		    && builtin_decl_explicit_p (BUILT_IN_BSWAP32)
> +		    && optab_handler (bswap_optab, SImode) != CODE_FOR_nothing)))
>  	  break;
>  	return false;
>        default:
> --- gcc/testsuite/gcc.target/i386/pr114319.c.jj	2024-03-13 10:59:57.378404934 +0100
> +++ gcc/testsuite/gcc.target/i386/pr114319.c	2024-03-13 10:59:46.612554118 +0100
> @@ -0,0 +1,19 @@
> +/* PR middle-end/114319 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -masm=att -mno-movbe" } */
> +/* { dg-additional-options "-march=i486" { target ia32 } } */
> +/* { dg-final { scan-assembler-times "\tbswap\t%r" 1 { target { ! ia32 } } } } */
> +/* { dg-final { scan-assembler-times "\tbswap\t%\[er]" 2 { target ia32 } } } */
> +
> +void
> +foo (unsigned long long x, unsigned char *y)
> +{
> +  y[0] = x >> 56;
> +  y[1] = x >> 48;
> +  y[2] = x >> 40;
> +  y[3] = x >> 32;
> +  y[4] = x >> 24;
> +  y[5] = x >> 16;
> +  y[6] = x >> 8;
> +  y[7] = x;
> +}
> 
> 	Jakub
> 
>
diff mbox series

Patch

--- gcc/gimple-ssa-store-merging.cc.jj	2024-01-03 11:51:29.449760086 +0100
+++ gcc/gimple-ssa-store-merging.cc	2024-03-12 23:51:30.740236577 +0100
@@ -3051,7 +3051,10 @@  imm_store_chain_info::try_coalesce_bswap
 	return false;
       case 64:
 	if (builtin_decl_explicit_p (BUILT_IN_BSWAP64)
-	    && optab_handler (bswap_optab, DImode) != CODE_FOR_nothing)
+	    && (optab_handler (bswap_optab, DImode) != CODE_FOR_nothing
+		|| (word_mode == SImode
+		    && builtin_decl_explicit_p (BUILT_IN_BSWAP32)
+		    && optab_handler (bswap_optab, SImode) != CODE_FOR_nothing)))
 	  break;
 	return false;
       default:
--- gcc/testsuite/gcc.target/i386/pr114319.c.jj	2024-03-13 10:59:57.378404934 +0100
+++ gcc/testsuite/gcc.target/i386/pr114319.c	2024-03-13 10:59:46.612554118 +0100
@@ -0,0 +1,19 @@ 
+/* PR middle-end/114319 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -masm=att -mno-movbe" } */
+/* { dg-additional-options "-march=i486" { target ia32 } } */
+/* { dg-final { scan-assembler-times "\tbswap\t%r" 1 { target { ! ia32 } } } } */
+/* { dg-final { scan-assembler-times "\tbswap\t%\[er]" 2 { target ia32 } } } */
+
+void
+foo (unsigned long long x, unsigned char *y)
+{
+  y[0] = x >> 56;
+  y[1] = x >> 48;
+  y[2] = x >> 40;
+  y[3] = x >> 32;
+  y[4] = x >> 24;
+  y[5] = x >> 16;
+  y[6] = x >> 8;
+  y[7] = x;
+}