[PATCH] Fix PR31146, make forwprop propagate ADDR_EXPRs through conversions

Richard Guenther rguenther@suse.de
Thu Mar 15 10:37:00 GMT 2007


This makes forwprop propagate ADDR_EXRPs through conversions so they
are available for later tree combining in conditionals like for the
code generated by

  (void) (TARGET_EXPR <D.2605, (double *) operator new (8, (void *) 
&a[i])>;, D.2605 != 0B ? try
    {
      *D.2605 = 0.0;
    }
  catch 
    {
      operator delete ((void *) D.2605, (void *) &a[i]);
    }, D.2605 : D.2605;)

which results in

  __p_5 = &a[i_3];
  iftmp.3_6 = (double *) __p_5;
  if (iftmp.3_6 != 0B) goto <L1>; else goto <L2>;

<L1>:;
  *iftmp.3_6 = 0.0;

<L2>:;

note that __p_5 is of type void*, but t_s_u_t_c says we can remove the
explicit cast.  This allows us to generate

  a[i_3] = 0.0;

if you combine this patch with the patch for PRs 30965 and 30978
(http://gcc.gnu.org/ml/gcc-patches/2007-03/msg00129.html).


Bootstrapped and tested on x86_64-unknown-linux-gnu, ok for mainline?

Thanks,
Richard.

2007-03-12  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/31146
	* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Handle
	propagating into conversions.

Index: gcc/tree-ssa-forwprop.c
===================================================================
*** gcc.orig/tree-ssa-forwprop.c	2007-03-12 14:15:17.000000000 +0100
--- gcc/tree-ssa-forwprop.c	2007-03-12 14:41:52.000000000 +0100
*************** forward_propagate_addr_expr_1 (tree stmt
*** 683,688 ****
--- 683,690 ----
    while (TREE_CODE (lhs) == COMPONENT_REF || TREE_CODE (lhs) == ARRAY_REF)
      lhs = TREE_OPERAND (lhs, 0);
  
+   rhs = GIMPLE_STMT_OPERAND (use_stmt, 1);
+ 
    /* Now see if the LHS node is an INDIRECT_REF using NAME.  If so, 
       propagate the ADDR_EXPR into the use of NAME and fold the result.  */
    if (TREE_CODE (lhs) == INDIRECT_REF && TREE_OPERAND (lhs, 0) == name)
*************** forward_propagate_addr_expr_1 (tree stmt
*** 694,708 ****
        tidy_after_forward_propagate_addr (use_stmt);
      }
  
!   /* Trivial case.  The use statement could be a trivial copy.  We
!      go ahead and handle that case here since it's trivial and
!      removes the need to run copy-prop before this pass to get
       the best results.  Also note that by handling this case here
       we can catch some cascading effects, ie the single use is
       in a copy, and the copy is used later by a single INDIRECT_REF
       for example.  */
!   else if (TREE_CODE (lhs) == SSA_NAME
!       	   && GIMPLE_STMT_OPERAND (use_stmt, 1) == name)
      {
        GIMPLE_STMT_OPERAND (use_stmt, 1)
  	= unshare_expr (GIMPLE_STMT_OPERAND (stmt, 1));
--- 696,714 ----
        tidy_after_forward_propagate_addr (use_stmt);
      }
  
!   /* Trivial case.  The use statement could be a trivial copy or a
!      useless conversion.  We go ahead and handle that case here since it's
!      trivial and removes the need to run copy-prop before this pass to get
       the best results.  Also note that by handling this case here
       we can catch some cascading effects, ie the single use is
       in a copy, and the copy is used later by a single INDIRECT_REF
       for example.  */
!   else if ((TREE_CODE (lhs) == SSA_NAME
!       	    && rhs == name)
! 	   || ((TREE_CODE (rhs) == NOP_EXPR
! 		|| TREE_CODE (rhs) == CONVERT_EXPR)
! 	       && tree_ssa_useless_type_conversion_1 (TREE_TYPE (rhs),
! 				 TREE_TYPE (GIMPLE_STMT_OPERAND (stmt, 1)))))
      {
        GIMPLE_STMT_OPERAND (use_stmt, 1)
  	= unshare_expr (GIMPLE_STMT_OPERAND (stmt, 1));
*************** forward_propagate_addr_expr_1 (tree stmt
*** 712,718 ****
  
    /* Strip away any outer COMPONENT_REF, ARRAY_REF or ADDR_EXPR
       nodes from the RHS.  */
-   rhs = GIMPLE_STMT_OPERAND (use_stmt, 1);
    while (TREE_CODE (rhs) == COMPONENT_REF
  	 || TREE_CODE (rhs) == ARRAY_REF
  	 || TREE_CODE (rhs) == ADDR_EXPR)
--- 718,723 ----



More information about the Gcc-patches mailing list