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 PR26406, forwprop causing VRP to fail


This fixes the testcase by only propagating single-use variables into
conditionals.

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

Ok for mainline?

Thanks,
Richard.


:ADDPATCH tree-optimization:

2006-02-22  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/26406
	* tree-ssa-forwprop.c (find_equivalent_equality_comparison):
	Only use single-use conversions to simplify conditionals.

	* g++.dg/tree-ssa/pr26406.C: New testcase.


Index: tree-ssa-forwprop.c
===================================================================
*** tree-ssa-forwprop.c	(revision 111330)
--- tree-ssa-forwprop.c	(working copy)
*************** find_equivalent_equality_comparison (tre
*** 428,438 ****
    tree op1 = TREE_OPERAND (cond, 1);
    tree def_stmt = SSA_NAME_DEF_STMT (op0);
  
-   while (def_stmt
- 	 && TREE_CODE (def_stmt) == MODIFY_EXPR
- 	 && TREE_CODE (TREE_OPERAND (def_stmt, 1)) == SSA_NAME)
-     def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (def_stmt, 1));
- 
    /* OP0 might have been a parameter, so first make sure it
       was defined by a MODIFY_EXPR.  */
    if (def_stmt && TREE_CODE (def_stmt) == MODIFY_EXPR)
--- 428,433 ----
*************** find_equivalent_equality_comparison (tre
*** 473,478 ****
--- 468,477 ----
  	      && TREE_CODE (TREE_TYPE (def_rhs_inner_type)) == FUNCTION_TYPE)
  	    return NULL;
  
+ 	  /* If the def lhs does not have only a single use, bail out.  */
+ 	  if (! has_single_use (TREE_OPERAND (def_stmt, 0)))
+ 	    return NULL;
+ 
  	  /* What we want to prove is that if we convert OP1 to
  	     the type of the object inside the NOP_EXPR that the
  	     result is still equivalent to SRC. 



/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-optimized" } */

int *f(int *b)
{
  int * a = new int[104];
  *a = 1;
  if (a == 0)
    return b;
  return a;
}

/* { dg-final { scan-tree-dump-not "if" "optimized" } } */
/* { dg-final { cleanup-tree-dump "optimized" } } */


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