From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2066) id ED4E13839C4A; Wed, 2 Jun 2021 04:14:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED4E13839C4A 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/guojiufu-branch)] Fix bootstrap-O3 fail X-Act-Checkin: gcc X-Git-Author: Jiufu Guo X-Git-Refname: refs/users/guojiufu/heads/guojiufu-branch X-Git-Oldrev: 35903420b260ca2206ebc3dc3c2e187ac5c42b92 X-Git-Newrev: 79af8adcfe8f4110505c86f6d0b13f38d744e101 Message-Id: <20210602041425.ED4E13839C4A@sourceware.org> Date: Wed, 2 Jun 2021 04:14:25 +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, 02 Jun 2021 04:14:26 -0000 https://gcc.gnu.org/g:79af8adcfe8f4110505c86f6d0b13f38d744e101 commit 79af8adcfe8f4110505c86f6d0b13f38d744e101 Author: Jiufu Guo Date: Wed Jun 2 11:29:40 2021 +0800 Fix bootstrap-O3 fail Diff: --- gcc/tree-ssa-loop-split.c | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/gcc/tree-ssa-loop-split.c b/gcc/tree-ssa-loop-split.c index 0428b0abea6..926966a2bbc 100644 --- a/gcc/tree-ssa-loop-split.c +++ b/gcc/tree-ssa-loop-split.c @@ -1610,6 +1610,39 @@ get_ne_cond_branch (struct loop *loop) auto_vec edges = get_loop_exit_edges (loop); FOR_EACH_VEC_ELT (edges, i, e) { + basic_block bb = e->src; + + /* Check if exit at gcond. */ + gimple *last = last_stmt (bb); + if (!last || gimple_code (last) != GIMPLE_COND) + continue; + gcond *cond = as_a (last); + enum tree_code code = gimple_cond_code (cond); + if (!(code == NE_EXPR + || (code == EQ_EXPR && (e->flags & EDGE_TRUE_VALUE)))) + continue; + + /* Check if bound is invarant. */ + tree idx = gimple_cond_lhs (cond); + tree bnd = gimple_cond_rhs (cond); + if (expr_invariant_in_loop_p (loop, idx)) + std::swap (idx, bnd); + else if (!expr_invariant_in_loop_p (loop, bnd)) + continue; + + /* Only unsigned type conversion could cause wrap. */ + tree type = TREE_TYPE (idx); + if (!INTEGRAL_TYPE_P (type) || TREE_CODE (idx) != SSA_NAME + || !TYPE_UNSIGNED (type)) + continue; + + /* Avoid to split if bound is MAX/MIN val. */ + tree bound_type = TREE_TYPE (bnd); + if (TREE_CODE (bnd) == INTEGER_CST && INTEGRAL_TYPE_P (bound_type) + && (bnd == TYPE_MAX_VALUE (bound_type) + || bnd == TYPE_MIN_VALUE (bound_type))) + continue; + /* Check if there is possible wrap. */ class tree_niter_desc niter; if (!number_of_iterations_exit (loop, e, &niter, false, false)) @@ -1623,7 +1656,7 @@ get_ne_cond_branch (struct loop *loop) the split loops: just jump from the exit edge of one loop to the header of new loop. */ if (single_pred_p (loop->latch) - && single_pred_edge (loop->latch)->src == e->src + && single_pred_edge (loop->latch)->src == bb && empty_block_p (loop->latch)) return e; @@ -1631,10 +1664,10 @@ get_ne_cond_branch (struct loop *loop) only, it is simple to link the split loops: jump from the end of one loop header to the new loop header, and use unchanged PHI result of first loop as the entry PHI value of the second loop. */ - if (e->src == loop->header) + if (bb == loop->header) { /* Only one phi. */ - gphi_iterator psi = gsi_start_phis (e->src); + gphi_iterator psi = gsi_start_phis (bb); if (gsi_end_p (psi)) continue; gphi *phi = psi.phi (); @@ -1642,8 +1675,8 @@ get_ne_cond_branch (struct loop *loop) if (!gsi_end_p (psi)) continue; - /* Get the idx from last stmt (the gcond) of e->src. */ - gimple *gc = last_stmt (e->src); + /* Get the idx from last stmt (the gcond) of bb. */ + gimple *gc = last_stmt (bb); gcc_assert (gimple_code (gc) == GIMPLE_COND); tree idx = gimple_cond_lhs (gc); if (expr_invariant_in_loop_p (loop, idx)) @@ -1656,7 +1689,7 @@ get_ne_cond_branch (struct loop *loop) /* ++i or ++i */ gimple_stmt_iterator gsi - = gsi_start_nondebug_after_labels_bb (e->src); + = gsi_start_nondebug_after_labels_bb (bb); if (gsi_end_p (gsi)) continue;