public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "glisse at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/57600] New: Turn 2 comparisons into 1 with the min
Date: Wed, 12 Jun 2013 18:48:00 -0000	[thread overview]
Message-ID: <bug-57600-4@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2013-06-12 18:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-12 18:48 glisse at gcc dot gnu.org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-57600-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).