public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "dominiq at lps dot ens dot fr" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/31249] New: pseudo-optimzation with sincos/cexpi Date: Sat, 17 Mar 2007 21:11:00 -0000 [thread overview] Message-ID: <bug-31249-12313@http.gcc.gnu.org/bugzilla/> (raw) 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
next reply other threads:[~2007-03-17 21:11 UTC|newest] Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top 2007-03-17 21:11 dominiq at lps dot ens dot fr [this message] 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
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-31249-12313@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: linkBe 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).