From: Kugan Vivekanandarajah <kugan.vivekanandarajah@linaro.org>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH 2/3][POPCOUNT] Check if zero check is done before entering the loop
Date: Fri, 22 Jun 2018 09:14:00 -0000 [thread overview]
Message-ID: <CAELXzTNzN5nWz_ng548x13DEfXDCouD5gb7CW16c=G51CuruMg@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2018-06-22 9:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-22 9:14 Kugan Vivekanandarajah [this message]
2018-06-25 10:02 ` Richard Biener
2018-06-27 5:01 ` Kugan Vivekanandarajah
2018-06-28 9:54 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAELXzTNzN5nWz_ng548x13DEfXDCouD5gb7CW16c=G51CuruMg@mail.gmail.com' \
--to=kugan.vivekanandarajah@linaro.org \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).