On Wed, 14 Nov 2018, Jakub Jelinek wrote:

> On Tue, Nov 13, 2018 at 10:19:10AM +0100, Jakub Jelinek wrote:
> > > >  Though, in this particular case the sqrt call is
> > > > optimized away, so it wouldn't make a difference.
> > > > 
> > > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk, or
> > > > should I do the gimple_build_assign + gsi_replace change?
> > > 
> > > I think that would be cleaner.
> > 
> > Ok, will do.  Thanks.
> 
> Here it is.  Bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

OK.

Richard.

> 2018-11-13  Jakub Jelinek  <ja...@redhat.com>
> 
>       PR tree-optimization/87977
>       * tree-ssa-math-opts.c (optimize_recip_sqrt): Don't reuse division
>       stmt, build a new one and replace the old one with it.  Formatting fix.
>       Call release_ssa_name (x) if !has_other_use and !delete_div.
>       (pass_cse_reciprocals::execute): Before calling optimize_recip_sqrt
>       verify lhs of stmt is still def.
> 
>       * gcc.dg/recip_sqrt_mult_1.c: Add -fcompare-debug to dg-options.
>       * gcc.dg/recip_sqrt_mult_2.c: Likewise.
>       * gcc.dg/recip_sqrt_mult_3.c: Likewise.
>       * gcc.dg/recip_sqrt_mult_4.c: Likewise.
>       * gcc.dg/recip_sqrt_mult_5.c: Likewise.
> 
> --- gcc/tree-ssa-math-opts.c.jj       2018-11-12 20:01:19.224793981 +0100
> +++ gcc/tree-ssa-math-opts.c  2018-11-13 11:30:16.326203020 +0100
> @@ -652,10 +652,14 @@ optimize_recip_sqrt (gimple_stmt_iterato
>         print_gimple_stmt (dump_file, stmt, 0, TDF_NONE);
>         fprintf (dump_file, "with new division\n");
>       }
> -      gimple_assign_set_lhs (stmt, sqr_ssa_name);
> -      gimple_assign_set_rhs2 (stmt, a);
> +      stmt
> +     = gimple_build_assign (sqr_ssa_name, gimple_assign_rhs_code (stmt),
> +                            gimple_assign_rhs1 (stmt), a);
> +      gsi_insert_before (def_gsi, stmt, GSI_SAME_STMT);
> +      gsi_remove (def_gsi, true);
> +      *def_gsi = gsi_for_stmt (stmt);
>        fold_stmt_inplace (def_gsi);
>        update_stmt (stmt);
>  
>        if (dump_file)
>       print_gimple_stmt (dump_file, stmt, 0, TDF_NONE);
> @@ -704,7 +707,7 @@ optimize_recip_sqrt (gimple_stmt_iterato
>  
>        gimple *new_stmt
>       = gimple_build_assign (x, MULT_EXPR,
> -                             orig_sqrt_ssa_name, sqr_ssa_name);
> +                            orig_sqrt_ssa_name, sqr_ssa_name);
>        gsi_insert_after (def_gsi, new_stmt, GSI_NEW_STMT);
>        update_stmt (stmt);
>      }
> @@ -715,6 +718,8 @@ optimize_recip_sqrt (gimple_stmt_iterato
>        gsi_remove (&gsi2, true);
>        release_defs (stmt);
>      }
> +  else
> +    release_ssa_name (x);
>  }
>  
>  /* Look for floating-point divisions among DEF's uses, and try to
> @@ -951,6 +956,7 @@ pass_cse_reciprocals::execute (function
>             stmt = gsi_stmt (gsi);
>             if (flag_unsafe_math_optimizations
>                 && is_gimple_assign (stmt)
> +               && gimple_assign_lhs (stmt) == def
>                 && !stmt_can_throw_internal (cfun, stmt)
>                 && gimple_assign_rhs_code (stmt) == RDIV_EXPR)
>               optimize_recip_sqrt (&gsi, def);
> --- gcc/testsuite/gcc.dg/recip_sqrt_mult_1.c.jj       2018-11-12 
> 20:01:19.315792497 +0100
> +++ gcc/testsuite/gcc.dg/recip_sqrt_mult_1.c  2018-11-13 11:17:41.667541915 
> +0100
> @@ -1,5 +1,5 @@
>  /* { dg-do compile } */
> -/* { dg-options "-Ofast -fdump-tree-recip" } */
> +/* { dg-options "-Ofast -fdump-tree-recip -fcompare-debug" } */
>  
>  double res, res2, tmp;
>  void
> --- gcc/testsuite/gcc.dg/recip_sqrt_mult_2.c.jj       2018-11-12 
> 20:01:19.320792415 +0100
> +++ gcc/testsuite/gcc.dg/recip_sqrt_mult_2.c  2018-11-13 11:17:41.668541899 
> +0100
> @@ -1,5 +1,5 @@
>  /* { dg-do compile } */
> -/* { dg-options "-Ofast -fdump-tree-optimized" } */
> +/* { dg-options "-Ofast -fdump-tree-optimized -fcompare-debug" } */
>  
>  float
>  foo (float a)
> --- gcc/testsuite/gcc.dg/recip_sqrt_mult_3.c.jj       2018-11-12 
> 20:01:19.363791713 +0100
> +++ gcc/testsuite/gcc.dg/recip_sqrt_mult_3.c  2018-11-13 11:17:41.671541850 
> +0100
> @@ -1,5 +1,5 @@
>  /* { dg-do compile } */
> -/* { dg-options "-Ofast -fdump-tree-optimized" } */
> +/* { dg-options "-Ofast -fdump-tree-optimized -fcompare-debug" } */
>  
>  double
>  foo (double a)
> --- gcc/testsuite/gcc.dg/recip_sqrt_mult_4.c.jj       2018-11-12 
> 20:01:19.371791582 +0100
> +++ gcc/testsuite/gcc.dg/recip_sqrt_mult_4.c  2018-11-13 11:17:41.686541603 
> +0100
> @@ -1,5 +1,5 @@
>  /* { dg-do compile } */
> -/* { dg-options "-Ofast -fdump-tree-recip" } */
> +/* { dg-options "-Ofast -fdump-tree-recip -fcompare-debug" } */
>  
>  /* The main path doesn't have any multiplications.
>     Avoid introducing them in the recip pass.  */
> --- gcc/testsuite/gcc.dg/recip_sqrt_mult_5.c.jj       2018-11-12 
> 20:01:19.386791336 +0100
> +++ gcc/testsuite/gcc.dg/recip_sqrt_mult_5.c  2018-11-13 11:17:41.705541293 
> +0100
> @@ -1,5 +1,5 @@
>  /* { dg-do compile } */
> -/* { dg-options "-Ofast -fdump-tree-recip" } */
> +/* { dg-options "-Ofast -fdump-tree-recip -fcompare-debug" } */
>  
>  /* We want to do the recip_sqrt transformations here there is already
>     a multiplication on the main path.  */
> 
> 
>       Jakub
> 
> 

-- 
Richard Biener <rguent...@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 
21284 (AG Nuernberg)

Reply via email to