From patchwork Thu Apr 20 17:38:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 85984 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp506864vqo; Thu, 20 Apr 2023 10:40:11 -0700 (PDT) X-Google-Smtp-Source: AKy350ZCLCwbOUiUvS0A7EOVJzFStIwMsRLIEgNbKNUWgHgiQz+U3+VIcuUbiRNT66+uYcHeg/kZ X-Received: by 2002:a17:907:3e87:b0:949:797e:ea91 with SMTP id hs7-20020a1709073e8700b00949797eea91mr2812850ejc.56.1682012411252; Thu, 20 Apr 2023 10:40:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682012411; cv=none; d=google.com; s=arc-20160816; b=uiLrXBhwWIi/wwxRlpY/qE4VJWFUaqKRBacWVt8OgdKWLVg7WVaU9kHOaCyNc7jcQ/ RTmDVFAERVpLfGqUSBN2ONamU3xM2Uok0BdnMc/bUEka2V9Ip533uYKWUjW+g6jsUWj/ MNhVsyc59y1++VDzAEfXMW60ko1AY29z+MNWswMu/YOgNgU2oqyoHG5pS+A9vMkRV3zr jl4d1RklVXem+NgPf7EOJw75y1sEZLQi3mQjKrZ9MOITtiX92UhN1GryGBPuVZUg8f5p nMUviCOcZZ1//YSp69Lj4ON1VQp2cTIEiUbmVHjdtv2GGn1TZv2IAMdaZE1492IF2+0g mG9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Uri8O3IEowTQMkQDNMIWxfH7v7sls9Wu3wP6z7NifcQ=; b=0dj1rJSV3dvj6OEfaTa/8LRxZfGn0a66rSn3eIlMFu4rGc6/buPlpgBXW37DcPAvZn VFzqePAHlgqisUg3uD2M2iwLkC8AGJ7Tx9NumAcaDAMKfLjB8ljjeRqhad7sjFpx3DjQ 5mHFSZSDhcu9ACmPB6UEzpUEEfEfmtEPNQXGyLJlblQRTFcpnnH8vrhFKhr1kvBo0Sr5 aNUWUIr9WUcRUiVJ1v9q4OMTJdV/YSEtAi2wNK0wlzs34fGmXc4NnHpq+f7noNK8V4Zj 0hjM6R8kLGe5JWR9AGrk1s/3oCVEUik0Z0EuIwuXKT7aSEdU3dH2MPuh6FjjX//EPMgL OCCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mxN2IESD; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f22-20020a170906825600b0094ece4d0739si2013817ejx.888.2023.04.20.10.40.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 10:40:11 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mxN2IESD; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E0A033857732 for ; Thu, 20 Apr 2023 17:40:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E0A033857732 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682012409; bh=Uri8O3IEowTQMkQDNMIWxfH7v7sls9Wu3wP6z7NifcQ=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=mxN2IESDlnPRmcD78Csj695qOVFTP0tdOxFOoCQhLtqd5z5gm3w3FF8SN8+gdzrhC hcaaGfilUUpgjyCU0pLnJKT5KHjEtgUSxgW/KXfc4KjJFakHQui3EvMgCJnc+h0Pr6 6ngC0oudyrp251MW37xEuUKtOg7lWJW//d/3Gr9U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id A1FA23858D37 for ; Thu, 20 Apr 2023 17:39:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A1FA23858D37 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-85-qiWE_RN5OTi6IIgaifagLA-1; Thu, 20 Apr 2023 13:39:22 -0400 X-MC-Unique: qiWE_RN5OTi6IIgaifagLA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A843A3C106A7; Thu, 20 Apr 2023 17:39:21 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 45E691121315; Thu, 20 Apr 2023 17:39:20 +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 33KHcuKv4184260 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 20 Apr 2023 19:39:05 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 33KHcpvc4184259; Thu, 20 Apr 2023 19:38:51 +0200 Date: Thu, 20 Apr 2023 19:38:50 +0200 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-vect-patterns: One small vect_recog_ctz_ffs_pattern tweak [PR109011] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 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_H2, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763717845767052260?= X-GMAIL-MSGID: =?utf-8?q?1763717845767052260?= Hi! I've noticed I've made a typo, ifn in this function this late is always only IFN_CTZ or IFN_FFS, never IFN_CLZ. Due to this typo, we weren't using the originally intended .CTZ (X) = .POPCOUNT ((X - 1) & ~X) but .CTZ (X) = PREC - .POPCOUNT (X | -X) instead when we want to emit __builtin_ctz*/.CTZ using .POPCOUNT. Both compute the same value, both are defined at 0 with the same value (PREC), both have same number of GIMPLE statements, but I think the former ought to be preferred, because lots of targets have andn as a single operation rather than two, and also putting a -1 constant into a vector register is often cheaper than vector with broadcast PREC power of two value. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-04-20 Jakub Jelinek PR tree-optimization/109011 * tree-vect-patterns.cc (vect_recog_ctz_ffs_pattern): Use .CTZ (X) = .POPCOUNT ((X - 1) & ~X) in preference to .CTZ (X) = PREC - .POPCOUNT (X | -X). Jakub --- gcc/tree-vect-patterns.cc.jj 2023-04-20 11:55:03.576154120 +0200 +++ gcc/tree-vect-patterns.cc 2023-04-20 12:09:17.884633795 +0200 @@ -1630,7 +1630,7 @@ vect_recog_ctz_ffs_pattern (vec_info *vi && defined_at_zero_new && val == prec && val_new == prec) - || (ifnnew == IFN_POPCOUNT && ifn == IFN_CLZ)) + || (ifnnew == IFN_POPCOUNT && ifn == IFN_CTZ)) { /* .CTZ (X) = PREC - .CLZ ((X - 1) & ~X) .CTZ (X) = .POPCOUNT ((X - 1) & ~X). */