public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/103222] New: [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu
@ 2021-11-13 8:26 haoxintu at gmail dot com
2021-11-13 11:07 ` [Bug tree-optimization/103222] " hubicka at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: haoxintu at gmail dot com @ 2021-11-13 8:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103222
Bug ID: 103222
Summary: [12 Regression] wrong code at -O2 and above on
x86_64-linux-gnu
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: haoxintu at gmail dot com
Target Milestone: ---
Hi all.
$cat small.c
#include <stdint.h>
#include <stdio.h>
int16_t a;
static uint32_t *b ;
static uint8_t func_2();
static int32_t func_1() {
int16_t a = 1;
func_2(0, a, a);
return 0;
}
uint8_t func_2(uint32_t p1, uint32_t p2, uint32_t p3) {
int p = 0;
for (15;; a++) {
for (0;;) {
if (p2)
break;
b = &p2;
return p2;
}
p3 = (p2 = p3, p);
}
return 0;
}
int main() {
func_1();
printf("%d\n", a);
return 0;
}
$gcc -O1 small.c ; ./a.out
2
$gcc -O2 small.c ; ./a.out
1
$gcc -O3 small.c ; ./a.out
1
$gcc -Os small.c ; ./a.out
1
$gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/haoxin/haoxin-data/compilers/gcc/build/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:../configure
--prefix=/home/haoxin/haoxin-data/compilers/gcc/build/ --enable-bootstrap
--enable-checking=release --enable-languages=c,c++ --enable-multilib :
(reconfigured) ../configure
--prefix=/home/haoxin/haoxin-data/compilers/gcc/build/ --enable-bootstrap
--enable-checking=release --enable-multilib --enable-languages=c,c++,lto
--no-create --no-recursion
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.0 20211113 (experimental) (GCC)
Note that this issue only happens in the current trunk version (12.0) of GCC.
Can also check in Godbolt: https://godbolt.org/z/rz7b9WxvT
Thanks,
Haoxin
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/103222] [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu
2021-11-13 8:26 [Bug tree-optimization/103222] New: [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu haoxintu at gmail dot com
@ 2021-11-13 11:07 ` hubicka at gcc dot gnu.org
2021-11-13 11:45 ` aldyh at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: hubicka at gcc dot gnu.org @ 2021-11-13 11:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103222
Jan Hubicka <hubicka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
CC| |aldyh at gcc dot gnu.org,
| |hubicka at gcc dot gnu.org
Last reconfirmed| |2021-11-13
--- Comment #1 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
So with -O1 we get:
int main ()
{
int16_t a_lsm.11;
int _2;
unsigned short a.5_4;
unsigned short _11;
short int _12;
<bb 2> [local count: 1073741835]:
a_lsm.11_16 = a;
a.5_4 = (unsigned short) a_lsm.11_16;
_11 = a.5_4 + 2;
_12 = (short int) _11;
a = _12;
_2 = (int) _12;
printf ("%d\n", _2);
return 0;
}
while with -O2 we get:
int main ()
{
int _2;
short int a.3_8;
unsigned short a.5_9;
unsigned short _10;
short int _11;
<bb 2> [local count: 1073741824]:
a.3_8 = a;
a.5_9 = (unsigned short) a.3_8;
_10 = a.5_9 + 1;
_11 = (short int) _10;
a = _11;
_2 = (int) _11;
printf ("%d\n", _2);
return 0;
}
Adding always_inline to func_2 makes -O1 and -O2 to agree up to ccp2
110t.mergephi2 and then 111t.threadfull makes a difference:
+ FAIL: path through PHI in bb3 (incoming bb:2) crosses loop
+path: 2->3->xx REJECTED
+Checking profitability of path (backwards): bb:3 (3 insns) bb:5 (latch)
+ Control statement insns: 2
+ Overall: 1 insns
+Checking profitability of path (backwards): bb:3 (3 insns) bb:5 (latch)
+ Control statement insns: 2
+ Overall: 1 insns
+ [1] Registering jump thread: (5, 3) incoming edge; (3, 4) nocopy;
+path: 5->3->4 SUCCESS
+Jump threading proved probability of edge 3->4 too small (it is 11.0%
(guessed) should be always (guessed))
int main ()
{
- uint32_t p3;
uint32_t p2;
+ uint32_t p3;
short int a.0_1;
int _2;
short int a.3_8;
@@ -13,28 +72,15 @@
short int _11;
<bb 2> [local count: 1073741824]:
-
- <bb 3> [local count: 9761289362]:
- # p3_7 = PHI <1(2), 0(5)>
- # p2_17 = PHI <1(2), p3_7(5)>
- if (p2_17 != 0)
- goto <bb 5>; [89.00%]
- else
- goto <bb 4>; [11.00%]
-
- <bb 4> [local count: 1073741824]:
- a.0_1 = a;
- _2 = (int) a.0_1;
- printf ("%d\n", _2);
- return 0;
-
- <bb 5> [local count: 8687547547]:
a.3_8 = a;
a.5_9 = (unsigned short) a.3_8;
_10 = a.5_9 + 1;
_11 = (short int) _10;
a = _11;
- goto <bb 3>; [100.00%]
+ a.0_1 = a;
+ _2 = (int) a.0_1;
+ printf ("%d\n", _2);
+ return 0;
}
and --disable-tree-threadfull1 fixes the difference.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/103222] [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu
2021-11-13 8:26 [Bug tree-optimization/103222] New: [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu haoxintu at gmail dot com
2021-11-13 11:07 ` [Bug tree-optimization/103222] " hubicka at gcc dot gnu.org
@ 2021-11-13 11:45 ` aldyh at gcc dot gnu.org
2021-11-13 11:46 ` aldyh at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: aldyh at gcc dot gnu.org @ 2021-11-13 11:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103222
Aldy Hernandez <aldyh at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P1
--- Comment #2 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
Oh my. So it does happen in real life.
This is exactly what we've been discussing here:
https://gcc.gnu.org/pipermail/gcc-patches/2021-November/584336.html
Thanks for providing a much needed reduced testcase ;-).
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/103222] [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu
2021-11-13 8:26 [Bug tree-optimization/103222] New: [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu haoxintu at gmail dot com
2021-11-13 11:07 ` [Bug tree-optimization/103222] " hubicka at gcc dot gnu.org
2021-11-13 11:45 ` aldyh at gcc dot gnu.org
@ 2021-11-13 11:46 ` aldyh at gcc dot gnu.org
2021-11-13 13:41 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: aldyh at gcc dot gnu.org @ 2021-11-13 11:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103222
--- Comment #3 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
Created attachment 51783
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51783&action=edit
patch in testing
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/103222] [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu
2021-11-13 8:26 [Bug tree-optimization/103222] New: [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu haoxintu at gmail dot com
` (2 preceding siblings ...)
2021-11-13 11:46 ` aldyh at gcc dot gnu.org
@ 2021-11-13 13:41 ` cvs-commit at gcc dot gnu.org
2021-11-13 13:44 ` aldyh at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-13 13:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103222
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Aldy Hernandez <aldyh@gcc.gnu.org>:
https://gcc.gnu.org/g:b7a23949b0dcc4205fcc2be6b84b91441faa384d
commit r12-5228-gb7a23949b0dcc4205fcc2be6b84b91441faa384d
Author: Aldy Hernandez <aldyh@redhat.com>
Date: Sat Nov 13 12:37:25 2021 +0100
path solver: Compute all PHI ranges simultaneously.
PHIs must be resolved simulatenously, otherwise we may not pick up the
ranges incoming to the block.
For example. If we put p3_7 in the cache before all PHIs have been
computed, we will pick up the wrong p3_7 value for p2_17:
# p3_7 = PHI <1(2), 0(5)>
# p2_17 = PHI <1(2), p3_7(5)>
This patch delays updating the cache until all PHIs have been
analyzed.
gcc/ChangeLog:
PR tree-optimization/103222
* gimple-range-path.cc (path_range_query::compute_ranges_in_phis):
New.
(path_range_query::compute_ranges_in_block): Call
compute_ranges_in_phis.
* gimple-range-path.h (path_range_query::compute_ranges_in_phis):
New.
gcc/testsuite/ChangeLog:
* gcc.dg/pr103222.c: New test.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/103222] [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu
2021-11-13 8:26 [Bug tree-optimization/103222] New: [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu haoxintu at gmail dot com
` (3 preceding siblings ...)
2021-11-13 13:41 ` cvs-commit at gcc dot gnu.org
@ 2021-11-13 13:44 ` aldyh at gcc dot gnu.org
2021-11-13 14:15 ` haoxintu at gmail dot com
2021-11-19 12:22 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: aldyh at gcc dot gnu.org @ 2021-11-13 13:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103222
Aldy Hernandez <aldyh at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEW |RESOLVED
--- Comment #5 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
fixed
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/103222] [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu
2021-11-13 8:26 [Bug tree-optimization/103222] New: [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu haoxintu at gmail dot com
` (4 preceding siblings ...)
2021-11-13 13:44 ` aldyh at gcc dot gnu.org
@ 2021-11-13 14:15 ` haoxintu at gmail dot com
2021-11-19 12:22 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: haoxintu at gmail dot com @ 2021-11-13 14:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103222
--- Comment #6 from Haoxin Tu <haoxintu at gmail dot com> ---
(In reply to Aldy Hernandez from comment #5)
> fixed
Thank you for the quick fixing!
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/103222] [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu
2021-11-13 8:26 [Bug tree-optimization/103222] New: [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu haoxintu at gmail dot com
` (5 preceding siblings ...)
2021-11-13 14:15 ` haoxintu at gmail dot com
@ 2021-11-19 12:22 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-19 12:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103222
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.0
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-11-19 12:22 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-13 8:26 [Bug tree-optimization/103222] New: [12 Regression] wrong code at -O2 and above on x86_64-linux-gnu haoxintu at gmail dot com
2021-11-13 11:07 ` [Bug tree-optimization/103222] " hubicka at gcc dot gnu.org
2021-11-13 11:45 ` aldyh at gcc dot gnu.org
2021-11-13 11:46 ` aldyh at gcc dot gnu.org
2021-11-13 13:41 ` cvs-commit at gcc dot gnu.org
2021-11-13 13:44 ` aldyh at gcc dot gnu.org
2021-11-13 14:15 ` haoxintu at gmail dot com
2021-11-19 12:22 ` 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).