public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/112807] ICE: SIGSEGV in contains_struct_check (tree.h:3747) with _BitInt() at -O1 and above
Date: Sun, 03 Dec 2023 16:54:56 +0000	[thread overview]
Message-ID: <bug-112807-4-v6Wq4wStjG@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-112807-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112807

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:eef6aea3052b4b8a60df211015dafcb4573d19fb

commit r14-6095-geef6aea3052b4b8a60df211015dafcb4573d19fb
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sun Dec 3 17:54:03 2023 +0100

    lower-bitint: Fix up lower_addsub_overflow [PR112807]

    lower_addsub_overflow uses handle_cast or handle_operand to extract current
    limb from the operands.  Both of those functions heavily assume that they
    return a large or huge BITINT_TYPE.  The problem in the testcase is that
    this is violated.  Normally, lower_addsub_overflow isn't even called if
    neither the return's type element type nor any of the operand is large/huge
    BITINT_TYPE (on x86_64 129+ bits), for middle BITINT_TYPE (on x86_64 65-128
    bits) some other code casts such operands to {,unsigned }__int128.
    In the testcase the result is complex unsigned, so small, but one of the
    arguments is _BitInt(256), so lower_addsub_overflow is called.  But
    range_for_prec asks the ranger for ranges of the operands and in this
    case the first argument has [0, 0xffffffff] range and second [-2, 1], so
    unsigned 32-bit and signed 2-bit, and in such case the code for
    handle_operand/handle_cast purposes would use the _BitInt(256) type for the
    first operand (ok), but because prec3 aka maximum of result precision and
    the VRP computes ranges of the arguments is 32, use cast to 32-bit
    BITINT_TYPE, which is why it didn't work correctly.
    The following patch ensures that in such cases we use handle_cast to the
    type of the other argument.

    Perhaps incrementally, we could try to optimize this in an earlier phase,
    see that while the .{ADD,SUB}_OVERFLOW has large/huge _BitInt argument, as
    ranger says it fits into a smaller type, add a cast of the larger argument
    to the smaller precision type in which it fits.  Either in
    gimple_lower_bitint, or match.pd.  An argument for the latter is that e.g.
    complex unsigned .ADD_OVERFLOW (unsigned_long_long_arg, unsigned_arg)
    where ranger says unsigned_long_long_arg fits into unsigned 32-bit could
    be also more efficient as
    .ADD_OVERFLOW ((unsigned) unsigned_long_long_arg, unsigned_arg)

    2023-12-03  Jakub Jelinek  <jakub@redhat.com>

            PR middle-end/112807
            * gimple-lower-bitint.cc
(bitint_large_huge::lower_addsub_overflow):
            When choosing type0 and type1 types, if prec3 has small/middle
bitint
            kind, use maximum of type0 and type1's precision instead of prec3.

            * gcc.dg/bitint-46.c: New test.

  parent reply	other threads:[~2023-12-03 16:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-01  9:56 [Bug tree-optimization/112807] New: " zsojka at seznam dot cz
2023-12-01 17:03 ` [Bug tree-optimization/112807] " jakub at gcc dot gnu.org
2023-12-01 17:52 ` jakub at gcc dot gnu.org
2023-12-03 16:54 ` cvs-commit at gcc dot gnu.org [this message]
2023-12-03 16:56 ` jakub at gcc dot gnu.org

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=bug-112807-4-v6Wq4wStjG@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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: link
Be 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).