public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Steven Bosscher <stevenb.gcc@gmail.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Cc: Vladimir Makarov <vmakarov@redhat.com>,
		"F. Kenneth Zadeck" <Kenneth.Zadeck@naturalbridge.com>
Subject: [PR38711] Use DF_LIVE in IRA if it available (for -O2 and higher)
Date: Sat, 13 Oct 2012 15:12:00 -0000	[thread overview]
Message-ID: <CABu31nPHeeXuH=YOwPBwufjOVuXv8N8RKyB+Zh1zsCd61T1DRw@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2766 bytes --]

Hello,

This fixes the long-standing enhancement request to use DF_LIVE in
IRA. To quote the first comment in the PR:

IRA should be using the DF-LIVE sets, which are smaller than the DF-LR
sets when they are available (typically at O2 and above). The proper
sets can be conveniently accessed using the df_get_live_[in,out]
functions which use DF-LIVE if it is available and fall back to DF-LR
if it is not.

I thought that DF_LIVE wasn't available at -O1 in IRA, but
interestingly ira.c:ira() adds it to the DF-problems list in that case
already:

$ grep -C3 -n df_live_add ira.c
4160-
4161-  if (optimize == 1)
4162-    {
4163:      df_live_add_problem ();
4164-      df_live_set_all_dirty ();
4165-    }
4166-#ifdef ENABLE_CHECKING

So DF_LIVE is already being computed for IRA. It's just not being used
because the DF_LR_{IN,OUT} macros are used instead of the
df_get_live_{in,out} functions. With my patch, the DF_LIVE sets are
used, which results in marginally faster compile times for my set of
cc1-i files on power64 and on x86_64, as well as smaller code. There's
also a good speedup for the PR54146 test case.

Only reload.c still uses the DF_LR_OUT. The comment in
find_dummy_reload() suggests this is intentional.

I also fond a bug in IRA:

4392-     touch the artificial uses and defs.  */
4393-  df_finish_pass (true);
4394-  if (optimize > 1)
4395:    df_live_add_problem ();
4396-  df_scan_alloc (NULL);
4397-  df_scan_blocks ();
4398-

At optimize>1 the DF_LIVE problem is already always computed. I think
the idea here was to *remove* the DF_LIVE problem at -O1, which is
also part of the attached patch.
(Perhaps we should even simply not add the DF_LIVE problem at -O1, but
that can be done in a follow-up patch if necessary.)

Bootstrapped and tested (with default checking and with release
checking) on powerpc64-unknown-linux-gnu and x86_64-unknown-linux-gnu.
OK for trunk?

Ciao!
Steven

        PR rtl-optimization/38711
        * df.h (df_get_live_out, df_get_live_in): Make static inline functions.
        * df-problems.c (df_get_live_out, df_get_live_in): Moved to df.h.
        * ira-lives.c (process_bb_node_lives): Use df_get_live_out instead of
        DF_LR_OUT.
        * ira-build.c (create_bb_allocnos): Likewise.
        (create_loop_allocnos): Likewise, and use df_get_live_in instead of
        DF_LR_IN.
        * ira-emit.c (generate_edge_moves): Likewise.
        (add_ranges_and_copies): Likewise.
        * ira.c (mark_elimination): Update DF_LR and DF_LIVE.
        (build_insn_chain): Use df_get_live_out instead of DF_LR_OUT.
        (do_reload): Remove the DF_LIVE problem for -O1.
        * ira-color.c (ira_loop_edge_freq): Use df_get_live_out instead of
        DF_LR_OUT, and df_get_live_in instead of DF_LR_IN.

