From patchwork Tue Mar 7 11:08:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 65370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2367315wrd; Tue, 7 Mar 2023 03:09:07 -0800 (PST) X-Google-Smtp-Source: AK7set8w9CXFoiguUZCELkwqJd5cpPOVZiNE18QilMWFcklnIpl+lkwgFv3C4QK6iBk9WC5TZZF/ X-Received: by 2002:a17:907:1ddb:b0:88a:7408:384c with SMTP id og27-20020a1709071ddb00b0088a7408384cmr13008629ejc.47.1678187347444; Tue, 07 Mar 2023 03:09:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678187347; cv=none; d=google.com; s=arc-20160816; b=VLFuVVJEGaf8uRdnTFfAARBXQqcTrXkZ4zK5qP7s4pSe4ccieVfIKAqxpGC+ZUswiJ gcTn4TNy16CjrZpO3J7juhEw7W7klnHYA3acXuyvzcDVBF12i0AwEtiDXfzWYaKqT39q YHlhmlHLW2N+4miE4Gtbsx7V00TbNS9ytiaiI5v0VoJeY4IdELPlvN4+tKBhBiChxnCr WqUZMDyQ9hif/xFjmIlIYuTh1DlqNq9YkQjG02AvMrlXqQb7fugEk2IJDkifnVq5jlG+ 1koSQv1DlT88M6LCMWC2Nk+wSnTwH/eVXKXccWmse/WzSwdUJPD/6hwpTWabTzm413jF 74pg== 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=rDptbmsAvKmjfWTjFR5t5ZCYayQNAQjT1bZD1iISqNg=; b=0j/sR+4/CdXvxisGN5qG1/05FInIF0Mi0VxDWx9KMdn0fKn19Ydajsq87rEcIEGwbB lFvVttAWCG6mo+d9zj6rvvlJCMvaT3khduMkCcnvRwnlKTvWRA9rDniCyeDEFvO7PA2w W2mT62Jyya/w8TsvCHm18E9L7wh8NV0u5/XqhHAEf0JX3icdXBSy9VeNAKmyxPoHF0y/ gP2IpKXNtF73V5xAZRE0FQ7j3kt0tOBpbcke5Uusc2RXVSVRw4ZhlVzjMNFaQukjH31D lYe6YkraDI54ORf55eCVYqesiXo7xwzfxgiQuIIGAgnktrP2e3ugndKUa1EJaybvHPs8 lT/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YztkVx8u; 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 n21-20020a1709065e1500b008b17879ce79si2530314eju.590.2023.03.07.03.09.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 03:09:07 -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=@gcc.gnu.org header.s=default header.b=YztkVx8u; 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 81A03385B523 for ; Tue, 7 Mar 2023 11:09:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81A03385B523 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678187346; bh=rDptbmsAvKmjfWTjFR5t5ZCYayQNAQjT1bZD1iISqNg=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=YztkVx8utDJNeCSy7NC2ET50vaCzzP5JRhRygufWtZuGYlObDunGklgDIBq9Mf9/g RvIt85alDNTTanPYBYJNveg9UbxhEbv/88torzq73azJN8Thl6QMsaJ+46WnLa9u1K lkJDu+lA0rrUgbCY6JUlA+X5ptqfzseRa1lbxZx4= 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 B01AB3858D39 for ; Tue, 7 Mar 2023 11:08:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B01AB3858D39 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 8DFD721A39; Tue, 7 Mar 2023 11:08:15 +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 7DA002C141; Tue, 7 Mar 2023 11:08:15 +0000 (UTC) Date: Tue, 7 Mar 2023 11:08:15 +0000 (UTC) To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] tree-optimization/109046 - re-combine complex loads 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 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: <20230307110906.81A03385B523@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759706975592493262?= X-GMAIL-MSGID: =?utf-8?q?1759706975592493262?= The following addresses PR109046 by adding an optimization to forwprop to combine a piecewise complex load to a complex load when there are no uses of the components. That's something useful in general and easier to do than avoiding the splitting in complex lowering. The testcase exercises both the manual and the complex lowering case. Bootstrapped and tested on x86_64-unknown-linux-gnu, OK? Thanks, Richard. PR tree-optimization/109046 * tree-ssa-forwprop.cc (pass_forwprop::execute): Combine piecewise complex loads. * gcc.dg/tree-ssa/forwprop-39.c: New testcase. --- gcc/testsuite/gcc.dg/tree-ssa/forwprop-39.c | 15 ++++++++++ gcc/tree-ssa-forwprop.cc | 31 ++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/forwprop-39.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-39.c b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-39.c new file mode 100644 index 00000000000..eb2930e77fd --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-39.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-std=c11 -O2 -fdump-tree-forwprop1 -fdump-tree-optimized" } */ + +#include + +extern void push1(void *p, float _Complex x); +void foo (void *q, float _Complex *x) +{ + float r = __real *x; + float i = __imag *x; + push1 (q, CMPLXF (r, i)); +} + +/* { dg-final { scan-tree-dump-not "COMPLEX_EXPR" "forwprop1" } } */ +/* { dg-final { scan-tree-dump-not "REALPART_EXPR" "optimized" } } */ diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc index 03fe0a3f6df..3111a2b96a3 100644 --- a/gcc/tree-ssa-forwprop.cc +++ b/gcc/tree-ssa-forwprop.cc @@ -3669,7 +3669,8 @@ pass_forwprop::execute (function *fun) /* Rewrite stores of a single-use complex build expression to component-wise stores. */ use_operand_p use_p; - gimple *use_stmt; + gimple *use_stmt, *def1, *def2; + tree rhs2; if (single_imm_use (lhs, &use_p, &use_stmt) && gimple_store_p (use_stmt) && !gimple_has_volatile_ops (use_stmt) @@ -3703,6 +3704,34 @@ pass_forwprop::execute (function *fun) release_defs (stmt); gsi_remove (&gsi, true); } + /* Rewrite a component-wise load of a complex to a complex + load if the components are not used separately. */ + else if (TREE_CODE (rhs) == SSA_NAME + && has_single_use (rhs) + && ((rhs2 = gimple_assign_rhs2 (stmt)), true) + && TREE_CODE (rhs2) == SSA_NAME + && has_single_use (rhs2) + && (def1 = SSA_NAME_DEF_STMT (rhs), + gimple_assign_load_p (def1)) + && (def2 = SSA_NAME_DEF_STMT (rhs2), + gimple_assign_load_p (def2)) + && (gimple_vuse (def1) == gimple_vuse (def2)) + && gimple_assign_rhs_code (def1) == REALPART_EXPR + && gimple_assign_rhs_code (def2) == IMAGPART_EXPR + && operand_equal_p (TREE_OPERAND (gimple_assign_rhs1 + (def1), 0), + TREE_OPERAND (gimple_assign_rhs1 + (def2), 0))) + { + tree cl = TREE_OPERAND (gimple_assign_rhs1 (def1), 0); + gimple_assign_set_rhs_from_tree (&gsi, unshare_expr (cl)); + gcc_assert (gsi_stmt (gsi) == stmt); + gimple_set_vuse (stmt, gimple_vuse (def1)); + gimple_set_modified (stmt, true); + gimple_stmt_iterator gsi2 = gsi_for_stmt (def1); + gsi_remove (&gsi, false); + gsi_insert_after (&gsi2, stmt, GSI_SAME_STMT); + } else gsi_next (&gsi); }