public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Improve unroller size estimate
@ 2017-02-14 14:55 Richard Biener
  2017-04-21  8:20 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2017-02-14 14:55 UTC (permalink / raw)
  To: gcc-patches


The following patch improves the constant_after_peeling estimate of
the GIMPLE unroller by not requiring a strictly "simple-iv" but
an evolution w/o symbols.  It also avoids computing any of this for
ops defined in a subloop of the loop we unroll (that only yields
garbage).  So it makes constant_after_peeling cheaper as well.

It also adjusts the simple-minded CCP to propagate all constants
(esp. float and vector constants).

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress, queued for 
GCC 8.

Richard.

2016-02-14  Richard Biener  <rguenther@suse.de>

	* tree-ssa-loop-ivcanon.c (constant_after_peeling): Do not require
	sth as strict as a simple_iv but a chrec without symbols and an
	operand defined in the loop we are peeling (and not some subloop).
	(propagate_constants_for_unrolling): Propagate all constants.

	* gcc.dg/vect/no-scevccp-outer-13.c: Adjust to prevent unrolling
	of inner loops.
	* gcc.dg/vect/no-scevccp-outer-7.c: Likewise.
	* gcc.dg/vect/vect-104.c: Likewise.

Index: gcc/tree-ssa-loop-ivcanon.c
===================================================================
--- gcc/tree-ssa-loop-ivcanon.c	(revision 245417)
+++ gcc/tree-ssa-loop-ivcanon.c	(working copy)
@@ -157,8 +157,6 @@ struct loop_size
 static bool
 constant_after_peeling (tree op, gimple *stmt, struct loop *loop)
 {
-  affine_iv iv;
-
   if (is_gimple_min_invariant (op))
     return true;
 
@@ -188,12 +186,12 @@ constant_after_peeling (tree op, gimple
       return false;
     }
 
-  /* Induction variables are constants.  */
-  if (!simple_iv (loop, loop_containing_stmt (stmt), op, &iv, false))
-    return false;
-  if (!is_gimple_min_invariant (iv.base))
+  /* Induction variables are constants when defined in loop.  */
+  if (loop_containing_stmt (stmt) != loop)
     return false;
-  if (!is_gimple_min_invariant (iv.step))
+  tree ev = analyze_scalar_evolution (loop, op);
+  if (chrec_contains_undetermined (ev)
+      || chrec_contains_symbols (ev))
     return false;
   return true;
 }
