public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/112750] New: wrong code with _BitInt(256) and above and __builtin_sub_overflow_p() at -O0
@ 2023-11-28 19:30 zsojka at seznam dot cz
  2023-11-30 10:20 ` [Bug middle-end/112750] wrong code with _BitInt(256) and above with " jakub at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: zsojka at seznam dot cz @ 2023-11-28 19:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112750
           Summary: wrong code with _BitInt(256) and above and
                    __builtin_sub_overflow_p() at -O0
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zsojka at seznam dot cz
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-pc-linux-gnu

Created attachment 56708
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56708&action=edit
reduced testcase

Output:
$ x86_64-pc-linux-gnu-gcc testcase.c
$ ./a.out 
Aborted

__builtin_sub_overflow_p() should indicate overflow, since 0xC00C598D can't fit
into int.

$ x86_64-pc-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/repo/gcc-trunk/binary-latest-amd64/bin/x86_64-pc-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/repo/gcc-trunk/binary-trunk-r14-5935-20231128165834-gf45d5e30bd9-checking-yes-rtl-df-extra-nobootstrap-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /repo/gcc-trunk//configure --enable-languages=c,c++
--enable-valgrind-annotations --disable-nls --enable-checking=yes,rtl,df,extra
--disable-bootstrap --with-cloog --with-ppl --with-isl
--build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu
--target=x86_64-pc-linux-gnu --with-ld=/usr/bin/x86_64-pc-linux-gnu-ld
--with-as=/usr/bin/x86_64-pc-linux-gnu-as --disable-libstdcxx-pch
--prefix=/repo/gcc-trunk//binary-trunk-r14-5935-20231128165834-gf45d5e30bd9-checking-yes-rtl-df-extra-nobootstrap-amd64
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.0.0 20231128 (experimental) (GCC)

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

* [Bug middle-end/112750] wrong code with _BitInt(256) and above with __builtin_sub_overflow_p() at -O0
  2023-11-28 19:30 [Bug middle-end/112750] New: wrong code with _BitInt(256) and above and __builtin_sub_overflow_p() at -O0 zsojka at seznam dot cz
@ 2023-11-30 10:20 ` jakub at gcc dot gnu.org
  2023-12-01  8:27 ` cvs-commit at gcc dot gnu.org
  2023-12-01  8:28 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-11-30 10:20 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
   Last reconfirmed|                            |2023-11-30

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 56725
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56725&action=edit
gcc14-pr112750.patch

Untested fix.

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

* [Bug middle-end/112750] wrong code with _BitInt(256) and above with __builtin_sub_overflow_p() at -O0
  2023-11-28 19:30 [Bug middle-end/112750] New: wrong code with _BitInt(256) and above and __builtin_sub_overflow_p() at -O0 zsojka at seznam dot cz
  2023-11-30 10:20 ` [Bug middle-end/112750] wrong code with _BitInt(256) and above with " jakub at gcc dot gnu.org
@ 2023-12-01  8:27 ` cvs-commit at gcc dot gnu.org
  2023-12-01  8:28 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-01  8:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 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:364332658ef790d09d250db39c5b13e27c3543f1

commit r14-6042-g364332658ef790d09d250db39c5b13e27c3543f1
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Dec 1 09:25:45 2023 +0100

    lower-bitint: Fix _BitInt .{ADD,SUB}_OVERFLOW lowering [PR112750]

    The .{ADD,SUB}_OVERFLOW lowering is implemented by performing normal
    addition/subtraction (perhaps extended to even more bits than normally by
    continuing with extended values of operands after running of normal bits)
    and in addition to that trying to compute if certain sets of bits are
either
    all zero or all sign extensions of the least significant bit.

    That code is in a lot of cases guarded just by a single condition (which
    can be idx > startlimb, idx >= startlimb or idx == startlimb) or by
    2 conditions - if (idx >= startlimb) { if (idx == startlimb) ... else ... }
    Now, if_then_if_then_else when the second argument is NULL works just as
    if_then and sets m_gsi to be within the initially empty then block and that
is
    where we emit code for constant tidx startlimb + (cmp_code == GT_EXPR).
    But in the 2 conditions case, m_gsi is set to the initially empty else
    block, so using EQ_EXPR for the condition was incorrect (and strangely
    nothing in the testsuite caught that), because the code for extracting the
    lowest set of bits (i.e. when tidx is startlimb) is then done when idx
    is not startlimb rather than when it is.
    The following patch fixes that.

    Note, when developing the lowering, I was using gcov to make sure all code
    is covered by the testsuite with minimum exceptions, so no idea how this
    slipped out.

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

            PR middle-end/112750
            * gimple-lower-bitint.cc
(bitint_large_huge::lower_addsub_overflow):
            Use NE_EXPR rather than EQ_EXPR for g2 if !single_comparison and
            adjust probabilities.

            * gcc.dg/bitint-41.c: Use -std=c23 rather than -std=c2x.
            * gcc.dg/torture/bitint-43.c: Likewise.
            * gcc.dg/torture/bitint-44.c: Likewise.
            * gcc.dg/torture/bitint-45.c: New test.

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

* [Bug middle-end/112750] wrong code with _BitInt(256) and above with __builtin_sub_overflow_p() at -O0
  2023-11-28 19:30 [Bug middle-end/112750] New: wrong code with _BitInt(256) and above and __builtin_sub_overflow_p() at -O0 zsojka at seznam dot cz
  2023-11-30 10:20 ` [Bug middle-end/112750] wrong code with _BitInt(256) and above with " jakub at gcc dot gnu.org
  2023-12-01  8:27 ` cvs-commit at gcc dot gnu.org
@ 2023-12-01  8:28 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-12-01  8:28 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed now.

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

end of thread, other threads:[~2023-12-01  8:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-28 19:30 [Bug middle-end/112750] New: wrong code with _BitInt(256) and above and __builtin_sub_overflow_p() at -O0 zsojka at seznam dot cz
2023-11-30 10:20 ` [Bug middle-end/112750] wrong code with _BitInt(256) and above with " jakub at gcc dot gnu.org
2023-12-01  8:27 ` cvs-commit at gcc dot gnu.org
2023-12-01  8:28 ` jakub at gcc dot gnu.org

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