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

            Bug ID: 70547
           Summary: Optimize multiplication of booleans to bit_and
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org
  Target Milestone: ---

int f(int a,int b,int c,int d){
  return (a<b)*(c<d);
}

produces

  _3 = a_1(D) < b_2(D);
  _4 = (int) _3;
  _7 = c_5(D) < d_6(D);
  _8 = (int) _7;
  _9 = _4 * _8;
  return _9;

Since we know that _4 and _8 are in the range [0, 1], we could replace the
multiplication with a cheaper AND.

Reply via email to