]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Bogus and missed folding on vector compares
authorRichard Biener <rguenther@suse.de>
Fri, 23 Jun 2023 08:15:27 +0000 (10:15 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 23 Jun 2023 09:22:38 +0000 (11:22 +0200)
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.

gcc/fold-const.cc
gcc/match.pd

index 3aa6851acd5eed486bad2da13560314ab95bb7aa..b05b3ae16e938eb6814b40500258af7af787de42 100644 (file)
@@ -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));
index 2dd23826034627ac5ee74821d9ec81f92c2a3baa..85d562a531d2af2f019eb78a926424e1c3880435 100644 (file)
@@ -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))))))))