From patchwork Thu Oct 19 08:33:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lehua Ding X-Patchwork-Id: 155374 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp239505vqb; Thu, 19 Oct 2023 01:37:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpKjCc47iy9eXiuA3JHKnk/1PkTGpWumdVJYpylud2TUWpoNnwOwbgzRo9qwcIThoPVUJp X-Received: by 2002:a67:c098:0:b0:452:55f5:55e9 with SMTP id x24-20020a67c098000000b0045255f555e9mr1251905vsi.14.1697704620867; Thu, 19 Oct 2023 01:37:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697704620; cv=pass; d=google.com; s=arc-20160816; b=gthH+7tZiGR63mF7QbcrR48ISdasNgIaWXdj3XJ2OiSVPFkJDJSpxBU0xAyDnUr/3/ kTzCL3eQYkV/MPZUGWBOx/jb5CUZgxvmg3BakBqyZ+r49coKycMopixiV0vdxRjwb+sX xfBBNnGb22iyUXjUVYG1xY59b5P93SRbTu7U6coLIlHVMlrv+VEOqQEVWcFrTqd7hdQp MQcF6rtOZLcnBe1oTp5ahO23YfqVN1pjWndF/FH/IkGrB/r5xE/DLJTpTrw6P1G1xAb1 I6CbUQrgyJm3jGT+qFxX034LHXPR4I5z8M1cMr+2/12Ua/1AHH3DcJWPPbyjt3k/JiWb AXSg== 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:feedback-id :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-filter:dmarc-filter :delivered-to; bh=x77KLPcn+6tLao+a0qj0iShdymd/O/Zh77voeRt7878=; fh=x/Q0OlwHuvCZ3FpkiZPiUSvevOYVxUAi4aNnf76mUPQ=; b=kQp47oF44rTScE7s8+KMMKkNgndc3mNbfa6yXC/DhTLsC5JosT+Gz4T4jn2PIWwHCQ vjKasYbPpsBzDaadN0IcWJkG3Ah8O1TH/F5YEhKGWFgQIGmnboIEosh+pQeHmdDoMPiq DMbAazs1HB0G0GNq5ub3H48EJjIpzL/yNAM3yYkr/3atwvWApYgoA5sq91usLQZhvUO6 p7bVdD3TjbloJuYaXnjSpVzH5Fh0B75mMG2uaSEEibkQXVm+yR3VHFzOmadibP/Z0wrW VbjTjYdnIh7pSrOijswX8xdUkeZz0Md+fNXGDlChq8frfVXM58gVK9BFo5P5twgtZhM2 DUFg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); 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" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w9-20020a0562140b2900b00658561d243csi1179179qvj.16.2023.10.19.01.37.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 01:37:00 -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; arc=pass (i=1); 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 22043385DC03 for ; Thu, 19 Oct 2023 08:36:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgau2.qq.com (smtpbgau2.qq.com [54.206.34.216]) by sourceware.org (Postfix) with ESMTPS id A93DE3857355 for ; Thu, 19 Oct 2023 08:33:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A93DE3857355 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A93DE3857355 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.206.34.216 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697704442; cv=none; b=AttQfct/MbYXAKdiCk0Tql88XQe9Lmmyhm3gquQe4KxLnO/44s9sLy5U6bwcoe/lAvDgfvcA69J7IO9oeboGeX910oRY3oGT0gJ43rj+Zxa4accGs9uIMyVjZZ/ihIZEdKcH9AajdNYHvwTnUiGCQD/vt1Xbvsl+O1khitFkyeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697704442; c=relaxed/simple; bh=G0FWAculJBG0YJwRtFsod1OkOAUAzjJSPfXQNRoUi/Y=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=c0/Q+sTUE+5xXITMygNwHPiUxJUFpd3h9lMbhmxP6fLHF9QkQsMOxMz6VpUXBDJcygNpOKpRD+hhbnJopfb2y9PIs7uGXVbK7QpewFH3MVusnKD0+vEcY30UUqRWZ/TJ49LHMRZxg9jThpswa+FsWWz1VTZ1xw8D/kCXzzcZ81I= ARC-Authentication-Results: i=1; server2.sourceware.org X-QQ-mid: bizesmtp65t1697704432tlq52w00 Received: from rios-cad121.hadoop.rioslab.org ( [58.60.1.9]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 19 Oct 2023 16:33:51 +0800 (CST) X-QQ-SSF: 01400000000000C0F000000A0000000 X-QQ-FEAT: eTp2eCgHrZmdTVZGUnggptAXjwGd8EDJe0AgEac/gg4LA92L1AFbeJa6YTqS2 9WoT6usT6RnCpxiiMeZYjqH9Z5T8x3f8swg1EV1SOdz6Gzg8t9nrME8u8glaoXzBWxocOId gxpkXcQ9O005XGGd/GfzfhmTALptbO+VwY6pH4SBU3/9G3ttXjvBxYOy28u1EwsTgEfoDsk zcLVoF3JCi5NX1sVrZkrsDmJSw0Hd6CUXkTMEP4rktwFu3R+2KesK3B55TM+N0kbvTEzmtA sZ5p6Y1d6JZkkGrab2r51OszPArph/xT3IBBldWUn+rjKA+wYZNIP4YSIps0Lt/XyteaWOR ChRB7aNA36HwDEiYicX6m7YCfJHhkMeuSdvESSy0yJE1g7LWKEa9lsSe2kVF7LszBZ9Kkp1 X-QQ-GoodBg: 2 X-BIZMAIL-ID: 6836356960606838608 From: Lehua Ding To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, kito.cheng@gmail.com, rdapp.gcc@gmail.com, palmer@rivosinc.com, jeffreyalaw@gmail.com, lehua.ding@rivai.ai Subject: [PATCH V3 05/11] RISC-V: P5: Combine phase 1 and 2 Date: Thu, 19 Oct 2023 16:33:27 +0800 Message-Id: <20231019083333.2052340-6-lehua.ding@rivai.ai> X-Mailer: git-send-email 2.36.3 In-Reply-To: <20231019083333.2052340-1-lehua.ding@rivai.ai> References: <20231019083333.2052340-1-lehua.ding@rivai.ai> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz6a-0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, 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.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: 1780172320628333047 X-GMAIL-MSGID: 1780172320628333047 gcc/ChangeLog: * config/riscv/riscv-vsetvl.cc (pre_vsetvl::fuse_local_vsetvl_info): New. (pass_vsetvl::compute_local_backward_infos): Removed. (pass_vsetvl::need_vsetvl): Removed. (pass_vsetvl::transfer_before): Removed. (pass_vsetvl::transfer_after): Removed. (pass_vsetvl::emit_local_forward_vsetvls): Removed. --- gcc/config/riscv/riscv-vsetvl.cc | 270 ++++++++++++++----------------- 1 file changed, 124 insertions(+), 146 deletions(-) diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index f8b708c248a..dad3d7c941e 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -2722,6 +2722,130 @@ public: }; +void +pre_vsetvl::fuse_local_vsetvl_info () +{ + m_reg_def_loc + = sbitmap_vector_alloc (last_basic_block_for_fn (cfun), GP_REG_LAST + 1); + bitmap_vector_clear (m_reg_def_loc, last_basic_block_for_fn (cfun)); + bitmap_ones (m_reg_def_loc[ENTRY_BLOCK_PTR_FOR_FN (cfun)->index]); + + for (bb_info *bb : crtl->ssa->bbs ()) + { + auto &block_info = get_block_info (bb); + block_info.m_bb = bb; + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, " Try fuse basic block %d\n", bb->index ()); + } + auto_vec infos; + for (insn_info *insn : bb->real_nondebug_insns ()) + { + vsetvl_info curr_info = vsetvl_info (insn); + if (curr_info.valid_p () || curr_info.unknown_p ()) + infos.safe_push (curr_info); + + /* Collecting GP registers modified by the current bb. */ + if (insn->is_real ()) + for (def_info *def : insn->defs ()) + if (def->is_reg () && GP_REG_P (def->regno ())) + bitmap_set_bit (m_reg_def_loc[bb->index ()], def->regno ()); + } + + vsetvl_info prev_info = vsetvl_info (); + prev_info.set_empty (); + for (auto &curr_info : infos) + { + if (prev_info.empty_p ()) + prev_info = curr_info; + else if ((curr_info.unknown_p () && prev_info.valid_p ()) + || (curr_info.valid_p () && prev_info.unknown_p ())) + { + block_info.infos.safe_push (prev_info); + prev_info = curr_info; + } + else if (curr_info.valid_p () && prev_info.valid_p ()) + { + if (m_dem.available_p (prev_info, curr_info)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, + " Ignore curr info since prev info " + "available with it:\n"); + fprintf (dump_file, " prev_info: "); + prev_info.dump (dump_file, " "); + fprintf (dump_file, " curr_info: "); + curr_info.dump (dump_file, " "); + fprintf (dump_file, "\n"); + } + if (!curr_info.vl_use_by_non_rvv_insn_p () + && vsetvl_insn_p (curr_info.get_insn ()->rtl ())) + m_delete_list.safe_push (curr_info); + + if (curr_info.get_read_vl_insn ()) + prev_info.set_read_vl_insn (curr_info.get_read_vl_insn ()); + } + else if (m_dem.compatible_p (prev_info, curr_info)) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, " Fuse curr info since prev info " + "compatible with it:\n"); + fprintf (dump_file, " prev_info: "); + prev_info.dump (dump_file, " "); + fprintf (dump_file, " curr_info: "); + curr_info.dump (dump_file, " "); + } + m_dem.merge (prev_info, curr_info); + if (curr_info.get_read_vl_insn ()) + prev_info.set_read_vl_insn (curr_info.get_read_vl_insn ()); + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, " prev_info after fused: "); + prev_info.dump (dump_file, " "); + fprintf (dump_file, "\n"); + } + } + else + { + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, + " Cannot fuse uncompatible infos:\n"); + fprintf (dump_file, " prev_info: "); + prev_info.dump (dump_file, " "); + fprintf (dump_file, " curr_info: "); + curr_info.dump (dump_file, " "); + } + block_info.infos.safe_push (prev_info); + prev_info = curr_info; + } + } + } + + if (prev_info.valid_p () || prev_info.unknown_p ()) + block_info.infos.safe_push (prev_info); + } + + m_avl_regs = sbitmap_alloc (GP_REG_LAST + 1); + bitmap_clear (m_avl_regs); + for (const bb_info *bb : crtl->ssa->bbs ()) + { + vsetvl_block_info &block_info = get_block_info (bb); + if (block_info.empty_p ()) + continue; + + vsetvl_info &header_info = block_info.get_entry_info (); + if (header_info.valid_p () && header_info.has_nonvlmax_reg_avl ()) + { + gcc_assert (GP_REG_P (REGNO (header_info.get_avl ()))); + bitmap_set_bit (m_avl_regs, REGNO (header_info.get_avl ())); + } + } +} + + const pass_data pass_data_vsetvl = { RTL_PASS, /* type */ "vsetvl", /* name */ @@ -2860,152 +2984,6 @@ make_pass_vsetvl (gcc::context *ctxt) return new pass_vsetvl (ctxt); } -/* Compute demanded information by backward data-flow analysis. */ -void -pass_vsetvl::compute_local_backward_infos (const bb_info *bb) -{ - vector_insn_info change; - change.set_empty (); - - auto &block_info = m_vector_manager->vector_block_infos[bb->index ()]; - block_info.reaching_out = change; - - for (insn_info *insn : bb->reverse_real_nondebug_insns ()) - { - auto &info = get_vector_info (insn); - - if (info.uninit_p ()) - /* If it is uninitialized, propagate it directly. */ - update_vector_info (insn, change); - else if (info.unknown_p ()) - change = info; - else - { - gcc_assert (info.valid_p () && "Unexpected Invalid demanded info"); - if (change.valid_p ()) - { - if (!(propagate_avl_across_demands_p (change, info) - && !reg_available_p (insn, change)) - && change.compatible_p (info)) - { - update_vector_info (insn, change.local_merge (info)); - /* Fix PR109399, we should update user vsetvl instruction - if there is a change in demand fusion. */ - if (vsetvl_insn_p (insn->rtl ())) - change_vsetvl_insn (insn, info); - } - } - change = info; - } - } - - block_info.local_dem = change; - if (block_info.local_dem.empty_p ()) - block_info.reaching_out = block_info.local_dem; -} - -/* Return true if a dem_info is required to transition from curr_info to - require before INSN. */ -bool -pass_vsetvl::need_vsetvl (const vector_insn_info &require, - const vector_insn_info &curr_info) const -{ - if (!curr_info.valid_p () || curr_info.unknown_p () || curr_info.uninit_p ()) - return true; - - if (require.compatible_p (static_cast (curr_info))) - return false; - - return true; -} - -/* Given an incoming state reaching INSN, modifies that state so that it is - minimally compatible with INSN. The resulting state is guaranteed to be - semantically legal for INSN, but may not be the state requested by INSN. */ -void -pass_vsetvl::transfer_before (vector_insn_info &info, insn_info *insn) const -{ - if (!has_vtype_op (insn->rtl ())) - return; - - const vector_insn_info require = get_vector_info (insn); - if (info.valid_p () && !need_vsetvl (require, info)) - return; - info = require; -} - -/* Given a state with which we evaluated insn (see transfer_before above for why - this might be different that the state insn requested), modify the state to - reflect the changes insn might make. */ -void -pass_vsetvl::transfer_after (vector_insn_info &info, insn_info *insn) const -{ - if (vector_config_insn_p (insn->rtl ())) - { - info = get_vector_info (insn); - return; - } - - if (fault_first_load_p (insn->rtl ()) - && info.update_fault_first_load_avl (insn)) - return; - - /* If this is something that updates VL/VTYPE that we don't know about, set - the state to unknown. */ - if (insn->is_call () || insn->is_asm () - || find_access (insn->defs (), VL_REGNUM) - || find_access (insn->defs (), VTYPE_REGNUM)) - info = vector_insn_info::get_unknown (); -} - -/* Emit vsetvl within each block by forward data-flow analysis. */ -void -pass_vsetvl::emit_local_forward_vsetvls (const bb_info *bb) -{ - auto &block_info = m_vector_manager->vector_block_infos[bb->index ()]; - if (block_info.local_dem.empty_p ()) - return; - - vector_insn_info curr_info; - for (insn_info *insn : bb->real_nondebug_insns ()) - { - const vector_insn_info prev_info = curr_info; - enum vsetvl_type type = NUM_VSETVL_TYPE; - transfer_before (curr_info, insn); - - if (has_vtype_op (insn->rtl ())) - { - if (static_cast (prev_info) - != static_cast (curr_info)) - { - const auto require = get_vector_info (insn); - if (!require.compatible_p ( - static_cast (prev_info))) - type = insert_vsetvl (EMIT_BEFORE, insn->rtl (), require, - prev_info); - } - } - - /* Fix the issue of following sequence: - vsetivli zero, 5 - .... - vsetvli zero, zero - vmv.x.s (demand AVL = 8). - .... - incorrect: vsetvli zero, zero ===> Since the curr_info is AVL = 8. - correct: vsetivli zero, 8 - vadd (demand AVL = 8). */ - if (type == VSETVL_VTYPE_CHANGE_ONLY) - { - /* Update the curr_info to be real correct AVL. */ - curr_info.set_avl_info (prev_info.get_avl_info ()); - } - transfer_after (curr_info, insn); - } - - block_info.reaching_out = curr_info; -} - /* Assemble the candidates expressions for LCM. */ void pass_vsetvl::prune_expressions (void)