public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/31249]  New: pseudo-optimzation with sincos/cexpi
@ 2007-03-17 21:11 dominiq at lps dot ens dot fr
  2007-03-18  9:50 ` [Bug middle-end/31249] " pinskia at gcc dot gnu dot org
                   ` (18 more replies)
  0 siblings, 19 replies; 21+ messages in thread
From: dominiq at lps dot ens dot fr @ 2007-03-17 21:11 UTC (permalink / raw)
  To: gcc-bugs

With gfortran and g++ the computation of cos(x) and sin(x) is "optimized" by
taking
the real and imaginary parts of cexpi(x) (at least it is what I understand).
This is working
if and only if the computation of cexpi(x) is faster than the sum of the
separate computations 
of cos(x) and sin(x). 

Now consider the following code:

integer, parameter :: n=1000000
integer :: i
real(8) :: pi, ss, sc, t, dt
pi = acos(-1.0d0)
dt=pi/n
sc=0
ss=0
t=0
do i= 1, 100*n
  sc = sc + cos(t-dt)
  ss = ss + sin(t)
  t = t+dt
end do
print *, sc, ss
end

the result is (G5 1.8Ghz, OSX 10.3.9):

[karma] bug/timing% gfc -O3 sincos.f90 
[karma] bug/timing% time a.out 
 -6.324121638644320E-002 -2.934958087315009E-003
13.020u 0.050s 0:13.59 96.1%    0+0k 0+2io 0pf+0w

It is easy to see that I have fooled the optimizer with the line

  sc = sc + cos(t-dt)

If I replace it by:

  sc = sc + cos(t)

the result is now (over a 50% increase of the CPU time):

[karma] bug/timing% gfc -O3 sincos_o.f90
[karma] bug/timing% time a.out
 -6.324121573032526E-002 -2.934958087315009E-003
21.740u 0.080s 0:22.18 98.3%    0+0k 0+2io 0pf+0w

to be compared with the result of the code:

integer, parameter :: n=1000000
integer :: i
real(8) :: pi, ss, sc, t, dt
complex(8) :: z, dz
pi = acos(-1.0d0)
dt=pi/n
dz=cmplx(0.0d0,dt,8)
sc=0
ss=0
z=0
do i= 1, 100*n
  sc = sc + real(exp(z))
  ss = ss + aimag(exp(z))
  z = z+dz
end do
print *, sc, ss
end

is

[karma] bug/timing% gfc -O3 cexp.f90
[karma] bug/timing% time a.out
 -6.324121573032526E-002 -2.934958087315009E-003
20.850u 0.110s 0:21.45 97.7%    0+0k 0+2io 0pf+0w

Following the comments in PR #30969, 30980, and 31161, I have understood that
on OSX cexpi "fallback" to cexp in perfect agreement with the above timings.

So it would probably nice to disable the sincos "optimisation" on platforms
that
do not support fast cexpi such as OSX (as presently configured).

Note that on Sat, 30 Sep 2006 in

http://gcc.gnu.org/ml/fortran/2006-09/msg00454.html

I have reported (in vain) a timing regression for the fatigue.f90 polyhedron
test case.
Is this related to this pseudo-optimization or to another change?


-- 
           Summary: pseudo-optimzation with sincos/cexpi
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dominiq at lps dot ens dot fr
GCC target triplet: powerpc-apple-darwin7


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31249


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2009-12-04 17:10 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-17 21:11 [Bug middle-end/31249] New: pseudo-optimzation with sincos/cexpi dominiq at lps dot ens dot fr
2007-03-18  9:50 ` [Bug middle-end/31249] " pinskia at gcc dot gnu dot org
2007-03-18 10:20 ` dominiq at lps dot ens dot fr
2007-03-19  9:28 ` dominiq at lps dot ens dot fr
2007-03-19 10:43 ` rguenth at gcc dot gnu dot org
2007-03-19 12:44 ` dominiq at lps dot ens dot fr
2007-03-19 17:52   ` Andrew Pinski
2007-03-19 17:53 ` pinskia at gmail dot com
2007-03-20 11:04 ` rguenth at gcc dot gnu dot org
2007-03-20 13:57 ` dominiq at lps dot ens dot fr
2007-03-20 14:03 ` dominiq at lps dot ens dot fr
2007-03-20 14:26 ` rguenth at gcc dot gnu dot org
2007-03-20 14:58 ` dominiq at lps dot ens dot fr
2007-03-20 15:07 ` rguenth at gcc dot gnu dot org
2007-03-20 16:09 ` dominiq at lps dot ens dot fr
2007-03-20 16:12 ` rguenth at gcc dot gnu dot org
2007-03-20 16:14 ` pinskia at gcc dot gnu dot org
2007-03-21 15:36 ` dominiq at lps dot ens dot fr
2007-03-21 15:57 ` rguenth at gcc dot gnu dot org
2007-03-21 16:09 ` dominiq at lps dot ens dot fr
2009-12-04 17:10 ` [Bug middle-end/31249] pseudo-optimization " dominiq at lps dot ens dot fr

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).