From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2066) id CB8413848404; Wed, 9 Jun 2021 04:55:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB8413848404 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)] Pass bootstrap-O3 and regtest X-Act-Checkin: gcc X-Git-Author: Jiufu Guo X-Git-Refname: refs/users/guojiufu/heads/personal-branch X-Git-Oldrev: 4acec8dc6f5b20eb940eb2b0b64da87cdd059dfa X-Git-Newrev: 2caa0d6f3c759b6c5507093e09fff188cb7b9bfd Message-Id: <20210609045518.CB8413848404@sourceware.org> Date: Wed, 9 Jun 2021 04:55:17 +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: Wed, 09 Jun 2021 04:55:18 -0000 https://gcc.gnu.org/g:2caa0d6f3c759b6c5507093e09fff188cb7b9bfd commit 2caa0d6f3c759b6c5507093e09fff188cb7b9bfd Author: Jiufu Guo Date: Wed Jun 9 10:25:02 2021 +0800 Pass bootstrap-O3 and regtest Diff: --- gcc/tree-ssa-loop-split.c | 89 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 3 deletions(-) diff --git a/gcc/tree-ssa-loop-split.c b/gcc/tree-ssa-loop-split.c index abc81a6144c..ccde6bb24a7 100644 --- a/gcc/tree-ssa-loop-split.c +++ b/gcc/tree-ssa-loop-split.c @@ -1778,7 +1778,7 @@ get_wrap_assumption (class loop *loop, edge *exit, idx_elements &data) code = swap_tree_comparison (code); if ((e->flags & EDGE_TRUE_VALUE) && code == EQ_EXPR) code = NE_EXPR; - if (code != NE_EXPR && code != LT_EXPR) + if (code != NE_EXPR && code != LT_EXPR && code != LE_EXPR) continue; /* Check if idx is iv with base and step. */ @@ -1823,6 +1823,84 @@ get_wrap_assumption (class loop *loop, edge *exit, idx_elements &data) return NULL_TREE; } +/* Update the idx and bnd with faster type for no wrap/oveflow loop. */ + +static bool +update_idx_bnd_type (class loop *loop, idx_elements &data) +{ + return false; + /* Use sizetype as machine fast type, ok for most targets? */ + tree fast_type = sizetype; + + /* New base and new bound. */ + gphi *phi = data.phi; + tree bnd = data.bnd; + edge pre_e = loop_preheader_edge (loop); + tree base = PHI_ARG_DEF_FROM_EDGE (phi, pre_e); + tree new_base = fold_convert (fast_type, base); + tree new_bnd = fold_convert (fast_type, bnd); + gimple_seq seq = NULL; + new_base = force_gimple_operand (new_base, &seq, true, NULL_TREE); + if (seq) + gsi_insert_seq_on_edge_immediate (pre_e, seq); + seq = NULL; + new_bnd = force_gimple_operand (new_bnd, &seq, true, NULL_TREE); + if (seq) + gsi_insert_seq_on_edge_immediate (pre_e, seq); + + /* new_i = phi (new_b, new_n) + new_n = new_i + 1 */ + edge latch_e = loop_latch_edge (loop); + const char *name = "idx"; + tree new_idx = make_temp_ssa_name (fast_type, NULL, name); + tree new_next = make_temp_ssa_name (fast_type, NULL, name); + gphi *newphi = create_phi_node (new_idx, loop->header); + add_phi_arg (newphi, new_base, pre_e, UNKNOWN_LOCATION); + add_phi_arg (newphi, new_next, latch_e, UNKNOWN_LOCATION); + + /* New increase stmt. */ + gimple *inc_stmt = data.inc_stmt; + tree step = gimple_assign_rhs2 (inc_stmt); + step = fold_convert (fast_type, step); + new_idx = PHI_RESULT (newphi); + tree_code inc_code = gimple_assign_rhs_code (inc_stmt); + gimple *new_inc = gimple_build_assign (new_next, inc_code, new_idx, step); + gimple_stmt_iterator gsi = gsi_for_stmt (inc_stmt); + gsi_insert_before (&gsi, new_inc, GSI_SAME_STMT); + + /* Update gcond. */ + gcond *gc = data.gc; + bool inv = bnd == gimple_cond_lhs (gc); + tree cmp_idx = data.cmp_on_next ? new_next : new_idx; + gimple_cond_set_lhs (gc, inv ? new_bnd : cmp_idx); + gimple_cond_set_rhs (gc, inv ? cmp_idx : new_bnd); + update_stmt (gc); + + /* next = (next type)new_next + And remove next = prev + 1. */ + tree next = data.next; + tree type = TREE_TYPE (next); + gimple *stmt = gimple_build_assign (next, fold_convert (type, new_next)); + gsi = gsi_for_stmt (inc_stmt); + gsi_insert_before (&gsi, stmt, GSI_SAME_STMT); + + gsi = gsi_for_stmt (inc_stmt); + gsi_remove (&gsi, true); + + /* prev = (prev type)new_prev + And remove prev = phi. */ + tree idx = PHI_RESULT (phi); + type = TREE_TYPE (idx); + stmt = gimple_build_assign (idx, fold_convert (type, new_idx)); + gsi = gsi_start_bb (loop->header); + gsi_insert_before (&gsi, stmt, GSI_SAME_STMT); + + gsi = gsi_for_stmt (phi); + gsi_remove (&gsi, true); + + return true; +} + /* Split out a new loop which would not wrap, under the guard that NO_WRAP_COND will not be true. */ @@ -1925,8 +2003,13 @@ split_loop_on_wrap (class loop *loop) idx_elements data; tree no_wrap_assumption = get_wrap_assumption (loop, &e, data); - if (no_wrap_assumption && split_wrap_boundary (loop, e, no_wrap_assumption)) - return true; + if (no_wrap_assumption + && (integer_onep (no_wrap_assumption) + || split_wrap_boundary (loop, e, no_wrap_assumption))) + { + update_idx_bnd_type (loop, data); + return true; + } return false; }