From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 78B8A383468B for ; Mon, 20 Nov 2023 08:37:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 78B8A383468B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 78B8A383468B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700469444; cv=none; b=do25mPTqXGud3yttsxuvjwSOvQmpwje4xv651yFUk5805+v3lkyJPjMRy0QdYomHkrw8YRzQgEXSth3ZYCxHNYZAT+dWU9KvJhKkSRHpIR1U7Bf5QdHgRMzVe16hsEjtXPZva1CAoAM3elP6LSlYXIM80SPbeXbbLlB1JriwLL0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700469444; c=relaxed/simple; bh=uBZy/BIovf43hIz7GC45QvrLwk9I5co2x9Gr1hQ04mY=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=EZHY3LQF1M3SQN0vn1VhI/PTd1mt29XEmpg7LFIYRAN6cRaORfJZKdU8lrzDUzw7djD9I4VsgqJneuRUx7iU//YOnWBqbV3Sdt+c0jPgYfaBeFeewuEYsJG5CIYKZVYdfF+rGvjCKU5Ad1Lk5T02VB8KTBdcBqskjKbpKM+4bts= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700469441; h=from:from:reply-to: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=S4mkrU5MrnnSeFNKAxlEytAGp5Q556k9wrZ/ybbG8TU=; b=RIaRev5ENRLmKCipHIwtbm4KVGooDGc0PcHQGcTyWy4WOqPhllUU9UDSo3LEV7af+z1Pb0 M1uSiddJcSMCZpVkDhB4+q7PXeURkhx7dJtUnQVpSkbpum+fZ4UxKsX+JxqovaR6+uMEwJ PxL5YPidAokxH5bVejc00flnsySQ0IE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-Gildhc-oOgq8Q1BNvV0hfA-1; Mon, 20 Nov 2023 03:37:19 -0500 X-MC-Unique: Gildhc-oOgq8Q1BNvV0hfA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8AAA38110E0; Mon, 20 Nov 2023 08:37:19 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.53]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4EB30C1596F; Mon, 20 Nov 2023 08:37:19 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3AK8bGqo1532914 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 20 Nov 2023 09:37:17 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AK8bGf11532913; Mon, 20 Nov 2023 09:37:16 +0100 Date: Mon, 20 Nov 2023 09:37:15 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] tree-ssa-math-opts: popcount (X) == 1 to (X ^ (X - 1)) > (X - 1) optimization [PR90693] Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 Mon, Nov 20, 2023 at 07:54:54AM +0000, Richard Biener wrote: > On Fri, 17 Nov 2023, Jakub Jelinek wrote: > > Per the earlier discussions on this PR, the following patch folds > > popcount (x) == 1 (and != 1) into (x ^ (x - 1)) > x - 1 (or <=) > > if the corresponding popcount optab isn't implemented (I think any > > double-word popcount or call will be necessarily slower than the > > above cheap 3 op check and even for -Os larger or same size). > > > > I've noticed e.g. C++ aligned new starts with std::has_single_bit > > which does popcount (x) == 1. > > > > As a follow-up, I'm considering changing in this routine the popcount > > call to IFN_POPCOUNT with 2 arguments and during expansion test costs. > > > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > Classically this would have been an RTL expansion alternative, given > we want to do less of those the next place would have been the ISEL > pass. Any particular reason you chose widening-mul for this (guess > that pass just has a bad name and it's the effective "optimize" ISEL pass > we have). I think the ssa-math-opts pass does far more of this staff than the isel pass which only deals with vector stuff right now and you've even mentioned that pass for that in the PR90693 thread. That said, I can move it into the isel pass as well if you prefer that. Jakub