public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-4169] middle-end: use MAX_FIXED_MODE_SIZE instead of precidion of TImode/DImode
@ 2023-09-20  7:46 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2023-09-20  7:46 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:47ecac52bd4cae84dc786731c655c3bfe1ade377

commit r14-4169-g47ecac52bd4cae84dc786731c655c3bfe1ade377
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Sep 20 09:45:42 2023 +0200

    middle-end: use MAX_FIXED_MODE_SIZE instead of precidion of TImode/DImode
    
    On Tue, Sep 19, 2023 at 05:50:59PM +0100, Richard Sandiford wrote:
    > How about using MAX_FIXED_MODE_SIZE for things like this?
    
    Seems like a good idea.
    
    The following patch does that.
    
    2023-09-20  Jakub Jelinek  <jakub@redhat.com>
    
            * match.pd ((x << c) >> c): Use MAX_FIXED_MODE_SIZE instead of
            GET_MODE_PRECISION of TImode or DImode depending on whether
            TImode is supported scalar mode.
            * gimple-lower-bitint.cc (bitint_precision_kind): Likewise.
            * expr.cc (expand_expr_real_1): Likewise.
            * tree-ssa-sccvn.cc (eliminate_dom_walker::eliminate_stmt): Likewise.
            * ubsan.cc (ubsan_encode_value, ubsan_type_descriptor): Likewise.

Diff:
---
 gcc/expr.cc                | 14 ++++----------
 gcc/gimple-lower-bitint.cc | 12 +++++-------
 gcc/match.pd               |  4 +---
 gcc/tree-ssa-sccvn.cc      |  5 +----
 gcc/ubsan.cc               | 38 +++++++++++---------------------------
 5 files changed, 22 insertions(+), 51 deletions(-)

diff --git a/gcc/expr.cc b/gcc/expr.cc
index d5b6494b4fc..308ddc09e63 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -11044,17 +11044,11 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
 	    scalar_int_mode limb_mode
 	      = as_a <scalar_int_mode> (info.limb_mode);
 	    unsigned int limb_prec = GET_MODE_PRECISION (limb_mode);
-	    if (prec > limb_prec)
+	    if (prec > limb_prec && prec > MAX_FIXED_MODE_SIZE)
 	      {
-		scalar_int_mode arith_mode
-		  = (targetm.scalar_mode_supported_p (TImode)
-		     ? TImode : DImode);
-		if (prec > GET_MODE_PRECISION (arith_mode))
-		  {
-		    /* Emit large/huge _BitInt INTEGER_CSTs into memory.  */
-		    exp = tree_output_constant_def (exp);
-		    return expand_expr (exp, target, VOIDmode, modifier);
-		  }
+		/* Emit large/huge _BitInt INTEGER_CSTs into memory.  */
+		exp = tree_output_constant_def (exp);
+		return expand_expr (exp, target, VOIDmode, modifier);
 	      }
 	  }
 
diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index cf4bcfc5ba4..d1651a06b85 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -100,21 +100,19 @@ bitint_precision_kind (int prec)
       small_max_prec = prec;
       return bitint_prec_small;
     }
-  scalar_int_mode arith_mode = (targetm.scalar_mode_supported_p (TImode)
-				? TImode : DImode);
   if (!large_min_prec
-      && GET_MODE_PRECISION (arith_mode) > GET_MODE_PRECISION (limb_mode))
-    large_min_prec = GET_MODE_PRECISION (arith_mode) + 1;
+      && GET_MODE_PRECISION (limb_mode) < MAX_FIXED_MODE_SIZE)
+    large_min_prec = MAX_FIXED_MODE_SIZE + 1;
   if (!limb_prec)
     limb_prec = GET_MODE_PRECISION (limb_mode);
   if (!huge_min_prec)
     {
-      if (4 * limb_prec >= GET_MODE_PRECISION (arith_mode))
+      if (4 * limb_prec >= MAX_FIXED_MODE_SIZE)
 	huge_min_prec = 4 * limb_prec;
       else
-	huge_min_prec = GET_MODE_PRECISION (arith_mode) + 1;
+	huge_min_prec = MAX_FIXED_MODE_SIZE + 1;
     }
