* [Bug c/115374] fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN
2024-06-06 19:01 [Bug c/115374] New: fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN k3x-devel at outlook dot com
@ 2024-06-06 19:04 ` pinskia at gcc dot gnu.org
2024-06-06 19:06 ` pinskia at gcc dot gnu.org
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-06 19:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115374
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-06-06
Status|UNCONFIRMED |WAITING
Ever confirmed|0 |1
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Your example code is undefined due to the way it changes the stack without
mentioning it to the compiler.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/115374] fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN
2024-06-06 19:01 [Bug c/115374] New: fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN k3x-devel at outlook dot com
2024-06-06 19:04 ` [Bug c/115374] " pinskia at gcc dot gnu.org
@ 2024-06-06 19:06 ` pinskia at gcc dot gnu.org
2024-06-06 19:13 ` k3x-devel at outlook dot com
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-06 19:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115374
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
And for mmx code, you can't combine it in a nice way without using EMMS.
So it might be a bug in the code you are testing with.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/115374] fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN
2024-06-06 19:01 [Bug c/115374] New: fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN k3x-devel at outlook dot com
2024-06-06 19:04 ` [Bug c/115374] " pinskia at gcc dot gnu.org
2024-06-06 19:06 ` pinskia at gcc dot gnu.org
@ 2024-06-06 19:13 ` k3x-devel at outlook dot com
2024-06-06 19:15 ` k3x-devel at outlook dot com
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: k3x-devel at outlook dot com @ 2024-06-06 19:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115374
Mario Hros <k3x-devel at outlook dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #58371|0 |1
is obsolete| |
--- Comment #3 from Mario Hros <k3x-devel at outlook dot com> ---
Created attachment 58372
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58372&action=edit
reporoduction code, compile with -O3 -lm
Prints "is NaN and should not be"
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/115374] fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN
2024-06-06 19:01 [Bug c/115374] New: fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN k3x-devel at outlook dot com
` (2 preceding siblings ...)
2024-06-06 19:13 ` k3x-devel at outlook dot com
@ 2024-06-06 19:15 ` k3x-devel at outlook dot com
2024-06-06 19:18 ` pinskia at gcc dot gnu.org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: k3x-devel at outlook dot com @ 2024-06-06 19:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115374
--- Comment #4 from Mario Hros <k3x-devel at outlook dot com> ---
I already reported the problem in the code using MMX without EMMS - it was
FFMPEG
(https://patchwork.ffmpeg.org/project/ffmpeg/patch/AM9P193MB194004554ECF79F43679CFB2AFF92@AM9P193MB1940.EURP193.PROD.OUTLOOK.COM/).
This bug report is about the strange behavior where GCC doesn't seem to be
using result of the fmod@plt at all. Or am I missing something?
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/115374] fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN
2024-06-06 19:01 [Bug c/115374] New: fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN k3x-devel at outlook dot com
` (3 preceding siblings ...)
2024-06-06 19:15 ` k3x-devel at outlook dot com
@ 2024-06-06 19:18 ` pinskia at gcc dot gnu.org
2024-06-06 19:20 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-06 19:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115374
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The inline-asm is still broken
https://gcc.gnu.org/onlinedocs/gcc-14.1.0/gcc/Extended-Asm.html#x86-Floating-Point-asm-Operands
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/115374] fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN
2024-06-06 19:01 [Bug c/115374] New: fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN k3x-devel at outlook dot com
` (4 preceding siblings ...)
2024-06-06 19:18 ` pinskia at gcc dot gnu.org
@ 2024-06-06 19:20 ` pinskia at gcc dot gnu.org
2024-06-06 19:28 ` k3x-devel at outlook dot com
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-06 19:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115374
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Mario Hros from comment #4)
>
> This bug report is about the strange behavior where GCC doesn't seem to be
> using result of the fmod@plt at all. Or am I missing something?
Yes you are missing the fmod function will set errno on error. If you don't
want to depend on that behavior use -fno-math-errno .
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/115374] fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN
2024-06-06 19:01 [Bug c/115374] New: fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN k3x-devel at outlook dot com
` (5 preceding siblings ...)
2024-06-06 19:20 ` pinskia at gcc dot gnu.org
@ 2024-06-06 19:28 ` k3x-devel at outlook dot com
2024-06-06 19:32 ` ubizjak at gmail dot com
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: k3x-devel at outlook dot com @ 2024-06-06 19:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115374
--- Comment #7 from Mario Hros <k3x-devel at outlook dot com> ---
Created attachment 58373
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58373&action=edit
reporoduction code, compile with -O3 -lm
prints:
is NaN and should not be
errno = 0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/115374] fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN
2024-06-06 19:01 [Bug c/115374] New: fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN k3x-devel at outlook dot com
` (6 preceding siblings ...)
2024-06-06 19:28 ` k3x-devel at outlook dot com
@ 2024-06-06 19:32 ` ubizjak at gmail dot com
2024-06-07 6:09 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: ubizjak at gmail dot com @ 2024-06-06 19:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115374
--- Comment #8 from Uroš Bizjak <ubizjak at gmail dot com> ---
When compiling the following testcase:
--cut here--
#include <math.h>
double
__attribute__((noinline))
do_fmod (double x, double y)
{
return fmod(x, y);
}
--cut here--
one can find in _.265t.optimized:
__attribute__((noinline))
double do_fmod (double x, double y)
{
double _5;
<bb 2> [local count: 1073741824]:
_5 = .FMOD (x_2(D), y_3(D));
if (_5 == _5)
goto <bb 4>; [99.95%]
else
goto <bb 3>; [0.05%]
<bb 3> [local count: 536864]:
fmod (x_2(D), y_3(D));
<bb 4> [local count: 1073741824]:
return _5;
}
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/115374] fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN
2024-06-06 19:01 [Bug c/115374] New: fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN k3x-devel at outlook dot com
` (7 preceding siblings ...)
2024-06-06 19:32 ` ubizjak at gmail dot com
@ 2024-06-07 6:09 ` rguenth at gcc dot gnu.org
2024-06-07 15:20 ` k3x-devel at outlook dot com
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-07 6:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115374
--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
Yep, it's call DCE which elides the errno setting function call iff the result
is not NaN.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/115374] fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN
2024-06-06 19:01 [Bug c/115374] New: fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN k3x-devel at outlook dot com
` (8 preceding siblings ...)
2024-06-07 6:09 ` rguenth at gcc dot gnu.org
@ 2024-06-07 15:20 ` k3x-devel at outlook dot com
2024-06-07 15:23 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: k3x-devel at outlook dot com @ 2024-06-07 15:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115374
--- Comment #10 from Mario Hros <k3x-devel at outlook dot com> ---
That _.265t.optimized posted matches my observation. So the call into glibc
fmod() is made to set errno eventually, ok. But shouldn't the returned value
from the glibc call be used instead of returning NaN? I am not the one to
decide. If that works as expected, then it is not a bug and this issue can be
closed.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/115374] fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN
2024-06-06 19:01 [Bug c/115374] New: fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN k3x-devel at outlook dot com
` (9 preceding siblings ...)
2024-06-07 15:20 ` k3x-devel at outlook dot com
@ 2024-06-07 15:23 ` jakub at gcc dot gnu.org
2024-06-07 15:30 ` k3x-devel at outlook dot com
2024-06-07 15:34 ` jakub at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-06-07 15:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115374
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Mario Hros from comment #10)
> That _.265t.optimized posted matches my observation. So the call into glibc
> fmod() is made to set errno eventually, ok. But shouldn't the returned value
> from the glibc call be used instead of returning NaN?
Why? We know the result should be NaN and we have a NaN from the inline fmod
expansion. The glibc call is purely to set errno.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/115374] fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN
2024-06-06 19:01 [Bug c/115374] New: fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN k3x-devel at outlook dot com
` (10 preceding siblings ...)
2024-06-07 15:23 ` jakub at gcc dot gnu.org
@ 2024-06-07 15:30 ` k3x-devel at outlook dot com
2024-06-07 15:34 ` jakub at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: k3x-devel at outlook dot com @ 2024-06-07 15:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115374
Mario Hros <k3x-devel at outlook dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |WONTFIX
Status|WAITING |RESOLVED
--- Comment #12 from Mario Hros <k3x-devel at outlook dot com> ---
Because fmod() does not work when the FPU is in an invalid operation state,
despite the fact that it could if glibc's implementation had been used as a
"fallback". But maybe it's not worth it. I'll mark this as resolved. I am sorry
for bothering you.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug c/115374] fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN
2024-06-06 19:01 [Bug c/115374] New: fmod() in x86_64 -O3 not using return value from the glibc's implementation if x87 FPU fprem returns NaN k3x-devel at outlook dot com
` (11 preceding siblings ...)
2024-06-07 15:30 ` k3x-devel at outlook dot com
@ 2024-06-07 15:34 ` jakub at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-06-07 15:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115374
--- Comment #13 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The bug is mixing MMX with floating point and expecting it to work, it will
never work properly, you need manual emms in between, or better yet, avoid MMX
altogether, it really isn't worth it. Just use SSE and higher.
^ permalink raw reply [flat|nested] 14+ messages in thread