public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] target/102125 - alternative memcpy folding improvement
@ 2022-03-23 14:57 Richard Biener
  2022-03-30 14:55 ` Richard Earnshaw
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2022-03-23 14:57 UTC (permalink / raw)
  To: gcc-patches; +Cc: richard.earnshaw

The following extends the heuristical memcpy folding path with the
ability to use misaligned accesses on strict-alignment targets just
like the size-based path does.  That avoids regressing the following
testcase on arm

    uint64_t bar64(const uint8_t *rData1)
    {
        uint64_t buffer;
        memcpy(&buffer, rData1, sizeof(buffer));
        return buffer;
    }

when r12-3482-g5f6a6c91d7c592 is reverted.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to trunk.

OK to revert r12-3482-g5f6a6c91d7c592?

Thanks,
Richard.

2022-03-23  Richard Biener  <rguenther@suse.de>

	PR target/102125
	* gimple-fold.cc (gimple_fold_builtin_memory_op): Allow the
	use of movmisalign when either the source or destination
	decl is properly aligned.
---
 gcc/gimple-fold.cc | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index c9179abb27e..5eff7d68ac1 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -1254,7 +1254,11 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
 	    srcvar = fold_build2 (MEM_REF, desttype, src, off0);
 	  else
 	    {
-	      if (STRICT_ALIGNMENT)
+	      enum machine_mode mode = TYPE_MODE (desttype);
+	      if ((mode == BLKmode && STRICT_ALIGNMENT)
+		  || (targetm.slow_unaligned_access (mode, src_align)
+		      && (optab_handler (movmisalign_optab, mode)
+			  == CODE_FOR_nothing)))
 		return false;
 	      srctype = build_aligned_type (TYPE_MAIN_VARIANT (desttype),
 					    src_align);
@@ -1267,7 +1271,11 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
 	    destvar = fold_build2 (MEM_REF, srctype, dest, off0);
 	  else
 	    {
-	      if (STRICT_ALIGNMENT)
+	      enum machine_mode mode = TYPE_MODE (srctype);
+	      if ((mode == BLKmode && STRICT_ALIGNMENT)
+		  || (targetm.slow_unaligned_access (mode, dest_align)
+		      && (optab_handler (movmisalign_optab, mode)
+			  == CODE_FOR_nothing)))
 		return false;
 	      desttype = build_aligned_type (TYPE_MAIN_VARIANT (srctype),
 					     dest_align);
-- 
2.34.1

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

* Re: [PATCH] target/102125 - alternative memcpy folding improvement
  2022-03-23 14:57 [PATCH] target/102125 - alternative memcpy folding improvement Richard Biener
@ 2022-03-30 14:55 ` Richard Earnshaw
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Earnshaw @ 2022-03-30 14:55 UTC (permalink / raw)
  To: Richard Biener, gcc-patches; +Cc: richard.earnshaw



On 23/03/2022 14:57, Richard Biener via Gcc-patches wrote:
> The following extends the heuristical memcpy folding path with the
> ability to use misaligned accesses on strict-alignment targets just
> like the size-based path does.  That avoids regressing the following
> testcase on arm
> 
>      uint64_t bar64(const uint8_t *rData1)
>      {
>          uint64_t buffer;
>          memcpy(&buffer, rData1, sizeof(buffer));
>          return buffer;
>      }
> 
> when r12-3482-g5f6a6c91d7c592 is reverted.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to trunk.
> 
> OK to revert r12-3482-g5f6a6c91d7c592?

Yes, go ahead.

R.

