public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Prevent TYPE_PRECISION on VECTOR_TYPEs
@ 2023-06-27  9:45 Richard Biener
  2023-06-27  9:47 ` Jakub Jelinek
  0 siblings, 1 reply; 17+ messages in thread
From: Richard Biener @ 2023-06-27  9:45 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek, jeffreyalaw

The following makes sure that using TYPE_PRECISION on VECTOR_TYPE
ICEs when tree checking is enabled.  This should avoid wrong-code
in cases like PR110182 and instead ICE.

It also introduces a TYPE_PRECISION_RAW accessor and adjusts
places I found that are eligible to use that.

Bootstrapped and tested on x86_64-unknown-linux-gnu with all
languages enabled.

OK for trunk?  There is definitely going to be fallout but it
should be straight-forward to fix with quick fixes using
TYPE_PRECISION_RAW possible.

Thanks,
Richard.

	* tree.h (TYPE_PRECISION): Check for non-VECTOR_TYPE.
	(TYPE_PRECISION_RAW): Provide raw access to the precision
	field.
	* tree.cc (verify_type_variant): Compare TYPE_PRECISION_RAW.
	(gimple_canonical_types_compatible_p): Likewise.
	* tree-streamer-out.cc (pack_ts_type_common_value_fields):
	Stream TYPE_PRECISION_RAW.
	* tree-streamer-in.cc (unpack_ts_type_common_value_fields):
	Likewise.
	* lto-streamer-out.cc (hash_tree): Hash TYPE_PRECISION_RAW.

gcc/lto/
	* lto-common.cc (compare_tree_sccs_1): Use TYPE_PRECISION_RAW.
---
 gcc/lto-streamer-out.cc  | 2 +-
 gcc/lto/lto-common.cc    | 2 +-
 gcc/tree-streamer-in.cc  | 2 +-
 gcc/tree-streamer-out.cc | 2 +-
 gcc/tree.cc              | 6 +++---
 gcc/tree.h               | 4 +++-
 6 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/gcc/lto-streamer-out.cc b/gcc/lto-streamer-out.cc
index 5ab2eb4301e..3432dd434e2 100644
--- a/gcc/lto-streamer-out.cc
+++ b/gcc/lto-streamer-out.cc
@@ -1373,7 +1373,7 @@ hash_tree (struct streamer_tree_cache_d *cache, hash_map<tree, hashval_t> *map,
       if (AGGREGATE_TYPE_P (t))
 	hstate.add_flag (TYPE_TYPELESS_STORAGE (t));
       hstate.commit_flag ();
-      hstate.add_int (TYPE_PRECISION (t));
+      hstate.add_int (TYPE_PRECISION_RAW (t));
       hstate.add_int (TYPE_ALIGN (t));
       hstate.add_int (TYPE_EMPTY_P (t));
     }
diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc
index 537570204b3..afe051edf74 100644
--- a/gcc/lto/lto-common.cc
+++ b/gcc/lto/lto-common.cc
@@ -1280,7 +1280,7 @@ compare_tree_sccs_1 (tree t1, tree t2, tree **map)
       compare_values (TYPE_RESTRICT);
       compare_values (TYPE_USER_ALIGN);
       compare_values (TYPE_READONLY);
-      compare_values (TYPE_PRECISION);
+      compare_values (TYPE_PRECISION_RAW);
       compare_values (TYPE_ALIGN);
       /* Do not compare TYPE_ALIAS_SET.  Doing so introduce ordering issues
 	 with calls to get_alias_set which may initialize it for streamed
diff --git a/gcc/tree-streamer-in.cc b/gcc/tree-streamer-in.cc
index c803800862c..e6919e463c0 100644
--- a/gcc/tree-streamer-in.cc
+++ b/gcc/tree-streamer-in.cc
@@ -387,7 +387,7 @@ unpack_ts_type_common_value_fields (struct bitpack_d *bp, tree expr)
     TYPE_TYPELESS_STORAGE (expr) = (unsigned) bp_unpack_value (bp, 1);
   TYPE_EMPTY_P (expr) = (unsigned) bp_unpack_value (bp, 1);
   TYPE_NO_NAMED_ARGS_STDARG_P (expr) = (unsigned) bp_unpack_value (bp, 1);
-  TYPE_PRECISION (expr) = bp_unpack_var_len_unsigned (bp);
+  TYPE_PRECISION_RAW (expr) = bp_unpack_var_len_unsigned (bp);
   SET_TYPE_ALIGN (expr, bp_unpack_var_len_unsigned (bp));
 #ifdef ACCEL_COMPILER
   if (TYPE_ALIGN (expr) > targetm.absolute_biggest_alignment)
diff --git a/gcc/tree-streamer-out.cc b/gcc/tree-streamer-out.cc
index 5751f77273b..719cbeacf99 100644
--- a/gcc/tree-streamer-out.cc
+++ b/gcc/tree-streamer-out.cc
@@ -356,7 +356,7 @@ pack_ts_type_common_value_fields (struct bitpack_d *bp, tree expr)
     bp_pack_value (bp, TYPE_TYPELESS_STORAGE (expr), 1);
   bp_pack_value (bp, TYPE_EMPTY_P (expr), 1);
   bp_pack_value (bp, TYPE_NO_NAMED_ARGS_STDARG_P (expr), 1);
-  bp_pack_var_len_unsigned (bp, TYPE_PRECISION (expr));
+  bp_pack_var_len_unsigned (bp, TYPE_PRECISION_RAW (expr));
   bp_pack_var_len_unsigned (bp, TYPE_ALIGN (expr));
 }
 
diff --git a/gcc/tree.cc b/gcc/tree.cc
index 8e144bc090e..58288efa2e2 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -13423,7 +13423,7 @@ verify_type_variant (const_tree t, tree tv)
 	}
       verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
     }
-  verify_variant_match (TYPE_PRECISION);
+  verify_variant_match (TYPE_PRECISION_RAW);
   if (RECORD_OR_UNION_TYPE_P (t))
     verify_variant_match (TYPE_TRANSPARENT_AGGR);
   else if (TREE_CODE (t) == ARRAY_TYPE)
@@ -13701,8 +13701,8 @@ gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
       || TREE_CODE (t1) == OFFSET_TYPE
       || POINTER_TYPE_P (t1))
     {
-      /* Can't be the same type if they have different recision.  */
-      if (TYPE_PRECISION (t1) != TYPE_PRECISION (t2))
+      /* Can't be the same type if they have different precision.  */
+      if (TYPE_PRECISION_RAW (t1) != TYPE_PRECISION_RAW (t2))
 	return false;
 
       /* In some cases the signed and unsigned types are required to be
diff --git a/gcc/tree.h b/gcc/tree.h
index 1854fe4a7d4..1b791335d38 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -2191,7 +2191,9 @@ class auto_suppress_location_wrappers
 #define TYPE_SIZE_UNIT(NODE) (TYPE_CHECK (NODE)->type_common.size_unit)
 #define TYPE_POINTER_TO(NODE) (TYPE_CHECK (NODE)->type_common.pointer_to)
 #define TYPE_REFERENCE_TO(NODE) (TYPE_CHECK (NODE)->type_common.reference_to)
-#define TYPE_PRECISION(NODE) (TYPE_CHECK (NODE)->type_common.precision)
+#define TYPE_PRECISION(NODE) \
+  (TREE_NOT_CHECK (TYPE_CHECK (NODE), VECTOR_TYPE)->type_common.precision)
+#define TYPE_PRECISION_RAW(NODE) (TYPE_CHECK (NODE)->type_common.precision)
 #define TYPE_NAME(NODE) (TYPE_CHECK (NODE)->type_common.name)
 #define TYPE_NEXT_VARIANT(NODE) (TYPE_CHECK (NODE)->type_common.next_variant)
 #define TYPE_MAIN_VARIANT(NODE) (TYPE_CHECK (NODE)->type_common.main_variant)
-- 
2.35.3

^ permalink raw reply	[flat|nested] 17+ messages in thread
* Re: [PATCH] Prevent TYPE_PRECISION on VECTOR_TYPEs
@ 2023-06-09 11:23 Richard Biener
  2023-06-09 11:53 ` Richard Biener
  0 siblings, 1 reply; 17+ messages in thread
