rtl-optimization/109237 - speedup bb_is_just_return

Message ID 20230322100420.B430D3858416@sourceware.org
State Committed
Commit 776a5bb5894315ab144dc74222fc580fde8fdd87
Headers
Series rtl-optimization/109237 - speedup bb_is_just_return |

Commit Message

Richard Biener March 22, 2023, 10:03 a.m. UTC
  For the testcase bb_is_just_return is on top of the profile, changing
it to walk BB insns backwards puts it off the profile.  That's because
in the forward walk you have to process possibly many debug insns
but in a backward walk you very likely run into control insns first.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

OK?

For the record, the profile was (after the delete_trivially_dead_insns 
fix)

Samples: 289K of event 'cycles:u', Event count (approx.): 384226334976                      
Overhead       Samples  Command  Shared Object     Symbol                                   
   3.52%          9747  cc1      cc1               [.] bb_is_just_return                   
#

and after the fix bb_is_just_return has no recorded samples anymore.

Thanks,
Richard.

	PR rtl-optimization/109237
	* cfgcleanup.cc (bb_is_just_return): Walk insns backwards.
---
 gcc/cfgcleanup.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/gcc/cfgcleanup.cc b/gcc/cfgcleanup.cc
index 194e0e5de12..4cd33878ef3 100644
--- a/gcc/cfgcleanup.cc
+++ b/gcc/cfgcleanup.cc
@@ -2608,7 +2608,7 @@  bb_is_just_return (basic_block bb, rtx_insn **ret, rtx_insn **use)
   if (bb == EXIT_BLOCK_PTR_FOR_FN (cfun))
     return false;
 
-  FOR_BB_INSNS (bb, insn)
+  FOR_BB_INSNS_REVERSE (bb, insn)
     if (NONDEBUG_INSN_P (insn))
       {
 	rtx pat = PATTERN (insn);