public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded
@ 2004-04-03 23:49 kazu at cs dot umass dot edu
  2004-04-04  3:00 ` [Bug optimization/14841] " pinskia at gcc dot gnu dot org
                   ` (21 more replies)
  0 siblings, 22 replies; 26+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-04-03 23:49 UTC (permalink / raw)
  To: gcc-bugs

static const int banana[] = { 0, 1, 2, 3 };

int
foo (void)
{
  return banana[2];
}

const int grape[] = { 0, 1, 2, 3 };

int
bar (void)
{
  return grape[2];
}

I get:

;; Function foo (foo)

foo ()
{
<bb 0>:
  return banana[2];

}



;; Function bar (bar)

bar ()
{
<bb 0>:
  return grape[2];

}

-- 
           Summary: [tree-ssa] const_array[CST] is not folded
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Keywords: pessimizes-code
          Severity: enhancement
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at cs dot umass dot edu
                CC: gcc-bugs at gcc dot gnu dot org
OtherBugsDependingO 14840
             nThis:


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
@ 2004-04-04  3:00 ` pinskia at gcc dot gnu dot org
  2004-05-24 22:25 ` [Bug tree-optimization/14841] " pinskia at gcc dot gnu dot org
                   ` (20 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-04  3:00 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-04-04 03:00 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-04-04 03:00:27
               date|                            |
   Target Milestone|---                         |tree-ssa


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
  2004-04-04  3:00 ` [Bug optimization/14841] " pinskia at gcc dot gnu dot org
