public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] rtl-optimization/109237 - speedup bb_is_just_return
@ 2023-03-22 10:03 Richard Biener
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Biener @ 2023-03-22 10:03 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek

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(-)

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);
-- 
2.35.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] rtl-optimization/109237 - speedup bb_is_just_return
@ 2023-04-19  7:18 Richard Biener
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Biener @ 2023-04-19  7:18 UTC (permalink / raw)
  To: gcc-patches

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.

This is a fixed version of the patch originally applied and
reverted.

Re-bootstrap & regtest running on x86_64-unknown-linux-gnu, will push
after that re-succeeds.

Richard.

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

diff --git a/gcc/cfgcleanup.cc b/gcc/cfgcleanup.cc
index 194e0e5de12..78f59e99653 100644
--- a/gcc/cfgcleanup.cc
+++ b/gcc/cfgcleanup.cc
@@ -2608,14 +2608,14 @@ 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);
 
 	if (!*ret && ANY_RETURN_P (pat))
 	  *ret = insn;
-	else if (!*ret && !*use && GET_CODE (pat) == USE
+	else if (*ret && !*use && GET_CODE (pat) == USE
 	    && REG_P (XEXP (pat, 0))
 	    && REG_FUNCTION_VALUE_P (XEXP (pat, 0)))
 	  *use = insn;
-- 
2.35.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rtl-optimization/109237 - speedup bb_is_just_return
  2023-03-28  7:49 ` Jakub Jelinek
@ 2023-03-28  8:40   ` Richard Biener
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Biener @ 2023-03-28  8:40 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Tue, 28 Mar 2023, Jakub Jelinek wrote:

> On Wed, Mar 22, 2023 at 10:03:42AM +0000, Richard Biener via Gcc-patches wrote:
> > 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.
> 
> This seems to regress
> +FAIL: gcc.dg/guality/pr54200.c   -Os  -DPREVENT_OPTIMIZATION  line 20 z == 3
> on x86_64.
> This was meant just as a performance improvement, right?

Yes.  I have reverted the change and will revisit in GCC 14 (I have
tested an adjusted patch that avoids the above regression).

Richard.

> Just with -Os -g0 the assembly difference is:
> --- pr54200.s1	2023-03-28 09:45:57.120647323 +0200
> +++ pr54200.s2	2023-03-28 09:46:00.423599004 +0200
> @@ -19,10 +19,11 @@ foo:
>  	cmpl	$1, %esi
>  	jne	.L3
>  	movl	$2, o(%rip)
> -	ret
> +	jmp	.L4
>  .L3:
>  	addl	%esi, %eax
>  	addl	%edx, %eax
> +.L4:
>  	ret
>  	.cfi_endproc
>  .LFE1:
> so 1 byte longer (ret is 1 byte, jmp 2 bytes), but might be also slower.
> The difference starts during the pro_and_epilogue pass.
> 
> > --- 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);
> > -- 
> > 2.35.3
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rtl-optimization/109237 - speedup bb_is_just_return
       [not found] <20230322100356.5B99E3857C48@sourceware.org>
@ 2023-03-28  7:49 ` Jakub Jelinek
  2023-03-28  8:40   ` Richard Biener
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2023-03-28  7:49 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Wed, Mar 22, 2023 at 10:03:42AM +0000, Richard Biener via Gcc-patches wrote:
> 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.

This seems to regress
+FAIL: gcc.dg/guality/pr54200.c   -Os  -DPREVENT_OPTIMIZATION  line 20 z == 3
on x86_64.
This was meant just as a performance improvement, right?
Just with -Os -g0 the assembly difference is:
--- pr54200.s1	2023-03-28 09:45:57.120647323 +0200
+++ pr54200.s2	2023-03-28 09:46:00.423599004 +0200
@@ -19,10 +19,11 @@ foo:
 	cmpl	$1, %esi
 	jne	.L3
 	movl	$2, o(%rip)
-	ret
+	jmp	.L4
 .L3:
 	addl	%esi, %eax
 	addl	%edx, %eax
+.L4:
 	ret
 	.cfi_endproc
 .LFE1:
so 1 byte longer (ret is 1 byte, jmp 2 bytes), but might be also slower.
The difference starts during the pro_and_epilogue pass.

> --- 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);
> -- 
> 2.35.3

	Jakub


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rtl-optimization/109237 - speedup bb_is_just_return
       [not found] <20230322100405.914ED38582AB@sourceware.org>
@ 2023-03-26 18:01 ` Jeff Law
  0 siblings, 0 replies; 5+ messages in thread
From: Jeff Law @ 2023-03-26 18:01 UTC (permalink / raw)
  To: Richard Biener, gcc-patches; +Cc: Jakub Jelinek



On 3/22/23 04:03, Richard Biener via Gcc-patches wrote:
> 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.
OK.  Sorry if I introduced this hog.

jeff

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-04-19  7:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-22 10:03 [PATCH] rtl-optimization/109237 - speedup bb_is_just_return Richard Biener
     [not found] <20230322100405.914ED38582AB@sourceware.org>
2023-03-26 18:01 ` Jeff Law
     [not found] <20230322100356.5B99E3857C48@sourceware.org>
2023-03-28  7:49 ` Jakub Jelinek
2023-03-28  8:40   ` Richard Biener
2023-04-19  7:18 Richard Biener

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).