diff mbox

Use iv_can_overflow_p in ivopts

Message ID 20160705194623.GA90837@kam.mff.cuni.cz
State New
Headers show

Commit Message

Jan Hubicka July 5, 2016, 7:46 p.m. UTC
Hi,
this patch makes ivopts to use iv_can_overflow_p on its candidates. This helps
to determine if candidate wraps in case it is not directly originating from IV
variable (i.e. it is derived IV or artificial one). For those we can not use
type information because we do now know if they are going to be computed each
iteration. We can still use the iv_can_overflow_p analysis.

I also wrote code that propagates overflow flag from original IVs to derived
ones and it does improve some of real world benchmarks. This patch alone seems
quite benchmark neutral but I would like to proceed in smaller steps.

Bootstrapped/regtested x86_64-linux, OK?

Honza
	* tree-scalar-evolution.c (iv_can_overflow_p): Export.
	* tree-scalar-evolution.h (iv_can_overflow_p): Declare.
	* tree-ssa-loop-ivopts.c (alloc_iv): Use it.

Comments

Richard Biener July 6, 2016, 7:38 a.m. UTC | #1
On Tue, 5 Jul 2016, Jan Hubicka wrote:

> Hi,
> this patch makes ivopts to use iv_can_overflow_p on its candidates. This helps
> to determine if candidate wraps in case it is not directly originating from IV
> variable (i.e. it is derived IV or artificial one). For those we can not use
> type information because we do now know if they are going to be computed each
> iteration. We can still use the iv_can_overflow_p analysis.
> 
> I also wrote code that propagates overflow flag from original IVs to derived
> ones and it does improve some of real world benchmarks. This patch alone seems
> quite benchmark neutral but I would like to proceed in smaller steps.
> 
> Bootstrapped/regtested x86_64-linux, OK?
> 
> Honza
> 	* tree-scalar-evolution.c (iv_can_overflow_p): Export.
> 	* tree-scalar-evolution.h (iv_can_overflow_p): Declare.
> 	* tree-ssa-loop-ivopts.c (alloc_iv): Use it.
> 
> Index: tree-scalar-evolution.c
> ===================================================================
> --- tree-scalar-evolution.c	(revision 238012)
> +++ tree-scalar-evolution.c	(working copy)
> @@ -3317,7 +3317,7 @@ scev_reset (void)
>     use this test even for derived IVs not computed every iteration or
>     hypotetical IVs to be inserted into code.  */
>  
> -static bool
> +bool
>  iv_can_overflow_p (struct loop *loop, tree type, tree base, tree step)
>  {
>    widest_int nit;
> Index: tree-scalar-evolution.h
> ===================================================================
> --- tree-scalar-evolution.h	(revision 238005)
> +++ tree-scalar-evolution.h	(working copy)
> @@ -38,6 +38,7 @@ extern unsigned int scev_const_prop (voi
>  extern bool expression_expensive_p (tree);
>  extern bool simple_iv (struct loop *, struct loop *, tree, struct affine_iv *,
>  		       bool);
> +extern bool iv_can_overflow_p (struct loop *, tree, tree, tree);
>  extern tree compute_overall_effect_of_inner_loop (struct loop *, tree);
>  
>  /* Returns the basic block preceding LOOP, or the CFG entry block when
> Index: tree-ssa-loop-ivopts.c
> ===================================================================
> --- tree-ssa-loop-ivopts.c	(revision 238005)
> +++ tree-ssa-loop-ivopts.c	(working copy)
> @@ -1181,6 +1182,9 @@ alloc_iv (struct ivopts_data *data, tree
>    iv->biv_p = false;
>    iv->nonlin_use = NULL;
>    iv->ssa_name = NULL_TREE;
> +  if (!no_overflow && !iv_can_overflow_p (data->current_loop, TREE_TYPE (base),
> +					  base, step))

please put the && to the next line.

Ok with that change.

Richard.

> +    no_overflow = true;
>    iv->no_overflow = no_overflow;
>    iv->have_address_use = false;
>  
> 
>
diff mbox

Patch

Index: tree-scalar-evolution.c
===================================================================
--- tree-scalar-evolution.c	(revision 238012)
+++ tree-scalar-evolution.c	(working copy)
@@ -3317,7 +3317,7 @@  scev_reset (void)
    use this test even for derived IVs not computed every iteration or
    hypotetical IVs to be inserted into code.  */
 
-static bool
+bool
 iv_can_overflow_p (struct loop *loop, tree type, tree base, tree step)
 {
   widest_int nit;
Index: tree-scalar-evolution.h
===================================================================
--- tree-scalar-evolution.h	(revision 238005)
+++ tree-scalar-evolution.h	(working copy)
@@ -38,6 +38,7 @@  extern unsigned int scev_const_prop (voi
 extern bool expression_expensive_p (tree);
 extern bool simple_iv (struct loop *, struct loop *, tree, struct affine_iv *,
 		       bool);
+extern bool iv_can_overflow_p (struct loop *, tree, tree, tree);
 extern tree compute_overall_effect_of_inner_loop (struct loop *, tree);
 
 /* Returns the basic block preceding LOOP, or the CFG entry block when
Index: tree-ssa-loop-ivopts.c
===================================================================
--- tree-ssa-loop-ivopts.c	(revision 238005)
+++ tree-ssa-loop-ivopts.c	(working copy)
@@ -1181,6 +1182,9 @@  alloc_iv (struct ivopts_data *data, tree
   iv->biv_p = false;
   iv->nonlin_use = NULL;
   iv->ssa_name = NULL_TREE;
+  if (!no_overflow && !iv_can_overflow_p (data->current_loop, TREE_TYPE (base),
+					  base, step))
+    no_overflow = true;
   iv->no_overflow = no_overflow;
   iv->have_address_use = false;