<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 - xor %a, C -> xor %a, -1 canonicalization"
   href="https://bugs.llvm.org/show_bug.cgi?id=37610">37610</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>xor %a, C -> xor %a, -1 canonicalization
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </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>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>lebedev.ri@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Clang sometimes generates from

#include <cstdint>
uint8_t and_0(uint32_t cache, uint8_t count) {
  return uint8_t(cache) & uint8_t((uint8_t(1) << uint8_t(count)) - uint8_t(1));
}

this

define dso_local zeroext i8 @and_0(unsigned int, unsigned char)(i32, i8
zeroext) local_unnamed_addr #0 {
  %3 = zext i8 %1 to i32
  %4 = shl i32 1, %3
  %5 = add i32 %4, 255
  %6 = and i32 %5, %0
  %7 = trunc i32 %6 to i8
  ret i8 %7
}

Because the constant is not -1, the final code is suboptimal

<a href="https://godbolt.org/g/DeY8sr">https://godbolt.org/g/DeY8sr</a>

Should we canonicalize it somehow?
<a href="https://rise4fun.com/Alive/sEB">https://rise4fun.com/Alive/sEB</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>