public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Kewen Lin <linkw@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-4815] fold-const: Treat fp conversion to a type with same mode as copy
Date: Wed, 21 Dec 2022 03:07:47 +0000 (GMT)	[thread overview]
Message-ID: <20221221030747.BCA3A385B51C@sourceware.org> (raw)

https://gcc.gnu.org/g:94cf7a2d95bf6db873cdcc4085a697ad40057957

commit r13-4815-g94cf7a2d95bf6db873cdcc4085a697ad40057957
Author: Kewen Lin <linkw@linux.ibm.com>
Date:   Tue Dec 20 21:04:54 2022 -0600

    fold-const: Treat fp conversion to a type with same mode as copy
    
    In function fold_convert_const_real_from_real, when the modes of
    two types involved in fp conversion are the same, we can simply
    take it as copy, rebuild with the exactly same TREE_REAL_CST and
    the target type.  It is more efficient and helps to avoid possible
    unexpected signalling bit clearing in [1].
    
    [1] https://gcc.gnu.org/pipermail/gcc-patches/2022-December/608533.html
    
    gcc/ChangeLog:
    
            * fold-const.cc (fold_convert_const_real_from_real): Treat floating
            point conversion to a type with same mode as copy instead of normal
            convertFormat.

Diff:
---
 gcc/fold-const.cc | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 00e2af0680c..d4ee3b30983 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -2178,6 +2178,15 @@ fold_convert_const_real_from_real (tree type, const_tree arg1)
   REAL_VALUE_TYPE value;
   tree t;
 
+  /* If the underlying modes are the same, simply treat it as
+     copy and rebuild with TREE_REAL_CST information and the
+     given type.  */
+  if (TYPE_MODE (type) == TYPE_MODE (TREE_TYPE (arg1)))
+    {
+      t = build_real (type, TREE_REAL_CST (arg1));
+      return t;
+    }
+
   /* Don't perform the operation if flag_signaling_nans is on
      and the operand is a signaling NaN.  */
   if (HONOR_SNANS (arg1)

                 reply	other threads:[~2022-12-21  3:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20221221030747.BCA3A385B51C@sourceware.org \
    --to=linkw@gcc.gnu.org \
    --cc=gcc-cvs@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).