On Tue, 26 Jan 2021, Jakub Jelinek wrote:

> On Tue, Jan 26, 2021 at 11:37:42AM +0100, Jan Hubicka wrote:
> > I think it would make more sense.
> > We could also simply clean it up next stage1.
> 
> I'll rebootstrap/retest the following version then (adding PROP_rtl
> just in case it would be called during expand or later).
> 
> 2021-01-26  Jakub Jelinek  <ja...@redhat.com>
> 
>       PR tree-optimization/97260
>       * varpool.c: Include tree-pass.h.
>       (ctor_for_folding): In GENERIC return DECL_INITIAL for TREE_READONLY
>       non-TREE_SIDE_EFFECTS automatic variables.
> 
>       * gcc.dg/tree-ssa/pr97260.c: New test.
> 
> --- gcc/varpool.c.jj  2021-01-26 11:15:49.190411160 +0100
> +++ gcc/varpool.c     2021-01-26 11:36:46.081295478 +0100
> @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.
>  #include "context.h"
>  #include "stringpool.h"
>  #include "attribs.h"
> +#include "tree-pass.h"
>  
>  const char * const tls_model_names[]={"none", "emulated",
>                                     "global-dynamic", "local-dynamic",
> @@ -412,6 +413,13 @@ ctor_for_folding (tree decl)
>    if (!TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
>      {
>        gcc_assert (!TREE_PUBLIC (decl));
> +      /* Unless this is called during FE folding.  */
> +      if (cfun
> +       && (cfun->curr_properties & (PROP_trees | PROP_rtl)) == 0

don't you want && (cfun->curr_properties & PROP_trees) != 0?

> +       && TREE_READONLY (decl)
> +       && !TREE_SIDE_EFFECTS (decl)
> +       && DECL_INITIAL (decl))
> +     return DECL_INITIAL (decl);
>        return error_mark_node;
>      }
>  
> --- gcc/testsuite/gcc.dg/tree-ssa/pr97260.c.jj        2021-01-26 
> 11:17:09.818501694 +0100
> +++ gcc/testsuite/gcc.dg/tree-ssa/pr97260.c   2021-01-26 11:17:09.818501694 
> +0100
> @@ -0,0 +1,11 @@
> +/* PR tree-optimization/97260 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-optimized" } */
> +/* { dg-final { scan-tree-dump "return 0;" "optimized" } } */
> +
> +int
> +foo (void)
> +{
> +  const char a[] = "1234";
> +  return __builtin_memcmp (a, "1234", 4);
> +}
> 
> 
>       Jakub
> 
> 

-- 
Richard Biener <rguent...@suse.de>
SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg,
Germany; GF: Felix Imendörffer; HRB 36809 (AG Nuernberg)

Reply via email to