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

            Bug ID: 124622
           Summary: Missed opportunity for IPA CP cloning, IPA reference
                    constification in 544.nab_r
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

The hot function mme34 has

 if (dim == 4)

conditional code, but the global static dim variable is just set in three
places, to either 3 or 4 with the setter to 4 being

REAL_T mme4(REAL_T * x, REAL_T * f, int *iter)
{
   dim = 4;
   return mme34(x, f, iter);
}

the setter to 3 (also the initial value of dim) being in an initialization
function as well as a corresponding

REAL_T mme(REAL_T * x, REAL_T * f, int *iter)
{  
   dim = 3;
   return mme34(x, f, iter);    
}

the mme4 function is not used, so with -flto only setters to value 3 remain.
Still the runtime conditionals in mme34 on dim prevail.  Without LTO the
static mme34 function would be a candidate for "IPA CP" of 'dim'.

This IPA transform would turn 'dim' into a parameter, replacing accesses
to 'dim' in the callee by constants.  Feels like IPA reference which
knows that mme34 does not write to 'dim':

Function name:mme34/153:
    locals read: prm dim frozen max_step chknm nconstrained pairlistnp upairsnp
lpairsnp pairlist nb_pairs upairs lpairs N14pearlist grad reqack
    locals written: nb_pairs tpair tmme tcons tborn tphi tangl tbond tnonb tmd
treduce grad reqack
  globals read: ALL
  globals written: ALL

with LTO at WPA time the write with value 4 is gone, but we do not promote
the variable constant for some reason.

Reply via email to