From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1733) id 17ABD3858CD1; Mon, 19 Feb 2024 14:49:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 17ABD3858CD1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1708354182; bh=1QXhazLA2pWVC1jAL4A0ULYUsYGaUAoZUBnHFhxhtUg=; h=From:To:Subject:Date:From; b=yPrftOa/CTuh8IXxsxjNzUT9gIELsU9GTiYlgPlFnDs/ZQuZ2AAQ4RWGU53uEIpaH tAtfnmSiXP3HLVtzhQ1l/Qd0BD/9fwCfUCqWPSlxCQ4QReNditPXMk+nxuycPBAHrM JwmPNbyi9oSBVXk5CiiXUfO4e2vcKw5XVR1OVHlQ= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Georg-Johann Lay To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/gjl/heads/gcc-8)] rtl-optimization/101188 - Backport from ae193f9008e02683e27f3c87f3b06f38e103b1d0 X-Act-Checkin: gcc X-Git-Author: Georg-Johann Lay X-Git-Refname: refs/users/gjl/heads/gcc-8 X-Git-Oldrev: eafe83f2f20ef0c1e7703c361ba314b44574523c X-Git-Newrev: 071bd78ee13ec34191869168d04b015833a5014f Message-Id: <20240219144942.17ABD3858CD1@sourceware.org> Date: Mon, 19 Feb 2024 14:49:42 +0000 (GMT) List-Id: https://gcc.gnu.org/g:071bd78ee13ec34191869168d04b015833a5014f commit 071bd78ee13ec34191869168d04b015833a5014f Author: Georg-Johann Lay Date: Mon Feb 19 13:31:08 2024 +0100 rtl-optimization/101188 - Backport from ae193f9008e02683e27f3c87f3b06f38e103b1d0 Use reduced version of the PR101188 fix that only handles CLOBBERs. It's not clear how to backport the full fix from Jeff Law. gcc/ PR rtl-optimization/101188 * postreload.c (reload_cse_move2add): Record effect of CLOBBERs. * testsuite/gcc.c-torture/execute/pr101188.c: New test. Diff: --- gcc/ChangeLog | 9 ++++ gcc/postreload.c | 9 ++++ gcc/testsuite/gcc.c-torture/execute/pr101188.c | 60 ++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b9c7f42907b9..b87842429bec 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2024-02-19 Backport from ae193f9008e02683e27f3c87f3b06f38e103b1d0 + + Use reduced version of the PR101188 fix that only handles CLOBBERs. + It's not clear how to backport the full fix from Jeff Law. + + PR rtl-optimization/101188 + * postreload.c (reload_cse_move2add): Record effect of CLOBBERs. + * testsuite/gcc.c-torture/execute/pr101188.c: New test. + 2021-05-14 Release Manager * GCC 8.5.0 released. diff --git a/gcc/postreload.c b/gcc/postreload.c index b97392337e70..51c395c11c12 100644 --- a/gcc/postreload.c +++ b/gcc/postreload.c @@ -40,6 +40,7 @@ along with GCC; see the file COPYING3. If not see #include "cselib.h" #include "tree-pass.h" #include "dbgcnt.h" +#include "rtl-iter.h" static int reload_cse_noop_set_p (rtx); static bool reload_cse_simplify (rtx_insn *, rtx); @@ -2027,6 +2028,14 @@ reload_cse_move2add (rtx_insn *first) if (success) delete_insn (insn); changed |= success; + // By setting "insn = next" below, we are bypassing the + // side-effects of next, see PR101188. Do them by hand + subrtx_iterator::array_type array; + FOR_EACH_SUBRTX (iter, array, PATTERN (next), NONCONST) + { + if (GET_CODE (*iter) == CLOBBER) + move2add_note_store (XEXP (*iter, 0), *iter, next); + } insn = next; move2add_record_mode (reg); reg_offset[regno] diff --git a/gcc/testsuite/gcc.c-torture/execute/pr101188.c b/gcc/testsuite/gcc.c-torture/execute/pr101188.c new file mode 100644 index 000000000000..460149ada492 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr101188.c @@ -0,0 +1,60 @@ +typedef __UINT8_TYPE__ uint8_t; +typedef __UINT16_TYPE__ uint16_t; + +typedef uint8_t (*fn1)(void *a); +typedef void (*fn2)(void *a, int *arg); + +struct S +{ + uint8_t buffer[64]; + uint16_t n; + fn2 f2; + void *a; + fn1 f1; +}; + +volatile uint16_t x; + +void __attribute__((__noinline__,__noclone__)) +foo (uint16_t n) +{ + x = n; +} + +void __attribute__((__noinline__,__noclone__)) +testfn (struct S *self) +{ + int arg; + + foo (self->n); + self->n++; + self->f2 (self->a, &arg); + self->buffer[0] = self->f1 (self->a); +} + +static unsigned char myfn2_called = 0; + +static void +myfn2 (void *a, int *arg) +{ + myfn2_called = 1; +} + +static uint8_t +myfn1 (void *a) +{ + return 0; +} + +int main (void) +{ + struct S s; + s.n = 0; + s.f2 = myfn2; + s.f1 = myfn1; + testfn (&s); + if (myfn2_called != 1) + __builtin_abort(); + return 0; +} +