diff mbox series

Fix factor_out_conditional_operation heuristics for constants

Message ID 20240912171953.3392313-1-quic_apinski@quicinc.com
State New
Headers show
Series Fix factor_out_conditional_operation heuristics for constants | expand

Commit Message

Andrew Pinski Sept. 12, 2024, 5:19 p.m. UTC
While working on a different patch, I noticed the heuristics were not
doing the right thing if there was statements before the NOP/PREDICTs.
(LABELS don't have other statements before them).

This fixes that oversight which was added in r15-3334-gceda727dafba6e.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-phiopt.cc (factor_out_conditional_operation): Instead
	of just ignorning a NOP/PREDICT, skip over them before checking
	the heuristics.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
---
 gcc/tree-ssa-phiopt.cc | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Comments

Richard Biener Sept. 13, 2024, 11:13 a.m. UTC | #1
On Thu, Sep 12, 2024 at 7:20 PM Andrew Pinski <quic_apinski@quicinc.com> wrote:
>
> While working on a different patch, I noticed the heuristics were not
> doing the right thing if there was statements before the NOP/PREDICTs.
> (LABELS don't have other statements before them).
>
> This fixes that oversight which was added in r15-3334-gceda727dafba6e.
>
> Bootstrapped and tested on x86_64-linux-gnu.

OK

> gcc/ChangeLog:
>
>         * tree-ssa-phiopt.cc (factor_out_conditional_operation): Instead
>         of just ignorning a NOP/PREDICT, skip over them before checking
>         the heuristics.
>
> Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
> ---
>  gcc/tree-ssa-phiopt.cc | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
> index 5710bc32e61..e5413e40572 100644
> --- a/gcc/tree-ssa-phiopt.cc
> +++ b/gcc/tree-ssa-phiopt.cc
> @@ -332,15 +332,17 @@ factor_out_conditional_operation (edge e0, edge e1, gphi *phi,
>         {
>           gsi = gsi_for_stmt (arg0_def_stmt);
>           gsi_prev_nondebug (&gsi);
> +         /* Ignore nops, predicates and labels. */
> +         while (!gsi_end_p (gsi)
> +                 && (gimple_code (gsi_stmt (gsi)) == GIMPLE_NOP
> +                     || gimple_code (gsi_stmt (gsi)) == GIMPLE_PREDICT
> +                     || gimple_code (gsi_stmt (gsi)) == GIMPLE_LABEL))
> +           gsi_prev_nondebug (&gsi);
> +
>           if (!gsi_end_p (gsi))
>             {
>               gimple *stmt = gsi_stmt (gsi);
> -             /* Ignore nops, predicates and labels. */
> -             if (gimple_code (stmt) == GIMPLE_NOP
> -                 || gimple_code (stmt) == GIMPLE_PREDICT
> -                 || gimple_code (stmt) == GIMPLE_LABEL)
> -               ;
> -             else if (gassign *assign = dyn_cast <gassign *> (stmt))
> +             if (gassign *assign = dyn_cast <gassign *> (stmt))
>                 {
>                   tree lhs = gimple_assign_lhs (assign);
>                   enum tree_code ass_code
> --
> 2.43.0
>
diff mbox series

Patch

diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index 5710bc32e61..e5413e40572 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -332,15 +332,17 @@  factor_out_conditional_operation (edge e0, edge e1, gphi *phi,
 	{
 	  gsi = gsi_for_stmt (arg0_def_stmt);
 	  gsi_prev_nondebug (&gsi);
+	  /* Ignore nops, predicates and labels. */
+	  while (!gsi_end_p (gsi)
+		  && (gimple_code (gsi_stmt (gsi)) == GIMPLE_NOP
+		      || gimple_code (gsi_stmt (gsi)) == GIMPLE_PREDICT
+		      || gimple_code (gsi_stmt (gsi)) == GIMPLE_LABEL))
+	    gsi_prev_nondebug (&gsi);
+
 	  if (!gsi_end_p (gsi))
 	    {
 	      gimple *stmt = gsi_stmt (gsi);
-	      /* Ignore nops, predicates and labels. */
-	      if (gimple_code (stmt) == GIMPLE_NOP
-		  || gimple_code (stmt) == GIMPLE_PREDICT
-		  || gimple_code (stmt) == GIMPLE_LABEL)
-		;
-	      else if (gassign *assign = dyn_cast <gassign *> (stmt))
+	      if (gassign *assign = dyn_cast <gassign *> (stmt))
 		{
 		  tree lhs = gimple_assign_lhs (assign);
 		  enum tree_code ass_code