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

            Bug ID: 91088
           Summary: IPA-cp cost evaluation is too conservative for "if
                    (f(param) cmp const_val)" condition
           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: ---

Current IPA-cp only detects conditional statement like "if (param cmp
const_val)", and gives a reasonable cost evaluation used in function
versioning. But beyond this form, any generalized form as f(param), a function
on the parameter, which involves extra operations and constant values, will be
conservatively treated, have not use in cost computation.

The following is an example, compiled with "-O3 -fno-inline".

The value "5" is propagated into callee(), for "if (v < 3)", ipa-cp can
deduce that "true branch" will not be executed, and benefit for function
versioning is large. And for "if (v * 2 < 6)", ipa-cp can not handle that, and
conservatively takes cost of "true branch" into account, so get a "no need to
clone function" conclusion.

int foo();

int callee(int v)
{
  // if (v < 3)      // will make a constprop copy with v = 5
  // if (v * 2 < 6)  // will no make a constprop copy
    {
      foo();
      foo();
      foo();
      foo();
      foo();
      foo();
      foo();
      foo();
      foo();
    }
  else
    return 1;
}

int caller()
{
  return callee (5);
}

Reply via email to