From patchwork Thu Jun 23 13:46:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 55329 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 B4557385734D for ; Thu, 23 Jun 2022 13:46:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B4557385734D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1655992017; bh=PNXdy5ikGywdOwZWNA7FVCsxVt4xyL8ln2nRZ8axZH0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=oTWORjZefEm0T5z2fX5gauGD3cT02P+/cjtByCW/O/ZfgHd6mMgOK/ISmAqZmyhbI srQ5urbzpgrHe/pVJlHWek6vCsUkEpSxQGidtlWc0V0T0jCog/3qZg6XNDeERoDkFc F7l+Gj+BT31RNxmvPMbtdhSRRoCwyqKr4//dWg8I= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id A778F38582B1 for ; Thu, 23 Jun 2022 13:46:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A778F38582B1 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 0E00F289A7F; Thu, 23 Jun 2022 15:46:26 +0200 (CEST) Date: Thu, 23 Jun 2022 15:46:26 +0200 To: gcc-patches@gcc.gnu.org, rguenther@suse.de Subject: Fix stmt_kills_ref_p wrt external throws Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, this patch adds missing check to stmt_kills_ref_p for case that function is terminated by EH before call return value kills the ref. In the PR I tried to construct testcase but I don't know how to do that until I annotate EH code with fnspec attributes which I will do in separate patch and add a testcase. Bootstrapped/regtested x86_64-linux, OK? PR ipa/106057 * tree-ssa-alias.cc (stmt_kills_ref_p): Check for external throw. diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc index b1e7a2d5afc..e427ee6744a 100644 --- a/gcc/tree-ssa-alias.cc +++ b/gcc/tree-ssa-alias.cc @@ -87,10 +87,11 @@ along with GCC; see the file COPYING3. If not see This function tries to disambiguate two reference trees. - bool ptr_deref_may_alias_global_p (tree) + bool ptr_deref_may_alias_global_p (tree, bool) This function queries if dereferencing a pointer variable may - alias global memory. + alias global memory. If bool argument is true, global memory + is considered to also include function local memory that escaped. More low-level disambiguators are available and documented in this file. Low-level disambiguators dealing with points-to @@ -3333,11 +3334,18 @@ stmt_kills_ref_p (gimple *stmt, ao_ref *ref) && TREE_CODE (gimple_get_lhs (stmt)) != SSA_NAME /* The assignment is not necessarily carried out if it can throw and we can catch it in the current function where we could inspect - the previous value. + the previous value. Similarly if the function can throw externally + and the ref does not diea on the function return. ??? We only need to care about the RHS throwing. For aggregate assignments or similar calls and non-call exceptions the LHS - might throw as well. */ - && !stmt_can_throw_internal (cfun, stmt)) + might throw as well. + ??? We also should care about possible longjmp, but since we + do not understand that longjmp is not using global memory we will + not consider a kill here since the function call will be considered + as possibly using REF. */ + && !stmt_can_throw_internal (cfun, stmt) + && (!stmt_can_throw_external (cfun, stmt) + || !ref_may_alias_global_p (ref, false))) { tree lhs = gimple_get_lhs (stmt); /* If LHS is literally a base of the access we are done. */ @@ -3434,8 +3442,12 @@ stmt_kills_ref_p (gimple *stmt, ao_ref *ref) && node->binds_to_current_def_p () && (summary = get_modref_function_summary (node)) != NULL && summary->kills.length () + /* Check that we can not trap while evaulating function + parameters. This check is overly conservative. */ && (!cfun->can_throw_non_call_exceptions - || !stmt_can_throw_internal (cfun, stmt))) + || (!stmt_can_throw_internal (cfun, stmt) + && (!stmt_can_throw_external (cfun, stmt) + || !ref_may_alias_global_p (ref, stmt))))) { for (auto kill : summary->kills) {