[Bug ipa/92133] New: Support multi versioning on self recursive function

fxue at os dot amperecomputing.com gcc-bugzilla@gcc.gnu.org
Thu Oct 17 08:02:00 GMT 2019


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

            Bug ID: 92133
           Summary: Support multi versioning on self recursive function
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fxue at os dot amperecomputing.com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

For recursive function, IPA does not allow constant propagation on parameter
that is used to control recursion. It is common that the parameter is inc/dec
(arithmetic op) a constant before entering next recursion. The following
example gives a general source code pattern.

int recur_fn (int i)
{
  if (i == 6)
    {
      do_work ();
      return 0;
    }

  do_prepare ();

  recur_fn (i + 1);

  do_post ();

  return 0;
}

int foo()
{
  ...
  recur_fn (1);
  ...
}

A straight forward optimization is to duplicate recur_fn () 6 times, which
constitute a calling chain on the specialized copies as:

  recur_fn<i=1>() -> recur_fn<i=2>() -> ... -> recur_fn<i=6>()


More information about the Gcc-bugs mailing list