complex: Don't DCE unused COMPLEX_EXPRs for -O0 [PR119190]

Message ID Z8/s2TdDV8aV3TF7@tucnak
State New
Headers
Series complex: Don't DCE unused COMPLEX_EXPRs for -O0 [PR119190] |

Commit Message

Jakub Jelinek March 11, 2025, 7:57 a.m. UTC
  Hi!

The PR116463 r15-3128 change regressed the following testcase at -O0.
While for -O1+ we can do -fvar-tracking-assignments, for -O0 we don't
(partly because it is compile time expensive and partly because at -O0
most of the vars live most of their lifetime in memory slots), so if we
DCE some statements, it can mean that DW_AT_location for some vars won't
be available or even it won't be possible to put a breakpoint at some
particular line in the source.
We normally perform dce just in the subpasses of
pass_local_optimization_passes or pass_all_optimizations or
pass_all_optimizations_g, so don't do that at all for -O0.  So the complex
change is an exception.  And it was described as a way to help forwprop and
reassoc, neither applies to -O0.

This regresses PR119120 again though, I'll post a patch for that momentarily.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2025-03-11  Jakub Jelinek  <jakub@redhat.com>

	PR debug/119190
	* tree-complex.cc (update_complex_assignment, tree_lower_complex):
	Perform simple dce on dce_worklist only if optimize.

	* gfortran.dg/guality/pr119190.f90: New test.


	Jakub
  

Comments

Richard Biener March 11, 2025, 8:53 a.m. UTC | #1
On Tue, 11 Mar 2025, Jakub Jelinek wrote:

> Hi!
> 
> The PR116463 r15-3128 change regressed the following testcase at -O0.
> While for -O1+ we can do -fvar-tracking-assignments, for -O0 we don't
> (partly because it is compile time expensive and partly because at -O0
> most of the vars live most of their lifetime in memory slots), so if we
> DCE some statements, it can mean that DW_AT_location for some vars won't
> be available or even it won't be possible to put a breakpoint at some
> particular line in the source.
> We normally perform dce just in the subpasses of
> pass_local_optimization_passes or pass_all_optimizations or
> pass_all_optimizations_g, so don't do that at all for -O0.  So the complex
> change is an exception.  And it was described as a way to help forwprop and
> reassoc, neither applies to -O0.
> 
> This regresses PR119120 again though, I'll post a patch for that momentarily.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

> 2025-03-11  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR debug/119190
> 	* tree-complex.cc (update_complex_assignment, tree_lower_complex):
> 	Perform simple dce on dce_worklist only if optimize.
> 
> 	* gfortran.dg/guality/pr119190.f90: New test.
> 
> --- gcc/tree-complex.cc.jj	2025-01-02 11:23:34.810261473 +0100
> +++ gcc/tree-complex.cc	2025-03-10 13:18:42.655209216 +0100
> @@ -735,7 +735,8 @@ update_complex_assignment (gimple_stmt_i
>    update_stmt (stmt);
>    if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt))
>      bitmap_set_bit (need_eh_cleanup, gimple_bb (stmt)->index);
> -  bitmap_set_bit (dce_worklist, SSA_NAME_VERSION (gimple_assign_lhs (stmt)));
> +  if (optimize)
> +    bitmap_set_bit (dce_worklist, SSA_NAME_VERSION (gimple_assign_lhs (stmt)));
>  
>    update_complex_components (gsi, gsi_stmt (*gsi), r, i);
>  }
> @@ -1967,7 +1968,8 @@ tree_lower_complex (void)
>    complex_propagate.ssa_propagate ();
>  
>    need_eh_cleanup = BITMAP_ALLOC (NULL);
> -  dce_worklist = BITMAP_ALLOC (NULL);
> +  if (optimize)
> +    dce_worklist = BITMAP_ALLOC (NULL);
>  
>    complex_variable_components = new int_tree_htab_type (10);
>  
> @@ -2014,8 +2016,11 @@ tree_lower_complex (void)
>  
>    gsi_commit_edge_inserts ();
>  
> -  simple_dce_from_worklist (dce_worklist, need_eh_cleanup);
> -  BITMAP_FREE (dce_worklist);
> +  if (optimize)
> +    {
> +      simple_dce_from_worklist (dce_worklist, need_eh_cleanup);
> +      BITMAP_FREE (dce_worklist);
> +    }
>  
>    unsigned todo
>      = gimple_purge_all_dead_eh_edges (need_eh_cleanup) ? TODO_cleanup_cfg : 0;
> --- gcc/testsuite/gfortran.dg/guality/pr119190.f90.jj	2025-03-10 13:19:34.375502530 +0100
> +++ gcc/testsuite/gfortran.dg/guality/pr119190.f90	2025-03-10 13:24:13.394683486 +0100
> @@ -0,0 +1,13 @@
> +! PR debug/119190
> +! { dg-do run }
> +! { dg-options "-g" }
> +
> +program foo
> +  integer :: ia, ib
> +  complex :: ci
> +  ia = 1
> +  ib = 2
> +  ci = cmplx(ia, ib)
> +  print *, ia
> +  print *, ib	! { dg-final { gdb-test 12 "ci" "(1,2)" } }
> +end program
> 
> 	Jakub
> 
>
  

Patch

--- gcc/tree-complex.cc.jj	2025-01-02 11:23:34.810261473 +0100
+++ gcc/tree-complex.cc	2025-03-10 13:18:42.655209216 +0100
@@ -735,7 +735,8 @@  update_complex_assignment (gimple_stmt_i
   update_stmt (stmt);
   if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt))
     bitmap_set_bit (need_eh_cleanup, gimple_bb (stmt)->index);
-  bitmap_set_bit (dce_worklist, SSA_NAME_VERSION (gimple_assign_lhs (stmt)));
+  if (optimize)
+    bitmap_set_bit (dce_worklist, SSA_NAME_VERSION (gimple_assign_lhs (stmt)));
 
   update_complex_components (gsi, gsi_stmt (*gsi), r, i);
 }
@@ -1967,7 +1968,8 @@  tree_lower_complex (void)
   complex_propagate.ssa_propagate ();
 
   need_eh_cleanup = BITMAP_ALLOC (NULL);
-  dce_worklist = BITMAP_ALLOC (NULL);
+  if (optimize)
+    dce_worklist = BITMAP_ALLOC (NULL);
 
   complex_variable_components = new int_tree_htab_type (10);
 
@@ -2014,8 +2016,11 @@  tree_lower_complex (void)
 
   gsi_commit_edge_inserts ();
 
-  simple_dce_from_worklist (dce_worklist, need_eh_cleanup);
-  BITMAP_FREE (dce_worklist);
+  if (optimize)
+    {
+      simple_dce_from_worklist (dce_worklist, need_eh_cleanup);
+      BITMAP_FREE (dce_worklist);
+    }
 
   unsigned todo
     = gimple_purge_all_dead_eh_edges (need_eh_cleanup) ? TODO_cleanup_cfg : 0;
--- gcc/testsuite/gfortran.dg/guality/pr119190.f90.jj	2025-03-10 13:19:34.375502530 +0100
+++ gcc/testsuite/gfortran.dg/guality/pr119190.f90	2025-03-10 13:24:13.394683486 +0100
@@ -0,0 +1,13 @@ 
+! PR debug/119190
+! { dg-do run }
+! { dg-options "-g" }
+
+program foo
+  integer :: ia, ib
+  complex :: ci
+  ia = 1
+  ib = 2
+  ci = cmplx(ia, ib)
+  print *, ia
+  print *, ib	! { dg-final { gdb-test 12 "ci" "(1,2)" } }
+end program