I am currently testing the following patch to fix PR69117 where
during value-numbering we end up using SSA name info (points-to info
in this case but also range-info in general) from the value leader
which may be defined under different conditions than the use is.

The only fix I can think of appropriate for this stage is to make
sure the SSA name info of the leaders is conservative for all possible
uses (thus SSA names value-numbered the same).

Conservatively we can always keep the information from the dominating
name or drop the info in case the two names do not have a dominance
relationship (that's the case where things go wrong for the testcase
and the case where the SCC VN algorithm differs from a RPO one).
Doing either of those three choices makes the operation cheap
(not allocate memory or compute unions).

Hopefully the patch will survive testing.

Bootstrap and regtest in progress on x86_64-unknown-linux-gnu.

Richard.

2016-01-14  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/69117
        * tree-ssa-sccvn.h (struct vn_ssa_aux): Add info member.
        * tree-ssa-sccvn.c (set_ssa_val_to): Save and adjust SSA name info
        of the leader conservatively.
        (free_scc_vn): Restore original SSA name infos.

        * gcc.dg/torture/pr69117.c: New testcase.

Index: gcc/tree-ssa-sccvn.c
===================================================================
*** gcc/tree-ssa-sccvn.c        (revision 232315)
--- gcc/tree-ssa-sccvn.c        (working copy)
*************** set_ssa_val_to (tree from, tree to)
*** 3037,3042 ****
--- 3037,3109 ----
               == get_addr_base_and_unit_offset (TREE_OPERAND (to, 0), &toff))
           && coff == toff))
      {
+       /* If we equate two SSA names we have to make the side-band info
+          of the leader conservative (and remember whatever original value
+        was present).  */
+       if (TREE_CODE (to) == SSA_NAME)
+       {
+         if (INTEGRAL_TYPE_P (TREE_TYPE (to))
+             && SSA_NAME_RANGE_INFO (to))
+           {
+             if (SSA_NAME_IS_DEFAULT_DEF (to)
+                 || dominated_by_p (CDI_DOMINATORS,
+                                    gimple_bb (SSA_NAME_DEF_STMT (from)),
+                                    gimple_bb (SSA_NAME_DEF_STMT (to))))
+               /* Keep the info from the dominator.  */
+               ;
+             else if (SSA_NAME_IS_DEFAULT_DEF (from)
+                      || dominated_by_p (CDI_DOMINATORS,
+                                         gimple_bb (SSA_NAME_DEF_STMT (to)),
+                                         gimple_bb (SSA_NAME_DEF_STMT (from))))
+               {
+                 /* Save old info.  */
+                 if (! VN_INFO (to)->info.range_info)
+                   VN_INFO (to)->info.range_info = SSA_NAME_RANGE_INFO (to);
+                 /* Use that from the dominator.  */
+                 SSA_NAME_RANGE_INFO (to) = SSA_NAME_RANGE_INFO (from);
+               }
+             else
+               {
+                 /* Save old info.  */
+                 if (! VN_INFO (to)->info.range_info)
+                   VN_INFO (to)->info.range_info = SSA_NAME_RANGE_INFO (to);
+                 /* Rather than allocating memory and unioning the info
+                    just clear it.  */
+                 SSA_NAME_RANGE_INFO (to) = NULL;
+               }
+           }
+         else if (POINTER_TYPE_P (TREE_TYPE (to))
+                  && SSA_NAME_PTR_INFO (to))
+           {
+             if (SSA_NAME_IS_DEFAULT_DEF (to)
+                 || dominated_by_p (CDI_DOMINATORS,
+                                    gimple_bb (SSA_NAME_DEF_STMT (from)),
+                                    gimple_bb (SSA_NAME_DEF_STMT (to))))
+               /* Keep the info from the dominator.  */
+               ;
+             else if (SSA_NAME_IS_DEFAULT_DEF (from)
+                      || dominated_by_p (CDI_DOMINATORS,
+                                         gimple_bb (SSA_NAME_DEF_STMT (to)),
+                                         gimple_bb (SSA_NAME_DEF_STMT (from))))
+               {
+                 /* Save old info.  */
+                 if (! VN_INFO (to)->info.ptr_info)
+                   VN_INFO (to)->info.ptr_info = SSA_NAME_PTR_INFO (to);
+                 /* Use that from the dominator.  */
+                 SSA_NAME_PTR_INFO (to) = SSA_NAME_PTR_INFO (from);
+               }
+             else
+               {
+                 /* Save old info.  */
+                 if (! VN_INFO (to)->info.ptr_info)
+                   VN_INFO (to)->info.ptr_info = SSA_NAME_PTR_INFO (to);
+                 /* Rather than allocating memory and unioning the info
+                    just clear it.  */
+                 SSA_NAME_PTR_INFO (to) = NULL;
+               }
+           }
+       }
+ 
        VN_INFO (from)->valnum = to;
        if (dump_file && (dump_flags & TDF_DETAILS))
        fprintf (dump_file, " (changed)\n");
*************** free_scc_vn (void)
*** 4152,4160 ****
      {
        tree name = ssa_name (i);
        if (name
!         && has_VN_INFO (name)
!         && VN_INFO (name)->needs_insertion)
!       release_ssa_name (name);
      }
    obstack_free (&vn_ssa_aux_obstack, NULL);
    vn_ssa_aux_table.release ();
--- 4219,4235 ----
      {
        tree name = ssa_name (i);
        if (name
!         && has_VN_INFO (name))
!       {
!         if (VN_INFO (name)->needs_insertion)
!           release_ssa_name (name);
!         else if (POINTER_TYPE_P (TREE_TYPE (name))
!                  && VN_INFO (name)->info.ptr_info)
!           SSA_NAME_PTR_INFO (name) = VN_INFO (name)->info.ptr_info;
!         else if (INTEGRAL_TYPE_P (TREE_TYPE (name))
!                  && VN_INFO (name)->info.range_info)
!           SSA_NAME_RANGE_INFO (name) = VN_INFO (name)->info.range_info;
!       }
      }
    obstack_free (&vn_ssa_aux_obstack, NULL);
    vn_ssa_aux_table.release ();
Index: gcc/tree-ssa-sccvn.h
===================================================================
*** gcc/tree-ssa-sccvn.h        (revision 232315)
--- gcc/tree-ssa-sccvn.h        (working copy)
*************** typedef struct vn_ssa_aux
*** 169,174 ****
--- 169,177 ----
    /* Statements to insert if needs_insertion is true.  */
    gimple_seq expr;
  
+   /* Saved SSA name info.  */
+   tree_ssa_name::ssa_name_info_type info;
+ 
    /* Unique identifier that all expressions with the same value have. */
    unsigned int value_id;
  
Index: gcc/testsuite/gcc.dg/torture/pr69117.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr69117.c      (revision 0)
--- gcc/testsuite/gcc.dg/torture/pr69117.c      (working copy)
***************
*** 0 ****
--- 1,23 ----
+ /* { dg-do run } */
+ /* { dg-additional-options "-fstrict-aliasing" } */
+ 
+ int a, c, *d = &c, **e = &d, *g = &a;
+ static int ***b, **f = &d;
+ 
+ int
+ main ()
+ {
+   **f = 0;
+   int ****h = 0;
+   if (c) 
+     {
+       *h = &e; 
+       ***b = 0;
+     }
+   *e = g;
+ 
+   if (d != &a)
+     __builtin_abort ();
+ 
+   return 0;
+ }

Reply via email to