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: 57059 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3017948wrn; Tue, 14 Feb 2023 06:50:45 -0800 (PST) X-Google-Smtp-Source: AK7set+uNRHNybVWFARoj/G5dZ3Qlt6anysYzak5/s4sQsm1d0zlsRW0s6Z44qGuCXCRC0QWAHxm X-Received: by 2002:a17:907:8c85:b0:8b1:3131:76e9 with SMTP id td5-20020a1709078c8500b008b1313176e9mr2135522ejc.46.1676386245422; Tue, 14 Feb 2023 06:50:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676386245; cv=none; d=google.com; s=arc-20160816; b=efwmS1q1UdzHeLYdV9fR9PhmP2nnKbwXDikAPFKGMgnXH3xG2X0qnlW2BQ52S9a4mW TljwxIZ1tXEB+W2yA9pZWo8qHUBiJOEJ3ZhInovDKzVGg75xoDfQ4Pdrjy3y2S5njOtJ AWnmHIiPWE7HnkjV3+OVi3hLJLFRVb4igoZNQzKOWqgeTxlZB+qsp3fqSnJUNvGwOMZK 2nHLDkkMAQ5BeufJc106i8JyJPriOQHLSRSMp0IwGWqBM9rk/iBd7bYD0tfcX+O4RFLx gJF/n5hbfOq+2StLWxqW3Te69kpuffoZa1m878f9rtbEBaxF4MsUTJ4ZpdCIwQriO/MY b/uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :user-agent:subject:cc:to:from:dkim-signature:dkim-signature :dmarc-filter:delivered-to; bh=Ctu1uQm3MEynu+qG6HF6SRUgQOxlivs34HW/zc/d2ZY=; b=iixmeWS5/FjhgjZb179fVTCeWzxAEPAB/irJoFiXcDuOkCQVVOUQgbvaBBUuF5HSE4 cXAww3Vk8NebLVpUL6AcodUWKcZYqOomy4+rhWUSEltXfnvljyKeqK9eg8ao6eLXjipB qxTGNLtaJbDLY9Xrc7ygbX0eL+H++Ej7BRqyJSrRCZHYj7jF+Ma2MIISwwIoTXUWOzyu Lr0tmR+ijoCiK3GAw3eE2m6UfjLgTgbv3XBiFXSRaBVhGIaK3ygKS8DaLqSfq5js6alw i8A4qF4sn32MHUGXzcFYipt5++ksBY1NWO4Z8BUdvGZmQ6hB95BOD6QsKgOZQNfjYESg cRHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=oW5LTETT; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=FuPWI4Mk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 16-20020a170906225000b0086b6a3fd247si22436719ejr.557.2023.02.14.06.50.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 06:50:45 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=oW5LTETT; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=FuPWI4Mk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E87338582AB for ; Tue, 14 Feb 2023 14:50:43 +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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757818383565217711?= X-GMAIL-MSGID: =?utf-8?q?1757818383565217711?= 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); +}