public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] match.pd: Some build_nonstandard_integer_type tweaks
@ 2023-09-19  7:48 Jakub Jelinek
  2023-09-19  8:40 ` Richard Biener
  2023-09-19 16:50 ` Richard Sandiford
  0 siblings, 2 replies; 5+ messages in thread
From: Jakub Jelinek @ 2023-09-19  7:48 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches, Andrew Pinski

Hi!

As discussed earlier, using build_nonstandard_integer_type blindly for all
INTEGRAL_TYPE_Ps is problematic now that we have BITINT_TYPE, because it
always creates an INTEGRAL_TYPE with some possibly very large precision.
The following patch attempts to deal with 3 such spots in match.pd, others
still need looking at.

In the first case, I think it is quite expensive/undesirable to create
a non-standard INTEGER_TYPE with possibly huge precision and then
immediately just see type_has_mode_precision_p being false for it, or even
worse introducing a cast to TImode or OImode or XImode INTEGER_TYPE which
nothing will be able to actually handle.  128-bit or 64-bit (on 32-bit
targets) types are the largest supported by the backend, so the following
patch avoids creating and matching conversions to larger types, it is
an optimization anyway and so should be used when it is cheap that way.

In the second hunk, I believe the uses of build_nonstandard_integer_type
aren't useful at all.  It is when matching a ? -1 : 0 and trying to express
it as say -(type) (bool) a etc., but this is all GIMPLE only, where most of
integral types with same precision/signedness are compatible and we know
-1 is representable in that type, so I really don't see any reason not to
perform the negation of a [0, 1] valued expression in type, rather
than doing it in
build_nonstandard_integer_type (TYPE_PRECISION (type), TYPE_UNSIGNED (type))
(except that it breaks the BITINT_TYPEs).  I don't think we need to do
something like range_check_type.
While in there, I've also noticed it was using a (with {
tree booltrue = constant_boolean_node (true, boolean_type_node);
} and removed that + replaced uses of booltrue with boolean_true_node
which the above function always returns.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2023-09-19  Jakub Jelinek  <jakub@redhat.com>

	* match.pd ((x << c) >> c): Don't call build_nonstandard_integer_type
	nor check type_has_mode_precision_p for width larger than [TD]Imode
	precision.
	(a ? CST1 : CST2): Don't use build_nonstandard_type, just convert
	to type.  Use boolean_true_node instead of
	constant_boolean_node (true, boolean_type_node).  Formatting fixes.

--- gcc/match.pd.jj	2023-09-18 10:37:56.002965361 +0200
+++ gcc/match.pd	2023-09-18 12:14:32.321631010 +0200
@@ -4114,9 +4114,13 @@ (define_operator_list SYNC_FETCH_AND_AND
    (if (INTEGRAL_TYPE_P (type))
     (with {
       int width = element_precision (type) - tree_to_uhwi (@1);
-      tree stype = build_nonstandard_integer_type (width, 0);
+      tree stype = NULL_TREE;
+      scalar_int_mode mode = (targetm.scalar_mode_supported_p (TImode)
+			      ? TImode : DImode);
+      if (width <= GET_MODE_PRECISION (mode))
+	stype = build_nonstandard_integer_type (width, 0);
      }
-     (if (width == 1 || type_has_mode_precision_p (stype))
+     (if (stype && (width == 1 || type_has_mode_precision_p (stype)))
       (convert (convert:stype @0))))))))
 
 /* Optimize x >> x into 0 */
@@ -5092,49 +5096,24 @@ (define_operator_list SYNC_FETCH_AND_AND
     /* a ? -1 : 0 -> -a.  No need to check the TYPE_PRECISION not being 1
        here as the powerof2cst case above will handle that case correctly.  */
     (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1))
