From patchwork Thu Oct 1 17:39:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1375344 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=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4C2L3X2MNPz9sSf for ; Fri, 2 Oct 2020 03:39:34 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5276B398B816; Thu, 1 Oct 2020 17:39:32 +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 D0E053851C0A for ; Thu, 1 Oct 2020 17:39:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D0E053851C0A 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.221.27]) by mx2.suse.de (Postfix) with ESMTP id B8935B2AC for ; Thu, 1 Oct 2020 17:39:27 +0000 (UTC) From: Martin Jambor To: GCC Patches Subject: [PATCH] ipa-prop: Fix multiple-target speculation resolution User-Agent: Notmuch/0.31 (https://notmuchmail.org) Emacs/26.3 (x86_64-suse-linux-gnu) Date: Thu, 01 Oct 2020 19:39:27 +0200 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-3038.0 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: Jan Hubicka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, as the FIXME which this patch removes states, the current code does not work when a call with multiple speculative targets gets resolved through parameter tracking during inlining - it feeds the inliner an edge it has already dealt with. The patch makes the code which should prevent it aware of the possibility that that speculation can have more than one target now. Bootstrapped and tested and LTO bootstrapped on x86_64-linux. I did not try profiled LTO bootstrap because it fails even without the patch (even without Ada, just C, C++ and Fortran, at least commit 92f0d3d03a7 does). OK for trunk? Thanks, Martin gcc/ChangeLog: 2020-09-30 Martin Jambor PR ipa/96394 * ipa-prop.c (update_indirect_edges_after_inlining): Do not add resolved speculation edges to vector of new direct edges even in presence of multiple speculative direct edges for a single call. gcc/testsuite/ChangeLog: 2020-09-30 Martin Jambor PR ipa/96394 * gcc.dg/tree-prof/pr96394.c: New test. --- gcc/ipa-prop.c | 10 ++-- gcc/testsuite/gcc.dg/tree-prof/pr96394.c | 64 ++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-prof/pr96394.c diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index b28c78eeab4..2ef7a48c5d2 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -3787,11 +3787,13 @@ update_indirect_edges_after_inlining (struct cgraph_edge *cs, param_index = ici->param_index; jfunc = ipa_get_ith_jump_func (top, param_index); - cgraph_node *spec_target = NULL; - /* FIXME: This may need updating for multiple calls. */ + auto_vec spec_targets; if (ie->speculative) - spec_target = ie->first_speculative_call_target ()->callee; + for (cgraph_edge *direct = ie->first_speculative_call_target (); + direct; + direct = direct->next_speculative_call_target ()) + spec_targets.safe_push (direct->callee); if (!opt_for_fn (node->decl, flag_indirect_inlining)) new_direct_edge = NULL; @@ -3814,7 +3816,7 @@ update_indirect_edges_after_inlining (struct cgraph_edge *cs, /* If speculation was removed, then we need to do nothing. */ if (new_direct_edge && new_direct_edge != ie - && new_direct_edge->callee == spec_target) + && spec_targets.contains (new_direct_edge->callee)) { new_direct_edge->indirect_inlining_edge = 1; top = IPA_EDGE_REF (cs); diff --git a/gcc/testsuite/gcc.dg/tree-prof/pr96394.c b/gcc/testsuite/gcc.dg/tree-prof/pr96394.c new file mode 100644 index 00000000000..4280182a7c3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-prof/pr96394.c @@ -0,0 +1,64 @@ +/* PR ipa/96394 */ +/* { dg-options "-O2" } */ + +typedef struct _entry { + int has_next; + int next_ix; + int count; +} entry; + +extern entry table[]; + +void * +__attribute__((noipa)) +PyErr_Format(entry * e){ return 0; } + +void ae(entry *); +int h(entry *); +int ap(entry *); +int ag(entry *); + +int ag(entry *j) { + if (j->has_next) + h(&table[j->next_ix]); + return 0; +} +static int ai(entry *j, int k(entry *), int l, int m) { + int am = 1; + int ab; + + /* k is either 'h' or 'ap': 50%/50% */ + ab = k(j); + + /* loop never gets executed on real data */ + for (; j->count >= 2; am += 2) + if (l) { + entry *i = &table[am + m]; + PyErr_Format(i); + } + return ab; +} +void +__attribute__((noipa)) +bug() { + h(table); + h(table); +} +int h(entry *j) { return ai(j, ap, 4, 5); } +int ap(entry *j) { return ai(j, ag, 14, 4); } + +int main(void) +{ + bug(); +} + +entry table[2] = { + { .has_next = 1 + , .next_ix = 1 + , .count = 0 + }, + { .has_next = 0 + , .next_ix = 0 + , .count = 0 + }, +};