From patchwork Wed Nov 24 21:30:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 48113 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 0F2A7385800F for ; Wed, 24 Nov 2021 21:31:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F2A7385800F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637789507; bh=Z52wPocqmfs+ouEzbiKVtiMZKRbycNSl1SwW9qMhFZQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=d3tDe/yv/WQ/iitYhRB9ruu3CMNMJX+Jo4V580WeHLhLl3lgm4+swaF3andCKS8Bu xwiBksuu8N4/Qzxa3DeltkK74Pzpm82QSzoIhKglgRuV5JbtVFT6lxQ4mrA4+WIVct VE27yNrWBJEDCsg7TZy6wE+h1VOOpQLt/45QYHs0= 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 23500385AC3C for ; Wed, 24 Nov 2021 21:30:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 23500385AC3C Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id B1072280941; Wed, 24 Nov 2021 22:30:47 +0100 (CET) Date: Wed, 24 Nov 2021 22:30:47 +0100 To: gcc-patches@gcc.gnu.org Subject: Fix handling of static chain in modref Message-ID: <20211124213047.GB13308@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-11.7 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 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: 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 fixes wrong code issue where modref did not propagate flags for static chain in ipa_merge_modref_summary_after_inlininig. It is a place I missed to update in original patch extending return slot tracking to static chain. Unlike return slot we need to propagate flags here (return slot is write only parameter and does not need it) Bootstrapped/regtested x86_64-linux, comitted. gcc/ChangeLog: 2021-11-24 Jan Hubicka * ipa-modref.c (implicit_eaf_flags_for_edge_and_arg): Break out from... (modref_merge_call_site_flags): ... here. (ipa_merge_modref_summary_after_inlining): Use it. gcc/testsuite/ChangeLog: 2021-11-24 Jan Hubicka * gcc.c-torture/execute/pr103405.c: New test. diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c index 923ae6c1dd3..c2edc0d28a6 100644 --- a/gcc/ipa-modref.c +++ b/gcc/ipa-modref.c @@ -4827,6 +4827,30 @@ modref_propagate_dump_scc (cgraph_node *component_node) } } +/* Determine EAF flags know for call E with CALLEE_ECF_FLAGS and ARG. */ + +int +implicit_eaf_flags_for_edge_and_arg (cgraph_edge *e, int callee_ecf_flags, + bool ignore_stores, int arg) +{ + /* Returning the value is already accounted to at local propagation. */ + int implicit_flags = EAF_NOT_RETURNED_DIRECTLY + | EAF_NOT_RETURNED_INDIRECTLY; + if (ignore_stores) + implicit_flags |= ignore_stores_eaf_flags; + if (callee_ecf_flags & ECF_PURE) + implicit_flags |= implicit_pure_eaf_flags; + if (callee_ecf_flags & (ECF_CONST | ECF_NOVOPS)) + implicit_flags |= implicit_const_eaf_flags; + class fnspec_summary *fnspec_sum = fnspec_summaries->get (e); + if (fnspec_sum) + { + attr_fnspec fnspec (fnspec_sum->fnspec); + implicit_flags |= fnspec.arg_eaf_flags (arg); + } + return implicit_flags; +} + /* Process escapes in SUM and merge SUMMARY to CUR_SUMMARY and SUMMARY_LTO to CUR_SUMMARY_LTO. Return true if something changed. */ @@ -4857,9 +4881,8 @@ modref_merge_call_site_flags (escape_summary *sum, { int flags = 0; int flags_lto = 0; - /* Returning the value is already accounted to at local propagation. */ - int implicit_flags = EAF_NOT_RETURNED_DIRECTLY - | EAF_NOT_RETURNED_INDIRECTLY; + int implicit_flags = implicit_eaf_flags_for_edge_and_arg + (e, callee_ecf_flags, ignore_stores, ee->arg); if (summary && ee->arg < summary->arg_flags.length ()) flags = summary->arg_flags[ee->arg]; @@ -4995,6 +5018,7 @@ modref_propagate_flags_in_scc (cgraph_node *component_node) if (ecf_flags & (ECF_CONST | ECF_NOVOPS) || !callee_edge->inline_failed) continue; + /* Get the callee and its summary. */ enum availability avail; callee = callee_edge->callee->function_or_virtual_thunk_symbol @@ -5081,6 +5105,9 @@ ipa_merge_modref_summary_after_inlining (cgraph_edge *edge) class modref_summary_lto *callee_info_lto = summaries_lto ? summaries_lto->get (edge->callee) : NULL; int flags = flags_from_decl_or_type (edge->callee->decl); + /* Combine in outer flags. */ + for (cgraph_node *n = edge->caller; n->inlined_to; n = n->callers->caller) + flags |= flags_from_decl_or_type (edge->callee->decl); bool ignore_stores = ignore_stores_p (edge->caller->decl, flags); if (!callee_info && to_info) @@ -5148,10 +5175,11 @@ ipa_merge_modref_summary_after_inlining (cgraph_edge *edge) FOR_EACH_VEC_ELT (sum->esc, i, ee) { bool needed = false; - /* TODO: We do not have jump functions for return slots, so we - never propagate them to outer function. */ - if (ee->parm_index < 0) - continue; + int implicit_flags = implicit_eaf_flags_for_edge_and_arg + (edge, flags, ignore_stores, + ee->arg); + if (!ee->direct) + implicit_flags = deref_flags (implicit_flags, ignore_stores); if (to_info && (int)to_info->arg_flags.length () > ee->parm_index) { int flags = callee_info @@ -5159,11 +5187,14 @@ ipa_merge_modref_summary_after_inlining (cgraph_edge *edge) ? callee_info->arg_flags[ee->arg] : 0; if (!ee->direct) flags = deref_flags (flags, ignore_stores); - else if (ignore_stores) - flags |= ignore_stores_eaf_flags; - flags |= ee->min_flags; - to_info->arg_flags[ee->parm_index] &= flags; - if (to_info->arg_flags[ee->parm_index]) + flags |= ee->min_flags | implicit_flags; + eaf_flags_t &f = ee->parm_index == MODREF_RETSLOT_PARM + ? to_info->retslot_flags + : ee->parm_index == MODREF_STATIC_CHAIN_PARM + ? to_info->static_chain_flags + : to_info->arg_flags[ee->parm_index]; + f &= flags; + if (f) needed = true; } if (to_info_lto @@ -5174,11 +5205,14 @@ ipa_merge_modref_summary_after_inlining (cgraph_edge *edge) ? callee_info_lto->arg_flags[ee->arg] : 0; if (!ee->direct) flags = deref_flags (flags, ignore_stores); - else if (ignore_stores) - flags |= ignore_stores_eaf_flags; - flags |= ee->min_flags; - to_info_lto->arg_flags[ee->parm_index] &= flags; - if (to_info_lto->arg_flags[ee->parm_index]) + flags |= ee->min_flags | implicit_flags; + eaf_flags_t &f = ee->parm_index == MODREF_RETSLOT_PARM + ? to_info_lto->retslot_flags + : ee->parm_index == MODREF_STATIC_CHAIN_PARM + ? to_info_lto->static_chain_flags + : to_info_lto->arg_flags[ee->parm_index]; + f &= flags; + if (f) needed = true; } struct escape_map entry = {ee->parm_index, ee->direct}; diff --git a/gcc/testsuite/gcc.c-torture/execute/pr103405.c b/gcc/testsuite/gcc.c-torture/execute/pr103405.c new file mode 100644 index 00000000000..f6005dc2983 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr103405.c @@ -0,0 +1,37 @@ +typedef __SIZE_TYPE__ size_t; +void *malloc(size_t); + +static inline int *starter(int a) +{ + int *b = malloc(sizeof(int)); + *b = a; + return b; +} + +static inline _Bool equal(int *l, int *r) +{ + if (l == 0) + __builtin_abort(); + if (r == 0) + __builtin_abort(); + return *r == *l; +} + +int main(void) +{ + int *i; + int *j; + void check(_Bool a) + { + _Bool t = equal(i, j); + if (a && t) __builtin_abort (); + _Bool t1 = equal(i, j); + if (!a && !t1) __builtin_abort (); + } + i = starter(1); + j = starter(0); + check(1); + i = starter(0); + check(0); + +}