From patchwork Tue Oct 17 11:34:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lehua Ding X-Patchwork-Id: 154128 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4074247vqb; Tue, 17 Oct 2023 04:49:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlm5uTgU5M6o9NQIArzfyFbHZs+/wr54v4DQQuGYbWW3o8WrOsTNZm8A3QADJslSrGYYp9 X-Received: by 2002:a05:620a:d8b:b0:777:73d3:1f55 with SMTP id q11-20020a05620a0d8b00b0077773d31f55mr1850071qkl.6.1697543358427; Tue, 17 Oct 2023 04:49:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697543358; cv=pass; d=google.com; s=arc-20160816; b=SiGA6pUirQ4YkgPtKp3q7sBaw0UMm3eW33MpeoDMFYC0Q4VVBeoW8rosOhUvFMLkeV fACsMPtU5p9Kt9ZKG6PGxYnFrdUrRM6ElBHqiDV/sEc3Ow60wt0xpMl+y9f8LL/hAgD4 Kvl+fl4AxVI5+5dSF7q216igLUcxFkSeBfuipk1DqBc5Jf/sj0uXkiPk4u2pmwe2HXHy Thv9y3BBnBjpozd1beHHAge+NZ1HfUM8Wjl9ZA4r93C6TMyzKU1OtXfUCGI7K+k41dsK Kx4LiT3YkGugPVpnHETvlloJ3derijUU9NoMoXOjcoEJkMdDlx7umCHlWayeho8Yc+FZ /lHg== 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=99YlImGbjYvdPJZlcHfMJq9U2JYZZrRhC3Qi+fjx/LQ=; fh=x/Q0OlwHuvCZ3FpkiZPiUSvevOYVxUAi4aNnf76mUPQ=; b=VR77UXXB3jAOzZo4U2BYrJFFfIESu/i3HGLDyDI8tlr2mG+IRx5n7MjBWtMgyr2pww Cu1Jw+2d42v251kNSPsTPEfYQT9wtdT0fFREahelDQW3TECBsgyHu3EHgbymOimQnRai hClYjir7j6r8EaDPY4JD3Hx1WWVzHOM74s0rmXdKEu80q1SBJtCrABKzY65wdp/EbGGr WjfKhL2jWl8YWX7uif4kE+/0EJPe5gfBLoyHJOAyTMJogOETGhoBg2axDK3wEDRrEeUQ 8Ci0moDlCeRjr0w2O8i95A6oHvDK1RRs7ouVCcSqZBksVG3QYrhwQWIaQi54RWuZo4+S fGsA== 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 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 d12-20020a37c40c000000b0076d92088466si926612qki.122.2023.10.17.04.49.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:49:18 -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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A74B13883023 for ; Tue, 17 Oct 2023 11:47:50 +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 A924C3856976 for ; Tue, 17 Oct 2023 11:36:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A924C3856976 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 A924C3856976 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=1697542564; cv=none; b=raTXapOkQmGYNl8k1PSA/QL9bcKUuFqQzBsLvAtRQAhCv/Mgq8M9aLkLwuidQiD3/7EIK+mI/SGM2QQIMG2fsaIlzdsktVEbGyKkGoJkGLEhk1OdalCPn/SXEprs0QdhKioBWcPsv8b4RscWvpxkXm32JduzGMuwVd8Gr0a35SE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697542564; c=relaxed/simple; bh=wJLa9r4ODGWJ8i8k7HY0qD9wNqtg3xQi+OuwdvYglTc=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=vdZdg9wvuBTEcZkINU4Nd+XafQBCu3AwFM4qdNfPqGE82DETylQkoudsYyuedOnQrg7is6D8CrQwTZwAuGA3rC4jOlqd0k6CTaZf6DTJ5K0CZXHFBDdUQ0H39brgXOSMdBOVqnsCLCqpURSkSH3y4ftm3ZQpf9tnRMS2PiEcvH8= ARC-Authentication-Results: i=1; server2.sourceware.org X-QQ-mid: bizesmtp62t1697542554t1nh5qw7 Received: from rios-cad121.hadoop.rioslab.org ( [58.60.1.9]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 17 Oct 2023 19:35:53 +0800 (CST) X-QQ-SSF: 01400000000000C0F000000A0000000 X-QQ-FEAT: V0qnkXF7A2ja7XX4Y7mT6DzLBlscHDjestOSnhIjziebFs/EJtj4/tg5CZnAk UuOGE2pVMMuXlj51/z8IGoiYqpZK8tQ/qSSTx4gM2EnwnYEoTwbEah1YSYozf8UPSZ/kAul NYTFanRoGoDMk6YlnSqnJ7Ccx+qGTOEn4aFYwhTqCVn8nELS1DePDj54oB7XzZJHgWN1AcY 768gnWgj/Ei7yS87V5wHWz+pyUxWs7VzLYoAN7/+Sk667OVB2T0I8yqidVBWLAoh2XM4ezk Bh+icmvxlIbPdG3TQDWL2k2pIFmhDNIm7MyAJWp6bK3ynIGQ1pp8k8ydiz2JgvP0bT7eQ+k 4+pGCgBufTVnE28fT3ep3L3C3ptaHIjLNvp4ZBOI1spHBxBPRTQ22QVhaGAx4mER9abpKYq vpMrNXeb8MQ= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 14976139417231915912 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 V2 13/14] RISC-V: P13: Reorganize functions used to modify RTL Date: Tue, 17 Oct 2023 19:34:59 +0800 Message-Id: <20231017113500.1160997-14-lehua.ding@rivai.ai> X-Mailer: git-send-email 2.36.3 In-Reply-To: <20231017113500.1160997-1-lehua.ding@rivai.ai> References: <20231017113500.1160997-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.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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: 1780003224391320358 X-GMAIL-MSGID: 1780003224391320358 This sub-patch reoriganize the functions that used to modify RTL. gcc/ChangeLog: * config/riscv/riscv-vsetvl.cc (has_no_uses): Moved. (validate_change_or_fail): Moved. (gen_vsetvl_pat): Removed. (emit_vsetvl_insn): Removed. (eliminate_insn): Removed. (change_insn): Removed. (change_vsetvl_insn): New. (pre_vsetvl::emit_vsetvl): New. (pre_vsetvl::remove_avl_operand): Adjust. (pre_vsetvl::remove_unused_dest_operand): Adjust. (pass_vsetvl::simple_vsetvl): Adjust. --- gcc/config/riscv/riscv-vsetvl.cc | 443 ++++++++++++------------------- 1 file changed, 176 insertions(+), 267 deletions(-) -- 2.36.3 diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index d91b0272d9f..78816cbee15 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -680,6 +680,30 @@ get_bb_index (unsigned expr_id, unsigned num_bb) return expr_id % num_bb; } +/* Return true if the SET result is not used by any instructions. */ +static bool +has_no_uses (basic_block cfg_bb, rtx_insn *rinsn, int regno) +{ + if (bitmap_bit_p (df_get_live_out (cfg_bb), regno)) + return false; + + rtx_insn *iter; + for (iter = NEXT_INSN (rinsn); iter && iter != NEXT_INSN (BB_END (cfg_bb)); + iter = NEXT_INSN (iter)) + if (df_find_use (iter, regno_reg_rtx[regno])) + return false; + + return true; +} + +/* Change insn and Assert the change always happens. */ +static void +validate_change_or_fail (rtx object, rtx *loc, rtx new_rtx, bool in_group) +{ + bool change_p = validate_change (object, loc, new_rtx, in_group); + gcc_assert (change_p); +} + /* This flags indicates the minimum demand of the vl and vtype values by the RVV instruction. For example, DEMAND_RATIO_P indicates that this RVV instruction only needs the SEW/LMUL ratio to remain the same, and does not @@ -1126,6 +1150,28 @@ public: } } + /* Returns the corresponding vsetvl rtx pat. */ + rtx get_vsetvl_pat (bool ignore_vl = false) const + { + rtx avl = get_avl (); + /* if optimization == 0 and the instruction is vmv.x.s/vfmv.f.s, + set the value of avl to (const_int 0) so that VSETVL PASS will + insert vsetvl correctly.*/ + if (!get_avl ()) + avl = GEN_INT (0); + rtx sew = gen_int_mode (get_sew (), Pmode); + rtx vlmul = gen_int_mode (get_vlmul (), Pmode); + rtx ta = gen_int_mode (get_ta (), Pmode); + rtx ma = gen_int_mode (get_ma (), Pmode); + + if (change_vtype_only_p ()) + return gen_vsetvl_vtype_change_only (sew, vlmul, ta, ma); + else if (has_reg_vl () && !ignore_vl) + return gen_vsetvl (Pmode, get_vl (), avl, sew, vlmul, ta, ma); + else + return gen_vsetvl_discard_result (Pmode, avl, sew, vlmul, ta, ma); + } + bool operator== (const vsetvl_info &other) const { gcc_assert (!uninit_p () && !other.uninit_p () @@ -1938,199 +1984,6 @@ public: } }; -/* Emit vsetvl instruction. */ -static rtx -gen_vsetvl_pat (enum vsetvl_type insn_type, const vsetvl_info &info, rtx vl) -{ - rtx avl = info.get_avl (); - /* if optimization == 0 and the instruction is vmv.x.s/vfmv.f.s, - set the value of avl to (const_int 0) so that VSETVL PASS will - insert vsetvl correctly.*/ - if (!info.get_avl ()) - avl = GEN_INT (0); - rtx sew = gen_int_mode (info.get_sew (), Pmode); - rtx vlmul = gen_int_mode (info.get_vlmul (), Pmode); - rtx ta = gen_int_mode (info.get_ta (), Pmode); - rtx ma = gen_int_mode (info.get_ma (), Pmode); - - if (insn_type == VSETVL_NORMAL) - { - gcc_assert (vl != NULL_RTX); - return gen_vsetvl (Pmode, vl, avl, sew, vlmul, ta, ma); - } - else if (insn_type == VSETVL_VTYPE_CHANGE_ONLY) - return gen_vsetvl_vtype_change_only (sew, vlmul, ta, ma); - else - return gen_vsetvl_discard_result (Pmode, avl, sew, vlmul, ta, ma); -} - -static rtx -gen_vsetvl_pat (rtx_insn *rinsn, const vsetvl_info &info, rtx vl = NULL_RTX) -{ - rtx new_pat; - vsetvl_info new_info = info; - /* For vmv.x.s, use 0 for avl. */ - if (!info.get_avl ()) - { - new_info.set_avl (const0_rtx); - new_info.set_avl_def (nullptr); - } - - if (vl) - new_pat = gen_vsetvl_pat (VSETVL_NORMAL, new_info, vl); - else - { - if (vsetvl_insn_p (rinsn) && !info.change_vtype_only_p ()) - new_pat = gen_vsetvl_pat (VSETVL_NORMAL, new_info, get_vl (rinsn)); - else if (info.change_vtype_only_p () - || INSN_CODE (rinsn) == CODE_FOR_vsetvl_vtype_change_only) - new_pat = gen_vsetvl_pat (VSETVL_VTYPE_CHANGE_ONLY, new_info, NULL_RTX); - else - new_pat = gen_vsetvl_pat (VSETVL_DISCARD_RESULT, new_info, NULL_RTX); - } - return new_pat; -} - -static void -emit_vsetvl_insn (enum vsetvl_type insn_type, enum emit_type emit_type, - const vsetvl_info &info, rtx vl, rtx_insn *rinsn) -{ - rtx pat = gen_vsetvl_pat (insn_type, info, vl); - - if (emit_type == EMIT_DIRECT) - { - emit_insn (pat); - if (dump_file) - { - fprintf (dump_file, " Insert vsetvl insn %d:\n", - INSN_UID (get_last_insn ())); - print_rtl_single (dump_file, get_last_insn ()); - } - } - else if (emit_type == EMIT_BEFORE) - { - emit_insn_before (pat, rinsn); - if (dump_file) - { - fprintf (dump_file, " Insert vsetvl insn before insn %d:\n", - INSN_UID (rinsn)); - print_rtl_single (dump_file, PREV_INSN (rinsn)); - } - } - else - { - emit_insn_after (pat, rinsn); - if (dump_file) - { - fprintf (dump_file, " Insert vsetvl insn after insn %d:\n", - INSN_UID (rinsn)); - print_rtl_single (dump_file, NEXT_INSN (rinsn)); - } - } -} - -static void -eliminate_insn (rtx_insn *rinsn) -{ - if (dump_file) - { - fprintf (dump_file, " Eliminate insn %d:\n", INSN_UID (rinsn)); - print_rtl_single (dump_file, rinsn); - } - if (in_sequence_p ()) - remove_insn (rinsn); - else - delete_insn (rinsn); -} - -/* Change insn and Assert the change always happens. */ -static void -validate_change_or_fail (rtx object, rtx *loc, rtx new_rtx, bool in_group) -{ - bool change_p = validate_change (object, loc, new_rtx, in_group); - gcc_assert (change_p); -} - -static void -change_insn (rtx_insn *rinsn, rtx new_pat) -{ - /* We don't apply change on RTL_SSA here since it's possible a - new INSN we add in the PASS before which doesn't have RTL_SSA - info yet.*/ - if (dump_file) - { - fprintf (dump_file, " Change insn %d from:\n", INSN_UID (rinsn)); - print_rtl_single (dump_file, rinsn); - } - - validate_change_or_fail (rinsn, &PATTERN (rinsn), new_pat, false); - - if (dump_file) - { - fprintf (dump_file, "\n to:\n"); - print_rtl_single (dump_file, rinsn); - } -} - -static bool -change_insn (function_info *ssa, insn_change change, insn_info *insn, - rtx new_pat) -{ - rtx_insn *rinsn = insn->rtl (); - auto attempt = ssa->new_change_attempt (); - if (!restrict_movement (change)) - return false; - - if (dump_file) - { - fprintf (dump_file, " Change insn %d from:\n", INSN_UID (rinsn)); - print_rtl_single (dump_file, rinsn); - } - - insn_change_watermark watermark; - validate_change_or_fail (rinsn, &PATTERN (rinsn), new_pat, true); - - /* These routines report failures themselves. */ - if (!recog (attempt, change) || !change_is_worthwhile (change, false)) - return false; - - remove_reg_equal_equiv_notes (rinsn); - confirm_change_group (); - ssa->change_insn (change); - - if (dump_file) - { - fprintf (dump_file, "\n to:\n"); - print_rtl_single (dump_file, rinsn); - } - - return true; -} - -static void -change_vsetvl_insn (const insn_info *insn, const vsetvl_info &info) -{ - rtx_insn *rinsn = insn->rtl (); - rtx new_pat = gen_vsetvl_pat (rinsn, info); - change_insn (rinsn, new_pat); -} - -/* Return true if the SET result is not used by any instructions. */ -static bool -has_no_uses (basic_block cfg_bb, rtx_insn *rinsn, int regno) -{ - if (bitmap_bit_p (df_get_live_out (cfg_bb), regno)) - return false; - - rtx_insn *iter; - for (iter = NEXT_INSN (rinsn); iter && iter != NEXT_INSN (BB_END (cfg_bb)); - iter = NEXT_INSN (iter)) - if (df_find_use (iter, regno_reg_rtx[regno])) - return false; - - return true; -} - class pre_vsetvl { private: @@ -2257,18 +2110,75 @@ private: } } - void insert_vsetvl (enum emit_type emit_type, rtx_insn *rinsn, - const vsetvl_info &info) + void insert_vsetvl_insn (enum emit_type emit_type, const vsetvl_info &info) { - if (info.change_vtype_only_p ()) - emit_vsetvl_insn (VSETVL_VTYPE_CHANGE_ONLY, emit_type, info, NULL_RTX, - rinsn); + rtx pat = info.get_vsetvl_pat (); + rtx_insn *rinsn = info.get_insn ()->rtl (); - else if (info.has_reg_vl ()) - emit_vsetvl_insn (VSETVL_NORMAL, emit_type, info, info.get_vl (), rinsn); + if (emit_type == EMIT_DIRECT) + { + emit_insn (pat); + if (dump_file) + { + fprintf (dump_file, " Insert vsetvl insn %d:\n", + INSN_UID (get_last_insn ())); + print_rtl_single (dump_file, get_last_insn ()); + } + } + else if (emit_type == EMIT_BEFORE) + { + emit_insn_before (pat, rinsn); + if (dump_file) + { + fprintf (dump_file, " Insert vsetvl insn before insn %d:\n", + INSN_UID (rinsn)); + print_rtl_single (dump_file, PREV_INSN (rinsn)); + } + } else - emit_vsetvl_insn (VSETVL_DISCARD_RESULT, emit_type, info, NULL_RTX, - rinsn); + { + emit_insn_after (pat, rinsn); + if (dump_file) + { + fprintf (dump_file, " Insert vsetvl insn after insn %d:\n", + INSN_UID (rinsn)); + print_rtl_single (dump_file, NEXT_INSN (rinsn)); + } + } + } + + void change_vsetvl_insn (const vsetvl_info &info) + { + rtx_insn *rinsn = info.get_insn ()->rtl (); + rtx new_pat = info.get_vsetvl_pat (); + + if (dump_file) + { + fprintf (dump_file, " Change insn %d from:\n", INSN_UID (rinsn)); + print_rtl_single (dump_file, rinsn); + } + + validate_change_or_fail (rinsn, &PATTERN (rinsn), new_pat, false); + + if (dump_file) + { + fprintf (dump_file, "\n to:\n"); + print_rtl_single (dump_file, rinsn); + } + } + + void remove_vsetvl_insn (const vsetvl_info &info) + { + rtx_insn *rinsn = info.get_insn ()->rtl (); + if (dump_file) + { + fprintf (dump_file, " Eliminate insn %d:\n", INSN_UID (rinsn)); + print_rtl_single (dump_file, rinsn); + } + if (in_sequence_p ()) + remove_insn (rinsn); + else + delete_insn (rinsn); } bool earliest_fusion_worthwhile_p (const basic_block cfg_bb) const @@ -3297,7 +3207,7 @@ pre_vsetvl::emit_vsetvl () if (curr_info.ignore_p ()) { if (vsetvl_insn_p (insn->rtl ())) - eliminate_insn (insn->rtl ()); + remove_vsetvl_insn (curr_info); continue; } else if (curr_info.valid_p ()) @@ -3314,7 +3224,7 @@ pre_vsetvl::emit_vsetvl () fprintf (dump_file, " to: "); curr_info.dump (dump_file, " "); } - change_vsetvl_insn (insn, curr_info); + change_vsetvl_insn (curr_info); } } else @@ -3326,7 +3236,7 @@ pre_vsetvl::emit_vsetvl () insn->uid ()); curr_info.dump (dump_file, " "); } - insert_vsetvl (EMIT_BEFORE, insn->rtl (), curr_info); + insert_vsetvl_insn (EMIT_BEFORE, curr_info); } } } @@ -3335,7 +3245,7 @@ pre_vsetvl::emit_vsetvl () for (const vsetvl_info &item : delete_list) { gcc_assert (vsetvl_insn_p (item.get_insn ()->rtl ())); - eliminate_insn (item.get_insn ()->rtl ()); + remove_vsetvl_insn (item); } /* Insert vsetvl as LCM suggest. */ @@ -3365,8 +3275,7 @@ pre_vsetvl::emit_vsetvl () rtl_profile_for_edge (eg); start_sequence (); - insn_info *insn = info.get_insn (); - insert_vsetvl (EMIT_DIRECT, insn->rtl (), info); + insert_vsetvl_insn (EMIT_DIRECT, info); rtx_insn *rinsn = get_insns (); end_sequence (); default_rtl_profile (); @@ -3385,7 +3294,6 @@ pre_vsetvl::emit_vsetvl () continue; const vsetvl_info &footer_info = block_info.get_footer_info (); - insn_info *insn = footer_info.get_insn (); if (footer_info.ignore_p ()) continue; @@ -3404,7 +3312,7 @@ pre_vsetvl::emit_vsetvl () footer_info.dump (dump_file, " "); } start_sequence (); - insert_vsetvl (EMIT_DIRECT, insn->rtl (), footer_info); + insert_vsetvl_insn (EMIT_DIRECT, footer_info); rtx_insn *rinsn = get_insns (); end_sequence (); default_rtl_profile (); @@ -3427,71 +3335,66 @@ pre_vsetvl::cleaup () void pre_vsetvl::remove_avl_operand () { - for (const bb_info *bb : crtl->ssa->bbs ()) - for (insn_info *insn : bb->real_nondebug_insns ()) - { - rtx_insn *rinsn = insn->rtl (); - /* Erase the AVL operand from the instruction. */ - if (!has_vl_op (rinsn) || !REG_P (get_vl (rinsn))) - continue; - rtx avl = get_vl (rinsn); - if (count_regno_occurrences (rinsn, REGNO (avl)) == 1) - { - /* Get the list of uses for the new instruction. */ - auto attempt = crtl->ssa->new_change_attempt (); - insn_change change (insn); - /* Remove the use of the substituted value. */ - access_array_builder uses_builder (attempt); - uses_builder.reserve (insn->num_uses () - 1); - for (use_info *use : insn->uses ()) - if (use != find_access (insn->uses (), REGNO (avl))) - uses_builder.quick_push (use); - use_array new_uses = use_array (uses_builder.finish ()); - change.new_uses = new_uses; - change.move_range = insn->ebb ()->insn_range (); - rtx pat; - if (fault_first_load_p (rinsn)) - pat = simplify_replace_rtx (PATTERN (rinsn), avl, const0_rtx); - else - { - rtx set = single_set (rinsn); - rtx src = simplify_replace_rtx (SET_SRC (set), avl, const0_rtx); - pat = gen_rtx_SET (SET_DEST (set), src); - } - bool ok = change_insn (crtl->ssa, change, insn, pat); - gcc_assert (ok); - } - } + basic_block cfg_bb; + rtx_insn *rinsn; + FOR_ALL_BB_FN (cfg_bb, cfun) + FOR_BB_INSNS (cfg_bb, rinsn) + if (NONDEBUG_INSN_P (rinsn) && has_vl_op (rinsn) + && REG_P (get_vl (rinsn))) + { + rtx avl = get_vl (rinsn); + if (count_regno_occurrences (rinsn, REGNO (avl)) == 1) + { + rtx new_pat; + if (fault_first_load_p (rinsn)) + new_pat + = simplify_replace_rtx (PATTERN (rinsn), avl, const0_rtx); + else + { + rtx set = single_set (rinsn); + rtx src + = simplify_replace_rtx (SET_SRC (set), avl, const0_rtx); + new_pat = gen_rtx_SET (SET_DEST (set), src); + } + if (dump_file) + { + fprintf (dump_file, " Cleanup insn %u's avl operand:\n", + INSN_UID (rinsn)); + print_rtl_single (dump_file, rinsn); + } + validate_change_or_fail (rinsn, &PATTERN (rinsn), new_pat, false); + } + } } void pre_vsetvl::remove_unused_dest_operand () { df_analyze (); - hash_set to_delete; basic_block cfg_bb; rtx_insn *rinsn; FOR_ALL_BB_FN (cfg_bb, cfun) - { - FOR_BB_INSNS (cfg_bb, rinsn) + FOR_BB_INSNS (cfg_bb, rinsn) + if (NONDEBUG_INSN_P (rinsn) && vsetvl_insn_p (rinsn)) { - if (NONDEBUG_INSN_P (rinsn) && vsetvl_insn_p (rinsn)) - { - rtx vl = get_vl (rinsn); - vsetvl_info info = vsetvl_info (rinsn); - if (has_no_uses (cfg_bb, rinsn, REGNO (vl))) - { - if (!info.has_vlmax_avl ()) - { - rtx new_pat = gen_vsetvl_pat (VSETVL_DISCARD_RESULT, info, - NULL_RTX); - validate_change_or_fail (rinsn, &PATTERN (rinsn), new_pat, - false); - } - } - } + rtx vl = get_vl (rinsn); + vsetvl_info info = vsetvl_info (rinsn); + if (has_no_uses (cfg_bb, rinsn, REGNO (vl))) + if (!info.has_vlmax_avl ()) + { + rtx new_pat = info.get_vsetvl_pat (true); + if (dump_file) + { + fprintf (dump_file, + " Remove vsetvl insn %u's dest(vl) operand since " + "it unused:\n", + INSN_UID (rinsn)); + print_rtl_single (dump_file, rinsn); + } + validate_change_or_fail (rinsn, &PATTERN (rinsn), new_pat, + false); + } } - } } const pass_data pass_data_vsetvl = { @@ -3536,9 +3439,15 @@ pass_vsetvl::simple_vsetvl () continue; if (has_vtype_op (rinsn)) { - const auto info = vsetvl_info (rinsn); - emit_vsetvl_insn (VSETVL_DISCARD_RESULT, EMIT_BEFORE, info, - NULL_RTX, rinsn); + const auto &info = vsetvl_info (rinsn); + rtx pat = info.get_vsetvl_pat (); + emit_insn_before (pat, rinsn); + if (dump_file) + { + fprintf (dump_file, " Insert vsetvl insn before insn %d:\n", + INSN_UID (rinsn)); + print_rtl_single (dump_file, PREV_INSN (rinsn)); + } } } }