public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/103399] New: [12 Regression] Wrong code with -O2
@ 2021-11-23 22:34 vsevolod.livinskij at frtk dot ru
2021-11-24 1:38 ` [Bug tree-optimization/103399] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: vsevolod.livinskij at frtk dot ru @ 2021-11-23 22:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103399
Bug ID: 103399
Summary: [12 Regression] Wrong code with -O2
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: vsevolod.livinskij at frtk dot ru
Target Milestone: ---
Link to the Compiler Explorer: https://godbolt.org/z/3GE6fKvYr
Reproducer:
#include <stdio.h>
char a = 0;
long long b[8][10][18];
void e(int, long long[][10][18]) __attribute__((noipa));
void e(int f, long long g[][10][18]) {
for (int d = 0; d < f; d += 3LL)
for (int c = 0; c < ((f ? g[5][0][0] : 0) ^ g[5][0][0]) + 1; c++)
a = 42;
}
int main() {
for (size_t i = 0; i < 8; ++i)
for (size_t k = 0; k < 10; ++k)
for (size_t j = 0; j < 8; ++j)
b[i][k][j] = -1311387439415292401LL;
e(8, b);
printf("%u\n", a);
if (a != 42)
__builtin_abort();
}
Error:
>$ g++ -O1 driver.cpp && ./a.out
42
>$ g++ -O2 driver.cpp && ./a.out
0
gcc version 12.0.0 20211123 (721d8b9e26bf8205c1f2125c2626919a408cdbe4) (GCC)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/103399] [12 Regression] Wrong code with -O2
2021-11-23 22:34 [Bug tree-optimization/103399] New: [12 Regression] Wrong code with -O2 vsevolod.livinskij at frtk dot ru
@ 2021-11-24 1:38 ` pinskia at gcc dot gnu.org
2021-11-24 2:00 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-24 1:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103399
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/103399] [12 Regression] Wrong code with -O2
2021-11-23 22:34 [Bug tree-optimization/103399] New: [12 Regression] Wrong code with -O2 vsevolod.livinskij at frtk dot ru
2021-11-24 1:38 ` [Bug tree-optimization/103399] " pinskia at gcc dot gnu.org
@ 2021-11-24 2:00 ` pinskia at gcc dot gnu.org
2021-11-24 2:00 ` pinskia at gcc dot gnu.org
2021-11-24 2:02 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-24 2:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103399
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2021-11-24
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed reduced testcase:
int t1 = -2;
int e(int) __attribute__((noipa));
int e(int f) {
int t = 0;
for (int d = 0; d < f; d ++) {
for (int c = 0; c < ((f ? t1 : 0) ^ t1) + 1; c++)
t= 42;
}
return t;
}
int main() {
unsigned a = e(1);
printf("%u\n", a);
if (a != 42)
__builtin_abort ();
}
Note the t1 being negative is important. t1 being global is also important, if
you do a load of t1 before either loop, you end up with working code.
THis is another bswap issue ...
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/103399] [12 Regression] Wrong code with -O2
2021-11-23 22:34 [Bug tree-optimization/103399] New: [12 Regression] Wrong code with -O2 vsevolod.livinskij at frtk dot ru
2021-11-24 1:38 ` [Bug tree-optimization/103399] " pinskia at gcc dot gnu.org
2021-11-24 2:00 ` pinskia at gcc dot gnu.org
@ 2021-11-24 2:00 ` pinskia at gcc dot gnu.org
2021-11-24 2:02 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-24 2:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103399
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Before bswap, we have:
iftmp.0_11 = t1;
t1.1_1 = t1;
_2 = t1.1_1 ^ iftmp.0_11;
But after we get:
load_dst_8 = MEM[(int *)&t1];
_2 = (int) load_dst_8;
Which is wrong as _2 should have been 0.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/103399] [12 Regression] Wrong code with -O2
2021-11-23 22:34 [Bug tree-optimization/103399] New: [12 Regression] Wrong code with -O2 vsevolod.livinskij at frtk dot ru
` (2 preceding siblings ...)
2021-11-24 2:00 ` pinskia at gcc dot gnu.org
@ 2021-11-24 2:02 ` pinskia at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-24 2:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103399
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|NEW |RESOLVED
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 103376.
*** This bug has been marked as a duplicate of bug 103376 ***
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-11-24 2:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-23 22:34 [Bug tree-optimization/103399] New: [12 Regression] Wrong code with -O2 vsevolod.livinskij at frtk dot ru
2021-11-24 1:38 ` [Bug tree-optimization/103399] " pinskia at gcc dot gnu.org
2021-11-24 2:00 ` pinskia at gcc dot gnu.org
2021-11-24 2:00 ` pinskia at gcc dot gnu.org
2021-11-24 2:02 ` 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).