<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/111728>111728</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Missed optimization: xor eax, eax is unnecessary on x86-64
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          AreaZR
      </td>
    </tr>
</table>

<pre>
    define i64 @tgt2(i64 %3) {
entry: 
  %4 = icmp eq i64 %3, 0
  %5 = sext i1 %4 to i64
  ret i64 %5
}

compiles to:

tgt2:                                   # @tgt2
        xor     eax, eax
        cmp     rdi, 1
        sbb rax, rax
        ret
 
 For x86-64.
 
 This has a completely unnecessary xor eax, eax at the start
 
 I assume the function is simply -!arg there
 
 https://godbolt.org/z/zaPY53YT1
 
 The sbb rax, rax renders it so.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEU8GOmzAQ_RpzGSUytgnkwCHbCKmHSlW1l-3N4NngyuDUY7bJfn1lwjYbLh0JBvvNY97M2JrInkbEmhVPrDhmeoq9D_UhoP75I2u9udYGX-2IYHcKmOLxFAUT1bwShWRiD6x8YvzI-AHHGK5MHuC2hBShgMkj2G44A_6GO-0L8E9RxRxFeIlg8xst-hT9ERMwfpCL2x4rj8vH_O78cLYOCaJn8vAZmRXLA_zfmJD_Slzy3uziw-xRX5Ly5B7wVF2yYGzC80eU2hbCjRnWzIBx2Vhc4wNcqt1mp7aPwHNvCXpNoCHV6jCiu8I0jtghkQ7XWeVdIegIsUegqMMqx1fQRNOAM_46jV20fgRLQHY4uytsmMh1OCU44CO1j_FMqcGiYaI5edN6F7c-nJho3tOjv78U8uU5X4vHVRsg4GgwENgI5LeZqaXZy73OsM5LUal9sZc862vFdwZluUPRSsllKdvStFIVUrVam7zKbC24UDnn-7xUheTbrjK66lRVVoUx6rVliuOgrds69zYkqZklmrDO85Qoc7pFR_P5F2LEPzCjTIh0HUKdSJt2OhFT3FmKdP9NtNFh_c0SoQF_jnaw7zq1Mp221TAsPYzKj8uQsym4etVUG_up3XZ-YKJJyRa3OQf_C7vIRDNLJCaapYa3WvwNAAD__7wwEzw">