public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/112659] New: missed-optimization: if (exp) return exp; else return 0;
@ 2023-11-21 21:56 goon.pri.low at gmail dot com
  2023-11-21 22:05 ` [Bug tree-optimization/112659] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: goon.pri.low at gmail dot com @ 2023-11-21 21:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112659
           Summary: missed-optimization: if (exp) return exp; else return
                    0;
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: goon.pri.low at gmail dot com
  Target Milestone: ---

This code here:

int unopt(int v) {
    if (v + 8)
        return v + 8;
    else
        return 0;
}

unopt:
        xor     edx, edx
        lea     eax, [rdi+8]
        cmp     edi, -8
        cmove   eax, edx
        ret

Could be optimized to:

int opt(int v) {
    return v + 8;
}

opt:
        lea     eax, [rdi+8]
        ret

Note: this happens for all operators, not just addition!
Also, have any suggestions for a better bug name? I am better at spotting
optimizations, not naming them.

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

end of thread, other threads:[~2024-05-09 18:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-21 21:56 [Bug tree-optimization/112659] New: missed-optimization: if (exp) return exp; else return 0; goon.pri.low at gmail dot com
2023-11-21 22:05 ` [Bug tree-optimization/112659] " pinskia at gcc dot gnu.org
2023-11-21 22:14 ` pinskia at gcc dot gnu.org
2023-11-21 22:16 ` pinskia at gcc dot gnu.org
2023-11-21 22:19 ` goon.pri.low at gmail dot com
2023-11-21 22:29 ` pinskia at gcc dot gnu.org
2024-05-08  7:43 ` pinskia at gcc dot gnu.org
2024-05-08  7:47 ` pinskia at gcc dot gnu.org
2024-05-08 23:35 ` pinskia at gcc dot gnu.org
2024-05-09 18:11 ` 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).