public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH GCC8][21/33]Support compare iv_use which both sides of comparison are IVs
       [not found] <VI1PR0802MB2176DF34E11846256591339FE7190@VI1PR0802MB2176.eurprd08.prod.outlook.com>
@ 2017-04-18 10:49 ` Bin Cheng
  2017-04-26 13:27   ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Bin Cheng @ 2017-04-18 10:49 UTC (permalink / raw)
  To: gcc-patches; +Cc: nd

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

Hi,
This patch supports compare iv_use for comparison whose both sides are IVs.
With this patch, optimal code is generated for PR53090.
Is it OK?

Thanks,
bin
2017-04-11  Bin Cheng  <bin.cheng@arm.com>

        PR tree-optimization/53090
        * tree-ssa-loop-ivopts.c (enum comp_iv_rewrite): New enum value
        COMP_IV_EXPR_2.
        (extract_cond_operands): Detect condition with IV on both sides
        and return COMP_IV_EXPR_2.
        (find_interesting_uses_cond): Add iv_use for both IVs in condition.
        (rewrite_use_compare): Simplify by removing call to function
        extract_cond_operands.

[-- Attachment #2: 0021-iv-comparing-against-another-iv-20170313.txt --]
[-- Type: text/plain, Size: 3528 bytes --]

From e1037de191416b437f6b1709dd70bb42606d8400 Mon Sep 17 00:00:00 2001
From: Bin Cheng <binche01@e108451-lin.cambridge.arm.com>
Date: Mon, 10 Apr 2017 12:06:25 +0100
Subject: [PATCH 21/33] iv-comparing-against-another-iv-20170313.txt

---
 gcc/tree-ssa-loop-ivopts.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 08b6245..21761e2 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -1651,6 +1651,9 @@ enum comp_iv_rewrite
   COMP_IV_NA,
   /* We may rewrite compare type iv_use by expressing value of the iv_use.  */
   COMP_IV_EXPR,
+  /* We may rewrite compare type iv_uses on both sides of comparison by
+     expressing value of each iv_use.  */
+  COMP_IV_EXPR_2,
   /* We may rewrite compare type iv_use by expressing value of the iv_use
      or by eliminating it with other iv_cand.  */
   COMP_IV_ELIM
@@ -1696,9 +1699,12 @@ extract_cond_operands (struct ivopts_data *data, gimple *stmt,
   if (TREE_CODE (*op1) == SSA_NAME)
     iv1 = get_iv (data, *op1);
 
-  /* If both sides of comparison are IVs.  */
+  /* If both sides of comparison are IVs.  We can express ivs on both end.  */
   if (iv0 && iv1 && !integer_zerop (iv0->step) && !integer_zerop (iv1->step))
-    goto end;
+    {
+      rewrite_type = COMP_IV_EXPR_2;
+      goto end;
+    }
 
   /* If none side of comparison is IV.  */
   if ((!iv0 || integer_zerop (iv0->step))
@@ -1738,10 +1744,11 @@ static void
 find_interesting_uses_cond (struct ivopts_data *data, gimple *stmt)
 {
   tree *var_p, *bound_p;
-  struct iv *var_iv;
+  struct iv *var_iv, *bound_iv;
   enum comp_iv_rewrite ret;
 
-  ret = extract_cond_operands (data, stmt, &var_p, &bound_p, &var_iv, NULL);
+  ret = extract_cond_operands (data, stmt,
+			       &var_p, &bound_p, &var_iv, &bound_iv);
   if (ret == COMP_IV_NA)
     {
       find_interesting_uses_op (data, *var_p);
@@ -1750,6 +1757,9 @@ find_interesting_uses_cond (struct ivopts_data *data, gimple *stmt)
     }
 
   record_group_use (data, var_p, var_iv, stmt, USE_COMPARE);
+  /* Record compare type iv_use for iv on the other side of comparison.  */
+  if (ret == COMP_IV_EXPR_2)
+    record_group_use (data, bound_p, bound_iv, stmt, USE_COMPARE);
 }
 
 /* Returns the outermost loop EXPR is obviously invariant in
@@ -6953,12 +6963,11 @@ static void
 rewrite_use_compare (struct ivopts_data *data,
 		     struct iv_use *use, struct iv_cand *cand)
 {
-  tree comp, *var_p, op, bound;
+  tree comp, op, bound;
   gimple_stmt_iterator bsi = gsi_for_stmt (use->stmt);
   enum tree_code compare;
   struct iv_group *group = data->vgroups[use->group_id];
   struct cost_pair *cp = get_group_iv_cost (data, group, cand);
-  enum comp_iv_rewrite rewrite_type;
 
   bound = cp->value;
   if (bound)
@@ -6991,13 +7000,10 @@ rewrite_use_compare (struct ivopts_data *data,
      giv.  */
   comp = get_computation_at (data->current_loop, use->stmt, use, cand);
   gcc_assert (comp != NULL_TREE);
-
-  rewrite_type = extract_cond_operands (data, use->stmt,
-					&var_p, NULL, NULL, NULL);
-  gcc_assert (rewrite_type != COMP_IV_NA);
-
-  *var_p = force_gimple_operand_gsi (&bsi, comp, true, SSA_NAME_VAR (*var_p),
-				     true, GSI_SAME_STMT);
+  gcc_assert (use->op_p != NULL);
+  *use->op_p = force_gimple_operand_gsi (&bsi, comp, true,
+					 SSA_NAME_VAR (*use->op_p),
+					 true, GSI_SAME_STMT);
 }
 
 /* Rewrite the groups using the selected induction variables.  */
-- 
1.9.1


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

* Re: [PATCH GCC8][21/33]Support compare iv_use which both sides of comparison are IVs
  2017-04-18 10:49 ` [PATCH GCC8][21/33]Support compare iv_use which both sides of comparison are IVs Bin Cheng
@ 2017-04-26 13:27   ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-04-26 13:27 UTC (permalink / raw)
  To: Bin Cheng; +Cc: gcc-patches, nd

On Tue, Apr 18, 2017 at 12:49 PM, Bin Cheng <Bin.Cheng@arm.com> wrote:
> Hi,
> This patch supports compare iv_use for comparison whose both sides are IVs.
> With this patch, optimal code is generated for PR53090.
> Is it OK?

Ok.

Richard.

> Thanks,
> bin
> 2017-04-11  Bin Cheng  <bin.cheng@arm.com>
>
>         PR tree-optimization/53090
>         * tree-ssa-loop-ivopts.c (enum comp_iv_rewrite): New enum value
>         COMP_IV_EXPR_2.
>         (extract_cond_operands): Detect condition with IV on both sides
>         and return COMP_IV_EXPR_2.
>         (find_interesting_uses_cond): Add iv_use for both IVs in condition.
>         (rewrite_use_compare): Simplify by removing call to function
>         extract_cond_operands.

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

end of thread, other threads:[~2017-04-26 13:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <VI1PR0802MB2176DF34E11846256591339FE7190@VI1PR0802MB2176.eurprd08.prod.outlook.com>
2017-04-18 10:49 ` [PATCH GCC8][21/33]Support compare iv_use which both sides of comparison are IVs Bin Cheng
2017-04-26 13:27   ` 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).