> Hi, > > I'm re-posting patches which I have posted at the end of stage 1 but > which have not passed review yet. > > 8<-------------------------------------------------------------------- > > C++ and especially Fortran pass data by references which are not > pointers potentially pointing anywhere and so can be assumed to be > safely dereferencable. This patch teaches IPA-SRA to treat them as > such and avoid the dance we do to prove that we can move loads from > them to the caller. > > When we do not know that a dereference will happen all the time, we > need a heuristics so that we do not force memory accesses that normally > happen only rarely. The patch simply uses the (possibly guessed) > profile and checks whether the (expected) number of loads is at least > half of function invocations invocations. > > Bootstrapped and tested individually when I originally posted it and > now bootstrapped and LTO-bootstrapped and tested as part of the whole > series. OK for master? > > > gcc/ChangeLog: > > 2022-11-11 Martin Jambor <mjam...@suse.cz> > > PR ipa/103585 > * ipa-sra.c (struct gensum_param_access): New field load_count. > (struct gensum_param_desc): New field safe_ref, adjusted comments. > (by_ref_count): Renamed to unsafe_by_ref_count, adjusted all uses. > (dump_gensum_access): Dump the new field. > (dump_gensum_param_descriptor): Likewise. > (create_parameter_descriptors): Set safe_ref field, move setting > by_ref forward. Only increment unsafe_by_ref_count for unsafe > by_ref parameters. > (allocate_access): Initialize new field. > (mark_param_dereference): Adjust indentation. Only add data to > bb_dereferences for unsafe by_ref parameters. > (scan_expr_access): For loads, accumulate BB counts. > (dereference_probable_p): New function. > (check_gensum_access): Fix leading comment, add parameter FUN. > Check cumulative counts of loads for safe by_ref accesses instead > of dereferences. > (process_scan_results): Do not propagate dereference distances for > safe by_ref parameters. Pass fun to check_gensum_access. Safe > by_ref params do not need the postdominance check. > > gcc/testsuite/ChangeLog: > > 2022-11-11 Martin Jambor <mjam...@suse.cz> > > * g++.dg/ipa/ipa-sra-5.C: New test > -/* Perform basic checks on ACCESS to PARM described by DESC and all its > - children, return true if the parameter cannot be split, otherwise return > - true and update *TOTAL_SIZE and *ONLY_CALLS. ENTRY_BB_INDEX must be the > - index of the entry BB in the function of PARM. */ > +/* Return true if the ACCESS loads happen frequently enough in FUN to risk > + moving them to the caller and only pass the result. */ > > static bool > -check_gensum_access (tree parm, gensum_param_desc *desc, > +dereference_probable_p (struct function *fun, gensum_param_access *access) > +{ > + return access->load_count > + >= ENTRY_BLOCK_PTR_FOR_FN (fun)->count.apply_scale (1, 2);
We may want to have --param for this. Otherwise the patch is OK. Honza