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

            Bug ID: 88712
           Summary: Optimization: mov edx, 0 not replaced with xor edx,
                    edx in this case
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: matt at godbolt dot org
  Target Milestone: ---

The code: 

---snip
int func(int val, const int *ptr)
{
  int res = val + 1234;
  if (res == *ptr)
  {
    res = 0;
  }
  return res;
}
---

generates the following ASM on all version of GCC back to 4.9.x:

---
func(int, int const*):
        lea     eax, [rdi+1234]
        mov     edx, 0
        cmp     DWORD PTR [rsi], eax
        cmove   eax, edx
        ret
---

The `mov edx, 0` is surprising to me. All the other compilers I tested (see
https://godbolt.org/z/Nt9pKp for more details) use the common `xor edx, edx`
(or `xor eax, eax`) idiom for zeroing edx.

Is this a missed optimization in the case of a cmov being generated, or am I
missing something subtle?

Reply via email to