This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/57600] New: Turn 2 comparisons into 1 with the min
- From: "glisse at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 12 Jun 2013 18:48:55 +0000
- Subject: [Bug tree-optimization/57600] New: Turn 2 comparisons into 1 with the min
- Auto-submitted: auto-generated
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.