Open Quuxplusone opened 8 years ago
Bugzilla Link | PR28937 |
Status | NEW |
Importance | P enhancement |
Reported by | npl@chello.at |
Reported on | 2016-08-11 08:07:46 -0700 |
Last modified on | 2017-11-06 10:43:04 -0800 |
Version | 3.8 |
Hardware | PC Linux |
CC | hfinkel@anl.gov, llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also |
This doesn't repro on OSX because OSX -fno-math-errno is the default. Ie, we only fail to optimize it if 'errno' is required to be set.
You are right, clang can optimize if I add this flag. gcc optimizes even if I
set -fmath-errno.
The attribute "const" is probably not syntactically correct and this is a
harder than I thought.
You`d have to take care to keep the *last* identical function call alive, and
not move them around functions that read/write errno.
double messy(double a)
{
double A = sin(a); // that can be removed, result is same as C
double B = log(a);
double C = sin(a); // that has to stay below other functions modifying errno
return A + B + C;
}
gcc 4.9 generates incorrect code with this example (with -fmath-errno set).
I'm trying to clean up the const-ness of library functions/builtins and their
mapping to LLVM intrinsics:
https://reviews.llvm.org/D39204
https://reviews.llvm.org/D39481
https://reviews.llvm.org/D39611
But I think we're already doing the right thing both in the example in the
description and in comment 2. Can we close this bug?