public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-2040] Bogus and missed folding on vector compares
Date: Fri, 23 Jun 2023 09:23:41 +0000 (GMT)	[thread overview]
Message-ID: <20230623092341.1BFE83858D20@sourceware.org> (raw)

https://gcc.gnu.org/g:6b32400e19a702137fd11571d199f725add0daf6

commit r14-2040-g6b32400e19a702137fd11571d199f725add0daf6
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Jun 23 10:15:27 2023 +0200

    Bogus and missed folding on vector compares
    
    fold_binary tries to transform (double)float1 CMP (double)float2
    into float1 CMP float2 but ends up using TYPE_PRECISION on the
    argument types.  For vector types that compares the number of
    lanes which should be always equal (so it's harmless as to
    not generating wrong code).  The following instead properly
    uses element_precision.
    
    The same happens in the corresponding match.pd pattern.
    
            * fold-const.cc (fold_binary_loc): Use element_precision
            when trying (double)float1 CMP (double)float2 to
            float1 CMP float2 simplification.
            * match.pd: Likewise.

Diff:
---
 gcc/fold-const.cc | 4 ++--
 gcc/match.pd      | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 3aa6851acd5..b05b3ae16e9 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -12564,10 +12564,10 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
 	tree targ1 = strip_float_extensions (arg1);
 	tree newtype = TREE_TYPE (targ0);
 
-	if (TYPE_PRECISION (TREE_TYPE (targ1)) > TYPE_PRECISION (newtype))
+	if (element_precision (TREE_TYPE (targ1)) > element_precision (newtype))
 	  newtype = TREE_TYPE (targ1);
 
-	if (TYPE_PRECISION (newtype) < TYPE_PRECISION (TREE_TYPE (arg0)))
+	if (element_precision (newtype) < element_precision (TREE_TYPE (arg0)))
 	  return fold_build2_loc (loc, code, type,
 			      fold_convert_loc (loc, newtype, targ0),
 			      fold_convert_loc (loc, newtype, targ1));
diff --git a/gcc/match.pd b/gcc/match.pd
index 2dd23826034..85d562a531d 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6034,10 +6034,10 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 	     type1 = double_type_node;
 	 }
       tree newtype
-        = (TYPE_PRECISION (TREE_TYPE (@00)) > TYPE_PRECISION (type1)
+        = (element_precision (TREE_TYPE (@00)) > element_precision (type1)
 	   ? TREE_TYPE (@00) : type1);
      }
-     (if (TYPE_PRECISION (TREE_TYPE (@0)) > TYPE_PRECISION (newtype))
+     (if (element_precision (TREE_TYPE (@0)) > element_precision (newtype))
       (cmp (convert:newtype @00) (convert:newtype @10))))))))

                 reply	other threads:[~2023-06-23  9:23 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=20230623092341.1BFE83858D20@sourceware.org \
    --to=rguenth@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).