On Tue, 4 Mar 2014, Jakub Jelinek wrote: > Hi! > > As discussed in the PR, the assumption that in !optimize functions > all SSA_NAMEs for a particular PARM_DECL or RESULT_DECL can be coalesced > together is wrong for -flto, if you compile with optimizations the object > file and then link with -O0 -flto, because the SSA_NAMEs can already > overlap. > > As we don't have info right now if a particular function has always been > compiled with !optimize during the LTO pipeline, this patch fixes the > wrong-code by always assuming it might be optimized at some point if > in_lto_p. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
Ok. Thanks, Richard. > 2014-03-04 Jakub Jelinek <ja...@redhat.com> > > PR lto/60404 > * cfgexpand.c (expand_used_vars): Do not assume all SSA_NAMEs > of PARM/RESULT_DECLs must be coalesced with optimize && in_lto_p. > * tree-ssa-coalesce.c (coalesce_ssa_name): Use MUST_COALESCE_COST - 1 > cost for in_lto_p. > > * gcc.dg/lto/pr60404_0.c: New test. > * gcc.dg/lto/pr60404_1.c: New file. > * gcc.dg/lto/pr60404_2.c: New file. > > --- gcc/cfgexpand.c.jj 2014-03-04 10:57:18.000000000 +0100 > +++ gcc/cfgexpand.c 2014-03-04 11:12:12.684524383 +0100 > @@ -1652,10 +1652,12 @@ expand_used_vars (void) > debug info, there is no need to do so if optimization is disabled > because all the SSA_NAMEs based on these DECLs have been coalesced > into a single partition, which is thus assigned the canonical RTL > - location of the DECLs. */ > + location of the DECLs. If in_lto_p, we can't rely on optimize, > + a function could be compiled with -O1 -flto first and only the > + link performed at -O0. */ > if (TREE_CODE (SSA_NAME_VAR (var)) == VAR_DECL) > expand_one_var (var, true, true); > - else if (DECL_IGNORED_P (SSA_NAME_VAR (var)) || optimize) > + else if (DECL_IGNORED_P (SSA_NAME_VAR (var)) || optimize || in_lto_p) > { > /* This is a PARM_DECL or RESULT_DECL. For those partitions that > contain the default def (representing the parm or result itself) > --- gcc/tree-ssa-coalesce.c.jj 2014-01-03 11:40:57.000000000 +0100 > +++ gcc/tree-ssa-coalesce.c 2014-03-04 11:15:46.955296026 +0100 > @@ -1289,9 +1289,12 @@ coalesce_ssa_name (void) > _require_ that all the names originating from it be > coalesced, because there must be a single partition > containing all the names so that it can be assigned > - the canonical RTL location of the DECL safely. */ > + the canonical RTL location of the DECL safely. > + If in_lto_p, a function could have been compiled > + originally with optimizations and only the link > + performed at -O0, so we can't actually require it. */ > const int cost > - = TREE_CODE (SSA_NAME_VAR (a)) == VAR_DECL > + = (TREE_CODE (SSA_NAME_VAR (a)) == VAR_DECL || in_lto_p) > ? MUST_COALESCE_COST - 1 : MUST_COALESCE_COST; > add_coalesce (cl, SSA_NAME_VERSION (a), > SSA_NAME_VERSION (*slot), cost); > --- gcc/testsuite/gcc.dg/lto/pr60404_0.c.jj 2014-03-04 11:19:48.503909557 > +0100 > +++ gcc/testsuite/gcc.dg/lto/pr60404_0.c 2014-03-04 11:09:51.590333222 > +0100 > @@ -0,0 +1,15 @@ > +/* { dg-lto-do run } */ > +/* { dg-lto-options { { -O1 -flto } } } */ > +/* { dg-extra-ld-options { -O0 } } */ > + > +extern void fn2 (int); > +int a[1], b; > + > +int > +main () > +{ > + fn2 (0); > + if (b != 0 || a[b] != 0) > + __builtin_abort (); > + return 0; > +} > --- gcc/testsuite/gcc.dg/lto/pr60404_1.c.jj 2014-03-04 11:19:51.057894910 > +0100 > +++ gcc/testsuite/gcc.dg/lto/pr60404_1.c 2014-03-04 09:32:35.000000000 > +0100 > @@ -0,0 +1,4 @@ > +void > +fn1 (int p) > +{ > +} > --- gcc/testsuite/gcc.dg/lto/pr60404_2.c.jj 2014-03-04 11:19:54.578874717 > +0100 > +++ gcc/testsuite/gcc.dg/lto/pr60404_2.c 2014-03-04 09:33:18.000000000 > +0100 > @@ -0,0 +1,9 @@ > +extern int b; > +extern void fn1 (int); > + > +void > +fn2 (int p) > +{ > + b = p++; > + fn1 (p); > +} > > Jakub > > -- Richard Biener <rguent...@suse.de> SUSE / SUSE Labs SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 GF: Jeff Hawn, Jennifer Guild, Felix Imend"orffer