<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: (float) x + (float) y -> (float) (x + y) incorrect"
href="https://llvm.org/bugs/show_bug.cgi?id=27036">27036</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>InstCombine: (float) x + (float) y -> (float) (x + y) incorrect
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</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>Scalar Optimizations
</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>InstCombiner::visitFAdd optimizes the following code (note: the `or` and the
`and` instruction are just to show the LLVM that no overflow occurs):
$ cat ../example.ll
define float @test(i26 %x, i26 %y) {
%xx = or i26 %x, 42074059
%yy = and i26 %y, 14942208
%t0 = sitofp i26 %xx to float
%t1 = sitofp i26 %yy to float
%rr = fadd float %t0, %t1
ret float %rr
}
define i1 @main() {
%y = call float @test(i26 42074059, i26 14942208)
%rr = fcmp oeq float 0xC163400680000000, %y
ret i1 %rr
}
To:
$ bin/opt < ../example.ll -instcombine -S > ../example2.ll && cat
../example2.ll
; ModuleID = '<stdin>'
define float @test(i26 %x, i26 %y) {
%xx = or i26 %x, -25034805
%yy = and i26 %y, 14942208
%addconv = add nsw i26 %xx, %yy
%rr = sitofp i26 %addconv to float
ret float %rr
}
define i1 @main() {
%y = call float @test(i26 -25034805, i26 14942208)
%rr = fcmp oeq float %y, 0xC163400680000000
ret i1 %rr
}
The results differ when running the optimized and the unoptimized version:
$ bin/lli -force-interpreter ../example.ll; echo $?
1
$ bin/lli -force-interpreter ../example2.ll; echo $?
0
The reason for the difference is that -25034805 cannot be accurately
represented with float but the result of the integer addition can be, so the
result of the optimized version changes.</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>