[llvm-bugs] [Bug 36969] New: Different optimizations on similar code

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Mar 31 12:13:08 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=36969

            Bug ID: 36969
           Summary: Different optimizations on similar code
           Product: new-bugs
           Version: 4.0
          Hardware: PC
                OS: MacOS X
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: lgalfaso at gmail.com
                CC: llvm-bugs at lists.llvm.org

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180331/43308ec6/attachment.html>


More information about the llvm-bugs mailing list