From patchwork Wed Oct 5 12:22:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1686332 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=2620:52:3:1:0:246e:9693:128c; helo=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=ZlDxFC5m; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4MjDKC3H2tz1yqn for ; Wed, 5 Oct 2022 23:24:31 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 709FC3857C44 for ; Wed, 5 Oct 2022 12:24:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 709FC3857C44 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664972669; bh=hMN1WasU59FiXnMei4L+rCCaHlgIvN4UvOZRNX0RJRo=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ZlDxFC5mYCtyRXGdJuoGEOpqTrUEe/2rFs4s2BAMWkubTaBGvBHJFOEP2yWkHDIbD +Roni5TPBTtxhmWBvTHExKapCaeCtOkcIX1UNKEaEfeAQpSWuIGs7HL/WTxft/oMNt IDeyRv/f3c2G3J8HCUEqr7PMi3uoKIJQe0h0tVwM= 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 18856385735F for ; Wed, 5 Oct 2022 12:22:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 18856385735F Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-241-r-tPisasNim3fm2M0ZMOhw-1; Wed, 05 Oct 2022 08:22:48 -0400 X-MC-Unique: r-tPisasNim3fm2M0ZMOhw-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 7B863101A52A for ; Wed, 5 Oct 2022 12:22:48 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.194.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 159CF1121314; Wed, 5 Oct 2022 12:22:40 +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 295CMd6J1579782 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 5 Oct 2022 14:22:39 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 295CMdFw1579781; Wed, 5 Oct 2022 14:22:39 +0200 To: GCC patches Subject: [COMMITTED] [PR tree-optimization/107052] range-ops: Take into account nonzero mask in popcount. Date: Wed, 5 Oct 2022 14:22:36 +0200 Message-Id: <20221005122236.1579762-2-aldyh@redhat.com> In-Reply-To: <20221005122236.1579762-1-aldyh@redhat.com> References: <20221005122236.1579762-1-aldyh@redhat.com> 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 X-Spam-Status: No, score=-11.8 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_LOW, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" PR tree-optimization/107052 gcc/ChangeLog: * gimple-range-op.cc (cfn_popcount::fold_range): Take into account nonzero bit mask. --- gcc/gimple-range-op.cc | 15 ++++++++++++--- gcc/testsuite/gcc.dg/tree-ssa/pr107052.c | 13 +++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107052.c diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 5b71d1cce6d..42ebc7d6ce5 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -422,15 +422,24 @@ public: virtual bool fold_range (irange &r, tree type, const irange &lh, const irange &rh, relation_kind rel) const { + 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); // 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; } - return cfn_ffs::fold_range (r, type, lh, rh, rel); + if (cfn_ffs::fold_range (r, type, lh, rh, rel)) + { + int_range<2> tmp (type, wi::zero (prec), pop); + r.intersect (tmp); + return true; + } + return false; } } op_cfn_popcount; diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107052.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107052.c new file mode 100644 index 00000000000..88b5213160d --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107052.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 > 3) + link_failure(); +} + +// { dg-final { scan-tree-dump-not "link_failure" "evrp" } }