[tree-ssa] Optimize ABS_EXPR

law@redhat.com law@redhat.com
Tue Aug 12 18:29:00 GMT 2003


This fixes another of the new tree-ssa tests by optimizing ABS_EXPR when
we know the sign of the source operand.  This change also makes the rewriting
of TRUNC_DIV_EXPR/TRUNC_MOD_EXPR a little more aggressive.

	* tree-ssa-dom.c (optimize_stmt): Optimize ABS_EXPR when we know
	the sign of the source operand.

	* tree-ssa-dom.c (optimize_stmt): Rewrite TRUNC_DIV_EXPR and
	TRUNC_MOD_EXPR even if the LHS is not an SSA variable.  Do not
	enter the new expression in the hash tables if !may_optimize_p.
	Also try GE_EXPR to see if this transformation is safe.

	* tree-ssa-dom.c (optimize_stmt): Fix typo in last change which
	prevented recording equivalences created by IOR_EXPR.

Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dom.c,v
retrieving revision 1.1.2.18
diff -c -3 -p -r1.1.2.18 tree-ssa-dom.c
*** tree-ssa-dom.c	12 Aug 2003 14:31:57 -0000	1.1.2.18
--- tree-ssa-dom.c	12 Aug 2003 18:23:20 -0000
*************** optimize_stmt (block_stmt_iterator si, v
*** 770,776 ****
  	 the result is nonzero is worth the effort.  */
        if (TREE_CODE (TREE_OPERAND (stmt, 0)) == SSA_NAME
  	  && TREE_CODE (TREE_OPERAND (stmt, 1)) == BIT_IOR_EXPR
! 	  && integer_zerop (TREE_OPERAND (TREE_OPERAND (stmt, 1), 1)))
  	{
  	  tree cond;
  	  tree op = TREE_OPERAND (stmt, 0);
--- 770,776 ----
  	 the result is nonzero is worth the effort.  */
        if (TREE_CODE (TREE_OPERAND (stmt, 0)) == SSA_NAME
  	  && TREE_CODE (TREE_OPERAND (stmt, 1)) == BIT_IOR_EXPR
! 	  && integer_nonzerop (TREE_OPERAND (TREE_OPERAND (stmt, 1), 1)))
  	{
  	  tree cond;
  	  tree op = TREE_OPERAND (stmt, 0);
*************** optimize_stmt (block_stmt_iterator si, v
*** 786,794 ****
        /* Transform TRUNC_DIV_EXPR and TRUNC_MOD_EXPR into RSHIFT_EXPR and
           BIT_AND_EXPR respectively if the first operand is greater than
  	 zero and the second operand is an exact power of two.  */
!       if (TREE_CODE (TREE_OPERAND (stmt, 0)) == SSA_NAME
! 	  && (TREE_CODE (TREE_OPERAND (stmt, 1)) == TRUNC_DIV_EXPR
! 	      || TREE_CODE (TREE_OPERAND (stmt, 1)) == TRUNC_MOD_EXPR)
  	  && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (stmt, 1), 0)))
  	  && integer_pow2p (TREE_OPERAND (TREE_OPERAND (stmt, 1), 1)))
          {
--- 786,793 ----
        /* Transform TRUNC_DIV_EXPR and TRUNC_MOD_EXPR into RSHIFT_EXPR and
           BIT_AND_EXPR respectively if the first operand is greater than
  	 zero and the second operand is an exact power of two.  */
!       if ((TREE_CODE (TREE_OPERAND (stmt, 1)) == TRUNC_DIV_EXPR
! 	   || TREE_CODE (TREE_OPERAND (stmt, 1)) == TRUNC_MOD_EXPR)
  	  && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (stmt, 1), 0)))
  	  && integer_pow2p (TREE_OPERAND (TREE_OPERAND (stmt, 1), 1)))
          {
*************** optimize_stmt (block_stmt_iterator si, v
*** 799,804 ****
--- 798,813 ----
  	  cond = build (COND_EXPR, void_type_node, cond, NULL, NULL);
  	  val = lookup_avail_expr (cond, block_avail_exprs_p, const_and_copies);
  
+ 	  /* Also try with GE_EXPR if we did not get a hit with GT_EXPR.  */
+ 	  if (! val || ! integer_onep (val))
+ 	    {
+ 	      cond = build (GE_EXPR, boolean_type_node, op, integer_zero_node);
+ 	      cond = build (COND_EXPR, void_type_node, cond, NULL, NULL);
+ 	      val = lookup_avail_expr (cond,
+ 				       block_avail_exprs_p,
+ 				       const_and_copies);
+ 	    }
+ 	    
  	  if (val && integer_onep (val))
  	    {
  	      tree t;
*************** optimize_stmt (block_stmt_iterator si, v
*** 814,831 ****
  					op1, integer_one_node)));
  
  	      /* Remove the old entry from the hash table.  */
! 	      htab_remove_elt (avail_exprs, stmt);
  
  	      /* Now update the RHS of the assignment to use the new node.  */
  	      TREE_OPERAND (stmt, 1) = t;
  
! 	      /* Now force the updated statement into the hash table.  */
! 	      lookup_avail_expr (stmt, block_avail_exprs_p, const_and_copies);
  
! 	      /* Annoyingly we now have two entries for this statement in
! 	         BLOCK_AVAIL_EXPRs.  Luckily we can just pop off the newest
! 		 entry.  */
! 	      VARRAY_POP (*block_avail_exprs_p);
  
  	      /* And make sure we record the fact that we modified this
  	         statement.  */
--- 823,905 ----
  					op1, integer_one_node)));
  
  	      /* Remove the old entry from the hash table.  */