> 
> Thanks,
> Richard.
> 
> 2022-03-23  Richard Biener  <rguenther@suse.de>
> 
> 	PR target/102125
> 	* gimple-fold.cc (gimple_fold_builtin_memory_op): Allow the
> 	use of movmisalign when either the source or destination
> 	decl is properly aligned.
> ---
>   gcc/gimple-fold.cc | 12 ++++++++++--
>   1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
> index c9179abb27e..5eff7d68ac1 100644
> --- a/gcc/gimple-fold.cc
> +++ b/gcc/gimple-fold.cc
> @@ -1254,7 +1254,11 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
>   	    srcvar = fold_build2 (MEM_REF, desttype, src, off0);
>   	  else
>   	    {
> -	      if (STRICT_ALIGNMENT)
> +	      enum machine_mode mode = TYPE_MODE (desttype);
> +	      if ((mode == BLKmode && STRICT_ALIGNMENT)
> +		  || (targetm.slow_unaligned_access (mode, src_align)
> +		      && (optab_handler (movmisalign_optab, mode)
> +			  == CODE_FOR_nothing)))
>   		return false;
>   	      srctype = build_aligned_type (TYPE_MAIN_VARIANT (desttype),
>   					    src_align);
> @@ -1267,7 +1271,11 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
>   	    destvar = fold_build2 (MEM_REF, srctype, dest, off0);
>   	  else
>   	    {
> -	      if (STRICT_ALIGNMENT)
> +	      enum machine_mode mode = TYPE_MODE (srctype);
> +	      if ((mode == BLKmode && STRICT_ALIGNMENT)
> +		  || (targetm.slow_unaligned_access (mode, dest_align)
> +		      && (optab_handler (movmisalign_optab, mode)
> +			  == CODE_FOR_nothing)))
>   		return false;
>   	      desttype = build_aligned_type (TYPE_MAIN_VARIANT (srctype),
>   					     dest_align);

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

* Re: [PATCH] target/102125 - alternative memcpy folding improvement
@ 2022-03-28  8:52 Richard Biener
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-03-28  8:52 UTC (permalink / raw)
  To: gcc-patches; +Cc: richard.earnshaw

On Wed, 23 Mar 2022, Richard Biener wrote:

> The following extends the heuristical memcpy folding path with the
> ability to use misaligned accesses on strict-alignment targets just
> like the size-based path does.  That avoids regressing the following
> testcase on arm
> 
>     uint64_t bar64(const uint8_t *rData1)
>     {
>         uint64_t buffer;
>         memcpy(&buffer, rData1, sizeof(buffer));
>         return buffer;
>     }
> 
> when r12-3482-g5f6a6c91d7c592 is reverted.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to trunk.
> 
> OK to revert r12-3482-g5f6a6c91d7c592?

Richard E. - ping?  May I revert your r12-3482-g5f6a6c91d7c592 now to fix
the P1 PR103393?

Thanks,
Richard.


> Thanks,
> Richard.
> 
> 2022-03-23  Richard Biener  <rguenther@suse.de>
> 
> 	PR target/102125
> 	* gimple-fold.cc (gimple_fold_builtin_memory_op): Allow the
> 	use of movmisalign when either the source or destination
> 	decl is properly aligned.
> ---
>  gcc/gimple-fold.cc | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
> index c9179abb27e..5eff7d68ac1 100644
> --- a/gcc/gimple-fold.cc
> +++ b/gcc/gimple-fold.cc
> @@ -1254,7 +1254,11 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
>  	    srcvar = fold_build2 (MEM_REF, desttype, src, off0);
>  	  else
>  	    {
> -	      if (STRICT_ALIGNMENT)
> +	      enum machine_mode mode = TYPE_MODE (desttype);
> +	      if ((mode == BLKmode && STRICT_ALIGNMENT)
> +		  || (targetm.slow_unaligned_access (mode, src_align)
> +		      && (optab_handler (movmisalign_optab, mode)
> +			  == CODE_FOR_nothing)))
>  		return false;
>  	      srctype = build_aligned_type (TYPE_MAIN_VARIANT (desttype),
>  					    src_align);
> @@ -1267,7 +1271,11 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
>  	    destvar = fold_build2 (MEM_REF, srctype, dest, off0);
>  	  else
>  	    {
> -	      if (STRICT_ALIGNMENT)
> +	      enum machine_mode mode = TYPE_MODE (srctype);
> +	      if ((mode == BLKmode && STRICT_ALIGNMENT)
> +		  || (targetm.slow_unaligned_access (mode, dest_align)
> +		      && (optab_handler (movmisalign_optab, mode)
> +			  == CODE_FOR_nothing)))
>  		return false;
>  	      desttype = build_aligned_type (TYPE_MAIN_VARIANT (srctype),
>  					     dest_align);
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Ivo Totev; HRB 36809 (AG Nuernberg)

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

end of thread, other threads:[~2022-03-30 14:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-23 14:57 [PATCH] target/102125 - alternative memcpy folding improvement Richard Biener
2022-03-30 14:55 ` Richard Earnshaw
2022-03-28  8:52 Richard Biener

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