<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 - Different optimizations on similar code"
   href="https://bugs.llvm.org/show_bug.cgi?id=36969">36969</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Different optimizations on similar code
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>4.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>lgalfaso@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I'm seeing different optimizations for these similar methods

bool add(const unsigned long long a, const unsigned long long b, unsigned long
long* to) {
  *to = a + b;
  return a > *to;
}

bool sub(const unsigned long long a, const unsigned long long b, unsigned long
long* to) {
  *to = a - b;
  return a < *to;
}

The first is properly optimized to
pushq   %rbp
movq    %rsp, %rbp
addq    %rsi, %rdi
setb    %al
movq    %rdi, (%rdx)
popq    %rbp
retq


The second generates
pushq   %rbp
movq    %rsp, %rbp
movq    %rdi, %rax
subq    %rsi, %rax
movq    %rax, (%rdx)
cmpq    %rdi, %rax
seta    %al
popq    %rbp
retq


Instead of following the same optimization as in the first case and generating
pushq   %rbp
movq    %rsp, %rbp
subq    %rsi, %rdi
setb    %al
movq    %rdi, (%rdx)
popq    %rbp
retq</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>