<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 - Optimization of float min/max"
href="https://bugs.llvm.org/show_bug.cgi?id=35026">35026</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Optimization of float min/max
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>5.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>kerndog73@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>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.</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>