<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: lshr + "sext" => ashr canonicalization"
   href="https://bugs.llvm.org/show_bug.cgi?id=42389">42389</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>InstCombine: lshr + "sext" => ashr 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>I have not triaged yet what folds are missing, but this gigantic fold is
missing:
<a href="https://godbolt.org/z/E9-txU">https://godbolt.org/z/E9-txU</a>

int bad(unsigned input, unsigned len) {
    unsigned diff = input >> (32 - len);
    // 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) {
    return int(input) >> (32 - len);
}

<a href="https://rise4fun.com/Alive/l3k">https://rise4fun.com/Alive/l3k</a>

Name: ashr
  %o3 = sub i32 32, %nbits
  %o4 = lshr i32 %x, %o3
  %o5 = add i32 %nbits, -1
  %o6 = lshr i32 %o4, %o5
  %o7 = icmp eq i32 %o6, 0
  %o8 = shl i32 1, %nbits
  %o9 = select i1 %o7, i32 0, i32 %o8
  %r = sub i32 %o4, %o9
=>
  %n0 = sub i32 32, %nbits
  %r = ashr i32 %x, %n0

I'm seeing this in real code.</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>