ext-dce + df-core could be treated as finite-state machine, whose states acting on livenow and livein bitmaps. In some situations, it can loop forever flipping/flopping or widening/narrowing livein states with livenow. Dataflow solver algorithm will never come to the null-worklists in this case. The cornerstone place here is livein state, which could be either widened or narrowed, and thus allow the machine to loop forever.
The solution could be to allow changing of livein bitmaps only in one direction: in our case - to expand. It will cause ext_dce_rd_transfer_n() to guarantee the dataflow solver algorithm to converge to its final state. PR rtl-optimization/119099 gcc/ChangeLog: * ext-dce.cc (ext_dce_rd_transfer_n): Allow livein sets to only expand. gcc/testsuite/ChangeLog: * gcc.c-torture/compile/pr119099.c: New test. Co-authored-by: Jeff Law <j...@ventanamicro.com> --- gcc/ext-dce.cc | 15 ++++------- .../gcc.c-torture/compile/pr119099.c | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr119099.c diff --git a/gcc/ext-dce.cc b/gcc/ext-dce.cc index e257e3bc873..a90c9ebf500 100644 --- a/gcc/ext-dce.cc +++ b/gcc/ext-dce.cc @@ -1089,16 +1089,11 @@ ext_dce_rd_transfer_n (int bb_index) ext_dce_process_bb (bb); - /* We may have narrowed the set of live objects at the start - of this block. If so, update the bitmaps and indicate to - the generic dataflow code that something changed. */ - if (!bitmap_equal_p (&livein[bb_index], livenow)) - { - bitmap_copy (&livein[bb_index], livenow); - return true; - } - - return false; + /* In order to guarantee the dataflow solver algorithm to converge + to its final state, livein sets should never be narrowed. + So, expand livein bitmap with livenow updates and return true + if livein was actually changed. */ + return bitmap_ior_into (&livein[bb_index], livenow); } /* Dummy function for the df_simple_dataflow API. */ diff --git a/gcc/testsuite/gcc.c-torture/compile/pr119099.c b/gcc/testsuite/gcc.c-torture/compile/pr119099.c new file mode 100644 index 00000000000..056b63d8cbc --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr119099.c @@ -0,0 +1,25 @@ +/* PR rtl-optimization/119099. + Checks that ext-dce won't hang in compile time. */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-flto" "-finline-functions" } } */ +/* { dg-timeout 10 } */ + +int a, b; + +void func2 (short); + +void func1 () +{ + while (1) + { + int loc = 8; + while (1) + { + func2 (loc); + if (a) + loc = 3; + else if (b) + break; + loc |= a; + } + } +} -- 2.34.1