[llvm-bugs] [Bug 44330] New: accuracy error by optimization of pow(x, -0.5) when -ffast-math is disabled
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Dec 18 00:08:44 PST 2019
https://bugs.llvm.org/show_bug.cgi?id=44330
Bug ID: 44330
Summary: accuracy error by optimization of pow(x, -0.5) when
-ffast-math is disabled
Product: libraries
Version: 9.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Transformation Utilities
Assignee: unassignedbugs at nondot.org
Reporter: utsumi.yuichiro at fujitsu.com
CC: llvm-bugs at lists.llvm.org
The following code causes accuracy error even when -ffast-math is disabled.
--------------- pow.c --------------------------
#include <math.h>
#include <stdio.h>
double (*libpow)(double, double) = pow;
double x = 1000000001.0;
int main() {
double a = libpow(x, -0.5); // not optimized
double b = pow(x, -0.5); // optimized
printf("lib pow: %.20g, pow: %.20g\n", a, b);
return 0;
}
--------------------------------------------------
This code includes `pow(x, -0.5)`.
The following is the result.
-------------------------------------------------------------------
$ clang -O1 pow.c -lm
$ ./a.out
lib pow: 3.1622776585872407456e-05, pow: 3.162277658587240068e-05
-------------------------------------------------------------------
The specified compile option is only `-O1` and `-ffast-math` is disabled but
the value of `lib pow` and `pow` differ.
This behavior is caused by
https://github.com/llvm/llvm-project/blob/release/9.x/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp#L1431
I think the optimization pow(x, -0.5) -> 1.0/sqrt(x) is admitted only when fast
math flag exist.
--
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/20191218/2c18d45f/attachment.html>
More information about the llvm-bugs
mailing list