This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR23821


This tries to address PR23821 where propagation of equivalences can
cause SCEV analysis to fail and thus loop optimizations to not trigger.

Two passes propagate this kind of equivalences, VRP and DOM.  For
VRP this patch simply disables doing so, for DOM we avoid propagating
equivalences into statements that look like induction variable
increments (something that is done in other places of DOM already).

Bootstrapped and tested on x86_64-unknown-linux-gnu.  I have
tested the effect on SPEC2000 and SPEC2006 and the effects are in
the noise.

Richard.

2009-09-30  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/23821
	* tree-vrp.c (vrp_finalize): Do not perform copy propagation.
	* tree-ssa-dom.c (cprop_operand): Do not propagate copies into
	simple IV increments.

Index: gcc/tree-vrp.c
===================================================================
*** gcc/tree-vrp.c.orig	2009-09-25 17:00:45.000000000 +0200
--- gcc/tree-vrp.c	2009-09-30 12:13:38.000000000 +0200
*************** vrp_finalize (void)
*** 7237,7243 ****
      }
  
    /* We may have ended with ranges that have exactly one value.  Those
!      values can be substituted as any other copy/const propagated
       value using substitute_and_fold.  */
    single_val_range = XCNEWVEC (prop_value_t, num_ssa_names);
  
--- 7237,7243 ----
      }
  
    /* We may have ended with ranges that have exactly one value.  Those
!      values can be substituted as any other const propagated
       value using substitute_and_fold.  */
    single_val_range = XCNEWVEC (prop_value_t, num_ssa_names);
  
*************** vrp_finalize (void)
*** 7245,7251 ****
    for (i = 0; i < num_ssa_names; i++)
      if (vr_value[i]
  	&& vr_value[i]->type == VR_RANGE
! 	&& vr_value[i]->min == vr_value[i]->max)
        {
  	single_val_range[i].value = vr_value[i]->min;
  	do_value_subst_p = true;
--- 7245,7252 ----
    for (i = 0; i < num_ssa_names; i++)
      if (vr_value[i]
  	&& vr_value[i]->type == VR_RANGE
! 	&& vr_value[i]->min == vr_value[i]->max
! 	&& is_gimple_min_invariant (vr_value[i]->min))
        {
  	single_val_range[i].value = vr_value[i]->min;
  	do_value_subst_p = true;
Index: gcc/tree-ssa-dom.c
===================================================================
*** gcc/tree-ssa-dom.c.orig	2009-09-28 17:35:21.000000000 +0200
--- gcc/tree-ssa-dom.c	2009-09-30 12:42:31.000000000 +0200
*************** cprop_operand (gimple stmt, use_operand_
*** 1998,2003 ****
--- 1998,2009 ----
        if (loop_depth_of_name (val) > loop_depth_of_name (op))
  	return;
  
+       /* Do not propagate copies into simple IV increment statements.
+          See PR23821 for how this can disturb IV analysis.  */
+       if (TREE_CODE (val) != INTEGER_CST
+ 	  && simple_iv_increment_p (stmt))
+ 	return;
+ 
        /* Dump details.  */
        if (dump_file && (dump_flags & TDF_DETAILS))
  	{
Index: gcc/testsuite/gcc.dg/torture/pr23821.c
===================================================================
*** /dev/null	1970-01-01 00:00:00.000000000 +0000
--- gcc/testsuite/gcc.dg/torture/pr23821.c	2009-09-30 12:32:00.000000000 +0200
***************
*** 0 ****
--- 1,29 ----
+ /* { dg-do compile } */
+ /* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
+ /* At -O1 DOM threads a jump in a non-optimal way which leads to
+    the bogus propagation.  */
+ /* { dg-skip-if "" { *-*-* } { "-O1" } { "" } } */
+ /* { dg-options "-fdump-tree-ivcanon-details" } */
+ 
+ static int a[199];
+ 
+ extern void abort (void);
+ 
+ int
+ main ()
+ {
+   int i, x;
+   for (i = 0; i < 199; i++)
+     {
+       x = a[i];
+       if (x != i)
+ 	abort ();
+     }
+   return 0;
+ }
+ 
+ /* Verify that we do not propagate the equivalence x == i into the
+    induction variable increment.  */
+ 
+ /* { dg-final { scan-tree-dump "Added canonical iv" "ivcanon" } } */
+ /* { dg-final { cleanup-tree-dump "ivcanon" } } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]