@ 2004-05-24 22:25 ` pinskia at gcc dot gnu dot org
  2004-08-13  0:04 ` steven at gcc dot gnu dot org
                   ` (19 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-24 22:25 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|3.5.0                       |---


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
  2004-04-04  3:00 ` [Bug optimization/14841] " pinskia at gcc dot gnu dot org
  2004-05-24 22:25 ` [Bug tree-optimization/14841] " pinskia at gcc dot gnu dot org
@ 2004-08-13  0:04 ` steven at gcc dot gnu dot org
  2004-08-13  8:13 ` kazu at cs dot umass dot edu
                   ` (18 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: steven at gcc dot gnu dot org @ 2004-08-13  0:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2004-08-13 00:04 -------
Given your test case, 
 
(gdb) set args -O2 t.c 
(gdb) b fold if (current_function_decl != (tree*)0) 
Breakpoint 5 at 0x658717: file ../../mainline/gcc/fold-const.c, line 6018. 
(gdb) run 
Starting program: /space/stevenb/build/gcc/cc1 -O2 t.c 
Breakpoint 3 at 0x2a9569d9c0 
Breakpoint 4 at 0x2a9569c750 
 foo 
 
Breakpoint 5, fold (expr=0x2a95905f80) at ../../mainline/gcc/fold-const.c:6018 
6018      const tree t = expr; 
(gdb) p debug_generic_expr (expr) 
banana<D1464>[2] 
$2 = void 
(gdb) p debug_tree(expr) 
 <array_ref 0x2a95905f80 
    type <integer_type 0x2a955978c0 int SI 
        size <integer_cst 0x2a95595780 constant invariant 32> 
        unit size <integer_cst 0x2a955958d0 constant invariant 4> 
        align 32 symtab 0 alias set -1 precision 32 min <integer_cst 
0x2a95595870 -2147483648> max <integer_cst 0x2a955958a0 2147483647> 
        pointer_to_this <pointer_type 0x2a955a8540>> 
    readonly 
    arg 0 <var_decl 0x2a95901ee0 banana 
        type <array_type 0x2a95901e00 type <integer_type 0x2a9562ec40 int> 
            BLK 
            size <integer_cst 0x2a95595de0 constant invariant 128> 
            unit size <integer_cst 0x2a9559f4b0 constant invariant 16> 
            align 32 symtab 0 alias set -1 domain <integer_type 0x2a95629a80>> 
        readonly used static BLK file t.c line 1 size <integer_cst 
0x2a95595de0 128> unit size <integer_cst 0x2a9559f4b0 16> 
        align 32 initial <constructor 0x2a9562c080>> 
    arg 1 <integer_cst 0x2a95913f30 type <integer_type 0x2a955978c0 int> 
constant invariant 2>> 
$3 = void 
(gdb) p debug_tree ((tree *)0x2a9562c080) 
 <constructor 0x2a9562c080 
    type <array_type 0x2a95901e00 
        type <integer_type 0x2a9562ec40 int readonly SI 
            size <integer_cst 0x2a95595780 constant invariant 32> 
            unit size <integer_cst 0x2a955958d0 constant invariant 4> 
            align 32 symtab 0 alias set -1 precision 32 min <integer_cst 
0x2a95595870 -2147483648> max <integer_cst 0x2a955958a0 2147483647> 
            pointer_to_this <pointer_type 0x2a9562ed20>> 
        BLK 
        size <integer_cst 0x2a95595de0 constant invariant 128> 
        unit size <integer_cst 0x2a9559f4b0 constant invariant 16> 
        align 32 symtab 0 alias set -1 
        domain <integer_type 0x2a95629a80 type <integer_type 0x2a955a6700 long 
unsigned int> 
            DI 
            size <integer_cst 0x2a95595900 constant invariant 64> 
            unit size <integer_cst 0x2a95595a50 constant invariant 8> 
            align 64 symtab 0 alias set -1 precision 64 min <integer_cst 
0x2a9559f5d0 0> max <integer_cst 0x2a95628000 3>>> 
    constant invariant static 
    arg 0 <tree_list 0x2a959139f0 
        purpose <integer_cst 0x2a959139c0 constant invariant 0> 
        value <integer_cst 0x2a95913990 constant invariant 0> 
        chain <tree_list 0x2a95913a80 
            purpose <integer_cst 0x2a95913a50 constant invariant 1> 
            value <integer_cst 0x2a95913a20 constant invariant 1> 
            chain <tree_list 0x2a95913b10 
                purpose <integer_cst 0x2a95913ae0 constant invariant 2> 
                value <integer_cst 0x2a95913ab0 constant invariant 2> 
                chain <tree_list 0x2a95913bd0 
                    purpose <integer_cst 0x2a95913ba0 constant invariant 3> 
                    value <integer_cst 0x2a95913b70 constant invariant 3>>>>>> 
$4 = void 
(gdb) 
 
So somebody should just teach fold-const to fold ARRAY_REFs to 
readonly memory. 
 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (2 preceding siblings ...)
  2004-08-13  0:04 ` steven at gcc dot gnu dot org
@ 2004-08-13  8:13 ` kazu at cs dot umass dot edu
  2004-08-30 22:24 ` steven at gcc dot gnu dot org
                   ` (17 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-08-13  8:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2004-08-13 08:13 -------
There is a piece of code in expr.c around line 6700 that folds references to
constant arrays with constant indecies.

The only problem is that we have to be careful not to fold
things like &array[2].

I am not sure if there is a way to see the containing expression
in fold().

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (3 preceding siblings ...)
  2004-08-13  8:13 ` kazu at cs dot umass dot edu
@ 2004-08-30 22:24 ` steven at gcc dot gnu dot org
  2004-08-30 22:26 ` steven at gcc dot gnu dot org
                   ` (16 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: steven at gcc dot gnu dot org @ 2004-08-30 22:24 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2004-08-30 22:24 -------
Diego said he want to lose track of this one. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dnovillo at redhat dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (5 preceding siblings ...)
  2004-08-30 22:26 ` steven at gcc dot gnu dot org
@ 2004-08-30 22:26 ` pinskia at gcc dot gnu dot org
  2004-08-31  0:10 ` steven at gcc dot gnu dot org
                   ` (14 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-30 22:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-30 22:26 -------
And the related bug is for structs, see PR 15838 for that one.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (4 preceding siblings ...)
  2004-08-30 22:24 ` steven at gcc dot gnu dot org
@ 2004-08-30 22:26 ` steven at gcc dot gnu dot org
  2004-08-30 22:26 ` pinskia at gcc dot gnu dot org
                   ` (15 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: steven at gcc dot gnu dot org @ 2004-08-30 22:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2004-08-30 22:26 -------
hmm for the really ambitious, of course that list_length call isn't strictly 
necessary... 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (6 preceding siblings ...)
  2004-08-30 22:26 ` pinskia at gcc dot gnu dot org
@ 2004-08-31  0:10 ` steven at gcc dot gnu dot org
  2004-08-31  0:18 ` dnovillo at gcc dot gnu dot org
                   ` (13 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: steven at gcc dot gnu dot org @ 2004-08-31  0:10 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2004-08-31 00:10 -------
Or I would lose track of it myself 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |stevenb at suse dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (7 preceding siblings ...)
  2004-08-31  0:10 ` steven at gcc dot gnu dot org
@ 2004-08-31  0:18 ` dnovillo at gcc dot gnu dot org
  2004-08-31  2:03 ` giovannibajo at libero dot it
                   ` (12 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: dnovillo at gcc dot gnu dot org @ 2004-08-31  0:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dnovillo at gcc dot gnu dot org  2004-08-31 00:18 -------
> fold array refs to constant arrays with a constant index
> 
> Find attached the almost completely untested patch ;-)
> 
Looks OK.  I would split the test done at the start of const_array_const_idx_elt
into a predicate that we can call from evaluate_stmt beforehand.

OK with that change (testing, etc).


Diego.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (8 preceding siblings ...)
  2004-08-31  0:18 ` dnovillo at gcc dot gnu dot org
@ 2004-08-31  2:03 ` giovannibajo at libero dot it
  2004-08-31  2:06 ` pinskia at gcc dot gnu dot org
                   ` (11 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: giovannibajo at libero dot it @ 2004-08-31  2:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2004-08-31 02:03 -------
Quick question, isn't it better to do this in fold?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |giovannibajo at libero dot
                   |                            |it


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (9 preceding siblings ...)
  2004-08-31  2:03 ` giovannibajo at libero dot it
@ 2004-08-31  2:06 ` pinskia at gcc dot gnu dot org
  2004-08-31  9:38 ` stevenb at suse dot de
                   ` (10 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-31  2:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-31 02:06 -------
Because you cannot do it in fold because we get the expression a[2] which is part of the bigger 
expression &a[2] which means that we cannot fold the first expression.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (10 preceding siblings ...)
  2004-08-31  2:06 ` pinskia at gcc dot gnu dot org
@ 2004-08-31  9:38 ` stevenb at suse dot de
  2004-08-31 18:13 ` steven at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: stevenb at suse dot de @ 2004-08-31  9:38 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From stevenb at suse dot de  2004-08-31 09:38 -------
Subject: Re:  [tree-ssa] const_array[CST] is not folded

On Tuesday 31 August 2004 04:06, pinskia at gcc dot gnu dot org wrote:
> ------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-31
> 02:06 ------- Because you cannot do it in fold because we get the
> expression a[2] which is part of the bigger expression &a[2] which means
> that we cannot fold the first expression.

Exactly. CCP is the right place for this.

The expr.c hack can probably be removed when the patch is in, if
somebody is interested.

Gr.
Steven




-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (11 preceding siblings ...)
  2004-08-31  9:38 ` stevenb at suse dot de
@ 2004-08-31 18:13 ` steven at gcc dot gnu dot org
  2004-08-31 21:00 ` steven at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: steven at gcc dot gnu dot org @ 2004-08-31 18:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2004-08-31 18:13 -------
mine 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |steven at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (12 preceding siblings ...)
  2004-08-31 18:13 ` steven at gcc dot gnu dot org
@ 2004-08-31 21:00 ` steven at gcc dot gnu dot org
  2004-08-31 21:03 ` dnovillo at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: steven at gcc dot gnu dot org @ 2004-08-31 21:00 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2004-08-31 21:00 -------
simple patch not good enough, and no clue how to 
handle "x = a.b.c.d.e[2].f[4].g" 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|steven at gcc dot gnu dot   |unassigned at gcc dot gnu
                   |org                         |dot org
             Status|ASSIGNED                    |NEW


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (13 preceding siblings ...)
  2004-08-31 21:00 ` steven at gcc dot gnu dot org
@ 2004-08-31 21:03 ` dnovillo at gcc dot gnu dot org
  2004-09-03 21:48 ` steven at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: dnovillo at gcc dot gnu dot org @ 2004-08-31 21:03 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dnovillo at gcc dot gnu dot org  2004-08-31 21:03 -------

OK.  I'll put it in my queue.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |dnovillo at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (14 preceding siblings ...)
  2004-08-31 21:03 ` dnovillo at gcc dot gnu dot org
@ 2004-09-03 21:48 ` steven at gcc dot gnu dot org
  2005-03-04  3:58 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: steven at gcc dot gnu dot org @ 2004-09-03 21:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2004-09-03 21:48 -------
What makes the general case with more fields a bit hard is that you apparently need to 
traverse the component/array ref list to the innermost reference to find the referenced variable.  
Otherwise there is to way to see if the component/array ref references a constant initializer.  
Like so: 
 
(gdb) p debug_tree (*stmt_p) 
 <modify_expr 0x2a95595870 
    type <integer_type 0x2a955968c0 int public SI 
        size <integer_cst 0x2a955949c0 constant invariant 32> 
        unit size <integer_cst 0x2a95594420 constant invariant 4> 
        align 32 symtab 0 alias set 4 precision 32 min <integer_cst 0x2a95594960 -2147483648> 
max <integer_cst 0x2a95594990 2147483647> 
        pointer_to_this <pointer_type 0x2a955b0540>> 
    side-effects 
    arg 0 <var_decl 0x2a959238c0 T.0 type <integer_type 0x2a955968c0 int> 
        used ignored SI file t.c line 12 size <integer_cst 0x2a955949c0 32> unit size 
<integer_cst 0x2a95594420 4> 
        align 32 context <function_decl 0x2a95923540 main>> 
    arg 1 <component_ref 0x2a95595820 type <integer_type 0x2a955968c0 int> 
 
        arg 0 <component_ref 0x2a955957d0 type <record_type 0x2a9590fe00 b> 
            arg 0 <var_decl 0x2a959232a0 t> arg 1 <field_decl 0x2a959230e0 b>> 
        arg 1 <field_decl 0x2a95923000 i type <integer_type 0x2a955968c0 int> 
            SI file t.c line 3 size <integer_cst 0x2a955949c0 32> unit size <integer_cst 
0x2a95594420 4> 
            align 32 offset_align 128 
            offset <integer_cst 0x2a95594450 constant invariant 0> 
            bit offset <integer_cst 0x2a955aa810 constant invariant 0> context <record_type 
0x2a9590fe00 b> arguments <integer_cst 0x2a95594450 0>>> 
    t.c:12> 
$11 = void 
(gdb) p debug_tree (rhs) 
 <component_ref 0x2a95595820 
    type <integer_type 0x2a955968c0 int public SI 
        size <integer_cst 0x2a955949c0 constant invariant 32> 
        unit size <integer_cst 0x2a95594420 constant invariant 4> 
        align 32 symtab 0 alias set 4 precision 32 min <integer_cst 0x2a95594960 -2147483648> 
max <integer_cst 0x2a95594990 2147483647> 
        pointer_to_this <pointer_type 0x2a955b0540>> 
 
    arg 0 <component_ref 0x2a955957d0 
        type <record_type 0x2a9590fe00 b type_0 SI size <integer_cst 0x2a955949c0 32> unit 
size <integer_cst 0x2a95594420 4> 
            align 32 symtab 0 alias set 3 fields <field_decl 0x2a95923000 i> context 
<translation_unit_decl 0x2a959239a0> 
            chain <type_decl 0x2a9590fee0>> 
 
        arg 0 <var_decl 0x2a959232a0 t type <record_type 0x2a9590fc40 a> 
            asm_written used public static SI file t.c line 7 size <integer_cst 0x2a955949c0 32> 
unit size <integer_cst 0x2a95594420 4> 
            align 32 initial <constructor 0x2a95634340> 
            (mem/s:SI (symbol_ref:DI ("t") [flags 0x2] <var_decl 0x2a959232a0 t>) [2 t+0 S4 A32]) 
chain <function_decl 0x2a95923540 main>> 
        arg 1 <field_decl 0x2a959230e0 b type <record_type 0x2a9590fe00 b> 
            SI file t.c line 4 size <integer_cst 0x2a955949c0 32> unit size <integer_cst 
0x2a95594420 4> 
            align 32 offset_align 128 
            offset <integer_cst 0x2a95594450 constant invariant 0> 
            bit offset <integer_cst 0x2a955aa810 constant invariant 0> context <record_type 
0x2a9590fc40 a> arguments <integer_cst 0x2a95594450 0>>> 
    arg 1 <field_decl 0x2a95923000 i type <integer_type 0x2a955968c0 int> 
        SI file t.c line 3 size <integer_cst 0x2a955949c0 32> unit size <integer_cst 
0x2a95594420 4> 
        align 32 offset_align 128 offset <integer_cst 0x2a95594450 0> bit offset <integer_cst 
0x2a955aa810 0> context <record_type 0x2a9590fe00 b> arguments <integer_cst 
0x2a95594450 0>>> 
$12 = void 
(gdb) p rhs->common.constant_flag 
$13 = 0 
(gdb) p debug_tree (rhs->exp.operands[0]->exp.operands[0]) 
 <var_decl 0x2a959232a0 t 
    type <record_type 0x2a9590fc40 a type_0 SI 
        size <integer_cst 0x2a955949c0 constant invariant 32> 
        unit size <integer_cst 0x2a95594420 constant invariant 4> 
        align 32 symtab 0 alias set 2 
        fields <field_decl 0x2a959230e0 b type <record_type 0x2a9590fe00 b> 
            SI file t.c line 4 size <integer_cst 0x2a955949c0 32> unit size <integer_cst 
0x2a95594420 4> 
            align 32 offset_align 128 
            offset <integer_cst 0x2a95594450 constant invariant 0> 
            bit offset <integer_cst 0x2a955aa810 constant invariant 0> context <record_type 
0x2a9590fc40 a> arguments <integer_cst 0x2a95594450 0>> context <translation_unit_decl 
0x2a959239a0> 
        chain <type_decl 0x2a9590fd20>> 
    asm_written used public static SI file t.c line 7 size <integer_cst 0x2a955949c0 32> unit 
size <integer_cst 0x2a95594420 4> 
    align 32 initial <constructor 0x2a95634340> 
    (mem/s:SI (symbol_ref:DI ("t") [flags 0x2] <var_decl 0x2a959232a0 t>) [2 t+0 S4 A32]) 
chain <function_decl 0x2a95923540 main>> 
$14 = void 
 
Either we should somehow mark the component ref itself as constant, or we have to traverse 
the (in this case) COMPONENT_REF to the innermost reference to see the variable that is 
referenced.  That might actually get pretty expensive, I'd think...??? 

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (15 preceding siblings ...)
  2004-09-03 21:48 ` steven at gcc dot gnu dot org
@ 2005-03-04  3:58 ` pinskia at gcc dot gnu dot org
  2005-05-04  2:16 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-03-04  3:58 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu dot
                   |                            |org
   Last reconfirmed|2004-12-03 01:47:22         |2005-03-04 03:57:51
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (16 preceding siblings ...)
  2005-03-04  3:58 ` pinskia at gcc dot gnu dot org
@ 2005-05-04  2:16 ` pinskia at gcc dot gnu dot org
  2005-05-07  3:08 ` kazu at cs dot umass dot edu
                   ` (3 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-04  2:16 UTC (permalink / raw)
  To: gcc-bugs



-- 
Bug 14841 depends on bug 17046, which changed state.

Bug 17046 Summary: An unused array is not optimized away.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17046

           What    |Old Value                   |New Value
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (17 preceding siblings ...)
  2005-05-04  2:16 ` pinskia at gcc dot gnu dot org
@ 2005-05-07  3:08 ` kazu at cs dot umass dot edu
  2005-05-07  5:12 ` schlie at comcast dot net
                   ` (2 subsequent siblings)
  21 siblings, 0 replies; 26+ messages in thread
From: kazu at cs dot umass dot edu @ 2005-05-07  3:08 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2005-05-07 03:08 -------
I've extended Steven's patch to handle nested aggregates
(i.e. any combination of ARRAY_REF and COMPONENT_REF).



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|dnovillo at gcc dot gnu dot |kazu at cs dot umass dot edu
                   |org                         |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (18 preceding siblings ...)
  2005-05-07  3:08 ` kazu at cs dot umass dot edu
@ 2005-05-07  5:12 ` schlie at comcast dot net
  2005-05-08 21:22 ` cvs-commit at gcc dot gnu dot org
  2005-05-08 21:30 ` kazu at cs dot umass dot edu
  21 siblings, 0 replies; 26+ messages in thread
From: schlie at comcast dot net @ 2005-05-07  5:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From schlie at comcast dot net  2005-05-07 05:12 -------
(In reply to comment #17)
> I've extended Steven's patch to handle nested aggregates
> (i.e. any combination of ARRAY_REF and COMPONENT_REF).

Does it also work with terminating static const char "strings" which
for some odd reason aren't char ARRAYs referenced via an ARRAY_REF's ?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (19 preceding siblings ...)
  2005-05-07  5:12 ` schlie at comcast dot net
@ 2005-05-08 21:22 ` cvs-commit at gcc dot gnu dot org
  2005-05-08 21:30 ` kazu at cs dot umass dot edu
  21 siblings, 0 replies; 26+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-05-08 21:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-05-08 21:22 -------
Subject: Bug 14841

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	kazu@gcc.gnu.org	2005-05-08 21:22:21

Modified files:
	gcc            : ChangeLog Makefile.in tree-ssa-ccp.c 
Added files:
	gcc/testsuite/gcc.dg/tree-ssa: pr14841.c 

Log message:
	gcc/
	PR tree-optimization/14841, tree-optimization/15838
	* tree-ssa-ccp.c (fold_const_aggregate_ref): New.
	(evaluate_stmt): Call it.
	
	testsuite/
	PR tree-optimization/14841, tree-optimization/15838
	* gcc.dg/tree-ssa/pr14841.c: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8663&r2=2.8664
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/Makefile.in.diff?cvsroot=gcc&r1=1.1481&r2=1.1482
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-ssa-ccp.c.diff?cvsroot=gcc&r1=2.69&r2=2.70
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/tree-ssa/pr14841.c.diff?cvsroot=gcc&r1=NONE&r2=1.1



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
  2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
                   ` (20 preceding siblings ...)
  2005-05-08 21:22 ` cvs-commit at gcc dot gnu dot org
@ 2005-05-08 21:30 ` kazu at cs dot umass dot edu
  21 siblings, 0 replies; 26+ messages in thread
From: kazu at cs dot umass dot edu @ 2005-05-08 21:30 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2005-05-08 21:30 -------
Just checked in a patch.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.1.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
       [not found] <bug-14841-5009@http.gcc.gnu.org/bugzilla/>
  2006-05-08 10:07 ` rguenth at gcc dot gnu dot org
  2006-05-08 10:09 ` rguenth at gcc dot gnu dot org
@ 2006-05-08 15:07 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 26+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-05-08 15:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #24 from pinskia at gcc dot gnu dot org  2006-05-08 15:07 -------
But that is not related to the orginal bug.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
       [not found] <bug-14841-5009@http.gcc.gnu.org/bugzilla/>
  2006-05-08 10:07 ` rguenth at gcc dot gnu dot org
@ 2006-05-08 10:09 ` rguenth at gcc dot gnu dot org
  2006-05-08 15:07 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 26+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-05-08 10:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #23 from rguenth at gcc dot gnu dot org  2006-05-08 10:08 -------
Dirk, you may want to take this one, too.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mueller at gcc dot gnu dot
                   |                            |org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

* [Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
       [not found] <bug-14841-5009@http.gcc.gnu.org/bugzilla/>
@ 2006-05-08 10:07 ` rguenth at gcc dot gnu dot org
  2006-05-08 10:09 ` rguenth at gcc dot gnu dot org
  2006-05-08 15:07 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 26+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-05-08 10:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #22 from rguenth at gcc dot gnu dot org  2006-05-08 10:07 -------
Doesn't really work, it misses support for STRING_CST.  See PR22303.

static const char *foo = "?";

char foobar () { return foo[0]; }

Something like the following should fix it (once fold_read_from_constant_string
is fixed):

Index: tree-ssa-ccp.c
===================================================================
*** tree-ssa-ccp.c      (revision 113606)
--- tree-ssa-ccp.c      (working copy)
*************** fold_const_aggregate_ref (tree t)
*** 1011,1020 ****
        }

        if (ctor == NULL_TREE
!         || TREE_CODE (ctor) != CONSTRUCTOR
          || !TREE_STATIC (ctor))
        return NULL_TREE;

        /* Get the index.  If we have an SSA_NAME, try to resolve it
         with the current lattice value for the SSA_NAME.  */
        idx = TREE_OPERAND (t, 1);
--- 1011,1024 ----
        }

        if (ctor == NULL_TREE
!         || TREE_CODE (ctor) != CONSTRUCTOR
          || !TREE_STATIC (ctor))
        return NULL_TREE;

        /* Get the index.  If we have an SSA_NAME, try to resolve it
         with the current lattice value for the SSA_NAME.  */
        idx = TREE_OPERAND (t, 1);
--- 1011,1024 ----
        }

        if (ctor == NULL_TREE
!         || (TREE_CODE (ctor) != CONSTRUCTOR
!             && TREE_CODE (ctor) != STRING_CST)
          || !TREE_STATIC (ctor))
        return NULL_TREE;

+       if (TREE_CODE (ctor) == STRING_CST)
+       return fold_read_from_constant_string (t);
+ 
        /* Get the index.  If we have an SSA_NAME, try to resolve it
         with the current lattice value for the SSA_NAME.  */
        idx = TREE_OPERAND (t, 1);


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|                            |22303
              nThis|                            |
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14841


^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2006-05-08 15:07 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-03 23:49 [Bug optimization/14841] New: [tree-ssa] const_array[CST] is not folded kazu at cs dot umass dot edu
2004-04-04  3:00 ` [Bug optimization/14841] " pinskia at gcc dot gnu dot org
2004-05-24 22:25 ` [Bug tree-optimization/14841] " pinskia at gcc dot gnu dot org
2004-08-13  0:04 ` steven at gcc dot gnu dot org
2004-08-13  8:13 ` kazu at cs dot umass dot edu
2004-08-30 22:24 ` steven at gcc dot gnu dot org
2004-08-30 22:26 ` steven at gcc dot gnu dot org
2004-08-30 22:26 ` pinskia at gcc dot gnu dot org
2004-08-31  0:10 ` steven at gcc dot gnu dot org
2004-08-31  0:18 ` dnovillo at gcc dot gnu dot org
2004-08-31  2:03 ` giovannibajo at libero dot it
2004-08-31  2:06 ` pinskia at gcc dot gnu dot org
2004-08-31  9:38 ` stevenb at suse dot de
2004-08-31 18:13 ` steven at gcc dot gnu dot org
2004-08-31 21:00 ` steven at gcc dot gnu dot org
2004-08-31 21:03 ` dnovillo at gcc dot gnu dot org
2004-09-03 21:48 ` steven at gcc dot gnu dot org
2005-03-04  3:58 ` pinskia at gcc dot gnu dot org
2005-05-04  2:16 ` pinskia at gcc dot gnu dot org
2005-05-07  3:08 ` kazu at cs dot umass dot edu
2005-05-07  5:12 ` schlie at comcast dot net
2005-05-08 21:22 ` cvs-commit at gcc dot gnu dot org
2005-05-08 21:30 ` kazu at cs dot umass dot edu
     [not found] <bug-14841-5009@http.gcc.gnu.org/bugzilla/>
2006-05-08 10:07 ` rguenth at gcc dot gnu dot org
2006-05-08 10:09 ` rguenth at gcc dot gnu dot org
2006-05-08 15:07 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).