From patchwork Tue Sep 27 15:01:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1493 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp379224wrt; Tue, 27 Sep 2022 08:02:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM713OOwmIk56QHakqXaNmeTg8qd71HGl3wFzw9/WjqRHom/KmXoh1+gqOrkLqe/+z7CYePe X-Received: by 2002:a17:907:6288:b0:72f:90ba:f0b2 with SMTP id nd8-20020a170907628800b0072f90baf0b2mr22093217ejc.696.1664290969641; Tue, 27 Sep 2022 08:02:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664290969; cv=none; d=google.com; s=arc-20160816; b=jCXMRhdHdj5vigB1sHKKOeygiE/5bv0p+R3oU6FRMM7C9nl/mf7EtbrnCTROaKC5hC Yo1AaqhNfbEhVMqCWwCvg0Ltj/7D1iW3UlZHa9gE4458391L014686oIXOAY5oGAu44d 0DhmFw5Ae/1ytnI0DNdms7Yh+TerQwYzU0qQUcnGBgWZPnNdIwaoc9SlFOhW5ik8pvdW NdrhMIhMWLumgt5S8pBpAyZ8vIIMawNYGWJ/vURfnpSdpho6aYdQQM9rOaxx77xdqn/t T8fCKfBcj38mU8GVv004gkJad9+CWNTZKANog8hT0+MRYrpGzwdgcdRceWtch1q+3sTh gsaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=3ORAkp778/DfgwqO2b7gO5g1QIOuFDbp7damLZrsbdE=; b=pb/ZyLZsbSq8NCr4OitB/qAvkGfA6tTXCiRkWsMC05NXtoMEVZKgbOkiAWKTZq3r3l jkA0gVWS+qfxyzEWw2GxZJKjtij8gkltJf8itiLigiXWHQwy2don3eof/aiTmKe82pe4 /LP4p+Bi6BHkwLQLOuT+mzoEeQ+Lh+j9Y52oCrILmpoLEO8YO7yS9e0Ccot1uVks+THA BX2Ge6nmbCi15KrLvkhDzu20BdlJuHQxTc3OZ5AhWhieVpoegcVEiiET0Yt6XUb7/P4T Z5QmLiIYjjKNK1+1ElRsnkAPx1TpIJL09FJZgmoCrLjyzizTNZo8uUQWTuQhECj/yCTJ r2SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LwDBGzLG; 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 y2-20020a1709064b0200b0076ed46e4440si1271385eju.636.2022.09.27.08.02.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 08:02:49 -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=LwDBGzLG; 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 4E66938582BE for ; Tue, 27 Sep 2022 15:02:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4E66938582BE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664290968; bh=3ORAkp778/DfgwqO2b7gO5g1QIOuFDbp7damLZrsbdE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=LwDBGzLGSnv0vw2W0B+LBgYZX0KKEY3DdkQ0gRRWHQI/2rMJ3xJfX3XjnDZEKSIAY AV72s8bTRdO+iMbWeT2AyZTsrmmM46xu1qH5q/cP0SYIKbDlDgPoV7GBlnh+eI7WOK tbrEEub8DyKIQeEi4VDtEtxud0WBZcubEbXDiQRU= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 9FAF63858C50 for ; Tue, 27 Sep 2022 15:01:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9FAF63858C50 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-224-B7aJshlTMw-6dZrOU-Sgfg-1; Tue, 27 Sep 2022 11:01:49 -0400 X-MC-Unique: B7aJshlTMw-6dZrOU-Sgfg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C84D1299E760 for ; Tue, 27 Sep 2022 15:01:48 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.195.199]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 790382027061; Tue, 27 Sep 2022 15:01:48 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 28RF1jvv3487683 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 27 Sep 2022 17:01:45 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 28RF1jmv3487682; Tue, 27 Sep 2022 17:01:45 +0200 To: GCC patches Subject: [COMMITTED] range-ops: Calculate the popcount of a singleton. Date: Tue, 27 Sep 2022 17:01:31 +0200 Message-Id: <20220927150131.3487543-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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 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: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Cc: drepper@redhat.com 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?1745135567902769818?= X-GMAIL-MSGID: =?utf-8?q?1745135567902769818?= The legacy popcount folding didn't actually fold singleton ranges. I don't think anyone noticed because there are match.pd patterns that pick up the slack using the global nonzero bits set by CCP. It's good form to handle this, even without CCP's help. Tested on x86-64 Linux. p.s. This doesn't fix anything else in PR107043, except at the first two testcases at -fno-tree-ccp, so nothing new. gcc/ChangeLog: * gimple-range-op.cc (cfn_popcount): Calculate the popcount of a singleton. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/popcount6b.c: New test. --- gcc/gimple-range-op.cc | 8 ++++++++ gcc/testsuite/gcc.dg/tree-ssa/popcount6b.c | 6 ++++++ 2 files changed, 14 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/popcount6b.c diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index d7c6dfa933d..3f5e5852e5a 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -397,6 +397,14 @@ public: { if (lh.undefined_p ()) return false; + // Calculating the popcount of a singleton is trivial. + if (lh.singleton_p ()) + { + wide_int nz = lh.get_nonzero_bits (); + wide_int pop = wi::shwi (wi::popcount (nz), TYPE_PRECISION (type)); + r.set (type, pop, pop); + return true; + } // __builtin_ffs* and __builtin_popcount* return [0, prec]. int prec = TYPE_PRECISION (lh.type ()); // If arg is non-zero, then ffs or popcount are non-zero. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/popcount6b.c b/gcc/testsuite/gcc.dg/tree-ssa/popcount6b.c new file mode 100644 index 00000000000..90336ecb070 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/popcount6b.c @@ -0,0 +1,6 @@ +// { dg-do compile } +// { dg-options "-O2 -fdump-tree-evrp -fno-tree-ccp" } + +#include "popcount6.c" + +// { dg-final { scan-tree-dump "return 1;" "evrp" } }