From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 1E5093864830; Fri, 19 Apr 2024 06:48:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E5093864830 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713509308; bh=hFUfrXFftVuyPSEYGyukr77r7scA4qDzV8XYQW27dVk=; h=From:To:Subject:Date:From; b=cu+qiAVkmcomnt5Qv3ZDPG6SquhUoqLDv+AiWnC/Vny6jvALUe3e/XOESW+Ugsijf oKabSDPyai8BdJwdSqx/QizMntplunDOuwM/6o5b1t32x9q91vCJTWKDNjfQvJDu4l 8OKJovJZ5apcEQoFDcqxnS0Bl03LGv81gUMtdqJs= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-10035] rtlanal: Fix set_noop_p for volatile loads or stores [PR114768] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 36f4c8a9ac8f71fc21fcb169c7913e8fef30d15c X-Git-Newrev: 9f295847a9c32081bdd0fe908ffba58e830a24fb Message-Id: <20240419064828.1E5093864830@sourceware.org> Date: Fri, 19 Apr 2024 06:48:28 +0000 (GMT) List-Id: https://gcc.gnu.org/g:9f295847a9c32081bdd0fe908ffba58e830a24fb commit r14-10035-g9f295847a9c32081bdd0fe908ffba58e830a24fb Author: Jakub Jelinek Date: Fri Apr 19 08:47:53 2024 +0200 rtlanal: Fix set_noop_p for volatile loads or stores [PR114768] 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. 2024-04-19 Jakub Jelinek 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. Diff: --- gcc/rtlanal.cc | 11 +++++++---- gcc/testsuite/gcc.dg/pr114768.c | 10 ++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc index d38455bc559..4158a531bdd 100644 --- a/gcc/rtlanal.cc +++ b/gcc/rtlanal.cc @@ -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); diff --git a/gcc/testsuite/gcc.dg/pr114768.c b/gcc/testsuite/gcc.dg/pr114768.c new file mode 100644 index 00000000000..2075f0d6b82 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr114768.c @@ -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; +}