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 B91E53858C41 for ; Fri, 15 Mar 2024 17:57:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B91E53858C41 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 B91E53858C41 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=1710525450; cv=none; b=LKceLoscEQXimvMf83wZ6L0yLL+sZ1FHThveG8vDOuq/97FuM6gOkh6VFdO1F5ZP4YeeTtwGlOn51vuh1HcEm67XVhvcQLVU4FVpjZNxRqZQQVr0dP6AoPWcUgd1nO3dogEOVdObUwL/O4Kd7oY+DsVh49zz7CE6Rokhcu/GGsI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710525450; c=relaxed/simple; bh=AKNSEfqqJrxSMKTEUVudw9kn5zYILU3/CkdPdbLdwcA=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=NoPA5JWCxjR5HzY0JC/GURwZ1qR42J0iVnZSPZozPScjDUwoPsNVb0BE4KoPBdYnXm3+y1O5Qo9wkJOb9QR3SISdt0PB4jjzI/BZObHLVcX03bUUIdVV2QiP7RXPcrthQKnqTkrte3cHgPtxGpNxAx6VSMFXvIGtv/1cMWRhk8Y= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.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 smtp-out1.suse.de (Postfix) with ESMTPS id 7E41421DDC; Fri, 15 Mar 2024 17:57:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1710525438; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=CvtSOD2H3DlLKLtQXIypfY4LOqprgXhzEhSsAd1XGx0=; b=uHBY0OHqASI7nON1iEaYHEYek49fKwQFUZ4pQQM+O5XJJR92MZHoNeAuXthnoiidlHZPZZ E/+sxD5bBvNd2HldgMsTCPjfFLkklF13Bc2hNJ1xmsVqKAWL4tWMzFQhr6IUWgd/FL1ZMU cxMw0yhNBFDOMrwx6RSynsb7cpMgGTg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1710525438; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=CvtSOD2H3DlLKLtQXIypfY4LOqprgXhzEhSsAd1XGx0=; b=WYFpn7PC0NsJPMVpdOGcLgwPd4r3nkD6Y76tMFsiFkKna74Uns/B3idl3/RMdfjHGdP3DT lmtsR8hrn74P4cBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1710525438; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=CvtSOD2H3DlLKLtQXIypfY4LOqprgXhzEhSsAd1XGx0=; b=uHBY0OHqASI7nON1iEaYHEYek49fKwQFUZ4pQQM+O5XJJR92MZHoNeAuXthnoiidlHZPZZ E/+sxD5bBvNd2HldgMsTCPjfFLkklF13Bc2hNJ1xmsVqKAWL4tWMzFQhr6IUWgd/FL1ZMU cxMw0yhNBFDOMrwx6RSynsb7cpMgGTg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1710525438; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=CvtSOD2H3DlLKLtQXIypfY4LOqprgXhzEhSsAd1XGx0=; b=WYFpn7PC0NsJPMVpdOGcLgwPd4r3nkD6Y76tMFsiFkKna74Uns/B3idl3/RMdfjHGdP3DT lmtsR8hrn74P4cBg== Received: from imap1.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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 743D413460; Fri, 15 Mar 2024 17:57:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 9c8eHP6L9GUlAwAAD6G6ig (envelope-from ); Fri, 15 Mar 2024 17:57:18 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH] ipa: Avoid duplicate replacements in IPA-SRA transformation phase User-Agent: Notmuch/0.38.2 (https://notmuchmail.org) Emacs/29.2 (x86_64-suse-linux-gnu) Date: Fri, 15 Mar 2024 18:57:18 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: 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]; NEURAL_HAM_SHORT(-0.20)[-1.000]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] 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,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 List-Id: 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