public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111469] New: Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45
@ 2023-09-19 7:16 shaohua.li at inf dot ethz.ch
2023-09-19 7:22 ` [Bug tree-optimization/111469] " pinskia at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-09-19 7:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111469
Bug ID: 111469
Summary: Wrong code at -Os on x86_64-linux-gnu since
r14-573-g69f1a8af45
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: shaohua.li at inf dot ethz.ch
CC: pinskia at gcc dot gnu.org
Target Milestone: ---
gcc at -Os produced the wrong code.
Bisected to r14-573-g69f1a8af45
Compiler explorer: https://godbolt.org/z/fheon13dP
$ cat a.c
int printf(const char *, ...);
int a;
long b, c, e, f;
char *g;
unsigned short h = 5;
static unsigned short *i = &h;
unsigned j;
long k(long m, long n) {
if (n)
e = m;
c = e;
return e;
}
char o() {
char l;
while (f)
;
l = *g;
return l;
}
int main() {
int p;
int q;
for (; j - 9 >= 29; j = k(-95, *i) + 127) {
*i || o();
long d = h;
p = d == 0 ? 0 : b % d;
q = p;
int *r[1] = {&q};
}
printf("%d\n", a);
}
$
$ gcc a.c && ./a.out
0
$ gcc a.c -Os && ./a.out
segmentation fault
$
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/111469] Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45
2023-09-19 7:16 [Bug tree-optimization/111469] New: Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45 shaohua.li at inf dot ethz.ch
@ 2023-09-19 7:22 ` pinskia at gcc dot gnu.org
2023-09-19 7:50 ` [Bug tree-optimization/111469] [14 Regression] " pinskia at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-19 7:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111469
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I am 99% sure this is a latent bug. Will find a testcase later tomorrow.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/111469] [14 Regression] Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45
2023-09-19 7:16 [Bug tree-optimization/111469] New: Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45 shaohua.li at inf dot ethz.ch
2023-09-19 7:22 ` [Bug tree-optimization/111469] " pinskia at gcc dot gnu.org
@ 2023-09-19 7:50 ` pinskia at gcc dot gnu.org
2023-09-19 7:51 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-19 7:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111469
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |14.0
Summary|Wrong code at -Os on |[14 Regression] Wrong code
|x86_64-linux-gnu since |at -Os on x86_64-linux-gnu
|r14-573-g69f1a8af45 |since r14-573-g69f1a8af45
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Looks like a latent bug in phiopt exposed by my phiopt patch. Still trying to
figure out what is going wrong.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/111469] [14 Regression] Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45
2023-09-19 7:16 [Bug tree-optimization/111469] New: Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45 shaohua.li at inf dot ethz.ch
2023-09-19 7:22 ` [Bug tree-optimization/111469] " pinskia at gcc dot gnu.org
2023-09-19 7:50 ` [Bug tree-optimization/111469] [14 Regression] " pinskia at gcc dot gnu.org
@ 2023-09-19 7:51 ` pinskia at gcc dot gnu.org
2023-09-19 8:17 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-19 7:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111469
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. it is a bug in minmax_replacement ...
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/111469] [14 Regression] Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45
2023-09-19 7:16 [Bug tree-optimization/111469] New: Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45 shaohua.li at inf dot ethz.ch
` (2 preceding siblings ...)
2023-09-19 7:51 ` pinskia at gcc dot gnu.org
@ 2023-09-19 8:17 ` pinskia at gcc dot gnu.org
2023-09-20 5:07 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-19 8:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111469
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2023-09-19
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
Reduced further and fails at -O1 and above now:
```
long f;
char *g;
[[gnu::noinline]]
char o() {
char l;
while (f)
;
l = *g;
return l;
}
[[gnu::noinline]]
unsigned short gg(unsigned short a, unsigned short b)
{
short d;
if (a > b)
{
d= b;
}
else
{
o();
d = a;
}
return d;
}
int main(void)
{
gg(3, 2);
}
```
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/111469] [14 Regression] Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45
2023-09-19 7:16 [Bug tree-optimization/111469] New: Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45 shaohua.li at inf dot ethz.ch
` (3 preceding siblings ...)
2023-09-19 8:17 ` pinskia at gcc dot gnu.org
@ 2023-09-20 5:07 ` pinskia at gcc dot gnu.org
2023-09-21 8:10 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-20 5:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111469
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I am going to fix minmax_replacement over the weekend.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/111469] [14 Regression] Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45
2023-09-19 7:16 [Bug tree-optimization/111469] New: Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45 shaohua.li at inf dot ethz.ch
` (4 preceding siblings ...)
2023-09-20 5:07 ` pinskia at gcc dot gnu.org
@ 2023-09-21 8:10 ` pinskia at gcc dot gnu.org
2023-09-24 19:17 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-21 8:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111469
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
URL| |https://gcc.gnu.org/piperma
| |il/gcc-patches/2023-Septemb
| |er/631099.html
Keywords| |patch
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-September/631099.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/111469] [14 Regression] Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45
2023-09-19 7:16 [Bug tree-optimization/111469] New: Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45 shaohua.li at inf dot ethz.ch
` (5 preceding siblings ...)
2023-09-21 8:10 ` pinskia at gcc dot gnu.org
@ 2023-09-24 19:17 ` pinskia at gcc dot gnu.org
2023-09-26 14:55 ` cvs-commit at gcc dot gnu.org
2023-09-26 14:56 ` pinskia at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-24 19:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111469
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |19373742 at buaa dot edu.cn
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 111574 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/111469] [14 Regression] Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45
2023-09-19 7:16 [Bug tree-optimization/111469] New: Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45 shaohua.li at inf dot ethz.ch
` (6 preceding siblings ...)
2023-09-24 19:17 ` pinskia at gcc dot gnu.org
@ 2023-09-26 14:55 ` cvs-commit at gcc dot gnu.org
2023-09-26 14:56 ` pinskia at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-26 14:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111469
--- Comment #8 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:68fa82e2d8f868a233103102dff2449a416bc566
commit r14-4279-g68fa82e2d8f868a233103102dff2449a416bc566
Author: Andrew Pinski <apinski@marvell.com>
Date: Thu Sep 21 03:05:17 2023 +0000
PHIOPT: Fix minmax_replacement for three way
So when diamond bb support was added to minmax_replacement in
r13-1950-g9bb19e143cfe,
the code was not expecting the alt_middle_bb not to exist if it was empty
(for threeway_p).
So when factor_out_conditional_conversion was used to factor out
conversions, it turns out
the assumption for alt_middle_bb to be wrong and we ended up with
threeway_p being true but
having middle_bb being empty but alt_middle_bb not being empty which causes
wrong code in
many cases.
This patch fixes the issue by adding a test for the 2 cases where the
assumption on
threeway_p case having the other bb being empty.
Changes made:
v2: Fix test for `(a <= u) b = MAX(a, d) else b = u`.
Note my plan for GCC 15 is remove minmax_replacement as match.pd will catch
all cases
at that point.
OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
PR tree-optimization/111469
gcc/ChangeLog:
* tree-ssa-phiopt.cc (minmax_replacement): Fix
the assumption for the `non-diamond` handling cases
of diamond code.
gcc/testsuite/ChangeLog:
* gcc.c-torture/execute/pr111469-1.c: New test.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/111469] [14 Regression] Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45
2023-09-19 7:16 [Bug tree-optimization/111469] New: Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45 shaohua.li at inf dot ethz.ch
` (7 preceding siblings ...)
2023-09-26 14:55 ` cvs-commit at gcc dot gnu.org
@ 2023-09-26 14:56 ` pinskia at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-26 14:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111469
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-09-26 14:56 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-19 7:16 [Bug tree-optimization/111469] New: Wrong code at -Os on x86_64-linux-gnu since r14-573-g69f1a8af45 shaohua.li at inf dot ethz.ch
2023-09-19 7:22 ` [Bug tree-optimization/111469] " pinskia at gcc dot gnu.org
2023-09-19 7:50 ` [Bug tree-optimization/111469] [14 Regression] " pinskia at gcc dot gnu.org
2023-09-19 7:51 ` pinskia at gcc dot gnu.org
2023-09-19 8:17 ` pinskia at gcc dot gnu.org
2023-09-20 5:07 ` pinskia at gcc dot gnu.org
2023-09-21 8:10 ` pinskia at gcc dot gnu.org
2023-09-24 19:17 ` pinskia at gcc dot gnu.org
2023-09-26 14:55 ` cvs-commit at gcc dot gnu.org
2023-09-26 14:56 ` 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).