diff mbox series

Manually handle recursiveness in prepare_block_for_update

Message ID 1579484321-580-1-git-send-email-apinski@marvell.com
State New
Headers show
Series Manually handle recursiveness in prepare_block_for_update | expand

Commit Message

Andrew Pinski Jan. 20, 2020, 1:38 a.m. UTC
From: Andrew Pinski <apinski@marvell.com>

Reported as PR 93321, prepare_block_for_update with some huge
recusive inlining can go past the stack limit.  The loop
at the end, could be transformed such that the last iteration goes
back to the begining of the function instead of the call.
This reduces the stack usage and speeds up slightly
the function.

OK?  Bootstrapped and tested on x86_64-linux-gnu with no regressions.

ChangeLog:
* tree-into-ssa.c (prepare_block_for_update): Manaually sibcall
optimize to self.
---
 gcc/tree-into-ssa.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Comments

Richard Biener Jan. 20, 2020, 8:30 a.m. UTC | #1
On Mon, Jan 20, 2020 at 2:39 AM <apinski@marvell.com> wrote:
>
> From: Andrew Pinski <apinski@marvell.com>
>
> Reported as PR 93321, prepare_block_for_update with some huge
> recusive inlining can go past the stack limit.  The loop
> at the end, could be transformed such that the last iteration goes
> back to the begining of the function instead of the call.
> This reduces the stack usage and speeds up slightly
> the function.
>
> OK?  Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Can you instead change it to a worklist, see for example
tree-ssa-pre.c:compute_avail
for a recipe.

OK with that change.

Richard.

> ChangeLog:
> * tree-into-ssa.c (prepare_block_for_update): Manaually sibcall
> optimize to self.
> ---
>  gcc/tree-into-ssa.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/tree-into-ssa.c b/gcc/tree-into-ssa.c
> index c27bf2ce121..6e139c3b056 100644
> --- a/gcc/tree-into-ssa.c
> +++ b/gcc/tree-into-ssa.c
> @@ -2616,6 +2616,7 @@ prepare_block_for_update (basic_block bb, bool insert_phi_p)
>    edge e;
>    edge_iterator ei;
>
> +again:
>    mark_block_for_update (bb);
>
>    /* Process PHI nodes marking interesting those that define or use
> @@ -2695,10 +2696,17 @@ prepare_block_for_update (basic_block bb, bool insert_phi_p)
>      }
>
>    /* Now visit all the blocks dominated by BB.  */
> -  for (son = first_dom_son (CDI_DOMINATORS, bb);
> -       son;
> -       son = next_dom_son (CDI_DOMINATORS, son))
> -    prepare_block_for_update (son, insert_phi_p);
> +  for (son = first_dom_son (CDI_DOMINATORS, bb); son; )
> +    {
> +      basic_block next = next_dom_son (CDI_DOMINATORS, son);
> +      if (!next)
> +       {
> +         bb = son;
> +         goto again;
> +       }
> +      prepare_block_for_update (son, insert_phi_p);
> +      son = next;
> +    }
>  }
>
>
> --
> 2.17.1
>
diff mbox series

Patch

diff --git a/gcc/tree-into-ssa.c b/gcc/tree-into-ssa.c
index c27bf2ce121..6e139c3b056 100644
--- a/gcc/tree-into-ssa.c
+++ b/gcc/tree-into-ssa.c
@@ -2616,6 +2616,7 @@  prepare_block_for_update (basic_block bb, bool insert_phi_p)
   edge e;
   edge_iterator ei;
 
+again:
   mark_block_for_update (bb);
 
   /* Process PHI nodes marking interesting those that define or use
@@ -2695,10 +2696,17 @@  prepare_block_for_update (basic_block bb, bool insert_phi_p)
     }
 
   /* Now visit all the blocks dominated by BB.  */
-  for (son = first_dom_son (CDI_DOMINATORS, bb);
-       son;
-       son = next_dom_son (CDI_DOMINATORS, son))
-    prepare_block_for_update (son, insert_phi_p);
+  for (son = first_dom_son (CDI_DOMINATORS, bb); son; )
+    {
+      basic_block next = next_dom_son (CDI_DOMINATORS, son);
+      if (!next)
+	{
+	  bb = son;
+	  goto again;
+	}
+      prepare_block_for_update (son, insert_phi_p);
+      son = next;
+    }
 }