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] tree-if-conv.c: Remove two "if" statements that alwaystrigger.


Hi,

Attached is a patch to remove two "if" statements that always trigger.

tree_if_convert_cond_expr receives a COND_EXPR as an argument.  Since
this COND_EXPR is a statement and not the one appearing as the rhs of
a MODIFY_EXPR, each arm of COND_EXPR always has a GOTO_EXPR.

In tree_if_convert_cond_expr's terms, then_clause and else_clause
always have GOTO_EXPR, so we don't need two "if" statements

  if (then_clause)

and

  if (else_clause)

as their conditions are always nonzero.

The patch simply removes them.  A lot of indentation changes are
unfortunate side effects.

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2004-11-07  Kazu Hirata  <kazu@cs.umass.edu>

	* tree-if-conv.c (tree_if_convert_cond_expr): Remove two "if"
	statements that always trigger.

Index: tree-if-conv.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-if-conv.c,v
retrieving revision 2.11
diff -c -d -p -r2.11 tree-if-conv.c
*** tree-if-conv.c	14 Oct 2004 18:19:46 -0000	2.11
--- tree-if-conv.c	6 Nov 2004 20:12:35 -0000
*************** static void
*** 271,277 ****
  tree_if_convert_cond_expr (struct loop *loop, tree stmt, tree cond,
  			   block_stmt_iterator *bsi)
  {
!   tree then_clause, else_clause, c, new_cond;
    new_cond = NULL_TREE;
  
    gcc_assert (TREE_CODE (stmt) == COND_EXPR);
--- 271,277 ----
  tree_if_convert_cond_expr (struct loop *loop, tree stmt, tree cond,
  			   block_stmt_iterator *bsi)
  {
!   tree then_clause, else_clause, c, c2, new_cond;
    new_cond = NULL_TREE;
  
    gcc_assert (TREE_CODE (stmt) == COND_EXPR);
*************** tree_if_convert_cond_expr (struct loop *
*** 290,316 ****
      }
  
    /* Add new condition into destination's predicate list.  */
-   if (then_clause)
-     /* if 'c' is true then then_clause is reached.  */
-     new_cond = add_to_dst_predicate_list (loop, then_clause, cond, 
- 					  unshare_expr (c), bsi);
  
!   if (else_clause)
!     {
!       tree c2;
!       if (!is_gimple_reg(c) && is_gimple_condexpr (c))
! 	{
! 	  tree new_stmt;
! 	  new_stmt = ifc_temp_var (TREE_TYPE (c), unshare_expr (c));
! 	  bsi_insert_before (bsi, new_stmt, BSI_SAME_STMT);
! 	  c = TREE_OPERAND (new_stmt, 0);
! 	}
  
!       /* if 'c' is false then else_clause is reached.  */
!       c2 = invert_truthvalue (unshare_expr (c));
!       add_to_dst_predicate_list (loop, else_clause, cond, c2, bsi);
      }
  
    /* Now this conditional statement is redundant. Remove it.
       But, do not remove exit condition! Update exit condition
       using new condition.  */
--- 290,312 ----
      }
  
    /* Add new condition into destination's predicate list.  */
  
!   /* If 'c' is true then then_clause is reached.  */
!   new_cond = add_to_dst_predicate_list (loop, then_clause, cond,
! 					unshare_expr (c), bsi);
  
!   if (!is_gimple_reg(c) && is_gimple_condexpr (c))
!     {
!       tree new_stmt;
!       new_stmt = ifc_temp_var (TREE_TYPE (c), unshare_expr (c));
!       bsi_insert_before (bsi, new_stmt, BSI_SAME_STMT);
!       c = TREE_OPERAND (new_stmt, 0);
      }
  
+   /* If 'c' is false then else_clause is reached.  */
+   c2 = invert_truthvalue (unshare_expr (c));
+   add_to_dst_predicate_list (loop, else_clause, cond, c2, bsi);
+ 
    /* Now this conditional statement is redundant. Remove it.
       But, do not remove exit condition! Update exit condition
       using new condition.  */


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