[LLVMbugs] [Bug 21492] New: Fused Multiply-Add (FMA) yields wrong results when inlined

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Nov 5 13:34:36 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=21492

            Bug ID: 21492
           Summary: Fused Multiply-Add (FMA) yields wrong results when
                    inlined
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: dan.spencer.np at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Reproducible in:

* x86-64 Ubuntu 14.04, clang++ 3.4 and 3.5.1
* x86-64 Ubuntu 14.04, Rust nightly

If the third argument to std::fma() in C++11 or Float::mul_add() in Rust is 0,
it always returns the first argument. If the third argument is != 0, it returns
the correct result. This happens for both the float and double types.
The issue occurs only when all arguments are constants and compiler
optimizations are turned on. This is why I believe this is an issue with LLVM
inlining the call.
gcc does not produce this issue.

clang++ -O2 --std=c++11 fmatest.cpp

    #include <cmath>
    #include <iostream>

    int main() {
        // prints "10"
        std::cout << std::fma(10.0f, 20.0f, 0.0f) << std::endl;

        // prints "200.001" (10*20 + 0.001)
        std::cout << std::fma(10.0f, 20.0f, 0.001f) << std::endl;
        return 0;
    }

rustc -O fmatest.rs

    fn main() {
        // prints "10"
        println!("{}", Float::mul_add(10.0f32, 20.0, 0.0));

        // prints "200.001007" (10*20 + 0.001)
        println!("{}", Float::mul_add(10.0f32, 20.0, 0.001));
    }

-- 
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/20141105/e8cde68c/attachment.html>


More information about the llvm-bugs mailing list