From: Richard Biener @ 2023-06-09 11:23 UTC (permalink / raw)
  To: gcc-patches; +Cc: pinskia

On Fri, 9 Jun 2023, Richard Biener wrote:

> The following makes sure that using TYPE_PRECISION on VECTOR_TYPE
> ICEs when tree checking is enabled.  This should avoid wrong-code
> in cases like PR110182 and instead ICE.
> 
> Bootstrap and regtest pending on x86_64-unknown-linux-gnu, I guess
> there will be some fallout of such change ...

The following is what I need to get it to boostrap on 
x86_64-unknown-linux-gnu (with all languages enabled).

I think some cases warrant a TYPE_PRECISION_RAW but most
are fixing existing errors.  For some cases I didn't dig
deep enough if the code also needs to compare TYPE_VECTOR_SUBPARTS.

The testsuite is running and shows more issues ...

I put this on hold for the moment but hope to get back to it at
some point.  I'll followup with the testresults though.

Richard.


diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index 9c8eed5442a..34566a342bd 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -1338,6 +1338,10 @@ shorten_binary_op (tree result_type, tree op0, tree op1, bool bitwise)
   int uns;
   tree type;
 
+  /* Do not shorten vector operations.  */
+  if (VECTOR_TYPE_P (result_type))
+    return result_type;
+
   /* Cast OP0 and OP1 to RESULT_TYPE.  Doing so prevents
      excessive narrowing when we call get_narrower below.  For
      example, suppose that OP0 is of unsigned int extended
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index 3f3c6685bb3..a8c033ba008 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -12574,10 +12574,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));
@@ -14540,7 +14540,8 @@ tree_expr_maybe_real_minus_zero_p (const_tree x)
 static bool
 tree_simple_nonnegative_warnv_p (enum tree_code code, tree type)
 {
-  if ((TYPE_PRECISION (type) != 1 || TYPE_UNSIGNED (type))
+  if (!VECTOR_TYPE_P (type)
+      && (TYPE_PRECISION (type) != 1 || TYPE_UNSIGNED (type))
       && truth_value_p (code))
     /* Truth values evaluate to 0 or 1, which is nonnegative unless we
        have a signed:1 type (where the value is -1 and 0).  */
