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 PR42871, recursion in phi_translate


We end up recursing in phi-translate because we have something
like a[i_1] in the set we want to translate but not i_1 and
we end up using a[i_1] as leader for i_1 (where both a[i_1]
and i_1 have the same value-id).

The problem is that when translating in a case like above
and the translation turns both expressions into the same
value-id we can end up with the non-NAME, thus drop the
leader.  Nothing too bad for regular ANTIC - we'd just drop
the expression on the floor again, but with PA-ANTIC we
can run into the first situation.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

Just in case - Danny, is there anything that should avoid
running into the case described by the 2nd paragraph?

Thanks,
Richard.

2010-01-27  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/42871
	* tree-ssa-pre.c (phi_translate_set): Make sure to retain
	leaders.

	* g++.dg/torture/pr42871.C: New testcase.

Index: gcc/tree-ssa-pre.c
===================================================================
*** gcc/tree-ssa-pre.c	(revision 156276)
--- gcc/tree-ssa-pre.c	(working copy)
*************** phi_translate_set (bitmap_set_t dest, bi
*** 1834,1845 ****
      {
        pre_expr translated;
        translated = phi_translate (expr, set, NULL, pred, phiblock);
  
        /* Don't add empty translations to the cache  */
        if (translated)
  	phi_trans_add (expr, translated, pred);
  
!       if (translated != NULL)
  	bitmap_value_insert_into_set (dest, translated);
      }
    VEC_free (pre_expr, heap, exprs);
--- 1834,1853 ----
      {
        pre_expr translated;
        translated = phi_translate (expr, set, NULL, pred, phiblock);
+       if (!translated)
+ 	continue;
  
        /* Don't add empty translations to the cache  */
        if (translated)
  	phi_trans_add (expr, translated, pred);
  
!       /* We might end up with multiple expressions from SET being
! 	 translated to the same value.  In this case we do not want
! 	 to retain the NARY or REFERENCE expression but prefer a NAME
! 	 which would be the leader.  */
!       if (translated->kind == NAME)
! 	bitmap_value_replace_in_set (dest, translated);
!       else
  	bitmap_value_insert_into_set (dest, translated);
      }
    VEC_free (pre_expr, heap, exprs);
Index: gcc/testsuite/g++.dg/torture/pr42871.C
===================================================================
*** gcc/testsuite/g++.dg/torture/pr42871.C	(revision 0)
--- gcc/testsuite/g++.dg/torture/pr42871.C	(revision 0)
***************
*** 0 ****
--- 1,40 ----
+ struct C
+ {
+   ~C ();
+   int c3;
+ };
+ 
+ C *b2;
+ 
+ static void
+ b1 (const C &x, unsigned b3, unsigned b4)
+ {
+   unsigned i = 0;
+   for (; i < b3; i++)
+     if (i < b4)
+       {
+         b2[0].c3 = x.c3;
+         return;
+       }
+ }
+ 
+ int a ();
+ 
+ void
+ bar (unsigned b3, unsigned b4)
+ {
+   C c[100];
+   for (int i = 0; i < 100; i++)
+     {
+       c[i].c3 = i;
+       for (int j = 0; j < b3; j++)
+         if (j < b4)
+           {
+             b2[0].c3 = 0;
+             break;
+           }
+       b1 (c[i], b3, b4);
+       a ();
+     }
+ }
+ 


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