+     (negate (convert:type (convert:boolean_type_node @0))))))
+  (if (integer_zerop (@1))
+   (switch
+    /* a ? 0 : 1 -> !a. */
+    (if (integer_onep (@2))
+     (convert (bit_xor (convert:boolean_type_node @0) { boolean_true_node; })))
+    /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */
+    (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@2))
      (with {
-       auto prec = TYPE_PRECISION (type);
-       auto unsign = TYPE_UNSIGNED (type);
-       tree inttype = build_nonstandard_integer_type (prec, unsign);
+       tree shift = build_int_cst (integer_type_node, tree_log2 (@2));
       }
-      (convert (negate (convert:inttype (convert:boolean_type_node @0))))))))
-  (if (integer_zerop (@1))
-   (with {
-      tree booltrue = constant_boolean_node (true, boolean_type_node);
-    }
-    (switch
-     /* a ? 0 : 1 -> !a. */
-     (if (integer_onep (@2))
-      (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )))
-     /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */
-     (if (INTEGRAL_TYPE_P (type) &&  integer_pow2p (@2))
-      (with {
-	tree shift = build_int_cst (integer_type_node, tree_log2 (@2));
-       }
-       (lshift (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } ))
-        { shift; })))
-     /* a ? -1 : 0 -> -(!a).  No need to check the TYPE_PRECISION not being 1
+      (lshift (convert (bit_xor (convert:boolean_type_node @0)
+				{ boolean_true_node; })) { shift; })))
+    /* a ? -1 : 0 -> -(!a).  No need to check the TYPE_PRECISION not being 1
        here as the powerof2cst case above will handle that case correctly.  */
-     (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2))
-      (with {
-	auto prec = TYPE_PRECISION (type);
-	auto unsign = TYPE_UNSIGNED (type);
-	tree inttype = build_nonstandard_integer_type (prec, unsign);
-       }
-       (convert
-	(negate
-         (convert:inttype
-	  (bit_xor (convert:boolean_type_node @0) { booltrue; } )
-	 )
-	)
-       )
-      )
-     )
-    )
-   )
-  )
- )
-)
+    (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2))
+     (negate (convert:type (bit_xor (convert:boolean_type_node @0)
+				    { boolean_true_node; }))))))))
 
 /* (a > 1) ? 0 : (cast)a is the same as (cast)(a == 1)
    for unsigned types. */

	Jakub


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

* Re: [PATCH] match.pd: Some build_nonstandard_integer_type tweaks
  2023-09-19  7:48 [PATCH] match.pd: Some build_nonstandard_integer_type tweaks Jakub Jelinek
@ 2023-09-19  8:40 ` Richard Biener
  2023-09-19 16:50 ` Richard Sandiford
  1 sibling, 0 replies; 5+ messages in thread
From: Richard Biener @ 2023-09-19  8:40 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Andrew Pinski

On Tue, 19 Sep 2023, Jakub Jelinek wrote:

> Hi!
> 
> As discussed earlier, using build_nonstandard_integer_type blindly for all
> INTEGRAL_TYPE_Ps is problematic now that we have BITINT_TYPE, because it
> always creates an INTEGRAL_TYPE with some possibly very large precision.
> The following patch attempts to deal with 3 such spots in match.pd, others
> still need looking at.
> 
> In the first case, I think it is quite expensive/undesirable to create
> a non-standard INTEGER_TYPE with possibly huge precision and then
> immediately just see type_has_mode_precision_p being false for it, or even
> worse introducing a cast to TImode or OImode or XImode INTEGER_TYPE which
> nothing will be able to actually handle.  128-bit or 64-bit (on 32-bit
> targets) types are the largest supported by the backend, so the following
> patch avoids creating and matching conversions to larger types, it is
> an optimization anyway and so should be used when it is cheap that way.
> 
> In the second hunk, I believe the uses of build_nonstandard_integer_type
> aren't useful at all.  It is when matching a ? -1 : 0 and trying to express
> it as say -(type) (bool) a etc., but this is all GIMPLE only, where most of
> integral types with same precision/signedness are compatible and we know
> -1 is representable in that type, so I really don't see any reason not to
> perform the negation of a [0, 1] valued expression in type, rather
> than doing it in
> build_nonstandard_integer_type (TYPE_PRECISION (type), TYPE_UNSIGNED (type))
> (except that it breaks the BITINT_TYPEs).  I don't think we need to do
> something like range_check_type.
> While in there, I've also noticed it was using a (with {
> tree booltrue = constant_boolean_node (true, boolean_type_node);
> } and removed that + replaced uses of booltrue with boolean_true_node
> which the above function always returns.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Thanks,
Richard.

