<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 --- - APFloat::fusedMultiplyAdd is broken, leading to incorrect constant folding for libc fmal calls."
   href="http://llvm.org/bugs/show_bug.cgi?id=20728">20728</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>APFloat::fusedMultiplyAdd is broken, leading to incorrect constant folding for libc fmal calls.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>All
          </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>Support Libraries
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>lhames@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>APFloat::multiplySignificand generates incorrect results when called with
Addend != 0 (i.e. from APFloat::fusedMultiplyAdd). This results in incorrect
results from libc fmal calls with constant arguments. I have tested this X86,
but I believe it will hit any architecture that uses APFloat to handle long
double constants.

The output is only incorrect for some constants.
E.g. fmal(3.0L, 4.0L, 5.0L) == 1.0 instead of 17.0L.
However fmal(-3.0L, 4.0L, 5.0L) == -7.0L as expected.

Compiling the following program with 'clang -O3 -o foo foo.c' on X86
demonstrates the bug:

#include <math.h>
#include <stdio.h>

int main(void) {
  printf("%Lf\n", fmal(3.0L, 4.0L, 5.0L));
  return 0;
}

The misbehavior for the specific constants above was introduced by r181715. The
commit message for that revision was: "Fix a bug that
APFloat::fusedMultiplyAdd() mistakenly evaluate "14.5f * -14.5f + 225.0f" to
225.0f.". I have confirmed that rolling back to r181714 causes "fmal(3.0L,
4.0L, 5.0L)" to generate correct results, but breaks "14.5f * -14.5f + 225.0f".</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>