James Molloy via llvm-dev
2016-Apr-04 13:59 UTC
[llvm-dev] RFC: Constant folding math functions for long double
Hi, Clang is currently unable to constant fold calls to math.h functions such as logl(), expl() etc. The problem is that APFloat doesn't have these functions, so Clang is forced to rely on the host math library. Because long double isn't portable, we only ever query the host math library for double or float results. I can see three methods for allowing constant folding for types that are larger than double, some more expensive than others: 1. Introduce a dependency on libMPFR, as GCC does. The dependency could be hard or soft, with a fallback to the current behaviour if it doesn't exist. 2. Write the trancendental functions ourselves in APFloat (yuck!) 3. If the long double format on the compiler host is the same as the target, use the host library. (2) is the hardest. (3) is the easiest, but only works in a subset of cases and I really don't like the idea of better output when compiling on one platform compared to another (with equivalent targets). What do people think about (1)? Or is this completely out of the question? Cheers, James -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160404/718bb13d/attachment-0001.html>
Renato Golin via llvm-dev
2016-Apr-04 14:06 UTC
[llvm-dev] RFC: Constant folding math functions for long double
On 4 April 2016 at 14:59, James Molloy via llvm-dev <llvm-dev at lists.llvm.org> wrote:> 1. Introduce a dependency on libMPFR, as GCC does. The dependency could be > hard or soft, with a fallback to the current behaviour if it doesn't exist.A soft dependency would be much better.> 3. If the long double format on the compiler host is the same as the > target, use the host library.No hard feelings about this one...> (2) is the hardest. (3) is the easiest, but only works in a subset of cases > and I really don't like the idea of better output when compiling on one > platform compared to another (with equivalent targets).If you make (1) a soft dependency, then (3) will have the same effect, ie, sometimes the code will be better, sometimes it won't. I personally don't feel bad about introducing soft dependencies or special cases to make code better, as long as the users understand how to make their code better if they wish (ie. documenting the dependency). So I think both (1) and (3) are acceptable solutions, when properly documented. cheers, --renato
Neil Henning via llvm-dev
2016-Apr-04 14:18 UTC
[llvm-dev] RFC: Constant folding math functions for long double
Please not (1). Cheers, -Neil. On 04/04/16 14:59, James Molloy via llvm-dev wrote:> Hi, > > Clang is currently unable to constant fold calls to math.h functions > such as logl(), expl() etc. > > The problem is that APFloat doesn't have these functions, so Clang is > forced to rely on the host math library. Because long double isn't > portable, we only ever query the host math library for double or float > results. > > I can see three methods for allowing constant folding for types that > are larger than double, some more expensive than others: > > 1. Introduce a dependency on libMPFR, as GCC does. The dependency > could be hard or soft, with a fallback to the current behaviour if it > doesn't exist. > 2. Write the trancendental functions ourselves in APFloat (yuck!) > 3. If the long double format on the compiler host is the same as the > target, use the host library. > > (2) is the hardest. (3) is the easiest, but only works in a subset of > cases and I really don't like the idea of better output when compiling > on one platform compared to another (with equivalent targets). > > What do people think about (1)? Or is this completely out of the question? > > Cheers, > > James > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160404/d91fc527/attachment.html>
James Molloy via llvm-dev
2016-Apr-04 14:19 UTC
[llvm-dev] RFC: Constant folding math functions for long double
Hi Neil,> Please not (1).Could you please elaborate on your concern a bit more? Cheers, James On Mon, 4 Apr 2016 at 15:18 Neil Henning via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Please not (1). > > Cheers, > -Neil. > > > On 04/04/16 14:59, James Molloy via llvm-dev wrote: > > Hi, > > Clang is currently unable to constant fold calls to math.h functions such > as logl(), expl() etc. > > The problem is that APFloat doesn't have these functions, so Clang is > forced to rely on the host math library. Because long double isn't > portable, we only ever query the host math library for double or float > results. > > I can see three methods for allowing constant folding for types that are > larger than double, some more expensive than others: > > 1. Introduce a dependency on libMPFR, as GCC does. The dependency could > be hard or soft, with a fallback to the current behaviour if it doesn't > exist. > 2. Write the trancendental functions ourselves in APFloat (yuck!) > 3. If the long double format on the compiler host is the same as the > target, use the host library. > > (2) is the hardest. (3) is the easiest, but only works in a subset of > cases and I really don't like the idea of better output when compiling on > one platform compared to another (with equivalent targets). > > What do people think about (1)? Or is this completely out of the question? > > Cheers, > > James > > > _______________________________________________ > LLVM Developers mailing listllvm-dev at lists.llvm.orghttp://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160404/7dbde9ca/attachment.html>
Tim Northover via llvm-dev
2016-Apr-04 14:58 UTC
[llvm-dev] RFC: Constant folding math functions for long double
On 4 April 2016 at 07:06, Renato Golin via llvm-dev <llvm-dev at lists.llvm.org> wrote:> If you make (1) a soft dependency, then (3) will have the same effect, > ie, sometimes the code will be better, sometimes it won't.You usually have far more control over which libraries you install than over libc and the ABI of your host system, so (1) has a strong advantage there. I like the sound of libMPFR or some equivalent. Tim.
Reid Kleckner via llvm-dev
2016-Apr-04 16:49 UTC
[llvm-dev] RFC: Constant folding math functions for long double
My feeling is that we shouldn't be relying on host long double routines. We're already skating on thin ice by relying on host double and float routines. This is a great way to make the compilation result vary depending on the host, which is something we try to avoid. An optional MPFR dependency would also be pretty painful. I expect it will frequently be missing and will not be exercised by most buildbots. On Mon, Apr 4, 2016 at 6:59 AM, James Molloy via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hi, > > Clang is currently unable to constant fold calls to math.h functions such > as logl(), expl() etc. > > The problem is that APFloat doesn't have these functions, so Clang is > forced to rely on the host math library. Because long double isn't > portable, we only ever query the host math library for double or float > results. > > I can see three methods for allowing constant folding for types that are > larger than double, some more expensive than others: > > 1. Introduce a dependency on libMPFR, as GCC does. The dependency could > be hard or soft, with a fallback to the current behaviour if it doesn't > exist. > 2. Write the trancendental functions ourselves in APFloat (yuck!) > 3. If the long double format on the compiler host is the same as the > target, use the host library. > > (2) is the hardest. (3) is the easiest, but only works in a subset of > cases and I really don't like the idea of better output when compiling on > one platform compared to another (with equivalent targets). > > What do people think about (1)? Or is this completely out of the question? > > Cheers, > > James > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160404/557f844a/attachment.html>
Stephen Canon via llvm-dev
2016-Apr-04 17:01 UTC
[llvm-dev] RFC: Constant folding math functions for long double
MPFR suffers from the same problem as host library routines; the results don’t (in general) match what you get at runtime. - Steve> On Apr 4, 2016, at 9:49 AM, Reid Kleckner via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > My feeling is that we shouldn't be relying on host long double routines. We're already skating on thin ice by relying on host double and float routines. This is a great way to make the compilation result vary depending on the host, which is something we try to avoid. > > An optional MPFR dependency would also be pretty painful. I expect it will frequently be missing and will not be exercised by most buildbots. > > On Mon, Apr 4, 2016 at 6:59 AM, James Molloy via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote: > Hi, > > Clang is currently unable to constant fold calls to math.h functions such as logl(), expl() etc. > > The problem is that APFloat doesn't have these functions, so Clang is forced to rely on the host math library. Because long double isn't portable, we only ever query the host math library for double or float results. > > I can see three methods for allowing constant folding for types that are larger than double, some more expensive than others: > > 1. Introduce a dependency on libMPFR, as GCC does. The dependency could be hard or soft, with a fallback to the current behaviour if it doesn't exist. > 2. Write the trancendental functions ourselves in APFloat (yuck!) > 3. If the long double format on the compiler host is the same as the target, use the host library. > > (2) is the hardest. (3) is the easiest, but only works in a subset of cases and I really don't like the idea of better output when compiling on one platform compared to another (with equivalent targets). > > What do people think about (1)? Or is this completely out of the question? > > Cheers, > > James-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160404/ddbf559d/attachment.html>
Renato Golin via llvm-dev
2016-Apr-04 17:15 UTC
[llvm-dev] RFC: Constant folding math functions for long double
On 4 April 2016 at 17:49, Reid Kleckner via llvm-dev <llvm-dev at lists.llvm.org> wrote:> An optional MPFR dependency would also be pretty painful. I expect it will > frequently be missing and will not be exercised by most buildbots.Wouldn't this be responsibility of whomever care? I mean, like any other back-end / plugin that people dump in ToT to help them "have third-party code hanging out but is not actually tested and should be fine as long as it doesn't break anything else". We seems to be gathering more and more of those things lately, and I thought people were generally ok with it. Not that I care too much, I don't have any use for MPFR myself, just wanting to understand where we cut the line. cheers, --renato
Joerg Sonnenberger via llvm-dev
2016-Apr-04 17:41 UTC
[llvm-dev] RFC: Constant folding math functions for long double
On Mon, Apr 04, 2016 at 09:49:24AM -0700, Reid Kleckner via llvm-dev wrote:> An optional MPFR dependency would also be pretty painful. I expect it will > frequently be missing and will not be exercised by most buildbots.IMO if constant folding of transcendental functions makes a significant difference for your program, you likely are doing something strange already. I don't think it matters much for a lot of use cases, so having an optional dependency for this seems to be fine. Note that the non-transcendental functions are quite a different deal, especially reasonable well behaving functions like log and exp. Joerg
James Molloy via llvm-dev
2016-Apr-04 17:46 UTC
[llvm-dev] RFC: Constant folding math functions for long double
Hi Joerg,> IMO if constant folding of transcendental functions makes a significantdifference for your program, you likely are doing something strange already. Alas it's not as simple as that. Currently, if you declare: std::uniform_real_distribution<float> x; LLVM emits two calls to logl() with constant arguments, a fdiv and a fptoui. Libc++'s implementation is consumed and folded much more nicely by LLVM, but at the moment anyone comparing LLVM and GCC will think that GCC is around 40% better for some workloads. James On Mon, 4 Apr 2016 at 17:49 Reid Kleckner <rnk at google.com> wrote:> My feeling is that we shouldn't be relying on host long double routines. > We're already skating on thin ice by relying on host double and float > routines. This is a great way to make the compilation result vary depending > on the host, which is something we try to avoid. > > An optional MPFR dependency would also be pretty painful. I expect it will > frequently be missing and will not be exercised by most buildbots. > > On Mon, Apr 4, 2016 at 6:59 AM, James Molloy via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> Hi, >> >> Clang is currently unable to constant fold calls to math.h functions such >> as logl(), expl() etc. >> >> The problem is that APFloat doesn't have these functions, so Clang is >> forced to rely on the host math library. Because long double isn't >> portable, we only ever query the host math library for double or float >> results. >> >> I can see three methods for allowing constant folding for types that are >> larger than double, some more expensive than others: >> >> 1. Introduce a dependency on libMPFR, as GCC does. The dependency could >> be hard or soft, with a fallback to the current behaviour if it doesn't >> exist. >> 2. Write the trancendental functions ourselves in APFloat (yuck!) >> 3. If the long double format on the compiler host is the same as the >> target, use the host library. >> >> (2) is the hardest. (3) is the easiest, but only works in a subset of >> cases and I really don't like the idea of better output when compiling on >> one platform compared to another (with equivalent targets). >> >> What do people think about (1)? Or is this completely out of the question? >> >> Cheers, >> >> James >> >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >>-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160404/9c80119e/attachment.html>
Reasonably Related Threads
- RFC: Constant folding math functions for long double
- RFC: Constant folding math functions for long double
- RFC: Constant folding math functions for long double
- RFC: Constant folding math functions for long double
- RFC: Constant folding math functions for long double