From: Richard Biener Date: Wed, 29 Mar 2023 07:51:58 +0000 (+0200) Subject: tree-optimization/109327 - forwprop stmt removal issue X-Git-Tag: basepoints/gcc-14~281 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7fd1d28d2436065da7fc0fe01d787fcdf3c14b83;p=thirdparty%2Fgcc.git 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. --- diff --git a/gcc/testsuite/gcc.dg/pr109327.c b/gcc/testsuite/gcc.dg/pr109327.c new file mode 100644 index 000000000000..827b26f148eb --- /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 5eccc7a89b59..bb0fa306312f 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 ");