From patchwork Thu May 28 12:06:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1299736 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Xn2M1j40z9sSF for ; Thu, 28 May 2020 22:24:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1DDFD397A48D; Thu, 28 May 2020 12:24:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 0A612395A836 for ; Thu, 28 May 2020 12:24:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0A612395A836 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mjambor@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 97DDFAC7F for ; Thu, 28 May 2020 12:24:32 +0000 (UTC) Resent-From: Martin Jambor Resent-Date: Thu, 28 May 2020 14:24:32 +0200 Resent-Message-ID: <20200528122432.GB22804@alvy> Resent-To: GCC Patches Message-Id: <4450ddf43c03fafd4e527094a72c3c0d106f35c3.1590667594.git.mjambor@suse.cz> In-Reply-To: References: From: Martin Jambor Date: Thu, 28 May 2020 14:06:35 +0200 Subject: [PATCH 1/4] ipa-sra: Do not remove statements necessary because of non-call EH (PR 95113) To: GCC Patches X-Spam-Status: No, score=-3043.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Cc: Richard Biener , Jan Hubicka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" PR 95113 revealed that when reasoning about which parameters are dead, IPA-SRA does not perform the same check related to non-call exceptions as tree DCE. It most certainly should and so this patch moves the condition used in tree-ssa-dce.c into a separate predicate (in tree-eh.c) and uses it from both places. gcc/ChangeLog: 2020-05-27 Martin Jambor PR ipa/95113 * gcc/tree-ssa-dce.c (mark_stmt_if_obviously_necessary): Move non-call exceptions check to... * gcc/tree-eh.c (stmt_unremovable_because_of_non_call_eh_p): ...this new function. * gcc/tree-eh.h (stmt_unremovable_because_of_non_call_eh_p): Declare it. * gcc/ipa-sra.c (isra_track_scalar_value_uses): Use it. New parameter fun. gcc/testsuite/ChangeLog: 2020-05-27 Martin Jambor PR ipa/95113 * gcc.dg/ipa/pr95113.c: New test. --- gcc/ipa-sra.c | 28 +++++++++++++------------ gcc/testsuite/gcc.dg/ipa/pr95113.c | 33 ++++++++++++++++++++++++++++++ gcc/tree-eh.c | 10 +++++++++ gcc/tree-eh.h | 1 + gcc/tree-ssa-dce.c | 4 +--- 5 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr95113.c diff --git a/gcc/ipa-sra.c b/gcc/ipa-sra.c index 7c922e40a4e..c81e8869e7a 100644 --- a/gcc/ipa-sra.c +++ b/gcc/ipa-sra.c @@ -795,17 +795,17 @@ get_single_param_flow_source (const isra_param_flow *param_flow) } /* Inspect all uses of NAME and simple arithmetic calculations involving NAME - in NODE and return a negative number if any of them is used for something - else than either an actual call argument, simple arithmetic operation or - debug statement. If there are no such uses, return the number of actual - arguments that this parameter eventually feeds to (or zero if there is none). - For any such parameter, mark PARM_NUM as one of its sources. ANALYZED is a - bitmap that tracks which SSA names we have already started - investigating. */ + in FUN represented with NODE and return a negative number if any of them is + used for something else than either an actual call argument, simple + arithmetic operation or debug statement. If there are no such uses, return + the number of actual arguments that this parameter eventually feeds to (or + zero if there is none). For any such parameter, mark PARM_NUM as one of its + sources. ANALYZED is a bitmap that tracks which SSA names we have already + started investigating. */ static int -isra_track_scalar_value_uses (cgraph_node *node, tree name, int parm_num, - bitmap analyzed) +isra_track_scalar_value_uses (function *fun, cgraph_node *node, tree name, + int parm_num, bitmap analyzed) { int res = 0; imm_use_iterator imm_iter; @@ -859,8 +859,9 @@ isra_track_scalar_value_uses (cgraph_node *node, tree name, int parm_num, } res += all_uses; } - else if ((is_gimple_assign (stmt) && !gimple_has_volatile_ops (stmt)) - || gimple_code (stmt) == GIMPLE_PHI) + else if (!stmt_unremovable_because_of_non_call_eh_p (fun, stmt) + && ((is_gimple_assign (stmt) && !gimple_has_volatile_ops (stmt)) + || gimple_code (stmt) == GIMPLE_PHI)) { tree lhs; if (gimple_code (stmt) == GIMPLE_PHI) @@ -876,7 +877,7 @@ isra_track_scalar_value_uses (cgraph_node *node, tree name, int parm_num, gcc_assert (!gimple_vdef (stmt)); if (bitmap_set_bit (analyzed, SSA_NAME_VERSION (lhs))) { - int tmp = isra_track_scalar_value_uses (node, lhs, parm_num, + int tmp = isra_track_scalar_value_uses (fun, node, lhs, parm_num, analyzed); if (tmp < 0) { @@ -927,7 +928,8 @@ isra_track_scalar_param_local_uses (function *fun, cgraph_node *node, tree parm, return true; bitmap analyzed = BITMAP_ALLOC (NULL); - int call_uses = isra_track_scalar_value_uses (node, name, parm_num, analyzed); + int call_uses = isra_track_scalar_value_uses (fun, node, name, parm_num, + analyzed); BITMAP_FREE (analyzed); if (call_uses < 0) return true; diff --git a/gcc/testsuite/gcc.dg/ipa/pr95113.c b/gcc/testsuite/gcc.dg/ipa/pr95113.c new file mode 100644 index 00000000000..a8f8c901ebe --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr95113.c @@ -0,0 +1,33 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fexceptions -fnon-call-exceptions" } */ +/* { dg-require-effective-target exceptions } */ + +int a, b; + +static inline long int +foo (long int x, int y) +{ + if (y == 0) + return 0; + + if (x == -1 && y == -1) + return 0; + + return x / y; +} + +static inline int +bar (int *p) +{ + int c = foo (a, 1) + *p; + return b; +} + +int +main () +{ + int d = 0; + b = foo (1, 1); + bar (&d); + return 0; +} diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c index 10ef2e3157c..4246dca8806 100644 --- a/gcc/tree-eh.c +++ b/gcc/tree-eh.c @@ -2936,6 +2936,16 @@ stmt_could_throw_p (function *fun, gimple *stmt) } } +/* Return true if STMT in function FUN must be assumed necessary because of + non-call exceptions. */ + +bool +stmt_unremovable_because_of_non_call_eh_p (function *fun, gimple *stmt) +{ + return (fun->can_throw_non_call_exceptions + && !fun->can_delete_dead_exceptions + && stmt_could_throw_p (fun, stmt)); +} /* Return true if expression T could throw an exception. */ diff --git a/gcc/tree-eh.h b/gcc/tree-eh.h index cb1019e0d87..ba911cadbe7 100644 --- a/gcc/tree-eh.h +++ b/gcc/tree-eh.h @@ -39,6 +39,7 @@ extern bool operation_could_trap_p (enum tree_code, bool, bool, tree); extern bool tree_could_trap_p (tree); extern tree rewrite_to_non_trapping_overflow (tree); extern bool stmt_could_throw_p (function *, gimple *); +extern bool stmt_unremovable_because_of_non_call_eh_p (function *, gimple *); extern bool tree_could_throw_p (tree); extern bool stmt_can_throw_external (function *, gimple *); extern bool stmt_can_throw_internal (function *, gimple *); diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c index 757cfad5b5e..fae5ae72340 100644 --- a/gcc/tree-ssa-dce.c +++ b/gcc/tree-ssa-dce.c @@ -201,9 +201,7 @@ mark_stmt_if_obviously_necessary (gimple *stmt, bool aggressive) { /* With non-call exceptions, we have to assume that all statements could throw. If a statement could throw, it can be deemed necessary. */ - if (cfun->can_throw_non_call_exceptions - && !cfun->can_delete_dead_exceptions - && stmt_could_throw_p (cfun, stmt)) + if (stmt_unremovable_because_of_non_call_eh_p (cfun, stmt)) { mark_stmt_necessary (stmt, true); return;