[llvm-bugs] [Bug 35026] New: Optimization of float min/max

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Oct 21 15:19:53 PDT 2017


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

            Bug ID: 35026
           Summary: Optimization of float min/max
           Product: clang
           Version: 5.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kerndog73 at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

Here's some very simple code

#include <cmath>

float min0(const float a, const float b) {
    return a > b ? b : a;
}
float max0(const float a, const float b) {
    return a < b ? b : a;
}
float min1(const float a, const float b) {
    return a < b ? a : b;
}
float max1(const float a, const float b) {
    return a > b ? a : b;
}
float minStd(const float a, const float b) {
    return std::min(a, b);
}
float maxStd(const float a, const float b) {
    return std::max(a, b);
}
float minInf0(const float value) {
    return min0(value, INFINITY);
}
float maxInf0(const float value) {
    return max0(value, -INFINITY);
}
float minInf1(const float value) {
    return min1(value, INFINITY);
}
float maxInf1(const float value) {
    return max1(value, -INFINITY);
}
float minInfStd(const float value) {
    return maxStd(value, INFINITY);
}
float maxInfStd(const float value) {
    return minStd(value, -INFINITY);
}

and here's the assembly generated with -O3. I used gcc.godbolt.org to tidy it
up.

min0(float, float):                              # @min0(float, float)
        minss   xmm1, xmm0
        movaps  xmm0, xmm1
        ret
max0(float, float):                              # @max0(float, float)
        maxss   xmm1, xmm0
        movaps  xmm0, xmm1
        ret
min1(float, float):                              # @min1(float, float)
        minss   xmm0, xmm1
        ret
max1(float, float):                              # @max1(float, float)
        maxss   xmm0, xmm1
        ret
minStd(float, float):                            # @minStd(float, float)
        minss   xmm1, xmm0
        movaps  xmm0, xmm1
        ret
maxStd(float, float):                            # @maxStd(float, float)
        maxss   xmm1, xmm0
        movaps  xmm0, xmm1
        ret
minInf0(float):                            # @minInf0(float)
        ret
maxInf0(float):                            # @maxInf0(float)
        ret
.LCPI8_0:
        .long   2139095040              # float +Inf
minInf1(float):                            # @minInf1(float)
        minss   xmm0, dword ptr [rip + .LCPI8_0]
        ret
.LCPI9_0:
        .long   4286578688              # float -Inf
maxInf1(float):                            # @maxInf1(float)
        maxss   xmm0, dword ptr [rip + .LCPI9_0]
        ret
.LCPI10_0:
        .long   2139095040              # float +Inf
minInfStd(float):                          # @minInfStd(float)
        movss   xmm1, dword ptr [rip + .LCPI10_0] # xmm1 =
mem[0],zero,zero,zero
        maxss   xmm1, xmm0
        movaps  xmm0, xmm1
        ret
.LCPI11_0:
        .long   4286578688              # float -Inf
maxInfStd(float):                          # @maxInfStd(float)
        movss   xmm1, dword ptr [rip + .LCPI11_0] # xmm1 =
mem[0],zero,zero,zero
        minss   xmm1, xmm0
        movaps  xmm0, xmm1
        ret

I expected the bodies of all of the min/max functions to either be 
        minss xmm0 xmm1
        ret 
or 
        maxss xmm0 xmm1 
        ret
respectively.

I expected the bodies of the remaining functions to be
        ret
because all numbers are smaller than INFINITY and all numbers are larger than
-INFINITY.

-- 
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/20171021/8ac54633/attachment-0001.html>


More information about the llvm-bugs mailing list