public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/97968] New: Unnecessary mov instruction with comparison and cmov
@ 2020-11-24 15:19 denis.campredon at gmail dot com
  2021-09-01  7:50 ` [Bug middle-end/97968] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: denis.campredon at gmail dot com @ 2020-11-24 15:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97968
           Summary: Unnecessary mov instruction with comparison and cmov
           Product: gcc
           Version: 11.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: ---

The same problem applies with all comparison operators but '==' for 'int' and
'long'  on x86-64.

(Returning a negative value instead of 0 makes the compiler generate a jump
instead of a cmov. I don't know if it's worth a bug)

-------------------
int f(int n, int j)
{
    return n > j ? n : 0;
}
-------------------


with O2 produces


-------------------
f(int, int):
        mov     eax, edi
        cmp     edi, esi
        mov     edx, 0
        cmovle  eax, edx
        ret
-------------------

Ideally it should produce something like that. (the first mov can be deleted
with some little changes later)

-----------------------
f(int, int):
        mov     eax, 0
        cmp     edi, esi
        cmovg   eax, edi
        ret
-----------------------

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

end of thread, other threads:[~2024-03-10 23:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-24 15:19 [Bug rtl-optimization/97968] New: Unnecessary mov instruction with comparison and cmov denis.campredon at gmail dot com
2021-09-01  7:50 ` [Bug middle-end/97968] [9/10/11/12 Regression] " pinskia at gcc dot gnu.org
2021-09-19 23:15 ` pinskia at gcc dot gnu.org
2021-09-19 23:16 ` pinskia at gcc dot gnu.org
2022-01-21 13:25 ` rguenth at gcc dot gnu.org
2022-01-21 15:20 ` denis.campredon at gmail dot com
2022-05-27  9:43 ` [Bug middle-end/97968] [10/11/12/13 " rguenth at gcc dot gnu.org
2022-06-28 10:42 ` jakub at gcc dot gnu.org
2023-07-07 10:38 ` [Bug middle-end/97968] [11/12/13/14 " rguenth at gcc dot gnu.org
2023-07-13 21:12 ` pinskia at gcc dot gnu.org
2024-03-10 23:11 ` [Bug middle-end/97968] [11 " law 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).