public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/98334] New: Failure to optimally optimize add loop to mul
@ 2020-12-16 18:48 gabravier at gmail dot com
  2020-12-17 10:04 ` [Bug tree-optimization/98334] " jakub at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: gabravier at gmail dot com @ 2020-12-16 18:48 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98334
           Summary: Failure to optimally optimize add loop to mul
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

int f(int i, unsigned int n) {
    int result = 0;
    while (n > 0) {
        result += i;
        n -= 1;
    }
    return result;
}

GCC optimizes this function to code that effectively does `return (n == 0) ? 0
: (i - 1) * n + n;`. It could instead emit the more optimal `return (n == 0) ?
0 : i * n;`, or just `return i * n;` on platforms where multiplication is fast.
This transformation is done by LLVM, but not by GCC.

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

end of thread, other threads:[~2023-02-17 18:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-16 18:48 [Bug tree-optimization/98334] New: Failure to optimally optimize add loop to mul gabravier at gmail dot com
2020-12-17 10:04 ` [Bug tree-optimization/98334] " jakub at gcc dot gnu.org
2020-12-17 10:59 ` [Bug rtl-optimization/98334] " jakub at gcc dot gnu.org
2021-01-04 15:36 ` rguenth at gcc dot gnu.org
2021-01-05  9:59 ` cvs-commit at gcc dot gnu.org
2021-01-05 10:01 ` jakub at gcc dot gnu.org
2022-05-27 20:34 ` roger at nextmovesoftware dot com
2023-02-17 18:35 ` 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).