Message ID | 20110121123843.GF2724@tyan-ft48-01.lab.bos.redhat.com |
---|---|
State | New |
Headers | show |
On Fri, Jan 21, 2011 at 1:38 PM, Jakub Jelinek <jakub@redhat.com> wrote: > Hi! > > The following testcase incorrectly optimizes i = v; into i = 1; > in inlined foo into main (while keeping i = v; in foo out of line copy). > > Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for > trunk? Ok. Thanks, Richard. > 2011-01-21 Jakub Jelinek <jakub@redhat.com> > > PR tree-optimization/47391 > * varpool.c (const_value_known_p): Return false if > decl is volatile. > > * gcc.dg/pr47391.c: New test. > > --- gcc/varpool.c.jj 2010-11-26 18:39:11.000000000 +0100 > +++ gcc/varpool.c 2011-01-21 09:22:33.000000000 +0100 > @@ -370,7 +370,7 @@ const_value_known_p (tree decl) > > gcc_assert (TREE_CODE (decl) == VAR_DECL); > > - if (!TREE_READONLY (decl)) > + if (!TREE_READONLY (decl) || TREE_THIS_VOLATILE (decl)) > return false; > > /* Gimplifier takes away constructors of local vars */ > --- gcc/testsuite/gcc.dg/pr47391.c.jj 2011-01-21 09:31:33.000000000 +0100 > +++ gcc/testsuite/gcc.dg/pr47391.c 2011-01-21 09:32:23.000000000 +0100 > @@ -0,0 +1,22 @@ > +/* PR tree-optimization/47391 */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-optimized" } */ > + > +const volatile int v = 1; > +int i = 0; > + > +void > +foo (void) > +{ > + i = v; > +} > + > +int > +main (void) > +{ > + foo (); > + return 0; > +} > + > +/* { dg-final { scan-tree-dump-not "i = 1;" "optimized" } } */ > +/* { dg-final { cleanup-tree-dump "optimized" } } */ > > Jakub >
--- gcc/varpool.c.jj 2010-11-26 18:39:11.000000000 +0100 +++ gcc/varpool.c 2011-01-21 09:22:33.000000000 +0100 @@ -370,7 +370,7 @@ const_value_known_p (tree decl) gcc_assert (TREE_CODE (decl) == VAR_DECL); - if (!TREE_READONLY (decl)) + if (!TREE_READONLY (decl) || TREE_THIS_VOLATILE (decl)) return false; /* Gimplifier takes away constructors of local vars */ --- gcc/testsuite/gcc.dg/pr47391.c.jj 2011-01-21 09:31:33.000000000 +0100 +++ gcc/testsuite/gcc.dg/pr47391.c 2011-01-21 09:32:23.000000000 +0100 @@ -0,0 +1,22 @@ +/* PR tree-optimization/47391 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +const volatile int v = 1; +int i = 0; + +void +foo (void) +{ + i = v; +} + +int +main (void) +{ + foo (); + return 0; +} + +/* { dg-final { scan-tree-dump-not "i = 1;" "optimized" } } */ +/* { dg-final { cleanup-tree-dump "optimized" } } */