public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/109002] New: -O1 -ftree-pre -ftree-partial-pre results in stall value
@ 2023-03-03 6:40 akihiko.odaki at daynix dot com
2023-03-03 6:51 ` [Bug tree-optimization/109002] " pinskia at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: akihiko.odaki at daynix dot com @ 2023-03-03 6:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109002
Bug ID: 109002
Summary: -O1 -ftree-pre -ftree-partial-pre results in stall
value
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: akihiko.odaki at daynix dot com
Target Milestone: ---
The following should emit an executable which prints "a" forever, but the
actual compiled executable prints nothing and just hangs. It seems the code
sees a stall value of variable g.
gcc -O1 -ftree-pre -ftree-partial-pre -x c - <<EOF
#include <stdio.h>
int g;
int h;
int main(void)
{
for (int i = 0; ; i++) {
for (int j = 0; j < g; j++);
if (i & 1) {
if (h)
continue;
if (g)
puts("a");
g = 1;
}
}
}
EOF
I reproduced this bug with the current master. gcc -v says:
Using built-in specs.
COLLECT_GCC=/home/alarm/gcc-installation/usr/local/bin/gcc
COLLECT_LTO_WRAPPER=/home/alarm/gcc-installation/usr/local/bin/../libexec/gcc/aarch64-unknown-linux-gnu/13.0.1/lto-wrapper
Target: aarch64-unknown-linux-gnu
Configured with: ../gcc/configure --disable-bootstrap : (reconfigured)
../gcc/configure --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.0.1 20230302 (experimental) (GCC)
COLLECT_GCC_OPTIONS='-v' '-mlittle-endian' '-mabi=lp64'
/home/alarm/gcc-installation/usr/local/bin/../libexec/gcc/aarch64-unknown-linux-gnu/13.0.1/cc1
-quiet -v -iprefix
/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/aarch64-unknown-linux-gnu/13.0.1/
/home/alarm/a.c -quiet -dumpbase a.c -dumpbase-ext .c -mlittle-endian
-mabi=lp64 -version -o /tmp/ccetU9yt.s
GNU C17 (GCC) version 13.0.1 20230302 (experimental)
(aarch64-unknown-linux-gnu)
compiled by GNU C version 12.1.0, GMP version 6.2.1, MPFR version
4.2.0, MPC version 1.3.1, isl version isl-0.25-GMP
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
ignoring nonexistent directory
"/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/aarch64-unknown-linux-gnu/13.0.1/../../../../aarch64-unknown-linux-gnu/include"
ignoring duplicate directory
"/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/../../lib/gcc/aarch64-unknown-linux-gnu/13.0.1/include"
ignoring duplicate directory
"/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/../../lib/gcc/aarch64-unknown-linux-gnu/13.0.1/include-fixed"
ignoring nonexistent directory
"/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/../../lib/gcc/aarch64-unknown-linux-gnu/13.0.1/../../../../aarch64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/aarch64-unknown-linux-gnu/13.0.1/include
/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/aarch64-unknown-linux-gnu/13.0.1/include-fixed
/usr/local/include
/usr/include
End of search list.
Compiler executable checksum: 374b2759695ed1b72f52cb0f1847fbb3
COLLECT_GCC_OPTIONS='-v' '-mlittle-endian' '-mabi=lp64'
as -v -EL -mabi=lp64 -o /tmp/ccTu98hj.o /tmp/ccetU9yt.s
GNU assembler version 2.38 (aarch64-unknown-linux-gnu) using BFD version (GNU
Binutils) 2.38
COMPILER_PATH=/home/alarm/gcc-installation/usr/local/bin/../libexec/gcc/aarch64-unknown-linux-gnu/13.0.1/:/home/alarm/gcc-installation/usr/local/bin/../libexec/gcc/
LIBRARY_PATH=/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/aarch64-unknown-linux-gnu/13.0.1/:/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/:/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/aarch64-unknown-linux-gnu/13.0.1/../../../../lib64/:/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/aarch64-unknown-linux-gnu/13.0.1/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'a.'
/home/alarm/gcc-installation/usr/local/bin/../libexec/gcc/aarch64-unknown-linux-gnu/13.0.1/collect2
-plugin
/home/alarm/gcc-installation/usr/local/bin/../libexec/gcc/aarch64-unknown-linux-gnu/13.0.1/liblto_plugin.so
-plugin-opt=/home/alarm/gcc-installation/usr/local/bin/../libexec/gcc/aarch64-unknown-linux-gnu/13.0.1/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccup8iGA.res -plugin-opt=-pass-through=-lgcc
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s
--eh-frame-hdr -dynamic-linker /lib/ld-linux-aarch64.so.1 -X -EL -maarch64linux
/lib/crt1.o /lib/crti.o
/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/aarch64-unknown-linux-gnu/13.0.1/crtbegin.o
-L/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/aarch64-unknown-linux-gnu/13.0.1
-L/home/alarm/gcc-installation/usr/local/bin/../lib/gcc
-L/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/aarch64-unknown-linux-gnu/13.0.1/../../../../lib64
-L/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/aarch64-unknown-linux-gnu/13.0.1/../../..
/tmp/ccTu98hj.o -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc
--push-state --as-needed -lgcc_s --pop-state
/home/alarm/gcc-installation/usr/local/bin/../lib/gcc/aarch64-unknown-linux-gnu/13.0.1/crtend.o
/lib/crtn.o
COLLECT_GCC_OPTIONS='-v' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'a.'
git bisect revealed this is a regression caused by commit
5edf02ed2b6de024f83a023d046a6a18f645bc83.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/109002] -O1 -ftree-pre -ftree-partial-pre results in stall value
2023-03-03 6:40 [Bug tree-optimization/109002] New: -O1 -ftree-pre -ftree-partial-pre results in stall value akihiko.odaki at daynix dot com
@ 2023-03-03 6:51 ` pinskia at gcc dot gnu.org
2023-03-03 6:58 ` akihiko.odaki at daynix dot com
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-03 6:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109002
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note there will be undefined behavior when i become INT_MAx.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/109002] -O1 -ftree-pre -ftree-partial-pre results in stall value
2023-03-03 6:40 [Bug tree-optimization/109002] New: -O1 -ftree-pre -ftree-partial-pre results in stall value akihiko.odaki at daynix dot com
2023-03-03 6:51 ` [Bug tree-optimization/109002] " pinskia at gcc dot gnu.org
@ 2023-03-03 6:58 ` akihiko.odaki at daynix dot com
2023-03-03 8:50 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: akihiko.odaki at daynix dot com @ 2023-03-03 6:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109002
--- Comment #2 from Akihiko Odaki <akihiko.odaki at daynix dot com> ---
Oops. Replacing i++ with i = !i removes the undefined behavior while the bug
still remains.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/109002] -O1 -ftree-pre -ftree-partial-pre results in stall value
2023-03-03 6:40 [Bug tree-optimization/109002] New: -O1 -ftree-pre -ftree-partial-pre results in stall value akihiko.odaki at daynix dot com
2023-03-03 6:51 ` [Bug tree-optimization/109002] " pinskia at gcc dot gnu.org
2023-03-03 6:58 ` akihiko.odaki at daynix dot com
@ 2023-03-03 8:50 ` rguenth at gcc dot gnu.org
2023-03-03 9:38 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-03 8:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109002
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2023-03-03
Status|UNCONFIRMED |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
I will have a look.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/109002] -O1 -ftree-pre -ftree-partial-pre results in stall value
2023-03-03 6:40 [Bug tree-optimization/109002] New: -O1 -ftree-pre -ftree-partial-pre results in stall value akihiko.odaki at daynix dot com
` (2 preceding siblings ...)
2023-03-03 8:50 ` rguenth at gcc dot gnu.org
@ 2023-03-03 9:38 ` rguenth at gcc dot gnu.org
2023-03-03 9:55 ` [Bug tree-optimization/109002] [13 Regression] " rguenth at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-03 9:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109002
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
When doing partial PRE we somehow lose the effect of
g = 1;
we also generate weird PHIs:
<bb 2>
pretmp_20 = h;
pretmp_22 = g;
<bb 3>
# prephitmp_21 = PHI <pretmp_20(2), prephitmp_25(10)>
# prephitmp_23 = PHI <pretmp_22(2), prephitmp_24(10)>
# prephitmp_24 = PHI <pretmp_22(2), prephitmp_24(10)>
# prephitmp_25 = PHI <pretmp_20(2), prephitmp_25(10)>
those are all unnecessary ...
There's one old detail I never understood in partial ANTIC compute and that
gets us weird expressions in here, which is that we do not PHI translate
ANTIC_IN when computing PA_OUT. Fixing that fixes this bug.
I have no idea how to create a testcase for the testsuite though besides
verifying we're not inserting any PHI - but we also fail to partial-PRE the
load
of h here, likely because of the iteration order imposed by the infinite
loop which is probably also key to the miscompilation.
Anyway, I have a fix, but I'm not 100% sure it fixes the actual cause.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/109002] [13 Regression] -O1 -ftree-pre -ftree-partial-pre results in stall value
2023-03-03 6:40 [Bug tree-optimization/109002] New: -O1 -ftree-pre -ftree-partial-pre results in stall value akihiko.odaki at daynix dot com
` (3 preceding siblings ...)
2023-03-03 9:38 ` rguenth at gcc dot gnu.org
@ 2023-03-03 9:55 ` rguenth at gcc dot gnu.org
2023-03-03 11:07 ` cvs-commit at gcc dot gnu.org
2023-03-03 11:07 ` rguenth at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-03 9:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109002
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|-O1 -ftree-pre |[13 Regression] -O1
|-ftree-partial-pre results |-ftree-pre
|in stall value |-ftree-partial-pre results
| |in stall value
Target Milestone|--- |13.0
Known to work| |12.2.0
Priority|P3 |P1
Keywords| |needs-bisection
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
Looks like GCC 12 "works", I suspect the compile-time optimizations in pruning
to be the reason since PA_IN has bogus virtual operands in expressions which is
what the fix fixes.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/109002] [13 Regression] -O1 -ftree-pre -ftree-partial-pre results in stall value
2023-03-03 6:40 [Bug tree-optimization/109002] New: -O1 -ftree-pre -ftree-partial-pre results in stall value akihiko.odaki at daynix dot com
` (4 preceding siblings ...)
2023-03-03 9:55 ` [Bug tree-optimization/109002] [13 Regression] " rguenth at gcc dot gnu.org
@ 2023-03-03 11:07 ` cvs-commit at gcc dot gnu.org
2023-03-03 11:07 ` rguenth at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-03-03 11:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109002
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:
https://gcc.gnu.org/g:0132acc03cada2c3b47c48a205e821563153fc80
commit r13-6443-g0132acc03cada2c3b47c48a205e821563153fc80
Author: Richard Biener <rguenther@suse.de>
Date: Fri Mar 3 10:41:29 2023 +0100
tree-optimization/109002 - partial PRE miscompilation
Partial PRE ends up miscompiling the testcase in PR109002, likely
involving a corner case when inifinite loops are involved. The
following avoids the miscompilation by addressing a long-standing
oddity that manifests in odd partial partial redundancies eliminated
that are full redundancies. The oddity is that while we properly
PHI translate the PA_IN set from the successors when computing
PA_OUT but we fail to do the same for ANTIC_IN which is supposed
to be unioned. That results in expressions with wrong virtual
operands being placed in the PA_OUT/IN sets and the pruning
machinery to go wrong because it assumes the expressions in the
sets have virtual operands that are valid in the respective blocks.
PR tree-optimization/109002
* tree-ssa-pre.cc (compute_partial_antic_aux): Properly
PHI-translate ANTIC_IN.
* gcc.dg/torture/pr109002.c: New testcase.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/109002] [13 Regression] -O1 -ftree-pre -ftree-partial-pre results in stall value
2023-03-03 6:40 [Bug tree-optimization/109002] New: -O1 -ftree-pre -ftree-partial-pre results in stall value akihiko.odaki at daynix dot com
` (5 preceding siblings ...)
2023-03-03 11:07 ` cvs-commit at gcc dot gnu.org
@ 2023-03-03 11:07 ` rguenth at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-03 11:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109002
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-03-03 11:07 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-03 6:40 [Bug tree-optimization/109002] New: -O1 -ftree-pre -ftree-partial-pre results in stall value akihiko.odaki at daynix dot com
2023-03-03 6:51 ` [Bug tree-optimization/109002] " pinskia at gcc dot gnu.org
2023-03-03 6:58 ` akihiko.odaki at daynix dot com
2023-03-03 8:50 ` rguenth at gcc dot gnu.org
2023-03-03 9:38 ` rguenth at gcc dot gnu.org
2023-03-03 9:55 ` [Bug tree-optimization/109002] [13 Regression] " rguenth at gcc dot gnu.org
2023-03-03 11:07 ` cvs-commit at gcc dot gnu.org
2023-03-03 11:07 ` rguenth 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).