[PATCH] Fix PR71039

Richard Biener rguenther@suse.de
Tue May 10 13:07:00 GMT 2016


The following fixes PR71039 - we were failing to verify we can
insert the lhs on the predecessor edges.

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

Richard.

2016-05-10  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/71039
	* tree-ssa-phiprop.c: Include tree-ssa-loop.h.
	(chk_uses): New function.
	(propagate_with_phi): Verify we can safely replicate the lhs of an
	aggregate assignment on all incoming edges.

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

Index: gcc/tree-ssa-phiprop.c
===================================================================
*** gcc/tree-ssa-phiprop.c	(revision 236066)
--- gcc/tree-ssa-phiprop.c	(working copy)
*************** along with GCC; see the file COPYING3.
*** 32,37 ****
--- 32,38 ----
  #include "gimplify.h"
  #include "gimple-iterator.h"
  #include "stor-layout.h"
+ #include "tree-ssa-loop.h"
  
  /* This pass propagates indirect loads through the PHI node for its
     address to make the load source possibly non-addressable and to
*************** phiprop_insert_phi (basic_block bb, gphi
*** 230,235 ****
--- 231,249 ----
    return res;
  }
  
+ /* Verify if *idx is available at *DATA.  */
+ 
+ static bool
+ chk_uses (tree t, tree *idx, void *data)
+ {
+   basic_block dom = (basic_block) data;
+   if (TREE_CODE (*idx) == SSA_NAME)
+     return (SSA_NAME_IS_DEFAULT_DEF (*idx)
+ 	    || ! dominated_by_p (CDI_DOMINATORS,
+ 				 gimple_bb (SSA_NAME_DEF_STMT (*idx)), dom));
+   return true;
+ }
+ 
  /* Propagate between the phi node arguments of PHI in BB and phi result
     users.  For now this matches
          # p_2 = PHI <&x, &y>
*************** propagate_with_phi (basic_block bb, gphi
*** 342,347 ****
--- 356,368 ----
           insert aggregate copies on the edges instead.  */
        if (!is_gimple_reg_type (TREE_TYPE (TREE_TYPE (ptr))))
  	{
+ 	  /* As we replicate the lhs on each incoming edge all
+ 	     used SSA names have to be available there.  */
+ 	  if (! for_each_index (gimple_assign_lhs_ptr (use_stmt),
+ 				chk_uses,
+ 				get_immediate_dominator (CDI_DOMINATORS,
+ 							 gimple_bb (phi))))
+ 	    goto next;
  	  phiprop_insert_phi (bb, phi, use_stmt, phivn, n);
  
  	  /* Remove old stmt.  The phi is taken care of by DCE.  */
Index: gcc/testsuite/gcc.dg/torture/pr71039.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr71039.c	(revision 0)
--- gcc/testsuite/gcc.dg/torture/pr71039.c	(working copy)
***************
*** 0 ****
--- 1,14 ----
+ /* { dg-do compile } */
+ 
+ struct wv
+ {
+   int qi;
+ } qp, *ft;
+ void *pb;
+ 
+ void
+ wz (void)
+ {
+   struct wv *vf = pb ? (struct wv *)&pb : &qp;
+   *ft = *vf;
+ }



More information about the Gcc-patches mailing list