[llvm-bugs] [Bug 40280] New: FP exception on optimized code
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Jan 10 02:22:49 PST 2019
https://bugs.llvm.org/show_bug.cgi?id=40280
Bug ID: 40280
Summary: FP exception on optimized code
Product: clang
Version: 6.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: LLVM Codegen
Assignee: unassignedclangbugs at nondot.org
Reporter: graeser at mi.fu-berlin.de
CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
richard-llvm at metafoo.co.uk
Created attachment 21310
--> https://bugs.llvm.org/attachment.cgi?id=21310&action=edit
Minimal example
The following code snippet should never divide by zero. However, if compiled
with '-O3' it leads to a floating point exception when called using a certain
pattern.
See attachment for a minimal example.
for (int i=0; i<=3; i++)can be expected. It seems that clang
for (int j=0; j<=3; j++)
for (int k=0; k<=3; k++)
if ((m!=i) && (m!=j) && (m!=k))
z += x*(1.0/(m-k))*(1.0/(m-j))*(1.0/(m-i));
If the trapping of FP errors is not enabled, the correct result is computed. So
it seems that clang generates operations for the ruled out cases. Notice that
the order of the factors in the arithmetic expression as well as the way the
function containing this code is called does matter.
It seems that clang implicitly makes the assumption that user code does not
track FP errors on '-O3'. Gcc only makes this assumption if we explicitly allow
this using '-O3 -fno-trapping-math' where the same behaviour is observed (but
expected).
The problem shows up on a 64bit ubuntu 18.04 with clang-5.0.1 and clang-6.0.0
but not with clang-4.0.0.
Bug 11356 and bug 26969 look related but are either marked fixed or have been
filed against an old clang-3.7 while this one does not show up before
clang-5.0.
--
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/20190110/c94221b6/attachment.html>
More information about the llvm-bugs
mailing list