Bug 39672 - Local statics not promoted to const
Summary: Local statics not promoted to const
Status: RESOLVED WORKSFORME
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.5.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2009-04-07 11:14 UTC by Richard Biener
Modified: 2009-04-08 10:21 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2009-04-07 11:14:06 UTC
For

int foo(void)
{
  static int blah = 1;
  return blah;
}

we should be able to promote blah to TREE_READONLY during ipa-reference (or
local analysis) if blah does not have its address taken and is not written
to in the function body.

This occurs for example in 189.lucas via

        real(kind=r16), save :: mt,one=1,two=2,one_fourth,pi,theta,theta2

note the save attribute.
Comment 1 Jan Hubicka 2009-04-07 11:44:06 UTC
Subject: Re:   New: Local statics not promoted to const

ipa-reference definitly is supposed to do this transform.  I will debug
why it does not in this testcase.

Honza
Comment 2 rguenther@suse.de 2009-04-07 12:14:13 UTC
Subject: Re:  Local statics not promoted to
 const

On Tue, 7 Apr 2009, hubicka at ucw dot cz wrote:

> ------- Comment #1 from hubicka at ucw dot cz  2009-04-07 11:44 -------
> Subject: Re:   New: Local statics not promoted to const
> 
> ipa-reference definitly is supposed to do this transform.  I will debug
> why it does not in this testcase.

I think it only adjusts global statics.

Richard.
Comment 3 Jan Hubicka 2009-04-07 15:14:12 UTC
Subject: Re:  Local statics not promoted to const

> I think it only adjusts global statics.
This is why I originally implemented varpool to have both local and
global static alike, so it should not.

Well, time to debug it ;)

Honza
Comment 4 Richard Biener 2009-04-08 10:21:14 UTC
Err, this works.  I just messed up my local tree.