public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-1753] tree-cfg: do not duplicate returns_twice calls
@ 2022-07-19 14:16 Alexander Monakov
  0 siblings, 0 replies; only message in thread
From: Alexander Monakov @ 2022-07-19 14:16 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:26cea5f108e0facdb080e385000bb141b086845f

commit r13-1753-g26cea5f108e0facdb080e385000bb141b086845f
Author: Alexander Monakov <amonakov@ispras.ru>
Date:   Fri Jan 14 20:51:12 2022 +0300

    tree-cfg: do not duplicate returns_twice calls
    
    A returns_twice call may have associated abnormal edges that correspond
    to the "second return" from the call. If the call is duplicated, the
    copies of those edges also need to be abnormal, but e.g. tracer does not
    enforce that. Just prohibit the (unlikely to be useful) duplication.
    
    gcc/ChangeLog:
    
            * cfghooks.cc (duplicate_block): Expand comment.
            * tree-cfg.cc (gimple_can_duplicate_bb_p): Reject blocks with
            calls that may return twice.

Diff:
---
 gcc/cfghooks.cc | 13 ++++++++++---
 gcc/tree-cfg.cc |  7 +++++--
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/gcc/cfghooks.cc b/gcc/cfghooks.cc
index e435891fac6..c6ac9532cb8 100644
--- a/gcc/cfghooks.cc
+++ b/gcc/cfghooks.cc
@@ -1086,9 +1086,16 @@ can_duplicate_block_p (const_basic_block bb)
   return cfg_hooks->can_duplicate_block_p (bb);
 }
 
-/* Duplicates basic block BB and redirects edge E to it.  Returns the
-   new basic block.  The new basic block is placed after the basic block
-   AFTER.  */
+/* Duplicate basic block BB, place it after AFTER (if non-null) and redirect
+   edge E to it (if non-null).  Return the new basic block.
+
+   If BB contains a returns_twice call, the caller is responsible for recreating
+   incoming abnormal edges corresponding to the "second return" for the copy.
+   gimple_can_duplicate_bb_p rejects such blocks, while RTL likes to live
+   dangerously.
+
+   If BB has incoming abnormal edges for some other reason, their destinations
+   should be tied to label(s) of the original BB and not the copy.  */
 
 basic_block
 duplicate_block (basic_block bb, edge e, basic_block after, copy_bb_data *id)
diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index bfcb1425f7e..a365aad678f 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -6313,12 +6313,15 @@ gimple_can_duplicate_bb_p (const_basic_block bb)
     {
       gimple *g = gsi_stmt (gsi);
 
-      /* An IFN_GOMP_SIMT_ENTER_ALLOC/IFN_GOMP_SIMT_EXIT call must be
+      /* Prohibit duplication of returns_twice calls, otherwise associated
+	 abnormal edges also need to be duplicated properly.
+	 An IFN_GOMP_SIMT_ENTER_ALLOC/IFN_GOMP_SIMT_EXIT call must be
 	 duplicated as part of its group, or not at all.
 	 The IFN_GOMP_SIMT_VOTE_ANY and IFN_GOMP_SIMT_XCHG_* are part of such a
 	 group, so the same holds there.  */
       if (is_gimple_call (g)
-	  && (gimple_call_internal_p (g, IFN_GOMP_SIMT_ENTER_ALLOC)
+	  && (gimple_call_flags (g) & ECF_RETURNS_TWICE
+	      || gimple_call_internal_p (g, IFN_GOMP_SIMT_ENTER_ALLOC)
 	      || gimple_call_internal_p (g, IFN_GOMP_SIMT_EXIT)
 	      || gimple_call_internal_p (g, IFN_GOMP_SIMT_VOTE_ANY)
 	      || gimple_call_internal_p (g, IFN_GOMP_SIMT_XCHG_BFLY)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-07-19 14:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19 14:16 [gcc r13-1753] tree-cfg: do not duplicate returns_twice calls Alexander Monakov

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).