<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 - Missing optimization with (var&const)==const"
   href="https://bugs.llvm.org/show_bug.cgi?id=47797">47797</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missing optimization with (var&const)==const
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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>blubban@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>$ clang -Oz

void t();
void x(int a) { if ((a&1234) == 1234) t(); }
void y(int a) { if (!(1234&~a)) t(); }


Output (x86_64):

x(int):                                  # @x(int)
        mov     eax, 1234
        and     edi, eax
        cmp     edi, eax
        je      t()                   # TAILCALL
        ret
y(int):                                  # @y(int)
        mov     eax, 1234
        and     edi, eax
        cmp     edi, eax
        je      t()                   # TAILCALL
        ret


Expected output: `not edi; test edi,1234; je t(); ret` for both, it's one byte
smaller.

It intuitively seems faster too, since and+cmp calculates a less-than flag that
not+test doesn't, but modern x86 performance is quite unintuitive, so who
knows.

Compiler Explorer: <a href="https://godbolt.org/z/Yeofdo">https://godbolt.org/z/Yeofdo</a></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>