diff mbox series

object-size: Use simple_dce_from_worklist in object-size pass

Message ID 20240903235754.2829849-1-quic_apinski@quicinc.com
State New
Headers show
Series object-size: Use simple_dce_from_worklist in object-size pass | expand

Commit Message

Andrew Pinski Sept. 3, 2024, 11:57 p.m. UTC
While trying to see if there was a way to improve object-size pass
to use the ranger (for pointer plus), I noticed that it leaves around
the statement containing __builtin_object_size if it was reduced to a constant.
This fixes that by using simple_dce_from_worklist.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-object-size.cc (object_sizes_execute): Mark lhs for maybe dceing
	if doing a propagate. Call simple_dce_from_worklist.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
---
 gcc/tree-object-size.cc | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Richard Biener Sept. 4, 2024, 7:38 a.m. UTC | #1
On Wed, Sep 4, 2024 at 1:58 AM Andrew Pinski <quic_apinski@quicinc.com> wrote:
>
> While trying to see if there was a way to improve object-size pass
> to use the ranger (for pointer plus), I noticed that it leaves around
> the statement containing __builtin_object_size if it was reduced to a constant.
> This fixes that by using simple_dce_from_worklist.
>
> Bootstrapped and tested on x86_64-linux-gnu.

OK.

> gcc/ChangeLog:
>
>         * tree-object-size.cc (object_sizes_execute): Mark lhs for maybe dceing
>         if doing a propagate. Call simple_dce_from_worklist.
>
> Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
> ---
>  gcc/tree-object-size.cc | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc
> index 4c1fa9b555f..6544730e153 100644
> --- a/gcc/tree-object-size.cc
> +++ b/gcc/tree-object-size.cc
> @@ -38,6 +38,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "builtins.h"
>  #include "gimplify-me.h"
>  #include "gimplify.h"
> +#include "tree-ssa-dce.h"
>
>  struct object_size_info
>  {
> @@ -2187,6 +2188,7 @@ static unsigned int
>  object_sizes_execute (function *fun, bool early)
>  {
>    todo = 0;
> +  auto_bitmap sdce_worklist;
>
>    basic_block bb;
>    FOR_EACH_BB_FN (bb, fun)
> @@ -2277,13 +2279,18 @@ object_sizes_execute (function *fun, bool early)
>
>           /* Propagate into all uses and fold those stmts.  */
>           if (!SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
> -           replace_uses_by (lhs, result);
> +           {
> +             replace_uses_by (lhs, result);
> +             /* Mark lhs as being possiblely DCEd. */
> +             bitmap_set_bit (sdce_worklist, SSA_NAME_VERSION (lhs));
> +           }
>           else
>             replace_call_with_value (&i, result);
>         }
>      }
>
>    fini_object_sizes ();
> +  simple_dce_from_worklist (sdce_worklist);
>    return todo;
>  }
>
> --
> 2.43.0
>
diff mbox series

Patch

diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc
index 4c1fa9b555f..6544730e153 100644
--- a/gcc/tree-object-size.cc
+++ b/gcc/tree-object-size.cc
@@ -38,6 +38,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "builtins.h"
 #include "gimplify-me.h"
 #include "gimplify.h"
+#include "tree-ssa-dce.h"
 
 struct object_size_info
 {
@@ -2187,6 +2188,7 @@  static unsigned int
 object_sizes_execute (function *fun, bool early)
 {
   todo = 0;
+  auto_bitmap sdce_worklist;
 
   basic_block bb;
   FOR_EACH_BB_FN (bb, fun)
@@ -2277,13 +2279,18 @@  object_sizes_execute (function *fun, bool early)
 
 	  /* Propagate into all uses and fold those stmts.  */
 	  if (!SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
-	    replace_uses_by (lhs, result);
+	    {
+	      replace_uses_by (lhs, result);
+	      /* Mark lhs as being possiblely DCEd. */
+	      bitmap_set_bit (sdce_worklist, SSA_NAME_VERSION (lhs));
+	    }
 	  else
 	    replace_call_with_value (&i, result);
 	}
     }
 
   fini_object_sizes ();
+  simple_dce_from_worklist (sdce_worklist);
   return todo;
 }