Message ID | CADzB+2m=6o2qL0du97sYdDwZbH-1YsZhFgv4kQxTm2wDOU_Twg@mail.gmail.com |
---|---|
State | New |
Headers | show |
On Mon, Nov 14, 2016 at 6:04 AM, Jason Merrill <jason@redhat.com> wrote: > On Wed, Nov 9, 2016 at 7:24 AM, Jakub Jelinek <jakub@redhat.com> wrote: >> The match.pd hunk is needed, otherwise the generic folding happily folds >> int arr[2]; >> ... >> auto [ x, y ] = arr; >> &x == &arr[0] >> into 0, because it thinks x and arr are distinct VAR_DECLs. Though, if >> such comparisons are required to be folded in constexpr contexts under >> certain conditions, we'd need to handle the DECL_VALUE_EXPRs in constexpr.c >> somehow. > > What do you think of this approach instead? get_addr_base_and_unit_offset_1 is infrastructure related to get_ref_base_and_extent, get_inner_reference and get_base_address. All of those should really behave the same with respect to the innermost decl. Thus I don't think we should handle this here. Richard.
On Mon, Nov 14, 2016 at 12:04:24AM -0500, Jason Merrill wrote: > On Wed, Nov 9, 2016 at 7:24 AM, Jakub Jelinek <jakub@redhat.com> wrote: > > The match.pd hunk is needed, otherwise the generic folding happily folds > > int arr[2]; > > ... > > auto [ x, y ] = arr; > > &x == &arr[0] > > into 0, because it thinks x and arr are distinct VAR_DECLs. Though, if > > such comparisons are required to be folded in constexpr contexts under > > certain conditions, we'd need to handle the DECL_VALUE_EXPRs in constexpr.c > > somehow. > > What do you think of this approach instead? As Richard said, we'd need to change the 3 other functions too. And there is additional complication, for OpenMP we defer gimplification of vars with DECL_VALUE_EXPRs on them, because they often get a different DECL_VALUE_EXPR. So if optimizers look through DECL_VALUE_EXPR rather than punt on vars with DECL_VALUE_EXPR, we risk the undesirable value expressions might leak into the IL. So I think we want just punt on vars with DECL_VALUE_EXPR (perhaps even in those 4 functions), except for constexpr.c where we perhaps special case the decomposition vars or something similar. Jakub
diff --git a/gcc/match.pd b/gcc/match.pd index 79a418f..29ddcd8 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2547,15 +2547,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (with { int equal = 2; - /* Punt in GENERIC on variables with value expressions; - the value expressions might point to fields/elements - of other vars etc. */ - if (GENERIC - && ((VAR_P (base0) && DECL_HAS_VALUE_EXPR_P (base0)) - || (VAR_P (base1) && DECL_HAS_VALUE_EXPR_P (base1)))) - ; - else if (decl_in_symtab_p (base0) - && decl_in_symtab_p (base1)) + if (decl_in_symtab_p (base0) + && decl_in_symtab_p (base1)) equal = symtab_node::get_create (base0) ->equal_address_to (symtab_node::get_create (base1)); else if ((DECL_P (base0) diff --git a/gcc/tree-dfa.c b/gcc/tree-dfa.c index 0396feb..0a8523b 100644 --- a/gcc/tree-dfa.c +++ b/gcc/tree-dfa.c @@ -673,6 +673,15 @@ get_addr_base_and_unit_offset_1 (tree exp, HOST_WIDE_INT *poffset, { switch (TREE_CODE (exp)) { + case VAR_DECL: + if (DECL_HAS_VALUE_EXPR_P (exp)) + { + exp = DECL_VALUE_EXPR (exp); + continue; + } + else + goto done; + case BIT_FIELD_REF: { HOST_WIDE_INT this_off = TREE_INT_CST_LOW (TREE_OPERAND (exp, 2));