public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/105338] New: Regression: jump or cmove generated for pattern (x ? CST : 0)
@ 2022-04-21 17:47 denis.campredon at gmail dot com
  2022-04-22  6:13 ` [Bug rtl-optimization/105338] [12 Regression] " rguenth at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: denis.campredon at gmail dot com @ 2022-04-21 17:47 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105338
           Summary: Regression: jump or cmove generated for pattern (x ?
                    CST : 0)
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: denis.campredon at gmail dot com
  Target Milestone: ---

int f(int i) {
    return i ? 5 : 0;
}

int g(int i) {
    return i ? -2 : 0;
}

int h(int b) {
    return !!b * -2;
}

int i(int b) {
    return !!b * 5;
}

int j(int b) {
    if (!b) return 0;
    return -2;
}
-------------
With -02 gcc 11.2 the five functions above output branchless code like:

f(int):
        neg     edi
        sbb     eax, eax
        and     eax, 5
        ret
g(int):
        neg     edi
        sbb     eax, eax
        and     eax, -2
        ret
...
--------------

Whereas -02 gcc 12 now outputs a cmov or jump depending of sign of the
constant:
f(int):
        mov     eax, edi
        test    edi, edi
        mov     edx, 5
        cmovne  eax, edx
        ret

g(int):
        mov     eax, edi
        test    edi, edi
        jne     .L11
        ret
.L11:
        mov     eax, -2
        ret

h(int):
        mov     eax, edi
        test    edi, edi
        jne     .L17
        ret
.L17:
        mov     eax, -2
        ret

i(int):
        mov     eax, edi
        test    edi, edi
        mov     edx, 5
        cmovne  eax, edx
        ret

j(int):
        mov     eax, edi
        test    edi, edi
        mov     edx, -2
        cmovne  eax, edx
        ret
---------------------------

Alternatively, with the following code

int k(int b) {
    bool b2 = b;
    return b2 * 5;
}
----------------

Both gcc 12 and 11.2 are outputing
k(int):
        xor     eax, eax
        test    edi, edi
        setne   al
        lea     eax, [rax+rax*4]
        ret

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

end of thread, other threads:[~2022-04-26  8:21 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-21 17:47 [Bug rtl-optimization/105338] New: Regression: jump or cmove generated for pattern (x ? CST : 0) denis.campredon at gmail dot com
2022-04-22  6:13 ` [Bug rtl-optimization/105338] [12 Regression] " rguenth at gcc dot gnu.org
2022-04-22  9:17 ` jakub at gcc dot gnu.org
2022-04-22  9:48 ` pinskia at gcc dot gnu.org
2022-04-22 11:00 ` jakub at gcc dot gnu.org
2022-04-22 11:11 ` rguenth at gcc dot gnu.org
2022-04-22 11:14 ` rguenth at gcc dot gnu.org
2022-04-22 11:20 ` rguenth at gcc dot gnu.org
2022-04-22 12:28 ` jakub at gcc dot gnu.org
2022-04-22 13:59 ` jakub at gcc dot gnu.org
2022-04-22 14:11 ` jakub at gcc dot gnu.org
2022-04-22 14:24 ` [Bug target/105338] " jakub at gcc dot gnu.org
2022-04-23  8:26 ` cvs-commit at gcc dot gnu.org
2022-04-25 14:48 ` jakub at gcc dot gnu.org
2022-04-26  5:05 ` denis.campredon at gmail dot com
2022-04-26  8:21 ` jakub 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).