From patchwork Mon Oct 23 13:32:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 156885 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1300184vqx; Mon, 23 Oct 2023 06:32:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVNE2az8RWOmBWX7CSYGSGshjm/lXpbDJ8rNNGojWSzOlojdgChzPadrI4IhFIc6b0oD8y X-Received: by 2002:a05:622a:1997:b0:41c:e92a:c611 with SMTP id u23-20020a05622a199700b0041ce92ac611mr7356538qtc.38.1698067946344; Mon, 23 Oct 2023 06:32:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698067946; cv=pass; d=google.com; s=arc-20160816; b=HggkjDJDkJgJ5j+Cs450snqDtCTpusKL5K6mJ6oSsARbk+WGIu9J5/vKGsE+aUXwne e/2RypHpSV1gTPRrR9dQ5VBOy+nWD42khUX7yqXz9NuO6P6TMBsoOHSIL3kcEfhi4SOj Er6Q3ESmelKgUzUiY2aCWF/20gmV2dRRODftXA9FWEKDMiGpsR4vvsUmS19sM/EzDP5u v+jk9gWDrdW+5AGGUNvh2GGn2Y3Re5X1by6RHyCGQV2mNnJOfflMKlrjwsh1NRpggZjJ Xb/iHnr6806T1r8QLgzYihJ6IK4RSAPJVWLp+GGN7EQDmvR7GCM/SsKdEgrLM+8+V99o aL4g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:errors-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :user-agent:subject:to:from:date:arc-filter:dmarc-filter :delivered-to; bh=AIDX5gUSOdxWALIdrtJHouSMFAFvGnxgi67tG1oy7QQ=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=FOZyhHEGTpU5NdtLdR9NZWypMy8/1OteqYuYFCzW8Od5W6iqfsaAlDLfBFB+2gAmab NNf0Z03FZuPBzo60yj5GYYy3ugeZff5Xe0CY8T0vwJghPLMhZPCtsHyUp218BLduhQ3T FulNMxGekpLE7kZvJBuIjLKXebzPqe3Mr+LkuhFzqu4N46O02SULSnsEqzfW7pTX/+a2 SXoole57FFyww7ZD0HC50rwILNlUCIpViOBIXeYV4GuP3xecZrWOA2C83iWTlcGN0rYW oTCIlGhC01D2spyZptNhottDaR0+EIbleuebuZ427tCWBaZblFnCUaCVWx3tdxrZEQk8 ASeQ== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id y2-20020a05622a004200b00419738eabfasi5418006qtw.40.2023.10.23.06.32.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 06:32:26 -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; arc=pass (i=1); 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"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B77493857707 for ; Mon, 23 Oct 2023 13:32:25 +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 7A9BC3858413 for ; Mon, 23 Oct 2023 13:32:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A9BC3858413 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7A9BC3858413 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2178:6::1d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698067922; cv=none; b=uhRXqXE/5P7VPK7SZM8cc74+0S5z1EcFpReJe5aqAlbZJ5GnW+91AvLqSwZGN2JGXsAZjFg0k74oeEwYDcdzmvPY6F4bxiBerEafaXlahq4BXpSn4mlTKStiOlD7GMdxRtrAnyekppMrr64L1WoyCY3aJrK7dfC0rdCh1Ny2XoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698067922; c=relaxed/simple; bh=Lpe8mSUa8hYIEYZUEwL3kF1IKLx6FAj0RCxxsELbXnY=; h=Date:From:To:Subject:MIME-Version; b=lrBJ83QCJbG6Kccghqdw1E5wJ28iofAEX3e1AWBND0jDfNRtwtLPOleyrjwxrSlAmIfWz/O22MGou6k4gTSxdGkfJrf9HloAK8BOINQtau6xTF7riwzpevIY+dHfDT9ukZNfkYKwSW/2BwOPRvPJZJ6Gc8LCrOxLiLNaGNCTqD4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 3405D1FE18 for ; Mon, 23 Oct 2023 13:32:00 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id EECE02C8CD for ; Mon, 23 Oct 2023 13:31:59 +0000 (UTC) Date: Mon, 23 Oct 2023 13:32:00 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] ipa/111914 - perform parameter init after remapping types User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Level: X-Spamd-Bar: / Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=none; spf=softfail (smtp-out2.suse.de: 149.44.160.134 is neither permitted nor denied by domain of rguenther@suse.de) smtp.mailfrom=rguenther@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [-0.01 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RWL_MAILSPIKE_GOOD(0.00)[149.44.160.134:from]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-3.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; R_SPF_SOFTFAIL(0.60)[~all:c]; RCPT_COUNT_ONE(0.00)[1]; MISSING_MID(2.50)[]; VIOLATED_DIRECT_SPF(3.50)[]; MX_GOOD(-0.01)[]; NEURAL_HAM_SHORT(-1.00)[-1.000]; DMARC_NA(0.20)[suse.de]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: -0.01 X-Rspamd-Queue-Id: 3405D1FE18 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, MISSING_MID, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 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 Message-Id: <20231023133225.B77493857707@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780553294788418434 X-GMAIL-MSGID: 1780553294788418434 The following addresses a mismatch in SSA name vs. symbol when we emit a dummy assignment when not optimizing. The temporary we create is not remapped by initialize_inlined_parameters because we have no easy way to get at it. The following instead emits the additional statement after we have remapped the type of the replacement variable. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR ipa/111914 * tree-inline.cc (setup_one_parameter): Move code emitting a dummy load when not optimizing ... (initialize_inlined_parameters): ... here to after when we remapped the parameter type. * gcc.dg/pr111914.c: New testcase. --- gcc/testsuite/gcc.dg/pr111914.c | 14 ++++++++++++++ gcc/tree-inline.cc | 26 ++++++++++++++++++-------- 2 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr111914.c diff --git a/gcc/testsuite/gcc.dg/pr111914.c b/gcc/testsuite/gcc.dg/pr111914.c new file mode 100644 index 00000000000..05804bddcb9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr111914.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" } */ + +__attribute__((always_inline)) +static inline void f(int n, int (*a())[n]) +{ + /* Unused 'a'. */ +} + +void g(void) +{ + int (*a())[1]; + f(1, a); +} diff --git a/gcc/tree-inline.cc b/gcc/tree-inline.cc index d63060c9429..69387b525f9 100644 --- a/gcc/tree-inline.cc +++ b/gcc/tree-inline.cc @@ -3578,9 +3578,7 @@ setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn, STRIP_USELESS_TYPE_CONVERSION (rhs); - /* If we are in SSA form properly remap the default definition - or assign to a dummy SSA name if the parameter is unused and - we are not optimizing. */ + /* If we are in SSA form properly remap the default definition. */ if (gimple_in_ssa_p (cfun) && is_gimple_reg (p)) { if (def) @@ -3590,11 +3588,6 @@ setup_one_parameter (copy_body_data *id, tree p, tree value, tree fn, SSA_NAME_IS_DEFAULT_DEF (def) = 0; set_ssa_default_def (cfun, var, NULL); } - else if (!optimize) - { - def = make_ssa_name (var); - init_stmt = gimple_build_assign (def, rhs); - } } else if (!is_empty_type (TREE_TYPE (var))) init_stmt = gimple_build_assign (var, rhs); @@ -3653,6 +3646,23 @@ initialize_inlined_parameters (copy_body_data *id, gimple *stmt, && SSA_NAME_VAR (*defp) == var) TREE_TYPE (*defp) = TREE_TYPE (var); } + /* When not optimizing and the parameter is unused, assign to + a dummy SSA name. Do this after remapping the type above. */ + else if (!optimize + && is_gimple_reg (p) + && i < gimple_call_num_args (stmt)) + { + tree val = gimple_call_arg (stmt, i); + if (val != error_mark_node) + { + if (!useless_type_conversion_p (TREE_TYPE (p), + TREE_TYPE (val))) + val = force_value_to_type (TREE_TYPE (p), val); + def = make_ssa_name (var); + gimple *init_stmt = gimple_build_assign (def, val); + insert_init_stmt (id, bb, init_stmt); + } + } } }