From patchwork Thu Apr 27 07:24:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 88142 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp90740vqo; Thu, 27 Apr 2023 00:25:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ797dWg1sTfV8hd2L3vrpgxuL0m4gluBgCcZKAO44nMSQiAYOWL4M4O80Jl5lM8+QgobXf3 X-Received: by 2002:a05:6402:44b:b0:4fe:1b62:4741 with SMTP id p11-20020a056402044b00b004fe1b624741mr692224edw.28.1682580333817; Thu, 27 Apr 2023 00:25:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682580333; cv=none; d=google.com; s=arc-20160816; b=maPTU1TTVG7C/YvYkVoLuM9jdvDRSIjFfZdpmKMk/tD6jeNsO8SzLBLqifWNJyhNlB UQ3R82RnRysQ68il4j6lMQgI/AmjqDrDKMZpl05vQd5qQk+SjKibj74NoZEED4rkFvKO 0jY6cQryAVxINqqlrdHq+HslT2Pz8CFtlM9RAtqYFyqJh/a9P3f/a/9ObttVXIgkYR4K +o5AP3l49tpOQYGQ3T1Y+JpPo+S2p+PRCkhwM8W2q/k6IGQR7TAS6uFZefQCw6zZQkIe 0tx/fxKlkwdHxbE2jrVRt/W1Vqx61I8s+kv4zIrp8S1oiR2SSiHMw4il3Gi3E0Xr6N7S OPxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:cc:to:date:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=aO86ylAeQEQoh0AXzBYnzMHeM1I2Hi3JIWVHkqbca18=; b=aq+Rc9guPht16qniHfd7BBSOoZwGlekapO7ekFwbFJ1A8JWLX7QjbLd9VHw5P8DhTs kHJna9KsOoUPFR1gUdQ21HRTKhS5eo9FVNyo3tRsFTg0Lm2PU9FpRycg7mpQnrc2RGW9 RV80opZMLdikGXeyZ/qsKdFDWjVuJ+U77GoiJuuobje3kbCqtklcGsj/Y2flYsmDqC0w CshWRpC2h7PniYvI+FofpvNUKJsdLrpwNb+P0ixJBG/dK4CQZYWlmn/Zcu1SDJ6B7+GY SQZaAn7b8WZHVawst+AGhgSzCFpDNixUD0tyC2lFy/v32Zn19tRT/eD95GFM5coBTpJ2 LxWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CQpIxyob; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f5-20020a056402150500b005047b5d4479si12622905edw.415.2023.04.27.00.25.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 00:25:33 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=CQpIxyob; 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"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B70AD3858C74 for ; Thu, 27 Apr 2023 07:25:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B70AD3858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682580332; bh=aO86ylAeQEQoh0AXzBYnzMHeM1I2Hi3JIWVHkqbca18=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=CQpIxyobf+wPj3+o8XbJpAavYsPVc9Xf5/K/j9hZurah/qiyZJAksy9vHh15jn9Ic 4UWlDKwzJ6pu2nMQJUtxgk0d+HPn3FYo0B1q239MidWLJCaPTp7cNdylCtzeRzYEha FdFRPduCexSeGa4nC2htwiagrB0EWzRmh6FJ00bk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id BAD783858D20 for ; Thu, 27 Apr 2023 07:24:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BAD783858D20 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id DDC9321A6E for ; Thu, 27 Apr 2023 07:24:46 +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 D412A2C141; Thu, 27 Apr 2023 07:24:46 +0000 (UTC) Date: Thu, 27 Apr 2023 07:24:46 +0000 (UTC) To: gcc-patches@gcc.gnu.org cc: Martin Jambor Subject: [PATCH] ipa/109607 - properly gimplify conversions introduced by IPA param manipulation User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, 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 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: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230427072532.B70AD3858C74@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764313356224948533?= X-GMAIL-MSGID: =?utf-8?q?1764313356224948533?= The following addresses IPA param manipulation (through IPA SRA) replacing BIT_FIELD_REF <*this_8(D), 8, 56> with BIT_FIELD_REF (ISRA.814), 8, 56> which is supposed to be invalid GIMPLE (ISRA.814 is a register). There's currently insufficient checking in place to catch this in the IL verifier but I am working on that as part of fixing PR109594. The solution for the particular testcase I am running into this is to split the conversion to a separate stmt. Generally the modification phase is set up for this but the extra_stmts sequence isn't passed around everywhere. The following passes it to modify_expression from modify_assignment when rewriting the RHS. Bootstrapped and tested on x86_64-unknown-linux-gnu. OK for trunk? Thanks, Richard. PR ipa/109607 * ipa-param-manipulation.h (ipa_param_body_adjustments::modify_expression): Add extra_stmts argument. * ipa-param-manipulation.cc (ipa_param_body_adjustments::modify_expression): Likewise. When we need a conversion and the replacement is a register split the conversion out. (ipa_param_body_adjustments::modify_assignment): Pass extra_stmts to RHS modify_expression. * g++.dg/torture/pr109607.C: New testcase. --- gcc/ipa-param-manipulation.cc | 10 ++++++++-- gcc/ipa-param-manipulation.h | 2 +- gcc/testsuite/g++.dg/torture/pr109607.C | 13 +++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/torture/pr109607.C diff --git a/gcc/ipa-param-manipulation.cc b/gcc/ipa-param-manipulation.cc index 42488ee09c3..33dcab9c33c 100644 --- a/gcc/ipa-param-manipulation.cc +++ b/gcc/ipa-param-manipulation.cc @@ -1825,7 +1825,8 @@ ipa_param_body_adjustments::replace_removed_params_ssa_names (tree old_name, necessary conversions. */ bool -ipa_param_body_adjustments::modify_expression (tree *expr_p, bool convert) +ipa_param_body_adjustments::modify_expression (tree *expr_p, bool convert, + gimple_seq *extra_stmts) { tree expr = *expr_p; @@ -1860,6 +1861,11 @@ ipa_param_body_adjustments::modify_expression (tree *expr_p, bool convert) gcc_checking_assert (tree_to_shwi (TYPE_SIZE (TREE_TYPE (expr))) == tree_to_shwi (TYPE_SIZE (TREE_TYPE (repl)))); tree vce = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (expr), repl); + if (is_gimple_reg (repl)) + { + gcc_assert (extra_stmts); + vce = force_gimple_operand (vce, extra_stmts, true, NULL_TREE); + } *expr_p = vce; } else @@ -1887,7 +1893,7 @@ ipa_param_body_adjustments::modify_assignment (gimple *stmt, lhs_p = gimple_assign_lhs_ptr (stmt); any = modify_expression (lhs_p, false); - any |= modify_expression (rhs_p, false); + any |= modify_expression (rhs_p, false, extra_stmts); if (any && !useless_type_conversion_p (TREE_TYPE (*lhs_p), TREE_TYPE (*rhs_p))) { diff --git a/gcc/ipa-param-manipulation.h b/gcc/ipa-param-manipulation.h index 9cc957ae7bb..9798eedf0b6 100644 --- a/gcc/ipa-param-manipulation.h +++ b/gcc/ipa-param-manipulation.h @@ -373,7 +373,7 @@ private: unsigned unit_offset); ipa_param_body_replacement *lookup_first_base_replacement (tree base); tree replace_removed_params_ssa_names (tree old_name, gimple *stmt); - bool modify_expression (tree *expr_p, bool convert); + bool modify_expression (tree *expr_p, bool convert, gimple_seq * = nullptr); bool modify_assignment (gimple *stmt, gimple_seq *extra_stmts); bool modify_call_stmt (gcall **stmt_p, gimple *orig_stmt); bool modify_cfun_body (); diff --git a/gcc/testsuite/g++.dg/torture/pr109607.C b/gcc/testsuite/g++.dg/torture/pr109607.C new file mode 100644 index 00000000000..f7e2a7457af --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr109607.C @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-require-effective-target lp64 } + +enum profile_quality { GUESSED_LOCAL }; +struct profile_count { + long m_val : 61; + profile_quality m_quality : 3; + bool verify() { + m_quality ? __builtin_abort (), 0 : 0; + return m_val == GUESSED_LOCAL; + } +} count; +void verify_flow_info() { count.verify(); }