From patchwork Tue Feb 14 14:50:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1742439 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=oW5LTETT; dkim=pass header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=FuPWI4Mk; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PGPJr5GdJz23r4 for ; Wed, 15 Feb 2023 01:50:34 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 39EEF3858430 for ; Tue, 14 Feb 2023 14:50:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 099803858D1E for ; Tue, 14 Feb 2023 14:50:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 099803858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id F0DC71FF41; Tue, 14 Feb 2023 14:50:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1676386213; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=Ctu1uQm3MEynu+qG6HF6SRUgQOxlivs34HW/zc/d2ZY=; b=oW5LTETT9nUkcZhx+q97LWg5uG+bshPO+6olpuklhXbYwoM0QBwiGzhBxhDv+UT6FmUdjo RA0XYDfitYkwTRLIEkiuL0t7Zh9hPSIIg+FEgYDz1uTksFUkd8Ec9QCtPKv4MAbrcObuot MMqBl08PW45OD/2JYjTq9EqacUgRXZA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1676386213; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=Ctu1uQm3MEynu+qG6HF6SRUgQOxlivs34HW/zc/d2ZY=; b=FuPWI4Mk0QNLtv9jPI42xFRPyGXukvLCpAspprs4EaW1MjZT4kAS/uNZw94N8JKNae3n0j AjAkRw3Utrmz2nBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E3F0013A21; Tue, 14 Feb 2023 14:50:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id w/2jN6Wf62MAYAAAMHmgww (envelope-from ); Tue, 14 Feb 2023 14:50:13 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka , Jan Hubicka Subject: [PATCH] ipa: Avoid IPA confusing scalar values and single-field aggregates (PR 108679) User-Agent: Notmuch/0.37 (https://notmuchmail.org) Emacs/28.2 (x86_64-suse-linux-gnu) Date: Tue, 14 Feb 2023 15:50:04 +0100 Message-ID: MIME-Version: 1.0 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_SOFTFAIL, 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 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, PR 108679 testcase shows a situation when IPA-CP is able to track a scalar constant in a single-field structure that is part of a bigger structure. This smaller struture is however also passed in a few calls to other functions, but the two same-but-different entities, originally places at the same offset and with the same size, and this confuses the mechanism that takes care of handling call statements after IPA-SRA. I think that in stage 4 it is best to revert to GCC 12 behavior in this particular case (when IPA-CP detects a constant in a single-field structure or a single element array that is part of a bigger aggregate) and the patch below does that. If accepted, I plan to file a missed-optimization bug to track that we could use the IPA-CP propagated value to re-construct the small aggregate arguments. Bootstrapped and tested and LTO bootstrapped on x86_64-linux. OK for master? Thanks, Martin gcc/ChangeLog: 2023-02-13 Martin Jambor PR ipa/108679 * ipa-sra.cc (push_param_adjustments_for_index): Do not omit creation of non-scalar replacements even if IPA-CP knows their contents. gcc/testsuite/ChangeLog: 2023-02-13 Martin Jambor PR ipa/108679 * gcc.dg/ipa/pr108679.c: New test. --- gcc/ipa-sra.cc | 2 +- gcc/testsuite/gcc.dg/ipa/pr108679.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr108679.c diff --git a/gcc/ipa-sra.cc b/gcc/ipa-sra.cc index 0495f446bf4..3de7d426b7e 100644 --- a/gcc/ipa-sra.cc +++ b/gcc/ipa-sra.cc @@ -3989,7 +3989,7 @@ push_param_adjustments_for_index (isra_func_summary *ifs, unsigned base_index, { ipa_argagg_value_list avl (ipcp_ts); tree value = avl.get_value (base_index, pa->unit_offset); - if (value) + if (value && !AGGREGATE_TYPE_P (pa->type)) { if (dump_file) fprintf (dump_file, " - omitting component at byte " diff --git a/gcc/testsuite/gcc.dg/ipa/pr108679.c b/gcc/testsuite/gcc.dg/ipa/pr108679.c new file mode 100644 index 00000000000..b1ed50bb831 --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr108679.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +struct S1 { + signed f0; +}; +struct S2 { + struct S1 f2; + short f8; +} g_18; +void safe_lshift_func_int16_t_s_u(); +void safe_unary_minus_func_uint64_t_u(); +int safe_mul_func_uint8_t_u_u(int, struct S1 p_14); +int g_732, func_6_l_17; +static int *func_12(); +static int func_6(struct S2 p_7) { func_12(func_6_l_17, p_7.f2, g_18, 0); } +static int *func_12(int, struct S1 p_14) { + safe_lshift_func_int16_t_s_u(); + safe_unary_minus_func_uint64_t_u(); + g_732 = safe_mul_func_uint8_t_u_u(0, p_14); +} +int main() { + struct S2 l_10 = {3}; + func_6(l_10); +}