<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 - [InstCombine] and-mask + conditional "sext" -> and-mask + sext"
   href="https://bugs.llvm.org/show_bug.cgi?id=42412">42412</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[InstCombine] and-mask + conditional "sext" -> and-mask + sext
          </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>There's also identical problem to <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - InstCombine: lshr + "sext" => ashr canonicalization"
   href="show_bug.cgi?id=42389">https://bugs.llvm.org/show_bug.cgi?id=42389</a>
with different bit buffer abstraction:
<a href="https://godbolt.org/z/po3_0Y">https://godbolt.org/z/po3_0Y</a>
<a href="https://rise4fun.com/Alive/btQ">https://rise4fun.com/Alive/btQ</a>

int bad(unsigned input, unsigned len) {
    unsigned diff = input & ((1 << len)-1);
    // If the first bit is 1 we need to turn this into a negative number
    if (diff >> (len - 1))
        diff -= (1 << len);
    return diff;
}
int good(unsigned input, unsigned len) {
    unsigned diff = input & ((1 << len)-1);
    diff <<= (32-len);
    diff = int(diff) >> (32-len);
    return diff;
}

Name: 
  %o3 = shl i32 1, %len
  %o4 = add nsw i32 %o3, -1
  %o5 = and i32 %o4, %data
  %o6 = add i32 %len, -1
  %o7 = lshr i32 %o5, %o6
  %o8 = icmp eq i32 %o7, 0
  %o9 = select i1 %o8, i32 0, i32 %o3
  %r = sub i32 %o5, %o9
=>
  %n3 = shl nsw i32 -1, %len
  %n4 = xor i32 %n3, -1
  %n5 = and i32 %n4, %data
  %n6 = sub i32 32, %len
  %n7 = shl i32 %n5, %n6
  %r = ashr i32 %n7, %n6

Did not analyse this one yet.</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>