public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/guojiufu/heads/personal-branch)] using number_of_iterations_exit to check wrap/overflow
@ 2021-05-31  5:56 Jiu Fu Guo
  0 siblings, 0 replies; 2+ messages in thread
From: Jiu Fu Guo @ 2021-05-31  5:56 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:0ed4c5d27ef0fb6e27046a749754752c9b27f2a4

commit 0ed4c5d27ef0fb6e27046a749754752c9b27f2a4
Author: Jiufu Guo <guojiufu@linux.ibm.com>
Date:   Fri May 14 23:33:57 2021 +0800

    using number_of_iterations_exit to check wrap/overflow

Diff:
---
 gcc/tree-ssa-loop-split.c | 38 +++++---------------------------------
 1 file changed, 5 insertions(+), 33 deletions(-)

diff --git a/gcc/tree-ssa-loop-split.c b/gcc/tree-ssa-loop-split.c
index 425593ca70f..6ae36635d6b 100644
--- a/gcc/tree-ssa-loop-split.c
+++ b/gcc/tree-ssa-loop-split.c
@@ -1629,43 +1629,15 @@ get_ne_cond_branch (struct loop *loop)
       else if (!expr_invariant_in_loop_p (loop, bnd))
 	continue;
 
-      /* By default, unsigned type conversion could cause overflow.  */
-      tree type = TREE_TYPE (idx);
-      if (!INTEGRAL_TYPE_P (type) || TREE_CODE (idx) != SSA_NAME
-	  || !TYPE_UNSIGNED (type)
-	  || TYPE_PRECISION (type) == TYPE_PRECISION (sizetype))
+      /* If no overflow/wrap happen, no need to split.  */
+      if (nowrap_type_p (TREE_TYPE (idx)))
 	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;
-
-      /* Extract conversion from idx.  */
-      if (TREE_CODE (idx) == SSA_NAME)
-	{
-	  gimple *stmt = SSA_NAME_DEF_STMT (idx);
-	  if (is_gimple_assign (stmt)
-	      && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt))
-	      && flow_bb_inside_loop_p (loop, gimple_bb (stmt)))
-	    idx = gimple_assign_rhs1 (stmt);
-	}
-
-      /* Check if idx is simple iv with possible overflow/wrap.  */
-      class loop *useloop = loop_containing_stmt (cond);
-      affine_iv iv;
-      if (!simple_iv (loop, useloop, idx, &iv, false))
+      class tree_niter_desc niter;
+      if (!number_of_iterations_exit (loop, e, &niter, false, false, NULL))
 	continue;
-      if (iv.no_overflow)
+      if (niter.control.no_overflow)
 	return NULL;
 
-      /* If base is know value (esplically 0/1), other optimizations may be
-	 able to analyze "idx != bnd" as "idx < bnd" or "idx > bnd".  */
-      if (TREE_CODE (iv.base) == INTEGER_CST)
-	continue;
-
       /* Check loop is simple to split.  */
       gcc_assert (bb != loop->latch);


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [gcc(refs/users/guojiufu/heads/personal-branch)] using number_of_iterations_exit to check wrap/overflow
@ 2021-05-20  6:28 Jiu Fu Guo
  0 siblings, 0 replies; 2+ messages in thread
From: Jiu Fu Guo @ 2021-05-20  6:28 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ed4bd03ea9e7555889d8af83c4bcdc3515dac2bb

commit ed4bd03ea9e7555889d8af83c4bcdc3515dac2bb
Author: Jiufu Guo <guojiufu@linux.ibm.com>
Date:   Fri May 14 23:33:57 2021 +0800

    using number_of_iterations_exit to check wrap/overflow

Diff:
---
 gcc/tree-ssa-loop-split.c | 38 +++++---------------------------------
 1 file changed, 5 insertions(+), 33 deletions(-)

diff --git a/gcc/tree-ssa-loop-split.c b/gcc/tree-ssa-loop-split.c
index 425593ca70f..6ae36635d6b 100644
--- a/gcc/tree-ssa-loop-split.c
+++ b/gcc/tree-ssa-loop-split.c
@@ -1629,43 +1629,15 @@ get_ne_cond_branch (struct loop *loop)
       else if (!expr_invariant_in_loop_p (loop, bnd))
 	continue;
 
-      /* By default, unsigned type conversion could cause overflow.  */
-      tree type = TREE_TYPE (idx);
-      if (!INTEGRAL_TYPE_P (type) || TREE_CODE (idx) != SSA_NAME
-	  || !TYPE_UNSIGNED (type)
-	  || TYPE_PRECISION (type) == TYPE_PRECISION (sizetype))
+      /* If no overflow/wrap happen, no need to split.  */
+      if (nowrap_type_p (TREE_TYPE (idx)))
 	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;
-
-      /* Extract conversion from idx.  */
-      if (TREE_CODE (idx) == SSA_NAME)
-	{
-	  gimple *stmt = SSA_NAME_DEF_STMT (idx);
-	  if (is_gimple_assign (stmt)
-	      && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt))
-	      && flow_bb_inside_loop_p (loop, gimple_bb (stmt)))
-	    idx = gimple_assign_rhs1 (stmt);
-	}
-
-      /* Check if idx is simple iv with possible overflow/wrap.  */
-      class loop *useloop = loop_containing_stmt (cond);
-      affine_iv iv;
-      if (!simple_iv (loop, useloop, idx, &iv, false))
+      class tree_niter_desc niter;
+      if (!number_of_iterations_exit (loop, e, &niter, false, false, NULL))
 	continue;
-      if (iv.no_overflow)
+      if (niter.control.no_overflow)
 	return NULL;
 
-      /* If base is know value (esplically 0/1), other optimizations may be
-	 able to analyze "idx != bnd" as "idx < bnd" or "idx > bnd".  */
-      if (TREE_CODE (iv.base) == INTEGER_CST)
-	continue;
-
       /* Check loop is simple to split.  */
       gcc_assert (bb != loop->latch);


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-31  5:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-31  5:56 [gcc(refs/users/guojiufu/heads/personal-branch)] using number_of_iterations_exit to check wrap/overflow Jiu Fu Guo
  -- strict thread matches above, loose matches on Subject: below --
2021-05-20  6:28 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).