[Bug tree-optimization/14841] [tree-ssa] const_array[CST] is not folded
steven at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Fri Sep 3 21:48:00 GMT 2004
------- 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
More information about the Gcc-bugs
mailing list