public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114425] New: wrong code with _BitInt() __builtin_add_overflow_p() at -O2
@ 2024-03-22 4:15 zsojka at seznam dot cz
2024-03-22 11:37 ` [Bug tree-optimization/114425] " zsojka at seznam dot cz
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: zsojka at seznam dot cz @ 2024-03-22 4:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114425
Bug ID: 114425
Summary: wrong code with _BitInt() __builtin_add_overflow_p()
at -O2
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: zsojka at seznam dot cz
CC: jakub at gcc dot gnu.org
Target Milestone: ---
Host: x86_64-pc-linux-gnu
Target: x86_64-pc-linux-gnu
Created attachment 57764
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57764&action=edit
reduced testcase
Output:
$ x86_64-pc-linux-gnu-gcc -O2 testcase.c
$ ./a.out
Aborted
$ 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-9595-20240321132344-ga2fe34e0b99-checking-yes-rtl-df-extra-nobootstrap-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/14.0.1/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 --enable-libsanitizer
--disable-libstdcxx-pch
--prefix=/repo/gcc-trunk//binary-trunk-r14-9595-20240321132344-ga2fe34e0b99-checking-yes-rtl-df-extra-nobootstrap-amd64
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.0.1 20240321 (experimental) (GCC)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/114425] wrong code with _BitInt() __builtin_add_overflow_p() at -O2
2024-03-22 4:15 [Bug tree-optimization/114425] New: wrong code with _BitInt() __builtin_add_overflow_p() at -O2 zsojka at seznam dot cz
@ 2024-03-22 11:37 ` zsojka at seznam dot cz
2024-03-22 11:50 ` [Bug tree-optimization/114425] wrong code with _BitInt() __builtin_add_overflow_p() and __builtin_mul_overflow_p() " jakub at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: zsojka at seznam dot cz @ 2024-03-22 11:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114425
--- Comment #1 from Zdenek Sojka <zsojka at seznam dot cz> ---
Created attachment 57771
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57771&action=edit
another testcase, using __builtin_mul_overflow_p
Output for second testcase:
$ x86_64-pc-linux-gnu-gcc -O2 testcase2.c
$ ./a.out
Aborted
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/114425] wrong code with _BitInt() __builtin_add_overflow_p() and __builtin_mul_overflow_p() at -O2
2024-03-22 4:15 [Bug tree-optimization/114425] New: wrong code with _BitInt() __builtin_add_overflow_p() at -O2 zsojka at seznam dot cz
2024-03-22 11:37 ` [Bug tree-optimization/114425] " zsojka at seznam dot cz
@ 2024-03-22 11:50 ` jakub at gcc dot gnu.org
2024-03-22 11:57 ` zsojka at seznam dot cz
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-03-22 11:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114425
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Strangely it is dependent on the printf loop, without that it works fine.
Slightly adjusted testcase:
#if __BITINT_MAXWIDTH__ >= 2000
_BitInt(8) a;
_BitInt(300) b;
_BitInt(2000) c;
unsigned
foo (_BitInt(2000) d)
{
int o = __builtin_add_overflow_p (d, 0, b);
_BitInt(2000) m = c * a;
unsigned u = m;
return u + o;
}
__attribute__((noipa)) void
bar (int x)
{
(void) x;
}
#endif
int
main ()
{
#if __BITINT_MAXWIDTH__ >= 2000
unsigned x = foo
(0xfa7ac16f2613255eeb217e871c1f02221e26ce11f82d6a33206ec0ad5d4414722019933c0e2wb);
for (unsigned i = 0; i < sizeof (x); i++)
bar (((volatile unsigned char *) &x)[i]);
if (x != 1)
__builtin_abort ();
#endif
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/114425] wrong code with _BitInt() __builtin_add_overflow_p() and __builtin_mul_overflow_p() at -O2
2024-03-22 4:15 [Bug tree-optimization/114425] New: wrong code with _BitInt() __builtin_add_overflow_p() at -O2 zsojka at seznam dot cz
2024-03-22 11:37 ` [Bug tree-optimization/114425] " zsojka at seznam dot cz
2024-03-22 11:50 ` [Bug tree-optimization/114425] wrong code with _BitInt() __builtin_add_overflow_p() and __builtin_mul_overflow_p() " jakub at gcc dot gnu.org
@ 2024-03-22 11:57 ` zsojka at seznam dot cz
2024-03-22 11:57 ` zsojka at seznam dot cz
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: zsojka at seznam dot cz @ 2024-03-22 11:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114425
--- Comment #3 from Zdenek Sojka <zsojka at seznam dot cz> ---
Created attachment 57772
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57772&action=edit
unreduced testcase ; output differs between -O0 and -O2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/114425] wrong code with _BitInt() __builtin_add_overflow_p() and __builtin_mul_overflow_p() at -O2
2024-03-22 4:15 [Bug tree-optimization/114425] New: wrong code with _BitInt() __builtin_add_overflow_p() at -O2 zsojka at seznam dot cz
` (2 preceding siblings ...)
2024-03-22 11:57 ` zsojka at seznam dot cz
@ 2024-03-22 11:57 ` zsojka at seznam dot cz
2024-03-22 14:02 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: zsojka at seznam dot cz @ 2024-03-22 11:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114425
--- Comment #4 from Zdenek Sojka <zsojka at seznam dot cz> ---
Created attachment 57773
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57773&action=edit
another unreduced testcase ; output differs between -O0 and -O2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/114425] wrong code with _BitInt() __builtin_add_overflow_p() and __builtin_mul_overflow_p() at -O2
2024-03-22 4:15 [Bug tree-optimization/114425] New: wrong code with _BitInt() __builtin_add_overflow_p() at -O2 zsojka at seznam dot cz
` (3 preceding siblings ...)
2024-03-22 11:57 ` zsojka at seznam dot cz
@ 2024-03-22 14:02 ` jakub at gcc dot gnu.org
2024-03-22 14:18 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-03-22 14:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114425
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2024-03-22
Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 57779
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57779&action=edit
gcc14-pr114425.patch
Untested fix.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/114425] wrong code with _BitInt() __builtin_add_overflow_p() and __builtin_mul_overflow_p() at -O2
2024-03-22 4:15 [Bug tree-optimization/114425] New: wrong code with _BitInt() __builtin_add_overflow_p() at -O2 zsojka at seznam dot cz
` (4 preceding siblings ...)
2024-03-22 14:02 ` jakub at gcc dot gnu.org
@ 2024-03-22 14:18 ` jakub at gcc dot gnu.org
2024-03-23 10:19 ` cvs-commit at gcc dot gnu.org
2024-03-23 10:21 ` jakub at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-03-22 14:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114425
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Though, guess it would help if evrp avoided undesirable propagation here:
It is changing:
<bb 2> :
# DEBUG BEGIN_STMT
_8 = .ADD_OVERFLOW (d_7(D), 0);
_1 = IMAGPART_EXPR <_8>;
_2 = (_Bool) _1;
# DEBUG o => (int) _2
# DEBUG BEGIN_STMT
a.0_3 = a;
_4 = (_BitInt(2000)) a.0_3;
c.1_5 = c;
m_11 = _4 * c.1_5;
# DEBUG m => m_11
# DEBUG BEGIN_STMT
u_12 = (unsigned int) m_11;
# DEBUG u => u_12
# DEBUG BEGIN_STMT
- o.2_6 = (unsigned int) _2;
+ o.2_6 = (unsigned int) _1;
_13 = o.2_6 + u_12;
return _13;
}
which is surely possible because IMAGPART_EXPR of .{ADD,SUB,MUL}_OVERFLOW has
[0, 1]
range, but for such large/huge _BitInt IMAGPART_EXPR it extends the lifetime of
an expensive large variable rather than just being a boolean.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/114425] wrong code with _BitInt() __builtin_add_overflow_p() and __builtin_mul_overflow_p() at -O2
2024-03-22 4:15 [Bug tree-optimization/114425] New: wrong code with _BitInt() __builtin_add_overflow_p() at -O2 zsojka at seznam dot cz
` (5 preceding siblings ...)
2024-03-22 14:18 ` jakub at gcc dot gnu.org
@ 2024-03-23 10:19 ` cvs-commit at gcc dot gnu.org
2024-03-23 10:21 ` jakub at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-23 10:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114425
--- Comment #7 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:f92cf8cbbe199bda70d0dd7893e8c8836777e2d0
commit r14-9640-gf92cf8cbbe199bda70d0dd7893e8c8836777e2d0
Author: Jakub Jelinek <jakub@redhat.com>
Date: Sat Mar 23 11:19:09 2024 +0100
bitint: Handle complex types in build_bitint_stmt_ssa_conflicts [PR114425]
The task of the build_bitint_stmt_ssa_conflicts hook for
tree-ssa-coalesce.cc next to special casing the
multiplication/division/modulo is to ignore statements with
large/huge _BitInt lhs which isn't in names bitmap and on the
other side pretend all uses of the stmt are used in a later stmt
(single user of that SSA_NAME or perhaps single user of lhs of
the single user etc.) where the lowering will actually emit the
code.
Unfortunately the function wasn't handling COMPLEX_TYPE of the large/huge
BITINT_TYPE, while the FE doesn't really support such types, they are
used under the hood for __builtin_{add,sub,mul}_overflow{,_p}, they are
also present or absent from the names bitmap and should be treated the
same.
Without this patch, the operands of .ADD_OVERFLOW were incorrectly
pretended
to be used right in that call statement rather than on the cast stmt from
IMAGPART_EXPR of .ADD_OVERFLOW return value to some integral type.
2024-03-23 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/114425
* gimple-lower-bitint.cc (build_bitint_stmt_ssa_conflicts): Handle
_Complex large/huge _BitInt types like the large/huge _BitInt
types.
* gcc.dg/torture/bitint-67.c: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/114425] wrong code with _BitInt() __builtin_add_overflow_p() and __builtin_mul_overflow_p() at -O2
2024-03-22 4:15 [Bug tree-optimization/114425] New: wrong code with _BitInt() __builtin_add_overflow_p() at -O2 zsojka at seznam dot cz
` (6 preceding siblings ...)
2024-03-23 10:19 ` cvs-commit at gcc dot gnu.org
@ 2024-03-23 10:21 ` jakub at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-03-23 10:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114425
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Target Milestone|--- |14.0
Resolution|--- |FIXED
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-03-23 10:21 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-22 4:15 [Bug tree-optimization/114425] New: wrong code with _BitInt() __builtin_add_overflow_p() at -O2 zsojka at seznam dot cz
2024-03-22 11:37 ` [Bug tree-optimization/114425] " zsojka at seznam dot cz
2024-03-22 11:50 ` [Bug tree-optimization/114425] wrong code with _BitInt() __builtin_add_overflow_p() and __builtin_mul_overflow_p() " jakub at gcc dot gnu.org
2024-03-22 11:57 ` zsojka at seznam dot cz
2024-03-22 11:57 ` zsojka at seznam dot cz
2024-03-22 14:02 ` jakub at gcc dot gnu.org
2024-03-22 14:18 ` jakub at gcc dot gnu.org
2024-03-23 10:19 ` cvs-commit at gcc dot gnu.org
2024-03-23 10:21 ` 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).