From patchwork Fri Jan 14 18:20:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 50046 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1CD7B383642A for ; Fri, 14 Jan 2022 18:22:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1CD7B383642A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642184562; bh=55WRQVxc6JG2K/GOzBM8QIM6BxPw65bqHIx/AJsqgPU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=JVjIzwZ8zDIcNLPG466QZrdIvZM2zjqQ4rWIGycw29/z1OPGEaMf/4YrmnCWMWJFG 3VWwQWfR06ecY/pYl2KNd6BFA8DLKfF8ht6M6jKDDOhKLWgrLt385GsXeKSdMG2Cf7 RztYfHerTpV6t1OKjjALkans0u5U+ILpkjlWdK1M= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id E330C3836419 for ; Fri, 14 Jan 2022 18:21:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E330C3836419 Received: from localhost.intra.ispras.ru (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTP id DB26840D403D; Fri, 14 Jan 2022 18:21:21 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/3] tree-ssa-sink: do not sink to in front of setjmp Date: Fri, 14 Jan 2022 21:20:45 +0300 Message-Id: <20220114182047.6270-2-amonakov@ispras.ru> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alexander Monakov via Gcc-patches From: Alexander Monakov Reply-To: Alexander Monakov Cc: Alexander Monakov Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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. */ From patchwork Fri Jan 14 18:20:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 50047 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E1D8F383600D for ; Fri, 14 Jan 2022 18:23:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1D8F383600D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642184618; bh=rlgg127iei3SQ5a5KH+7ewPKJJu8U9Tmjc4W7S7F6/E=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=VukF0kt3I+W/Slic7PhkaHZyrSQxHY35fyJXyhbg79pyAZ0dsF+J+wqC34ipYWq5V 4o/aso6HyQ7z4Q3BQcaJ+Zyua1QfvKsTyIttQWTDLEB8RFhnBJbpzraQlUDNOQ6a1S T1UDXl8L94tcSLmkc7Ocdpj9p6FJ1yobKLoMn550= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id 280FB385ED4A for ; Fri, 14 Jan 2022 18:21:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 280FB385ED4A Received: from localhost.intra.ispras.ru (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTP id 21E6840755FA; Fri, 14 Jan 2022 18:21:24 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/3] tree-cfg: do not duplicate returns_twice calls Date: Fri, 14 Jan 2022 21:20:46 +0300 Message-Id: <20220114182047.6270-3-amonakov@ispras.ru> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alexander Monakov via Gcc-patches From: Alexander Monakov Reply-To: Alexander Monakov Cc: Alexander Monakov Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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: * tree-cfg.c (gimple_can_duplicate_bb_p): Reject blocks with calls that may return twice. --- gcc/tree-cfg.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index b7fe313b7..a99f1acb4 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -6304,12 +6304,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) From patchwork Fri Jan 14 18:20:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 50048 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 621DF3850429 for ; Fri, 14 Jan 2022 18:24:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 621DF3850429 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642184675; bh=qEPCxTR4YxG/9HFfiGcGSSuNWUcvU58bWQ9WqXCbGdI=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=P8Neo/Fct3SFDQKSZCUle+izbAZ8VkAJT09mQt9XtkA5+U2++ZqI3I4dCBPfTcAr+ hAcx8mY8LmQGXwQ7KLbeoJJ74N8+31WtSndSyms84KXFgSRzdTKZy3FzbcD8iOF1jG TcO+otEWhhiu4LZhqR5cWrX38H6fOgJW8UiiKRKU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id EEAA23836015 for ; Fri, 14 Jan 2022 18:21:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EEAA23836015 Received: from localhost.intra.ispras.ru (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTP id D88C240D403D; Fri, 14 Jan 2022 18:21:24 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH 3/3] tree-cfg: check placement of returns_twice calls Date: Fri, 14 Jan 2022 21:20:47 +0300 Message-Id: <20220114182047.6270-4-amonakov@ispras.ru> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alexander Monakov via Gcc-patches From: Alexander Monakov Reply-To: Alexander Monakov Cc: Alexander Monakov Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When a returns_twice call has an associated abnormal edge, the edge corresponds to the "second return" from the call. It wouldn't make sense if any executable statements appeared between the call and the destination of the edge (they wouldn't be re-executed upon the "second return"), so verify that. gcc/ChangeLog: * tree-cfg.c (gimple_verify_flow_info): Check placement of returns_twice calls. --- gcc/tree-cfg.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index a99f1acb4..70bd31d3d 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -5644,6 +5644,7 @@ gimple_verify_flow_info (void) } /* Verify that body of basic block BB is free of control flow. */ + bool seen_nondebug_stmt = false; for (; !gsi_end_p (gsi); gsi_next (&gsi)) { gimple *stmt = gsi_stmt (gsi); @@ -5664,6 +5665,38 @@ gimple_verify_flow_info (void) gimple_label_label (label_stmt), bb->index); err = 1; } + + /* Check that no statements appear between a returns_twice call + and its associated abnormal edge. */ + if (gimple_code (stmt) == GIMPLE_CALL + && gimple_call_flags (stmt) & ECF_RETURNS_TWICE) + { + const char *misplaced = NULL; + /* TM is an exception: it points abnormal edges just after the + call that starts a transaction, i.e. it must end the BB. */ + if (gimple_call_builtin_p (stmt, BUILT_IN_TM_START)) + { + if (single_succ_p (bb) + && bb_has_abnormal_pred (single_succ (bb)) + && !gsi_one_nondebug_before_end_p (gsi)) + misplaced = "not last"; + } + else + { + if (seen_nondebug_stmt + && bb_has_abnormal_pred (bb)) + misplaced = "not first"; + } + if (misplaced) + { + error ("returns_twice call is %s in basic block %d", + misplaced, bb->index); + print_gimple_stmt (stderr, stmt, 0, TDF_SLIM); + err = 1; + } + } + if (!is_gimple_debug (stmt)) + seen_nondebug_stmt = true; } gsi = gsi_last_nondebug_bb (bb);