From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2066) id 217543857807; Mon, 31 May 2021 06:03:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 217543857807 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)] Use number_of_iterations_exit as main check X-Act-Checkin: gcc X-Git-Author: Jiufu Guo X-Git-Refname: refs/users/guojiufu/heads/guojiufu-branch X-Git-Oldrev: 8423688fbe868b9bbbbc07024cc1ac132370e553 X-Git-Newrev: 3db06dd76539b5fdcbb8a71ad1b8fb861b96d3d6 Message-Id: <20210531060354.217543857807@sourceware.org> Date: Mon, 31 May 2021 06:03:54 +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: Mon, 31 May 2021 06:03:54 -0000 https://gcc.gnu.org/g:3db06dd76539b5fdcbb8a71ad1b8fb861b96d3d6 commit 3db06dd76539b5fdcbb8a71ad1b8fb861b96d3d6 Author: Jiufu Guo Date: Sat May 15 13:56:01 2021 +0800 Use number_of_iterations_exit as main check Diff: --- gcc/testsuite/g++.dg/vect/pr98064.cc | 4 ++- gcc/tree-ssa-loop-split.c | 51 ++++++++++++------------------------ 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/gcc/testsuite/g++.dg/vect/pr98064.cc b/gcc/testsuite/g++.dg/vect/pr98064.cc index 74043ce7725..dcb2985d05a 100644 --- a/gcc/testsuite/g++.dg/vect/pr98064.cc +++ b/gcc/testsuite/g++.dg/vect/pr98064.cc @@ -1,5 +1,7 @@ // { dg-do compile } -// { dg-additional-options "-O3" } +// { dg-additional-options "-O3 -Wno-stringop-overflow" } +/* There is warning message when "short g = var_8; g; g++" + is optimized/analyzed as string operation,e.g. memset. */ const long long &min(const long long &__a, long long &__b) { if (__b < __a) diff --git a/gcc/tree-ssa-loop-split.c b/gcc/tree-ssa-loop-split.c index 6ae36635d6b..5c1742b5ff4 100644 --- a/gcc/tree-ssa-loop-split.c +++ b/gcc/tree-ssa-loop-split.c @@ -1609,51 +1609,29 @@ 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 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; - - /* If no overflow/wrap happen, no need to split. */ - if (nowrap_type_p (TREE_TYPE (idx))) - continue; + /* Check if there is possible wrap/overflow. */ class tree_niter_desc niter; - if (!number_of_iterations_exit (loop, e, &niter, false, false, NULL)) + if (!number_of_iterations_exit (loop, e, &niter, false, false)) continue; if (niter.control.no_overflow) return NULL; + if (niter.cmp != NE_EXPR) + continue; /* Check loop is simple to split. */ - gcc_assert (bb != loop->latch); - if (single_pred_p (loop->latch) - && single_pred_edge (loop->latch)->src == bb + && single_pred_edge (loop->latch)->src == e->src && (gsi_end_p (gsi_start_nondebug_bb (loop->latch)))) return e; - /* Cheap header. */ - if (bb == loop->header) + /* Simple header. */ + if (e->src == loop->header) { - if (get_virtual_phi (bb)) + if (get_virtual_phi (e->src)) continue; /* Only one phi. */ - gphi_iterator psi = gsi_start_phis (bb); + gphi_iterator psi = gsi_start_phis (e->src); if (gsi_end_p (psi)) continue; gsi_next (&psi); @@ -1661,18 +1639,23 @@ get_ne_cond_branch (struct loop *loop) continue; /* ++i or ++i */ - gimple_stmt_iterator gsi = gsi_start_bb (bb); + gimple_stmt_iterator gsi = gsi_start_bb (e->src); if (gsi_end_p (gsi)) continue; + gimple *gc = last_stmt (e->src); + tree idx = gimple_cond_lhs (gc); + if (expr_invariant_in_loop_p (loop, idx)) + idx = gimple_cond_rhs (gc); + gimple *s1 = gsi_stmt (gsi); - if (!(is_gimple_assign (s1) + if (!(is_gimple_assign (s1) && idx && (idx == gimple_assign_lhs (s1) || idx == gimple_assign_rhs1 (s1)))) continue; gsi_next (&gsi); - if (!gsi_end_p (gsi) && gsi_stmt (gsi) == cond) + if (!gsi_end_p (gsi) && gsi_stmt (gsi) == gc) return e; } }