http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57326

            Bug ID: 57326
           Summary: Piecewise folding of operations on PHI nodes
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org

While experimenting with something else, I noticed that:

unsigned f(unsigned x,unsigned y,bool b){
#define m (b?-1:0)
  return (x&m)|(y&~m);
#undef m
}

produces the following .optimized with -O2:

  unsigned int _8;
  unsigned int prephitmp_11;
  unsigned int _14;

  <bb 2>:
  if (b_3(D) != 0)
    goto <bb 4>;
  else
    goto <bb 3>;

  <bb 3>:

  <bb 4>:
  # _14 = PHI <x_4(D)(2), 0(3)>
  # prephitmp_11 = PHI <0(2), y_6(D)(3)>
  _8 = _14 | prephitmp_11;
  return _8;

It seems to me that it would be possible to replace the affectation to _8 with:
_8 = PHI <x_4(D)|0(2), 0|y_6(D)(3)>

where each element folds nicely.

Reply via email to