aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2023-03-29 09:51:58 +0200
committerRichard Biener <rguenther@suse.de>2023-03-29 10:34:22 +0200
commit7fd1d28d2436065da7fc0fe01d787fcdf3c14b83 (patch)
treea35d1e2034305e0b4a5a74636e325d683d0ee397
parent36330e2e95564a360e6dbcfb4e7566d5c2177415 (diff)
downloadgcc-7fd1d28d2436065da7fc0fe01d787fcdf3c14b83.zip
gcc-7fd1d28d2436065da7fc0fe01d787fcdf3c14b83.tar.gz
gcc-7fd1d28d2436065da7fc0fe01d787fcdf3c14b83.tar.bz2
tree-optimization/109327 - forwprop stmt removal issue
There's interfering between the to_removed queue and other mechanisms removing stmts, in this case remove_prop_source_from_use. The following makes the to_remove queue draining more permissive. PR tree-optimization/109327 * tree-ssa-forwprop.cc (pass_forwprop::execute): Deal with already removed stmts when draining to_remove. * gcc.dg/pr109327.c: New testcase.
-rw-r--r--gcc/testsuite/gcc.dg/pr109327.c15
-rw-r--r--gcc/tree-ssa-forwprop.cc4
2 files changed, 19 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/pr109327.c b/gcc/testsuite/gcc.dg/pr109327.c
new file mode 100644
index 0000000..827b26f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr109327.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fno-tree-ccp" } */
+
+int a;
+void b(int c) {}
+int main()
+{
+ int d = 0, *e = &a;
+ if (d) {
+ int *f = e;
+ while (a)
+ b(e != f);
+ }
+ return 0;
+}
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 5eccc7a..bb0fa30 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -4061,6 +4061,10 @@ pass_forwprop::execute (function *fun)
while (!to_remove.is_empty())
{
gimple *stmt = to_remove.pop ();
+ /* For example remove_prop_source_from_use can remove stmts queued
+ for removal. Deal with this gracefully. */
+ if (!gimple_bb (stmt))
+ continue;
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, "Removing dead stmt ");