[-- Attachment #2: ira-speedup-3.diff --]
[-- Type: application/octet-stream, Size: 10723 bytes --]

	PR rtl-optimization/38711
	* df.h (df_get_live_out, df_get_live_in): Make static inline functions.
	* df-problems.c (df_get_live_out, df_get_live_in): Moved to df.h.
	* ira-lives.c (process_bb_node_lives): Use df_get_live_out instead of
	DF_LR_OUT.
	* ira-build.c (create_bb_allocnos): Likewise.
	(create_loop_allocnos): Likewise, and use df_get_live_in instead of
	DF_LR_IN.
	* ira-emit.c (generate_edge_moves): Likewise.
	(add_ranges_and_copies): Likewise.
	* ira.c (mark_elimination): Update DF_LR and DF_LIVE.
	(build_insn_chain): Use df_get_live_out instead of DF_LR_OUT.
	(do_reload): Remove the DF_LIVE problem for -O1.
	* ira-color.c (ira_loop_edge_freq): Use df_get_live_out instead of
	DF_LR_OUT, and df_get_live_in instead of DF_LR_IN.

Index: df.h
===================================================================
--- df.h	(revision 192422)
+++ df.h	(working copy)
@@ -951,8 +951,6 @@ extern void debug_df_chain (struct df_link *);
 extern struct df_link *df_chain_create (df_ref, df_ref);
 extern void df_chain_unlink (df_ref);
 extern void df_chain_copy (df_ref, struct df_link *);
-extern bitmap df_get_live_in (basic_block);
-extern bitmap df_get_live_out (basic_block);
 extern void df_grow_bb_info (struct dataflow *);
 extern void df_chain_dump (struct df_link *, FILE *);
 extern void df_print_bb_index (basic_block bb, FILE *file);
@@ -1023,7 +1021,10 @@ extern void df_compute_regs_ever_live (bool);
 extern bool df_read_modify_subreg_p (rtx);
 extern void df_scan_verify (void);
 
-/* Get basic block info.  */
+\f
+/*----------------------------------------------------------------------------
+   Public functions access functions for the dataflow problems.
+----------------------------------------------------------------------------*/
 
 static inline struct df_scan_bb_info *
 df_scan_get_bb_info (unsigned int index)
@@ -1079,6 +1080,39 @@ df_word_lr_get_bb_info (unsigned int index)
     return NULL;
 }
 
+/* Get the live at out set for BB no matter what problem happens to be
+   defined.  This function is used by the register allocators who
+   choose different dataflow problems depending on the optimization
+   level.  */
+
+static inline bitmap
+df_get_live_out (basic_block bb)
+{
+  gcc_checking_assert (df_lr);
+
+  if (df_live)
+    return DF_LIVE_OUT (bb);
+  else
+    return DF_LR_OUT (bb);
+}
+
+/* Get the live at in set for BB no matter what problem happens to be
+   defined.  This function is used by the register allocators who
+   choose different dataflow problems depending on the optimization
+   level.  */
+
+static inline bitmap
+df_get_live_in (basic_block bb)
+{
+  gcc_checking_assert (df_lr);
+
+  if (df_live)
+    return DF_LIVE_IN (bb);
+  else
+    return DF_LR_IN (bb);
+}
+
+/* Get basic block info.  */
 /* Get the artificial defs for a basic block.  */
 
 static inline df_ref *
Index: df-problems.c
===================================================================
--- df-problems.c	(revision 192422)
+++ df-problems.c	(working copy)
@@ -57,43 +57,7 @@ along with GCC; see the file COPYING3.  If not see
 static bitmap_head seen_in_block;
 static bitmap_head seen_in_insn;
 
-\f
 /*----------------------------------------------------------------------------
-   Public functions access functions for the dataflow problems.
-----------------------------------------------------------------------------*/
-/* Get the live at out set for BB no matter what problem happens to be
-   defined.  This function is used by the register allocators who
-   choose different dataflow problems depending on the optimization
-   level.  */
-
-bitmap
-df_get_live_out (basic_block bb)
-{
-  gcc_assert (df_lr);
-
-  if (df_live)
-    return DF_LIVE_OUT (bb);
-  else
-    return DF_LR_OUT (bb);
-}
-
-/* Get the live at in set for BB no matter what problem happens to be
-   defined.  This function is used by the register allocators who
-   choose different dataflow problems depending on the optimization
-   level.  */
-
-bitmap
-df_get_live_in (basic_block bb)
-{
-  gcc_assert (df_lr);
-
-  if (df_live)
-    return DF_LIVE_IN (bb);
-  else
-    return DF_LR_IN (bb);
-}
-
-/*----------------------------------------------------------------------------
    Utility functions.
 ----------------------------------------------------------------------------*/
 
Index: ira-lives.c
===================================================================
--- ira-lives.c	(revision 192422)
+++ ira-lives.c	(working copy)
@@ -1148,7 +1148,7 @@ process_bb_node_lives (ira_loop_tree_node_t loop_t
 	  high_pressure_start_point[ira_pressure_classes[i]] = -1;
 	}
       curr_bb_node = loop_tree_node;
-      reg_live_out = DF_LR_OUT (bb);
+      reg_live_out = df_get_live_out (bb);
       sparseset_clear (objects_live);
       REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_out);
       AND_COMPL_HARD_REG_SET (hard_regs_live, eliminable_regset);
