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

* [Bug middle-end/112664] missed-optimization: extra comparison when reordering statements
  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 ` pinskia at gcc dot gnu.org
  2023-11-22  0:31 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-22  0:30 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|                            |missed-optimization

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

* [Bug middle-end/112664] missed-optimization: extra comparison when reordering statements
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-22  0:31 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup.

*** This bug has been marked as a duplicate of bug 105496 ***

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

* [Bug middle-end/112664] missed-optimization: extra comparison when reordering statements
  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
  4 siblings, 0 replies; 6+ messages in thread
From: goon.pri.low at gmail dot com @ 2023-11-22  0:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from gooncreeper <goon.pri.low at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> Dup.
> 
> *** This bug has been marked as a duplicate of bug 105496 ***

Apologies.
Though, how are you so good at finding duplicates? What's the secret?

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

* [Bug middle-end/112664] missed-optimization: extra comparison when reordering statements
  2023-11-22  0:27 [Bug middle-end/112664] New: missed-optimization: extra comparison when reordering statements goon.pri.low at gmail dot com
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-22  0:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to gooncreeper from comment #2)
> Though, how are you so good at finding duplicates? What's the secret?

Everyone says I have bugzilla memorized but I don't, I am just really code at
doing keyword searches and knowing what keywords to search for. In this case I
searched for "canonical compare" because I knew this was a canonicalization
issue with how GCC changed `v < 6` into `v <= 5`

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

* [Bug middle-end/112664] missed-optimization: extra comparison when reordering statements
  2023-11-22  0:27 [Bug middle-end/112664] New: missed-optimization: extra comparison when reordering statements goon.pri.low at gmail dot com
                   ` (3 preceding siblings ...)
  2023-11-22  0:41 ` pinskia at gcc dot gnu.org
@ 2023-11-22  0:56 ` goon.pri.low at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: goon.pri.low at gmail dot com @ 2023-11-22  0:56 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from gooncreeper <goon.pri.low at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> Dup.
> 
> *** This bug has been marked as a duplicate of bug 105496 ***

Apologies.
Though, how are you so good at finding duplicates? What's the secret?(In reply
to Andrew Pinski from comment #3)
> (In reply to gooncreeper from comment #2)
> > Though, how are you so good at finding duplicates? What's the secret?
> 
> Everyone says I have bugzilla memorized but I don't, I am just really code
> at doing keyword searches and knowing what keywords to search for. In this
> case I searched for "canonical compare" because I knew this was a
> canonicalization issue with how GCC changed `v < 6` into `v <= 5`

Ah, if I knew the fancy names of optimizations I would probably be a bit better
at checking my finds.

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