<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 - Improve codegen for std::midpoint"
   href="https://bugs.llvm.org/show_bug.cgi?id=43658">43658</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Improve codegen for std::midpoint
          </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>Backend: X86
          </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>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When one argument is a known constant value, gcc produces better code.

int foo(int a) {
    return std::midpoint(a,100);
}

Clang trunk -O3

foo(int):                                # @foo(int)
        cmp     edi, 100
        mov     ecx, 100
        mov     eax, edi
        cmovg   eax, ecx
        cmp     edi, 99
        cmovg   ecx, edi
        sub     ecx, eax
        shr     ecx
        mov     eax, ecx
        neg     eax
        cmp     edi, 100
        cmovle  eax, ecx
        add     eax, edi
        ret

Block RThroughput: 2.7

GCC -O3
foo(int):
        mov     edx, 100
        cmp     edi, 101
        mov     eax, edx
        cmovl   edx, edi
        setl    cl
        cmovge  eax, edi
        movzx   ecx, cl
        lea     ecx, [rcx-1+rcx]
        sub     eax, edx
        shr     eax
        imul    eax, ecx
        add     eax, edi
        ret

Block RThroughput: 2.5

<a href="https://godbolt.org/z/F6PE2w">https://godbolt.org/z/F6PE2w</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>