From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 20CD13858D20 for ; Thu, 28 Mar 2024 15:39:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 20CD13858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 20CD13858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711640352; cv=none; b=YyQ07Vyfc8RSw4d5fKJnRWDyWE4K9JhBaUD4FkjFw5z7NmNwrKsgzj1rTuxxyfCPGPiWrdjld2+6cGWBKQvKHhj7YF9cGMKOv3EAh14JOPdQHXd2t0PgsNX403VAmqMLx28jeHimDBXai5Dy4mwEA3qR4Ge9BV13r0B7RG7WvTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711640352; c=relaxed/simple; bh=/ek92Za0YHMq/Kw32wpkMj16bW9IHg2kqZRbCOWRuNk=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=Sizq5OvCk8brbIflMgj1BI8+i4jNn7rRPmJ97AgaWt3mZyyeb0eMwWqYdUlYEYx7kaBcr88WkvrHpQO/n9kmJtFpcEALqToxqAbKKcks/ZB/iyvQMwDA/rR6FfAbFHr5xiiryWE/jLIjUDU/oD8cx11Ksqxyt7aUrPqaaVirecw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (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 smtp-out1.suse.de (Postfix) with ESMTPS id C2FB73409A; Thu, 28 Mar 2024 15:39:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1711640345; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=F8niCNex5WpwrEe1CyXXNXjjSTBkuOwtUVspNynUZ2U=; b=iOtAHaiqeHTJ/SpBQysvT3Eb2jiS2mmxv6gvhdoPx8CSA2aag91qFscZMs9SaagB/QvSed sZdV93euHLBBvRQ9uhucgAP5qOFw9f3dlddLjY4M27++N1YC0f/MEGqgWKGyJFr3b99zIV B4toY5ftqbH9P3Dc+VBGrzHk3b7YmvI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1711640345; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=F8niCNex5WpwrEe1CyXXNXjjSTBkuOwtUVspNynUZ2U=; b=4nnuNSdBPBsH0TEDSD0hT585FABkR1t5u1rNMVJZM6TceUBrutJZsmvvz8xTlYaGfuBBQr rCu8N1f/Ty3m3zBQ== Authentication-Results: smtp-out1.suse.de; none Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (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 imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id ADC8513A92; Thu, 28 Mar 2024 15:39:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id MMcoKhmPBWasZwAAn2gu4w (envelope-from ); Thu, 28 Mar 2024 15:39:05 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: Re: [PATCH] ipa: Avoid duplicate replacements in IPA-SRA transformation phase In-Reply-To: References: User-Agent: Notmuch/0.38.2 (https://notmuchmail.org) Emacs/29.3 (x86_64-suse-linux-gnu) Date: Thu, 28 Mar 2024 16:38:56 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -4.30 X-Spamd-Result: default: False [-4.30 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_THREE(0.00)[3]; MID_RHS_MATCH_FROMTLD(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; TO_DN_ALL(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Level: X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hello, and ping, please. (In my copy I have fixed the formatting issue spotted by Jakub.) Martin On Fri, Mar 15 2024, Martin Jambor wrote: > Hi, > > when the analysis part of IPA-SRA figures out that it would split out > a scalar part of an aggregate which is known by IPA-CP to contain a > known constant, it skips it knowing that the transformation part looks > at IPA-CP aggregate results too and does the right thing (which can > include doing the propagation in GIMPLE because that is the last > moment the parameter exists). > > However, when IPA-SRA wants to split out a smaller non-aggregate out > of an aggregate, which happens to be of the same size as a known > scalar constant at the same offset, the transformation bit fails to > recognize the situation, tries to do both splitting and constant > propagation and in PR 111571 testcase creates a nonsensical call > statement on which the call redirection then ICEs. > > Fixed by making sure we don't try to do two replacements of the same > part of the same parameter. > > The look-up among replacements requires these are sorted and this > patch just sorts them if they are not already sorted before each new > look-up. The worst number of sortings that can happen is number of > parameters which are both split and have aggregate constants times > param_ipa_max_agg_items (default 16). I don't think complicating the > source code to optimize for this unlikely case is worth it but if need > be, it can of course be done. > > Bootstrapped and tested on x86_64-linux. OK for master and eventually > also the gcc-13 branch? > > Thanks, > > Martin > > > > gcc/ChangeLog: > > 2024-03-15 Martin Jambor > > PR ipa/111571 > * ipa-param-manipulation.cc > (ipa_param_body_adjustments::common_initialization): Avoid creating > duplicate replacement entries. > > gcc/testsuite/ChangeLog: > > 2024-03-15 Martin Jambor > > PR ipa/111571 > * gcc.dg/ipa/pr111571.c: New test. > --- > gcc/ipa-param-manipulation.cc | 16 ++++++++++++++++ > gcc/testsuite/gcc.dg/ipa/pr111571.c | 29 +++++++++++++++++++++++++++++ > 2 files changed, 45 insertions(+) > create mode 100644 gcc/testsuite/gcc.dg/ipa/pr111571.c > > diff --git a/gcc/ipa-param-manipulation.cc b/gcc/ipa-param-manipulation.cc > index 3e0df6a6f77..4c6337cc563 100644 > --- a/gcc/ipa-param-manipulation.cc > +++ b/gcc/ipa-param-manipulation.cc > @@ -1525,6 +1525,22 @@ ipa_param_body_adjustments::common_initialization (tree old_fndecl, > replacement with a constant (for split aggregates passed > by value). */ > > + if (split[parm_num]) > + { > + /* We must be careful not to add a duplicate > + replacement. */ > + sort_replacements (); > + ipa_param_body_replacement *pbr = > + lookup_replacement_1 (m_oparms[parm_num], > + av.unit_offset); > + if (pbr) > + { > + /* Otherwise IPA-SRA should have bailed out. */ > + gcc_assert (AGGREGATE_TYPE_P (TREE_TYPE (pbr->repl))); > + continue; > + } > + } > + > tree repl; > if (av.by_ref) > repl = av.value; > diff --git a/gcc/testsuite/gcc.dg/ipa/pr111571.c b/gcc/testsuite/gcc.dg/ipa/pr111571.c > new file mode 100644 > index 00000000000..2a4adc608db > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/ipa/pr111571.c > @@ -0,0 +1,29 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2" } */ > + > +struct a { > + int b; > +}; > +struct c { > + long d; > + struct a e; > + long f; > +}; > +int g, h, i; > +int j() {return 0;} > +static void k(struct a l, int p) { > + if (h) > + g = 0; > + for (; g; g = j()) > + if (l.b) > + break; > +} > +static void m(struct c l) { > + k(l.e, l.f); > + for (;; --i) > + ; > +} > +int main() { > + struct c n = {10, 9}; > + m(n); > +} > -- > 2.44.0