From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 1EC023858C2C for ; Tue, 23 Jan 2024 12:41:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1EC023858C2C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1EC023858C2C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706013683; cv=none; b=pAHPEKt4wFD1B5bXOfY5QCvwN2bp0HUEUWBzKvkf3OeTZm+TAGJDsEZCDd+qbMFy7MbR0flgz9MOjobgOyOv7C0xLsxRrMGYqN+f9tv5wKA4+BclcAXH4qUeimuGAulOnEyiN1Gn2bpdYG/UAJdKnabQbObCOxUWvY7vlCrmeeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706013683; c=relaxed/simple; bh=n0BnYAoL6w5rrLNTo9Q6oJ9Y+t3RhcMCjWQTvV2yTRs=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:Message-ID:MIME-Version; b=M8txtUCKmnl+/wg6BMjbhTWI3iGWCMVvyhbokeR+KpbVMNgCS4SnjqycN+jToOlDSZV2I+sF/9znwu8kGQPqLYlV5XY/wIqOKgVPgX+Qtd30xn4WX08qKOd6N4MMNA7Zu/mZFug+Wqw7fNIHrcm9Nv0aMnt4Kd+e9/E1YROeIMg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id CA1EC1F790; Tue, 23 Jan 2024 12:41:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706013681; h=from:from:reply-to: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=xkKzDxlCd1OOrCUs/XcsdoHYHdMe38a/XroWhRjYJcA=; b=LO+F1ZJOX2EM2IuCUMFDy8jUcHC5gNcFqNgWXH5jueEbvlKwgiw8re22gdTyc8KyyKmG5m QxvwP7xxIm9uoI8mK1rgbLLX6iXXtZFx+LGrAxaQhScfyqQtmA2/8LezdFgpBQ9Smvh0ai vjppCAvLuKsestFkwAxkFuPOv1UYHMk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706013681; h=from:from:reply-to: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=xkKzDxlCd1OOrCUs/XcsdoHYHdMe38a/XroWhRjYJcA=; b=kIXqQvp+6DLdyrTKozi0g+BrB9oWgVDzYGc/PvFltu1LCNZjxmD74oeMi84e6l0rMEtnb9 qP95a2W0AU6jQgBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1706013680; h=from:from:reply-to: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=xkKzDxlCd1OOrCUs/XcsdoHYHdMe38a/XroWhRjYJcA=; b=A+5w4B4EuSVP7Y+70GQ6/YEwTHFj8XzOrb3Tx/AHNiP2pwFL8bRdWrLv298dUbvxNlbztQ 4Ek7faVRvylzPmDlt6QjCwWefF5Cpb9pPEZmMwChYuOHzpbQ5+T92eeP0tYl4xFjkrVhQR vKg3Ew4dSTsTHtZR1hu2Y0AmUs2/T5E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1706013680; h=from:from:reply-to: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=xkKzDxlCd1OOrCUs/XcsdoHYHdMe38a/XroWhRjYJcA=; b=/6X6qDyGchEV7R4wGrsIWrMvyQnrihw6hzsIch24EdZNEO6JXzddj/e6oJczVVLGdoBjdv YNALbUbky1928qDQ== Date: Tue, 23 Jan 2024 13:40:15 +0100 (CET) From: Richard Biener To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] tree-optimization/113552 - fix num_call accounting in simd clone vectorization In-Reply-To: Message-ID: <96o9o1on-0523-6s9p-n00q-o7qn476p0470@fhfr.qr> References: <20240123115653.47E5C136A4@imap1.dmz-prg2.suse.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-3.10 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[gnu.org:url]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%] X-Spam-Level: X-Spam-Score: -3.10 X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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 Tue, 23 Jan 2024, Jakub Jelinek wrote: > On Tue, Jan 23, 2024 at 01:03:46PM +0100, Richard Biener wrote: > > On Tue, 23 Jan 2024, Jakub Jelinek wrote: > > > > > On Tue, Jan 23, 2024 at 12:56:52PM +0100, Richard Biener wrote: > > > > The following avoids using exact_log2 on the number of SIMD clone calls > > > > to be emitted when vectorizing calls since that can easily be not > > > > a power of two in which case it will return -1. For different simd > > > > clones the number of calls will differ by a multiply with a power of two > > > > only so using floor_log2 is good enough here. > > > > > > > > Bootstrap and regtest running on x86_64-unknown-linux-gnu. > > > > > > > > PR tree-optimization/113552 > > > > * tree-vect-stmts.cc (vectorizable_simd_clone_call): Use > > > > floor_log2 instead of exact_log2 on the number of calls. > > > > > > Is there any target which supports non-power-of-two simdlen? > > > If not, perhaps we should add !pow2p_hwi (num_calls) to the continue; > > > condition a few lines earlier? > > > > Is non-power-of-two simdlen a thing? Note there's nothing wrong > > with non-power-of-two num_calls, with VF == 4 and a group size > > of 3 you get 12 lanes and either 3 (simdlen == 4) or 6 (simdlen == 2) > > calls. > > > > Iff non-power-of-two simdlen is a thing then we could bias > > by + num_calls (no idea why we use *_log2 in the first place, but it > > was that way since the beginning). > > Ah, with SLP I can understand it doesn't have to be a power of two, > the original > + if (n->simdclone->simdlen > + < (unsigned) LOOP_VINFO_VECT_FACTOR (loop_vinfo)) > + this_badness += (exact_log2 (LOOP_VINFO_VECT_FACTOR (loop_vinfo)) > + - exact_log2 (n->simdclone->simdlen)) * 1024; > was written for loop vectorization only and I think correctly assumed > power of 2 loop vectorization factors as well as simdlens. Note even without SLP we could vectorize a group size of 3 with interleaving. But yes, VF for interleaving is a power of two and so is simdlen so the above should have worked. > I admit I don't remember why log2 rather than the count has been used, > the first version of the patch is > https://gcc.gnu.org/pipermail/gcc-patches/2013-November/374728.html > But if we keep using log2, perhaps better ceil_log2 because num_calls of > 3 is certainly more expensive than 2. I think only the relative accounting to the other this_badness increments matter since as said, at least with power-of-two simdlen we'd get different {ceil,floor}_log2 values for different simdlen. It's never going to be 3 vs 2 but 3 * 2^n vs. 3 * 2^m so floor or ceil doesn't matter. In fact we could have just using some inverse of exact_log2 (n->simdclone->simdlen). That is, it's only simdlen that's varying in this addend to this_badness. For the exact_log2 case the behavior is unchanged and we now only get a sensible number for the others now. Maybe log2 was for the fear of overflow or over-accounting compared to the other increments. When overflow is not an issue we could also use floor_log2 (num_calls * 4096) to be more "precise". I don't know why we have all these different weights and why they are the way they are - but it's a lot of apples and oranges we put together in a magic number to compare ;) I prefer to do a minimal change now, but both floor and ceil work for me, so if you prefer I can change (but as said, it would only matter with the mixing with the other cost factors, and in unknown ways since the desire is not spelled out). Richard.