[PATCH] Fix Tree-SRA bug with array slices
Eric Botcazou
ebotcazou@adacore.com
Sun Jun 18 13:05:00 GMT 2006
Hi,
The Tree-SRA pass mishandles array slices (aka ARRAY_RANGE_REFs). For
example, on the attached testcase compiled at -O, it turns
<bb 2>:
key = "XXX";
key[1 ...]{lb: 1 sz: 1} = "__";
key = key;
D.614_7 = key[3]{lb: 1 sz: 1};
into
<bb 2>:
key$3_3 = "XXX"[3]{lb: 1 sz: 1};
key$2_8 = "XXX"[2]{lb: 1 sz: 1};
key$1_9 = "XXX"[1]{lb: 1 sz: 1};
key[1 ...]{lb: 1 sz: 1} = "__";
key$3_10 = key[3]{lb: 1 sz: 1};
key$2_11 = key[2]{lb: 1 sz: 1};
key$1_12 = key[1]{lb: 1 sz: 1};
key$2_13 = key$2_11;
key$1_14 = key$1_12;
key$3_15 = key$3_10;
D.614_7 = key$3_15;
Note how key$3_10, key$3_15 and eventually D.614_7 are loaded with garbage.
The proposed fix is to treat ARRAY_RANGE_REFs as groups of ARRAY_REFs. The
end result on the testcase is
<bb 2>:
key$3_3 = "XXX"[3]{lb: 1 sz: 1};
key$2_8 = "XXX"[2]{lb: 1 sz: 1};
key$1_9 = "XXX"[1]{lb: 1 sz: 1};
key$2_10 = "__"[2]{lb: 1 sz: 1};
key$1_11 = "__"[1]{lb: 1 sz: 1};
key$2_12 = key$2_10;
key$1_13 = key$1_11;
key$3_14 = key$3_3;
D.614_7 = key$3_14;
Bootstrapped/regtested on i586-suse-linux. OK for mainline?
2006-06-18 Eric Botcazou <ebotcazou@adacore.com>
* tree.c (range_in_array_bounds_p): New predicate.
* tree.h (range_in_array_bounds_p): Declare it.
* tree-eh.c (tree_could_trap_p) <ARRAY_RANGE_REF>: Use it to
return a less conservative answer.
* tree-sra.c (struct sra_elt): Add new pointer field 'groups'
and flag 'is_group'.
(IS_ELEMENT_FOR_GROUP): New macro.
(FOR_EACH_ACTUAL_CHILD): Likewise.
(next_child_for_group): New helper function.
(can_completely_scalarize_p): Take into account groups.
(sra_hash_tree): Handle RANGE_EXPR.
(sra_elt_eq): Likewise.
(lookup_element): Be prepared for handling groups.
(is_valid_const_index): Delete.
(maybe_lookup_element_for_expr) <ARRAY_REF>: Use in_array_bounds_p
instead of is_valid_const_index.
<ARRAY_RANGE_REF>: New case.
(sra_walk_expr) <ARRAY_REF>: Use in_array_bounds_p instead of
is_valid_const_index.
<ARRAY_RANGE_REF>: Do not unconditionally punt.
(scan_dump): Dump info for groups too.
(decide_instantiation_1): Likewise.
(decide_block_copy): Assert that the element is not a group.
Propagate decision to groups.
(generate_one_element_ref): Handle RANGE_EXPR.
(mark_no_warning): Iterate over actual childs.
(generate_copy_inout): Likewise.
(generate_element_copy): Likewise.
(generate_element_zero): Likewise.
(generate_element_init_1): Likewise.
(dump_sra_elt_name): Handle RANGE_EXPR.
--
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: e923-017.diff
Type: text/x-diff
Size: 15122 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20060618/84ed5379/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.adb
Type: text/x-adasrc
Size: 287 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20060618/84ed5379/attachment-0001.bin>
More information about the Gcc-patches
mailing list