From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2093) id CCCDE3858428; Thu, 26 Jan 2023 19:12:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CCCDE3858428 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674760330; bh=qFoFxhFOavA4jZkjH3HOlOzkU3NhaS3OKy+lU4Fm3N4=; h=From:To:Subject:Date:From; b=NvH97Bpuj5KxJuxI+bD/8HwC5jPpJlFSPQaqKm9IA3VPBmiMrAN52Zsimmtx59g6Z DG+X4RTq/5iIONyh2nxlo11asR/lifBtu1Ih1fcexQb6uMEUmvzByNjgzIkGqb4bi5 gp4Yf0mUh19/PQnr4cootvNLxC8RbgMCuA7kYCZw= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Kito Cheng To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5406] RISC-V: Fix backward_propagate_worthwhile_p X-Act-Checkin: gcc X-Git-Author: Ju-Zhe Zhong X-Git-Refname: refs/heads/master X-Git-Oldrev: 011ba384b343e99bb86eb3ac86c7628c4cd98f8b X-Git-Newrev: 8d8cc482ea49fd6fed81b47c948263fd82a1936b Message-Id: <20230126191210.CCCDE3858428@sourceware.org> Date: Thu, 26 Jan 2023 19:12:10 +0000 (GMT) List-Id: https://gcc.gnu.org/g:8d8cc482ea49fd6fed81b47c948263fd82a1936b commit r13-5406-g8d8cc482ea49fd6fed81b47c948263fd82a1936b Author: Ju-Zhe Zhong Date: Tue Jan 3 15:16:41 2023 +0800 RISC-V: Fix backward_propagate_worthwhile_p gcc/ChangeLog: * config/riscv/riscv-vsetvl.cc (loop_basic_block_p): Adjust function. (backward_propagate_worthwhile_p): Fix non-worthwhile. Diff: --- 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 79336447deb..4d0e97d7ed7 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;