[Bug middle-end/101062] [10 Regression] wrong code with "-O2 -fno-toplevel-reorder -frename-registers"

2022-05-11 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101062

Jakub Jelinek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #24 from Jakub Jelinek  ---
Fixed.

[Bug middle-end/101062] [10 Regression] wrong code with "-O2 -fno-toplevel-reorder -frename-registers"

2022-05-11 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101062

--- Comment #23 from CVS Commits  ---
The releases/gcc-9 branch has been updated by Jakub Jelinek
:

https://gcc.gnu.org/g:80f194b25f573b409ada5761778fb6dfb3cf85e9

commit r9-10080-g80f194b25f573b409ada5761778fb6dfb3cf85e9
Author: Jakub Jelinek 
Date:   Fri Jun 18 11:20:40 2021 +0200

stor-layout: Don't create DECL_BIT_FIELD_REPRESENTATIVE for QUAL_UNION_TYPE
[PR101062]

> The following patch does create them, but treats all such bitfields as if
> they were in a structure where the particular bitfield is the only field.

While the patch passed bootstrap/regtest on the trunk, when trying to
backport it to 11 branch the bootstrap failed with
atree.ads:3844:34: size for "Node_Record" too small
errors.  Turns out the error is not about size being too small, but
actually
about size being non-constant, and comes from:
 /* In a FIELD_DECL of a RECORD_TYPE, this is a pointer to the storage
representative FIELD_DECL.  */
 #define DECL_BIT_FIELD_REPRESENTATIVE(NODE) \
   (FIELD_DECL_CHECK (NODE)->field_decl.qualifier)

 /* For a FIELD_DECL in a QUAL_UNION_TYPE, records the expression, which
if nonzero, indicates that the field occupies the type.  */
  #define DECL_QUALIFIER(NODE) (FIELD_DECL_CHECK
(NODE)->field_decl.qualifier)
so by setting up DECL_BIT_FIELD_REPRESENTATIVE in QUAL_UNION_TYPE we
actually set or modify DECL_QUALIFIER and then construct size as COND_EXPRs
with those bit field representatives (e.g. with array type) as conditions
which doesn't fold into constant.

The following patch fixes it by not creating DECL_BIT_FIELD_REPRESENTATIVEs
for QUAL_UNION_TYPE as there is nowhere to store them,

Shall we change tree.h to document that DECL_BIT_FIELD_REPRESENTATIVE
is valid also on UNION_TYPE?
I see:
tree-ssa-alias.c-  if (TREE_CODE (type1) == RECORD_TYPE
tree-ssa-alias.c:  && DECL_BIT_FIELD_REPRESENTATIVE (field1))
tree-ssa-alias.c:field1 = DECL_BIT_FIELD_REPRESENTATIVE (field1);
tree-ssa-alias.c-  if (TREE_CODE (type2) == RECORD_TYPE
tree-ssa-alias.c:  && DECL_BIT_FIELD_REPRESENTATIVE (field2))
tree-ssa-alias.c:field2 = DECL_BIT_FIELD_REPRESENTATIVE (field2);
Shall we change that to || == UNION_TYPE or do we assume all fields
are overlapping in a UNION_TYPE already?
At other spots (asan, ubsan, expr.c) it is unclear what will happen
if they see a QUAL_UNION_TYPE with a DECL_QUALIFIER (or does the Ada FE
lower that somehow)?

2021-06-18  Jakub Jelinek  

PR middle-end/101062
* stor-layout.c (finish_bitfield_layout): Don't add bitfield
representatives in QUAL_UNION_TYPE.

(cherry picked from commit 3587c2c241eda0f3ab54ea60d46e9caf12d69b5a)

[Bug middle-end/101062] [10 Regression] wrong code with "-O2 -fno-toplevel-reorder -frename-registers"

2022-05-11 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101062

--- Comment #22 from CVS Commits  ---
The releases/gcc-9 branch has been updated by Jakub Jelinek
:

https://gcc.gnu.org/g:d0b1d8d3b85bb4466fae20e72a8fa35dd7277229

commit r9-10079-gd0b1d8d3b85bb4466fae20e72a8fa35dd7277229
Author: Jakub Jelinek 
Date:   Wed Jun 16 12:17:55 2021 +0200

stor-layout: Create DECL_BIT_FIELD_REPRESENTATIVE even for bitfields in
unions [PR101062]

The following testcase is miscompiled on x86_64-linux, the bitfield store
is implemented as a RMW 64-bit operation at d+24 when the d variable has
size of only 28 bytes and scheduling moves in between the R and W part
a store to a different variable that happens to be right after the d
variable.

The reason for this is that we weren't creating
DECL_BIT_FIELD_REPRESENTATIVEs for bitfields in unions.

The following patch does create them, but treats all such bitfields as if
they were in a structure where the particular bitfield is the only field.

2021-06-16  Jakub Jelinek  

PR middle-end/101062
* stor-layout.c (finish_bitfield_representative): For fields in
unions
assume nextf is always NULL.
(finish_bitfield_layout): Compute bit field representatives also in
unions, but handle it as if each bitfield was the only field in the
aggregate.

* gcc.dg/pr101062.c: New test.

(cherry picked from commit b4b50bf2864e09f028a39a3f460222632c4d7348)

[Bug middle-end/101062] [10 Regression] wrong code with "-O2 -fno-toplevel-reorder -frename-registers"

2022-05-10 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101062

