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: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to