[LLVMbugs] [Bug 20728] New: APFloat::fusedMultiplyAdd is broken, leading to incorrect constant folding for libc fmal calls.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Aug 21 11:42:57 PDT 2014


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

            Bug ID: 20728
           Summary: APFloat::fusedMultiplyAdd is broken, leading to
                    incorrect constant folding for libc fmal calls.
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Support Libraries
          Assignee: unassignedbugs at nondot.org
          Reporter: lhames at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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".

-- 
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/20140821/8dbadd77/attachment.html>


More information about the llvm-bugs mailing list