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]

[tree-ssa] Copyprop vs abnormal PHIs


This fixes a problem Andrew noticed while working on the SSA->Normal
pass.  Specifically the copy propagation we do during the Normal->SSA
translation was creating a situation where two variables which 
were arguments associated with abnormal edges in a PHI node had
conflicting lifetimes.  This is a strict no-no as it creates situations
where the SSA->Normal translator can not property translate the code
back into normal form.

	* tree-flow.h (struct var_ann_d): New field occurs_in_abnormal_phi.
	* tree-ssa.c (MAY_COPYPROP_P): Do not allow copy propagations
	if either argument occurs in an abnormal phi.
	* tree-dfa.c (add_phi_arg): Set occurs_in_abrnomal_phi as needed.
	* tree-ssa-copyprop.c (copyprop_stmt): Do not allow copy
	propagations if either argument occurs in an abnormal phi.
	(copyprop_phi): Likewise.

Index: tree-dfa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-dfa.c,v
retrieving revision 1.1.4.111
diff -c -3 -p -r1.1.4.111 tree-dfa.c
*** tree-dfa.c	8 May 2003 20:29:29 -0000	1.1.4.111
--- tree-dfa.c	13 May 2003 16:31:58 -0000
*************** add_phi_arg (phi, def, e)
*** 937,942 ****
--- 937,951 ----
    if (i >= PHI_ARG_CAPACITY (phi))
      abort ();
  #endif
+ 
+   /* Copy propagation needs to know what object occur in abnormal
+      PHI nodes.  This is a convenient place to record such information.  */
+   if (e->flags & EDGE_ABNORMAL)
+     {
+       var_ann (def)->occurs_in_abnormal_phi = 1;
+       var_ann (PHI_RESULT (phi))->occurs_in_abnormal_phi = 1;
+     }
+ 
    PHI_ARG_DEF (phi, i) = def;
    PHI_ARG_EDGE (phi, i) = e;
    PHI_NUM_ARGS (phi)++;
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow.h,v
retrieving revision 1.1.4.77
diff -c -3 -p -r1.1.4.77 tree-flow.h
*** tree-flow.h	8 May 2003 20:29:29 -0000	1.1.4.77
--- tree-flow.h	13 May 2003 16:31:58 -0000
*************** struct var_ann_d GTY(())
*** 93,100 ****
    /* Used when building root_var structures in tree_ssa_live.[ch].  */
    unsigned root_var_processed : 1;
  
    /* Unused bits.  */
!   unsigned unused : 24;
  
    /* An INDIRECT_REF expression representing all the dereferences of this
       pointer.  Used to store aliasing information for pointer dereferences
--- 93,103 ----
    /* Used when building root_var structures in tree_ssa_live.[ch].  */
    unsigned root_var_processed : 1;
  
+   /* Nonzero if the variable occurs in an abnormal PHI.  */
+   unsigned occurs_in_abnormal_phi : 1;
+ 
    /* Unused bits.  */
!   unsigned unused : 23;
  
    /* An INDIRECT_REF expression representing all the dereferences of this
       pointer.  Used to store aliasing information for pointer dereferences
Index: tree-ssa-copyprop.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-copyprop.c,v
retrieving revision 1.1.2.1
diff -c -3 -p -r1.1.2.1 tree-ssa-copyprop.c
*** tree-ssa-copyprop.c	1 Mar 2003 00:09:07 -0000	1.1.2.1
--- tree-ssa-copyprop.c	13 May 2003 16:32:06 -0000
*************** copyprop_stmt (stmt)
*** 114,120 ****
        tree *use_p = (tree *) VARRAY_GENERIC_PTR (uses, i);
        tree orig = get_original (*use_p, &vuse);
  
!       if (orig)
  	{
  	  if (dump_file && (dump_flags & TDF_DETAILS))
  	    {
--- 114,122 ----
        tree *use_p = (tree *) VARRAY_GENERIC_PTR (uses, i);
        tree orig = get_original (*use_p, &vuse);
  
!       if (orig
! 	  && ! var_ann (SSA_NAME_VAR (*use_p))->occurs_in_abnormal_phi
! 	  && ! var_ann (SSA_NAME_VAR (orig))->occurs_in_abnormal_phi)
  	{
  	  if (dump_file && (dump_flags & TDF_DETAILS))
  	    {
*************** copyprop_phi (phi)
*** 159,165 ****
        tree arg = PHI_ARG_DEF (phi, i);
        tree orig = get_original (arg, &vuse);
  
!       if (orig)
  	{
  	  if (dump_file && dump_flags & TDF_DETAILS)
  	    {
--- 161,169 ----
        tree arg = PHI_ARG_DEF (phi, i);
        tree orig = get_original (arg, &vuse);
  
!       if (orig
! 	  && ! var_ann (SSA_NAME_VAR (arg))->occurs_in_abnormal_phi
! 	  && ! var_ann (SSA_NAME_VAR (orig))->occurs_in_abnormal_phi)
  	{
  	  if (dump_file && dump_flags & TDF_DETAILS)
  	    {
Index: tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.4.75
diff -c -3 -p -r1.1.4.75 tree-ssa.c
*** tree-ssa.c	8 May 2003 20:29:30 -0000	1.1.4.75
--- tree-ssa.c	13 May 2003 16:32:09 -0000
*************** static bool var_is_live			PARAMS ((tree,
*** 226,232 ****
  	   && TREE_CODE (SSA_NAME_VAR (RHS)) == INDIRECT_REF)		\
       /* FIXME.  For now, don't propagate pointers if they haven't been	\
          dereferenced (see update_indirect_ref_vuses).  */		\
!      && (!POINTER_TYPE_P (TREE_TYPE (RHS)) || indirect_ref (RHS)))
  
  
  /* Main entry point to the SSA builder.  FNDECL is the gimplified function
--- 226,234 ----
  	   && TREE_CODE (SSA_NAME_VAR (RHS)) == INDIRECT_REF)		\
       /* FIXME.  For now, don't propagate pointers if they haven't been	\
          dereferenced (see update_indirect_ref_vuses).  */		\
!      && (!POINTER_TYPE_P (TREE_TYPE (RHS)) || indirect_ref (RHS))	\
!      && ! var_ann (SSA_NAME_VAR (LHS))->occurs_in_abnormal_phi		\
!      && ! var_ann (SSA_NAME_VAR (RHS))->occurs_in_abnormal_phi)
  
  
  /* Main entry point to the SSA builder.  FNDECL is the gimplified function










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