public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kargl at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/107294] Missed optimization: multiplying real with complex number in Fortran (only)
Date: Mon, 17 Oct 2022 15:14:03 +0000	[thread overview]
Message-ID: <bug-107294-4-XIXKXPOcdq@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107294-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107294

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #3 from kargl at gcc dot gnu.org ---
(In reply to Richard Biener from comment #1)

> Not sure who is correct, or if both are and we can optimize the multiply
> by zero here (maybe in the context of a - b * 0.0 and a + b * 0.0).

The Fortran behavior is specified in Fortran 2023 (22-007r1.pdf) in


  10.1.5.2.1 Interpretation of numeric intrinsic operations
  ...
  Except for a value of type real or complex raised to an integer power,
  if the operands have different types or kind type parameters, the
  effect is as if each operand that differs in type or kind type
  parameter from those of the result is converted to the type and kind
  type parameter of the result before the operation is performed.  When
  a value of type real or complex is raised to an integer power, the
  integer operand need not be converted.

So, 
  __result_csmul = COMPLEX_EXPR <a, 0.0> * b;

is correct.  There is a caveat.  The Fortran standard does not mandate
the sign of zero.  If one wants to ignore exceptional values (i.e.,
0 * NaN, 0 * +-inf ), then one could annotate 0.0 to be +0.  But, that
will lead to so seriously flawed computations.

This should probably be closed with WONTFIX.

PS: -ffast-math might produce the optimized assembly.

  parent reply	other threads:[~2022-10-17 15:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-17 12:39 [Bug fortran/107294] New: " bartoldeman at users dot sourceforge.net
2022-10-17 12:58 ` [Bug fortran/107294] " rguenth at gcc dot gnu.org
2022-10-17 13:02 ` rguenth at gcc dot gnu.org
2022-10-17 15:14 ` kargl at gcc dot gnu.org [this message]
2022-10-17 16:13 ` bartoldeman at users dot sourceforge.net
2022-10-17 16:14 ` bartoldeman at users dot sourceforge.net

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-107294-4-XIXKXPOcdq@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: link
Be 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).