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.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 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=1664972569; 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: in-reply-to:in-reply-to:references:references; bh=hMN1WasU59FiXnMei4L+rCCaHlgIvN4UvOZRNX0RJRo=; b=WhC1n0HGoXxjOWwqYVBxLvpdemUXgeQraEDY9pOzlf/naolvHjXkrjFzNvD8E0u6tBDQD+ lR3I5MAZeU4YsMPscJq/b/kAjuikSn5gM4CVtNCvdF4LU6SSEp6W21qsEU4/HCMq6fASQj wS0k2EJh567vRaJKFgSiohciHNMy3Lk= 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 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , drepper@redhat.com, Aldy Hernandez 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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" } } -- 2.37.1