[llvm-dev] FW: fenv.h vs the optimizer

Kaylor, Andrew via llvm-dev llvm-dev at lists.llvm.org
Thu Aug 18 10:34:18 PDT 2016

Oops.  Looks like I accidently dropped the mailing list when replying to this.

From: Kaylor, Andrew
Sent: Thursday, August 18, 2016 10:02 AM
To: 'Reid Kleckner' <rnk at google.com>; Will <will at millcomputing.com>; Tim Amini Golling <mehdi.amini at apple.com>; Chandler Carruth (chandlerc at gmail.com) <chandlerc at gmail.com>
Subject: RE: [llvm-dev] fenv.h vs the optimizer

We are definitely interested in correctly handling the FP side effects.

I’ve been reading up on the past community discussions of this in hopes of bringing this back into focus.  The last discussion I found on the topic was this thread started by Medhi in February:


Chandler made a proposal in that thread that seemed to be widely agreed upon, but then as far as I can tell nothing was done to implement it.


From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Reid Kleckner via llvm-dev
Sent: Thursday, August 18, 2016 8:42 AM
To: Will <will at millcomputing.com<mailto:will at millcomputing.com>>; Tim Amini Golling <mehdi.amini at apple.com<mailto:mehdi.amini at apple.com>>
Cc: llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>>
Subject: Re: [llvm-dev] fenv.h vs the optimizer

LLVM has never really supported fenv.h:

Even if we added support for the rounding modes, we don't support non-call exceptions either:

I think there is interest in addressing the rounding mode stuff, but less interest in modelling FP side effects. Medhi had some ideas around this.

On Thu, Aug 18, 2016 at 1:12 AM, Will via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote:
Howdy all,

I've been playing around with programs that use the C11 fenv.h.

It seems that, currently, the LLVM compiler does not regard to the exception-flag side-effects of floating point operations?

When run on my macbook, the example code on http://en.cppreference.com/w/c/numeric/fenv/FE_exceptions does not print all the expected exceptions.

Other examples:

void foo() {
    printf("foo downward: %f\n", rint(0.5));
    printf("foo upward: %f\n", rint(0.5));

If compiled with optimization, only one call to rint() is made and the result is reused.

void bar(double a, double b) {
    a / b;
    printf("bar %f / %f is %sexact\n", a, b, fetestexcept(FE_INEXACT)? "in": "");

The compiler omits the divide as the result is unused.  And so on.

Presumably this has never worked?  And perhaps LLVM is no worse than other compilers in this regard?

Is there any appetite to fix it?  What kind of changes would need to be made?



LLVM Developers mailing list
llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160818/a4c12a3a/attachment.html>

More information about the llvm-dev mailing list