The problem here is remove_unused_var is called on a name that is
defined by a phi node but it deletes it like removing a normal statement.
remove_phi_node should be called rather than gsi_remove for phinodes.
Note there is a possibility of using simple_dce_from_worklist instead
but that is for another day.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/116922
gcc/ChangeLog:
* gimple-ssa-backprop.cc (remove_unused_var): Handle phi
nodes correctly.
gcc/testsuite/ChangeLog:
* gcc.dg/torture/pr116922.c: New test.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
(cherry picked from commit
cea87c84eacdb422caeada734ba5138c994d7022)
print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
}
gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
- gsi_remove (&gsi, true);
- release_defs (stmt);
+ if (gimple_code (stmt) == GIMPLE_PHI)
+ remove_phi_node (&gsi, true);
+ else
+ {
+ unlink_stmt_vdef (stmt);
+ gsi_remove (&gsi, true);
+ release_defs (stmt);
+ }
}
/* Note that we're replacing OLD_RHS with NEW_RHS in STMT. */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-additional-options "-ffast-math" } */
+/* PR tree-optimization/116922 */
+
+
+static int g;
+
+void
+foo (int c, double v, double *r)
+{
+b:
+ do
+ v /= g - v;
+ while (c);
+ *r = v;
+
+ double x;
+ foo (5, (double)0, &x);
+}