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] Minor improvements


I was looking at test for an unrelated problem when I noticed that we
were not folding expressions in return statements.  The problem is
get_rhs (and set_rhs) didn't properly deal with the fact that
a return of a value actually looks something like this:

      RETURN_EXPR
          |
      MODIFY_EXPR
         /\
        /  \
       /    \
      /      \
RESULT_DECL  EXPRESSION


Fixing get_rhs and set_rhs to look inside the MODIFY_EXPR in a RETURN_EXPR
caused the expected propagations to occur.

At the same time I also noticed that if optimization results in collapsing
a conditional into something like this:


   if (exp)
      goto label
   else
      goto label

We didn't realize that the conditional as a whole was pointless.  This
kind of code can occur when inlining a function which has an exit path
such as

   if (foo)
     return val1;
   else
     return val2;

And the caller doesn't actually care about the return value.

Bootstrapped and regression tested.  Whee.

	* tree-cfg.c (remove_useless_stmts_and_vars): Handle case where
	both arms of an if-then-else simply jump to the same location.

	* tree-cfg.c (get_rhs): Correctly handle MODIFY_EXPR embedded in
	a RETURN_EXPR.
	(set_rhs): Likewise.


Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.4.90
diff -c -3 -p -r1.1.4.90 tree-cfg.c
*** tree-cfg.c	15 May 2003 17:00:13 -0000	1.1.4.90
--- tree-cfg.c	16 May 2003 15:45:45 -0000
*************** remove_useless_stmts_and_vars (first_p)
*** 1451,1460 ****
  	      *stmt_p = then_clause;
  	       repeat = 1;
  	    }
! 	  if (integer_zerop (cond) && IS_EMPTY_STMT (then_clause))
  	    {
  	      *stmt_p = else_clause;
  	       repeat = 1;
  	    }
  	}
        else if (code == SWITCH_EXPR)
--- 1451,1468 ----
  	      *stmt_p = then_clause;
  	       repeat = 1;
  	    }
! 	  else if (integer_zerop (cond) && IS_EMPTY_STMT (then_clause))
  	    {
  	      *stmt_p = else_clause;
  	       repeat = 1;
+ 	    }
+ 	  else if (TREE_CODE (then_clause) == GOTO_EXPR
+ 	      && TREE_CODE (else_clause) == GOTO_EXPR
+ 	      && (GOTO_DESTINATION (then_clause)
+ 		  == GOTO_DESTINATION (else_clause)))
+ 	    {
+ 	      *stmt_p = then_clause;
+ 	      repeat = 1;
  	    }
  	}
        else if (code == SWITCH_EXPR)
Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-ccp.c,v
retrieving revision 1.1.2.68
diff -c -3 -p -r1.1.2.68 tree-ssa-ccp.c
*** tree-ssa-ccp.c	2 May 2003 13:52:38 -0000	1.1.2.68
--- tree-ssa-ccp.c	16 May 2003 15:45:47 -0000
*************** get_rhs (stmt)
*** 1221,1227 ****
    else if (code == SWITCH_EXPR)
      return SWITCH_COND (stmt);
    else if (code == RETURN_EXPR)
!     return TREE_OPERAND (stmt, 0);
    else if (code == GOTO_EXPR)
      return GOTO_DESTINATION (stmt);
    else if (code == LABEL_EXPR)
--- 1221,1232 ----
    else if (code == SWITCH_EXPR)
      return SWITCH_COND (stmt);
    else if (code == RETURN_EXPR)
!     {
!       if (TREE_CODE (TREE_OPERAND (stmt, 0)) == MODIFY_EXPR)
! 	return TREE_OPERAND (TREE_OPERAND (stmt, 0), 1);
!       else
! 	return TREE_OPERAND (stmt, 0);
!     }
    else if (code == GOTO_EXPR)
      return GOTO_DESTINATION (stmt);
    else if (code == LABEL_EXPR)
*************** set_rhs (stmt, expr)
*** 1247,1253 ****
    else if (code == SWITCH_EXPR)
      SWITCH_COND (stmt) = expr;
    else if (code == RETURN_EXPR)
!     TREE_OPERAND (stmt, 0) = expr;
    else if (code == GOTO_EXPR)
      GOTO_DESTINATION (stmt) = expr;
    else if (code == LABEL_EXPR)
--- 1252,1264 ----
    else if (code == SWITCH_EXPR)
      SWITCH_COND (stmt) = expr;
    else if (code == RETURN_EXPR)
!     {
!       if (TREE_OPERAND (stmt, 0)
! 	  && TREE_CODE (TREE_OPERAND (stmt, 0)) == MODIFY_EXPR)
! 	TREE_OPERAND (TREE_OPERAND (stmt, 0), 1) = expr;
!       else
! 	TREE_OPERAND (stmt, 0) == expr;
!     }
    else if (code == GOTO_EXPR)
      GOTO_DESTINATION (stmt) = expr;
    else if (code == LABEL_EXPR)








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