From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2066) id D6293398A021; Thu, 3 Jun 2021 03:38:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D6293398A021 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jiu Fu Guo To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/guojiufu/heads/personal-branch)] update idx type for orig no-wrap loop, do not get idx_phi though parm X-Act-Checkin: gcc X-Git-Author: guojiufu X-Git-Refname: refs/users/guojiufu/heads/personal-branch X-Git-Oldrev: f2d41ac14f081bfaa3812185beaf1f146e80fd75 X-Git-Newrev: a327d36522c9a0668277f9a51b79f33f2be11208 Message-Id: <20210603033805.D6293398A021@sourceware.org> Date: Thu, 3 Jun 2021 03:38:05 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Jun 2021 03:38:05 -0000 https://gcc.gnu.org/g:a327d36522c9a0668277f9a51b79f33f2be11208 commit a327d36522c9a0668277f9a51b79f33f2be11208 Author: guojiufu Date: Thu Jun 3 11:37:53 2021 +0800 update idx type for orig no-wrap loop, do not get idx_phi though parm Diff: --- gcc/tree-ssa-loop-split.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/gcc/tree-ssa-loop-split.c b/gcc/tree-ssa-loop-split.c index 283c6fc6d90..a35a7d19814 100644 --- a/gcc/tree-ssa-loop-split.c +++ b/gcc/tree-ssa-loop-split.c @@ -1653,7 +1653,7 @@ filter_conversions (class loop *loop, tree idx, tree *small_type = NULL, Return NULL_TREE, if wrap will not happen. */ static tree -get_wrap_assumption (class loop *loop, edge *exit, gphi **idx_phi) +get_wrap_assumption (class loop *loop, edge *exit) { int i; edge e; @@ -1708,12 +1708,12 @@ get_wrap_assumption (class loop *loop, edge *exit, gphi **idx_phi) stmt = filter_conversions (loop, gimple_assign_rhs1 (stmt)); if (gimple_code (stmt) != GIMPLE_PHI) continue; - *idx_phi = as_a (stmt); + gphi *idx_phi = as_a (stmt); /* Check if idx is iv with base and step. */ affine_iv iv; tree iv_niters = NULL_TREE; - idx = PHI_RESULT (*idx_phi); + idx = PHI_RESULT (idx_phi); if (!simple_iv_with_niters (loop, loop_containing_stmt (gc), idx, &iv, &iv_niters, false)) continue; @@ -1722,7 +1722,7 @@ get_wrap_assumption (class loop *loop, edge *exit, gphi **idx_phi) /* If there is conversions on idx, Get the longest and shortest type during converting. */ - tree next = PHI_ARG_DEF_FROM_EDGE (*idx_phi, loop_latch_edge (loop)); + tree next = PHI_ARG_DEF_FROM_EDGE (idx_phi, loop_latch_edge (loop)); tree small_type = TREE_TYPE (next); tree large_type = small_type; stmt = filter_conversions (loop, next, &small_type, &large_type); @@ -1753,8 +1753,7 @@ get_wrap_assumption (class loop *loop, edge *exit, gphi **idx_phi) = fold_build2 (TRUTH_AND_EXPR, boolean_type_node, no_wrap_assump, fold_build2 (LE_EXPR, boolean_type_node, base, bnd)); - /* Check if 100% sure wrap or no wrap. */ - if (integer_zerop (no_wrap_assump) || integer_onep (no_wrap_assump)) + if (integer_zerop (no_wrap_assump)) continue; *exit = e; @@ -1767,9 +1766,12 @@ get_wrap_assumption (class loop *loop, edge *exit, gphi **idx_phi) /* Update the idx and bnd with faster type for no wrap/oveflow loop. */ static bool -update_idx_bnd_type (class loop *loop, gimple *last, gphi *idx_phi) +update_idx_bnd_type (class loop *loop, edge e) { /* Get bnd and idx from gcond. */ + gimple *last = last_stmt (e->src); + if (!last || gimple_code (last) != GIMPLE_COND) + return false; gcond *gc = as_a (last); tree bnd = gimple_cond_rhs (gc); tree idx = gimple_cond_lhs (gc); @@ -1780,8 +1782,9 @@ update_idx_bnd_type (class loop *loop, gimple *last, gphi *idx_phi) std::swap (idx, bnd); } + gphi *idx_phi; + tree next; edge latch_e = loop_latch_edge (loop); - tree next = PHI_ARG_DEF_FROM_EDGE (idx_phi, latch_e); /* Get increasement stmt: next = prev + 1. And check the exit gcond is comparing on the prev or next. */ @@ -1790,21 +1793,29 @@ update_idx_bnd_type (class loop *loop, gimple *last, gphi *idx_phi) gimple *stmt = filter_conversions (loop, idx); if (gimple_code (stmt) == GIMPLE_PHI) { + idx_phi = as_a (stmt); + next = PHI_ARG_DEF_FROM_EDGE (idx_phi, latch_e); inc_stmt = filter_conversions (loop, next); cmp_next = false; } else { inc_stmt = stmt; + if (!is_gimple_assign (inc_stmt)) + return false; + stmt = filter_conversions (loop, gimple_assign_rhs1 (stmt)); + if (gimple_code (stmt) != GIMPLE_PHI) + return false; + idx_phi = as_a (stmt); cmp_next = true; } if (!is_gimple_assign (inc_stmt) || gimple_assign_rhs_code (inc_stmt) != PLUS_EXPR - || !flow_bb_inside_loop_p (loop, gimple_bb (inc_stmt))) - return false; + || !flow_bb_inside_loop_p (loop, gimple_bb (inc_stmt)) + || gimple_bb (idx_phi) != loop->header) + return false; - /* Use sizetype as machine fast type, ok for most targets? */ tree fast_type = sizetype; @@ -1961,13 +1972,13 @@ split_loop_on_wrap (class loop *loop) free (bbs); edge e; - gphi *idx_phi; - tree assumption = get_wrap_assumption (loop, &e, &idx_phi); + tree no_wrap_assumption = get_wrap_assumption (loop, &e); - if (assumption && split_wrap_boundary (loop, e, assumption)) + if (no_wrap_assumption + && (integer_onep (no_wrap_assumption) + || split_wrap_boundary (loop, e, no_wrap_assumption))) { - // rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa); - update_idx_bnd_type (loop, last_stmt (e->src), idx_phi); + update_idx_bnd_type (loop, e); return true; }