public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/65855] New: missing optimization: triangular numbers
@ 2015-04-23  4:52 shawn at churchofgit dot com
  2015-04-23  5:32 ` [Bug middle-end/65855] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: shawn at churchofgit dot com @ 2015-04-23  4:52 UTC (permalink / raw)
  To: gcc-bugs

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;
}


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

end of thread, other threads:[~2023-11-22  0:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-23  4:52 [Bug c/65855] New: missing optimization: triangular numbers shawn at churchofgit dot com
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

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).