public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/112664] New: missed-optimization: extra comparison when reordering statements
@ 2023-11-22  0:27 goon.pri.low at gmail dot com
  2023-11-22  0:30 ` [Bug middle-end/112664] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: goon.pri.low at gmail dot com @ 2023-11-22  0:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112664
           Summary: missed-optimization: extra comparison when reordering
                    statements
           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: ---

These two functions which you would expect to be essentially equivalent, has
the first one with an extra comparison.

int unopt(int v) {
    if (v < 6) {
        return 15;
    }

    if (v > 6) {
        return 3;
    }

    return 9;
}

unopt:
        mov     eax, 15
        cmp     edi, 5
        jle     .L1
        cmp     edi, 6
        mov     eax, 3
        mov     edx, 9
        cmove   eax, edx
.L1:
        ret

The second one it reuses the old comparison.

int opt(int v) {
    if (v > 6) {
        return 3;
    }

    if (v < 6) {
        return 15;
    }

    return 9;
}

opt:
        mov     eax, 3
        cmp     edi, 6
        jg      .L6
        mov     eax, 15
        mov     edx, 9
        cmove   eax, edx
.L6:
        ret

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-22  0:27 [Bug middle-end/112664] New: missed-optimization: extra comparison when reordering statements goon.pri.low at gmail dot com
2023-11-22  0:30 ` [Bug middle-end/112664] " pinskia at gcc dot gnu.org
2023-11-22  0:31 ` pinskia at gcc dot gnu.org
2023-11-22  0:35 ` goon.pri.low at gmail dot com
2023-11-22  0:41 ` pinskia at gcc dot gnu.org
2023-11-22  0:56 ` 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).