public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/57071] New: Optimize  (-1)**k  to 1 - 2 * mod(K, 2)
@ 2013-04-25 17:59 burnus at gcc dot gnu.org
  2013-04-25 18:06 ` [Bug fortran/57071] " burnus at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: burnus at gcc dot gnu.org @ 2013-04-25 17:59 UTC (permalink / raw)
  To: gcc-bugs


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


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

end of thread, other threads:[~2013-05-17 23:06 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-25 17:59 [Bug fortran/57071] New: Optimize (-1)**k to 1 - 2 * mod(K, 2) burnus at gcc dot gnu.org
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

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