public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/105984] New: [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1
@ 2022-06-15 5:20 zsojka at seznam dot cz
2022-06-15 9:15 ` [Bug middle-end/105984] " rguenth at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: zsojka at seznam dot cz @ 2022-06-15 5:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105984
Bug ID: 105984
Summary: [13 Regression] wrong code with
__builtin_mul_overflow_p() at -O1
Product: gcc
Version: 13.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
CC: jakub at gcc dot gnu.org
Target Milestone: ---
Host: x86_64-pc-linux-gnu
Created attachment 53139
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53139&action=edit
reduced testcase
Output:
$ x86_64-pc-linux-gnu-gcc -O1 testcase.c
$ ./a.out
Aborted
The generated code:
main:
mov rax, QWORD PTR g[rip]
sub rax, 1
mov QWORD PTR g[rip], rax
jne .L6
mov eax, 0
ret
just shows the multiplication was evaluated to overflow at compile time.
$ 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-r13-1092-20220614173648-g3e16b4359e8-checking-yes-rtl-df-extra-nobootstrap-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/13.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-r13-1092-20220614173648-g3e16b4359e8-checking-yes-rtl-df-extra-nobootstrap-amd64
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.0.0 20220614 (experimental) (GCC)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/105984] [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1
2022-06-15 5:20 [Bug middle-end/105984] New: [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1 zsojka at seznam dot cz
@ 2022-06-15 9:15 ` rguenth at gcc dot gnu.org
2022-06-15 9:26 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-06-15 9:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105984
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |needs-bisection
Target Milestone|--- |13.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/105984] [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1
2022-06-15 5:20 [Bug middle-end/105984] New: [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1 zsojka at seznam dot cz
2022-06-15 9:15 ` [Bug middle-end/105984] " rguenth at gcc dot gnu.org
@ 2022-06-15 9:26 ` jakub at gcc dot gnu.org
2022-06-15 11:18 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-15 9:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105984
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2022-06-15
Status|UNCONFIRMED |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org
Keywords|needs-bisection |
Priority|P3 |P1
Ever confirmed|0 |1
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with my r13-979-g1982fe2692b6c3b7f969ffc4edac59f9d4359e91
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/105984] [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1
2022-06-15 5:20 [Bug middle-end/105984] New: [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1 zsojka at seznam dot cz
2022-06-15 9:15 ` [Bug middle-end/105984] " rguenth at gcc dot gnu.org
2022-06-15 9:26 ` jakub at gcc dot gnu.org
@ 2022-06-15 11:18 ` jakub at gcc dot gnu.org
2022-06-16 12:36 ` cvs-commit at gcc dot gnu.org
2022-06-16 12:38 ` jakub at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-15 11:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105984
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 53143
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53143&action=edit
gcc13-pr105984.patch
Untested fix.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/105984] [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1
2022-06-15 5:20 [Bug middle-end/105984] New: [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1 zsojka at seznam dot cz
` (2 preceding siblings ...)
2022-06-15 11:18 ` jakub at gcc dot gnu.org
@ 2022-06-16 12:36 ` cvs-commit at gcc dot gnu.org
2022-06-16 12:38 ` jakub at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-06-16 12:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105984
--- Comment #3 from CVS 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:74e6a40335765077e235269f19d2d9905d0d9e44
commit r13-1133-g74e6a40335765077e235269f19d2d9905d0d9e44
Author: Jakub Jelinek <jakub@redhat.com>
Date: Thu Jun 16 14:36:04 2022 +0200
match.pd: Fix up __builtin_mul_overflow_p signed type optimization
[PR105984]
Earlier in the simplification pattern, we require that @0 has compatible
type to the type of IMAGPART_EXPR, but for @1 which is a non-zero constant
all we require is that it the constant fits into that type.
Later the code checks if the constant is negative, because when min / max
values are divided by negative divisor, lo will be higher than hi.
In the following testcase, @1 has unsigned char type, while @0 has
int type, so @1 which is 254 is wi::neg_p and we were swapping lo and hi,
even when @1 cast to int isn't negative.
We could use tree_int_cst_sgn (@1) < 0 as the check instead and it would
work both for narrower types of @1 and even same or wider ones, but
I've noticed we probably don't want to call fold_convert (TREE_TYPE (@0),
@1)
twice and when we save that result in a temporary, we can just use
wi::neg_p
on that temporary.
2022-06-16 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/105984
* match.pd (__builtin_mul_overflow_p (x, cst, (stype) 0) ->
x > stype_max / cst || x < stype_min / cst): fold_convert @1
to TREE_TYPE (@0) just once and test for negative divisor
also on that folded constant instead of on @1.
* gcc.c-torture/execute/pr105984.c: New test.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug middle-end/105984] [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1
2022-06-15 5:20 [Bug middle-end/105984] New: [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1 zsojka at seznam dot cz
` (3 preceding siblings ...)
2022-06-16 12:36 ` cvs-commit at gcc dot gnu.org
@ 2022-06-16 12:38 ` jakub at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-16 12:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105984
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed, thanks for the report.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-06-16 12:38 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-15 5:20 [Bug middle-end/105984] New: [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1 zsojka at seznam dot cz
2022-06-15 9:15 ` [Bug middle-end/105984] " rguenth at gcc dot gnu.org
2022-06-15 9:26 ` jakub at gcc dot gnu.org
2022-06-15 11:18 ` jakub at gcc dot gnu.org
2022-06-16 12:36 ` cvs-commit at gcc dot gnu.org
2022-06-16 12:38 ` 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).