Hi! During analysis, we correctly ignore debug stmt uses, but if we don't release the ssa name we stopped using, the debug stmts uses are left in the IL. The reset_debug_uses call is needed because the code modifies the division stmt in place. Perhaps better would be not to do that, i.e. create a new division and gsi_replace it, then just the release_ssa_name would be enough and the generic code could add e.g. the 1.0 / _1 replacement for the debug stmt? 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? 2018-11-13 Jakub Jelinek <ja...@redhat.com> PR tree-optimization/87977 * tree-ssa-math-opts.c (optimize_recip_sqrt): Call reset_debug_uses on stmt before changing the lhs if !has_other_use. Formatting fix. Call release_ssa_name (x) if !has_other_use and !delete_div. * 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-10-23 10:13:22.640922226 +0200 +++ gcc/tree-ssa-math-opts.c 2018-11-12 16:55:45.468734060 +0100 @@ -652,6 +652,8 @@ optimize_recip_sqrt (gimple_stmt_iterato print_gimple_stmt (dump_file, stmt, 0, TDF_NONE); fprintf (dump_file, "with new division\n"); } + if (!has_other_use) + reset_debug_uses (stmt); gimple_assign_set_lhs (stmt, sqr_ssa_name); gimple_assign_set_rhs2 (stmt, a); fold_stmt_inplace (def_gsi); @@ -704,7 +706,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 +717,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 --- gcc/testsuite/gcc.dg/recip_sqrt_mult_1.c.jj 2018-09-11 18:12:24.876207127 +0200 +++ gcc/testsuite/gcc.dg/recip_sqrt_mult_1.c 2018-11-12 16:57:53.301634244 +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-09-11 18:12:24.876207127 +0200 +++ gcc/testsuite/gcc.dg/recip_sqrt_mult_2.c 2018-11-12 16:58:01.250503686 +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-09-11 18:12:24.876207127 +0200 +++ gcc/testsuite/gcc.dg/recip_sqrt_mult_3.c 2018-11-12 16:58:12.302322133 +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-09-11 18:12:24.877207110 +0200 +++ gcc/testsuite/gcc.dg/recip_sqrt_mult_4.c 2018-11-12 16:58:35.748936997 +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-09-11 18:12:24.875207143 +0200 +++ gcc/testsuite/gcc.dg/recip_sqrt_mult_5.c 2018-11-12 16:58:41.950835127 +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