From bfce27245b07beb03c41fef0f9f833849b05c28d Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 5 Feb 2020 11:36:25 +0100 Subject: Fix up comment typo. 2020-02-05 Jakub Jelinek * tree-ssa-alias.c (aliasing_matching_component_refs_p): Fix up function comment typo. --- gcc/tree-ssa-alias.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gcc/tree-ssa-alias.c') diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index 670676f..c7e6679 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -856,7 +856,7 @@ type_has_components_p (tree type) /* MATCH1 and MATCH2 which are part of access path of REF1 and REF2 respectively are either pointing to same address or are completely - disjoint. If PARITAL_OVERLAP is true, assume that outermost arrays may + disjoint. If PARTIAL_OVERLAP is true, assume that outermost arrays may just partly overlap. Try to disambiguate using the access path starting from the match -- cgit v1.1 From 9a5338e57db1cda13fa788b0e0debbcf99a475d6 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Tue, 11 Feb 2020 16:53:13 -0700 Subject: PR tree-optimization/93683 - ICE on calloc with unused return value in ao_ref_init_from_ptr_and_size gcc/testsuite/ChangeLog: PR tree-optimization/93683 * gcc.dg/tree-ssa/ssa-dse-39.c: New test. gcc/ChangeLog: PR tree-optimization/93683 * tree-ssa-alias.c (stmt_kills_ref_p): Avoid using LHS when not set. --- gcc/tree-ssa-alias.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gcc/tree-ssa-alias.c') diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index c7e6679..fd78105 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -3265,6 +3265,8 @@ stmt_kills_ref_p (gimple *stmt, ao_ref *ref) return false; dest = gimple_call_lhs (stmt); + if (!dest) + return false; len = fold_build2 (MULT_EXPR, TREE_TYPE (arg0), arg0, arg1); } else -- cgit v1.1 From 91e50b2aa2dece9e22ae793d2a1a14b33bf3859d Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Fri, 21 Feb 2020 15:36:00 +0100 Subject: tree-optimization: fix access path oracle on mismatched array refs [PR93586] nonoverlapping_array_refs_p is not supposed to give meaningful results when bases of ref1 and ref2 are not same or completely disjoint and here it is called on c[0][j_2][0] and c[0][1] so bases in sence of this functions are "c[0][j_2]" and "c[0]" which do partially overlap. nonoverlapping_array_refs however walks pair of array references and in this case it misses to note the fact that if it walked across first mismatched pair it is no longer safe to compare rest. The reason why it continues matching is because it hopes it will eventually get pair of COMPONENT_REFs from types of same size and use TBAA to conclude that their addresses must be either same or completely disjoint. This patch makes the loop to terminate early but popping all the remaining pairs so walking can continue. We could re-synchronize on arrays of same size with TBAA but this is bit fishy (because we try to support some sort of partial array overlaps) and hard to implement (because of zero sized arrays and VLAs) so I think it is not worth the effort. In addition I notied that the function is not !flag_strict_aliasing safe and added early exits on places we set seen_unmatched_ref_p since later we do not check that in: /* If we skipped array refs on type of different sizes, we can no longer be sure that there are not partial overlaps. */ if (seen_unmatched_ref_p && !operand_equal_p (TYPE_SIZE (type1), TYPE_SIZE (type2), 0)) { ++alias_stats .nonoverlapping_refs_since_match_p_may_alias; } PR tree-optimization/93586 * tree-ssa-alias.c (nonoverlapping_array_refs_p): Finish array walk after mismatched array refs; do not sure type size information to recover from unmatched referneces with !flag_strict_aliasing_p. * gcc.dg/torture/pr93586.c: New testcase. --- gcc/tree-ssa-alias.c | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'gcc/tree-ssa-alias.c') diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index fd78105..7554e20 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -1486,9 +1486,27 @@ nonoverlapping_refs_since_match_p (tree match1, tree ref1, .nonoverlapping_refs_since_match_p_no_alias; return 1; } - partial_overlap = false; if (cmp == -1) - seen_unmatched_ref_p = true; + { + seen_unmatched_ref_p = true; + /* We can not maintain the invariant that bases are either + same or completely disjoint. However we can still recover + from type based alias analysis if we reach referneces to + same sizes. We do not attempt to match array sizes, so + just finish array walking and look for component refs. */ + if (!flag_strict_aliasing) + { + ++alias_stats.nonoverlapping_refs_since_match_p_may_alias; + return -1; + } + for (i++; i < narray_refs1; i++) + { + component_refs1.pop (); + component_refs2.pop (); + } + break; + } + partial_overlap = false; } } @@ -1503,7 +1521,14 @@ nonoverlapping_refs_since_match_p (tree match1, tree ref1, } ref1 = component_refs1.pop (); if (TREE_CODE (ref1) != COMPONENT_REF) - seen_unmatched_ref_p = true; + { + seen_unmatched_ref_p = true; + if (!flag_strict_aliasing) + { + ++alias_stats.nonoverlapping_refs_since_match_p_may_alias; + return -1; + } + } } while (!RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (ref1, 0)))); @@ -1517,7 +1542,14 @@ nonoverlapping_refs_since_match_p (tree match1, tree ref1, } ref2 = component_refs2.pop (); if (TREE_CODE (ref2) != COMPONENT_REF) - seen_unmatched_ref_p = true; + { + if (!flag_strict_aliasing) + { + ++alias_stats.nonoverlapping_refs_since_match_p_may_alias; + return -1; + } + seen_unmatched_ref_p = true; + } } while (!RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (ref2, 0)))); @@ -1537,6 +1569,8 @@ nonoverlapping_refs_since_match_p (tree match1, tree ref1, partial_overlap = false; + gcc_checking_assert (!seen_unmatched_ref_p || flag_strict_aliasing); + /* If we skipped array refs on type of different sizes, we can no longer be sure that there are not partial overlaps. */ if (seen_unmatched_ref_p -- cgit v1.1 From 9640ff5a88f25fc9bf581136fb25d1c2f756d5d4 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Thu, 27 Feb 2020 18:36:39 +0100 Subject: middle-end: Fix wrong code caused by disagreemed between FRE and access path oracle [PR 92152] FRE is checking stores for equivalence based on their address, value and base+ref alias sets. Because ref alias set is not always the alias set of innermost type, but it may be one of refs in the access path (as decided by component_uses_parent_alias_set_from) it means that we can not really rely on the remaining part of access path to be meaningful in any way except for offset+size computation. The patch makes alias (which is used by FRE to validate transform) and tree-ssa-alias to share same logic for ending the access path relevant for TBAA. tree-ssa-alias previously ended access paths on VIEW_CONVERT_EXPR and BIT_FIELD_REF so it is not hard to wire in common predicate. However it led to additional issues (I tried to read the code quite carefully for possible extra fun, so I hope I found it all): 1) alias_component_refs_walk compares base and reference sizes to see if one access path may continue by another. This check can be confused by an union containing structure with zero sized array. In this case we no longer see the refernece to zero sized array and think that ref size is 0. In an access path there can be at most one (valid) trailing/zero sized array access, so the sizes in the access path are decreasing with the this exception. This is already handled by the logic, however the access is not expected to happen past the end of TBAA segment. I suppose this was kind of latent problem before because one can think of access path doing traling array past VIEW_CONVERT_EXPR, but since in C code we don't VCE and in non-C we don't do trailing arrays, we did not hit the problem. I fixed this by tracking if the trailing array references appearing after the end of TBAA access path and mostly punt in the second case (because we need to support kind of all type puning here). I do not think we can assume much of sanity here, in particular, we no longer know there is only one because FRE may mix things up. An exception is the walk that looks for occurence of basetype of path1 within TBAA relevant part of path2. Here we realy care about TBAA relevant parts of paths and thus do not need to give up. I broke out the logic into ends_tbaa_access_path_p to avoid duplication and to let me stick some detailed comments. This became much more complex than I originally imagined (still it is useful to make oracle both faster and more precise). Note that logic in aliasing_component_refs_walk is safe since it works on TBAA relevant segments of paths only. 2) nonoverlapping_refs_since_match_p is using TBAA only in the corner case that the paths got out of sync and re-synchronize of types of same size are found. I thus extended it to whole paths (not only TBAA relevant parts) and track if the TBAA part can be used by counting of number of TBAA relevant res on the stack. I have noticed that in one case we call nonoverlapping_refs_since_match_p before checking for view converting MEM_REFs and in others we check after. I think we want to just disable TBAA part if view convert is in there but still disambiguate. I will do this incrementaly. 3) nonoverlapping_component_refs_p uses TBAA so it needs to punt on end of TBAA path. It deals with no sizes and thus there is not the issue as in 1). I am also attaching one (most probably) valid C++ testcase (by Mark Williams) where we incorrectly disambiguated while the code is valid by the common initial sequence rule. This happens to be fixed by same patch. Here one access goes through union and follows by access path trhough one filed, while other access path start by different field of the union with common initial sequence. This made aliasing_component_refs_p to not find the overlapping type (because there is none) and disambiguate. Now we cut the first access path by the union reference and this makes us to find the path continuation in alias_component_refs_walk. If FRE is ever made more careful about access paths past the fist union reference (I think that would be good idea since unions are quite common in C++ and we throw away quite useful info) then we will need to teach access path oracle about the common initial sequence rule (which, as Mark pointed out, is part of both C and C++ standards). Only argument that can possibly invalidate this testcase is that I do not see that stadnard is clear about the situation where one access path contains the union but other starts after the union. Clearly if both start after the union reference we are right to disambiguate (since there is no union unvolved). If both starts before union then there is common initial sequence and by standard it is defined. This case works on current trunk because aliasing_component_refs_p resorts to base+offset after finding the match. But even that is more or less an accident I would say. I had to xfail three testcases. While alias-access-path ones are artificial and odd, 20030807-7 is derived from gcc and shows that we give up on disambiguations of tree_node union, so this patch disables useful transform in real world code. I am still planning to collect some data on the effect of this change to TBAA, but unless we want to reorganize FRE, I do not think there is better solution. gcc/ChangeLog: 2020-02-26 Jan Hubicka PR middle-end/92152 * alias.c (ends_tbaa_access_path_p): Break out from ... (component_uses_parent_alias_set_from): ... here. * alias.h (ends_tbaa_access_path_p): Declare. * tree-ssa-alias.c (access_path_may_continue_p): Break out from ...; handle trailing arrays past end of tbaa access path. (aliasing_component_refs_p): ... here; likewise. (nonoverlapping_refs_since_match_p): Track TBAA segment of the access path; disambiguate also past end of it. (nonoverlapping_component_refs_p): Use only TBAA segment of the access path. gcc/testsuite/ChangeLog: 2020-02-26 Jan Hubicka PR middle-end/92152 * gcc.dg/tree-ssa/alias-access-path-12.c: New testcase. * g++.dg/torture/pr92152.C: New testcase. * gcc.dg/torture/pr92152.c: New testcase. * gcc.dg/tree-ssa/20030807-7.c: xfail. * gcc.dg/tree-ssa/alias-access-path-4.c: xfail one case. * gcc.dg/tree-ssa/alias-access-path-5.c: xfail one case. --- gcc/tree-ssa-alias.c | 178 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 127 insertions(+), 51 deletions(-) (limited to 'gcc/tree-ssa-alias.c') diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index 7554e20..2e8290f35 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -995,6 +995,51 @@ aliasing_component_refs_walk (tree ref1, tree type1, tree base1, return -1; } +/* Consider access path1 base1....ref1 and access path2 base2...ref2. + Return true if they can be composed to single access path + base1...ref1...base2...ref2. + + REF_TYPE1 if type of REF1. END_STRUCT_PAST_END1 is true if there is + a trailing array access after REF1 in the non-TBAA part of the access. + REF1_ALIAS_SET is the alias set of REF1. + + BASE_TYPE2 is type of base2. END_STRUCT_REF2 is non-NULL if there is + a traling array access in the TBAA part of access path2. + BASE2_ALIAS_SET is the alias set of base2. */ + +bool +access_path_may_continue_p (tree ref_type1, bool end_struct_past_end1, + alias_set_type ref1_alias_set, + tree base_type2, tree end_struct_ref2, + alias_set_type base2_alias_set) +{ + /* Access path can not continue past types with no components. */ + if (!type_has_components_p (ref_type1)) + return false; + + /* If first access path ends by too small type to hold base of + the second access path, typically paths can not continue. + + Punt if end_struct_past_end1 is true. We want to support arbitrary + type puning past first COMPONENT_REF to union because redundant store + elimination depends on this, see PR92152. For this reason we can not + check size of the reference because types may partially overlap. */ + if (!end_struct_past_end1) + { + if (compare_type_sizes (ref_type1, base_type2) < 0) + return false; + /* If the path2 contains trailing array access we can strenghten the check + to verify that also the size of element of the trailing array fits. + In fact we could check for offset + type_size, but we do not track + offsets and this is quite side case. */ + if (end_struct_ref2 + && compare_type_sizes (ref_type1, TREE_TYPE (end_struct_ref2)) < 0) + return false; + } + return (base2_alias_set == ref1_alias_set + || alias_set_subset_of (base2_alias_set, ref1_alias_set)); +} + /* Determine if the two component references REF1 and REF2 which are based on access types TYPE1 and TYPE2 and of which at least one is based on an indirect reference may alias. @@ -1021,8 +1066,30 @@ aliasing_component_refs_p (tree ref1, tree type1, type2; bool maybe_match = false; tree end_struct_ref1 = NULL, end_struct_ref2 = NULL; + bool end_struct_past_end1 = false; + bool end_struct_past_end2 = false; + + /* Choose bases and base types to search for. + The access path is as follows: + base....end_of_tbaa_ref...actual_ref + At one place in the access path may be a reference to zero sized or + trailing array. + + We generally discard the segment after end_of_tbaa_ref however + we need to be careful in case it contains zero sized or traling array. + These may happen after refernce to union and in this case we need to + not disambiguate type puning scenarios. + + We set: + base1 to point to base + + ref1 to point to end_of_tbaa_ref - /* Choose bases and base types to search for. */ + end_struct_ref1 to point the trailing reference (if it exists + in range base....end_of_tbaa_ref + + end_struct_past_end1 is true if this traling refernece occurs in + end_of_tbaa_ref...actual_ref. */ base1 = ref1; while (handled_component_p (base1)) { @@ -1042,9 +1109,15 @@ aliasing_component_refs_p (tree ref1, gcc_checking_assert (!end_struct_ref1); end_struct_ref1 = base1; } - if (TREE_CODE (base1) == VIEW_CONVERT_EXPR - || TREE_CODE (base1) == BIT_FIELD_REF) - ref1 = TREE_OPERAND (base1, 0); + if (ends_tbaa_access_path_p (base1)) + { + ref1 = TREE_OPERAND (base1, 0); + if (end_struct_ref1) + { + end_struct_past_end1 = true; + end_struct_ref1 = NULL; + } + } base1 = TREE_OPERAND (base1, 0); } type1 = TREE_TYPE (base1); @@ -1056,9 +1129,15 @@ aliasing_component_refs_p (tree ref1, gcc_checking_assert (!end_struct_ref2); end_struct_ref2 = base2; } - if (TREE_CODE (base2) == VIEW_CONVERT_EXPR - || TREE_CODE (base2) == BIT_FIELD_REF) - ref2 = TREE_OPERAND (base2, 0); + if (ends_tbaa_access_path_p (base2)) + { + ref2 = TREE_OPERAND (base2, 0); + if (end_struct_ref2) + { + end_struct_past_end2 = true; + end_struct_ref2 = NULL; + } + } base2 = TREE_OPERAND (base2, 0); } type2 = TREE_TYPE (base2); @@ -1070,7 +1149,8 @@ aliasing_component_refs_p (tree ref1, /* If type2 is big enough to contain type1 walk its access path. We also need to care of arrays at the end of structs that may extend - beyond the end of structure. */ + beyond the end of structure. If this occurs in the TBAA part of the + access path, we need to consider the increased type as well. */ if (cmp_outer >= 0 || (end_struct_ref2 && compare_type_sizes (TREE_TYPE (end_struct_ref2), type1) >= 0)) @@ -1113,31 +1193,14 @@ aliasing_component_refs_p (tree ref1, return false; } - /* If we have two type access paths B1.path1 and B2.path2 they may - only alias if either B1 is in B2.path2 or B2 is in B1.path1. - But we can still have a path that goes B1.path1...B2.path2 with - a part that we do not see. So we can only disambiguate now - if there is no B2 in the tail of path1 and no B1 on the - tail of path2. */ - if (compare_type_sizes (TREE_TYPE (ref2), type1) >= 0 - && (!end_struct_ref1 - || compare_type_sizes (TREE_TYPE (ref2), - TREE_TYPE (end_struct_ref1)) >= 0) - && type_has_components_p (TREE_TYPE (ref2)) - && (base1_alias_set == ref2_alias_set - || alias_set_subset_of (base1_alias_set, ref2_alias_set))) - { - ++alias_stats.aliasing_component_refs_p_may_alias; - return true; - } - /* If this is ptr vs. decl then we know there is no ptr ... decl path. */ - if (compare_type_sizes (TREE_TYPE (ref1), type2) >= 0 - && (!end_struct_ref2 - || compare_type_sizes (TREE_TYPE (ref1), - TREE_TYPE (end_struct_ref2)) >= 0) - && type_has_components_p (TREE_TYPE (ref1)) - && (base2_alias_set == ref1_alias_set - || alias_set_subset_of (base2_alias_set, ref1_alias_set))) + if (access_path_may_continue_p (TREE_TYPE (ref1), end_struct_past_end1, + ref1_alias_set, + type2, end_struct_ref2, + base2_alias_set) + || access_path_may_continue_p (TREE_TYPE (ref2), end_struct_past_end2, + ref2_alias_set, + type1, end_struct_ref1, + base1_alias_set)) { ++alias_stats.aliasing_component_refs_p_may_alias; return true; @@ -1348,6 +1411,7 @@ nonoverlapping_refs_since_match_p (tree match1, tree ref1, tree match2, tree ref2, bool partial_overlap) { + int ntbaa1 = 0, ntbaa2 = 0; /* Early return if there are no references to match, we do not need to walk the access paths. @@ -1365,25 +1429,33 @@ nonoverlapping_refs_since_match_p (tree match1, tree ref1, /* Create the stack of handled components for REF1. */ while (handled_component_p (ref1) && ref1 != match1) { - if (TREE_CODE (ref1) == VIEW_CONVERT_EXPR - || TREE_CODE (ref1) == BIT_FIELD_REF) - component_refs1.truncate (0); + /* We use TBAA only to re-synchronize after mismatched refs. So we + do not need to truncate access path after TBAA part ends. */ + if (ends_tbaa_access_path_p (ref1)) + ntbaa1 = 0; else - component_refs1.safe_push (ref1); + ntbaa1++; + component_refs1.safe_push (ref1); ref1 = TREE_OPERAND (ref1, 0); } /* Create the stack of handled components for REF2. */ while (handled_component_p (ref2) && ref2 != match2) { - if (TREE_CODE (ref2) == VIEW_CONVERT_EXPR - || TREE_CODE (ref2) == BIT_FIELD_REF) - component_refs2.truncate (0); + if (ends_tbaa_access_path_p (ref2)) + ntbaa2 = 0; else - component_refs2.safe_push (ref2); + ntbaa2++; + component_refs2.safe_push (ref2); ref2 = TREE_OPERAND (ref2, 0); } + if (!flag_strict_aliasing) + { + ntbaa1 = 0; + ntbaa2 = 0; + } + bool mem_ref1 = TREE_CODE (ref1) == MEM_REF && ref1 != match1; bool mem_ref2 = TREE_CODE (ref2) == MEM_REF && ref2 != match2; @@ -1444,6 +1516,7 @@ nonoverlapping_refs_since_match_p (tree match1, tree ref1, for (; narray_refs1 > narray_refs2; narray_refs1--) { ref1 = component_refs1.pop (); + ntbaa1--; /* If index is non-zero we need to check whether the reference does not break the main invariant that bases are either @@ -1471,6 +1544,7 @@ nonoverlapping_refs_since_match_p (tree match1, tree ref1, for (; narray_refs2 > narray_refs1; narray_refs2--) { ref2 = component_refs2.pop (); + ntbaa2--; if (!operand_equal_p (TREE_OPERAND (ref2, 1), cheap_array_ref_low_bound (ref2), 0)) return 0; @@ -1480,6 +1554,8 @@ nonoverlapping_refs_since_match_p (tree match1, tree ref1, { int cmp = nonoverlapping_array_refs_p (component_refs1.pop (), component_refs2.pop ()); + ntbaa1--; + ntbaa2--; if (cmp == 1 && !partial_overlap) { ++alias_stats @@ -1494,7 +1570,7 @@ nonoverlapping_refs_since_match_p (tree match1, tree ref1, from type based alias analysis if we reach referneces to same sizes. We do not attempt to match array sizes, so just finish array walking and look for component refs. */ - if (!flag_strict_aliasing) + if (ntbaa1 < 0 || ntbaa2 < 0) { ++alias_stats.nonoverlapping_refs_since_match_p_may_alias; return -1; @@ -1503,6 +1579,8 @@ nonoverlapping_refs_since_match_p (tree match1, tree ref1, { component_refs1.pop (); component_refs2.pop (); + ntbaa1--; + ntbaa2--; } break; } @@ -1520,10 +1598,11 @@ nonoverlapping_refs_since_match_p (tree match1, tree ref1, return 0; } ref1 = component_refs1.pop (); + ntbaa1--; if (TREE_CODE (ref1) != COMPONENT_REF) { seen_unmatched_ref_p = true; - if (!flag_strict_aliasing) + if (ntbaa1 < 0 || ntbaa2 < 0) { ++alias_stats.nonoverlapping_refs_since_match_p_may_alias; return -1; @@ -1541,9 +1620,10 @@ nonoverlapping_refs_since_match_p (tree match1, tree ref1, return 0; } ref2 = component_refs2.pop (); + ntbaa2--; if (TREE_CODE (ref2) != COMPONENT_REF) { - if (!flag_strict_aliasing) + if (ntbaa1 < 0 || ntbaa2 < 0) { ++alias_stats.nonoverlapping_refs_since_match_p_may_alias; return -1; @@ -1569,11 +1649,9 @@ nonoverlapping_refs_since_match_p (tree match1, tree ref1, partial_overlap = false; - gcc_checking_assert (!seen_unmatched_ref_p || flag_strict_aliasing); - /* If we skipped array refs on type of different sizes, we can no longer be sure that there are not partial overlaps. */ - if (seen_unmatched_ref_p + if (seen_unmatched_ref_p && ntbaa1 >= 0 && ntbaa2 >= 0 && !operand_equal_p (TYPE_SIZE (type1), TYPE_SIZE (type2), 0)) { ++alias_stats @@ -1663,8 +1741,7 @@ nonoverlapping_component_refs_p (const_tree x, const_tree y) if (TREE_CODE (type) == RECORD_TYPE) fieldsx.safe_push (field); } - else if (TREE_CODE (x) == VIEW_CONVERT_EXPR - || TREE_CODE (x) == BIT_FIELD_REF) + else if (ends_tbaa_access_path_p (x)) fieldsx.truncate (0); x = TREE_OPERAND (x, 0); } @@ -1680,8 +1757,7 @@ nonoverlapping_component_refs_p (const_tree x, const_tree y) if (TREE_CODE (type) == RECORD_TYPE) fieldsy.safe_push (TREE_OPERAND (y, 1)); } - else if (TREE_CODE (y) == VIEW_CONVERT_EXPR - || TREE_CODE (y) == BIT_FIELD_REF) + else if (ends_tbaa_access_path_p (y)) fieldsy.truncate (0); y = TREE_OPERAND (y, 0); } -- cgit v1.1 From 3d6fd7ce6dc4b6baa11920387d62dc001980aa70 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 3 Mar 2020 11:01:09 +0100 Subject: tree-optimization/93946 - fix bogus redundant store removal in FRE, DSE and DOM This fixes a common mistake in removing a store that looks redudnant but is not because it changes the dynamic type of the memory and thus makes a difference for following loads with TBAA. 2020-03-03 Richard Biener PR tree-optimization/93946 * alias.h (refs_same_for_tbaa_p): Declare. * alias.c (refs_same_for_tbaa_p): New function. * tree-ssa-alias.c (ao_ref_alias_set): For a NULL ref return zero. * tree-ssa-scopedtables.h (avail_exprs_stack::lookup_avail_expr): Add output argument giving access to the hashtable entry. * tree-ssa-scopedtables.c (avail_exprs_stack::lookup_avail_expr): Likewise. * tree-ssa-dom.c: Include alias.h. (dom_opt_dom_walker::optimize_stmt): Validate TBAA state before removing redundant store. * tree-ssa-sccvn.h (vn_reference_s::base_set): New member. (ao_ref_init_from_vn_reference): Adjust prototype. (vn_reference_lookup_pieces): Likewise. (vn_reference_insert_pieces): Likewise. * tree-ssa-sccvn.c: Track base alias set in addition to alias set everywhere. (eliminate_dom_walker::eliminate_stmt): Also check base alias set when removing redundant stores. (visit_reference_op_store): Likewise. * dse.c (record_store): Adjust valdity check for redundant store removal. * gcc.dg/torture/pr93946-1.c: New testcase. * gcc.dg/torture/pr93946-2.c: Likewise. --- gcc/tree-ssa-alias.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'gcc/tree-ssa-alias.c') diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index 2e8290f35..df9ba0d 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -697,6 +697,8 @@ ao_ref_alias_set (ao_ref *ref) { if (ref->ref_alias_set != -1) return ref->ref_alias_set; + if (!ref->ref) + return 0; ref->ref_alias_set = get_alias_set (ref->ref); return ref->ref_alias_set; } -- cgit v1.1 From e71b408aa242ffc76ffd19ebcdbd40279a1d9349 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 14 Apr 2020 13:16:25 +0200 Subject: middle-end/94539 - void * aliases every other pointer This makes same_type_for_tbaa_p conservative in the same way get_alias_set is about void * which we allow to alias all other pointers. 2020-04-15 Richard Biener PR middle-end/94539 * tree-ssa-alias.c (same_type_for_tbaa): Defer to alias_sets_conflict_p for pointers. * gcc.dg/alias-14.c: Make dg-do run. --- gcc/tree-ssa-alias.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'gcc/tree-ssa-alias.c') diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index df9ba0d..ede4f19 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -839,7 +839,16 @@ same_type_for_tbaa (tree type1, tree type2) would mean that conversions between them are useless, whereas they are not (e.g. type and subtypes can have different modes). So, in the end, they are only guaranteed to have the same alias set. */ - if (get_alias_set (type1) == get_alias_set (type2)) + alias_set_type set1 = get_alias_set (type1); + alias_set_type set2 = get_alias_set (type2); + if (set1 == set2) + return -1; + + /* Pointers to void are considered compatible with all other pointers, + so for two pointers see what the alias set resolution thinks. */ + if (POINTER_TYPE_P (type1) + && POINTER_TYPE_P (type2) + && alias_sets_conflict_p (set1, set2)) return -1; /* The types are known to be not equal. */ -- cgit v1.1