diff --git a/gcc/tree-ssa-scopedtables.cc b/gcc/tree-ssa-scopedtables.cc
index 528ddf2a2ab..e698ef97343 100644
--- a/gcc/tree-ssa-scopedtables.cc
+++ b/gcc/tree-ssa-scopedtables.cc
@@ -574,7 +574,7 @@ hashable_expr_equal_p (const struct hashable_expr *expr0,
       && (TREE_CODE (type0) == ERROR_MARK
 	  || TREE_CODE (type1) == ERROR_MARK
 	  || TYPE_UNSIGNED (type0) != TYPE_UNSIGNED (type1)
-	  || TYPE_PRECISION (type0) != TYPE_PRECISION (type1)
+	  || element_precision (type0) != element_precision (type1)
 	  || TYPE_MODE (type0) != TYPE_MODE (type1)))
     return false;
 
diff --git a/gcc/tree.cc b/gcc/tree.cc
index 8e144bc090e..4b43e209c6e 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -13423,7 +13423,10 @@ verify_type_variant (const_tree t, tree tv)
 	}
       verify_variant_match (TYPE_NEEDS_CONSTRUCTING);
     }
-  verify_variant_match (TYPE_PRECISION);
+  /* ???  Need a TYPE_PRECISION_RAW here?  TYPE_VECTOR_SUBPARTS
+     is a poly-int.  */
+  if (!VECTOR_TYPE_P (t))
+    verify_variant_match (TYPE_PRECISION);
   if (RECORD_OR_UNION_TYPE_P (t))
     verify_variant_match (TYPE_TRANSPARENT_AGGR);
   else if (TREE_CODE (t) == ARRAY_TYPE)
