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] Optimizing COND_EXPRs


I noticed this while bringing jump threading up to date.  Basically we
have all the information we need to optimize away a goodly number of
COND_EXPRs during the jump threading pass, so we might as well go ahead
and do so :-)

This has the nice side effect that it makes jump threading more effective.

	* tree-ssa-dom.c (thread_jumps_walk_stmts): Go ahead and optimize
	a COND_EXPR with a compile-time constant condition.


Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dom.c,v
retrieving revision 1.1.2.69
diff -c -3 -p -r1.1.2.69 tree-ssa-dom.c
*** tree-ssa-dom.c	31 Oct 2003 06:11:23 -0000	1.1.2.69
--- tree-ssa-dom.c	31 Oct 2003 15:56:00 -0000
*************** thread_jumps_walk_stmts (struct dom_walk
*** 945,953 ****
        tree stmt = bsi_stmt (si);
        int may_optimize_p;
        varray_type vdefs;
  
!       /* Check for redundant computations.  Do this optimization only
! 	 for assignments that have no volatile ops and conditionals.  */
  
        /* This is a simpler test than the one in optimize_stmt because
  	 we only care about recording equivalences for assignments.
--- 945,979 ----
        tree stmt = bsi_stmt (si);
        int may_optimize_p;
        varray_type vdefs;
+       tree cached_lhs = NULL;
  
!       /* First try to eliminate any conditionals which have a known
! 	 compile time constant value.  */
!       if (TREE_CODE (stmt) == COND_EXPR || TREE_CODE (stmt) == SWITCH_EXPR)
! 	cached_lhs = lookup_avail_expr (stmt, NULL, false);
!       if (! cached_lhs && TREE_CODE (stmt) == COND_EXPR)
! 	cached_lhs = simplify_cond_and_lookup_avail_expr (stmt,
! 							  NULL,
! 							  stmt_ann (stmt),
! 							  false);
! 
!       if (cached_lhs && is_gimple_min_invariant (cached_lhs))
! 	{
! 	  modify_stmt (stmt);
! 
! 	  if (TREE_CODE (stmt) == COND_EXPR)
! 	    {
! 	      COND_EXPR_COND (stmt) = cached_lhs;
! 	      cfg_altered = cleanup_cond_expr_graph (bb, si);
! 	    }
! 	  else if (TREE_CODE (stmt) == SWITCH_EXPR)
! 	    {
! 	      SWITCH_COND (stmt) = cached_lhs;
! 	      cfg_altered = cleanup_switch_expr_graph (bb, si);
! 	    }
! 
! 	  continue;
! 	}
  
        /* This is a simpler test than the one in optimize_stmt because
  	 we only care about recording equivalences for assignments.




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