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

            Bug ID: 57600
           Summary: Turn 2 comparisons into 1 with the min
           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

Hello,

in this code:

double SumProduct(const double* v1, const double* v2, int n1, int n2)
{
  double sum=0;
  for(int i=0; i<n1 && i<n2; ++i)
    sum += v1[i]*v2[i];
  return sum;
}

it seems clear that i<n1 && i<n2 should be replaced with i<min(n1,n2) with the
min computation taken out of the loop. Not only do we have 2 comparisons
instead of one in the loop, this also prevents vectorization.

The closest PRs I have found (PR 10520 and PR 21855) are actually very
different.

Reply via email to