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


By eliminating the zero-extension, the switch expression matches
the form of the if expression, which allows us to look up the 
value we expected.

There's lots of other possibilities for this function, particularly
wrt even the minimal VRP that dom already does.

Bootstrapped and tested on i686-linux.


r~


	* tree-ssa-dom.c (simplify_switch_and_lookup_avail_expr): New.
	(eliminate_redundant_computations): Call it.

Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dom.c,v
retrieving revision 1.1.2.121
diff -c -p -d -r1.1.2.121 tree-ssa-dom.c
*** tree-ssa-dom.c	2 Feb 2004 14:55:15 -0000	1.1.2.121
--- tree-ssa-dom.c	4 Feb 2004 11:29:59 -0000
*************** static tree simplify_rhs_and_lookup_avai
*** 228,233 ****
--- 228,235 ----
  						tree, stmt_ann_t, int);
  static tree simplify_cond_and_lookup_avail_expr (tree, varray_type *,
  						 stmt_ann_t, int);
+ static tree simplify_switch_and_lookup_avail_expr (tree, varray_type *,
+ 						   stmt_ann_t, int);
  static tree find_equivalent_equality_comparison (tree);
  static void record_range (tree, basic_block, varray_type *);
  static bool extract_range_from_cond (tree, tree *, tree *, int *);
*************** simplify_cond_and_lookup_avail_expr (tre
*** 2102,2107 ****
--- 2104,2155 ----
    return 0;
  }
  
+ /* STMT is a SWITCH_EXPR for which we could not trivially determine its
+    result.  This routine attempts to find equivalent forms of the
+    condition which we may be able to optimize better.  */
+ 
+ static tree
+ simplify_switch_and_lookup_avail_expr (tree stmt,
+ 				       varray_type *block_avail_exprs_p,
+ 				       stmt_ann_t ann,
+ 				       int insert)
+ {
+   tree cond = SWITCH_COND (stmt);
+   tree def, to, ti;
+ 
+   /* The optimization that we really care about is removing unnecessary
+      casts.  That will let us do much better in propagating the inferred
+      constant at the switch target.  */
+   if (TREE_CODE (cond) == SSA_NAME)
+     {
+       def = SSA_NAME_DEF_STMT (cond);
+       if (TREE_CODE (def) == MODIFY_EXPR)
+ 	{
+ 	  def = TREE_OPERAND (def, 1);
+ 	  if (TREE_CODE (def) == NOP_EXPR)
+ 	    {
+ 	      def = TREE_OPERAND (def, 0);
+ 	      to = TREE_TYPE (cond);
+ 	      ti = TREE_TYPE (def);
+ 
+ 	      /* If we have an extension that preserves sign, then we
+ 		 can copy the source value into the switch.  */
+ 	      if (TREE_UNSIGNED (to) == TREE_UNSIGNED (ti)
+ 		  && TYPE_PRECISION (to) >= TYPE_PRECISION (ti)
+ 	          && is_gimple_val (def))
+ 		{
+ 		  SWITCH_COND (stmt) = def;
+ 		  ann->modified = 1;
+ 
+ 		  return lookup_avail_expr (stmt, block_avail_exprs_p, insert);
+ 		}
+ 	    }
+ 	}
+     }
+ 
+   return 0;
+ }
+ 
  /* Const/copy propagate into STMT's USES, VUSES, and the RHS of VDEFs. 
  
     Return nonzero if new symbols may have been exposed.  */
*************** eliminate_redundant_computations (struct
*** 2360,2366 ****
  						      &bd->avail_exprs,
  						      ann,
  						      insert);
!   /* We could do the same with SWITCH_EXPRs in the future.  */
  
    opt_stats.num_exprs_considered++;
  
--- 2408,2419 ----
  						      &bd->avail_exprs,
  						      ann,
  						      insert);
!   /* Similarly for a SWITCH_EXPR.  */
!   else if (!cached_lhs && TREE_CODE (stmt) == SWITCH_EXPR)
!     cached_lhs = simplify_switch_and_lookup_avail_expr (stmt,
! 						        &bd->avail_exprs,
! 						        ann,
! 						        insert);
  
    opt_stats.num_exprs_considered++;
  


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