-  if (prec <= GET_MODE_PRECISION (arith_mode))
+  if (prec <= MAX_FIXED_MODE_SIZE)
     {
       if (!mid_min_prec || prec < mid_min_prec)
 	mid_min_prec = prec;
diff --git a/gcc/match.pd b/gcc/match.pd
index 919651197f2..a37af05f873 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4124,9 +4124,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
     (with {
       int width = element_precision (type) - tree_to_uhwi (@1);
       tree stype = NULL_TREE;
-      scalar_int_mode mode = (targetm.scalar_mode_supported_p (TImode)
-			      ? TImode : DImode);
-      if (width <= GET_MODE_PRECISION (mode))
+      if (width <= MAX_FIXED_MODE_SIZE)
 	stype = build_nonstandard_integer_type (width, 0);
      }
      (if (stype && (width == 1 || type_has_mode_precision_p (stype)))
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 1eaf5f6a363..e46498568cb 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -7004,10 +7004,7 @@ eliminate_dom_walker::eliminate_stmt (basic_block b, gimple_stmt_iterator *gsi)
 	  && !type_has_mode_precision_p (TREE_TYPE (lhs)))
 	{
 	  if (TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE
-	      && (TYPE_PRECISION (TREE_TYPE (lhs))
-		  > (targetm.scalar_mode_supported_p (TImode)
-		     ? GET_MODE_PRECISION (TImode)
-		     : GET_MODE_PRECISION (DImode))))
+	      && TYPE_PRECISION (TREE_TYPE (lhs)) > MAX_FIXED_MODE_SIZE)
 	    lookup_lhs = NULL_TREE;
 	  else if (TREE_CODE (lhs) == COMPONENT_REF
 		   || TREE_CODE (lhs) == MEM_REF)
diff --git a/gcc/ubsan.cc b/gcc/ubsan.cc
index 25726df8ce9..4289ff41785 100644
--- a/gcc/ubsan.cc
+++ b/gcc/ubsan.cc
@@ -136,13 +136,10 @@ ubsan_encode_value (tree t, enum ubsan_encode_value_phase phase)
 	}
       else
 	{
-	  scalar_int_mode arith_mode
-	    = (targetm.scalar_mode_supported_p (TImode) ? TImode : DImode);
-	  if (TYPE_PRECISION (type) > GET_MODE_PRECISION (arith_mode))
+	  if (TYPE_PRECISION (type) > MAX_FIXED_MODE_SIZE)
 	    return build_zero_cst (pointer_sized_int_node);
-	  type
-	    = build_nonstandard_integer_type (GET_MODE_PRECISION (arith_mode),
-					      TYPE_UNSIGNED (type));
+	  type = build_nonstandard_integer_type (MAX_FIXED_MODE_SIZE,
+	  					 TYPE_UNSIGNED (type));
 	  t = fold_build1 (NOP_EXPR, type, t);
 	}
     }
@@ -381,14 +378,9 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
     {
       /* Temporary hack for -fsanitize=shift with _BitInt(129) and more.
 	 libubsan crashes if it is not TK_Integer type.  */
-      if (TREE_CODE (type) == BITINT_TYPE)
-	{
-	  scalar_int_mode arith_mode
-	    = (targetm.scalar_mode_supported_p (TImode)
-	       ? TImode : DImode);
-	  if (TYPE_PRECISION (type) > GET_MODE_PRECISION (arith_mode))
-	    type3 = build_qualified_type (type, TYPE_QUAL_CONST);
-	}
+      if (TREE_CODE (type) == BITINT_TYPE
+	  && TYPE_PRECISION (type) > MAX_FIXED_MODE_SIZE)
+	type3 = build_qualified_type (type, TYPE_QUAL_CONST);
       if (type3 == type)
 	pstyle = UBSAN_PRINT_NORMAL;
     }
@@ -523,16 +515,10 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
       tkind = 0x0000;
       break;
     case BITINT_TYPE:
-      {
-	/* FIXME: libubsan right now only supports _BitInts which
-	   fit into DImode or TImode.  */
-	scalar_int_mode arith_mode = (targetm.scalar_mode_supported_p (TImode)
-				      ? TImode : DImode);
-	if (TYPE_PRECISION (eltype) <= GET_MODE_PRECISION (arith_mode))
-	  tkind = 0x0000;
-	else
-	  tkind = 0xffff;
-      }
+      if (TYPE_PRECISION (eltype) <= MAX_FIXED_MODE_SIZE)
+	tkind = 0x0000;
+      else
+	tkind = 0xffff;
       break;
     case REAL_TYPE:
       /* FIXME: libubsan right now only supports float, double and
@@ -553,9 +539,7 @@ ubsan_type_descriptor (tree type, enum ubsan_print_style pstyle)
   if (pstyle == UBSAN_PRINT_FORCE_INT)
     {
       tkind = 0x0000;
-      scalar_int_mode arith_mode = (targetm.scalar_mode_supported_p (TImode)
-				    ? TImode : DImode);
-      tree t = lang_hooks.types.type_for_mode (arith_mode,
+      tree t = build_nonstandard_integer_type (MAX_FIXED_MODE_SIZE,
 					       TYPE_UNSIGNED (eltype));
       tinfo = get_ubsan_type_info_for_type (t);
     }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-20  7:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-20  7:46 [gcc r14-4169] middle-end: use MAX_FIXED_MODE_SIZE instead of precidion of TImode/DImode Jakub Jelinek

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