public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/57600] New: Turn 2 comparisons into 1 with the min
@ 2013-06-12 18:48 glisse at gcc dot gnu.org
  2013-06-13  8:19 ` [Bug tree-optimization/57600] " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-06-12 18:48 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-06-19 16:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-12 18:48 [Bug tree-optimization/57600] New: Turn 2 comparisons into 1 with the min glisse at gcc dot gnu.org
2013-06-13  8:19 ` [Bug tree-optimization/57600] " rguenth at gcc dot gnu.org
2013-06-13  8:40 ` glisse at gcc dot gnu.org
2013-06-13  9:20 ` jakub at gcc dot gnu.org
2013-06-13  9:26 ` glisse at gcc dot gnu.org
2015-06-19 15:25 ` alalaw01 at gcc dot gnu.org
2015-06-19 16:20 ` glisse at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).