<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 - Missed canonicalization for bit mask calculation"
   href="https://bugs.llvm.org/show_bug.cgi?id=37603">37603</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed canonicalization for bit mask calculation
          </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><a href="https://godbolt.org/g/VCMNpS">https://godbolt.org/g/VCMNpS</a>
<a href="https://rise4fun.com/Alive/idM">https://rise4fun.com/Alive/idM</a>

int mask_signed_add(int nbits) {
    return (1 << nbits) - 1;
}
unsigned mask_unsigned_add(unsigned nbits) {
    return (1 << nbits) - 1;
}
int mask_signed_xor(int nbits) {
    return ~(-(1 << nbits));
}
unsigned mask_unsigned_xor(unsigned nbits) {
    return ~(-(1 << nbits));
}

define dso_local i32 @mask_signed_add(int)(i32) local_unnamed_addr #0 {
  %2 = shl i32 1, %0
  %3 = add nsw i32 %2, -1
  ret i32 %3
}
define dso_local i32 @mask_unsigned_add(unsigned int)(i32) local_unnamed_addr
#0 {
  %2 = shl i32 1, %0
  %3 = add nsw i32 %2, -1
  ret i32 %3
}
define dso_local i32 @mask_signed_xor(int)(i32) local_unnamed_addr #0 {
  %2 = shl i32 -1, %0
  %3 = xor i32 %2, -1
  ret i32 %3
}
define dso_local i32 @mask_unsigned_xor(unsigned int)(i32) local_unnamed_addr
#0 {
  %2 = shl i32 -1, %0
  %3 = xor i32 %2, -1
  ret i32 %3
}

I think we really would prefer the second variant with `xor`,
because if we calculated mask, it is quite likely that
we will use it in `and` next, and then it can be fused into `andn`..

Thoughs?</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>