From patchwork Mon Jul 10 07:56:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "juzhe.zhong@rivai.ai" X-Patchwork-Id: 117679 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp4856285vqx; Mon, 10 Jul 2023 00:56:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlE+O48QyG2wG/8ErXeaIN1o1tzM/8JCmzK4IxbsxG3b2JoLMagwxRmyDBYfer0rTxrxtZP8 X-Received: by 2002:a05:6512:3090:b0:4f8:4512:c844 with SMTP id z16-20020a056512309000b004f84512c844mr10647680lfd.48.1688975802217; Mon, 10 Jul 2023 00:56:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688975802; cv=none; d=google.com; s=arc-20160816; b=CSwNVwda+fwz3ADlS7emjgDMIBa7luE5eQAzUxrPq+m4pSANAR4Q/FArUWarGDPHUU 4bVztonBiO3UhFX20GbHNnLFTkhjSyj2lJ3AA+Q/I6ckXRAQ09NbSFmJie43oacXbKEt BICWN51cW1rscpcE08GSgRVza9gxx4Td5rKbgZ5T91ebwzCPWGzyocMWGmTdhQ7GFvmX QmNAFqvU+MHM/XRCGj72pTewvlHYko8RpBdvm+XA07m1tLnvBnYRWFp4MEaIcVDBZmcf xjNSGDqHmjtmVcKtVnB5X8HrPIlG1I9sxTovF8yws61ZWTlpLzFLqPLQylgi3pgqBjph wOcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:feedback-id :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dmarc-filter:delivered-to; bh=Vpm9aCU03nTaVTkgwfkHrzxoHhex93qPgtObqUZFMjg=; fh=7RKA5lOre88ge/fWDb81f+Rb7lYCQO78QvjpyWj/w44=; b=omAwVEE/mkDS+4xfG3OaBFKwILcxeajAptw23yLdrlqpc278v9Oa9H2ijExXZcAhPf 3WmeYEo9JGbXUOGe5qLfoyww55OgQlBmUbfnGynw0lifuu+cyfoh4xviEd+3d8C5kc/1 CNWg1hTotxCRmN21Ml/2OTL9VaV6NvVqoaJJ+FDAGND5jZdWkcs/tVBdprfEboN7P1VB aMb4O65UMMT+s9dz+1VerCY4Ixegje7KzSpFwFhJWz2+6z3O6n050Xm+RZJ2iDsr6xqf xlx/mHTJ7b3QeydC8DPVaz+DFBWw9tiql6dPMYxIkYz86Z+usUThMwbNIM9O22Ba5tt6 Kj/A== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u2-20020aa7d882000000b0051e0f9bf73bsi8098716edq.261.2023.07.10.00.56.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 00:56:42 -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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A26073857C4F for ; Mon, 10 Jul 2023 07:56:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbg153.qq.com (smtpbg153.qq.com [13.245.218.24]) by sourceware.org (Postfix) with ESMTPS id 02A943858D32 for ; Mon, 10 Jul 2023 07:56:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 02A943858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai X-QQ-mid: bizesmtp63t1688975762ta6gl3d0 Received: from server1.localdomain ( [58.60.1.22]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 10 Jul 2023 15:56:01 +0800 (CST) X-QQ-SSF: 01400000000000G0T000000A0000000 X-QQ-FEAT: 5QxEZ1enDv/9JDWf792BGKgZa6mvVetM4WKwbu4idkRkNu6Zs0rq+haBLSMp2 wfMD5eNUYCTtqBJ+8TOIRzsxiuHO/VP90RY5WbO/UXJeEcZYlsR6su/JcfYG93FLf5KmCQm P+d8c7eC0jy/aSDf6z2xtY9pl6y5BlzmfQmQWdZv3EUC5J8TP6NpEfWccT2LnzrU3oFJLDE u1savH78DAdClvG32a4otThYqOUWKw6yyqX7AzZi9Xg/E1NUWHKB0IEk5yXn+67opih3Obq ZmAhw6enqfavfzrpx5Dyye/QRiQbEqGm26gZ8vzxCOAY1JpGY7BkM2iMuI74ZgRAPu3vkJh oog8vkma3/yHFozXqML1GbfP94wN4RORfIPz0pQuDF+m9dlgcXDFMoi0pYRweLKWlyY+fsE cqS4X/OPuoY= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 2159226014021011936 From: juzhe.zhong@rivai.ai To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, jeffreyalaw@gmail.com, Ju-Zhe Zhong Subject: [PATCH] GCSE: Export 'insert_insn_end_basic_block' as global function Date: Mon, 10 Jul 2023 15:56:00 +0800 Message-Id: <20230710075600.114191-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz7a-one-0 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, 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: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771019490843445263 X-GMAIL-MSGID: 1771019490843445263 From: Ju-Zhe Zhong Since VSETVL PASS in RISC-V port is using common part of 'insert_insn_end_basic_block (struct gcse_expr *expr, basic_block bb)' and we will also this helper function in riscv.cc for the following patches. So extract the common part codes of 'insert_insn_end_basic_block (struct gcse_expr *expr, basic_block bb)', the new function of the common part is also call 'insert_insn_end_basic_block (rtx_insn *pat, basic_block bb)' but with different arguments. And call 'insert_insn_end_basic_block (rtx_insn *pat, basic_block bb)' in 'insert_insn_end_basic_block (struct gcse_expr *expr, basic_block bb)' and VSETVL PASS in RISC-V port. Remove redundant codes of VSETVL PASS in RISC-V port. gcc/ChangeLog: * config/riscv/riscv-vsetvl.cc (add_label_notes): Remove it. (insert_insn_end_basic_block): Ditto. (pass_vsetvl::commit_vsetvls): Adapt for new helper function. * gcse.cc (insert_insn_end_basic_block): Export as global function. * gcse.h (insert_insn_end_basic_block): Ditto. --- gcc/config/riscv/riscv-vsetvl.cc | 128 +------------------------------ gcc/gcse.cc | 24 ++++-- gcc/gcse.h | 1 + 3 files changed, 23 insertions(+), 130 deletions(-) diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index ab47901e23f..586dc8e5379 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -98,6 +98,7 @@ along with GCC; see the file COPYING3. If not see #include "lcm.h" #include "predict.h" #include "profile-count.h" +#include "gcse.h" #include "riscv-vsetvl.h" using namespace rtl_ssa; @@ -763,127 +764,6 @@ insert_vsetvl (enum emit_type emit_type, rtx_insn *rinsn, return VSETVL_DISCARD_RESULT; } -/* If X contains any LABEL_REF's, add REG_LABEL_OPERAND notes for them - to INSN. If such notes are added to an insn which references a - CODE_LABEL, the LABEL_NUSES count is incremented. We have to add - that note, because the following loop optimization pass requires - them. */ - -/* ??? If there was a jump optimization pass after gcse and before loop, - then we would not need to do this here, because jump would add the - necessary REG_LABEL_OPERAND and REG_LABEL_TARGET notes. */ - -static void -add_label_notes (rtx x, rtx_insn *rinsn) -{ - enum rtx_code code = GET_CODE (x); - int i, j; - const char *fmt; - - if (code == LABEL_REF && !LABEL_REF_NONLOCAL_P (x)) - { - /* This code used to ignore labels that referred to dispatch tables to - avoid flow generating (slightly) worse code. - - We no longer ignore such label references (see LABEL_REF handling in - mark_jump_label for additional information). */ - - /* There's no reason for current users to emit jump-insns with - such a LABEL_REF, so we don't have to handle REG_LABEL_TARGET - notes. */ - gcc_assert (!JUMP_P (rinsn)); - add_reg_note (rinsn, REG_LABEL_OPERAND, label_ref_label (x)); - - if (LABEL_P (label_ref_label (x))) - LABEL_NUSES (label_ref_label (x))++; - - return; - } - - for (i = GET_RTX_LENGTH (code) - 1, fmt = GET_RTX_FORMAT (code); i >= 0; i--) - { - if (fmt[i] == 'e') - add_label_notes (XEXP (x, i), rinsn); - else if (fmt[i] == 'E') - for (j = XVECLEN (x, i) - 1; j >= 0; j--) - add_label_notes (XVECEXP (x, i, j), rinsn); - } -} - -/* Add EXPR to the end of basic block BB. - - This is used by both the PRE and code hoisting. */ - -static void -insert_insn_end_basic_block (rtx_insn *rinsn, basic_block cfg_bb) -{ - rtx_insn *end_rinsn = BB_END (cfg_bb); - rtx_insn *new_insn; - rtx_insn *pat, *pat_end; - - pat = rinsn; - gcc_assert (pat && INSN_P (pat)); - - pat_end = pat; - while (NEXT_INSN (pat_end) != NULL_RTX) - pat_end = NEXT_INSN (pat_end); - - /* If the last end_rinsn is a jump, insert EXPR in front. Similarly we need - to take care of trapping instructions in presence of non-call exceptions. - */ - - if (JUMP_P (end_rinsn) - || (NONJUMP_INSN_P (end_rinsn) - && (!single_succ_p (cfg_bb) - || single_succ_edge (cfg_bb)->flags & EDGE_ABNORMAL))) - { - /* FIXME: What if something in jump uses value set in new end_rinsn? */ - new_insn = emit_insn_before_noloc (pat, end_rinsn, cfg_bb); - } - - /* Likewise if the last end_rinsn is a call, as will happen in the presence - of exception handling. */ - else if (CALL_P (end_rinsn) - && (!single_succ_p (cfg_bb) - || single_succ_edge (cfg_bb)->flags & EDGE_ABNORMAL)) - { - /* Keeping in mind targets with small register classes and parameters - in registers, we search backward and place the instructions before - the first parameter is loaded. Do this for everyone for consistency - and a presumption that we'll get better code elsewhere as well. */ - - /* Since different machines initialize their parameter registers - in different orders, assume nothing. Collect the set of all - parameter registers. */ - end_rinsn = find_first_parameter_load (end_rinsn, BB_HEAD (cfg_bb)); - - /* If we found all the parameter loads, then we want to insert - before the first parameter load. - - If we did not find all the parameter loads, then we might have - stopped on the head of the block, which could be a CODE_LABEL. - If we inserted before the CODE_LABEL, then we would be putting - the end_rinsn in the wrong basic block. In that case, put the - end_rinsn after the CODE_LABEL. Also, respect NOTE_INSN_BASIC_BLOCK. - */ - while (LABEL_P (end_rinsn) || NOTE_INSN_BASIC_BLOCK_P (end_rinsn)) - end_rinsn = NEXT_INSN (end_rinsn); - - new_insn = emit_insn_before_noloc (pat, end_rinsn, cfg_bb); - } - else - new_insn = emit_insn_after_noloc (pat, end_rinsn, cfg_bb); - - while (1) - { - if (INSN_P (pat)) - add_label_notes (PATTERN (pat), new_insn); - if (pat == pat_end) - break; - pat = NEXT_INSN (pat); - } -} - /* Get VL/VTYPE information for INSN. */ static vl_vtype_info get_vl_vtype_info (const insn_info *insn) @@ -4126,13 +4006,13 @@ pass_vsetvl::commit_vsetvls (void) emit_insn (new_pat); rtx_insn *rinsn = get_insns (); end_sequence (); - insert_insn_end_basic_block (rinsn, cfg_bb); + rtx_insn *new_insn = insert_insn_end_basic_block (rinsn, cfg_bb); if (dump_file) { fprintf (dump_file, "\nInsert vsetvl insn %d at the end of :\n", - INSN_UID (rinsn), cfg_bb->index); - print_rtl_single (dump_file, rinsn); + INSN_UID (new_insn), cfg_bb->index); + print_rtl_single (dump_file, new_insn); } } diff --git a/gcc/gcse.cc b/gcc/gcse.cc index 72832736572..a954122fcb7 100644 --- a/gcc/gcse.cc +++ b/gcc/gcse.cc @@ -2015,16 +2015,13 @@ process_insert_insn (struct gcse_expr *expr) This is used by both the PRE and code hoisting. */ -static void -insert_insn_end_basic_block (struct gcse_expr *expr, basic_block bb) +rtx_insn * +insert_insn_end_basic_block (rtx_insn *pat, basic_block bb) { rtx_insn *insn = BB_END (bb); rtx_insn *new_insn; - rtx reg = expr->reaching_reg; - int regno = REGNO (reg); - rtx_insn *pat, *pat_end; + rtx_insn *pat_end; - pat = process_insert_insn (expr); gcc_assert (pat && INSN_P (pat)); pat_end = pat; @@ -2084,6 +2081,21 @@ insert_insn_end_basic_block (struct gcse_expr *expr, basic_block bb) break; pat = NEXT_INSN (pat); } + return new_insn; +} + +/* Add EXPR to the end of basic block BB. + + This is used by both the PRE and code hoisting. */ + +static void +insert_insn_end_basic_block (struct gcse_expr *expr, basic_block bb) +{ + rtx reg = expr->reaching_reg; + int regno = REGNO (reg); + + rtx_insn *insn = process_insert_insn (expr); + rtx_insn *new_insn = insert_insn_end_basic_block (insn, bb); gcse_create_count++; diff --git a/gcc/gcse.h b/gcc/gcse.h index 5582b29eec2..e68afdcea21 100644 --- a/gcc/gcse.h +++ b/gcc/gcse.h @@ -41,5 +41,6 @@ extern struct target_gcse *this_target_gcse; void gcse_cc_finalize (void); extern bool gcse_or_cprop_is_too_expensive (const char *); +extern rtx_insn *insert_insn_end_basic_block (rtx_insn *, basic_block); #endif