From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpbgau1.qq.com (smtpbgau1.qq.com [54.206.16.166]) by sourceware.org (Postfix) with ESMTPS id E5CDA3858D1E for ; Tue, 3 Jan 2023 07:16:49 +0000 (GMT) X-QQ-mid: bizesmtp69t1672730203t8lq27qb Received: from rios-cad5.localdomain ( [58.60.1.11]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 03 Jan 2023 15:16:43 +0800 (CST) X-QQ-SSF: 01400000000000E0L000000A0000000 X-QQ-FEAT: +oIWmpEafD/FvgZwzKI7eUFikKT1dQ0SsyVsC+aqMVccY7F6CZ62jwcLDh3Wk yjdMpGmDkPQNE3KHjiDy2GEt6p+lwj6/ucDjdTEC2ScLQvbzUrLg+xKDIEeMeRYFWn8XC+K vXgp1utBoJcVyaIrgWaecPq1WH1OZzV23w649PHOxil7MmW3gg8XRZpnTf97RBTryZaYKvk 1gj8LaJZ0mdcGkIWHHpwqh5kSKaw1V9eBB2GhviQYqWd6Au5QNQ4BiMCOvc1jLL/rNbad78 zGfDSR78Mu+mDw3T210sStHROvUr5vZZ/jmzh+zEr/6s6SR35tqV9K33c24jjBA0O135G/F cg1xUD1coqh8XOWh7C4RdleblZEsxyiNcgXwnpgBAXKLhW/C/+LB/0pGOOqOMAgimAAw0jb 6z2Uy3k+cMA= X-QQ-GoodBg: 2 From: juzhe.zhong@rivai.ai To: gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, palmer@dabbelt.com, Ju-Zhe Zhong Subject: [PATCH] RISC-V: Fix backward_propagate_worthwhile_p Date: Tue, 3 Jan 2023 15:16:41 +0800 Message-Id: <20230103071641.149958-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvr:qybglogicsvr7 X-Spam-Status: No, score=-12.4 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 List-Id: From: Ju-Zhe Zhong gcc/ChangeLog: * config/riscv/riscv-vsetvl.cc (loop_basic_block_p): Adjust function. (backward_propagate_worthwhile_p): Fix non-worthwhile. --- gcc/config/riscv/riscv-vsetvl.cc | 91 +++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 20 deletions(-) diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index ad0457ed89d..fe76bea297e 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -116,10 +116,27 @@ vlmax_avl_insn_p (rtx_insn *rinsn) || INSN_CODE (rinsn) == CODE_FOR_vlmax_avldi); } +/* Return true if the block is a loop itself: + local_dem + __________ + ____|____ | + | | | + |________| | + |_________| + reaching_out +*/ static bool loop_basic_block_p (const basic_block cfg_bb) { - return JUMP_P (BB_END (cfg_bb)) && any_condjump_p (BB_END (cfg_bb)); + if (JUMP_P (BB_END (cfg_bb)) && any_condjump_p (BB_END (cfg_bb))) + { + edge e; + edge_iterator ei; + FOR_EACH_EDGE (e, ei, cfg_bb->succs) + if (e->dest->index == cfg_bb->index) + return true; + } + return false; } /* Return true if it is an RVV instruction depends on VTYPE global @@ -271,26 +288,60 @@ backward_propagate_worthwhile_p (const basic_block cfg_bb, { if (loop_basic_block_p (cfg_bb)) { - if (block_info.local_dem.compatible_p (block_info.reaching_out)) - return true; - - /* There is a obvious case that is not worthwhile and meaningless - to propagate the demand information: - local_dem - __________ - ____|____ | - | | | - |________| | - |_________| - reaching_out - Header is incompatible with reaching_out and the block is loop itself, - we don't backward propagate the local_dem since we can't avoid emit - vsetvl for the local_dem. */ - edge e; - edge_iterator ei; - FOR_EACH_EDGE (e, ei, cfg_bb->succs) - if (e->dest->index == cfg_bb->index) + if (block_info.reaching_out.valid_or_dirty_p ()) + { + if (block_info.local_dem.compatible_p (block_info.reaching_out)) + { + /* Case 1 (Can backward propagate): + .... + bb0: + ... + for (int i = 0; i < n; i++) + { + vint16mf4_t v = __riscv_vle16_v_i16mf4 (in + i + 5, 7); + __riscv_vse16_v_i16mf4 (out + i + 5, v, 7); + } + The local_dem is compatible with reaching_out. Such case is + worthwhile backward propagation. */ + return true; + } + else + { + /* Case 2 (Don't backward propagate): + .... + bb0: + ... + for (int i = 0; i < n; i++) + { + vint16mf4_t v = __riscv_vle16_v_i16mf4 (in + i + 5, 7); + __riscv_vse16_v_i16mf4 (out + i + 5, v, 7); + vint16mf2_t v2 = __riscv_vle16_v_i16mf2 (in + i + 6, 8); + __riscv_vse16_v_i16mf2 (out + i + 6, v, 8); + } + The local_dem is incompatible with reaching_out. + It makes no sense to backward propagate the local_dem since we + can't avoid VSETVL inside the loop. */ + return false; + } + } + else + { + gcc_assert (block_info.reaching_out.unknown_p ()); + /* Case 3 (Don't backward propagate): + .... + bb0: + ... + for (int i = 0; i < n; i++) + { + vint16mf4_t v = __riscv_vle16_v_i16mf4 (in + i + 5, 7); + __riscv_vse16_v_i16mf4 (out + i + 5, v, 7); + fn3 (); + } + The local_dem is VALID, but the reaching_out is UNKNOWN. + It makes no sense to backward propagate the local_dem since we + can't avoid VSETVL inside the loop. */ return false; + } } return true; -- 2.36.3