> 2023-09-19  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* match.pd ((x << c) >> c): Don't call build_nonstandard_integer_type
> 	nor check type_has_mode_precision_p for width larger than [TD]Imode
> 	precision.
> 	(a ? CST1 : CST2): Don't use build_nonstandard_type, just convert
> 	to type.  Use boolean_true_node instead of
> 	constant_boolean_node (true, boolean_type_node).  Formatting fixes.
> 
> --- gcc/match.pd.jj	2023-09-18 10:37:56.002965361 +0200
> +++ gcc/match.pd	2023-09-18 12:14:32.321631010 +0200
> @@ -4114,9 +4114,13 @@ (define_operator_list SYNC_FETCH_AND_AND
>     (if (INTEGRAL_TYPE_P (type))
>      (with {
>        int width = element_precision (type) - tree_to_uhwi (@1);
> -      tree stype = build_nonstandard_integer_type (width, 0);
> +      tree stype = NULL_TREE;
> +      scalar_int_mode mode = (targetm.scalar_mode_supported_p (TImode)
> +			      ? TImode : DImode);
> +      if (width <= GET_MODE_PRECISION (mode))
> +	stype = build_nonstandard_integer_type (width, 0);
>       }
> -     (if (width == 1 || type_has_mode_precision_p (stype))
> +     (if (stype && (width == 1 || type_has_mode_precision_p (stype)))
>        (convert (convert:stype @0))))))))
>  
>  /* Optimize x >> x into 0 */
> @@ -5092,49 +5096,24 @@ (define_operator_list SYNC_FETCH_AND_AND
>      /* a ? -1 : 0 -> -a.  No need to check the TYPE_PRECISION not being 1
>         here as the powerof2cst case above will handle that case correctly.  */
>      (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1))
> +     (negate (convert:type (convert:boolean_type_node @0))))))
> +  (if (integer_zerop (@1))
> +   (switch
> +    /* a ? 0 : 1 -> !a. */
> +    (if (integer_onep (@2))
> +     (convert (bit_xor (convert:boolean_type_node @0) { boolean_true_node; })))
> +    /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */
> +    (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@2))
>       (with {
> -       auto prec = TYPE_PRECISION (type);
> -       auto unsign = TYPE_UNSIGNED (type);
> -       tree inttype = build_nonstandard_integer_type (prec, unsign);
> +       tree shift = build_int_cst (integer_type_node, tree_log2 (@2));
>        }
> -      (convert (negate (convert:inttype (convert:boolean_type_node @0))))))))
> -  (if (integer_zerop (@1))
> -   (with {
> -      tree booltrue = constant_boolean_node (true, boolean_type_node);
> -    }
> -    (switch
> -     /* a ? 0 : 1 -> !a. */
> -     (if (integer_onep (@2))
> -      (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )))
> -     /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */
> -     (if (INTEGRAL_TYPE_P (type) &&  integer_pow2p (@2))
> -      (with {
> -	tree shift = build_int_cst (integer_type_node, tree_log2 (@2));
> -       }
> -       (lshift (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } ))
> -        { shift; })))
> -     /* a ? -1 : 0 -> -(!a).  No need to check the TYPE_PRECISION not being 1
> +      (lshift (convert (bit_xor (convert:boolean_type_node @0)
> +				{ boolean_true_node; })) { shift; })))
> +    /* a ? -1 : 0 -> -(!a).  No need to check the TYPE_PRECISION not being 1
>         here as the powerof2cst case above will handle that case correctly.  */
> -     (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2))
> -      (with {
> -	auto prec = TYPE_PRECISION (type);
> -	auto unsign = TYPE_UNSIGNED (type);
> -	tree inttype = build_nonstandard_integer_type (prec, unsign);
> -       }
> -       (convert
> -	(negate
> -         (convert:inttype
> -	  (bit_xor (convert:boolean_type_node @0) { booltrue; } )
> -	 )
> -	)
> -       )
> -      )
> -     )
> -    )
> -   )
> -  )
> - )
> -)
> +    (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2))
> +     (negate (convert:type (bit_xor (convert:boolean_type_node @0)
> +				    { boolean_true_node; }))))))))
>  
>  /* (a > 1) ? 0 : (cast)a is the same as (cast)(a == 1)
>     for unsigned types. */
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

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

