public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/guojiufu/heads/guojiufu-branch)] Use number_of_iterations_exit as main check
@ 2021-05-31  6:03 Jiu Fu Guo
  0 siblings, 0 replies; only message in thread
From: Jiu Fu Guo @ 2021-05-31  6:03 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3db06dd76539b5fdcbb8a71ad1b8fb861b96d3d6

commit 3db06dd76539b5fdcbb8a71ad1b8fb861b96d3d6
Author: Jiufu Guo <guojiufu@linux.ibm.com>
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<edge> 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<gcond *> (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;
 	}
     }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-31  6:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-31  6:03 [gcc(refs/users/guojiufu/heads/guojiufu-branch)] Use number_of_iterations_exit as main check Jiu Fu Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).