This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix PR40081, wrong gimple from SRA
On Sun, 10 May 2009, Richard Guenther wrote:
> On Sun, 10 May 2009, H.J. Lu wrote:
>
> > On Sun, May 10, 2009 at 3:11 AM, Richard Guenther <rguenther@suse.de> wrote:
> > >
> > > This fixes wrong gimple from SRA created because SRA possibly uses
> > > volatile qualified scalar types as replacements which is obviously
> > > bogus (and at least a missed optimization, but in this case causing
> > > invalid gimple). ?The problem is latent since ever, thus I plan
> > > only to fix the trunk and 4.4.
> > >
> > > Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
> > > Also tested on the 4.4 branch, queued for applying there.
> > >
> > > Richard.
> > >
> > > 2009-05-10 ?Richard Guenther ?<rguenther@suse.de>
> > >
> > > ? ? ? ?PR tree-optimization/40081
> > > ? ? ? ?* tree-sra.c (instantiate_element): Instantiate scalar replacements
> > > ? ? ? ?using the main variant of the element type. ?Do not fiddle with
> > > ? ? ? ?TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS.
> > >
> > > ? ? ? ?* g++.dg/torture/pr40081.C: New testcase.
> > >
> > >
> >
> > This caused:
> >
> > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40090
>
> Huh, I didn't see those. But I am already testing a different fix
> for probably the same reason.
Here it is. Punt on structures with volatile fields.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to
trunk.
Richard.
2009-05-10 Richard Guenther <rguenther@suse.de>
PR tree-optimization/40081
Revert
* tree-sra.c (instantiate_element): Instantiate scalar replacements
using the main variant of the element type. Do not fiddle with
TREE_THIS_VOLATILE or TREE_SIDE_EFFECTS.
* tree-sra.c (sra_type_can_be_decomposed_p): Do not decompose
structs with volatile fields.
Index: gcc/tree-sra.c
===================================================================
*** gcc/tree-sra.c (revision 147330)
--- gcc/tree-sra.c (working copy)
*************** sra_type_can_be_decomposed_p (tree type)
*** 270,275 ****
--- 270,279 ----
!= TYPE_PRECISION (TREE_TYPE (t))))
goto fail;
+ /* And volatile fields. */
+ if (TREE_THIS_VOLATILE (t))
+ goto fail;
+
saw_one_field = true;
}
*************** instantiate_element (struct sra_elt *elt
*** 1277,1284 ****
nowarn = TREE_NO_WARNING (base_elt->parent->element);
base = base_elt->element;
! elt->replacement = var = make_rename_temp (TYPE_MAIN_VARIANT (elt->type),
! "SR");
if (DECL_P (elt->element)
&& !tree_int_cst_equal (DECL_SIZE (var), DECL_SIZE (elt->element)))
--- 1281,1287 ----
nowarn = TREE_NO_WARNING (base_elt->parent->element);
base = base_elt->element;
! elt->replacement = var = make_rename_temp (elt->type, "SR");
if (DECL_P (elt->element)
&& !tree_int_cst_equal (DECL_SIZE (var), DECL_SIZE (elt->element)))
*************** instantiate_element (struct sra_elt *elt
*** 1287,1294 ****
DECL_SIZE_UNIT (var) = DECL_SIZE_UNIT (elt->element);
elt->in_bitfld_block = 1;
! elt->replacement = fold_build3 (BIT_FIELD_REF,
! TYPE_MAIN_VARIANT (elt->type), var,
DECL_SIZE (var),
BYTES_BIG_ENDIAN
? size_binop (MINUS_EXPR,
--- 1290,1296 ----
DECL_SIZE_UNIT (var) = DECL_SIZE_UNIT (elt->element);
elt->in_bitfld_block = 1;
! elt->replacement = fold_build3 (BIT_FIELD_REF, elt->type, var,
DECL_SIZE (var),
BYTES_BIG_ENDIAN
? size_binop (MINUS_EXPR,
*************** instantiate_element (struct sra_elt *elt
*** 1305,1310 ****
--- 1307,1318 ----
DECL_SOURCE_LOCATION (var) = DECL_SOURCE_LOCATION (base);
DECL_ARTIFICIAL (var) = 1;
+ if (TREE_THIS_VOLATILE (elt->type))
+ {
+ TREE_THIS_VOLATILE (var) = 1;
+ TREE_SIDE_EFFECTS (var) = 1;
+ }
+
if (DECL_NAME (base) && !DECL_IGNORED_P (base))
{
char *pretty_name = build_element_name (elt);