public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-6264] tree-ssa-dce: Fix up maybe_optimize_arith_overflow for BITINT_TYPE [PR112880] Date: Thu, 7 Dec 2023 08:48:27 +0000 (GMT) [thread overview] Message-ID: <20231207084827.538E83858288@sourceware.org> (raw) https://gcc.gnu.org/g:f74939bd539c87f669e35042f7bc7aa47f0c29eb commit r14-6264-gf74939bd539c87f669e35042f7bc7aa47f0c29eb Author: Jakub Jelinek <jakub@redhat.com> Date: Thu Dec 7 09:46:38 2023 +0100 tree-ssa-dce: Fix up maybe_optimize_arith_overflow for BITINT_TYPE [PR112880] The following testcase ICEs because maybe_optimize_arith_overflow uses build_nonstandard_integer_type, which is inappropriate if type is large BITINT_TYPE. 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. Diff: --- gcc/testsuite/gcc.dg/bitint-49.c | 37 +++++++++++++++++++++++++++++++++++++ gcc/tree-ssa-dce.cc | 4 +--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/gcc.dg/bitint-49.c b/gcc/testsuite/gcc.dg/bitint-49.c new file mode 100644 index 00000000000..74d9bde7e15 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-49.c @@ -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); +} diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc index 4e371b21a90..fbf4773eb9d 100644 --- a/gcc/tree-ssa-dce.cc +++ b/gcc/tree-ssa-dce.cc @@ -1241,9 +1241,7 @@ maybe_optimize_arith_overflow (gimple_stmt_iterator *gsi, 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));
reply other threads:[~2023-12-07 8:48 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20231207084827.538E83858288@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).