public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Jeff Law <jeffreyalaw@gmail.com>,
	Eric Botcazou <botcazou@adacore.com>,
	 gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] rtlanal: Fix set_noop_p for volatile loads or stores [PR114768]
Date: Fri, 19 Apr 2024 08:33:42 +0200 (CEST)	[thread overview]
Message-ID: <qnpq0r83-64r3-27p2-qosn-9o0o099pno80@fhfr.qr> (raw)
In-Reply-To: <ZiIOA962zzOBoe87@tucnak>

On Fri, 19 Apr 2024, Jakub Jelinek wrote:

> Hi!
> 
> On the following testcase, combine propagates the mem/v load into mem store
> with the same address and then removes it, because noop_move_p says it is a
> no-op move.  If it was the other way around, i.e. mem/v store and mem load,
> or both would be mem/v, it would be kept.
> The problem is that rtx_equal_p never checks any kind of flags on the rtxes
> (and I think it would be quite dangerous to change it at this point), and
> set_noop_p checks side_effects_p on just one of the operands, not both.
> In the MEM <- MEM set, it only checks it on the destination, in
> store to ZERO_EXTRACT only checks it on the source.
> 
> The following patch adds the missing side_effects_p checks.
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Thanks,
Richard.

> 2024-04-19  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR rtl-optimization/114768
> 	* rtlanal.cc (set_noop_p): Don't return true for MEM <- MEM
> 	sets if src has side-effects or for stores into ZERO_EXTRACT
> 	if ZERO_EXTRACT operand has side-effects.
> 
> 	* gcc.dg/pr114768.c: New test.
> 
> --- gcc/rtlanal.cc.jj	2024-02-24 12:45:28.674249100 +0100
> +++ gcc/rtlanal.cc	2024-04-18 15:09:55.199499083 +0200
> @@ -1637,12 +1637,15 @@ set_noop_p (const_rtx set)
>      return true;
>  
>    if (MEM_P (dst) && MEM_P (src))
> -    return rtx_equal_p (dst, src) && !side_effects_p (dst);
> +    return (rtx_equal_p (dst, src)
> +	    && !side_effects_p (dst)
> +	    && !side_effects_p (src));
>  
>    if (GET_CODE (dst) == ZERO_EXTRACT)
> -    return rtx_equal_p (XEXP (dst, 0), src)
> -	   && !BITS_BIG_ENDIAN && XEXP (dst, 2) == const0_rtx
> -	   && !side_effects_p (src);
> +    return (rtx_equal_p (XEXP (dst, 0), src)
> +	    && !BITS_BIG_ENDIAN && XEXP (dst, 2) == const0_rtx
> +	    && !side_effects_p (src)
> +	    && !side_effects_p (XEXP (dst, 0)));
>  
>    if (GET_CODE (dst) == STRICT_LOW_PART)
>      dst = XEXP (dst, 0);
> --- gcc/testsuite/gcc.dg/pr114768.c.jj	2024-04-18 15:37:49.139433678 +0200
> +++ gcc/testsuite/gcc.dg/pr114768.c	2024-04-18 15:43:30.389730365 +0200
> @@ -0,0 +1,10 @@
> +/* PR rtl-optimization/114768 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-rtl-final" } */
> +/* { dg-final { scan-rtl-dump "\\\(mem/v:" "final" { target { ! { nvptx*-*-* } } } } } */
> +
> +void
> +foo (int *p)
> +{
> +  *p = *(volatile int *) p;
> +}
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

  reply	other threads:[~2024-04-19  6:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-19  6:24 Jakub Jelinek
2024-04-19  6:33 ` Richard Biener [this message]
2024-04-19 10:23 ` Thomas Schwinge
2024-04-19 10:30   ` Jakub Jelinek
2024-04-19 10:39     ` Enable 'gcc.dg/pr114768.c' for nvptx target [PR114768] (was: [PATCH] rtlanal: Fix set_noop_p for volatile loads or stores [PR114768]) Thomas Schwinge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=qnpq0r83-64r3-27p2-qosn-9o0o099pno80@fhfr.qr \
    --to=rguenther@suse.de \
    --cc=botcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jeffreyalaw@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).