public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/112662] New: missed-optimization: loop increment until wrap
@ 2023-11-21 23:10 goon.pri.low at gmail dot com
  2023-11-21 23:23 ` [Bug middle-end/112662] " pinskia at gcc dot gnu.org
  2023-12-30 16:21 ` goon.pri.low at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: goon.pri.low at gmail dot com @ 2023-11-21 23:10 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112662
           Summary: missed-optimization: loop increment until wrap
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: goon.pri.low at gmail dot com
  Target Milestone: ---

This function:

unsigned unopt(unsigned a) {
    while (++a > 999);
    return a;
}

unopt:
        lea     eax, [rdi+1]
        xor     edx, edx
        not     edi
        cmp     eax, 999
        cmovbe  edi, edx
        add     eax, edi
        ret

Can be optimized to:

unsigned opt(unsigned a) {
    if (++a > 999) return a;
    return 0;
}

opt:
        lea     eax, [rdi+1]
        xor     edx, edx
        cmp     eax, 999
        cmovbe  eax, edx
        ret

(saving two valuable instructions)

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

end of thread, other threads:[~2023-12-30 16:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-21 23:10 [Bug middle-end/112662] New: missed-optimization: loop increment until wrap goon.pri.low at gmail dot com
2023-11-21 23:23 ` [Bug middle-end/112662] " pinskia at gcc dot gnu.org
2023-12-30 16:21 ` goon.pri.low at gmail dot com

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