From patchwork Wed Jul 12 21:15:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1806992 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=hPtABYSC; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R1VsH4qVsz20Ph for ; Thu, 13 Jul 2023 07:16:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B52BB3857034 for ; Wed, 12 Jul 2023 21:15:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B52BB3857034 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689196559; bh=Cw6hJEqpjfUYbssBEZbX0ISRL28ZAUsPHL5easn8TaY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=hPtABYSCWCKS6J/8Nl8/uOcNBMlXjh8U/070LaSAQ+s4VxcF11oL/HCCZIxGMxT6g NKBKZvhBbZww/6O2Nos4ipo+QKSGU0fRUbqWLWPI99pDOvPa3Wu3c8U6GfZZI14AUu dc5l0JsJYz+ISoouQE9Pu7lryedFfod+N7hOXKDM= 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 D99643858D20 for ; Wed, 12 Jul 2023 21:15:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D99643858D20 Received: from mimecast-mx02.redhat.com (66.187.233.73 [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-192-8qoXCpjhPhqXN2uzR7ZmHw-1; Wed, 12 Jul 2023 17:15:35 -0400 X-MC-Unique: 8qoXCpjhPhqXN2uzR7ZmHw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E301A1C2BD99 for ; Wed, 12 Jul 2023 21:15:34 +0000 (UTC) Received: from abulafia.lan (unknown [10.39.192.61]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 818652166B28; Wed, 12 Jul 2023 21:15:34 +0000 (UTC) Received: from abulafia.lan (localhost [127.0.0.1]) by abulafia.lan (8.17.1/8.17.1) with ESMTPS id 36CLFVOG065906 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 12 Jul 2023 23:15:31 +0200 Received: (from aldyh@localhost) by abulafia.lan (8.17.1/8.17.1/Submit) id 36CLFV3C065905; Wed, 12 Jul 2023 23:15:31 +0200 To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED] [range-op] Take known set bits into account in popcount [PR107053] Date: Wed, 12 Jul 2023 23:15:27 +0200 Message-Id: <20230712211528.65888-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 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, RCVD_IN_MSPIKE_H4, 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 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 Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch teaches popcount about known set bits which are now available in the irange. PR tree-optimization/107053 gcc/ChangeLog: * gimple-range-op.cc (cfn_popcount): Use known set bits. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr107053.c: New test. --- gcc/gimple-range-op.cc | 11 +++++++---- gcc/testsuite/gcc.dg/tree-ssa/pr107053.c | 13 +++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107053.c diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 72c7b866f90..67b3c3d015e 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -880,17 +880,20 @@ public: if (lh.undefined_p ()) return false; unsigned prec = TYPE_PRECISION (type); - wide_int nz = lh.get_nonzero_bits (); - wide_int pop = wi::shwi (wi::popcount (nz), prec); + irange_bitmask bm = lh.get_bitmask (); + wide_int nz = bm.get_nonzero_bits (); + wide_int high = wi::shwi (wi::popcount (nz), prec); // Calculating the popcount of a singleton is trivial. if (lh.singleton_p ()) { - r.set (type, pop, pop); + r.set (type, high, high); return true; } if (cfn_ffs::fold_range (r, type, lh, rh, rel)) { - int_range<2> tmp (type, wi::zero (prec), pop); + wide_int known_ones = ~bm.mask () & bm.value (); + wide_int low = wi::shwi (wi::popcount (known_ones), prec); + int_range<2> tmp (type, low, high); r.intersect (tmp); return true; } diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107053.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107053.c new file mode 100644 index 00000000000..8195d0f57b4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107053.c @@ -0,0 +1,13 @@ +// { dg-do compile } +// { dg-options "-O2 -fdump-tree-evrp" } + +void link_failure(); +void f(int a) +{ + a |= 0x300; + int b = __builtin_popcount(a); + if (b < 2) + link_failure(); +} + +// { dg-final { scan-tree-dump-not "link_failure" "evrp" } }