public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/108844] New: sincos opportunity missed
@ 2023-02-18 9:38 tkoenig at gcc dot gnu.org
2023-02-20 8:28 ` [Bug tree-optimization/108844] " rguenth at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2023-02-18 9:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108844
Bug ID: 108844
Summary: sincos opportunity missed
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: tkoenig at gcc dot gnu.org
Target Milestone: ---
Two related test cases (which do the same, but are handled differently).
This is code for calculating a Jacobian, a frequent task in solving
non-linear systems of equations. (I am using C instead of Fortran because
Fortran does not support fallthrough).
$ cat a.c
#include <math.h>
void f1 (double x, double y, double f[2], double fjac[2][2], int flag)
{
switch (flag)
{
case 1:
f[0] = x * y;
f[1] = sin(x)*y*y;
break;
case 2:
fjac[0][0] = y;
fjac[1][0] = cos(x)*y*y;
fjac[0][1] = x;
fjac[1][1] = 2*sin(x)*y;
break;
case 3:
f[0] = x * y;
f[1] = sin(x)*y*y;
fjac[0][0] = y;
fjac[1][0] = cos(x)*y*y;
fjac[0][1] = x;
fjac[1][1] = 2*sin(x)*y;
break;
default:
__builtin_unreachable();
}
}
$ cat b.c
#include <math.h>
void f1 (double x, double y, double f[2], double fjac[2][2], int flag)
{
switch (flag)
{
case 1:
case 3:
f[0] = x * y;
f[1] = sin(x)*y*y;
if (flag != 3)
break;
/* Fallthrough */
case 2:
fjac[0][0] = y;
fjac[1][0] = cos(x)*y*y;
fjac[0][1] = x;
fjac[1][1] = 2*sin(x)*y;
break;
default:
__builtin_unreachable();
}
}
$ gcc -O3 -S a.c b.c
a.s looks good for flag=3:
leaq 64(%rsp), %rsi
leaq 72(%rsp), %rdi
movaps %xmm3, 48(%rsp)
movsd %xmm1, 32(%rsp)
movsd %xmm0, 24(%rsp)
call sincos
but the code for flag=2 looks like
cmpl $2, %edx
je .L2
[...]
.L2:
.cfi_restore_state
movaps %xmm3, 32(%rsp)
movsd %xmm1, 24(%rsp)
movsd %xmm0, (%rsp)
call cos
movsd (%rsp), %xmm2
movq %xmm0, %rbx
movapd %xmm2, %xmm0
call sin
b.s generates no call to sincos:
$ egrep '(sin|cos)' b.s
call sin
call sin
call cos
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug tree-optimization/108844] sincos opportunity missed
2023-02-18 9:38 [Bug tree-optimization/108844] New: sincos opportunity missed tkoenig at gcc dot gnu.org
@ 2023-02-20 8:28 ` rguenth at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-02-20 8:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108844
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2023-02-20
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. Probably a algorithmic deficiency in the sincos pass which tries
to combine all sin/cos uses of a specific value but in this case would need
to combine them into two distinct sincos calls.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-02-20 8:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-18 9:38 [Bug tree-optimization/108844] New: sincos opportunity missed tkoenig at gcc dot gnu.org
2023-02-20 8:28 ` [Bug tree-optimization/108844] " 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).