* [PATCH] tree-ssa-dce: Fix up maybe_optimize_arith_overflow for BITINT_TYPE [PR112880]
@ 2023-12-07 7:49 Jakub Jelinek
2023-12-07 7:56 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2023-12-07 7:49 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
Hi!
The following testcase ICEs because maybe_optimize_arith_overflow
uses build_nonstandard_integer_type, which is inappropriate if
type is large BITINT_TYPE.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk?
2023-12-07 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/112880
* tree-ssa-dce.cc (maybe_optimize_arith_overflow): Use
unsigned_type_for instead of conditionally calling
build_nonstandard_integer_type.
* gcc.dg/bitint-49.c: New test.
--- gcc/tree-ssa-dce.cc.jj 2023-12-05 16:14:36.833248092 +0100
+++ gcc/tree-ssa-dce.cc 2023-12-06 17:16:42.740873447 +0100
@@ -1241,9 +1241,7 @@ maybe_optimize_arith_overflow (gimple_st
tree arg1 = gimple_call_arg (stmt, 1);
location_t loc = gimple_location (stmt);
tree type = TREE_TYPE (TREE_TYPE (lhs));
- tree utype = type;
- if (!TYPE_UNSIGNED (type))
- utype = build_nonstandard_integer_type (TYPE_PRECISION (type), 1);
+ tree utype = unsigned_type_for (type);
tree result = fold_build2_loc (loc, subcode, utype,
fold_convert_loc (loc, utype, arg0),
fold_convert_loc (loc, utype, arg1));
--- gcc/testsuite/gcc.dg/bitint-49.c.jj 2023-12-06 17:15:30.461888327 +0100
+++ gcc/testsuite/gcc.dg/bitint-49.c 2023-12-06 17:15:01.669292609 +0100
@@ -0,0 +1,37 @@
+/* PR tree-optimization/112880 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-std=c23 -O2" } */
+
+#if __BITINT_MAXWIDTH__ >= 1024
+_BitInt(1024) a, b, c, d, e, f;
+
+void
+foo (void)
+{
+ __builtin_add_overflow (a, b, &a);
+ __builtin_sub_overflow (c, d, &c);
+ __builtin_mul_overflow (e, f, &e);
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 512
+_BitInt(512) g, h, i, j, k, l;
+
+void
+bar (void)
+{
+ __builtin_add_overflow (g, h, &g);
+ __builtin_sub_overflow (i, j, &i);
+ __builtin_mul_overflow (k, l, &k);
+}
+#endif
+
+_BitInt(32) m, n, o, p, q, r;
+
+void
+baz (void)
+{
+ __builtin_add_overflow (m, n, &m);
+ __builtin_sub_overflow (o, p, &o);
+ __builtin_mul_overflow (q, r, &q);
+}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] tree-ssa-dce: Fix up maybe_optimize_arith_overflow for BITINT_TYPE [PR112880]
2023-12-07 7:49 [PATCH] tree-ssa-dce: Fix up maybe_optimize_arith_overflow for BITINT_TYPE [PR112880] Jakub Jelinek
@ 2023-12-07 7:56 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-12-07 7:56 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On Thu, 7 Dec 2023, Jakub Jelinek wrote:
> Hi!
>
> The following testcase ICEs because maybe_optimize_arith_overflow
> uses build_nonstandard_integer_type, which is inappropriate if
> type is large BITINT_TYPE.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
> ok for trunk?
OK.
> 2023-12-07 Jakub Jelinek <jakub@redhat.com>
>
> PR tree-optimization/112880
> * tree-ssa-dce.cc (maybe_optimize_arith_overflow): Use
> unsigned_type_for instead of conditionally calling
> build_nonstandard_integer_type.
>
> * gcc.dg/bitint-49.c: New test.
>
> --- gcc/tree-ssa-dce.cc.jj 2023-12-05 16:14:36.833248092 +0100
> +++ gcc/tree-ssa-dce.cc 2023-12-06 17:16:42.740873447 +0100
> @@ -1241,9 +1241,7 @@ maybe_optimize_arith_overflow (gimple_st
> tree arg1 = gimple_call_arg (stmt, 1);
> location_t loc = gimple_location (stmt);
> tree type = TREE_TYPE (TREE_TYPE (lhs));
> - tree utype = type;
> - if (!TYPE_UNSIGNED (type))
> - utype = build_nonstandard_integer_type (TYPE_PRECISION (type), 1);
> + tree utype = unsigned_type_for (type);
> tree result = fold_build2_loc (loc, subcode, utype,
> fold_convert_loc (loc, utype, arg0),
> fold_convert_loc (loc, utype, arg1));
> --- gcc/testsuite/gcc.dg/bitint-49.c.jj 2023-12-06 17:15:30.461888327 +0100
> +++ gcc/testsuite/gcc.dg/bitint-49.c 2023-12-06 17:15:01.669292609 +0100
> @@ -0,0 +1,37 @@
> +/* PR tree-optimization/112880 */
> +/* { dg-do compile { target bitint } } */
> +/* { dg-options "-std=c23 -O2" } */
> +
> +#if __BITINT_MAXWIDTH__ >= 1024
> +_BitInt(1024) a, b, c, d, e, f;
> +
> +void
> +foo (void)
> +{
> + __builtin_add_overflow (a, b, &a);
> + __builtin_sub_overflow (c, d, &c);
> + __builtin_mul_overflow (e, f, &e);
> +}
> +#endif
> +
> +#if __BITINT_MAXWIDTH__ >= 512
> +_BitInt(512) g, h, i, j, k, l;
> +
> +void
> +bar (void)
> +{
> + __builtin_add_overflow (g, h, &g);
> + __builtin_sub_overflow (i, j, &i);
> + __builtin_mul_overflow (k, l, &k);
> +}
> +#endif
> +
> +_BitInt(32) m, n, o, p, q, r;
> +
> +void
> +baz (void)
> +{
> + __builtin_add_overflow (m, n, &m);
> + __builtin_sub_overflow (o, p, &o);
> + __builtin_mul_overflow (q, r, &q);
> +}
>
> 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] 2+ messages in thread
end of thread, other threads:[~2023-12-07 8:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-07 7:49 [PATCH] tree-ssa-dce: Fix up maybe_optimize_arith_overflow for BITINT_TYPE [PR112880] Jakub Jelinek
2023-12-07 7:56 ` 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).