<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [x86-64] Suboptimal codegen for (!x) as opposed to (0 == x)"
   href="https://bugs.llvm.org/show_bug.cgi?id=39968">39968</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[x86-64] Suboptimal codegen for (!x) as opposed to (0 == x)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>arthur.j.odwyer@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre><a href="https://godbolt.org/z/Z2afe8">https://godbolt.org/z/Z2afe8</a>

    #include <stdint.h>
    struct u128 { uint64_t x, y; };

    u128 shl2(uint64_t rdi, uint64_t rdx, int n)
    {
        if (n & 64) rdx = rdi;
    #if WORSE
        if (!(n & 64)) rdi = 0;
    #else
        if (0 == (n & 64)) rdi = 0;
    #endif
        return {rdi,rdx};
    }

Without -DWORSE, Clang generates perfect codegen.

    andl $64, %edx
    xorl %eax, %eax
    cmovneq %rdi, %rsi
    cmovneq %rdi, %rax
    movq %rsi, %rdx
    retq

But with -DWORSE, Clang generates a dead-store "shr" instruction:

    andl $64, %edx
    xorl %eax, %eax
    shrl $6, %edx      // USELESS INSTRUCTION!
    cmovneq %rdi, %rsi
    cmovneq %rdi, %rax
    movq %rsi, %rdx
    retq

This is surprising, given that the only difference is using (0 == x) versus
(!x). I would expect these to have equivalent codegen.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>