public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Georg-Johann Lay <gjl@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/gjl/heads/gcc-8)] rtl-optimization/101188 - Backport from ae193f9008e02683e27f3c87f3b06f38e103b1d0
Date: Mon, 19 Feb 2024 14:36:41 +0000 (GMT)	[thread overview]
Message-ID: <20240219143641.359953858005@sourceware.org> (raw)

https://gcc.gnu.org/g:900efd5c53f2738cfd136c70a32b26d182354f11

commit 900efd5c53f2738cfd136c70a32b26d182354f11
Author: Georg-Johann Lay <avr@gjlay.de>
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;
+}
+

             reply	other threads:[~2024-02-19 14:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-19 14:36 Georg-Johann Lay [this message]
2024-02-19 14:49 Georg-Johann Lay

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=20240219143641.359953858005@sourceware.org \
    --to=gjl@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).