[llvm-bugs] [Bug 39898] New: Missed min max optimization

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Dec 5 14:19:31 PST 2018


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

            Bug ID: 39898
           Summary: Missed min max optimization
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

int minmax(int num) {
    int t = std::max(15, num);
    return std::min(1, t);
}

Current codegen -O3, x86-64:
minmax(int):                             # @minmax(int)
        cmp     edi, 14
        mov     ecx, 15
        cmovg   ecx, edi
        cmp     ecx, 2
        mov     eax, 1
        cmovl   eax, ecx
        ret

We can fold it to 1 (GCC does it).

-- 
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/20181205/f0bd3a5f/attachment.html>


More information about the llvm-bugs mailing list