[patch, commited] for PR 31885

Zdenek Dvorak rakdver@kam.mff.cuni.cz
Thu May 10 21:46:00 GMT 2007


Hello,

scev analysis considers NULL_TREE (aka chrec_not_analyzed_yet) to be a special
chrec.  This is somewhat problematic, as NULL_TREE usually appears as an
operand of ARRAY_REFs and COMPONENT_REFs.  In the testcase (loop-29.c) 
we determine that the evolution of the control variable is {&a[1], +, cst}.
Number of iterations analysis then asks whether
chrec_contains_undetermined (&a[1]), and fails; thus we do not remove
the loop, as we failed to determine that it is not an infinite one.

Fortunately, chrec_not_analyzed_yet cannot really appear as a part of an
expression; we only use it as a return value from the cache in case some
ssa name was not analysed yet.  Therefore, to fix this problem it
suffices to prevent chrec_contains_undetermined and
automatically_generated_chrec_p from considering NULL to be special.

Accidentaly, I noticed the problem independently during the rewrite of
data reference analysis; as this piece of the patch is not really
related to the rewrite, I am posting it separately now.

Bootstrapped & regtested on x86_64 and ia64, commited.

Zdenek

Index: ChangeLog
===================================================================
*** ChangeLog	(revision 124601)
--- ChangeLog	(working copy)
***************
*** 1,3 ****
--- 1,10 ----
+ 2007-05-10  Zdenek Dvorak  <dvorakz@suse.cz>
+ 
+ 	PR tree-optimization/31885
+ 	* tree-chrec.c (chrec_contains_undetermined): Do not consider NULL_TREE
+ 	to be undetermined.
+ 	(automatically_generated_chrec_p): Return false for NULL.
+ 
  2007-05-08  Bernd Schmidt  <bernd.schmidt@analog.com>
  
  	* config/bfin/bfin.h (MOVE_RATIO): Define.
Index: testsuite/ChangeLog
===================================================================
*** testsuite/ChangeLog	(revision 124601)
--- testsuite/ChangeLog	(working copy)
***************
*** 1,3 ****
--- 1,8 ----
+ 2007-05-10  Zdenek Dvorak  <dvorakz@suse.cz>
+ 
+ 	PR tree-optimization/31885
+ 	* gcc.dg/tree-ssa/loop-29.c: New test.
+ 
  2007-05-10 Dominique d'Humières <dominiq@lps.ens.fr>
  
  	* assumed_dummy_1.f90: Fix dg directive.
Index: tree-chrec.c
===================================================================
*** tree-chrec.c	(revision 124601)
--- tree-chrec.c	(working copy)
*************** chrec_contains_undetermined (tree chrec)
*** 888,898 ****
  {
    int i, n;
  
!   if (chrec == chrec_dont_know
!       || chrec == chrec_not_analyzed_yet
!       || chrec == NULL_TREE)
      return true;
  
    n = TREE_OPERAND_LENGTH (chrec);
    for (i = 0; i < n; i++)
      if (chrec_contains_undetermined (TREE_OPERAND (chrec, i)))
--- 888,899 ----
  {
    int i, n;
  
!   if (chrec == chrec_dont_know)
      return true;
  
+   if (chrec == NULL_TREE)
+     return false;
+ 
    n = TREE_OPERAND_LENGTH (chrec);
    for (i = 0; i < n; i++)
      if (chrec_contains_undetermined (TREE_OPERAND (chrec, i)))
Index: tree-chrec.h
===================================================================
*** tree-chrec.h	(revision 124601)
--- tree-chrec.h	(working copy)
*************** extern GTY(()) tree chrec_known;
*** 36,43 ****
  static inline bool
  automatically_generated_chrec_p (tree chrec)
  {
!   return (chrec == chrec_not_analyzed_yet 
! 	  || chrec == chrec_dont_know
  	  || chrec == chrec_known);
  }
  
--- 36,42 ----
  static inline bool
  automatically_generated_chrec_p (tree chrec)
  {
!   return (chrec == chrec_dont_know
  	  || chrec == chrec_known);
  }
  
Index: testsuite/gcc.dg/tree-ssa/loop-29.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/loop-29.c	(revision 0)
--- testsuite/gcc.dg/tree-ssa/loop-29.c	(revision 0)
***************
*** 0 ****
--- 1,21 ----
+ /* PR 31885 */
+ 
+ /* { dg-do compile } */
+ /* { dg-options "-O1 -fdump-tree-empty" } */
+ 
+ struct s {
+     int *blah;
+ };
+ 
+ static struct s array[] = { { 0 } };
+ 
+ void
+ foo (struct s *p)
+ {
+   struct s *q = &array[1];
+   while (p < q)
+     p++;
+ }
+ 
+ /* { dg-final { scan-tree-dump-times "Removing empty loop" 1 "empty" } } */
+ /* { dg-final { cleanup-tree-dump "empty" } } */



More information about the Gcc-patches mailing list