public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/114547] New: missed-optimization: use sign flag
@ 2024-04-01 16:24 goon.pri.low at gmail dot com
  2024-04-01 16:25 ` [Bug middle-end/114547] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: goon.pri.low at gmail dot com @ 2024-04-01 16:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114547
           Summary: missed-optimization: use sign flag
           Product: gcc
           Version: 14.0
            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: ---

Example functions

int s(int *v, int n) {
        *v -= n;
        return *v < 0;
}

int ns(int *v, int n) {
        *v -= n;
        return *v >= 0;
}

Generated assembly

s:
        mov     eax, DWORD PTR [rdi]
        sub     eax, esi
        mov     DWORD PTR [rdi], eax
        shr     eax, 31
        ret
ns:
        mov     eax, DWORD PTR [rdi]
        sub     eax, esi
        mov     DWORD PTR [rdi], eax
        not     eax
        shr     eax, 31
        ret

Optimal assembly

s:
        xor     eax, eax
        sub     DWORD PTR [rdi], esi
        sets    al
        ret
ns:
        xor     eax, eax
        sub     DWORD PTR [rdi], esi
        setns   al
        ret

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

end of thread, other threads:[~2024-04-02 18:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-01 16:24 [Bug middle-end/114547] New: missed-optimization: use sign flag goon.pri.low at gmail dot com
2024-04-01 16:25 ` [Bug middle-end/114547] " pinskia at gcc dot gnu.org
2024-04-01 16:32 ` [Bug middle-end/114547] comparison than less than 0 (or greater or equal to than 0) after a subtraction does not use the flags regster pinskia at gcc dot gnu.org
2024-04-01 16:43 ` goon.pri.low at gmail dot com
2024-04-02 18:38 ` ubizjak 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).