! 	      if (may_optimize_p)
! 		htab_remove_elt (avail_exprs, stmt);
  
  	      /* Now update the RHS of the assignment to use the new node.  */
  	      TREE_OPERAND (stmt, 1) = t;
  
! 	      if (may_optimize_p)
! 		{
! 		  /* Now force the updated statement into the hash table.  */
! 		  lookup_avail_expr (stmt,
! 				     block_avail_exprs_p,
! 				     const_and_copies);
! 
! 		  /* Annoyingly we now have two entries for this statement in
! 		     BLOCK_AVAIL_EXPRs.  Luckily we can just pop off the newest
! 		     entry.  */
! 		  VARRAY_POP (*block_avail_exprs_p);
! 		}
! 
! 	      /* And make sure we record the fact that we modified this
! 	         statement.  */
! 	      ann->modified = 1;
! 	    }
!         }
! 
!       if (TREE_CODE (TREE_OPERAND (stmt, 1)) == ABS_EXPR
! 	  && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (TREE_OPERAND (stmt, 1), 0))))
!         {
! 	  tree cond, val;
! 	  tree op = TREE_OPERAND (TREE_OPERAND (stmt, 1), 0);
! 	  tree type = TREE_TYPE (op);
! 
! 	  cond = build (LT_EXPR, boolean_type_node, op,
! 			convert (type, integer_zero_node));
! 	  cond = build (COND_EXPR, void_type_node, cond, NULL, NULL);
! 	  val = lookup_avail_expr (cond, block_avail_exprs_p, const_and_copies);
! 
! 	  if (! val
! 	      || (! integer_onep (val) && ! integer_zerop (val)))
! 	    {
! 	      cond = build (LE_EXPR, boolean_type_node, op,
! 			    convert (type, integer_zero_node));
! 	      cond = build (COND_EXPR, void_type_node, cond, NULL, NULL);
! 	      val = lookup_avail_expr (cond,
! 				       block_avail_exprs_p,
! 				       const_and_copies);
! 	    }
! 	    
! 	  if (val
! 	      && (integer_onep (val) || integer_zerop (val)))
! 	    {
! 	      tree t;
! 
! 	      if (integer_onep (val))
! 		t = build1 (NEGATE_EXPR, TREE_TYPE (op), op);
! 	      else
! 		t = op;
! 
! 	      /* Remove the old entry from the hash table.  */
! 	      if (may_optimize_p)
! 		htab_remove_elt (avail_exprs, stmt);
! 
! 	      /* Now update the RHS of the assignment to use the new node.  */
! 	      TREE_OPERAND (stmt, 1) = t;
  
! 	      if (may_optimize_p)
! 		{
! 		  /* Now force the updated statement into the hash table.  */
! 		  lookup_avail_expr (stmt,
! 				     block_avail_exprs_p,
! 				     const_and_copies);
! 
! 		  /* Annoyingly we now have two entries for this statement in
! 		     BLOCK_AVAIL_EXPRs.  Luckily we can just pop off the newest
! 		     entry.  */
! 		  VARRAY_POP (*block_avail_exprs_p);
! 		}
  
  	      /* And make sure we record the fact that we modified this
  	         statement.  */





More information about the Gcc-patches mailing list