@@ -13701,8 +13704,12 @@ gimple_canonical_types_compatible_p (const_tree t1, const_tree t2,
       || TREE_CODE (t1) == OFFSET_TYPE
       || POINTER_TYPE_P (t1))
     {
-      /* Can't be the same type if they have different recision.  */
-      if (TYPE_PRECISION (t1) != TYPE_PRECISION (t2))
+      /* Can't be the same type if they have different precision.  */
+      /* ??? TYPE_PRECISION_RAW for speed.  */
+      if ((VECTOR_TYPE_P (t1)
+	   && maybe_ne (TYPE_VECTOR_SUBPARTS (t1), TYPE_VECTOR_SUBPARTS (t2)))
+	  || (!VECTOR_TYPE_P (t1)
+	      && TYPE_PRECISION (t1) != TYPE_PRECISION (t2)))
 	return false;
 
       /* In some cases the signed and unsigned types are required to be

^ permalink raw reply	[flat|nested] 17+ messages in thread
* [PATCH] Prevent TYPE_PRECISION on VECTOR_TYPEs
@ 2023-06-09  7:40 Richard Biener
  0 siblings, 0 replies; 17+ messages in thread
From: Richard Biener @ 2023-06-09  7:40 UTC (permalink / raw)
  To: gcc-patches; +Cc: pinskia

The following makes sure that using TYPE_PRECISION on VECTOR_TYPE
ICEs when tree checking is enabled.  This should avoid wrong-code
in cases like PR110182 and instead ICE.

Bootstrap and regtest pending on x86_64-unknown-linux-gnu, I guess
there will be some fallout of such change ...

	* tree.h (TYPE_PRECISION): Check for non-VECTOR_TYPE.
---
 gcc/tree.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/tree.h b/gcc/tree.h
index 1854fe4a7d4..9c525d14474 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -2191,7 +2191,8 @@ class auto_suppress_location_wrappers
 #define TYPE_SIZE_UNIT(NODE) (TYPE_CHECK (NODE)->type_common.size_unit)
 #define TYPE_POINTER_TO(NODE) (TYPE_CHECK (NODE)->type_common.pointer_to)
 #define TYPE_REFERENCE_TO(NODE) (TYPE_CHECK (NODE)->type_common.reference_to)
-#define TYPE_PRECISION(NODE) (TYPE_CHECK (NODE)->type_common.precision)
+#define TYPE_PRECISION(NODE) \
+  (TREE_NOT_CHECK (TYPE_CHECK (NODE), VECTOR_TYPE)->type_common.precision)
 #define TYPE_NAME(NODE) (TYPE_CHECK (NODE)->type_common.name)
 #define TYPE_NEXT_VARIANT(NODE) (TYPE_CHECK (NODE)->type_common.next_variant)
 #define TYPE_MAIN_VARIANT(NODE) (TYPE_CHECK (NODE)->type_common.main_variant)
-- 
2.35.3

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

end of thread, other threads:[~2023-06-29 15:13 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-27  9:45 [PATCH] Prevent TYPE_PRECISION on VECTOR_TYPEs Richard Biener
2023-06-27  9:47 ` Jakub Jelinek
2023-06-29  4:04   ` Li, Pan2
2023-06-29  4:18     ` Li, Pan2
2023-06-29 10:03       ` juzhe.zhong
2023-06-29 10:06         ` Robin Dapp
2023-06-29 10:07           ` Robin Dapp
2023-06-29 10:09             ` juzhe.zhong
2023-06-29  4:25     ` Jeff Law
2023-06-29  8:11       ` Richard Biener
2023-06-29  9:55         ` Robin Dapp
2023-06-29  9:56           ` Richard Biener
2023-06-29 11:07             ` Robin Dapp
2023-06-29 15:13         ` Jeff Law
  -- strict thread matches above, loose matches on Subject: below --
2023-06-09 11:23 Richard Biener
2023-06-09 11:53 ` Richard Biener
2023-06-09  7:40 Richard Biener

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