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 07E833857C5A for ; Fri, 4 Aug 2023 08:58:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 07E833857C5A Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kam.mff.cuni.cz Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 1A3392828D4; Fri, 4 Aug 2023 10:58:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1691139504; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GRXoKi6dwFtgfjNBXBt5vgbqZvHSXHz46Cz6aLIxsss=; b=cnujM5JtRWKr1LsFKBrrMLULC6xnIuzPzjuzQdG/zkV2N4+B9a34P/XwSQwgfAPi0VIC+1 4Bcmy3KTiL2uzN3R+EZ9/udUCSwC4VyWVH1Jy3GkFsBXQiOuVzs/FTunewEWToxYAij5eO u3H+utPPofeeF/pNxoHOxgC/Z0fQPWY= Date: Fri, 4 Aug 2023 10:58:24 +0200 From: Jan Hubicka To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: Re: Disable loop distribution for loops with estimated iterations 0 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,JMQ_SPF_NEUTRAL,KAM_NUMSUBJECT,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: > On Fri, Aug 4, 2023 at 9:16 AM Jan Hubicka via Gcc-patches > wrote: > > > > Hi, > > this prevents useless loop distribiton produced in hmmer. With FDO we now > > correctly work out that the loop created for last iteraiton is not going to > > iterate however loop distribution still produces a verioned loop that has no > > chance to survive loop vectorizer since we only keep distributed loops > > when loop vectorization suceeds and it requires number of (header) iterations > > to exceed the vectorization factor. > > > > Bootstrapped/regtested x86_64-linux, OK? > > OK. > > But why does optimize_loop_for_speed_p () return true when the loop > isn't expected to iterate? Wouldn't that be a better place to fix this > and similar issues in other places then? optimize_loop_for_speed_p checks whether the loop header is considered hot so we want to get it running fast. I think it is up to each loop transform to decide whether it helps loops with low iteration counts or hight iteration counts or both. Loop peeling and copy header are passes that does helps low iteration count loops. I think we have more. For example I wondered if I should also disable splitting but I think moving the conditional out of loop will likely help even if loop has small trip count. I briefly looked what passes already have cost model based on iteration estimate. I guess we should also tame down invariant motion and perhaps others. Honza > > Thanks, > Richard. > > > gcc/ChangeLog: > > > > * tree-loop-distribution.cc (loop_distribution::execute): Disable > > distribution for loops with estimated iterations 0. > > > > diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc > > index cf7c197aaf7..8ff2108f284 100644 > > --- a/gcc/tree-loop-distribution.cc > > +++ b/gcc/tree-loop-distribution.cc > > @@ -3871,10 +3871,20 @@ loop_distribution::execute (function *fun) > > > > bool destroy_p; > > int nb_generated_loops, nb_generated_calls; > > + bool only_patterns = !optimize_loop_for_speed_p (loop) > > + || !flag_tree_loop_distribution; > > + /* do not try to distribute loops that are not expected to iterate. */ > > + if (!only_patterns) > > + { > > + HOST_WIDE_INT iterations = estimated_loop_iterations_int (loop); > > + if (iterations < 0) > > + iterations = likely_max_loop_iterations_int (loop); > > + if (!iterations) > > + only_patterns = true; > > + } > > nb_generated_loops > > = distribute_loop (loop, work_list, cd, &nb_generated_calls, > > - &destroy_p, (!optimize_loop_for_speed_p (loop) > > - || !flag_tree_loop_distribution)); > > + &destroy_p, only_patterns); > > if (destroy_p) > > loops_to_be_destroyed.safe_push (loop); > >