[llvm-dev] PR43374 - when should comparing NaN values raise a floating point exception?
Roman Lebedev via llvm-dev
llvm-dev at lists.llvm.org
Tue Oct 8 07:43:35 PDT 2019
On Tue, Oct 8, 2019 at 4:54 PM Szabolcs Nagy via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
>
> * Sanjay Patel <spatel at rotateright.com> [2019-10-08 09:03:53 -0400]:
> > On Tue, Oct 8, 2019 at 8:44 AM Szabolcs Nagy <nsz at port70.net> wrote:
> >
> > > * Sanjay Patel <spatel at rotateright.com> [2019-10-08 08:07:10 -0400]:
> > > > On Tue, Oct 8, 2019 at 7:08 AM Szabolcs Nagy <nsz at port70.net> wrote:
> > > > > why is that ok?
> > > > >
> > > >
> > > > Because there are no FP exceptions/signals for this IR opcode:
> > > > http://llvm.org/docs/LangRef.html#floating-point-environment
> > >
> > > so llvm cannot support an iso c frontend on an ieee754 target?
> > > (or fortran for that matter)
> > >
> >
> > Not sure. I thought we solved the problems for all of the examples given so
> > far.
> > Do you have an end-to-end (C source to asm) example that shows a bug?
> > Please cite the C language law that is violated (add cfe-dev if there's a
> > front-end bug?).
>
> anything that should observably raise a floating-point exception
> does not work if llvm only provides silent operations or ignores
> fenv side-effects during lowering, e.g.
>
> #pragma STDC FENV_ACCESS ON
> int cmp(float x, float y)
> {
> return x < y;
> }
https://godbolt.org/z/scCqZJ
<source>:1:14: warning: pragma STDC FENV_ACCESS ON is not supported,
ignoring pragma [-Wunknown-pragmas]
#pragma STDC FENV_ACCESS ON
^
1 warning generated.
You want strict-FP support, which is mostly there on the LLVM side of things,
but is not there on clang side of things - https://reviews.llvm.org/D62731 e.g.
Roman.
> is lowered to fcmp olt which you say should be silent:
>
> define dso_local i32 @cmp(float %0, float %1) #0 {
> %3 = alloca float, align 4
> %4 = alloca float, align 4
> store float %0, float* %3, align 4
> store float %1, float* %4, align 4
> %5 = load float, float* %3, align 4
> %6 = load float, float* %4, align 4
> %7 = fcmp olt float %5, %6
> %8 = zext i1 %7 to i32
> ret i32 %8
> }
>
> this is observably non-iso c conform so clang miscompiles
> math libraries written in c (math functions are required
> to report errors by signaling floating-point exceptions).
This should go to cfe-dev.
> it also does not support snan, but that's not strictly
> required by iso c.
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
More information about the llvm-dev
mailing list