@@ -1259,7 +1257,7 @@ propagate_constants_for_unrolling (basic
 
       if (! SSA_NAME_OCCURS_IN_ABNORMAL_PHI (result)
 	  && gimple_phi_num_args (phi) == 1
-	  && TREE_CODE (arg) == INTEGER_CST)
+	  && CONSTANT_CLASS_P (arg))
 	{
 	  replace_uses_by (result, arg);
 	  gsi_remove (&gsi, true);
@@ -1276,7 +1274,7 @@ propagate_constants_for_unrolling (basic
       tree lhs;
 
       if (is_gimple_assign (stmt)
-	  && gimple_assign_rhs_code (stmt) == INTEGER_CST
+	  && TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) == tcc_constant
 	  && (lhs = gimple_assign_lhs (stmt), TREE_CODE (lhs) == SSA_NAME)
 	  && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
 	{
Index: gcc/testsuite/gcc.dg/vect/no-scevccp-outer-13.c
===================================================================
--- gcc/testsuite/gcc.dg/vect/no-scevccp-outer-13.c	(revision 245417)
+++ gcc/testsuite/gcc.dg/vect/no-scevccp-outer-13.c	(working copy)
@@ -1,4 +1,5 @@
 /* { dg-require-effective-target vect_int } */
+/* { dg-additional-options "--param max-completely-peel-times=1" } */
 
 #include <stdarg.h>
 #include "tree-vect.h"
Index: gcc/testsuite/gcc.dg/vect/no-scevccp-outer-7.c
===================================================================
--- gcc/testsuite/gcc.dg/vect/no-scevccp-outer-7.c	(revision 245417)
+++ gcc/testsuite/gcc.dg/vect/no-scevccp-outer-7.c	(working copy)
@@ -1,4 +1,5 @@
 /* { dg-require-effective-target vect_int } */
+/* { dg-additional-options "--param max-completely-peel-times=1" } */
 
 #include <stdarg.h>
 #include "tree-vect.h"
Index: gcc/testsuite/gcc.dg/vect/vect-104.c
===================================================================
--- gcc/testsuite/gcc.dg/vect/vect-104.c	(revision 245417)
+++ gcc/testsuite/gcc.dg/vect/vect-104.c	(working copy)
@@ -1,4 +1,5 @@
 /* { dg-require-effective-target vect_int } */
+/* { dg-additional-options "--param max-completely-peel-times=1" } */
 
 #include <stdlib.h>
 #include <stdarg.h>

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

* Re: [PATCH] Improve unroller size estimate
  2017-02-14 14:55 [PATCH] Improve unroller size estimate Richard Biener
@ 2017-04-21  8:20 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-04-21  8:20 UTC (permalink / raw)
  To: GCC Patches

On Tue, Feb 14, 2017 at 3:53 PM, Richard Biener <rguenther@suse.de> wrote:
>
> The following patch improves the constant_after_peeling estimate of
> the GIMPLE unroller by not requiring a strictly "simple-iv" but
> an evolution w/o symbols.  It also avoids computing any of this for
> ops defined in a subloop of the loop we unroll (that only yields
> garbage).  So it makes constant_after_peeling cheaper as well.
>
> It also adjusts the simple-minded CCP to propagate all constants
> (esp. float and vector constants).
>
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress, queued for
> GCC 8.

Re-bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

> Richard.
>
> 2016-02-14  Richard Biener  <rguenther@suse.de>
>
>         * tree-ssa-loop-ivcanon.c (constant_after_peeling): Do not require
>         sth as strict as a simple_iv but a chrec without symbols and an
>         operand defined in the loop we are peeling (and not some subloop).
>         (propagate_constants_for_unrolling): Propagate all constants.
>
>         * gcc.dg/vect/no-scevccp-outer-13.c: Adjust to prevent unrolling
>         of inner loops.
>         * gcc.dg/vect/no-scevccp-outer-7.c: Likewise.
>         * gcc.dg/vect/vect-104.c: Likewise.
>
> Index: gcc/tree-ssa-loop-ivcanon.c
> ===================================================================
> --- gcc/tree-ssa-loop-ivcanon.c (revision 245417)
> +++ gcc/tree-ssa-loop-ivcanon.c (working copy)
> @@ -157,8 +157,6 @@ struct loop_size
>  static bool
>  constant_after_peeling (tree op, gimple *stmt, struct loop *loop)
>  {
> -  affine_iv iv;
> -
>    if (is_gimple_min_invariant (op))
>      return true;
>
> @@ -188,12 +186,12 @@ constant_after_peeling (tree op, gimple
>        return false;
>      }
>
> -  /* Induction variables are constants.  */
> -  if (!simple_iv (loop, loop_containing_stmt (stmt), op, &iv, false))
> -    return false;
> -  if (!is_gimple_min_invariant (iv.base))
> +  /* Induction variables are constants when defined in loop.  */
> +  if (loop_containing_stmt (stmt) != loop)
>      return false;
> -  if (!is_gimple_min_invariant (iv.step))
> +  tree ev = analyze_scalar_evolution (loop, op);
> +  if (chrec_contains_undetermined (ev)
> +      || chrec_contains_symbols (ev))
>      return false;
>    return true;
>  }
> @@ -1259,7 +1257,7 @@ propagate_constants_for_unrolling (basic
>
>        if (! SSA_NAME_OCCURS_IN_ABNORMAL_PHI (result)
>           && gimple_phi_num_args (phi) == 1
> -         && TREE_CODE (arg) == INTEGER_CST)
> +         && CONSTANT_CLASS_P (arg))
>         {
>           replace_uses_by (result, arg);
>           gsi_remove (&gsi, true);
> @@ -1276,7 +1274,7 @@ propagate_constants_for_unrolling (basic
>        tree lhs;
>
>        if (is_gimple_assign (stmt)
> -         && gimple_assign_rhs_code (stmt) == INTEGER_CST
> +         && TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) == tcc_constant
>           && (lhs = gimple_assign_lhs (stmt), TREE_CODE (lhs) == SSA_NAME)
>           && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
>         {
> Index: gcc/testsuite/gcc.dg/vect/no-scevccp-outer-13.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/vect/no-scevccp-outer-13.c     (revision 245417)
> +++ gcc/testsuite/gcc.dg/vect/no-scevccp-outer-13.c     (working copy)
> @@ -1,4 +1,5 @@
>  /* { dg-require-effective-target vect_int } */
> +/* { dg-additional-options "--param max-completely-peel-times=1" } */
>
>  #include <stdarg.h>
>  #include "tree-vect.h"
> Index: gcc/testsuite/gcc.dg/vect/no-scevccp-outer-7.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/vect/no-scevccp-outer-7.c      (revision 245417)
> +++ gcc/testsuite/gcc.dg/vect/no-scevccp-outer-7.c      (working copy)
> @@ -1,4 +1,5 @@
>  /* { dg-require-effective-target vect_int } */
> +/* { dg-additional-options "--param max-completely-peel-times=1" } */
>
>  #include <stdarg.h>
>  #include "tree-vect.h"
> Index: gcc/testsuite/gcc.dg/vect/vect-104.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/vect/vect-104.c        (revision 245417)
> +++ gcc/testsuite/gcc.dg/vect/vect-104.c        (working copy)
> @@ -1,4 +1,5 @@
>  /* { dg-require-effective-target vect_int } */
> +/* { dg-additional-options "--param max-completely-peel-times=1" } */
>
>  #include <stdlib.h>
>  #include <stdarg.h>

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

end of thread, other threads:[~2017-04-21  8:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-14 14:55 [PATCH] Improve unroller size estimate Richard Biener
2017-04-21  8:20 ` 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).