<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 usub.sat(a, b) + b"
   href="https://bugs.llvm.org/show_bug.cgi?id=42178">42178</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed canonicalization for usub.sat(a, b) + b
          </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>david.bolvansky@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>#define T unsigned

T do_shift(T a, T b)
    {
    return a - ((a - b) & - (T)(a < b));
}

Current trunk:
do_shift:                               # @do_shift
        xor     eax, eax
        sub     esi, edi
        cmovae  eax, esi
        add     eax, edi
        ret

Clang 8:
do_shift:                               # @do_shift
        mov     eax, edi
        cmp     esi, edi
        cmova   eax, esi
        ret

define dso_local i32 @do_shift(i32, i32) local_unnamed_addr #0 {
  %3 = tail call i32 @llvm.usub.sat.i32(i32 %1, i32 %0)
  %4 = add i32 %3, %0
  ret i32 %4
}

As noted by nikic: "Looks like an instcombine fail: usub.sat(a, b) + b should
be canonicalized to umax(a, b)."</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>