public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: FX <fxcoudert@gmail.com>
To: Joseph Myers <joseph@codesourcery.com>
Cc: Jakub Jelinek <jakub@redhat.com>,
	gcc@gcc.gnu.org, FX via Fortran <fortran@gcc.gnu.org>
Subject: Re: Floating-point comparisons in the middle-end
Date: Thu, 1 Sep 2022 18:24:46 +0200	[thread overview]
Message-ID: <121CB5DE-35AD-4A8A-86A2-D74016CC8F87@gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2209011520170.550568@digraph.polyomino.org.uk>

> Presumably that can be reproduced without depending on the new built-in 
> function?  In which case it's an existing bug somewhere in the optimizers.

Yes:

$ cat a.c
#include <math.h>
#include <stdio.h>
#include <fenv.h>

void foo (void) {
  if (fetestexcept (FE_INVALID) & FE_INVALID)
    printf("Invalid raised\n");
  feclearexcept (FE_ALL_EXCEPT);
}

static inline int iseqsig(float x, float y) { return (x >= y && x <= y); }

int main (void) {
  float x = __builtin_nanf("");
  float y;

  printf("%d\n", iseqsig(__builtin_nanf(""), 1.));
  foo();

  printf("%d\n", iseqsig(x, __builtin_inff()));
  foo();
}

$ ./bin/gcc a.c -lm -fno-unsafe-math-optimizations -frounding-math -fsignaling-nans -O0 && ./a.out
0
Invalid raised
0
Invalid raised

$ ./bin/gcc a.c -lm -fno-unsafe-math-optimizations -frounding-math -fsignaling-nans -O1 && ./a.out
0
0


Do you want me to file a bug report?

FX

  parent reply	other threads:[~2022-09-01 16:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-01  8:04 FX
2022-09-01  8:19 ` Jakub Jelinek
2022-09-01  9:04   ` FX
2022-09-01  9:23     ` Jakub Jelinek
2022-09-01 10:06       ` FX
2022-09-01 15:21         ` Joseph Myers
2022-09-01 15:57           ` Marc Glisse
2022-09-01 16:22             ` Joseph Myers
2022-09-01 16:24           ` FX [this message]
2022-09-01 16:44             ` Joseph Myers
2022-09-01 18:15               ` FX
2022-09-01 14:32   ` Segher Boessenkool
2022-09-01 15:19 ` Joseph Myers
2022-09-01 18:38   ` FX
2022-09-01 19:13     ` Joseph Myers
2022-09-01 18:47   ` FX
2022-09-01 19:16     ` Joseph Myers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=121CB5DE-35AD-4A8A-86A2-D74016CC8F87@gmail.com \
    --to=fxcoudert@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=joseph@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).