[PATCH] D28335: [WIP] [RFC] Don't lower floating point intrinsics to libcalls which modify errno

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 4 17:59:30 PST 2017


efriedma added a comment.

> We also do need to model errno, however, or provide compiler-rt wrappers,etc. so that we can really use -fno-math-errno on systems where the math functions really do set errno and not miscompile code by reordering calls to math functions with calls to other functions (e.g. open, read) that set errno and where errno is later used (e.g. by perror).

Yes, that's what I was getting at with "Fix clang so it doesn't mark calls which have side-effects readnone."  It's hard to come up with a good solution here, though.  The options I can think of:

1. Make compiler-rt implement a bunch of libm functions with sane semantics.  Straightforward, but writing fast, correct libm routines is tricky.
2. Instead of marking the math functions readnone, mark them "dead_errno_write" or something like that.  That allows correct modeling, but it probably ends up blocking a substantial number of optimizations because we have to assume almost any pointer could alias errno.
3. Some solution which involves teaching the compiler or compiler-rt how to compute the address of errno.  This gets nasty fast because it's different for every libc implementation.

That's largely orthogonal to this patch, though.


Repository:
  rL LLVM

https://reviews.llvm.org/D28335





More information about the llvm-commits mailing list