* Re: [PATCH] match.pd: Some build_nonstandard_integer_type tweaks
  2023-09-19  7:48 [PATCH] match.pd: Some build_nonstandard_integer_type tweaks Jakub Jelinek
  2023-09-19  8:40 ` Richard Biener
@ 2023-09-19 16:50 ` Richard Sandiford
  2023-09-20  7:23   ` [PATCH] middle-end: use MAX_FIXED_MODE_SIZE instead of precidion of TImode/DImode Jakub Jelinek
  1 sibling, 1 reply; 5+ messages in thread
From: Richard Sandiford @ 2023-09-19 16:50 UTC (permalink / raw)
  To: Jakub Jelinek via Gcc-patches
  Cc: Richard Biener, Jakub Jelinek, Andrew Pinski

Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
> Hi!
>
> As discussed earlier, using build_nonstandard_integer_type blindly for all
> INTEGRAL_TYPE_Ps is problematic now that we have BITINT_TYPE, because it
> always creates an INTEGRAL_TYPE with some possibly very large precision.
> The following patch attempts to deal with 3 such spots in match.pd, others
> still need looking at.
>
> In the first case, I think it is quite expensive/undesirable to create
> a non-standard INTEGER_TYPE with possibly huge precision and then
> immediately just see type_has_mode_precision_p being false for it, or even
> worse introducing a cast to TImode or OImode or XImode INTEGER_TYPE which
> nothing will be able to actually handle.  128-bit or 64-bit (on 32-bit
> targets) types are the largest supported by the backend, so the following
> patch avoids creating and matching conversions to larger types, it is
> an optimization anyway and so should be used when it is cheap that way.
>
> In the second hunk, I believe the uses of build_nonstandard_integer_type
> aren't useful at all.  It is when matching a ? -1 : 0 and trying to express
> it as say -(type) (bool) a etc., but this is all GIMPLE only, where most of
> integral types with same precision/signedness are compatible and we know
> -1 is representable in that type, so I really don't see any reason not to
> perform the negation of a [0, 1] valued expression in type, rather
> than doing it in
> build_nonstandard_integer_type (TYPE_PRECISION (type), TYPE_UNSIGNED (type))
> (except that it breaks the BITINT_TYPEs).  I don't think we need to do
> something like range_check_type.
> While in there, I've also noticed it was using a (with {
> tree booltrue = constant_boolean_node (true, boolean_type_node);
> } and removed that + replaced uses of booltrue with boolean_true_node
> which the above function always returns.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2023-09-19  Jakub Jelinek  <jakub@redhat.com>
>
> 	* match.pd ((x << c) >> c): Don't call build_nonstandard_integer_type
> 	nor check type_has_mode_precision_p for width larger than [TD]Imode
> 	precision.
> 	(a ? CST1 : CST2): Don't use build_nonstandard_type, just convert
> 	to type.  Use boolean_true_node instead of
> 	constant_boolean_node (true, boolean_type_node).  Formatting fixes.
>
> --- gcc/match.pd.jj	2023-09-18 10:37:56.002965361 +0200
> +++ gcc/match.pd	2023-09-18 12:14:32.321631010 +0200
> @@ -4114,9 +4114,13 @@ (define_operator_list SYNC_FETCH_AND_AND
>     (if (INTEGRAL_TYPE_P (type))
>      (with {
>        int width = element_precision (type) - tree_to_uhwi (@1);
> -      tree stype = build_nonstandard_integer_type (width, 0);
> +      tree stype = NULL_TREE;
> +      scalar_int_mode mode = (targetm.scalar_mode_supported_p (TImode)
> +			      ? TImode : DImode);
> +      if (width <= GET_MODE_PRECISION (mode))
> +	stype = build_nonstandard_integer_type (width, 0);

How about using MAX_FIXED_MODE_SIZE for things like this?

Thanks,
Richard

>       }
> -     (if (width == 1 || type_has_mode_precision_p (stype))
> +     (if (stype && (width == 1 || type_has_mode_precision_p (stype)))
>        (convert (convert:stype @0))))))))
>  
>  /* Optimize x >> x into 0 */
> @@ -5092,49 +5096,24 @@ (define_operator_list SYNC_FETCH_AND_AND
>      /* a ? -1 : 0 -> -a.  No need to check the TYPE_PRECISION not being 1
>         here as the powerof2cst case above will handle that case correctly.  */
>      (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1))
> +     (negate (convert:type (convert:boolean_type_node @0))))))
> +  (if (integer_zerop (@1))
> +   (switch
> +    /* a ? 0 : 1 -> !a. */
> +    (if (integer_onep (@2))
> +     (convert (bit_xor (convert:boolean_type_node @0) { boolean_true_node; })))
> +    /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */
> +    (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@2))
>       (with {
> -       auto prec = TYPE_PRECISION (type);
> -       auto unsign = TYPE_UNSIGNED (type);
> -       tree inttype = build_nonstandard_integer_type (prec, unsign);
> +       tree shift = build_int_cst (integer_type_node, tree_log2 (@2));
>        }
> -      (convert (negate (convert:inttype (convert:boolean_type_node @0))))))))
> -  (if (integer_zerop (@1))
> -   (with {
> -      tree booltrue = constant_boolean_node (true, boolean_type_node);
> -    }
> -    (switch
> -     /* a ? 0 : 1 -> !a. */
> -     (if (integer_onep (@2))
> -      (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )))
> -     /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */
> -     (if (INTEGRAL_TYPE_P (type) &&  integer_pow2p (@2))
> -      (with {
> -	tree shift = build_int_cst (integer_type_node, tree_log2 (@2));
> -       }
> -       (lshift (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } ))
> -        { shift; })))
> -     /* a ? -1 : 0 -> -(!a).  No need to check the TYPE_PRECISION not being 1
> +      (lshift (convert (bit_xor (convert:boolean_type_node @0)
> +				{ boolean_true_node; })) { shift; })))
> +    /* a ? -1 : 0 -> -(!a).  No need to check the TYPE_PRECISION not being 1
>         here as the powerof2cst case above will handle that case correctly.  */
> -     (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2))
> -      (with {
> -	auto prec = TYPE_PRECISION (type);
> -	auto unsign = TYPE_UNSIGNED (type);
> -	tree inttype = build_nonstandard_integer_type (prec, unsign);
> -       }
> -       (convert
> -	(negate
> -         (convert:inttype
> -	  (bit_xor (convert:boolean_type_node @0) { booltrue; } )
> -	 )
> -	)
> -       )
> -      )
> -     )
> -    )
> -   )
> -  )
> - )
> -)
> +    (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2))
> +     (negate (convert:type (bit_xor (convert:boolean_type_node @0)
> +				    { boolean_true_node; }))))))))
>  
>  /* (a > 1) ? 0 : (cast)a is the same as (cast)(a == 1)
>     for unsigned types. */
>
> 	Jakub

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

* [PATCH] middle-end: use MAX_FIXED_MODE_SIZE instead of precidion of TImode/DImode
  2023-09-19 16:50 ` Richard Sandiford
