public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "shawn at churchofgit dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/65855] New: missing optimization: triangular numbers
Date: Thu, 23 Apr 2015 04:52:00 -0000	[thread overview]
Message-ID: <bug-65855-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 65855
           Summary: missing optimization: triangular numbers
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shawn at churchofgit dot com

Created attachment 35388
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35388&action=edit
triangle.c

If a register mode is available to avoid multiplication overflow, a loop that
is calculating triangular numbers could be optimized to a multiplication:

uint64_t triangle(uint32_t n) {
uint64_t t = 0;
for (uint64_t i=1;i<=n;i++) t += i;
return t;
}

=>

uint64_t triangle_fast(uint32_t _n) {
uint64_t t, n = _n;
t = (n * (n + 1)) / 2;
return t;
}


             reply	other threads:[~2015-04-23  4:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-23  4:52 shawn at churchofgit dot com [this message]
2015-04-23  5:32 ` [Bug middle-end/65855] " pinskia at gcc dot gnu.org
2015-04-25  4:26 ` shawn at churchofgit dot com
2015-04-27 12:11 ` rguenth at gcc dot gnu.org
2015-10-23 12:05 ` rguenth at gcc dot gnu.org
2015-10-23 12:42 ` rguenth at gcc dot gnu.org
2021-08-07  6:42 ` [Bug middle-end/65855] SCEV / SCCP " pinskia at gcc dot gnu.org
2021-08-28 23:42 ` pinskia at gcc dot gnu.org
2023-06-10 16:02 ` pinskia at gcc dot gnu.org
2023-11-22  0:09 ` pinskia 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-65855-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).