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 D99643858D20 for ; Wed, 12 Jul 2023 21:15:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D99643858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689196539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Cw6hJEqpjfUYbssBEZbX0ISRL28ZAUsPHL5easn8TaY=; b=PT/ueymaXFNAgqFl0wD8A9eMl8i3vt7nZGTSOUapX5TBOLzauV2cvv93ZUbiSYJi3PiQX1 GTKb1SFHNxnK/AxqA/D980rpYWclpLgupbgOlpSLokYQVTaHLsf2SzZ0ichVX+zR8UFvaB tqC8zlYpuVBGIFP1j8nLxttEXSVzRIY= 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 From: Aldy Hernandez 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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" } } -- 2.40.1