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] partial fix for tree-ssa/20031216-1.c


Partial because this manages to fold

  a_2 = b_1 + 2;
  a_3 = a_2 - 1;
  a_4 = a_3 - 1;
  if (a_4 != b_1) goto <L0>; else goto <L1>;

to 

  a_4 = b_1;
  if (a_4 != b_1) goto <L0>; else goto <L1>;

but somehow doesn't manage to simplify the branch.

Silly me thought fixing this mixing plus/minus thing would obviously solve
the problem and didn't bother checking before running it through a complete
test cycle.  Oh well, it'll make the next patch somewhat smaller...


r~


        * tree-ssa-dom.c (simplify_rhs_and_lookup_avail_expr): Allow
        mixing PLUS and MINUS when folding operations.

Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dom.c,v
retrieving revision 1.1.2.122
diff -c -p -d -r1.1.2.122 tree-ssa-dom.c
*** tree-ssa-dom.c	4 Feb 2004 11:36:10 -0000	1.1.2.122
--- tree-ssa-dom.c	6 Feb 2004 06:22:32 -0000
*************** simplify_rhs_and_lookup_avail_expr (stru
*** 1675,1708 ****
        tree rhs_def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (rhs, 0));
  
        /* See if the RHS_DEF_STMT has the same form as our statement.  */
!       if (TREE_CODE (rhs_def_stmt) == MODIFY_EXPR
! 	  && TREE_CODE (TREE_OPERAND (rhs_def_stmt, 1)) == rhs_code)
  	{
  	  tree rhs_def_rhs = TREE_OPERAND (rhs_def_stmt, 1);
! 	  tree def_stmt_op0 = TREE_OPERAND (rhs_def_rhs, 0);
! 	  tree def_stmt_op1 = TREE_OPERAND (rhs_def_rhs, 1);
  
! 	  if (TREE_CODE (def_stmt_op0) == SSA_NAME
! 	      && ! SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def_stmt_op0)
! 	      && TREE_CONSTANT (def_stmt_op1))
  	    {
! 	      tree outer_const = TREE_OPERAND (rhs, 1);
! 	      tree type = TREE_TYPE (TREE_OPERAND (stmt, 0));
! 	      tree t;
  
! 	      /* Build and fold (Y OP C2) OP C1.  */
! 	      t = fold (build (rhs_code, type, rhs_def_rhs, outer_const));
  
! 	      /* If the result is a suitable looking gimple expression,
! 		 then use it instead of the original expression for STMT.  */
! 	      if (TREE_CODE (t) == SSA_NAME
! 		  || (TREE_CODE (t) == rhs_code
! 		      && TREE_CODE (TREE_OPERAND (t, 0)) == SSA_NAME
! 		      && TREE_CONSTANT (TREE_OPERAND (t, 1))))
! 		result = update_rhs_and_lookup_avail_expr (stmt, t,
! 							   &bd->avail_exprs,
! 						           ann,
! 							   insert);
  	    }
  	}
      }
--- 1675,1715 ----
        tree rhs_def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (rhs, 0));
  
        /* See if the RHS_DEF_STMT has the same form as our statement.  */
!       if (TREE_CODE (rhs_def_stmt) == MODIFY_EXPR)
  	{
  	  tree rhs_def_rhs = TREE_OPERAND (rhs_def_stmt, 1);
! 	  enum tree_code rhs_def_code = TREE_CODE (rhs_def_rhs);
  
! 	  if (rhs_code == rhs_def_code
! 	      || (rhs_code == PLUS_EXPR && rhs_def_code == MINUS_EXPR)
! 	      || (rhs_code == MINUS_EXPR && rhs_def_code == PLUS_EXPR))
  	    {
! 	      tree def_stmt_op0 = TREE_OPERAND (rhs_def_rhs, 0);
! 	      tree def_stmt_op1 = TREE_OPERAND (rhs_def_rhs, 1);
  
! 	      if (TREE_CODE (def_stmt_op0) == SSA_NAME
! 		  && ! SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def_stmt_op0)
! 		  && TREE_CONSTANT (def_stmt_op1))
! 		{
! 		  tree outer_const = TREE_OPERAND (rhs, 1);
! 		  tree type = TREE_TYPE (TREE_OPERAND (stmt, 0));
! 		  tree t;
  
! 		  /* Build and fold (Y OP C2) OP C1.  */
! 		  t = fold (build (rhs_code, type, rhs_def_rhs, outer_const));
! 
! 		  /* If the result is a suitable looking gimple expression,
! 		     then use it instead of the original for STMT.  */
! 		  if (TREE_CODE (t) == SSA_NAME
! 		      || (TREE_CODE_CLASS (TREE_CODE (t)) == '1'
! 			  && TREE_CODE (TREE_OPERAND (t, 0)) == SSA_NAME)
! 		      || ((TREE_CODE_CLASS (TREE_CODE (t)) == '2'
! 			   || TREE_CODE_CLASS (TREE_CODE (t)) == '<')
! 			  && TREE_CODE (TREE_OPERAND (t, 0)) == SSA_NAME
! 			  && TREE_CONSTANT (TREE_OPERAND (t, 1))))
! 		    result = update_rhs_and_lookup_avail_expr
! 		      (stmt, t, &bd->avail_exprs, ann, insert);
! 		}
  	    }
  	}
      }


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