[llvm-bugs] [Bug 27036] New: InstCombine: (float) x + (float) y -> (float) (x + y) incorrect
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Mar 22 17:10:50 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=27036
Bug ID: 27036
Summary: InstCombine: (float) x + (float) y -> (float) (x + y)
incorrect
Product: libraries
Version: trunk
Hardware: Macintosh
OS: MacOS X
Status: NEW
Severity: normal
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: andres.noetzli at gmail.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
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.
--
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/20160323/936b8f45/attachment.html>
More information about the llvm-bugs
mailing list