public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/105235 - clean EH in execute_cse_conv_1
@ 2022-04-12  9:48 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2022-04-12  9:48 UTC (permalink / raw)
  To: gcc-patches

When a FP conversion is removed we have to eventually clean EH.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2022-04-12  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/105235
	* tree-ssa-math-opts.cc (execute_cse_conv_1): Clean EH and
	return whether the CFG changed.
	(execute_cse_sincos_1): Adjust.

	* g++.dg/opt/pr105235-1.C: New testcase.
---
 gcc/testsuite/g++.dg/opt/pr105235-1.C | 12 ++++++++++++
 gcc/tree-ssa-math-opts.cc             | 15 +++++++++------
 2 files changed, 21 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/opt/pr105235-1.C

diff --git a/gcc/testsuite/g++.dg/opt/pr105235-1.C b/gcc/testsuite/g++.dg/opt/pr105235-1.C
new file mode 100644
index 00000000000..b74d2034f5b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr105235-1.C
@@ -0,0 +1,12 @@
+// PR tree-optimization/105235
+// { dg-do compile }
+// { dg-options "-O -fno-tree-dominator-opts -fexceptions -fnon-call-exceptions -fno-tree-fre" }
+
+struct S { ~S (); };
+
+double
+foo (double d)
+{
+  S s;
+  return __builtin_ilogbl (d) + __builtin_sinl (d);
+}
diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc
index ac277756d24..102b7a2cc99 100644
--- a/gcc/tree-ssa-math-opts.cc
+++ b/gcc/tree-ssa-math-opts.cc
@@ -1113,7 +1113,7 @@ make_pass_cse_reciprocals (gcc::context *ctxt)
    conversions.  Return the prevailing name.  */
 
 static tree
-execute_cse_conv_1 (tree name)
+execute_cse_conv_1 (tree name, bool *cfg_changed)
 {
   if (SSA_NAME_IS_DEFAULT_DEF (name)
       || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name))
@@ -1189,15 +1189,18 @@ execute_cse_conv_1 (tree name)
 	  || !types_compatible_p (TREE_TYPE (name), TREE_TYPE (lhs)))
 	continue;
 
-      if (gimple_bb (def_stmt) == gimple_bb (use_stmt)
-	  || dominated_by_p (CDI_DOMINATORS, gimple_bb (use_stmt),
-			     gimple_bb (def_stmt)))
+      basic_block use_bb = gimple_bb (use_stmt);
+      if (gimple_bb (def_stmt) == use_bb
+	  || dominated_by_p (CDI_DOMINATORS, use_bb, gimple_bb (def_stmt)))
 	{
 	  sincos_stats.conv_removed++;
 
 	  gimple_stmt_iterator gsi = gsi_for_stmt (use_stmt);
 	  replace_uses_by (lhs, name);
-	  gsi_remove (&gsi, true);
+	  if (gsi_remove (&gsi, true)
+	      && gimple_purge_dead_eh_edges (use_bb))
+	    *cfg_changed = true;
+	  release_defs (use_stmt);
 	}
     }
 
@@ -1252,7 +1255,7 @@ execute_cse_sincos_1 (tree name)
   int i;
   bool cfg_changed = false;
 
-  name = execute_cse_conv_1 (name);
+  name = execute_cse_conv_1 (name, &cfg_changed);
 
   FOR_EACH_IMM_USE_STMT (use_stmt, use_iter, name)
     {
-- 
2.34.1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-12  9:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12  9:48 [PATCH] tree-optimization/105235 - clean EH in execute_cse_conv_1 Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).