[v2,5/7] IRA+LRA: Let the backend request to split basic blocks

Message ID alpine.DEB.2.21.2501050339050.49841@angie.orcam.me.uk
State Accepted
Headers
Series Fix data races with sub-longword accesses on Alpha |

Commit Message

Maciej W. Rozycki Jan. 6, 2025, 1:03 p.m. UTC
  The next change for Alpha will produce extra labels and branches in 
reload, which in turn requires basic blocks to be split at completion. 
We do this already for functions that can trap, so just extend the 
arrangement with a flag for the backend to use whenever it finds it 
necessary.

	gcc/
	* function.h (struct function): Add 
	`split_basic_blocks_after_reload' member.
	* lra.cc (lra): Handle it.
	* reload1.cc (reload): Likewise.
---
This was approved by Richard Sandiford in v1, so I'll commit it along with 
6/7, which relies on it.

No change from v1.
---
 gcc/function.h |    3 +++
 gcc/lra.cc     |    6 ++++--
 gcc/reload1.cc |    6 ++++--
 3 files changed, 11 insertions(+), 4 deletions(-)

gcc-split-basic-blocks-after-reload.diff
  

Comments

Richard Sandiford Jan. 6, 2025, 5:41 p.m. UTC | #1
"Maciej W. Rozycki" <macro@orcam.me.uk> writes:
> The next change for Alpha will produce extra labels and branches in 
> reload, which in turn requires basic blocks to be split at completion. 
> We do this already for functions that can trap, so just extend the 
> arrangement with a flag for the backend to use whenever it finds it 
> necessary.
>
> 	gcc/
> 	* function.h (struct function): Add 
> 	`split_basic_blocks_after_reload' member.
> 	* lra.cc (lra): Handle it.
> 	* reload1.cc (reload): Likewise.
> ---
> This was approved by Richard Sandiford in v1, so I'll commit it along with 
> 6/7, which relies on it.

Still stands, but I didn't think of this before, so thought I'd ask:

Would it also work to record max_label_num () before RA and then
compare that recorded value with max_label_num () after RA?
Or would that have too many false positives?

Thanks,
Richard

> No change from v1.
> ---
>  gcc/function.h |    3 +++
>  gcc/lra.cc     |    6 ++++--
>  gcc/reload1.cc |    6 ++++--
>  3 files changed, 11 insertions(+), 4 deletions(-)
>
> gcc-split-basic-blocks-after-reload.diff
>
> Index: gcc/gcc/function.h
> ===================================================================
> --- gcc.orig/gcc/function.h
> +++ gcc/gcc/function.h
> @@ -449,6 +449,9 @@ struct GTY(()) function {
>    /* Set for artificial function created for [[assume (cond)]].
>       These should be GIMPLE optimized, but not expanded to RTL.  */
>    unsigned int assume_function : 1;
> +
> +  /* Nonzero if reload will have to split basic blocks.  */
> +  unsigned int split_basic_blocks_after_reload : 1;
>  };
>  
>  /* Add the decl D to the local_decls list of FUN.  */
> Index: gcc/gcc/lra.cc
> ===================================================================
> --- gcc.orig/gcc/lra.cc
> +++ gcc/gcc/lra.cc
> @@ -2594,8 +2594,10 @@ lra (FILE *f, int verbose)
>  
>    inserted_p = fixup_abnormal_edges ();
>  
> -  /* We've possibly turned single trapping insn into multiple ones.  */
> -  if (cfun->can_throw_non_call_exceptions)
> +  /* Split basic blocks if we've possibly turned single trapping insn
> +     into multiple ones or otherwise the backend requested to do so.  */
> +  if (cfun->can_throw_non_call_exceptions
> +      || cfun->split_basic_blocks_after_reload)
>      {
>        auto_sbitmap blocks (last_basic_block_for_fn (cfun));
>        bitmap_ones (blocks);
> Index: gcc/gcc/reload1.cc
> ===================================================================
> --- gcc.orig/gcc/reload1.cc
> +++ gcc/gcc/reload1.cc
> @@ -1272,8 +1272,10 @@ reload (rtx_insn *first, int global)
>  
>    inserted = fixup_abnormal_edges ();
>  
> -  /* We've possibly turned single trapping insn into multiple ones.  */
> -  if (cfun->can_throw_non_call_exceptions)
> +  /* Split basic blocks if we've possibly turned single trapping insn
> +     into multiple ones or otherwise the backend requested to do so.  */
> +  if (cfun->can_throw_non_call_exceptions
> +      || cfun->split_basic_blocks_after_reload)
>      {
>        auto_sbitmap blocks (last_basic_block_for_fn (cfun));
>        bitmap_ones (blocks);
  

Patch

Index: gcc/gcc/function.h
===================================================================
--- gcc.orig/gcc/function.h
+++ gcc/gcc/function.h
@@ -449,6 +449,9 @@  struct GTY(()) function {
   /* Set for artificial function created for [[assume (cond)]].
      These should be GIMPLE optimized, but not expanded to RTL.  */
   unsigned int assume_function : 1;
+
+  /* Nonzero if reload will have to split basic blocks.  */
+  unsigned int split_basic_blocks_after_reload : 1;
 };
 
 /* Add the decl D to the local_decls list of FUN.  */
Index: gcc/gcc/lra.cc
===================================================================
--- gcc.orig/gcc/lra.cc
+++ gcc/gcc/lra.cc
@@ -2594,8 +2594,10 @@  lra (FILE *f, int verbose)
 
   inserted_p = fixup_abnormal_edges ();
 
-  /* We've possibly turned single trapping insn into multiple ones.  */
-  if (cfun->can_throw_non_call_exceptions)
+  /* Split basic blocks if we've possibly turned single trapping insn
+     into multiple ones or otherwise the backend requested to do so.  */
+  if (cfun->can_throw_non_call_exceptions
+      || cfun->split_basic_blocks_after_reload)
     {
       auto_sbitmap blocks (last_basic_block_for_fn (cfun));
       bitmap_ones (blocks);
Index: gcc/gcc/reload1.cc
===================================================================
--- gcc.orig/gcc/reload1.cc
+++ gcc/gcc/reload1.cc
@@ -1272,8 +1272,10 @@  reload (rtx_insn *first, int global)
 
   inserted = fixup_abnormal_edges ();
 
-  /* We've possibly turned single trapping insn into multiple ones.  */
-  if (cfun->can_throw_non_call_exceptions)
+  /* Split basic blocks if we've possibly turned single trapping insn
+     into multiple ones or otherwise the backend requested to do so.  */
+  if (cfun->can_throw_non_call_exceptions
+      || cfun->split_basic_blocks_after_reload)
     {
       auto_sbitmap blocks (last_basic_block_for_fn (cfun));
       bitmap_ones (blocks);