https://gcc.gnu.org/g:fe56cebfeff3cae43e3ddc853036deac648bc871
commit r17-6623-gfe56cebfeff3cae43e3ddc853036deac648bc871 Author: Kyrylo Tkachov <[email protected]> Date: Wed Nov 11 05:55:39 2026 -0800 df: Rescan only sibling calls in df_update_entry_exit_and_calls 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. The entry block defs are not read there. Make df_update_exit_block_uses return true if the exit block uses changed. In df_update_entry_exit_and_calls, rescan only the sibling calls, and only in that case. The call in stack-ptr-mod.cc now goes through df_update_entry_exit_and_calls, so the sibling calls are rescanned if the exit block uses changed, as they were by the next full rescan. This is cheap since it only happens when the uses changed. The call in function.cc that is used when not optimizing is unchanged, there are no sibling calls in that case. With this patch compiling the fmtlib tests uses 3% fewer instructions. Bootstrapped and tested on aarch64-none-linux-gnu. gcc/ChangeLog: * df.h (df_update_exit_block_uses): Return bool. * df-scan.cc (df_update_exit_block_uses): Return true if the exit block uses changed. (df_update_entry_exit_and_calls): Rescan only sibling calls, and only if the exit block uses changed. * stack-ptr-mod.cc (pass_stack_ptr_mod::execute): Call df_update_entry_exit_and_calls instead of df_update_exit_block_uses. Signed-off-by: Kyrylo Tkachov <[email protected]> Diff: --- gcc/df-scan.cc | 30 ++++++++++++++---------------- gcc/df.h | 2 +- gcc/stack-ptr-mod.cc | 4 ++-- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/gcc/df-scan.cc b/gcc/df-scan.cc index c6a5053ddbb6..831b4311cda9 100644 --- a/gcc/df-scan.cc +++ b/gcc/df-scan.cc @@ -3780,9 +3780,9 @@ df_record_exit_block_uses (bitmap exit_block_uses) } -/* Update the uses in the exit block. */ +/* Update the uses in the exit block. Return true if they changed. */ -void +bool df_update_exit_block_uses (void) { bool changed = false; @@ -3805,6 +3805,8 @@ df_update_exit_block_uses (void) bitmap_copy (df->exit_block_uses, refs); df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, EXIT_BLOCK)); } + + return changed; } static bool initialized = false; @@ -3832,27 +3834,23 @@ df_hard_reg_init (void) } /* Recompute the parts of scanning that are based on regs_ever_live - because something changed in that array. */ + because something changed in that array. The refs of a call insn depend + on the exit block uses only for sibling calls, see df_get_call_refs, so + rescan only those, and only if the exit block uses changed. */ void df_update_entry_exit_and_calls (void) { - basic_block bb; - df_update_entry_block_defs (); - df_update_exit_block_uses (); + if (!df_update_exit_block_uses ()) + return; - /* The call insns need to be rescanned because there may be changes - in the set of registers clobbered across the call. */ + basic_block bb; + rtx_insn *insn; 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); - } - } + FOR_BB_INSNS (bb, insn) + if (CALL_P (insn) && SIBLING_CALL_P (insn)) + df_insn_rescan (insn); } diff --git a/gcc/df.h b/gcc/df.h index e086a2890c6c..c1cdd796cf24 100644 --- a/gcc/df.h +++ b/gcc/df.h @@ -1085,7 +1085,7 @@ extern void df_ref_change_reg_with_loc (rtx, unsigned int); extern void df_notes_rescan (rtx_insn *); extern void df_hard_reg_init (void); extern void df_update_entry_block_defs (void); -extern void df_update_exit_block_uses (void); +extern bool df_update_exit_block_uses (void); extern void df_update_entry_exit_and_calls (void); extern bool df_hard_reg_used_p (unsigned int); extern unsigned int df_hard_reg_used_count (unsigned int); diff --git a/gcc/stack-ptr-mod.cc b/gcc/stack-ptr-mod.cc index 095cb2d25a0d..586bfaf41670 100644 --- a/gcc/stack-ptr-mod.cc +++ b/gcc/stack-ptr-mod.cc @@ -99,9 +99,9 @@ pass_stack_ptr_mod::execute (function *fun) /* The value coming into this pass was 0, and the exit block uses are based on this. If the value is now 1, we need to redo the - exit block uses. */ + exit block uses and the sibling calls that depend on them. */ if (df && crtl->sp_is_unchanging) - df_update_exit_block_uses (); + df_update_entry_exit_and_calls (); return 0; }
