[llvm-bugs] [Bug 35607] New: Missed optimization in math expression: max(min(a, b), max(a, b)) == max(a, b)

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Dec 10 08:47:16 PST 2017


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

            Bug ID: 35607
           Summary: Missed optimization in math expression:
                    max(min(a,b),max(a,b)) == max(a,b)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: zamazan4ik at tut.by
                CC: llvm-bugs at lists.llvm.org

clang(trunk) with '--std=c++17 -O3 -march=native -ffast-math' flags for this
code:

#include <algorithm>

int test(int a, int b)
{
    return std::max(std::min(a,b), std::max(a,b));
}

generates this assembly:


test(int, int): # @test(int, int)
  cmp esi, edi
  mov eax, edi
  cmovle eax, esi
  cmp edi, esi
  cmovl edi, esi
  cmp eax, edi
  cmovge edi, eax
  mov eax, edi
  ret

gcc(trunk) with '--std=c++17 -O3 -march=native -ffast-math':


test(int, int):
        cmp     edi, esi
        mov     eax, edi
        cmovl   eax, esi
        ret


Helpful link:
https://github.com/gcc-mirror/gcc/blob/07b69d3f1cd3dd8ebb0af1fbff95914daee477d2/gcc/match.pd

-- 
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/20171210/6f590b31/attachment-0001.html>


More information about the llvm-bugs mailing list