public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/105206] New: mis-optimization with -ffast-math and __builtin_powf
@ 2022-04-09 19:30 kargl at gcc dot gnu.org
2022-04-09 19:35 ` [Bug middle-end/105206] " kargl at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: kargl at gcc dot gnu.org @ 2022-04-09 19:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105206
Bug ID: 105206
Summary: mis-optimization with -ffast-math and __builtin_powf
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: kargl at gcc dot gnu.org
Target Milestone: ---
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/105206] mis-optimization with -ffast-math and __builtin_powf
2022-04-09 19:30 [Bug middle-end/105206] New: mis-optimization with -ffast-math and __builtin_powf kargl at gcc dot gnu.org
@ 2022-04-09 19:35 ` kargl at gcc dot gnu.org
2022-04-11 7:18 ` rguenth at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: kargl at gcc dot gnu.org @ 2022-04-09 19:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105206
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |minor
--- Comment #1 from kargl at gcc dot gnu.org ---
Not sure if anyone cares. I don't use -ffast-math, but this might considered a
mis-optimization with that option.
#include <math.h>
float
foof(float x)
{
return (powf(10.f,x));
}
double
food(double x)
{
return (pow(10.,x));
}
-fdump-tree-original shows
;; Function foof (null)
;; enabled by -tree-original
{
return powf (1.0e+1, x);
}
;; Function food (null)
;; enabled by -tree-original
{
return pow (1.0e+1, x);
}
Compiling to assembly shows
foof:
.LFB3:
.cfi_startproc
movaps %xmm0, %xmm1
movss .LC0(%rip), %xmm0
jmp powf
.cfi_endproc
food:
.LFB4:
.cfi_startproc
mulsd .LC1(%rip), %xmm0
jmp exp
.cfi_endproc
So, the middle-end is converting pow(10.x) to exp(x*log(10.0)) where log(10.0)
is reduced, but the same transformation of powf(10.f,x) still yields a call to
powf.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/105206] mis-optimization with -ffast-math and __builtin_powf
2022-04-09 19:30 [Bug middle-end/105206] New: mis-optimization with -ffast-math and __builtin_powf kargl at gcc dot gnu.org
2022-04-09 19:35 ` [Bug middle-end/105206] " kargl at gcc dot gnu.org
@ 2022-04-11 7:18 ` rguenth at gcc dot gnu.org
2022-04-11 14:45 ` kargl at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-11 7:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105206
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rguenth at gcc dot gnu.org
Keywords| |missed-optimization
Ever confirmed|0 |1
Last reconfirmed| |2022-04-11
Status|UNCONFIRMED |WAITING
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Hm, it works for me on linux with glibc, can you be more specific as to what
OS/libc (version) you are using?
foof:
.LFB0:
.cfi_startproc
mulss .LC0(%rip), %xmm0
jmp expf
food:
.LFB1:
.cfi_startproc
mulsd .LC1(%rip), %xmm0
jmp exp
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/105206] mis-optimization with -ffast-math and __builtin_powf
2022-04-09 19:30 [Bug middle-end/105206] New: mis-optimization with -ffast-math and __builtin_powf kargl at gcc dot gnu.org
2022-04-09 19:35 ` [Bug middle-end/105206] " kargl at gcc dot gnu.org
2022-04-11 7:18 ` rguenth at gcc dot gnu.org
@ 2022-04-11 14:45 ` kargl at gcc dot gnu.org
2022-04-11 19:21 ` sgk at troutmask dot apl.washington.edu
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: kargl at gcc dot gnu.org @ 2022-04-11 14:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105206
--- Comment #3 from kargl at gcc dot gnu.org ---
(In reply to Richard Biener from comment #2)
> Hm, it works for me on linux with glibc, can you be more specific as to what
> OS/libc (version) you are using?
>
> foof:
> .LFB0:
> .cfi_startproc
> mulss .LC0(%rip), %xmm0
> jmp expf
>
> food:
> .LFB1:
> .cfi_startproc
> mulsd .LC1(%rip), %xmm0
> jmp exp
Richard, I'm using x86_64-*-freebsd. I just checked with powl(), and got
fool:
.LFB5:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $16, %rsp
flds .LC0(%rip)
pushq 24(%rbp)
pushq 16(%rbp)
fstpt -16(%rbp)
movq -16(%rbp), %rax
movl -8(%rbp), %edx
pushq %rdx
pushq %rax
call powl
addq $32, %rsp
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
with -ffast-math.
This might be related to PR89125. The patch I attached to that PR has never
found its way into the repository. I'll do some more testing later today.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/105206] mis-optimization with -ffast-math and __builtin_powf
2022-04-09 19:30 [Bug middle-end/105206] New: mis-optimization with -ffast-math and __builtin_powf kargl at gcc dot gnu.org
` (2 preceding siblings ...)
2022-04-11 14:45 ` kargl at gcc dot gnu.org
@ 2022-04-11 19:21 ` sgk at troutmask dot apl.washington.edu
2022-04-11 19:24 ` [Bug target/105206] " kargl at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: sgk at troutmask dot apl.washington.edu @ 2022-04-11 19:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105206
--- Comment #4 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Mon, Apr 11, 2022 at 02:45:22PM +0000, kargl at gcc dot gnu.org wrote:
>
> This might be related to PR89125. The patch I attached to that PR has never
> found its way into the repository. I'll do some more testing later today.
>
Yep. This is related to PR89125. GCC does not use configure
to check for the availability of individual C99 libm functions.
After updating the patch in PR89125 for the *.c to *.cc migration
the patch gcc gives
foof:
.LFB3:
.cfi_startproc
mulss .LC0(%rip), %xmm0
jmp expf
.cfi_endproc
food:
.LFB4:
.cfi_startproc
mulsd .LC1(%rip), %xmm0
jmp exp
.cfi_endproc
fool:
.LFB5:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
fldt 16(%rbp)
popq %rbp
.cfi_def_cfa 7, 8
fldt .LC2(%rip)
fmulp %st, %st(1)
fldl2e
fmulp %st, %st(1)
fld %st(0)
frndint
fsubr %st, %st(1)
fxch %st(1)
f2xm1
fld1
faddp %st, %st(1)
fscale
fstp %st(1)
ret
.cfi_endproc
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/105206] mis-optimization with -ffast-math and __builtin_powf
2022-04-09 19:30 [Bug middle-end/105206] New: mis-optimization with -ffast-math and __builtin_powf kargl at gcc dot gnu.org
` (3 preceding siblings ...)
2022-04-11 19:21 ` sgk at troutmask dot apl.washington.edu
@ 2022-04-11 19:24 ` kargl at gcc dot gnu.org
2022-04-12 6:46 ` rguenther at suse dot de
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: kargl at gcc dot gnu.org @ 2022-04-11 19:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105206
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|middle-end |target
Depends on| |89125
Target| |x86_64-*-freebsd
--- Comment #5 from kargl at gcc dot gnu.org ---
I've updated the Component to target and added the target triplet.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89125
[Bug 89125] Misoptimization of converting sin(x) and cos(x) into
sincos(x,&s,&c)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/105206] mis-optimization with -ffast-math and __builtin_powf
2022-04-09 19:30 [Bug middle-end/105206] New: mis-optimization with -ffast-math and __builtin_powf kargl at gcc dot gnu.org
` (4 preceding siblings ...)
2022-04-11 19:24 ` [Bug target/105206] " kargl at gcc dot gnu.org
@ 2022-04-12 6:46 ` rguenther at suse dot de
2022-04-12 17:35 ` kargl at gcc dot gnu.org
2022-04-25 7:28 ` rguenth at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: rguenther at suse dot de @ 2022-04-12 6:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105206
--- Comment #6 from rguenther at suse dot de <rguenther at suse dot de> ---
On Mon, 11 Apr 2022, kargl at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105206
>
> --- Comment #3 from kargl at gcc dot gnu.org ---
> (In reply to Richard Biener from comment #2)
> > Hm, it works for me on linux with glibc, can you be more specific as to what
> > OS/libc (version) you are using?
> >
> > foof:
> > .LFB0:
> > .cfi_startproc
> > mulss .LC0(%rip), %xmm0
> > jmp expf
> >
> > food:
> > .LFB1:
> > .cfi_startproc
> > mulsd .LC1(%rip), %xmm0
> > jmp exp
>
> Richard, I'm using x86_64-*-freebsd. I just checked with powl(), and got
> fool:
> .LFB5:
> .cfi_startproc
> pushq %rbp
> .cfi_def_cfa_offset 16
> .cfi_offset 6, -16
> movq %rsp, %rbp
> .cfi_def_cfa_register 6
> subq $16, %rsp
> flds .LC0(%rip)
> pushq 24(%rbp)
> pushq 16(%rbp)
> fstpt -16(%rbp)
> movq -16(%rbp), %rax
> movl -8(%rbp), %edx
> pushq %rdx
> pushq %rax
> call powl
> addq $32, %rsp
> leave
> .cfi_def_cfa 7, 8
> ret
> .cfi_endproc
>
> with -ffast-math.
>
> This might be related to PR89125. The patch I attached to that PR has never
> found its way into the repository. I'll do some more testing later today.
Ah, yeah - that old issue, indeed good to revisit that.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/105206] mis-optimization with -ffast-math and __builtin_powf
2022-04-09 19:30 [Bug middle-end/105206] New: mis-optimization with -ffast-math and __builtin_powf kargl at gcc dot gnu.org
` (5 preceding siblings ...)
2022-04-12 6:46 ` rguenther at suse dot de
@ 2022-04-12 17:35 ` kargl at gcc dot gnu.org
2022-04-25 7:28 ` rguenth at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: kargl at gcc dot gnu.org @ 2022-04-12 17:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105206
kargl at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #7 from kargl at gcc dot gnu.org ---
(In reply to rguenther@suse.de from comment #6)
> On Mon, 11 Apr 2022, kargl at gcc dot gnu.org wrote:
>
> >
> > This might be related to PR89125. The patch I attached to that PR has never
> > found its way into the repository. I'll do some more testing later today.
>
> Ah, yeah - that old issue, indeed good to revisit that.
It's definitely a manifestation of PR89125. I'll close this
as a duplicate.
*** This bug has been marked as a duplicate of bug 89125 ***
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/105206] mis-optimization with -ffast-math and __builtin_powf
2022-04-09 19:30 [Bug middle-end/105206] New: mis-optimization with -ffast-math and __builtin_powf kargl at gcc dot gnu.org
` (6 preceding siblings ...)
2022-04-12 17:35 ` kargl at gcc dot gnu.org
@ 2022-04-25 7:28 ` rguenth at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-25 7:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105206
Bug 105206 depends on bug 89125, which changed state.
Bug 89125 Summary: Misoptimization of converting sin(x) and cos(x) into sincos(x,&s,&c)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89125
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-04-25 7:28 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-09 19:30 [Bug middle-end/105206] New: mis-optimization with -ffast-math and __builtin_powf kargl at gcc dot gnu.org
2022-04-09 19:35 ` [Bug middle-end/105206] " kargl at gcc dot gnu.org
2022-04-11 7:18 ` rguenth at gcc dot gnu.org
2022-04-11 14:45 ` kargl at gcc dot gnu.org
2022-04-11 19:21 ` sgk at troutmask dot apl.washington.edu
2022-04-11 19:24 ` [Bug target/105206] " kargl at gcc dot gnu.org
2022-04-12 6:46 ` rguenther at suse dot de
2022-04-12 17:35 ` kargl at gcc dot gnu.org
2022-04-25 7:28 ` rguenth at gcc dot gnu.org
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).