public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexander Monakov <amonakov@ispras.ru>
To: gcc-patches@gcc.gnu.org
Cc: Alexander Monakov <amonakov@ispras.ru>,
	Richard Biener <richard.guenther@gmail.com>
Subject: [PATCH 1/3] tree-ssa-sink: do not sink to in front of setjmp
Date: Fri, 14 Jan 2022 21:20:45 +0300	[thread overview]
Message-ID: <20220114182047.6270-2-amonakov@ispras.ru> (raw)
In-Reply-To: <CAFiYyc3h+fNQ4KdyRWBeVM=NESqSWbbJNB8iGctx_UZ5BVVyfA@mail.gmail.com>

gcc/ChangeLog:

	* tree-ssa-sink.c (select_best_block): Punt if selected block
	has incoming abnormal edges.

gcc/testsuite/ChangeLog:

	* gcc.dg/setjmp-7.c: New test.
---
 gcc/testsuite/gcc.dg/setjmp-7.c | 13 +++++++++++++
 gcc/tree-ssa-sink.c             |  6 ++++++
 2 files changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/setjmp-7.c

diff --git a/gcc/testsuite/gcc.dg/setjmp-7.c b/gcc/testsuite/gcc.dg/setjmp-7.c
new file mode 100644
index 000000000..44b5bcbfa
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/setjmp-7.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-guess-branch-probability -w" } */
+/* { dg-require-effective-target indirect_jumps } */
+
+struct __jmp_buf_tag { };
+typedef struct __jmp_buf_tag jmp_buf[1];
+struct globals { jmp_buf listingbuf; };
+extern struct globals *const ptr_to_globals;
+void foo()
+{
+    if ( _setjmp ( ((*ptr_to_globals).listingbuf )))
+	;
+}
diff --git a/gcc/tree-ssa-sink.c b/gcc/tree-ssa-sink.c
index 66d7ae89e..016ecbaec 100644
--- a/gcc/tree-ssa-sink.c
+++ b/gcc/tree-ssa-sink.c
@@ -208,6 +208,12 @@ select_best_block (basic_block early_bb,
       temp_bb = get_immediate_dominator (CDI_DOMINATORS, temp_bb);
     }
 
+  /* Placing a statement before a setjmp-like function would be invalid
+     (it cannot be reevaluated when execution follows an abnormal edge).
+     If we selected a block with abnormal predecessors, just punt.  */
+  if (bb_has_abnormal_pred (best_bb))
+    return early_bb;
+
   /* If we found a shallower loop nest, then we always consider that
      a win.  This will always give us the most control dependent block
      within that loop nest.  */
-- 
2.33.1


  parent reply	other threads:[~2022-01-14 18:21 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-13 14:25 [RFC PATCH] " Alexander Monakov
2021-12-13 14:45 ` Richard Biener
2021-12-13 15:20   ` Alexander Monakov
2021-12-14 11:10     ` Алексей Нурмухаметов
2022-01-03 13:41       ` Richard Biener
2022-01-03 16:35         ` Alexander Monakov
2022-01-04  7:25           ` Richard Biener
2022-01-14 18:20             ` Alexander Monakov
2022-01-14 18:20             ` Alexander Monakov [this message]
2022-01-17  7:47               ` [PATCH 1/3] " Richard Biener
2023-11-08  9:04               ` Florian Weimer
2023-11-08 10:01                 ` Richard Biener
2023-11-08 13:06                   ` Alexander Monakov
2022-01-14 18:20             ` [PATCH 2/3] tree-cfg: do not duplicate returns_twice calls Alexander Monakov
2022-01-17  8:08               ` Richard Biener
2022-07-12 20:10                 ` Alexander Monakov
2022-07-13  7:13                   ` Richard Biener
2022-07-13 14:57                     ` Alexander Monakov
2022-07-14  6:38                       ` Richard Biener
2022-07-14 20:12                         ` Alexander Monakov
2022-07-19  8:40                           ` Richard Biener
2022-07-19 20:00                             ` Alexander Monakov
2022-07-13 16:01                     ` Jeff Law
2022-01-14 18:20             ` [PATCH 3/3] tree-cfg: check placement of " Alexander Monakov
2022-01-17  8:12               ` Richard Biener

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=20220114182047.6270-2-amonakov@ispras.ru \
    --to=amonakov@ispras.ru \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@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).