From: Kyrylo Tkachov <[email protected]>

df_update_entry_exit_and_calls is called from several passes (df
analysis, shrink-wrapping, prologue/epilogue insertion) and rescans every
call insn in the function.  Almost every such rescan finds nothing
changed, yet each pays for collecting the refs, sorting them and
comparing them with the existing chains.  In a perf profile of compiling
fmt at -O3 on AArch64 this function was about 2.8% of cc1plus
instructions.

The refs of a call insn depend on regs_ever_live only through the test of
df->exit_block_uses for sibling calls in df_get_call_refs.  Move the
rescan into df_update_exit_block_uses, perform it only when the exit
block uses changed and only for sibling calls.  This also covers the
callers of df_update_exit_block_uses that do not go through
df_update_entry_exit_and_calls.

The test input is the C++ test suite of fmtlib/fmt
(https://github.com/fmtlib/fmt),
built with CMake in Release mode (-O3 -DNDEBUG -std=gnu++11).

user-space instructions drop -3.0% in total,
cycles -2.9%, wall time -2.6%.
Bootstrapped and tested on aarch64-none-linux-gnu.
Ok for trunk?
Thanks,
Kyrill

gcc/ChangeLog:

        * df-scan.cc (df_update_exit_block_uses): Rescan sibling calls if
        the exit block uses changed.
        (df_update_entry_exit_and_calls): Do not rescan call insns.

Signed-off-by: Kyrylo Tkachov <[email protected]>
---
 gcc/df-scan.cc | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/gcc/df-scan.cc b/gcc/df-scan.cc
index c6a5053ddbb..aaabd3c3f3b 100644
--- a/gcc/df-scan.cc
+++ b/gcc/df-scan.cc
@@ -3780,7 +3780,8 @@ df_record_exit_block_uses (bitmap exit_block_uses)
 }
 
 
-/* Update the uses in the exit block.  */
+/* Update the uses in the exit block.  If they changed, rescan the sibling
+   calls, whose refs depend on them.  */
 
 void
 df_update_exit_block_uses (void)
@@ -3804,6 +3805,15 @@ df_update_exit_block_uses (void)
       df_record_exit_block_uses (refs);
       bitmap_copy (df->exit_block_uses, refs);
       df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK));
+
+      /* Only sibling calls read df->exit_block_uses in df_get_call_refs,
+        so no other call insn needs a rescan.  */
+      basic_block bb;
+      rtx_insn *insn;
+      FOR_EACH_BB_FN (bb, cfun)
+       FOR_BB_INSNS (bb, insn)
+         if (CALL_P (insn) && SIBLING_CALL_P (insn))
+           df_insn_rescan (insn);
     }
 }
 
@@ -3837,22 +3847,8 @@ df_hard_reg_init (void)
 void
 df_update_entry_exit_and_calls (void)
 {
-  basic_block bb;
-
   df_update_entry_block_defs ();
   df_update_exit_block_uses ();
-
-  /* The call insns need to be rescanned because there may be changes
-     in the set of registers clobbered across the call.  */
-  FOR_EACH_BB_FN (bb, cfun)
-    {
-      rtx_insn *insn;
-      FOR_BB_INSNS (bb, insn)
-       {
-         if (INSN_P (insn) && CALL_P (insn))
-           df_insn_rescan (insn);
-       }
-    }
 }
 
 
-- 
2.54.0 (Apple Git-157)

Reply via email to