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 D0A7F3858D1E for ; Tue, 4 Oct 2022 04:28:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D0A7F3858D1E 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=1664857720; 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=++0RSuPnSD3uzXBLBPKTyVNfph3lzydXIqTKU2/R0CM=; b=XWtRXA6qUBi+xnkcImCuDyZPKPFXve3NNI+unz4Yq6kWn9+uvECoFoYjJeii/2Fa6S848b k8FZtQHvlypibydyo+7h5fwgoYI2UGOA2nlmTyPVhUTrabYUbnAg8MPrCs60IOsg78kTFF Qsedk70VG0PVdeYoRZwniPtUXuI3tKU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [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-673-G346a7bHOHywnTQAsPryqQ-1; Tue, 04 Oct 2022 00:28:37 -0400 X-MC-Unique: G346a7bHOHywnTQAsPryqQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CD4A938041D8 for ; Tue, 4 Oct 2022 04:28:36 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D125140EBF5; Tue, 4 Oct 2022 04:28:36 +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 2944SXBd1419943 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 4 Oct 2022 06:28:33 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 2944SXM61419942; Tue, 4 Oct 2022 06:28:33 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED] [PR107130] range-ops: Separate out ffs and popcount optimizations. Date: Tue, 4 Oct 2022 06:28:31 +0200 Message-Id: <20221004042831.1419926-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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=-12.3 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: __builtin_popcount and __builtin_ffs were sharing the same range-ops entry, but the nonzero mask optimization is not valid for ffs. Separate them out into two entries. PR tree-optimization/107130 gcc/ChangeLog: * gimple-range-op.cc (class cfn_popcount): Call op_cfn_ffs. (class cfn_ffs): New. (gimple_range_op_handler::maybe_builtin_call): Separate out CASE_CFN_FFS into its own case. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr107130.c: New test. --- gcc/gimple-range-op.cc | 37 +++++++++++++++++------- gcc/testsuite/gcc.dg/tree-ssa/pr107130.c | 19 ++++++++++++ 2 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr107130.c diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 3a7c9074659..5b71d1cce6d 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -387,8 +387,8 @@ cfn_toupper_tolower::fold_range (irange &r, tree type, const irange &lh, return true; } -// Implement range operator for CFN_BUILT_IN_FFS and CFN_BUILT_IN_POPCOUNT. -class cfn_popcount : public range_operator +// Implement range operator for CFN_BUILT_IN_FFS. +class cfn_ffs : public range_operator { public: using range_operator::fold_range; @@ -397,14 +397,6 @@ public: { if (lh.undefined_p ()) return false; - // 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; - } // __builtin_ffs* and __builtin_popcount* return [0, prec]. int prec = TYPE_PRECISION (lh.type ()); // If arg is non-zero, then ffs or popcount are non-zero. @@ -420,6 +412,26 @@ public: r.set (build_int_cst (type, mini), build_int_cst (type, maxi)); return true; } +} op_cfn_ffs; + +// Implement range operator for CFN_BUILT_IN_POPCOUNT. +class cfn_popcount : public cfn_ffs +{ +public: + using range_operator::fold_range; + virtual bool fold_range (irange &r, tree type, const irange &lh, + const irange &rh, relation_kind rel) const + { + // 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); + } } op_cfn_popcount; // Implement range operator for CFN_BUILT_IN_CLZ @@ -734,6 +746,11 @@ gimple_range_op_handler::maybe_builtin_call () break; CASE_CFN_FFS: + m_op1 = gimple_call_arg (call, 0); + m_int = &op_cfn_ffs; + m_valid = true; + break; + CASE_CFN_POPCOUNT: m_op1 = gimple_call_arg (call, 0); m_int = &op_cfn_popcount; diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr107130.c b/gcc/testsuite/gcc.dg/tree-ssa/pr107130.c new file mode 100644 index 00000000000..11fb816ad71 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr107130.c @@ -0,0 +1,19 @@ +// { dg-do compile } +// { dg-options "-Os -fno-tree-ccp -fno-tree-forwprop -fno-tree-fre -fdump-tree-vrp1" } + +static inline int +foo (int i) +{ + return __builtin_ffsl (i); +} + +int +main (void) +{ + int x = foo (41); + if (x != 1) + __builtin_abort (); + return 0; +} + +// { dg-final { scan-tree-dump-not "builtin_abort" "vrp1" } } -- 2.37.1