<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - InstCombine: fadd (fsub nnan ninf 0.0, X), X => 0 incorrect for X = NaN"
href="https://llvm.org/bugs/show_bug.cgi?id=26958">26958</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>InstCombine: fadd (fsub nnan ninf 0.0, X), X => 0 incorrect for X = NaN
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</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>Global Analyses
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>andres.noetzli@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>InstCombine optimizes the following program:
$ cat ../example.ll
define float @test(float %x) {
%a = fsub nnan ninf float 0.0, %x
%r = fadd float %a, %x
ret float %r
}
To the constant 0.0:
$ bin/opt < ../example.ll -instcombine -S
; ModuleID = '<stdin>'
define float @test(float %x) {
ret float 0.000000e+00
}
This does not seem to be correct, however, because the language reference
states that:
"nnan: No NaNs - Allow optimizations to assume the arguments and result are not
NaN. Such optimizations are required to retain defined behavior over NaNs, but
the value of the result is undefined." [0]
Using this rule we can construct a counterexample. Let "%x = NaN", then "%a =
undef" and "%r = fadd undef, NaN", so we cannot get 0.0 for %r because no
matter what we choose for undef, we always end up with %r being NaN.
This behavior is implemented in SimplifyFAddInst() in InstructionSimplify. The
optimization just checks whether nnan and ninf appear at least once somewhere
on the fadd and the fsub instruction but as the example above indicates, this
condition seems too weak.
[0] <a href="http://llvm.org/docs/LangRef.html#fast-math-flags">http://llvm.org/docs/LangRef.html#fast-math-flags</a></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>