public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110954] New: [14 Regression] Wrong code with -O0
@ 2023-08-09 0:34 vsevolod.livinskiy at gmail dot com
2023-08-09 0:39 ` [Bug tree-optimization/110954] " pinskia at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: vsevolod.livinskiy at gmail dot com @ 2023-08-09 0:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110954
Bug ID: 110954
Summary: [14 Regression] Wrong code with -O0
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: vsevolod.livinskiy at gmail dot com
Target Milestone: ---
Link to the compiler explorer:
https://godbolt.org/z/WYoT4hW9v
Reproducer:
#include <stdio.h>
unsigned long long a;
void b(unsigned long long *c, int g) { *c = g; }
int d, e = -38921963;
long f;
int main() {
d = (-1807546494482798067UL - f < (6033086967267 > 0)) & e |
!(-1807546494482798067UL - f < (6033086967267 > 0));
b(&a, d);
printf("%llu\n", a);
if (a != 1)
__builtin_abort();
}
Error:
>$ g++ -O0 test.cpp && ./a.out
18446744073670629653
Aborted (core dumped)
>$ /usr/bin/g++-11 -O0 test.cpp && ./a.out
1
gcc version 14.0.0 20230808 (20659be04c2749f9f47b085f1789eee0d145fb36)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/110954] [14 Regression] Wrong code with -O0
2023-08-09 0:34 [Bug tree-optimization/110954] New: [14 Regression] Wrong code with -O0 vsevolod.livinskiy at gmail dot com
@ 2023-08-09 0:39 ` pinskia at gcc dot gnu.org
2023-08-09 0:44 ` [Bug middle-end/110954] " pinskia at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-09 0:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110954
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2023-08-09
CC| |pinskia at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
Target Milestone|--- |14.0
Ever confirmed|0 |1
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think this is mine.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/110954] [14 Regression] Wrong code with -O0
2023-08-09 0:34 [Bug tree-optimization/110954] New: [14 Regression] Wrong code with -O0 vsevolod.livinskiy at gmail dot com
2023-08-09 0:39 ` [Bug tree-optimization/110954] " pinskia at gcc dot gnu.org
@ 2023-08-09 0:44 ` pinskia at gcc dot gnu.org
2023-08-09 19:39 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-09 0:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110954
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|tree-optimization |middle-end
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Generic has different type constraints than gimple and that is what is
confusing here.
bitwise_inverted_equal_p cannot check comparisons to see if they are inverse of
each other unless the type is a boolean type ...
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/110954] [14 Regression] Wrong code with -O0
2023-08-09 0:34 [Bug tree-optimization/110954] New: [14 Regression] Wrong code with -O0 vsevolod.livinskiy at gmail dot com
2023-08-09 0:39 ` [Bug tree-optimization/110954] " pinskia at gcc dot gnu.org
2023-08-09 0:44 ` [Bug middle-end/110954] " pinskia at gcc dot gnu.org
@ 2023-08-09 19:39 ` pinskia at gcc dot gnu.org
2023-08-10 0:21 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-09 19:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110954
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Cleaned and simplified up testcase:
```
#define comparison (f < 0)
int main() {
int f = 0;
int d = comparison | !comparison;
if (d != 1)
__builtin_abort();
}
```
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/110954] [14 Regression] Wrong code with -O0
2023-08-09 0:34 [Bug tree-optimization/110954] New: [14 Regression] Wrong code with -O0 vsevolod.livinskiy at gmail dot com
` (2 preceding siblings ...)
2023-08-09 19:39 ` pinskia at gcc dot gnu.org
@ 2023-08-10 0:21 ` pinskia at gcc dot gnu.org
2023-08-10 18:41 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-10 0:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110954
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
URL| |https://gcc.gnu.org/piperma
| |il/gcc-patches/2023-August/
| |626896.html
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-August/626896.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/110954] [14 Regression] Wrong code with -O0
2023-08-09 0:34 [Bug tree-optimization/110954] New: [14 Regression] Wrong code with -O0 vsevolod.livinskiy at gmail dot com
` (3 preceding siblings ...)
2023-08-10 0:21 ` pinskia at gcc dot gnu.org
@ 2023-08-10 18:41 ` pinskia at gcc dot gnu.org
2023-08-11 6:51 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-10 18:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110954
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 55718
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55718&action=edit
new patch which I am testing
The only thing is it is sometimes overly conserative with the check of
`!wascmp || element_precision (type) == 1` for vector types
but that is ok those were not handled before either anyways.
We do handle `a & ~a` and `a |^ ~a` for all cases (correctly) like we did
previously and before r14-2925-g2bae476b511dc441bf61da8a4 .
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/110954] [14 Regression] Wrong code with -O0
2023-08-09 0:34 [Bug tree-optimization/110954] New: [14 Regression] Wrong code with -O0 vsevolod.livinskiy at gmail dot com
` (4 preceding siblings ...)
2023-08-10 18:41 ` pinskia at gcc dot gnu.org
@ 2023-08-11 6:51 ` cvs-commit at gcc dot gnu.org
2023-08-13 17:50 ` pinskia at gcc dot gnu.org
2023-08-15 0:11 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-08-11 6:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110954
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:
https://gcc.gnu.org/g:f956c232649e4bb7482786cd54e5d5b4085cd00a
commit r14-3140-gf956c232649e4bb7482786cd54e5d5b4085cd00a
Author: Andrew Pinski <apinski@marvell.com>
Date: Wed Aug 9 13:49:24 2023 -0700
Fix PR 110954: wrong code with cmp | !cmp
This was an oversight on my part forgetting that
cmp will might have a different true value than all ones
but will have a value of 1 in most cases.
This means if we have `(f < 0) | !(f < 0)` we would
optimize this to -1 rather than just 1.
This is version 2 of the patch.
Decided to go down a different route than just checking if
the precission was 1 inside bitwise_inverted_equal_p.
So instead bitwise_inverted_equal_p gets passed an argument
that will be set if there was a comparison that was being compared
and the user of bitwise_inverted_equal_p decides what needs to be done.
In most uses of bitwise_inverted_equal_p, the check will be
`!wascmp || element_precision (type) == 1` .
But in the case of `a & ~a` and `a ^| ~a` we can handle the case
of wascmp by using constant_boolean_node isntead.
OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
PR tree-optimization/110954
gcc/ChangeLog:
* generic-match-head.cc (bitwise_inverted_equal_p): Add
wascmp argument and set it accordingly.
* gimple-match-head.cc (bitwise_inverted_equal_p): Add
wascmp argument to the macro.
(gimple_bitwise_inverted_equal_p): Add
wascmp argument and set it accordingly.
* match.pd (`a & ~a`, `a ^| ~a`): Update call
to bitwise_inverted_equal_p and handle wascmp case.
(`(~x | y) & x`, `(~x | y) & x`, `a?~t:t`): Update
call to bitwise_inverted_equal_p and check to see
if was !wascmp or if precision was 1.
gcc/testsuite/ChangeLog:
* gcc.c-torture/execute/pr110954-1.c: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/110954] [14 Regression] Wrong code with -O0
2023-08-09 0:34 [Bug tree-optimization/110954] New: [14 Regression] Wrong code with -O0 vsevolod.livinskiy at gmail dot com
` (5 preceding siblings ...)
2023-08-11 6:51 ` cvs-commit at gcc dot gnu.org
@ 2023-08-13 17:50 ` pinskia at gcc dot gnu.org
2023-08-15 0:11 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-13 17:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110954
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jwzeng at nuaa dot edu.cn
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 111007 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug middle-end/110954] [14 Regression] Wrong code with -O0
2023-08-09 0:34 [Bug tree-optimization/110954] New: [14 Regression] Wrong code with -O0 vsevolod.livinskiy at gmail dot com
` (6 preceding siblings ...)
2023-08-13 17:50 ` pinskia at gcc dot gnu.org
@ 2023-08-15 0:11 ` pinskia at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-15 0:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110954
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-08-15 0:11 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-09 0:34 [Bug tree-optimization/110954] New: [14 Regression] Wrong code with -O0 vsevolod.livinskiy at gmail dot com
2023-08-09 0:39 ` [Bug tree-optimization/110954] " pinskia at gcc dot gnu.org
2023-08-09 0:44 ` [Bug middle-end/110954] " pinskia at gcc dot gnu.org
2023-08-09 19:39 ` pinskia at gcc dot gnu.org
2023-08-10 0:21 ` pinskia at gcc dot gnu.org
2023-08-10 18:41 ` pinskia at gcc dot gnu.org
2023-08-11 6:51 ` cvs-commit at gcc dot gnu.org
2023-08-13 17:50 ` pinskia at gcc dot gnu.org
2023-08-15 0:11 ` pinskia 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).