public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "malat at debian dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/110622] x87: Miscompilation at O2 level (O1 is working)
Date: Thu, 21 Sep 2023 14:29:10 +0000 [thread overview]
Message-ID: <bug-110622-4-cmNLXLIkhs@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110622-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110622
--- Comment #16 from Mathieu Malaterre <malat at debian dot org> ---
(In reply to Xi Ruoyao from comment #15)
> (In reply to Mathieu Malaterre from comment #14)
> > (In reply to Andrew Pinski from comment #13)
> > > (In reply to Mathieu Malaterre from comment #12)
> > > > I am seeing a difference in result (log1p computation) in the range:
> > > >
> > > > 4318952042648305665 - 0x1.0000000000001p-64
> > > > 4368493837572636672 - 0x1.002p-53
> > > >
> > > > the other values seems to match expectation of log1p computation.
> > >
> > > But you used excess-precision=fast
> > >
> > > *** This bug has been marked as a duplicate of bug 323 ***
> >
> > AFAIK bug #323 does not mention my trick:
> >
> > asm volatile("" : "+r"(y.raw[0]) : : "memory");
> >
> > That simple line totally changed the optimizer code generation.
>
> Because in x87 the excessive precision only exists in x87 stack-like
> registers. The "memory" clobber forces a store and reload for all
> non-register variables, thus the value is truncated into a normal double
> value and the excessive precision is lost.
>
> There are infinite ways to work around an issue, but it does not mean PR 323
> must mention all of them.
Oh, I see. Basically my trick is convoluted `-ffloat-store`.
I finally took myself by the hand and convinced me with a simple code:
```
// gcc -m32 -fexcess-precision=fast -O2 t.c
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
[[gnu::noipa]] void test(uint64_t v, double x, double y) {
const double y2 = x + 1.0;
if (y != y2)
printf("error %" PRIu64 " %.17g %a\n", v, x, x);
else
printf("ok %" PRIu64 " %.17g %a\n", v, x, x);
}
void main() {
uint64_t kSamplesPerRange = 4000, start = 0, stop = 9218868437227405311;
uint64_t step = (stop / kSamplesPerRange);
for (uint64_t value_bits = start; value_bits <= stop; value_bits += step) {
double value;
memcpy(&value, &value_bits, sizeof value);
double x = value;
double y = x + 1.0;
test(value_bits, x, y);
}
}
```
please accept my apologies for the noise.
prev parent reply other threads:[~2023-09-21 14:29 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-11 6:28 [Bug c++/110622] New: x86: Miscompilation at O1 level (O0 " malat at debian dot org
2023-07-11 6:29 ` [Bug c++/110622] " malat at debian dot org
2023-07-11 6:30 ` malat at debian dot org
2023-07-11 6:31 ` pinskia at gcc dot gnu.org
2023-07-11 6:33 ` malat at debian dot org
2023-07-11 6:33 ` malat at debian dot org
2023-07-11 6:38 ` pinskia at gcc dot gnu.org
2023-07-11 6:44 ` [Bug target/110622] " malat at debian dot org
2023-07-11 8:25 ` malat at debian dot org
2023-09-21 9:44 ` malat at debian dot org
2023-09-21 9:48 ` [Bug target/110622] x87: Miscompilation at O2 level (O1 " malat at debian dot org
2023-09-21 9:51 ` malat at debian dot org
2023-09-21 9:56 ` malat at debian dot org
2023-09-21 13:33 ` pinskia at gcc dot gnu.org
2023-09-21 13:42 ` malat at debian dot org
2023-09-21 13:45 ` xry111 at gcc dot gnu.org
2023-09-21 14:29 ` malat at debian dot org [this message]
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=bug-110622-4-cmNLXLIkhs@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/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).