On Mon, Feb 22, 2016 at 11:46:19AM +0000, Alan Lawrence wrote: > On 19/02/16 17:52, Jakub Jelinek wrote: > >On Fri, Feb 19, 2016 at 05:42:34PM +0000, Alan Lawrence wrote: > >>This relates to FORTRAN code where different modules give different sizes > >>to the > >>same array in a COMMON block (contrary to the fortran language > >>specification). > >>SPEC have refused to patch the source code > >>(https://www.spec.org/cpu2006/Docs/faq.html#Run.05). > >> > >>Hence, this patch provides a Fortran-specific option -funknown-commons that > >>marks such arrays as having unknown size - that is, NULL_TREE for both > >>TYPE_SIZE and max value of TYPE_DOMAIN. DECL_SIZE is preserved for e.g. > >>output > >>in varasm.c. > >> > >>On AArch64, it fixes the 416.gamess issue, and allows compiling 416.gamess > >>without the -fno-aggressive-loop-optimizations previously required (numerous > >>other PRs relating to 416.gamess). > >> > >>I had to fix up a couple of places to deal with null TYPE_SIZE but in most > >>cases > > > >I think it is wrong to touch TYPE_SIZE/TYPE_SIZE_UNIT, IMHO it is much > >better just > >to ignore DECL_SIZE/DECL_SIZE_UNIT in the selected few places > >(get_ref_base_and_extent, the tree-ssa-loop-niters.c analysis) if the switch > >is on, for selected decls (aggregates with flexible array members and other > >similar trailing arrays, arrays themselves; all only if DECL_COMMON). > > So do you see... > > (a) A global command-line option, which we check alongside DECL_COMMON, in > (all or some of the) places which currently deal with flexible array > members? (I guess the flag would have no effect for compiling C code...or > (b) do we require it to 'enable' the existing flexible array member support?) > > (c) A new flag on each DECL, which we check in the places dealing with > flexible array members, which we set on those decls in the fortran frontend > if a fortran-frontend-only command-line option is passed? > > (d) A new flag on each DECL, which replaces the check for flexible array > members, plus a global command-line option, which controls both setting the > flag (on DECL_COMMONs) in the fortran frontend, and also setting it on > flexible array members in the C frontend? This might be 'cleanest' but is > also probably the most change and I doubt I'm going to have time to do this > for GCC 6... > > (e) Some other scheme that I've not understood yet?
(f) A global command-line option, which we check alongside DECL_COMMON and further tests (basically, we want only DECL_COMMON decls that either have ARRAY_TYPE, or some other aggregate type with flexible array member or some other trailing array in the struct), and use the resulting predicate in places where we optimize based on DECL_SIZE{,_UNIT} of the decl - if that predicate returns true, we assume the DECL_SIZE is "variable"/"unlimited"/whatever. The two spots known to me that would need to use this new predicate would be: tree.c (array_at_struct_end_p): /* If the reference is based on a declared entity, the size of the array is constrained by its given domain. */ if (DECL_P (ref)) return false; This would need to do if (DECL_P (ref) && !the_new_predicate (ref)) return false; tree-dfa.c (get_ref_base_and_extent): if (DECL_P (exp)) { ... } You want to do inside of that block something like if (the_new_predicate (exp)) { /* We need to deal with variable arrays ending structures. */ if (seen_variable_array_ref && maxsize != -1 && (TYPE_SIZE (TREE_TYPE (exp)) == NULL_TREE || TREE_CODE (TYPE_SIZE (TREE_TYPE (exp))) != INTEGER_CST || (bit_offset + maxsize == wi::to_offset (TYPE_SIZE (TREE_TYPE (exp)))))) maxsize = -1; else if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE) maxsize = -1; } /* If maxsize is unknown adjust it according to the size of the base decl. */ else if ((maxsize == -1 && DECL_SIZE (exp) && TREE_CODE (DECL_SIZE (exp)) == INTEGER_CST) maxsize = wi::to_offset (DECL_SIZE (exp)) - bit_offset; Thus, basically for the DECL_COMMON with trailing array readd the r233153 hunk (though it can be readded in slightly different spot), somehow deal with the case of ARRAY_TYPE itself, and only apply DEC_SIZE if the predicate is false. Jakub