public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/57071] New: Optimize (-1)**k to 1 - 2 * mod(K, 2) Date: Thu, 25 Apr 2013 17:59:00 -0000 [thread overview] Message-ID: <bug-57071-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57071 Bug #: 57071 Summary: Optimize (-1)**k to 1 - 2 * mod(K, 2) Classification: Unclassified Product: gcc Version: 4.9.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned@gcc.gnu.org ReportedBy: burnus@gcc.gnu.org CC: tkoenig@gcc.gnu.org Motivated by https://groups.google.com/forum/?fromgroups=#!topic/comp.lang.fortran/60jYF5XEY3c The code (k is an integer): (-1)**k and (-1.0)**k can be rather common in numeric code. The former is converted into _gfortran_pow_i4_i4 (-1, *k); the latter is __builtin_powif (-1.0e+0, *k); However, for (-1)**k, the result is simply 1 is k is even and -1 if it is odd, or in other words: 1 - 2 * mod(K, 2) integer function f(k) f = (-1)**k ! Or: (-1.0)**k end
next reply other threads:[~2013-04-25 17:59 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-04-25 17:59 burnus at gcc dot gnu.org [this message] 2013-04-25 18:06 ` [Bug fortran/57071] " burnus at gcc dot gnu.org 2013-04-26 6:52 ` Joost.VandeVondele at mat dot ethz.ch 2013-04-26 7:07 ` burnus at gcc dot gnu.org 2013-04-26 7:12 ` Joost.VandeVondele at mat dot ethz.ch 2013-04-26 7:26 ` burnus at gcc dot gnu.org 2013-04-26 9:16 ` rguenth at gcc dot gnu.org 2013-04-27 23:19 ` tkoenig at gcc dot gnu.org 2013-04-28 13:34 ` tkoenig at gcc dot gnu.org 2013-04-30 21:46 ` tkoenig at gcc dot gnu.org 2013-04-30 21:49 ` tkoenig at gcc dot gnu.org 2013-05-17 23:05 ` tkoenig at gcc dot gnu.org 2013-05-17 23:06 ` tkoenig at gcc dot gnu.org
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-57071-4@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).