public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/115474] New: Missed optimization: fold `std::max(a > b, a)` to `a` (bool a, bool b)
@ 2024-06-13 10:47 zhiwuyazhe154 at gmail dot com
  2024-06-13 14:05 ` [Bug tree-optimization/115474] " pinskia at gcc dot gnu.org
  2024-06-13 14:44 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: zhiwuyazhe154 at gmail dot com @ 2024-06-13 10:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115474
           Summary: Missed optimization: fold `std::max(a > b, a)` to `a`
                    (bool a, bool b)
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhiwuyazhe154 at gmail dot com
  Target Milestone: ---

godbolt example: https://godbolt.org/z/KG1fhaPvM

Code Example:
```
int func(bool a, bool b) {
    return std::max(a > b, a); // equals to a
}
```

In this case, when a == 0, a > b == 0(a); when a == 1, a > b <= 1(a). So it can
be folded to a.

GCC -O3:
func(bool, bool):
        cmp     sil, dil
        setb    dl
        cmp     dl, dil
        setb    al
        or      eax, edx
        movzx   eax, al
        ret

Expected code(CLANG -O3):
func(bool, bool):                             
        mov     eax, edi
        ret

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

end of thread, other threads:[~2024-06-13 14:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-13 10:47 [Bug tree-optimization/115474] New: Missed optimization: fold `std::max(a > b, a)` to `a` (bool a, bool b) zhiwuyazhe154 at gmail dot com
2024-06-13 14:05 ` [Bug tree-optimization/115474] " pinskia at gcc dot gnu.org
2024-06-13 14:44 ` 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).