From patchwork Mon Aug 14 05:41:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiufu Guo X-Patchwork-Id: 135133 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp2537954vqi; Sun, 13 Aug 2023 22:43:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH0IYFnyyz8FyFzHXnbganYgQX3ur0dgXUZFmo4/7C5NP7XupsmpnoKlVgz0VWaYDpGaMLF X-Received: by 2002:a05:6512:692:b0:4f8:7325:bcd4 with SMTP id t18-20020a056512069200b004f87325bcd4mr7363294lfe.0.1691991791663; Sun, 13 Aug 2023 22:43:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691991791; cv=none; d=google.com; s=arc-20160816; b=d79yMo7uXW/qQCW+bm14zErhEt3nOsRwrR9df66Ij7gbRUz/cXFwH3NJQj0lcw/8z8 WTprSu0oiAOpiSu7SdvNyeRTAyCzUNmYwBg+ia+G4TbR5FuvpYaVMmooeXoqc/ivo8Cl GPR+QofZtRbg7QlVhOnkxxo1CaUohpLST1HOjrgd6AVzSJtEY5LsP3CaBNCxvaeXqVCE eT1L+L9jj4UuHNQzb5EdtpCpGL/9V65FenKEMMRwxczd3P++ZpaXBlg9eNfYhE9R1nyO 0rYiSz/aMnK9mUSKJHXLhviedrPqcchDR7FwdVR/ApZHJIyWpurgaJdT5C5i7OA+tNuG qJ4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=xidu/TCt5POmUvDdNxUSPuxebLxii3ALXgSwmwTtJ6E=; fh=LwpA6VWkZpYvfqjT3jkuGnHXRwVGI2wu5tey08t2PNA=; b=n7538a1l1S9u71tcllzzk6zHwU9e2Re51dDXm5jzUC3Qjc0gpBuhO3XlUlr7czZzIT 0vT7eLni+lKLfB97SQPZrAdxFUtFq6MPfjXyHy+rtpgsM2qYkEL5Cg351lvt8mDW3bXm ik5o8ffQ8tIxRQMyvCc6SvkI371Uhwb7cpe5FleQ0TK0Tlae6Nqv1GxnEF0LNajFdvL4 Cq4Us1++z6dHxDnzWkarXd0HF3vl4HTGWqOimTvlRgGbrY2a0vaXHEcvvB3tBxr7yW4S 84nwTjbzwLaUozVTDiFaB6fMDgepcZF3K/qAxAanjYEzTJiX671TQmOuSMSlJfpRxNUQ ctwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=oCaicZcj; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ay2-20020a056402202200b005254561b160si3161416edb.483.2023.08.13.22.43.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Aug 2023 22:43:11 -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=oCaicZcj; 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 7BA743857718 for ; Mon, 14 Aug 2023 05:42:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7BA743857718 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691991779; bh=xidu/TCt5POmUvDdNxUSPuxebLxii3ALXgSwmwTtJ6E=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=oCaicZcjZxmUJ0P60AGnCKj8YkEM9T1xvCVpJ/rn9svD6GGz9pKbOzhBf8lQwT/qJ FKK7cumgI0aL4t0LiYPdTNdPfoYB3AyE1URXuui70POH0wJ5bgXpDFf74QtrNmwDcZ //RW1QFVoZuFMeOPfdVQt8vetvpoS5iU6Vd91t4o= 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 A92CF3858CDA; Mon, 14 Aug 2023 05:42:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A92CF3858CDA Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37E5ZrIJ026338; Mon, 14 Aug 2023 05:42:06 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sfe5f05qr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 14 Aug 2023 05:42:05 +0000 Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 37E5bSDf029764; Mon, 14 Aug 2023 05:42:05 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3sfe5f05q8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 14 Aug 2023 05:42:05 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 37E56XeV001119; Mon, 14 Aug 2023 05:42:03 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3semsxsuhf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 14 Aug 2023 05:42:03 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 37E5g0Q426739326 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 14 Aug 2023 05:42:00 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8BCAB2004D; Mon, 14 Aug 2023 05:42:00 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 38E3C20040; Mon, 14 Aug 2023 05:41:59 +0000 (GMT) Received: from genoa.aus.stglabs.ibm.com (unknown [9.40.192.157]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 14 Aug 2023 05:41:59 +0000 (GMT) To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, jeffreyalaw@gmail.com, richard.sandiford@arm.com, segher@kernel.crashing.org, linkw@gcc.gnu.org, bergner@linux.ibm.com, guojiufu@linux.ibm.com Subject: [PATCH 2/2] combine nonconstant_array walker and expander_sra walker Date: Mon, 14 Aug 2023 13:41:56 +0800 Message-Id: <20230814054156.2068718-2-guojiufu@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230814054156.2068718-1-guojiufu@linux.ibm.com> References: <20230814054156.2068718-1-guojiufu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: j0gyhAlaThGjwbQwtHRHOWh0yR-YMTqP X-Proofpoint-GUID: wFtTJa-YC3DGwYojLM4mfI4FyDrIlbL_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-08-13_24,2023-08-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 clxscore=1015 priorityscore=1501 mlxlogscore=999 malwarescore=0 mlxscore=0 spamscore=0 phishscore=0 impostorscore=0 adultscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2308140051 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, 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: Jiufu Guo via Gcc-patches From: Jiufu Guo Reply-To: Jiufu Guo Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774181985018686329 X-GMAIL-MSGID: 1774181985018686329 Hi, In the light-expander-sra, each statement in each basic-block of a function need to be analyzed, and there is a similar behavior in checking variable which need to be stored in the stack. These per-stmt analyses can be combined to improve cache locality. Bootstrapped and regtested on x86_64-redhat-linux, and powerpc64{,le}-linux-gnu. Is it ok for trunk? BR, Jeff (Jiufu Guo) gcc/ChangeLog: * cfgexpand.cc (discover_nonconstant_array_refs): Deleted. (struct array_and_sra_walk): New class. (pass_expand::execute): Call scan_function on array_and_sra_walk. --- gcc/cfgexpand.cc | 104 +++++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc index 21a09ebac96bbcddc67da73c42f470c6d5f60e6c..dc3ebe45275cc4b1c0873b4c6e5f6cbe2491ab8c 100644 --- a/gcc/cfgexpand.cc +++ b/gcc/cfgexpand.cc @@ -6843,59 +6843,59 @@ avoid_type_punning_on_regs (tree t, bitmap forced_stack_vars) bitmap_set_bit (forced_stack_vars, DECL_UID (base)); } -/* RTL expansion is not able to compile array references with variable - offsets for arrays stored in single register. Discover such - expressions and mark variables as addressable to avoid this - scenario. */ +/* Beside light-sra, walk stmts to discover expressions of array references + with variable offsets for arrays and mark variables as addressable to + avoid to be stored in single register. */ -static void -discover_nonconstant_array_refs (bitmap forced_stack_vars) +struct array_and_sra_walk : public expand_sra { - basic_block bb; - gimple_stmt_iterator gsi; + array_and_sra_walk (bitmap map) : wi{}, forced_stack_vars (map) + { + wi.info = forced_stack_vars; + }; - walk_stmt_info wi = {}; - wi.info = forced_stack_vars; - FOR_EACH_BB_FN (bb, cfun) - for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + void pre_analyze_stmt (gimple *stmt) + { + expand_sra::pre_analyze_stmt (stmt); + if (!is_gimple_debug (stmt)) + walk_gimple_op (stmt, discover_nonconstant_array_refs_r, &wi); + if (gimple_vdef (stmt)) { - gimple *stmt = gsi_stmt (gsi); - if (!is_gimple_debug (stmt)) + tree t = gimple_get_lhs (stmt); + if (t && REFERENCE_CLASS_P (t)) + avoid_type_punning_on_regs (t, forced_stack_vars); + } + } + + void analyze_call (gcall *call) + { + expand_sra::analyze_call (call); + if (gimple_call_internal_p (call)) + { + tree cand = NULL_TREE; + switch (gimple_call_internal_fn (call)) { - walk_gimple_op (stmt, discover_nonconstant_array_refs_r, &wi); - gcall *call = dyn_cast (stmt); - if (call && gimple_call_internal_p (call)) - { - tree cand = NULL_TREE; - switch (gimple_call_internal_fn (call)) - { - case IFN_LOAD_LANES: - /* The source must be a MEM. */ - cand = gimple_call_arg (call, 0); - break; - case IFN_STORE_LANES: - /* The destination must be a MEM. */ - cand = gimple_call_lhs (call); - break; - default: - break; - } - if (cand) - cand = get_base_address (cand); - if (cand - && DECL_P (cand) - && use_register_for_decl (cand)) - bitmap_set_bit (forced_stack_vars, DECL_UID (cand)); - } - if (gimple_vdef (stmt)) - { - tree t = gimple_get_lhs (stmt); - if (t && REFERENCE_CLASS_P (t)) - avoid_type_punning_on_regs (t, forced_stack_vars); - } + case IFN_LOAD_LANES: + /* The source must be a MEM. */ + cand = gimple_call_arg (call, 0); + break; + case IFN_STORE_LANES: + /* The destination must be a MEM. */ + cand = gimple_call_lhs (call); + break; + default: + break; } + if (cand) + cand = get_base_address (cand); + if (cand && DECL_P (cand) && use_register_for_decl (cand)) + bitmap_set_bit (forced_stack_vars, DECL_UID (cand)); } -} + }; + + walk_stmt_info wi; + bitmap forced_stack_vars; +}; /* This function sets crtl->args.internal_arg_pointer to a virtual register if DRAP is needed. Local register allocator will replace @@ -7091,12 +7091,12 @@ pass_expand::execute (function *fun) avoid_deep_ter_for_debug (gsi_stmt (gsi), 0); } - /* Mark arrays indexed with non-constant indices with TREE_ADDRESSABLE. */ + /* Mark arrays indexed with non-constant indices with TREE_ADDRESSABLE. + And scan expressions for possible SRA accesses. */ auto_bitmap forced_stack_vars; - discover_nonconstant_array_refs (forced_stack_vars); - - current_sra = new expand_sra; - scan_function (cfun, *current_sra); + array_and_sra_walk *walker = new array_and_sra_walk (forced_stack_vars); + current_sra = walker; + scan_function (cfun, *walker); /* Make sure all values used by the optimization passes have sane defaults. */ @@ -7526,7 +7526,7 @@ pass_expand::execute (function *fun) loop_optimizer_finalize (); } - delete current_sra; + delete walker; current_sra = NULL; timevar_pop (TV_POST_EXPAND);