public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/115202] New: [14/15 Regression] Missed optimization: std::min(f ?  (unsigned short)m : a, ~0)
@ 2024-05-23  7:44 652023330028 at smail dot nju.edu.cn
  2024-05-23  9:02 ` [Bug tree-optimization/115202] " rguenth at gcc dot gnu.org
  2024-05-23 12:18 ` [Bug tree-optimization/115202] [11/12/13/14/15 " pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-05-23  7:44 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115202
           Summary: [14/15 Regression] Missed optimization: std::min(f ?
                    (unsigned short)m : a, ~0)
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 652023330028 at smail dot nju.edu.cn
  Target Milestone: ---

Hello, we noticed that the code below can be optimized to be independent of
'm', but gcc -O3 seems to have missed it.

https://godbolt.org/z/a6MoofoYK

unsigned short m;
#include <algorithm>
unsigned short func(int a, int f) {
    return std::min(f ? m : a, ~0);
}

GCC-trunk -O3:
func(int, int):
        movzx   eax, WORD PTR m[rip]
        test    esi, esi
        mov     edx, -1
        cmove   eax, edi
        test    eax, eax
        cmovns  eax, edx
        ret


Expected code (gcc-13.2):
func(int, int):
        mov     eax, edi
        test    edi, edi
        jns     .L4
        test    esi, esi
        jne     .L4
        ret
.L4:
        mov     eax, 65535
        ret

If we did it correctly, it's caused by
https://github.com/gcc-mirror/gcc/commit/7b34cacc5735385e7e2855d7c0a6fad60ef4a99b

Thank you very much for your time and effort! We look forward to hearing from
you.

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-23  7:44 [Bug tree-optimization/115202] New: [14/15 Regression] Missed optimization: std::min(f ? (unsigned short)m : a, ~0) 652023330028 at smail dot nju.edu.cn
2024-05-23  9:02 ` [Bug tree-optimization/115202] " rguenth at gcc dot gnu.org
2024-05-23 12:18 ` [Bug tree-optimization/115202] [11/12/13/14/15 " 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).