@ 2023-09-20  7:23   ` Jakub Jelinek
  2023-09-20  7:43     ` Richard Biener
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2023-09-20  7:23 UTC (permalink / raw)
  To: richard.sandiford, Richard Biener; +Cc: gcc-patches

Hi!

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.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

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.

--- gcc/match.pd.jj	2023-09-19 19:47:23.969430272 +0200
+++ gcc/match.pd	2023-09-19 20:08:17.341559409 +0200
@@ -4124,9 +4124,7 @@ (define_operator_list SYNC_FETCH_AND_AND
     (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)))
--- gcc/gimple-lower-bitint.cc.jj	2023-09-08 11:29:20.105768005 +0200
+++ gcc/gimple-lower-bitint.cc	2023-09-19 20:01:50.927782331 +0200
@@ -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;
--- gcc/expr.cc.jj	2023-09-08 11:29:20.101768059 +0200
+++ gcc/expr.cc	2023-09-19 20:00:12.788108832 +0200
@@ -11044,17 +11044,11 @@ expand_expr_real_1 (tree exp, rtx target
 	    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);
 	      }
 	  }
 
--- gcc/tree-ssa-sccvn.cc.jj	2023-09-18 15:14:48.987358112 +0200
+++ gcc/tree-ssa-sccvn.cc	2023-09-19 20:02:53.160941163 +0200
@@ -7004,10 +7004,7 @@ eliminate_dom_walker::eliminate_stmt (ba
 	  && !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)
