From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 7E5293858413 for ; Mon, 12 Dec 2022 21:47:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7E5293858413 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=none smtp.mailfrom=kam.mff.cuni.cz Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 3486728047C; Mon, 12 Dec 2022 22:47:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1670881656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=bVuG9VKHZ4Og1kqoZThHv5JEJljukCyU2XX9uGeAobw=; b=RztnVZzjKmOG53kV1Y2gBLUsA5DjH98WpqqkjkMEsmACP9L4SMOshNhQwEsHZkPiRamPKC W8iL1eHj076fiZSmNY67S+wyp6a4userlxX0NDUX8jLrOiXKjbkQ02vtvS1KSjY8uaBVOu a6sMyXvQzvlC2RnVCc0xThDSjk+zKDY= Date: Mon, 12 Dec 2022 22:47:36 +0100 From: Jan Hubicka To: Martin Jambor Cc: GCC Patches Subject: Re: [PATCH 4/9] ipa-sra: Treat REFERENCE_TYPES as always dereferencable Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > 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 > > 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 > > * 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