--- Comment #21 from CVS Commits  ---
The releases/gcc-10 branch has been updated by Jakub Jelinek
:

https://gcc.gnu.org/g:3df2f5828752a91343d01defb215de326b5ddb4c

commit r10-10623-g3df2f5828752a91343d01defb215de326b5ddb4c
Author: Jakub Jelinek 
Date:   Fri Jun 18 11:20:40 2021 +0200

stor-layout: Don't create DECL_BIT_FIELD_REPRESENTATIVE for QUAL_UNION_TYPE
[PR101062]

> The following patch does create them, but treats all such bitfields as if
> they were in a structure where the particular bitfield is the only field.

While the patch passed bootstrap/regtest on the trunk, when trying to
backport it to 11 branch the bootstrap failed with
atree.ads:3844:34: size for "Node_Record" too small
errors.  Turns out the error is not about size being too small, but
actually
about size being non-constant, and comes from:
 /* In a FIELD_DECL of a RECORD_TYPE, this is a pointer to the storage
representative FIELD_DECL.  */
 #define DECL_BIT_FIELD_REPRESENTATIVE(NODE) \
   (FIELD_DECL_CHECK (NODE)->field_decl.qualifier)

 /* For a FIELD_DECL in a QUAL_UNION_TYPE, records the expression, which
if nonzero, indicates that the field occupies the type.  */
  #define DECL_QUALIFIER(NODE) (FIELD_DECL_CHECK
(NODE)->field_decl.qualifier)
so by setting up DECL_BIT_FIELD_REPRESENTATIVE in QUAL_UNION_TYPE we
actually set or modify DECL_QUALIFIER and then construct size as COND_EXPRs
with those bit field representatives (e.g. with array type) as conditions
which doesn't fold into constant.

The following patch fixes it by not creating DECL_BIT_FIELD_REPRESENTATIVEs
for QUAL_UNION_TYPE as there is nowhere to store them,

Shall we change tree.h to document that DECL_BIT_FIELD_REPRESENTATIVE
is valid also on UNION_TYPE?
I see:
tree-ssa-alias.c-  if (TREE_CODE (type1) == RECORD_TYPE
tree-ssa-alias.c:  && DECL_BIT_FIELD_REPRESENTATIVE (field1))
tree-ssa-alias.c:field1 = DECL_BIT_FIELD_REPRESENTATIVE (field1);
tree-ssa-alias.c-  if (TREE_CODE (type2) == RECORD_TYPE
tree-ssa-alias.c:  && DECL_BIT_FIELD_REPRESENTATIVE (field2))
tree-ssa-alias.c:field2 = DECL_BIT_FIELD_REPRESENTATIVE (field2);
Shall we change that to || == UNION_TYPE or do we assume all fields
are overlapping in a UNION_TYPE already?
At other spots (asan, ubsan, expr.c) it is unclear what will happen
if they see a QUAL_UNION_TYPE with a DECL_QUALIFIER (or does the Ada FE
lower that somehow)?

2021-06-18  Jakub Jelinek  

PR middle-end/101062
* stor-layout.c (finish_bitfield_layout): Don't add bitfield
representatives in QUAL_UNION_TYPE.

(cherry picked from commit 3587c2c241eda0f3ab54ea60d46e9caf12d69b5a)

[Bug middle-end/101062] [10 Regression] wrong code with "-O2 -fno-toplevel-reorder -frename-registers"

2022-05-10 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101062

--- Comment #20 from CVS Commits  ---
The releases/gcc-10 branch has been updated by Jakub Jelinek
:

https://gcc.gnu.org/g:0a278a8e2a95abe2bdad50ffd820b31363758a78

commit r10-10622-g0a278a8e2a95abe2bdad50ffd820b31363758a78
Author: Jakub Jelinek 
Date:   Wed Jun 16 12:17:55 2021 +0200

stor-layout: Create DECL_BIT_FIELD_REPRESENTATIVE even for bitfields in
unions [PR101062]

The following testcase is miscompiled on x86_64-linux, the bitfield store
is implemented as a RMW 64-bit operation at d+24 when the d variable has
size of only 28 bytes and scheduling moves in between the R and W part
a store to a different variable that happens to be right after the d
variable.

The reason for this is that we weren't creating
DECL_BIT_FIELD_REPRESENTATIVEs for bitfields in unions.

The following patch does create them, but treats all such bitfields as if
they were in a structure where the particular bitfield is the only field.

2021-06-16  Jakub Jelinek  

PR middle-end/101062
* stor-layout.c (finish_bitfield_representative): For fields in
unions
assume nextf is always NULL.
(finish_bitfield_layout): Compute bit field representatives also in
unions, but handle it as if each bitfield was the only field in the
aggregate.

* gcc.dg/pr101062.c: New test.

(cherry picked from commit b4b50bf2864e09f028a39a3f460222632c4d7348)

[Bug middle-end/101062] [10 Regression] wrong code with "-O2 -fno-toplevel-reorder -frename-registers"

2021-07-13 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101062

Jakub Jelinek  changed:

   What|Removed |Added

Summary|[10/11/12 Regression] wrong |[10 Regression] wrong code
   |code with "-O2  |with "-O2
   |-fno-toplevel-reorder   |-fno-toplevel-reorder
   |-frename-registers" |-frename-registers"

--- Comment #19 from Jakub Jelinek  ---
Fixed for 11.2 and trunk so far.