[PATCH] Avoid optimize_insns_for_speed_p () in gimple opts

Richard Biener rguenther@suse.de
Mon Apr 14 09:12:00 GMT 2014


When code was moved from RTL to GIMPLE those predicates slipped
into GIMPLE code which can have weird effects (crtl->maybe_hot_insn_p
is certainly not meaningful here and AFAICS initialized by
gimplification only and to the default behavior on function granularity).

So it's better to use BB predicates here, which the following does.

Bootstrap/regtest scheduled on x86_64-unknown-linux-gnu.

Richard.

2014-04-14  Richard Biener  <rguenther@suse.de>

	* tree-switch-conversion.c (lshift_cheap_p): Get speed_p
	as argument.
	(expand_switch_using_bit_tests_p): Likewise.
	(process_switch): Compute and pass on speed_p based on the
	switch stmt.
	* tree-ssa-math-opts.c (gimple_expand_builtin_pow): Use
	optimize_bb_for_speed_p.

Index: gcc/tree-switch-conversion.c
===================================================================
*** gcc/tree-switch-conversion.c	(revision 209359)
--- gcc/tree-switch-conversion.c	(working copy)
*************** hoist_edge_and_branch_if_true (gimple_st
*** 130,150 ****
     This function (and similar RTL-related cost code in e.g. IVOPTS) should
     be moved to some kind of interface file for GIMPLE/RTL interactions.  */
  static bool
! lshift_cheap_p (void)
  {
    /* FIXME: This should be made target dependent via this "this_target"
       mechanism, similar to e.g. can_copy_init_p in gcse.c.  */
    static bool init[2] = {false, false};
    static bool cheap[2] = {true, true};
-   bool speed_p;
  
    /* If the targer has no lshift in word_mode, the operation will most
       probably not be cheap.  ??? Does GCC even work for such targets?  */
    if (optab_handler (ashl_optab, word_mode) == CODE_FOR_nothing)
      return false;
  
-   speed_p = optimize_insn_for_speed_p ();
- 
    if (!init[speed_p])
      {
        rtx reg = gen_raw_REG (word_mode, 10000);
--- 130,147 ----
     This function (and similar RTL-related cost code in e.g. IVOPTS) should
     be moved to some kind of interface file for GIMPLE/RTL interactions.  */
  static bool
! lshift_cheap_p (bool speed_p)
  {
    /* FIXME: This should be made target dependent via this "this_target"
       mechanism, similar to e.g. can_copy_init_p in gcse.c.  */
    static bool init[2] = {false, false};
    static bool cheap[2] = {true, true};
  
    /* If the targer has no lshift in word_mode, the operation will most
       probably not be cheap.  ??? Does GCC even work for such targets?  */
    if (optab_handler (ashl_optab, word_mode) == CODE_FOR_nothing)
      return false;
  
    if (!init[speed_p])
      {
        rtx reg = gen_raw_REG (word_mode, 10000);
*************** lshift_cheap_p (void)
*** 165,176 ****
  static bool
  expand_switch_using_bit_tests_p (tree range,
  				 unsigned int uniq,
! 				 unsigned int count)
  {
    return (((uniq == 1 && count >= 3)
  	   || (uniq == 2 && count >= 5)
  	   || (uniq == 3 && count >= 6))
! 	  && lshift_cheap_p ()
  	  && compare_tree_int (range, GET_MODE_BITSIZE (word_mode)) < 0
  	  && compare_tree_int (range, 0) > 0);
  }
--- 162,173 ----
  static bool
  expand_switch_using_bit_tests_p (tree range,
  				 unsigned int uniq,
! 				 unsigned int count, bool speed_p)
  {
    return (((uniq == 1 && count >= 3)
  	   || (uniq == 2 && count >= 5)
  	   || (uniq == 3 && count >= 6))
! 	  && lshift_cheap_p (speed_p)
  	  && compare_tree_int (range, GET_MODE_BITSIZE (word_mode)) < 0
  	  && compare_tree_int (range, 0) > 0);
  }
*************** process_switch (gimple swtch)
*** 1357,1363 ****
    if (info.uniq <= MAX_CASE_BIT_TESTS)
      {
        if (expand_switch_using_bit_tests_p (info.range_size,
! 					   info.uniq, info.count))
  	{
  	  if (dump_file)
  	    fputs ("  expanding as bit test is preferable\n", dump_file);
--- 1354,1362 ----
    if (info.uniq <= MAX_CASE_BIT_TESTS)
      {
        if (expand_switch_using_bit_tests_p (info.range_size,
! 					   info.uniq, info.count,
! 					   optimize_bb_for_speed_p
! 					     (gimple_bb (swtch))))
  	{
  	  if (dump_file)
  	    fputs ("  expanding as bit test is preferable\n", dump_file);
Index: gcc/tree-ssa-math-opts.c
===================================================================
*** gcc/tree-ssa-math-opts.c	(revision 209359)
--- gcc/tree-ssa-math-opts.c	(working copy)
*************** gimple_expand_builtin_pow (gimple_stmt_i
*** 1162,1168 ****
    if (c_is_int
        && ((n >= -1 && n <= 2)
  	  || (flag_unsafe_math_optimizations
! 	      && optimize_insn_for_speed_p ()
  	      && powi_cost (n) <= POWI_MAX_MULTS)))
      return gimple_expand_builtin_powi (gsi, loc, arg0, n);
  
--- 1162,1168 ----
    if (c_is_int
        && ((n >= -1 && n <= 2)
  	  || (flag_unsafe_math_optimizations
! 	      && optimize_bb_for_speed_p (gsi_bb (*gsi))
  	      && powi_cost (n) <= POWI_MAX_MULTS)))
      return gimple_expand_builtin_powi (gsi, loc, arg0, n);
  



More information about the Gcc-patches mailing list