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: 1731 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp571859wrs; Wed, 5 Oct 2022 05:25:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM70/VnPgOX47MK8GVnbYq5dUCqessrOm6xObr7Z9PB649mR2vvWiG79YBg4/15Pv0lyRxBl X-Received: by 2002:a05:6402:3709:b0:459:279e:fdc6 with SMTP id ek9-20020a056402370900b00459279efdc6mr11173243edb.338.1664972714468; Wed, 05 Oct 2022 05:25:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664972714; cv=none; d=google.com; s=arc-20160816; b=DVfH67strRLT3PK7BpFpjgzPgRsen3L9pRlrdRCVoYhpu33/sR00nRUvo8BlyL20Ox mk8sb3aBkN/fRKgzycz9XQZxxZAGiaUq0sF4KLrEcuT5zUxlxK5CepSFLLNbzWbUlK70 yR0cj128g2b5h4yDYtxXMFpi8GGZ/T3TcicoWTSrMaugkdnXglm8eL+k8SYncKXyrNuF 8ATB7Jb/PcMnGXRUJUXWIt2S+0i3TDEWGfmuX2IrP0S3QQO2HGMp4jj5YMBacdd9g3KM LJUhx4wIx/qII0uIXYGXtMQiqOMG4mHov2FyDbUBPvnXugDd5oXyvEdg2y48/CMgb/IW FR4A== 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:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=hMN1WasU59FiXnMei4L+rCCaHlgIvN4UvOZRNX0RJRo=; b=QhS1MLhuQG4lQqXanojR8zZfZyAkxI5V6QR7FOeZySXAruoFFrBWf/yXyTeUnsdnl0 ugReJw8nDu1jrjoRr5znvc4kHgJdpWpoh/hwK/PGQBOoIuz65oGHRNfHXRZq5pVrpF0u Vtg7MOgx4fu65wJ3BjQ8aRtb6/Y1+QWUMFssuhIGcWRpTchxj7Juu3IE/0YwtKIWHqxZ eTwHxixrCGWoL+Tjhrrp46nLFKASwzhznXrmW3BKB7mzkSgHgo/cw247HdbM20NxRZU9 GDQlmvu0kcanyBF4ADeNWapcOrndDmAAGZTzGsTnaSfSxHBQ+13C+FuiRSVvfWw19uGp P9Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="qWw/F/pE"; 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 f22-20020a056402195600b0045934c32fbasi4859867edz.171.2022.10.05.05.25.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 05:25:14 -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="qWw/F/pE"; 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 B23D6385B83E for ; Wed, 5 Oct 2022 12:24:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B23D6385B83E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664972692; 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=qWw/F/pEx83sGstt38v5vVExTd8x2Rx3mgUqJcJwMFjeK9xIz5n6UqUJ5+nxHUcl0 b2X6hb9m01rrwwesF/CVGzf9QW3GhAfo18lMMOQ2ToFve13+/KUAr6RFH9wDO5l92t VSRVbo9hnP922WJsXRUm7Q54vHGVPXK9e0En4Lyo= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745850428919240417?= X-GMAIL-MSGID: =?utf-8?q?1745850428919240417?= 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" } }