<html>
    <head>
      <base href="http://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 --- - Fused Multiply-Add (FMA) yields wrong results when inlined"
   href="http://llvm.org/bugs/show_bug.cgi?id=21492">21492</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Fused Multiply-Add (FMA) yields wrong results when inlined
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </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>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>dan.spencer.np@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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));
    }</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>