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 via email to