public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114207] New: Wrong code bug since GCC 12.1
@ 2024-03-02 9:21 congli at smail dot nju.edu.cn
2024-03-02 9:33 ` [Bug tree-optimization/114207] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` pinskia at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: congli at smail dot nju.edu.cn @ 2024-03-02 9:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114207
Bug ID: 114207
Summary: Wrong code bug since GCC 12.1
Product: gcc
Version: 12.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: congli at smail dot nju.edu.cn
Target Milestone: ---
The program below shows a wrong code bug, where the correct result should be
"s.a=12, s.b=6" while `-w -O3 -fno-tree-forwprop` prints "s.a=12, s.b=0" or
"s.a=12, s.b=<random>". The bug stems from at least GCC 12.1 to our trunk.
```
#include <stdio.h>
#include <stdint.h>
struct S {
int a, b;
};
__attribute__((noinline))
void foo (struct S *s) {
struct S ss = (struct S) {
.a = s->b,
.b = s->a
};
*s = ss;
}
int main() {
struct S s = {6, 12};
foo(&s);
printf("s.a=%d, s.b=%d\n", s.a, s.b);
return 0;
}
```
Compiler Explorer: https://gcc.godbolt.org/z/8dbMWjsd8
After checking the assembly, we found that `8(%rsp)` (representing s.b) was not
initialized by the constant `6` while it is printed.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/114207] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop`
2024-03-02 9:21 [Bug c/114207] New: Wrong code bug since GCC 12.1 congli at smail dot nju.edu.cn
@ 2024-03-02 9:33 ` pinskia at gcc dot gnu.org
2024-03-02 17:53 ` [Bug tree-optimization/114207] [12/13/14 Regression] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` since r12-5439 jakub at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-02 9:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114207
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=111613
Keywords| |wrong-code
Status|UNCONFIRMED |NEW
Component|c |tree-optimization
Summary|Wrong code bug since GCC |modref gets confused by
|12.1 |vecotorized code ` -O3
| |-fno-tree-forwprop`
Target Milestone|--- |12.4
Ever confirmed|0 |1
Last reconfirmed| |2024-03-02
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
The IR is:
```
vectp.7_7 = &s_4(D)->b;
vectp.7_8 = vectp.7_7 + 18446744073709551612;
vect__1.8_9 = MEM <vector(2) int> [(int *)vectp.7_8];
vect__2.9_10 = VEC_PERM_EXPR <vect__1.8_9, vect__1.8_9, { 1, 0 }>;
MEM <vector(2) int> [(int *)s_4(D)] = vect__2.9_10;
```
modref thinks this only reads s->b somehow.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/114207] [12/13/14 Regression] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` since r12-5439
2024-03-02 9:21 [Bug c/114207] New: Wrong code bug since GCC 12.1 congli at smail dot nju.edu.cn
2024-03-02 9:33 ` [Bug tree-optimization/114207] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` pinskia at gcc dot gnu.org
@ 2024-03-02 17:53 ` jakub at gcc dot gnu.org
2024-03-03 13:13 ` hubicka at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-03-02 17:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114207
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hubicka at gcc dot gnu.org,
| |jakub at gcc dot gnu.org
Summary|[12/13/14 Regression] |[12/13/14 Regression]
|modref gets confused by |modref gets confused by
|vecotorized code ` -O3 |vecotorized code ` -O3
|-fno-tree-forwprop` |-fno-tree-forwprop` since
| |r12-5439
Priority|P3 |P2
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r12-5439-g0f5afb626381d19bfced30bc19cf3b03867fa6f5
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/114207] [12/13/14 Regression] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` since r12-5439
2024-03-02 9:21 [Bug c/114207] New: Wrong code bug since GCC 12.1 congli at smail dot nju.edu.cn
2024-03-02 9:33 ` [Bug tree-optimization/114207] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` pinskia at gcc dot gnu.org
2024-03-02 17:53 ` [Bug tree-optimization/114207] [12/13/14 Regression] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` since r12-5439 jakub at gcc dot gnu.org
@ 2024-03-03 13:13 ` hubicka at gcc dot gnu.org
2024-06-20 9:15 ` [Bug tree-optimization/114207] [12/13/14/15 " rguenth at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: hubicka at gcc dot gnu.org @ 2024-03-03 13:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114207
Jan Hubicka <hubicka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |hubicka at gcc dot gnu.org
--- Comment #3 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
mine.
The summary is:
loads:
Base 0: alias set 1
Ref 0: alias set 1
access: Parm 0 param offset:4 offset:0 size:64 max_size:64
stores:
Base 0: alias set 1
Ref 0: alias set 1
access: Parm 0 param offset:0 offset:0 size:64 max_size:64
while with fwprop we get:
loads:
Base 0: alias set 1
Ref 0: alias set 1
access: Parm 0 param offset:0 offset:0 size:64 max_size:64
stores:
Base 0: alias set 1
Ref 0: alias set 1
access: Parm 0 param offset:0 offset:0 size:64 max_size:64
So it seems that offset is misaccounted.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/114207] [12/13/14/15 Regression] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` since r12-5439
2024-03-02 9:21 [Bug c/114207] New: Wrong code bug since GCC 12.1 congli at smail dot nju.edu.cn
` (2 preceding siblings ...)
2024-03-03 13:13 ` hubicka at gcc dot gnu.org
@ 2024-06-20 9:15 ` rguenth at gcc dot gnu.org
2024-07-22 15:11 ` hubicka at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-20 9:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114207
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|12.4 |12.5
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 12.4 is being released, retargeting bugs to GCC 12.5.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/114207] [12/13/14/15 Regression] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` since r12-5439
2024-03-02 9:21 [Bug c/114207] New: Wrong code bug since GCC 12.1 congli at smail dot nju.edu.cn
` (3 preceding siblings ...)
2024-06-20 9:15 ` [Bug tree-optimization/114207] [12/13/14/15 " rguenth at gcc dot gnu.org
@ 2024-07-22 15:11 ` hubicka at gcc dot gnu.org
2024-07-22 16:05 ` [Bug ipa/114207] [12/13/14/15 Regression] modref gets confused by vectorized code `-O3 " cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: hubicka at gcc dot gnu.org @ 2024-07-22 15:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114207
--- Comment #5 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
The offset gets lost in ipa-prop.cc
diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 7d7cb3835d2..99ebd6229ec 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -1370,9 +1370,9 @@ unadjusted_ptr_and_unit_offset (tree op, tree *ret,
poly_int64 *offset_ret)
{
if (TREE_CODE (op) == ADDR_EXPR)
{
- poly_int64 extra_offset = 0;
+ poly_int64 extra_offset;
tree base = get_addr_base_and_unit_offset (TREE_OPERAND (op, 0),
- &offset);
+ &extra_offset);
if (!base)
{
base = get_base_address (TREE_OPERAND (op, 0));
here offset is the offset being tracked and get_addr_base_and_unit_offset is
intended to initialize extra_offset which is later added to offset.
In the testcase the pointer is first offseted by +4 and later by -4 which
combines to 0.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug ipa/114207] [12/13/14/15 Regression] modref gets confused by vectorized code `-O3 -fno-tree-forwprop` since r12-5439
2024-03-02 9:21 [Bug c/114207] New: Wrong code bug since GCC 12.1 congli at smail dot nju.edu.cn
` (4 preceding siblings ...)
2024-07-22 15:11 ` hubicka at gcc dot gnu.org
@ 2024-07-22 16:05 ` cvs-commit at gcc dot gnu.org
2024-07-22 16:55 ` cvs-commit at gcc dot gnu.org
2024-07-22 16:58 ` [Bug ipa/114207] [12/13 " hubicka at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-22 16:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114207
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jan Hubicka <hubicka@gcc.gnu.org>:
https://gcc.gnu.org/g:391f46f10b0586c074014de82efe76787739bb0c
commit r15-2201-g391f46f10b0586c074014de82efe76787739bb0c
Author: Jan Hubicka <hubicka@ucw.cz>
Date: Mon Jul 22 18:05:26 2024 +0200
Fix accounting of offsets in unadjusted_ptr_and_unit_offset
unadjusted_ptr_and_unit_offset accidentally throws away the offset computed
by
get_addr_base_and_unit_offset. Instead of passing extra_offset it passes
offset.
PR ipa/114207
gcc/ChangeLog:
* ipa-prop.cc (unadjusted_ptr_and_unit_offset): Fix accounting of
offsets in ADDR_EXPR.
gcc/testsuite/ChangeLog:
* gcc.c-torture/execute/pr114207.c: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug ipa/114207] [12/13/14/15 Regression] modref gets confused by vectorized code `-O3 -fno-tree-forwprop` since r12-5439
2024-03-02 9:21 [Bug c/114207] New: Wrong code bug since GCC 12.1 congli at smail dot nju.edu.cn
` (5 preceding siblings ...)
2024-07-22 16:05 ` [Bug ipa/114207] [12/13/14/15 Regression] modref gets confused by vectorized code `-O3 " cvs-commit at gcc dot gnu.org
@ 2024-07-22 16:55 ` cvs-commit at gcc dot gnu.org
2024-07-22 16:58 ` [Bug ipa/114207] [12/13 " hubicka at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-22 16:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114207
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Jan Hubicka
<hubicka@gcc.gnu.org>:
https://gcc.gnu.org/g:f2e98084792821c3849074867d5b007c49028854
commit r14-10488-gf2e98084792821c3849074867d5b007c49028854
Author: Jan Hubicka <hubicka@ucw.cz>
Date: Mon Jul 22 18:05:26 2024 +0200
Fix accounting of offsets in unadjusted_ptr_and_unit_offset
unadjusted_ptr_and_unit_offset accidentally throws away the offset computed
by
get_addr_base_and_unit_offset. Instead of passing extra_offset it passes
offset.
PR ipa/114207
gcc/ChangeLog:
* ipa-prop.cc (unadjusted_ptr_and_unit_offset): Fix accounting of
offsets in ADDR_EXPR.
gcc/testsuite/ChangeLog:
* gcc.c-torture/execute/pr114207.c: New test.
(cherry picked from commit 391f46f10b0586c074014de82efe76787739bb0c)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug ipa/114207] [12/13 Regression] modref gets confused by vectorized code `-O3 -fno-tree-forwprop` since r12-5439
2024-03-02 9:21 [Bug c/114207] New: Wrong code bug since GCC 12.1 congli at smail dot nju.edu.cn
` (6 preceding siblings ...)
2024-07-22 16:55 ` cvs-commit at gcc dot gnu.org
@ 2024-07-22 16:58 ` hubicka at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: hubicka at gcc dot gnu.org @ 2024-07-22 16:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114207
Jan Hubicka <hubicka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[12/13/14/15 Regression] |[12/13 Regression] modref
|modref gets confused by |gets confused by vectorized
|vectorized code `-O3 |code `-O3
|-fno-tree-forwprop` since |-fno-tree-forwprop` since
|r12-5439 |r12-5439
--- Comment #8 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
Fixed on 14/15 so far
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-07-22 16:58 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-02 9:21 [Bug c/114207] New: Wrong code bug since GCC 12.1 congli at smail dot nju.edu.cn
2024-03-02 9:33 ` [Bug tree-optimization/114207] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` pinskia at gcc dot gnu.org
2024-03-02 17:53 ` [Bug tree-optimization/114207] [12/13/14 Regression] modref gets confused by vecotorized code ` -O3 -fno-tree-forwprop` since r12-5439 jakub at gcc dot gnu.org
2024-03-03 13:13 ` hubicka at gcc dot gnu.org
2024-06-20 9:15 ` [Bug tree-optimization/114207] [12/13/14/15 " rguenth at gcc dot gnu.org
2024-07-22 15:11 ` hubicka at gcc dot gnu.org
2024-07-22 16:05 ` [Bug ipa/114207] [12/13/14/15 Regression] modref gets confused by vectorized code `-O3 " cvs-commit at gcc dot gnu.org
2024-07-22 16:55 ` cvs-commit at gcc dot gnu.org
2024-07-22 16:58 ` [Bug ipa/114207] [12/13 " hubicka 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).