https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99101

--- Comment #24 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
I do not think there is problem with pdom for cyclic WRT acyclic paths. Both
notions are equivalent here. 

If you have instruction I in, say, header of a loop and you determine it live
then the condition controlling loopback is in control dependent blocks and that
will bring it live which transitively brings everything else.

The thing is that post dominance assumes that every path must progress to exit
node (as promised by -ffinite-loops)

volatile int xx;
int main()
{
  int jobs_ = 1;
  int at_eof_ = 0;
  while (1)
    {
      for (int i = 0; i < jobs_; i++)
        {
          if (at_eof_)
            continue;
          at_eof_ = 1;
          __builtin_printf ("1\n");
          if (xx)
            return 1;
        }
      jobs_ = 0;
    }
  return 0;
}

has infinite loop that is sort of equivalent to

volatile int xx;
int main()
{
  int jobs_ = 1;
  int at_eof_ = 0;
  while (1)
    {
      if (at_eof_)
        continue;
      at_eof_ = 1;
      __builtin_printf ("1\n");
      if (xx)
        return 1;
      jobs_ = 0;
      while (jobs_ == 0);
    }
  return 0;
}
and we manage to "shortcut" "while (jobs_ == 0);" rather than forcing the
original lop to be finite. Since the difference is not visible across any path
that must progress to exit node, both are valid in this sense.

With -fno-finite-loops pdoms still do not consider infinite paths, but since we
make sure that every BB has a path to exit every infinite path can be
approximated by sequence of finite paths. Since we keep all the finite paths
consitent, the only problem may be that we will optimize out the condtiion
deciding on back edge but we don't do that becuase we mark them necessary...

Reply via email to