From patchwork Tue Feb 27 07:04:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufu Guo X-Patchwork-Id: 207158 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2640803dyb; Tue, 27 Feb 2024 03:50:08 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVw+hORCEHcvj8Ob5iiUR71toZ7dFxcGJTQ6MkAeTIH0bvINALuC6+dfhy2gUtG9uQWEa1BqbAg7HneYrMInLAt+fi/yw== X-Google-Smtp-Source: AGHT+IEGOVwEJMWLa0pzhclMZe7W2zfUrW37Md7DBy66hVY9K/yt3SVwgoff1N3iP8xtFt1bFFyZ X-Received: by 2002:a05:620a:2a08:b0:787:1fba:5848 with SMTP id o8-20020a05620a2a0800b007871fba5848mr2159394qkp.74.1709034608056; Tue, 27 Feb 2024 03:50:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709034608; cv=pass; d=google.com; s=arc-20160816; b=GxQOpm14Qd3tT1xk86YjF69rBxskow7aSrcapWx8sB/87a+7ns02WpQc29XNHWCGJr BzSZ0kfBgi6KVHeLFQbi4ufpvAcC35T0zYRCn7hZ5nDyQ/2UfwpL/apBVwaTFjv3Xua2 7M43XWczFjeVmnrZwmEnXT1GBo1oOhLCeCXiln00sOZ0Xh/eZm8fm3DsVnwshaZ9cg8b W58IN/BMjje2CcXgwNy1AA/zAmpzz04RgOFAuSbmJqCUhiC1UycTBcoDDFOBNlU8vnDZ koN+WB0/JgTCLNyePemvYZNbdAHsayl7PiNv/OmhxtTJjsm1/fVzANLI+iaRAperq3Mo 0FFg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version :content-transfer-encoding:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-filter:dmarc-filter :delivered-to; bh=Yx/RZIeZeXOZsnXQxKDZtwj6JRYxb2zU5df8/IAfnVA=; fh=K+JqHH8RnLlTWvnozmPrYUJPr/ljxWaDvUkEICtE/mg=; b=weZFWS9yqSiHiukg0kjZVUZWRtVemJt9dc6vaIOXZaK/cfkXdaPwStyR1FWjbr3OFj R98q/E8KxRen4hphPiLgqBB6SncT03ncJMyszXKoVmH7owjG44w+oda1P6wzY8WNk3AA VAn7HVF0H0THb8Fx668kNZArz0rrHGg+KX7eU1A89+Y6rFe7ke3f+SJvR+a/mIu6ot6/ ahm4Tyr9pYeBzxD0lvShF3InuV67V0wry6/KtY/rDdlVum2T17dsO6/SCgFoeVgNGH+f 8DzglQFH5q+0iDv8RDXTU1Rix8eCtP4vc7dML/A8g5shF+xWUna9lX57t0Bq+u6+mQMY DxsQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=IEDc+Lq4; 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=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id a26-20020a05620a02fa00b00785cb0a01c0si7292426qko.425.2024.02.27.03.50.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 03:50:08 -0800 (PST) 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=@ibm.com header.s=pp1 header.b=IEDc+Lq4; 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=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BA1A23858293 for ; Tue, 27 Feb 2024 11:50:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id E0819385840B; Tue, 27 Feb 2024 11:49:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E0819385840B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E0819385840B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034556; cv=none; b=Uj1S1f0LoKqKCbNKs1bEwsySxKhjokCkfqKdpCpWGntc7ervtOFSskU/WGyE+JO4bV14Wf1Q/7x4iuf8mAbZUYo3h3IFzDnP1U8RaxGMT1/31IdjG6qtc9KyxMDKeuY2oiAiL7riuKIqEWhB5x+gcdijDRdB08kymIK4zyQe1pI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709034556; c=relaxed/simple; bh=KGMqW8BkMtwxQa3nVulUJuAmlCEsWfcAppIFYEeoQfA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=vYkK2V6eLCT/d1S20ytEbbfMkBj0o8B0eEdvUJszdnIeTt5Dm25OQSDM5kYUlTd5L1BqZFRsshXDvbRsHdwQPVKv98UrP+qy+IjcuNj50lJgdPWdb58RW69jTnsL9+5X/LgeSLvnd/IiVLj+NCHwxbrXjCx4SoiIqH7YOfggTqs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41RARFCC017731; Tue, 27 Feb 2024 11:49:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : mime-version; s=pp1; bh=Yx/RZIeZeXOZsnXQxKDZtwj6JRYxb2zU5df8/IAfnVA=; b=IEDc+Lq4LYSq0K12IETKN7+aKYtdFKGk/HOTrz91ipJ8LCEPwi4qxjVMUW1dJSmYqjEY YYQQWjPykcoYHk9T/TwyiyFcmkJNaHQtMF0hKiTnMbwv4m1KkIA4RxWPurahAkQaEQTt cGLbeCOgezxlNTE8xJg/m/+e2nUXE3t6knd174mg0AoGl1+aWPKw4PJyUVaDd746zVyo MLoT/kdEvEQoLKf6p9KGwy50BsbvLck+9oFYtByh2eYcxfNP6V7qIWfEHSX25dCkZpIA 26i3Et3xzwnl+rMi2srBIaFP9mCeWjkLdwkRoQzMDjRjLq0s7y90pgHYaHjubIVMyw02 0Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3whe0d1ysj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Feb 2024 11:49:02 +0000 Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 41RAefM8003994; Tue, 27 Feb 2024 11:49:01 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3whe0d1ys6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Feb 2024 11:49:01 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 41RB4M4E024160; Tue, 27 Feb 2024 11:49:00 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3wfw0k71h6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Feb 2024 11:49:00 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41R74GSq37617966 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Feb 2024 07:04:18 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C513E20040; Tue, 27 Feb 2024 07:04:16 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 335EF2004F; Tue, 27 Feb 2024 07:04:15 +0000 (GMT) Received: from genoa.aus.stglabs.ibm.com (unknown [9.40.192.157]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 27 Feb 2024 07:04:15 +0000 (GMT) From: Jiufu Guo To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, jeffreyalaw@gmail.com, richard.sandiford@arm.com, segher@kernel.crashing.org, dje.gcc@gmail.com, linkw@gcc.gnu.org, bergner@linux.ibm.com, guojiufu@linux.ibm.com Subject: [PATCH 1/3, RFC] fsra: Add final gimple sra just before expander Date: Tue, 27 Feb 2024 15:04:10 +0800 Message-Id: <20240227070412.3471038-2-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240227070412.3471038-1-guojiufu@linux.ibm.com> References: <20240227070412.3471038-1-guojiufu@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: JaapNcGV2KZ3s24Pp58kmKME9GO3V3Ei X-Proofpoint-ORIG-GUID: 9pgLWqUV0Lv7KgbhwS8K8PKThU7Tc1J6 X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-26_11,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxscore=0 priorityscore=1501 mlxlogscore=461 spamscore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 impostorscore=0 malwarescore=0 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402270092 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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.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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792052673126016640 X-GMAIL-MSGID: 1792052673126016640 This patch adds a new mode for sra pass: "fsra". This 'fsra' pass handle function parameters and returns as candidates. And run it at the end of GIMPLE passes sequences. gcc/ChangeLog: * passes.def: Add pass pass_sra_final. * tree-pass.h (make_pass_sra_final): Declare make_pass_sra_final. * tree-sra.cc (enum sra_mode): New enum item SRA_MODE_FINAL_INTRA. (build_accesses_from_assign): Accept SRA_MODE_FINAL_INTRA. (find_var_candidates): Collect candidates for SRA_MODE_FINAL_INTRA. (final_intra_sra): New function. (class pass_sra_final): New pass class. (make_pass_sra_final): New function. --- gcc/passes.def | 2 ++ gcc/tree-pass.h | 1 + gcc/tree-sra.cc | 81 +++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/gcc/passes.def b/gcc/passes.def index 1cbbd413097..183c1becd65 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -449,6 +449,8 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_harden_conditional_branches); NEXT_PASS (pass_harden_compares); NEXT_PASS (pass_warn_access, /*early=*/false); + NEXT_PASS (pass_sra_final); + NEXT_PASS (pass_cleanup_cfg_post_optimizing); NEXT_PASS (pass_warn_function_noreturn); diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h index 29267589eeb..2d0e12bd1bb 100644 --- a/gcc/tree-pass.h +++ b/gcc/tree-pass.h @@ -366,6 +366,7 @@ extern gimple_opt_pass *make_pass_early_tree_profile (gcc::context *ctxt); extern gimple_opt_pass *make_pass_cleanup_eh (gcc::context *ctxt); extern gimple_opt_pass *make_pass_sra (gcc::context *ctxt); extern gimple_opt_pass *make_pass_sra_early (gcc::context *ctxt); +extern gimple_opt_pass *make_pass_sra_final (gcc::context *ctxt); extern gimple_opt_pass *make_pass_tail_recursion (gcc::context *ctxt); extern gimple_opt_pass *make_pass_tail_calls (gcc::context *ctxt); extern gimple_opt_pass *make_pass_fix_loops (gcc::context *ctxt); diff --git a/gcc/tree-sra.cc b/gcc/tree-sra.cc index f8e71ec48b9..aacc76f58b5 100644 --- a/gcc/tree-sra.cc +++ b/gcc/tree-sra.cc @@ -21,14 +21,16 @@ along with GCC; see the file COPYING3. If not see . */ /* This file implements Scalar Reduction of Aggregates (SRA). SRA is run - twice, once in the early stages of compilation (early SRA) and once in the - late stages (late SRA). The aim of both is to turn references to scalar - parts of aggregates into uses of independent scalar variables. + three times, once in the early stages of compilation (early SRA) and once + in the late stages (late SRA). The aim of them is to turn references to + scalar parts of aggregates into uses of independent scalar variables. - The two passes are nearly identical, the only difference is that early SRA + The three passes are nearly identical, the difference are that early SRA does not scalarize unions which are used as the result in a GIMPLE_RETURN statement because together with inlining this can lead to weird type - conversions. + conversions. The third pass is more care about parameters and returns, + it would be helpful for the parameters and returns which are passed through + registers. Both passes operate in four stages: @@ -104,6 +106,7 @@ along with GCC; see the file COPYING3. If not see /* Enumeration of all aggregate reductions we can do. */ enum sra_mode { SRA_MODE_EARLY_IPA, /* early call regularization */ SRA_MODE_EARLY_INTRA, /* early intraprocedural SRA */ + SRA_MODE_FINAL_INTRA, /* final gimple intraprocedural SRA */ SRA_MODE_INTRA }; /* late intraprocedural SRA */ /* Global variable describing which aggregate reduction we are performing at @@ -1437,7 +1440,8 @@ build_accesses_from_assign (gimple *stmt) } if (lacc && racc - && (sra_mode == SRA_MODE_EARLY_INTRA || sra_mode == SRA_MODE_INTRA) + && (sra_mode == SRA_MODE_EARLY_INTRA || sra_mode == SRA_MODE_INTRA + || sra_mode == SRA_MODE_FINAL_INTRA) && !lacc->grp_unscalarizable_region && !racc->grp_unscalarizable_region && AGGREGATE_TYPE_P (TREE_TYPE (lhs)) @@ -2149,6 +2153,24 @@ find_var_candidates (void) parm = DECL_CHAIN (parm)) ret |= maybe_add_sra_candidate (parm); + /* fsra only care about parameters and returns */ + if (sra_mode == SRA_MODE_FINAL_INTRA) + { + if (!DECL_RESULT (current_function_decl)) + return ret; + + edge_iterator ei; + edge e; + FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds) + if (greturn *r = safe_dyn_cast (*gsi_last_bb (e->src))) + { + tree val = gimple_return_retval (r); + if (val && VAR_P (val)) + ret |= maybe_add_sra_candidate (val); + } + return ret; + } + FOR_EACH_LOCAL_DECL (cfun, i, var) { if (!VAR_P (var)) @@ -5017,6 +5039,14 @@ late_intra_sra (void) return perform_intra_sra (); } +/* Perform "final sra" intraprocedural SRA just before expander. */ +static unsigned int +final_intra_sra (void) +{ + sra_mode = SRA_MODE_FINAL_INTRA; + return perform_intra_sra (); +} + static bool gate_intra_sra (void) @@ -5099,3 +5129,42 @@ make_pass_sra (gcc::context *ctxt) { return new pass_sra (ctxt); } + +namespace +{ +const pass_data pass_data_sra_final = { + GIMPLE_PASS, /* type */ + "fsra", /* name */ + OPTGROUP_NONE, /* optinfo_flags */ + TV_TREE_SRA, /* tv_id */ + (PROP_cfg | PROP_ssa), /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + TODO_update_ssa, /* todo_flags_finish */ +}; + +class pass_sra_final : public gimple_opt_pass +{ +public: + pass_sra_final (gcc::context *ctxt) + : gimple_opt_pass (pass_data_sra_final, ctxt) + { + } + + /* opt_pass methods: */ + bool gate (function *) final override { return gate_intra_sra (); } + unsigned int execute (function *) final override + { + return final_intra_sra (); + } + +}; // class pass_sra_final + +} // namespace + +gimple_opt_pass * +make_pass_sra_final (gcc::context *ctxt) +{ + return new pass_sra_final (ctxt); +}