Bug 35402 - Store CCP will not inline static const variable which is default initialized
Summary: Store CCP will not inline static const variable which is default initialized
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.3.0
: P3 enhancement
Target Milestone: 4.4.0
Assignee: Andrew Pinski
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: missed-optimization, patch
Depends on: 35513
Blocks: 35403
  Show dependency treegraph
 
Reported: 2008-02-28 22:08 UTC by Andrew Pinski
Modified: 2008-03-06 21:59 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-02-28 22:08:57


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2008-02-28 22:08:38 UTC
Testcase:
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-optimized" } */

static const int conststaticvariable;

int f(void)
{
  return conststaticvariable;
}

/* There should be no reference to conststaticvariable as we should have inlined the 0. */
/* { dg-final { scan-tree-dump-times "conststaticvariable" o "optimized"} } */
/* { dg-final { cleanup-tree-dump "optimized" } } */
Comment 1 Andrew Pinski 2008-02-28 22:08:57 UTC
Mine.
Comment 2 Andrew Pinski 2008-02-28 22:26:21 UTC
>/* { dg-final { scan-tree-dump-times "conststaticvariable" o "optimized"} } */

that should be:
/* { dg-final { scan-tree-dump-times "conststaticvariable" 0 "optimized"} } */

:)
Comment 3 Richard Biener 2008-02-29 12:43:04 UTC
Please change tree-ssa-sccvn.c:try_to_simplify accordingly (eventually that
should use a common helper function to extract a constant initializer for
the tcc_reference case, too).  Thanks!
Comment 4 Andrew Pinski 2008-03-05 23:40:14 UTC
(In reply to comment #3)
> Please change tree-ssa-sccvn.c:try_to_simplify accordingly (eventually that
> should use a common helper function to extract a constant initializer for
> the tcc_reference case, too).  Thanks!

There is already a helper function in tree-ssa-ccp.c: get_symbol_constant_value .
This is what I am changing if tree-ssa-sccvn.c:try_to_simplify wants to use it, it should too.

I think there are too many duplicated functions all around really.  This is just one example.

-- PInski
Comment 5 Andrew Pinski 2008-03-06 21:57:01 UTC
Subject: Bug 35402

Author: pinskia
Date: Thu Mar  6 21:56:04 2008
New Revision: 132991

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132991
Log:
2008-03-06  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR tree-opt/35402
        * tree-ssa-ccp.c (get_symbol_constant_value): Handle
        integral and scalar float variables which have a
        NULL DECL_INITIAL.

2008-03-06  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR tree-opt/35402
        * gcc.dg/tree-ssa/ssa-store-ccp-1.c: New test.


Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ssa-store-ccp-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-ccp.c

Comment 6 Andrew Pinski 2008-03-06 21:59:06 UTC
Fixed.