public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 2/3][POPCOUNT] Check if zero check is done before entering the loop
@ 2018-06-22  9:14 Kugan Vivekanandarajah
  2018-06-25 10:02 ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Kugan Vivekanandarajah @ 2018-06-22  9:14 UTC (permalink / raw)
  To: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 223 bytes --]

gcc/ChangeLog:

2018-06-22  Kugan Vivekanandarajah  <kuganv@linaro.org>

    * tree-ssa-loop-niter.c (number_of_iterations_popcount): If popcount
    argument is checked for zero before entering loop, avoid checking again.

[-- Attachment #2: 0002-in-niter-dont-check-for-zero-when-it-is-alrealy-chec.patch --]
[-- Type: text/x-patch, Size: 2174 bytes --]

From 4f2a6ad5a49eec0a1cae15e033329f889f9137b9 Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah <kugan.vivekanandarajah@linaro.org>
Date: Fri, 22 Jun 2018 14:11:28 +1000
Subject: [PATCH 2/3] in niter dont check for zero when it is alrealy checked

Change-Id: I98982537bca14cb99a85d0da70d33a6c044385fd
---
 gcc/tree-ssa-loop-niter.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index 9365915..2299aca 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -2503,6 +2503,7 @@ number_of_iterations_popcount (loop_p loop, edge exit,
   HOST_WIDE_INT max;
   adjust = true;
   tree fn = NULL_TREE;
+  bool check_zero = true;
 
   /* Check loop terminating branch is like
      if (b != 0).  */
@@ -2590,7 +2591,37 @@ number_of_iterations_popcount (loop_p loop, edge exit,
 
   niter->niter = iter;
   niter->assumptions = boolean_true_node;
-  if (adjust)
+  if (adjust
+      && EDGE_COUNT (loop->header->preds) == 2)
+    {
+      /* Sometimes, src of the popcount is checked for
+	 zero before entering the loop.  In this case we
+	 dont need to check for zero again.  */
+      edge pred_edge = EDGE_PRED (loop->header, 0);
+      gimple *stmt = last_stmt (pred_edge->src);
+
+      /* If there is an empty pre-header, go one block
+	 above.  */
+      if (!stmt
+	  && EDGE_COUNT (pred_edge->src->preds) == 1)
+	{
+	  pred_edge = EDGE_PRED (pred_edge->src, 0);
+	  stmt = last_stmt (pred_edge->src);
+	}
+
+      /* If we have the src != 0 check and if we are entering
+	 the loop when the condition is true, we can skip zero
+	 check.  */
+      if (stmt
+	  && gimple_code (stmt) == GIMPLE_COND
+	  && gimple_cond_code (stmt) == NE_EXPR
+	  && pred_edge->flags & EDGE_TRUE_VALUE
+	  && TREE_CODE (gimple_cond_lhs (stmt)) == SSA_NAME
+	  && (gimple_phi_arg_def (phi, loop_preheader_edge (loop)->dest_idx)
+	      == gimple_cond_lhs (stmt)))
+	check_zero = false;
+    }
+  if (adjust && check_zero)
     niter->may_be_zero = fold_build2 (EQ_EXPR, boolean_type_node, src,
 				      build_zero_cst
 				      (TREE_TYPE (src)));
-- 
2.7.4


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

end of thread, other threads:[~2018-06-28  9:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-22  9:14 [PATCH 2/3][POPCOUNT] Check if zero check is done before entering the loop Kugan Vivekanandarajah
2018-06-25 10:02 ` Richard Biener
2018-06-27  5:01   ` Kugan Vivekanandarajah
2018-06-28  9:54     ` Richard Biener

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).