--- gcc/ubsan.cc.jj	2023-09-08 11:29:20.136767581 +0200
+++ gcc/ubsan.cc	2023-09-19 20:06:56.118657251 +0200
@@ -136,13 +136,10 @@ ubsan_encode_value (tree t, enum ubsan_e
 	}
       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 u
     {
       /* 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 u
       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 u
   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);
     }


	Jakub


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

* Re: [PATCH] middle-end: use MAX_FIXED_MODE_SIZE instead of precidion of TImode/DImode
  2023-09-20  7:23   ` [PATCH] middle-end: use MAX_FIXED_MODE_SIZE instead of precidion of TImode/DImode Jakub Jelinek
@ 2023-09-20  7:43     ` Richard Biener
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Biener @ 2023-09-20  7:43 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: richard.sandiford, gcc-patches

On Wed, 20 Sep 2023, Jakub Jelinek wrote:

> Hi!
> 
> 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.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

> 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.
> 
> --- gcc/match.pd.jj	2023-09-19 19:47:23.969430272 +0200
> +++ gcc/match.pd	2023-09-19 20:08:17.341559409 +0200
> @@ -4124,9 +4124,7 @@ (define_operator_list SYNC_FETCH_AND_AND
>      (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)))
> --- gcc/gimple-lower-bitint.cc.jj	2023-09-08 11:29:20.105768005 +0200
> +++ gcc/gimple-lower-bitint.cc	2023-09-19 20:01:50.927782331 +0200
> @@ -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;
> --- gcc/expr.cc.jj	2023-09-08 11:29:20.101768059 +0200
> +++ gcc/expr.cc	2023-09-19 20:00:12.788108832 +0200
> @@ -11044,17 +11044,11 @@ expand_expr_real_1 (tree exp, rtx target
>  	    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);
>  	      }
>  	  }
>  
> --- gcc/tree-ssa-sccvn.cc.jj	2023-09-18 15:14:48.987358112 +0200
> +++ gcc/tree-ssa-sccvn.cc	2023-09-19 20:02:53.160941163 +0200
> @@ -7004,10 +7004,7 @@ eliminate_dom_walker::eliminate_stmt (ba
>  	  && !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)
> --- gcc/ubsan.cc.jj	2023-09-08 11:29:20.136767581 +0200
> +++ gcc/ubsan.cc	2023-09-19 20:06:56.118657251 +0200
> @@ -136,13 +136,10 @@ ubsan_encode_value (tree t, enum ubsan_e
>  	}
>        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 u
>      {
>        /* 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 u
>        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 u
>    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);
>      }
> 
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

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

end of thread, other threads:[~2023-09-20  7:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-19  7:48 [PATCH] match.pd: Some build_nonstandard_integer_type tweaks Jakub Jelinek
2023-09-19  8:40 ` Richard Biener
2023-09-19 16:50 ` Richard Sandiford
2023-09-20  7:23   ` [PATCH] middle-end: use MAX_FIXED_MODE_SIZE instead of precidion of TImode/DImode Jakub Jelinek
2023-09-20  7:43     ` 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).