[PATCH] more regmove dead code

Richard Guenther richard.guenther@gmail.com
Wed Feb 25 17:14:00 GMT 2009


On Wed, Feb 25, 2009 at 4:16 PM, Paolo Bonzini <bonzini@gnu.org> wrote:
> Also following post-IRA cleanup, the first half of regmove_optimize has
> this interesting structure:
>
>  for (pass = 0; pass <= 2; pass++)
>    {
>      if (! flag_regmove && pass >= flag_expensive_optimizations)
>       goto done;
>
>      ...
>
>      for (...)
>        {
>          /* some transformations here... */
>        }
>    }
>
> where:
>
> 1) flag_regmove is always true, so the first if never triggers;
>
> 2) all the code in /* some transformations here... */ is guarded by
> "flag_expensive_optimizations && ! pass", making the second pass is
> totally useless.
>
> So the entire code is equivalent to:
>
>  if (flag_expensive_optimizations)
>    {
>      for (...)
>        {
>          /* some transformations here... */
>        }
>    }
>
> Now, protecting code to only run under flag_expensive_optimizations is
> dubious for anything that only runs at optimize >= 2 (so
> flag_expensive_optimizations is on by default), but that's something for
> a different patch.  And it makes the attached patch nice and readable,
> since it does not change the indentation of the code.
>
> It does remove one walk of the insn stream, so it's better than nothing
> WRT compilation time.  And it makes adaptation of regmove to cfglayout
> mode much simpler.
>
> I made a little unrelated change, by removing the now-trivially-useless
> rest_of_handle_regmove wrapper.
>
> Ok for trunk or 4.5, at the discretion of the reviewer?

Ok for trunk if this was bootstrapped / tested.

Thanks,
Richard.

> Paolo
>
> 2009-02-25  Paolo Bonzini  <bonzini@gnu.org>
>
>        * regmove.c (regmove_optimize): Conform to struct rtl_opt_pass
>        execute function prototype.  Get f and nregs from max_reg_num
>        and get_insns.  Remove the first backward pass as it's dead,
>        guard the forward pass by flag_expensive_optimizations.
>        (rest_of_handle_regmove): Delete.
>        (pass_regmove): Replace it with regmove_optimize.
>
> Index: regmove.c
> ===================================================================
> --- regmove.c   (revision 144425)
> +++ regmove.c   (working copy)
> @@ -882,25 +882,21 @@ fixup_match_2 (rtx insn, rtx dst, rtx sr
>   return 0;
>  }
>
> -/* Main entry for the register move optimization.
> -   F is the first instruction.
> -   NREGS is one plus the highest pseudo-reg number used in the instruction.
> -   REGMOVE_DUMP_FILE is a stream for output of a trace of actions taken
> -   (or 0 if none should be output).  */
> +/* Main entry for the register move optimization.  */
>
> -static void
> -regmove_optimize (rtx f, int nregs)
> +static unsigned int
> +regmove_optimize (void)
>  {
>   rtx insn;
>   struct match match;
> -  int pass;
>   int i;
>   rtx copy_src, copy_dst;
> +  int nregs = max_reg_num ();
>
>   /* ??? Hack.  Regmove doesn't examine the CFG, and gets mightily
>      confused by non-call exceptions ending blocks.  */
>   if (flag_non_call_exceptions)
> -    return;
> +    return 0;
>
>   df_note_add_problem ();
>   df_analyze ();
> @@ -912,35 +908,26 @@ regmove_optimize (rtx f, int nregs)
>   for (i = nregs; --i >= 0; )
>     regno_src_regno[i] = -1;
>
> -  /* A forward/backward pass.  Replace output operands with input operands.  */
> +  /* A forward pass.  Replace output operands with input operands.  */
>
> -  for (pass = 0; pass <= 2; pass++)
> +  if (flag_expensive_optimizations)
>     {
> -      if (! flag_regmove && pass >= flag_expensive_optimizations)
> -       goto done;
> -
>       if (dump_file)
> -       fprintf (dump_file, "Starting %s pass...\n",
> -                pass ? "backward" : "forward");
> +       fprintf (dump_file, "Starting forward pass...\n");
>
> -      for (insn = pass ? get_last_insn () : f; insn;
> -          insn = pass ? PREV_INSN (insn) : NEXT_INSN (insn))
> +      for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
>        {
> -         rtx set;
> -
> -         set = single_set (insn);
> +         rtx set = single_set (insn);
>          if (! set)
>            continue;
>
> -         if (flag_expensive_optimizations && ! pass
> -             && (GET_CODE (SET_SRC (set)) == SIGN_EXTEND
> -                 || GET_CODE (SET_SRC (set)) == ZERO_EXTEND)
> +         if ((GET_CODE (SET_SRC (set)) == SIGN_EXTEND
> +              || GET_CODE (SET_SRC (set)) == ZERO_EXTEND)
>              && REG_P (XEXP (SET_SRC (set), 0))
>              && REG_P (SET_DEST (set)))
>            optimize_reg_copy_3 (insn, SET_DEST (set), SET_SRC (set));
>
> -         if (flag_expensive_optimizations && ! pass
> -             && REG_P (SET_SRC (set))
> +         if (REG_P (SET_SRC (set))
>              && REG_P (SET_DEST (set)))
>            {
>              /* If this is a register-register copy where SRC is not dead,
> @@ -1255,6 +1242,7 @@ regmove_optimize (rtx f, int nregs)
>     }
>   regstat_free_n_sets_and_refs ();
>   regstat_free_ri ();
> +  return 0;
>  }
>
>  /* Returns nonzero if INSN's pattern has matching constraints for any operand.
> @@ -1356,14 +1344,6 @@ gate_handle_regmove (void)
>   return (optimize > 0 && flag_regmove);
>  }
>
> -/* Register allocation pre-pass, to reduce number of moves necessary
> -   for two-address machines.  */
> -static unsigned int
> -rest_of_handle_regmove (void)
> -{
> -  regmove_optimize (get_insns (), max_reg_num ());
> -  return 0;
> -}
>
>  struct rtl_opt_pass pass_regmove =
>  {
> @@ -1371,7 +1351,7 @@ struct rtl_opt_pass pass_regmove =
>   RTL_PASS,
>   "regmove",                            /* name */
>   gate_handle_regmove,                  /* gate */
> -  rest_of_handle_regmove,               /* execute */
> +  regmove_optimize,                    /* execute */
>   NULL,                                 /* sub */
>   NULL,                                 /* next */
>   0,                                    /* static_pass_number */
>
>



More information about the Gcc-patches mailing list