<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 optimizations for comparison with multiplications"
   href="https://bugs.llvm.org/show_bug.cgi?id=38264">38264</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed optimizations for comparison with multiplications
          </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>Hello,

int f2(int x, int y, int z) {
    int tmp = y--;
    if (tmp * x > x * y)
        return 1;
    return 0;
}

Current codegen:
f2(int, int, int): # @f2(int, int, int)
  lea ecx, [rsi - 1]
  imul esi, edi
  imul ecx, edi
  xor eax, eax
  cmp esi, ecx
  setg al
  ret

GCC:
f2(int, int, int):
  xor eax, eax
  test edi, edi
  setg al
  ret



/////////////////////
int f2(int x, int y, int z) {
    if ((y-1) * x > x * y)
        return 1;
    return 0;
}

f2(int, int, int): # @f2(int, int, int)
  lea ecx, [rsi - 1]
  imul ecx, edi
  imul esi, edi
  xor eax, eax
  cmp ecx, esi
  setg al
  ret

GCC:
f2(int, int, int):
  mov eax, edi
  shr eax, 31
  ret


For unsigned case - Clang:
f2(unsigned int, unsigned int, unsigned int): # @f2(unsigned int, unsigned int,
unsigned int)
  lea ecx, [rsi - 1]
  imul ecx, edi
  imul esi, edi
  xor eax, eax
  cmp ecx, esi
  seta al
  ret

GCC (one multiplication is eliminated):
f2(unsigned int, unsigned int, unsigned int):
  sub esi, 1
  xor eax, eax
  imul esi, edi
  add esi, edi
  setc al
  ret</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>