Index: ira-build.c
===================================================================
--- ira-build.c	(revision 192422)
+++ ira-build.c	(working copy)
@@ -1715,7 +1715,7 @@ create_bb_allocnos (ira_loop_tree_node_t bb_node)
       create_insn_allocnos (PATTERN (insn), false);
   /* It might be a allocno living through from one subloop to
      another.  */
-  EXECUTE_IF_SET_IN_REG_SET (DF_LR_IN (bb), FIRST_PSEUDO_REGISTER, i, bi)
+  EXECUTE_IF_SET_IN_REG_SET (df_get_live_in (bb), FIRST_PSEUDO_REGISTER, i, bi)
     if (ira_curr_regno_allocno_map[i] == NULL)
       ira_create_allocno (i, false, ira_curr_loop_tree_node);
 }
@@ -1731,9 +1731,9 @@ create_loop_allocnos (edge e)
   bitmap_iterator bi;
   ira_loop_tree_node_t parent;
 
-  live_in_regs = DF_LR_IN (e->dest);
+  live_in_regs = df_get_live_in (e->dest);
   border_allocnos = ira_curr_loop_tree_node->border_allocnos;
-  EXECUTE_IF_SET_IN_REG_SET (DF_LR_OUT (e->src),
+  EXECUTE_IF_SET_IN_REG_SET (df_get_live_out (e->src),
 			     FIRST_PSEUDO_REGISTER, i, bi)
     if (bitmap_bit_p (live_in_regs, i))
       {
Index: ira-emit.c
===================================================================
--- ira-emit.c	(revision 192422)
+++ ira-emit.c	(working copy)
@@ -495,6 +495,7 @@ generate_edge_moves (edge e)
   bitmap_iterator bi;
   ira_allocno_t src_allocno, dest_allocno, *src_map, *dest_map;
   move_t move;
+  bitmap regs_live_in_dest, regs_live_out_src;
 
   src_loop_node = IRA_BB_NODE (e->src)->parent;
   dest_loop_node = IRA_BB_NODE (e->dest)->parent;
@@ -503,9 +504,11 @@ generate_edge_moves (edge e)
     return;
   src_map = src_loop_node->regno_allocno_map;
   dest_map = dest_loop_node->regno_allocno_map;
-  EXECUTE_IF_SET_IN_REG_SET (DF_LR_IN (e->dest),
+  regs_live_in_dest = df_get_live_in (e->dest);
+  regs_live_out_src = df_get_live_out (e->src);
+  EXECUTE_IF_SET_IN_REG_SET (regs_live_in_dest,
 			     FIRST_PSEUDO_REGISTER, regno, bi)
-    if (bitmap_bit_p (DF_LR_OUT (e->src), regno))
+    if (bitmap_bit_p (regs_live_out_src, regno))
       {
 	src_allocno = src_map[regno];
 	dest_allocno = dest_map[regno];
@@ -1206,15 +1209,16 @@ add_ranges_and_copies (void)
 	 destination block) to use for searching allocnos by their
 	 regnos because of subsequent IR flattening.  */
       node = IRA_BB_NODE (bb)->parent;
-      bitmap_copy (live_through, DF_LR_IN (bb));
+      bitmap_copy (live_through, df_get_live_in (bb));
       add_range_and_copies_from_move_list
 	(at_bb_start[bb->index], node, live_through, REG_FREQ_FROM_BB (bb));
-      bitmap_copy (live_through, DF_LR_OUT (bb));
+      bitmap_copy (live_through, df_get_live_out (bb));
       add_range_and_copies_from_move_list
 	(at_bb_end[bb->index], node, live_through, REG_FREQ_FROM_BB (bb));
       FOR_EACH_EDGE (e, ei, bb->succs)
 	{
-	  bitmap_and (live_through, DF_LR_IN (e->dest), DF_LR_OUT (bb));
+	  bitmap_and (live_through,
+		      df_get_live_in (e->dest), df_get_live_out (bb));
 	  add_range_and_copies_from_move_list
 	    ((move_t) e->aux, node, live_through,
 	     REG_FREQ_FROM_EDGE_FREQ (EDGE_FREQUENCY (e)));
Index: ira.c
===================================================================
--- ira.c	(revision 192423)
+++ ira.c	(working copy)
@@ -2337,17 +2337,24 @@ void
 mark_elimination (int from, int to)
 {
   basic_block bb;
+  bitmap r;
 
   FOR_EACH_BB (bb)
     {
-      /* We don't use LIVE info in IRA.  */
-      bitmap r = DF_LR_IN (bb);
-
-      if (REGNO_REG_SET_P (r, from))
+      r = DF_LR_IN (bb);
+      if (bitmap_bit_p (r, from))
 	{
-	  CLEAR_REGNO_REG_SET (r, from);
-	  SET_REGNO_REG_SET (r, to);
+	  bitmap_clear_bit (r, from);
+	  bitmap_set_bit (r, to);
 	}
+      if (! df_live)
+        continue;
+      r = DF_LIVE_IN (bb);
+      if (bitmap_bit_p (r, from))
+	{
+	  bitmap_clear_bit (r, from);
+	  bitmap_set_bit (r, to);
+	}
     }
 }
 
@@ -3319,14 +3326,14 @@ build_insn_chain (void)
       CLEAR_REG_SET (live_relevant_regs);
       bitmap_clear (live_subregs_used);
 
-      EXECUTE_IF_SET_IN_BITMAP (DF_LR_OUT (bb), 0, i, bi)
+      EXECUTE_IF_SET_IN_BITMAP (df_get_live_out (bb), 0, i, bi)
 	{
 	  if (i >= FIRST_PSEUDO_REGISTER)
 	    break;
 	  bitmap_set_bit (live_relevant_regs, i);
 	}
 
-      EXECUTE_IF_SET_IN_BITMAP (DF_LR_OUT (bb),
+      EXECUTE_IF_SET_IN_BITMAP (df_get_live_out (bb),
 				FIRST_PSEUDO_REGISTER, i, bi)
 	{
 	  if (pseudo_for_reload_consideration_p (i))
@@ -4397,8 +4404,8 @@ do_reload (void)
      df_rescan_all_insns is not going to help here because it does not
      touch the artificial uses and defs.  */
   df_finish_pass (true);
-  if (optimize > 1)
-    df_live_add_problem ();
+  if (optimize == 1)
+    df_remove_problem (df_live);
   df_scan_alloc (NULL);
   df_scan_blocks ();
 
Index: ira-color.c
===================================================================
--- ira-color.c	(revision 192422)
+++ ira-color.c	(working copy)
@@ -2014,8 +2014,8 @@ ira_loop_edge_freq (ira_loop_tree_node_t loop_node
       FOR_EACH_EDGE (e, ei, loop_node->loop->header->preds)
 	if (e->src != loop_node->loop->latch
 	    && (regno < 0
-		|| (bitmap_bit_p (DF_LR_OUT (e->src), regno)
-		    && bitmap_bit_p (DF_LR_IN (e->dest), regno))))
+		|| (bitmap_bit_p (df_get_live_out (e->src), regno)
+		    && bitmap_bit_p (df_get_live_in (e->dest), regno))))
 	  freq += EDGE_FREQUENCY (e);
     }
   else
@@ -2023,8 +2023,8 @@ ira_loop_edge_freq (ira_loop_tree_node_t loop_node
       edges = get_loop_exit_edges (loop_node->loop);
       FOR_EACH_VEC_ELT (edge, edges, i, e)
 	if (regno < 0
-	    || (bitmap_bit_p (DF_LR_OUT (e->src), regno)
-		&& bitmap_bit_p (DF_LR_IN (e->dest), regno)))
+	    || (bitmap_bit_p (df_get_live_out (e->src), regno)
+		&& bitmap_bit_p (df_get_live_in (e->dest), regno)))
 	  freq += EDGE_FREQUENCY (e);
       VEC_free (edge, heap, edges);
     }

             reply	other threads:[~2012-10-13 13:41 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-13 15:12 Steven Bosscher [this message]
2012-10-13 15:38 ` Vladimir Makarov
2012-10-13 15:51   ` Steven Bosscher
2012-10-13 21:41     ` Vladimir Makarov
2012-10-14 11:42       ` Steven Bosscher
2012-10-14 17:37         ` Vladimir Makarov
2012-10-14 19:43           ` Steven Bosscher
2012-10-27 23:36       ` Steven Bosscher
2012-10-28  0:38         ` Steven Bosscher
2012-10-28 20:52           ` Vladimir Makarov
2012-10-13 20:59 ` Eric Botcazou
2012-10-13 21:08   ` Steven Bosscher
2012-10-13 21:15     ` Eric Botcazou
2012-10-13 21:52       ` Steven Bosscher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABu31nPHeeXuH=YOwPBwufjOVuXv8N8RKyB+Zh1zsCd61T1DRw@mail.gmail.com' \
    --to=stevenb.gcc@gmail.com \
    --cc=Kenneth.Zadeck@naturalbridge.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=vmakarov@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).