[pushed] backprop: Avoid double deletions [PR125579]

Message ID 87v7c0gcra.fsf@googlemail.com
State Committed
Headers
Series [pushed] backprop: Avoid double deletions [PR125579] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-aarch64-bootstrap fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap fail Patch failed to apply

Commit Message

Richard Sandiford June 3, 2026, 10:05 a.m. UTC
  In this PR, two values were simplified to the same phi, which in
turn was made redundant by other simplifications.  The pass then
tried to delete the phi twice.

Tested on powerpc64le-linux-gnu and x86_64-linux-gnu.  Pushed as
obvious.

Richard


gcc/
	PR tree-optimization/125579
	* gimple-ssa-backprop.cc (backprop::execute): Avoid double deletions.

gcc/testsuite/
	PR tree-optimization/125579
	* gcc.dg/pr125579.c: New test.
---
 gcc/gimple-ssa-backprop.cc      |  4 +++-
 gcc/testsuite/gcc.dg/pr125579.c | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr125579.c
  

Patch

diff --git a/gcc/gimple-ssa-backprop.cc b/gcc/gimple-ssa-backprop.cc
index 61ceb88ec89..5d7295c9d8e 100644
--- a/gcc/gimple-ssa-backprop.cc
+++ b/gcc/gimple-ssa-backprop.cc
@@ -1119,10 +1119,12 @@  backprop::execute ()
 	commit_replacement (v);
 
   /* Phase 5: Remove any statements that might have become dead.  */
+  auto_bitmap deleted_vars;
   for (unsigned int i = 0; i < m_vars.length (); ++i)
     if (var_info *v = m_vars[i])
       if (TREE_CODE (v->new_value) == SSA_NAME
-	  && has_zero_uses (v->new_value))
+	  && has_zero_uses (v->new_value)
+	  && bitmap_set_bit (deleted_vars, SSA_NAME_VERSION (v->new_value)))
 	{
 	  gimple *stmt = SSA_NAME_DEF_STMT (v->new_value);
 	  gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
diff --git a/gcc/testsuite/gcc.dg/pr125579.c b/gcc/testsuite/gcc.dg/pr125579.c
new file mode 100644
index 00000000000..1293d4d91f9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr125579.c
@@ -0,0 +1,16 @@ 
+/* { dg-options "-w -O3 -fno-tree-ccp -fno-inline" } */
+
+int printf(const char *, ...);
+int a;
+void c(int d) {
+  unsigned e = 0;
+  if (a)
+    e = -(0 / (e * 0));
+  while (a) {
+    if (d)
+      continue;
+    printf("%d", e);
+    e++;
+  }
+}
+int main() { c(1); }