From 3b7eecca20bcb05e0220b3d012df012902a23534 Mon Sep 17 00:00:00 2001
From: Andrew Pinski <apinski@marvell.com>
Date: Tue, 2 May 2023 00:08:19 -0700
Subject: [PATCH] Add stats to simple_dce_from_worklist

While looking to move substitute_and_fold_engine
over to use simple_dce_from_worklist, I noticed
that we don't record the stats of the removed stmts/phis.
So this does that.

OK? Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

	* tree-ssa-dce.cc (simple_dce_from_worklist): Record
	stats on removed number of statements and phis.
---
 gcc/tree-ssa-dce.cc | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc
index 1fd88e8ee37c..e4c32e630dfd 100644
--- a/gcc/tree-ssa-dce.cc
+++ b/gcc/tree-ssa-dce.cc
@@ -2099,6 +2099,8 @@ make_pass_cd_dce (gcc::context *ctxt)
 void
 simple_dce_from_worklist (bitmap worklist)
 {
+  int phiremoved = 0;
+  int stmtremoved = 0;
   while (! bitmap_empty_p (worklist))
     {
       /* Pop item.  */
@@ -2144,12 +2146,20 @@ simple_dce_from_worklist (bitmap worklist)
 	}
       gimple_stmt_iterator gsi = gsi_for_stmt (t);
       if (gimple_code (t) == GIMPLE_PHI)
-	remove_phi_node (&gsi, true);
+	{
+	  remove_phi_node (&gsi, true);
+	  phiremoved++;
+	}
       else
 	{
 	  unlink_stmt_vdef (t);
 	  gsi_remove (&gsi, true);
 	  release_defs (t);
+	  stmtremoved++;
 	}
     }
+  statistics_counter_event (cfun, "PHIs removed",
+			    phiremoved);
+  statistics_counter_event (cfun, "Statements removed",
+			    stmtremoved);
 }
-- 
GitLab