public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "denis.campredon at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/97968] New: Unnecessary mov instruction with comparison and cmov
Date: Tue, 24 Nov 2020 15:19:09 +0000	[thread overview]
Message-ID: <bug-97968-4@http.gcc.gnu.org/bugzilla/> (raw)

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
-----------------------

             reply	other threads:[~2020-11-24 15:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-24 15:19 denis.campredon at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-97968-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).