From patchwork Thu Mar 23 10:09:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 73964 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2821729wrt; Thu, 23 Mar 2023 03:09:51 -0700 (PDT) X-Google-Smtp-Source: AK7set9i60ks9vIMBykh/m6dKrjMyumbpCD4YL/q+LKZCF5aTGrTPUqVzuvZtPNBPuJBz+5+i8Zo X-Received: by 2002:a17:906:2505:b0:932:9502:4fd1 with SMTP id i5-20020a170906250500b0093295024fd1mr10063894ejb.43.1679566191257; Thu, 23 Mar 2023 03:09:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679566191; cv=none; d=google.com; s=arc-20160816; b=fqWq+jKCznrER/IldIHvw+jog42N+zCBlAS+b61BDXTUCsqf9uLmzevjTApReczOT3 FQvErf/58zp5ZaPp2Dk5rt8+43VWFnlbHROYKlTtrgRz2Tedy3e+sZngsZCtJvPTgdo3 zJelqTBuFHNGfaDZyz6qor3CY/p6G9JDaTdss5QNjkiMF09tP4Lgz3fJet3GcGknjxFi 68J78vNX/+qUfHfhecV26lOY0d6UnXWyoXLcbhNycCIxGGSeG5JVDOTYwtGJYG06lM39 MGKb2L4SCnP1wcwgZ+ot8RC5nhcmir8PIs/6NF+Y3mxq5BqDVCcGWj/zCsTqxuJbvUjF yguw== 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=x0EWqyHxeO67zRzsYW/8IrIdhwYCaNCH6VNHIuGMayc=; b=HCPUtM//d6LT5UxxT7086NMfyrSx/OK48AIuV7+ZQMla6EZgTdrIBJjoRw8E5D5YuU 2TKpLfiH3wXSt0mlQz0wS5SvnPdCrdRXBYdgZ3ujjXp7CPE7Q5ZBYY7olA3e4fEc0x1Q /i1J6ebCOUv7SG+KmsI7paVv0HfeHh4neWobr8aB2Yii9SaM4J3/PruiURt/wXz89iCJ 5EZQj5XRTJUiTBF8Bcq5T74VRoPyuY0Ty2p4kiGcKH7t+ZTkt+WUx87uU4+rSfUDxmj3 1UTVCKoicQ9H/tgQnq+E3ltdq5SfkNJtRXrtUsVoYLZKmDWPBamx9POq2YR3szVEfy7P X9kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=IRsN0Qop; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=4dF0OCVf; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id s16-20020a170906061000b008b593e8957esi16761178ejb.884.2023.03.23.03.09.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Mar 2023 03:09:51 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=IRsN0Qop; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=4dF0OCVf; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 9C36D3870896 for ; Thu, 23 Mar 2023 10:09:46 +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 C1B913858C39 for ; Thu, 23 Mar 2023 10:09:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C1B913858C39 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 528E11FDB6; Thu, 23 Mar 2023 10:09:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1679566160; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=x0EWqyHxeO67zRzsYW/8IrIdhwYCaNCH6VNHIuGMayc=; b=IRsN0Qop6XgBCdukl34Rafv7ystHMlA/BYrxaGyYPH+LtbSPr3wUE63pPjAV3uqVMZ8i1C S0xxRMRxoBTaNAr6VpVaJGT2ZsDEbHLxrs0AFDeEeDMhb5O4VmF77kK8ADYUHdQ5M6NxB/ LU+GTFMRWNq0PLfwgXsR1oxp8q8NHFs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1679566160; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=x0EWqyHxeO67zRzsYW/8IrIdhwYCaNCH6VNHIuGMayc=; b=4dF0OCVf2SmWXT4b1htgvA0sXvugXXhwa5etbhSJ9dADdiRbx7S+DZxz/At4EVlFtg5D27 +dzGsr7eesdxFWAA== 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 405ED132C2; Thu, 23 Mar 2023 10:09:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6nViDlAlHGR1XwAAMHmgww (envelope-from ); Thu, 23 Mar 2023 10:09:20 +0000 From: Martin Jambor To: GCC Patches Cc: Jan Hubicka Subject: [PATCH] ipa: Avoid another ICE when dealing with type-incompatibilities (PR 108959) User-Agent: Notmuch/0.37 (https://notmuchmail.org) Emacs/28.2 (x86_64-suse-linux-gnu) Date: Thu, 23 Mar 2023 11:09:19 +0100 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 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?1761152798746791220?= X-GMAIL-MSGID: =?utf-8?q?1761152798746791220?= Hi, PR 108959 shows one more example where undefined code with type incompatible accesses to stuff passed in parameters can cause an ICE because we try to create a VIEW_CONVERT_EXPR of mismatching sizes: 1. IPA-CP tries to push one type from above, 2. IPA-SRA (correctly) decides the parameter is useless because it is only used to construct an argument to another function which does not use it and so the formal parameter should be removed, 3. but the code reconciling IPA-CP and IPA-SRA transformations still wants to perform the IPA-CP and overrides the built-in DCE of useless statements and tries to stuff constants into them instead, constants of a type with mismatching type and size. This patch avoids the situation in IPA-SRA by purging the IPA-CP results from any "aggregate" constants that are passed in parameters which are detected to be useless. It also removes IPA value range and bits information associated with removed parameters stored in the same structure so that the useless information is not streamed later on. Bootstrapped and LTO-bootstrapped and tested on x86_64-linux. OK for trunk? Thanks, Martin gcc/ChangeLog: 2023-03-22 Martin Jambor PR ipa/108959 * ipa-sra.cc (zap_useless_ipcp_results): New function. (process_isra_node_results): Call it. gcc/testsuite/ChangeLog: 2023-03-17 Martin Jambor PR ipa/108959 * gcc.dg/ipa/pr108959.c: New test. --- gcc/ipa-sra.cc | 66 +++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/ipa/pr108959.c | 22 ++++++++++ 2 files changed, 88 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/ipa/pr108959.c diff --git a/gcc/ipa-sra.cc b/gcc/ipa-sra.cc index 3de7d426b7e..7b8260bc9e1 100644 --- a/gcc/ipa-sra.cc +++ b/gcc/ipa-sra.cc @@ -4028,6 +4028,70 @@ mark_callers_calls_comdat_local (struct cgraph_node *node, void *) return false; } +/* Remove any IPA-CP results stored in TS that are associated with removed + parameters as marked in IFS. */ + +static void +zap_useless_ipcp_results (const isra_func_summary *ifs, ipcp_transformation *ts) +{ + unsigned ts_len = vec_safe_length (ts->m_agg_values); + + if (ts_len == 0) + return; + + bool removed_item = false; + unsigned dst_index = 0; + + for (unsigned i = 0; i < ts_len; i++) + { + ipa_argagg_value *v = &(*ts->m_agg_values)[i]; + const isra_param_desc *desc = &(*ifs->m_parameters)[v->index]; + + if (!desc->locally_unused) + { + if (removed_item) + (*ts->m_agg_values)[dst_index] = *v; + dst_index++; + } + else + removed_item = true; + } + if (dst_index == 0) + { + ggc_free (ts->m_agg_values); + ts->m_agg_values = NULL; + } + else if (removed_item) + ts->m_agg_values->truncate (dst_index); + + bool useful_bits = false; + unsigned count = vec_safe_length (ts->bits); + for (unsigned i = 0; i < count; i++) + if ((*ts->bits)[i]) + { + const isra_param_desc *desc = &(*ifs->m_parameters)[i]; + if (desc->locally_unused) + (*ts->bits)[i] = NULL; + else + useful_bits = true; + } + if (!useful_bits) + ts->bits = NULL; + + bool useful_vr = false; + count = vec_safe_length (ts->m_vr); + for (unsigned i = 0; i < count; i++) + if ((*ts->m_vr)[i].known) + { + const isra_param_desc *desc = &(*ifs->m_parameters)[i]; + if (desc->locally_unused) + (*ts->m_vr)[i].known = false; + else + useful_vr = true; + } + if (!useful_vr) + ts->m_vr = NULL; +} /* Do final processing of results of IPA propagation regarding NODE, clone it if appropriate. */ @@ -4080,6 +4144,8 @@ process_isra_node_results (cgraph_node *node, } ipcp_transformation *ipcp_ts = ipcp_get_transformation_summary (node); + if (ipcp_ts) + zap_useless_ipcp_results (ifs, ipcp_ts); vec *new_params = NULL; if (ipa_param_adjustments *old_adjustments = cinfo ? cinfo->param_adjustments : NULL) diff --git a/gcc/testsuite/gcc.dg/ipa/pr108959.c b/gcc/testsuite/gcc.dg/ipa/pr108959.c new file mode 100644 index 00000000000..cd1f88658ef --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/pr108959.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +union U2 { + long f0; + int f1; +}; +int g_16; +int g_70[20]; +static int func_61(int) { + for (;;) + g_70[g_16] = 4; +} +static int func_43(int *p_44) +{ + func_61(*p_44); +} +int main() { + union U2 l_38 = {9}; + int *l_49 = (int *) &l_38; + func_43(l_49); +}