From patchwork Sat May 4 08:30:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931237 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Peqa4u+5; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgt02Lt7z1xnS for ; Sat, 4 May 2024 18:33:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 80553386F43B for ; Sat, 4 May 2024 08:33:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by sourceware.org (Postfix) with ESMTPS id F0B5A3846079 for ; Sat, 4 May 2024 08:31:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F0B5A3846079 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F0B5A3846079 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.139.111.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811465; cv=none; b=ROzFByOB9noiNQJbHHqUhtAA1Bu1Ao2kS94VOo3i3b26rpgNZGWQJNvzzFuTDhewnu6SliUiRMM2HQtIKfkPmbQazfs5jRa3eX1MPRCJAdzvqIHmpC5g9DiL9Yp25EZF9cc06O8toR/2zILxFwr7N+44BirbXyKAp99KQq2Eh5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811465; c=relaxed/simple; bh=ereLgbtHIIvDDlUm4hvMK22X+Ht1xukjxwHE9Z5gmd8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FknN66kXZ/cQj5oB95vrfQpBmhnGfjQ6Zr5K2ki2cl4HTdiZKmuxzG5UlhDcmsn94/gs2aAhjYO2GxQN3Bx5fPBkdZoZUFSAubDgqnDD7k3cclYtbyEz6zg/hes5iTHfbpNkle6p+RAB5tAsHNJwFOoBT/UffazQ65pnesDP7/4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811462; 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=YNTKpSeO6WbFm+kqdIYT1bvN78cropXvCgUfB3rrWlo=; b=Peqa4u+5qMpjTFaCK6EfOBrgTxHYaMXYbEf8MWdjBd0LkdbA/4pNz64e/q4cQqFYvRIJS2 ITJjCyWcv4Cj94WHA9raLlcNZMJKMXGMKvi40/66AGqWCBSl4+IxbA3enov0fsieOMvokX CZXEzmO+ZpWOMyIYikIE4Ejshu0/gEk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-578-miGzNXr1MFe6C3lx2ccD2Q-1; Sat, 04 May 2024 04:31:00 -0400 X-MC-Unique: miGzNXr1MFe6C3lx2ccD2Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 67092800CA2 for ; Sat, 4 May 2024 08:31:00 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1C722C13FA1; Sat, 4 May 2024 08:30:59 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448UwQG139788 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:30:58 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448Uwq0139787; Sat, 4 May 2024 10:30:58 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 01/23] Minimal prange class showing inlining degradation to VRP. Date: Sat, 4 May 2024 10:30:29 +0200 Message-ID: <20240504083056.139719-2-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org There is a 2% slowdown to VRP unrelated to the work at hand. This patch is a skeleton implementation of prange that exhibits this degradation. It is meant as a place in the commit history we can return to in order to revisit the issue. The relevant discussion is here: https://gcc.gnu.org/pipermail/gcc/2024-May/243898.html gcc/ChangeLog: * value-range.h (class prange): New. --- gcc/value-range.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/gcc/value-range.h b/gcc/value-range.h index 934eec9e386..f52d5165707 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -378,6 +378,39 @@ private: wide_int m_ranges[N*2]; }; +class prange : public vrange +{ +public: + static bool supports_p (const_tree) { return false; } + virtual bool supports_type_p (const_tree) const final override { return false; } + virtual void accept (const vrange_visitor &) const final override {} + virtual void set_undefined () final override {} + virtual void set_varying (tree) final override {} + virtual void set_nonzero (tree) final override {} + virtual void set_zero (tree) final override; + virtual void set_nonnegative (tree) final override {} + virtual bool contains_p (tree) const final override { return false; } + virtual bool fits_p (const vrange &) const final override { return false; } + virtual bool singleton_p (tree * = NULL) const final override { return false; } + virtual bool zero_p () const final override { return false; } + virtual bool nonzero_p () const final override { return false; } + virtual void set (tree, tree, value_range_kind = VR_RANGE) final override {} + virtual tree type () const final override { return NULL; } + virtual bool union_ (const vrange &) final override { return false; } + virtual bool intersect (const vrange &) final override { return false; } + virtual tree lbound () const final override { return NULL; } + virtual tree ubound () const final override { return NULL; } + + wide_int lower_bound () const; + wide_int upper_bound () const; + irange_bitmask get_bitmask () const final override; + void update_bitmask (const irange_bitmask &) final override {} +private: + wide_int m_min; + wide_int m_max; + irange_bitmask m_bitmask; +}; + // Unsupported temporaries may be created by ranger before it's known // they're unsupported, or by vr_values::get_value_range. @@ -1187,6 +1220,32 @@ irange_val_max (const_tree type) return wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type)); } +inline void +prange::set_zero (tree type) +{ + wide_int zero = wi::zero (TYPE_PRECISION (type)); + m_min = m_max = zero; + m_bitmask = irange_bitmask (zero, zero); +} + +inline wide_int +prange::lower_bound () const +{ + return m_min; +} + +inline wide_int +prange::upper_bound () const +{ + return m_max; +} + +inline irange_bitmask +prange::get_bitmask () const +{ + return m_bitmask; +} + inline frange::frange () : vrange (VR_FRANGE) From patchwork Sat May 4 08:30:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931235 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Q8j3+atE; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgrf0BC2z1xnS for ; Sat, 4 May 2024 18:32:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3795B386F45A for ; Sat, 4 May 2024 08:32:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id 6B242384474A for ; Sat, 4 May 2024 08:31:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B242384474A Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6B242384474A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811467; cv=none; b=Gj0+3fFOHUEy444LJJ2/bZavRGlb/zjgdxhtUkzeUNigkRVr7L7iiXLhv9jpyjsM2uTBScQ0W5yjrg9hUsFqWF/DiypsuwRVqaFf7ZQj6ia6egAXxvNFYZ1xJRpITXX9CrAyKycyBPl9jagcL65Ls+CLM5cB6slY5EVgV5iLD0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811467; c=relaxed/simple; bh=QsPpK/2SniPXznRhvlCL8xdbkye3pyp6pld4yZksC2k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kpNyYioy2AUZoP3hcvWDgdTjKrbwH9k6VF6bh0feKWctZndUuxCFtbEucUlVG6D2pEib6NCZnhgZafU3PEZObLfOVo/Gf98BxgtqCUtHQyiaO2Mi+fcqgh/Y3rp9Dayb8vgZiS6eeZvxNYDjVLWGSTM0la/USl/mvhF6KzPynFY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811463; 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=rj6uyud8xHA8tXWIIqd9WyNag1BKK6P9+AHSc3ugCjA=; b=Q8j3+atEOY1TFF3wA5wcaHOpG1uaZ3pF+rdUEKHk+CYrxy2OqGE76T77bkNEZp2E15UWZA FIxQQxwkq5uo+g1b/skweSTY9rFqfBB0W6+Wyp/DR+4vd8WNgOCfPs4twZlTpY/Ue/Bcxs 9kPRo0XpeYVL1iBCWxlq/O3UPpGFFDY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-489-9inAgugNMfydb60l0iIIVA-1; Sat, 04 May 2024 04:31:01 -0400 X-MC-Unique: 9inAgugNMfydb60l0iIIVA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ABC0B8943A1 for ; Sat, 4 May 2024 08:31:00 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 436F6200B08F; Sat, 4 May 2024 08:31:00 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448Uw31139792 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:30:59 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448Uwnf139791; Sat, 4 May 2024 10:30:58 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 02/23] Implement basic prange class. Date: Sat, 4 May 2024 10:30:30 +0200 Message-ID: <20240504083056.139719-3-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This provides a bare prange class with bounds and bitmasks. It will be a drop-in replacement for pointer ranges, so we can pull their support from irange. The range-op code will be contributed as a follow-up. The code is disabled by default, as irange::supports_p still accepts pointers: inline bool irange::supports_p (const_tree type) { return INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type); } Once the prange operators are implemented in range-ops, pointer support will be removed from irange to activate pranges. gcc/ChangeLog: * value-range-pretty-print.cc (vrange_printer::visit): New. * value-range-pretty-print.h: Declare prange visit() method. * value-range.cc (vrange::operator=): Add prange support. (vrange::operator==): Same. (prange::accept): New. (prange::set_nonnegative): New. (prange::set): New. (prange::contains_p): New. (prange::singleton_p): New. (prange::lbound): New. (prange::ubound): New. (prange::union_): New. (prange::intersect): New. (prange::operator=): New. (prange::operator==): New. (prange::invert): New. (prange::verify_range): New. (prange::update_bitmask): New. (range_tests_misc): Use prange. * value-range.h (enum value_range_discriminator): Add VR_PRANGE. (class prange): New. (Value_Range::init): Add prange support. (Value_Range::operator=): Same. (Value_Range::supports_type_p): Same. (prange::prange): New. (prange::supports_p): New. (prange::supports_type_p): New. (prange::set_undefined): New. (prange::set_varying): New. (prange::set_nonzero): New. (prange::set_zero): New. (prange::contains_p): New. (prange::zero_p): New. (prange::nonzero_p): New. (prange::type): New. (prange::lower_bound): New. (prange::upper_bound): New. (prange::varying_compatible_p): New. (prange::get_bitmask): New. (prange::fits_p): New. --- gcc/value-range-pretty-print.cc | 25 +++ gcc/value-range-pretty-print.h | 1 + gcc/value-range.cc | 303 +++++++++++++++++++++++++++++++- gcc/value-range.h | 199 ++++++++++++++++++--- 4 files changed, 500 insertions(+), 28 deletions(-) diff --git a/gcc/value-range-pretty-print.cc b/gcc/value-range-pretty-print.cc index b6d23dce6d2..b11d6494774 100644 --- a/gcc/value-range-pretty-print.cc +++ b/gcc/value-range-pretty-print.cc @@ -112,6 +112,31 @@ vrange_printer::visit (const irange &r) const print_irange_bitmasks (pp, r.m_bitmask); } +void +vrange_printer::visit (const prange &r) const +{ + pp_string (pp, "[prange] "); + if (r.undefined_p ()) + { + pp_string (pp, "UNDEFINED"); + return; + } + dump_generic_node (pp, r.type (), 0, TDF_NONE | TDF_NOUID, false); + pp_character (pp, ' '); + if (r.varying_p ()) + { + pp_string (pp, "VARYING"); + return; + } + + pp_character (pp, '['); + print_int_bound (pp, r.lower_bound (), r.type ()); + pp_string (pp, ", "); + print_int_bound (pp, r.upper_bound (), r.type ()); + pp_character (pp, ']'); + print_irange_bitmasks (pp, r.m_bitmask); +} + void vrange_printer::print_real_value (tree type, const REAL_VALUE_TYPE &r) const { diff --git a/gcc/value-range-pretty-print.h b/gcc/value-range-pretty-print.h index 44cd6e81298..5522aad0673 100644 --- a/gcc/value-range-pretty-print.h +++ b/gcc/value-range-pretty-print.h @@ -27,6 +27,7 @@ public: vrange_printer (pretty_printer *pp_) : pp (pp_) { } void visit (const unsupported_range &) const override; void visit (const irange &) const override; + void visit (const prange &) const override; void visit (const frange &) const override; private: void print_frange_nan (const frange &) const; diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 7250115261f..84113ccfbd0 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -251,6 +251,8 @@ vrange::operator= (const vrange &src) { if (is_a (src)) as_a (*this) = as_a (src); + else if (is_a (src)) + as_a (*this) = as_a (src); else if (is_a (src)) as_a (*this) = as_a (src); else @@ -268,6 +270,8 @@ vrange::operator== (const vrange &src) const { if (is_a (src)) return as_a (*this) == as_a (src); + if (is_a (src)) + return as_a (*this) == as_a (src); if (is_a (src)) return as_a (*this) == as_a (src); gcc_unreachable (); @@ -397,6 +401,294 @@ irange::set_nonnegative (tree type) wi::to_wide (TYPE_MAX_VALUE (type))); } +// Prange implementation. + +void +prange::accept (const vrange_visitor &v) const +{ + v.visit (*this); +} + +void +prange::set_nonnegative (tree type) +{ + set (type, + wi::zero (TYPE_PRECISION (type)), + wi::max_value (TYPE_PRECISION (type), UNSIGNED)); +} + +void +prange::set (tree min, tree max, value_range_kind kind) +{ + return set (TREE_TYPE (min), wi::to_wide (min), wi::to_wide (max), kind); +} + +void +prange::set (tree type, const wide_int &min, const wide_int &max, + value_range_kind kind) +{ + if (kind == VR_UNDEFINED) + { + set_undefined (); + return; + } + if (kind == VR_VARYING) + { + set_varying (type); + return; + } + if (kind == VR_ANTI_RANGE) + { + gcc_checking_assert (min == 0 && max == 0); + set_nonzero (type); + return; + } + m_type = type; + m_min = min; + m_max = max; + if (m_min == 0 && m_max == -1) + { + m_kind = VR_VARYING; + m_bitmask.set_unknown (TYPE_PRECISION (type)); + if (flag_checking) + verify_range (); + return; + } + + m_kind = VR_RANGE; + m_bitmask = get_bitmask_from_range (type, min, max); + if (flag_checking) + verify_range (); +} + +bool +prange::contains_p (const wide_int &w) const +{ + if (undefined_p ()) + return false; + + if (varying_p ()) + return true; + + return (wi::le_p (lower_bound (), w, UNSIGNED) + && wi::ge_p (upper_bound (), w, UNSIGNED)); +} + +bool +prange::singleton_p (tree *result) const +{ + if (m_kind == VR_RANGE && lower_bound () == upper_bound ()) + { + if (result) + *result = wide_int_to_tree (type (), m_min); + return true; + } + return false; +} + +tree +prange::lbound () const +{ + return wide_int_to_tree (type (), m_min); +} + +tree +prange::ubound () const +{ + return wide_int_to_tree (type (), m_max); +} + +bool +prange::union_ (const vrange &v) +{ + const prange &r = as_a (v); + + if (r.undefined_p ()) + return false; + if (undefined_p ()) + { + *this = r; + if (flag_checking) + verify_range (); + return true; + } + if (varying_p ()) + return false; + if (r.varying_p ()) + { + set_varying (type ()); + return true; + } + + wide_int new_lb = wi::min (r.lower_bound (), lower_bound (), UNSIGNED); + wide_int new_ub = wi::max (r.upper_bound (), upper_bound (), UNSIGNED); + prange new_range (type (), new_lb, new_ub); + new_range.m_bitmask.union_ (m_bitmask); + new_range.m_bitmask.union_ (r.m_bitmask); + if (new_range.varying_compatible_p ()) + { + set_varying (type ()); + return true; + } + if (flag_checking) + new_range.verify_range (); + if (new_range == *this) + return false; + *this = new_range; + return true; +} + +bool +prange::intersect (const vrange &v) +{ + const prange &r = as_a (v); + gcc_checking_assert (undefined_p () || r.undefined_p () + || range_compatible_p (type (), r.type ())); + + if (undefined_p ()) + return false; + if (r.undefined_p ()) + { + set_undefined (); + return true; + } + if (r.varying_p ()) + return false; + if (varying_p ()) + { + *this = r; + return true; + } + + prange save = *this; + m_min = wi::max (r.lower_bound (), lower_bound (), UNSIGNED); + m_max = wi::min (r.upper_bound (), upper_bound (), UNSIGNED); + if (wi::gt_p (m_min, m_max, UNSIGNED)) + { + set_undefined (); + return true; + } + + // Intersect all bitmasks: the old one, the new one, and the other operand's. + irange_bitmask new_bitmask = get_bitmask_from_range (m_type, m_min, m_max); + m_bitmask.intersect (new_bitmask); + m_bitmask.intersect (r.m_bitmask); + + if (flag_checking) + verify_range (); + if (*this == save) + return false; + return true; +} + +prange & +prange::operator= (const prange &src) +{ + m_type = src.m_type; + m_kind = src.m_kind; + m_min = src.m_min; + m_max = src.m_max; + m_bitmask = src.m_bitmask; + if (flag_checking) + verify_range (); + return *this; +} + +bool +prange::operator== (const prange &src) const +{ + if (m_kind == src.m_kind) + { + if (undefined_p ()) + return true; + + if (varying_p ()) + return types_compatible_p (type (), src.type ()); + + return (m_min == src.m_min && m_max == src.m_max + && m_bitmask == src.m_bitmask); + } + return false; +} + +void +prange::invert () +{ + gcc_checking_assert (!undefined_p () && !varying_p ()); + + wide_int new_lb, new_ub; + unsigned prec = TYPE_PRECISION (type ()); + wide_int type_min = wi::zero (prec); + wide_int type_max = wi::max_value (prec, UNSIGNED); + wi::overflow_type ovf; + + if (lower_bound () == type_min) + { + new_lb = wi::add (upper_bound (), 1, UNSIGNED, &ovf); + if (ovf) + new_lb = type_min; + new_ub = type_max; + set (type (), new_lb, new_ub); + } + else if (upper_bound () == type_max) + { + wi::overflow_type ovf; + new_lb = type_min; + new_ub = wi::sub (lower_bound (), 1, UNSIGNED, &ovf); + if (ovf) + new_ub = type_max; + set (type (), new_lb, new_ub); + } + else + set_varying (type ()); +} + +void +prange::verify_range () const +{ + gcc_checking_assert (m_discriminator == VR_PRANGE); + + if (m_kind == VR_UNDEFINED) + return; + + gcc_checking_assert (supports_p (type ())); + + if (m_kind == VR_VARYING) + { + gcc_checking_assert (varying_compatible_p ()); + return; + } + gcc_checking_assert (!varying_compatible_p ()); + gcc_checking_assert (m_kind == VR_RANGE); +} + +void +prange::update_bitmask (const irange_bitmask &bm) +{ + gcc_checking_assert (!undefined_p ()); + + // If all the bits are known, this is a singleton. + if (bm.mask () == 0) + { + set (type (), m_bitmask.value (), m_bitmask.value ()); + return; + } + + // Drop VARYINGs with known bits to a plain range. + if (m_kind == VR_VARYING && !bm.unknown_p ()) + m_kind = VR_RANGE; + + m_bitmask = bm; + if (varying_compatible_p ()) + m_kind = VR_VARYING; + + if (flag_checking) + verify_range (); +} + + +// Frange implementation. + void frange::accept (const vrange_visitor &v) const { @@ -2542,11 +2834,12 @@ range_tests_misc () // Make sure NULL and non-NULL of pointer types work, and that // inverses of them are consistent. tree voidp = build_pointer_type (void_type_node); - r0.set_zero (voidp); - r1 = r0; - r0.invert (); - r0.invert (); - ASSERT_TRUE (r0 == r1); + prange p0; + p0.set_zero (voidp); + prange p1 = p0; + p0.invert (); + p0.invert (); + ASSERT_TRUE (p0 == p1); // [10,20] U [15, 30] => [10, 30]. r0 = range_int (10, 20); diff --git a/gcc/value-range.h b/gcc/value-range.h index f52d5165707..6fe31d67582 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -47,6 +47,8 @@ enum value_range_discriminator { // Range holds an integer or pointer. VR_IRANGE, + // Pointer range. + VR_PRANGE, // Floating point range. VR_FRANGE, // Range holds an unsupported type. @@ -380,32 +382,49 @@ private: class prange : public vrange { + friend class prange_storage; + friend class vrange_printer; public: - static bool supports_p (const_tree) { return false; } - virtual bool supports_type_p (const_tree) const final override { return false; } - virtual void accept (const vrange_visitor &) const final override {} - virtual void set_undefined () final override {} - virtual void set_varying (tree) final override {} - virtual void set_nonzero (tree) final override {} - virtual void set_zero (tree) final override; - virtual void set_nonnegative (tree) final override {} - virtual bool contains_p (tree) const final override { return false; } - virtual bool fits_p (const vrange &) const final override { return false; } - virtual bool singleton_p (tree * = NULL) const final override { return false; } - virtual bool zero_p () const final override { return false; } - virtual bool nonzero_p () const final override { return false; } - virtual void set (tree, tree, value_range_kind = VR_RANGE) final override {} - virtual tree type () const final override { return NULL; } - virtual bool union_ (const vrange &) final override { return false; } - virtual bool intersect (const vrange &) final override { return false; } - virtual tree lbound () const final override { return NULL; } - virtual tree ubound () const final override { return NULL; } - + prange (); + prange (const prange &); + prange (tree type); + prange (tree type, const wide_int &, const wide_int &, + value_range_kind = VR_RANGE); + static bool supports_p (const_tree type); + virtual bool supports_type_p (const_tree type) const final override; + virtual void accept (const vrange_visitor &v) const final override; + virtual void set_undefined () final override; + virtual void set_varying (tree type) final override; + virtual void set_nonzero (tree type) final override; + virtual void set_zero (tree type) final override; + virtual void set_nonnegative (tree type) final override; + virtual bool contains_p (tree cst) const final override; + virtual bool fits_p (const vrange &v) const final override; + virtual bool singleton_p (tree *result = NULL) const final override; + virtual bool zero_p () const final override; + virtual bool nonzero_p () const final override; + virtual void set (tree, tree, value_range_kind = VR_RANGE) final override; + virtual tree type () const final override; + virtual bool union_ (const vrange &v) final override; + virtual bool intersect (const vrange &v) final override; + virtual tree lbound () const final override; + virtual tree ubound () const final override; + + prange& operator= (const prange &); + bool operator== (const prange &) const; + void set (tree type, const wide_int &, const wide_int &, + value_range_kind = VR_RANGE); + void invert (); + bool contains_p (const wide_int &) const; wide_int lower_bound () const; wide_int upper_bound () const; + void verify_range () const; irange_bitmask get_bitmask () const final override; - void update_bitmask (const irange_bitmask &) final override {} -private: + void update_bitmask (const irange_bitmask &) final override; +protected: + bool varying_compatible_p () const; + + tree m_type; wide_int m_min; wide_int m_max; irange_bitmask m_bitmask; @@ -656,6 +675,13 @@ is_a (vrange &v) return v.m_discriminator == VR_IRANGE; } +template <> +inline bool +is_a (vrange &v) +{ + return v.m_discriminator == VR_PRANGE; +} + template <> inline bool is_a (vrange &v) @@ -708,6 +734,7 @@ class vrange_visitor { public: virtual void visit (const irange &) const { } + virtual void visit (const prange &) const { } virtual void visit (const frange &) const { } virtual void visit (const unsupported_range &) const { } }; @@ -775,6 +802,7 @@ private: vrange *m_vrange; // The buffer must be at least the size of the largest range. static_assert (sizeof (int_range_max) > sizeof (frange), ""); + static_assert (sizeof (int_range_max) > sizeof (prange), ""); char m_buffer[sizeof (int_range_max)]; }; @@ -850,6 +878,8 @@ Value_Range::init (tree type) if (irange::supports_p (type)) m_vrange = new (&m_buffer) int_range_max (); + else if (prange::supports_p (type)) + m_vrange = new (&m_buffer) prange (); else if (frange::supports_p (type)) m_vrange = new (&m_buffer) frange (); else @@ -863,6 +893,8 @@ Value_Range::init (const vrange &r) { if (is_a (r)) m_vrange = new (&m_buffer) int_range_max (as_a (r)); + else if (is_a (r)) + m_vrange = new (&m_buffer) prange (as_a (r)); else if (is_a (r)) m_vrange = new (&m_buffer) frange (as_a (r)); else @@ -920,7 +952,9 @@ Value_Range::operator const vrange &() const inline bool Value_Range::supports_type_p (const_tree type) { - return irange::supports_p (type) || frange::supports_p (type); + return irange::supports_p (type) + || prange::supports_p (type) + || frange::supports_p (type); } extern value_range_kind get_legacy_range (const vrange &, tree &min, tree &max); @@ -1220,32 +1254,151 @@ irange_val_max (const_tree type) return wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type)); } +inline +prange::prange () + : vrange (VR_PRANGE) +{ + set_undefined (); +} + +inline +prange::prange (const prange &r) + : vrange (VR_PRANGE) +{ + *this = r; +} + +inline +prange::prange (tree type) + : vrange (VR_PRANGE) +{ + set_varying (type); +} + +inline +prange::prange (tree type, const wide_int &lb, const wide_int &ub, + value_range_kind kind) + : vrange (VR_PRANGE) +{ + set (type, lb, ub, kind); +} + +inline bool +prange::supports_p (const_tree type) +{ + return POINTER_TYPE_P (type); +} + +inline bool +prange::supports_type_p (const_tree type) const +{ + return POINTER_TYPE_P (type); +} + +inline void +prange::set_undefined () +{ + m_kind = VR_UNDEFINED; +} + +inline void +prange::set_varying (tree type) +{ + m_kind = VR_VARYING; + m_type = type; + m_min = wi::zero (TYPE_PRECISION (type)); + m_max = wi::max_value (TYPE_PRECISION (type), UNSIGNED); + m_bitmask.set_unknown (TYPE_PRECISION (type)); + + if (flag_checking) + verify_range (); +} + +inline void +prange::set_nonzero (tree type) +{ + m_kind = VR_RANGE; + m_type = type; + m_min = wi::one (TYPE_PRECISION (type)); + m_max = wi::max_value (TYPE_PRECISION (type), UNSIGNED); + m_bitmask.set_unknown (TYPE_PRECISION (type)); + + if (flag_checking) + verify_range (); +} + inline void prange::set_zero (tree type) { + m_kind = VR_RANGE; + m_type = type; wide_int zero = wi::zero (TYPE_PRECISION (type)); m_min = m_max = zero; m_bitmask = irange_bitmask (zero, zero); + + if (flag_checking) + verify_range (); +} + +inline bool +prange::contains_p (tree cst) const +{ + return contains_p (wi::to_wide (cst)); +} + +inline bool +prange::zero_p () const +{ + return m_kind == VR_RANGE && m_min == 0 && m_max == 0; +} + +inline bool +prange::nonzero_p () const +{ + return m_kind == VR_RANGE && m_min == 1 && m_max == -1; +} + +inline tree +prange::type () const +{ + gcc_checking_assert (!undefined_p ()); + return m_type; } inline wide_int prange::lower_bound () const { + gcc_checking_assert (!undefined_p ()); return m_min; } inline wide_int prange::upper_bound () const { + gcc_checking_assert (!undefined_p ()); return m_max; } +inline bool +prange::varying_compatible_p () const +{ + return (!undefined_p () + && m_min == 0 && m_max == -1 && get_bitmask ().unknown_p ()); +} + inline irange_bitmask prange::get_bitmask () const { return m_bitmask; } +inline bool +prange::fits_p (const vrange &) const +{ + return true; +} + + inline frange::frange () : vrange (VR_FRANGE) From patchwork Sat May 4 08:30:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931232 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=LgVCQq/z; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgrJ1frPz1xnS for ; Sat, 4 May 2024 18:31:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0D0FE386F435 for ; Sat, 4 May 2024 08:31:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by sourceware.org (Postfix) with ESMTPS id 2B95738449C7 for ; Sat, 4 May 2024 08:31:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B95738449C7 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2B95738449C7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.139.111.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811465; cv=none; b=B3CMOm4bdq1QUIqEtBa4N8X3ezFsTliyfPzh3G25d2syFZiJmXx0dMWx9yXKhBVkdPeie4qfVYa2H0f29WMirthvObCjoUjk/kCtFb4t+a4PBuxq8KzSZzvAAuZWbseETwWvOihoc7oC/eOpCwFcyh6Z1KIQ9viYOy+MrWpOmgA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811465; c=relaxed/simple; bh=TZAV3kIHBw5U/ZS9hbud0h8gmguugcko72yTYBOVJi8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kwU4XoXscB2D4Ts7jEV2jZDn8rL3aGGDifBR0zD6BxXJaifv1st2FR/+WHV6P/jfMktl59XKA+Gg3eaa7KSnXuNfKgz0bVKAX2qMswQBQC6aCEE2rc+qjbSSknFdBwVn1J2uae+eXWWgZ3VNc8dt6pnKZXDnu4lmvRkLPmdqvxI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811462; 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=d2qDqecG5usnUmcmqNyM1/86hVhrF6SuCu4hXRSGD3c=; b=LgVCQq/zFZ98K7HtTqyc6vB5Axpiy/hCjt2U++yoVdyA04vosFecbFHU4H9ABQiZScRB3j GOJen9rMXDDF3FIkPigKwATVf7GKEQxu+gmoKFCDfA0vgdVTAn6Ee4/++9F2ytBUZN7Yfg rGwL2eGROl3Ag2e5V+OVcQufXWFWUTM= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-580-8-nKtlcBNoiDfkd6XNz4FA-1; Sat, 04 May 2024 04:31:00 -0400 X-MC-Unique: 8-nKtlcBNoiDfkd6XNz4FA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A799E3C000BE for ; Sat, 4 May 2024 08:31:00 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 62A82200E66B; Sat, 4 May 2024 08:31:00 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448Uxx2139796 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:30:59 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448Uxbh139795; Sat, 4 May 2024 10:30:59 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 03/23] Add streaming support for prange. Date: Sat, 4 May 2024 10:30:31 +0200 Message-ID: <20240504083056.139719-4-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * data-streamer-in.cc (streamer_read_value_range): Add prange support. * data-streamer-out.cc (streamer_write_vrange): Same. --- gcc/data-streamer-in.cc | 12 ++++++++++++ gcc/data-streamer-out.cc | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/gcc/data-streamer-in.cc b/gcc/data-streamer-in.cc index 3a0d3c6ad0f..12cb10e42c0 100644 --- a/gcc/data-streamer-in.cc +++ b/gcc/data-streamer-in.cc @@ -268,6 +268,18 @@ streamer_read_value_range (class lto_input_block *ib, data_in *data_in, } return; } + if (is_a (vr)) + { + prange &r = as_a (vr); + wide_int lb = streamer_read_wide_int (ib); + wide_int ub = streamer_read_wide_int (ib); + r.set (type, lb, ub); + wide_int value = streamer_read_wide_int (ib); + wide_int mask = streamer_read_wide_int (ib); + irange_bitmask bm (value, mask); + r.update_bitmask (bm); + return; + } gcc_unreachable (); } diff --git a/gcc/data-streamer-out.cc b/gcc/data-streamer-out.cc index 07cc6bd2018..c237e30f704 100644 --- a/gcc/data-streamer-out.cc +++ b/gcc/data-streamer-out.cc @@ -450,6 +450,16 @@ streamer_write_vrange (struct output_block *ob, const vrange &v) } return; } + if (is_a (v)) + { + const prange &r = as_a (v); + streamer_write_wide_int (ob, r.lower_bound ()); + streamer_write_wide_int (ob, r.upper_bound ()); + irange_bitmask bm = r.get_bitmask (); + streamer_write_wide_int (ob, bm.value ()); + streamer_write_wide_int (ob, bm.mask ()); + return; + } gcc_unreachable (); } From patchwork Sat May 4 08:30:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931234 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=C4ZfUIQj; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgrQ4K0tz1xnS for ; Sat, 4 May 2024 18:31:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C5DD6386F426 for ; Sat, 4 May 2024 08:31:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id 73ADD3844750 for ; Sat, 4 May 2024 08:31:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 73ADD3844750 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 73ADD3844750 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811465; cv=none; b=YYQvaeWoBHWxWFsP4twuDyENsSgeZsWT5Oz6xRWU4zfhLRPzEt/dF0sDcS84pWVp9pysDCMJeuoLOpO0VAXcfdJ6a/jjHOsbB9UORyRdE8qRatytIN6bkmiEpAcoB8vrn+5C8oaLjNmKNhKgOprbMuOPzUf0FNigO5DFkLF5lDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811465; c=relaxed/simple; bh=p45CWFJ5WyYjcdvU9SNEMdg4JOimEngi84CfozGhjLo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wBFQ7eijM4b0+sFZVFyGYulTqiEkrmi7P2ugMZD5EZswNLeCz4jL3A26TeC3gJcpqdUhyH7s2o43FmCSA5NWtOZeyoFBcz0X3cUu4rG98taiqnsav2nZgA15OC7Gb+dTxV2NI2Dn9QxOzRpLMjgY3sFrni4ZmrNNZWb/ZR+fI5k= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811463; 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=IjFJwgGiw+XZfj8Q1tTjHxUeHgq0lT8zvfqJja2QzDk=; b=C4ZfUIQj+tKL/BNfuiyaQ6hLbB/lBFyFqLCl2lqIoWbLNQGI/isiXIHun6ksARxZHKpKX/ Y/lw9I5iRStyErEerwltZ805Ksy+m/GBw1yor3lpnQnn5YotfKDlDwPJBG2z2G6VIH2mkH 8IQMXAoowsUbow+ZSaQ2CRW5OzFW8+U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-489-V8m3E8atP_eShtcmkkz2hQ-1; Sat, 04 May 2024 04:31:01 -0400 X-MC-Unique: V8m3E8atP_eShtcmkkz2hQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EAF1E834FB1 for ; Sat, 4 May 2024 08:31:00 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A2FA3C13FA1; Sat, 4 May 2024 08:31:00 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448Uxq6139800 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:30:59 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448UxP0139799; Sat, 4 May 2024 10:30:59 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 04/23] Add storage support for prange. Date: Sat, 4 May 2024 10:30:32 +0200 Message-ID: <20240504083056.139719-5-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * value-range-storage.cc (vrange_allocator::clone_varying): Add prange support. (vrange_allocator::clone_undefined): Same. (vrange_storage::alloc): Same. (vrange_storage::set_vrange): Same. (vrange_storage::get_vrange): Same. (vrange_storage::fits_p): Same. (vrange_storage::equal_p): Same. (prange_storage::alloc): New. (prange_storage::prange_storage): New. (prange_storage::set_prange): New. (prange_storage::get_prange): New. (prange_storage::equal_p): New. (prange_storage::fits_p): New. * value-range-storage.h (class prange_storage): Add prange support. --- gcc/value-range-storage.cc | 117 +++++++++++++++++++++++++++++++++++++ gcc/value-range-storage.h | 33 +++++++++++ 2 files changed, 150 insertions(+) diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc index 09a29776a0e..bbae0da4772 100644 --- a/gcc/value-range-storage.cc +++ b/gcc/value-range-storage.cc @@ -118,6 +118,8 @@ vrange_allocator::clone_varying (tree type) { if (irange::supports_p (type)) return irange_storage::alloc (*m_alloc, int_range <1> (type)); + if (prange::supports_p (type)) + return prange_storage::alloc (*m_alloc, prange (type)); if (frange::supports_p (type)) return frange_storage::alloc (*m_alloc, frange (type)); return NULL; @@ -128,6 +130,8 @@ vrange_allocator::clone_undefined (tree type) { if (irange::supports_p (type)) return irange_storage::alloc (*m_alloc, int_range<1> ()); + if (prange::supports_p (type)) + return prange_storage::alloc (*m_alloc, prange ()); if (frange::supports_p (type)) return frange_storage::alloc (*m_alloc, frange ()); return NULL; @@ -141,6 +145,8 @@ vrange_storage::alloc (vrange_internal_alloc &allocator, const vrange &r) { if (is_a (r)) return irange_storage::alloc (allocator, as_a (r)); + if (is_a (r)) + return prange_storage::alloc (allocator, as_a (r)); if (is_a (r)) return frange_storage::alloc (allocator, as_a (r)); return NULL; @@ -157,6 +163,12 @@ vrange_storage::set_vrange (const vrange &r) gcc_checking_assert (s->fits_p (as_a (r))); s->set_irange (as_a (r)); } + else if (is_a (r)) + { + prange_storage *s = static_cast (this); + gcc_checking_assert (s->fits_p (as_a (r))); + s->set_prange (as_a (r)); + } else if (is_a (r)) { frange_storage *s = static_cast (this); @@ -190,6 +202,11 @@ vrange_storage::get_vrange (vrange &r, tree type) const const irange_storage *s = static_cast (this); s->get_irange (as_a (r), type); } + else if (is_a (r)) + { + const prange_storage *s = static_cast (this); + s->get_prange (as_a (r), type); + } else if (is_a (r)) { const frange_storage *s = static_cast (this); @@ -209,6 +226,11 @@ vrange_storage::fits_p (const vrange &r) const const irange_storage *s = static_cast (this); return s->fits_p (as_a (r)); } + if (is_a (r)) + { + const prange_storage *s = static_cast (this); + return s->fits_p (as_a (r)); + } if (is_a (r)) { const frange_storage *s = static_cast (this); @@ -230,6 +252,11 @@ vrange_storage::equal_p (const vrange &r) const const irange_storage *s = static_cast (this); return s->equal_p (as_a (r)); } + if (is_a (r)) + { + const prange_storage *s = static_cast (this); + return s->equal_p (as_a (r)); + } if (is_a (r)) { const frange_storage *s = static_cast (this); @@ -559,6 +586,96 @@ frange_storage::fits_p (const frange &) const return true; } +//============================================================================ +// prange_storage implementation +//============================================================================ + +prange_storage * +prange_storage::alloc (vrange_internal_alloc &allocator, const prange &r) +{ + // Assume all pointers are the same size. + unsigned prec = TYPE_PRECISION (TREE_TYPE (null_pointer_node)); + gcc_checking_assert (r.undefined_p () || TYPE_PRECISION (r.type ()) == prec); + + typedef trailing_wide_ints twi; + size_t size = sizeof (prange_storage) + twi::extra_size (prec); + prange_storage *p = static_cast (allocator.alloc (size)); + new (p) prange_storage (r); + return p; +} + +// Initialize the storage with R. + +prange_storage::prange_storage (const prange &r) +{ + // It is the caller's responsibility to allocate enough space such + // that the precision fits. + unsigned prec = TYPE_PRECISION (TREE_TYPE (null_pointer_node)); + m_trailing_ints.set_precision (prec); + + set_prange (r); +} + +void +prange_storage::set_prange (const prange &r) +{ + if (r.undefined_p ()) + m_kind = VR_UNDEFINED; + else if (r.varying_p ()) + m_kind = VR_VARYING; + else + { + m_kind = VR_RANGE; + set_low (r.lower_bound ()); + set_high (r.upper_bound ()); + irange_bitmask bm = r.m_bitmask; + set_value (bm.value ()); + set_mask (bm.mask ()); + } +} + +void +prange_storage::get_prange (prange &r, tree type) const +{ + gcc_checking_assert (r.supports_type_p (type)); + + if (m_kind == VR_UNDEFINED) + r.set_undefined (); + else if (m_kind == VR_VARYING) + r.set_varying (type); + else + { + gcc_checking_assert (m_kind == VR_RANGE); + gcc_checking_assert (TYPE_PRECISION (type) == m_trailing_ints.get_precision ()); + r.m_kind = VR_RANGE; + r.m_type = type; + r.m_min = get_low (); + r.m_max = get_high (); + r.m_bitmask = irange_bitmask (get_value (), get_mask ()); + if (flag_checking) + r.verify_range (); + } +} + +bool +prange_storage::equal_p (const prange &r) const +{ + if (r.undefined_p ()) + return m_kind == VR_UNDEFINED; + + prange tmp; + get_prange (tmp, r.type ()); + return tmp == r; +} + +bool +prange_storage::fits_p (const prange &) const +{ + // All pointers are the same size. + return true; +} + + static vrange_allocator ggc_vrange_allocator (true); vrange_storage *ggc_alloc_vrange_storage (tree type) diff --git a/gcc/value-range-storage.h b/gcc/value-range-storage.h index 5756de7e32d..dd6813873ea 100644 --- a/gcc/value-range-storage.h +++ b/gcc/value-range-storage.h @@ -98,6 +98,39 @@ private: irange_storage (const irange &r); }; +// Efficient memory storage for a prange. + +class prange_storage : public vrange_storage +{ +public: + static prange_storage *alloc (vrange_internal_alloc &, const prange &); + void set_prange (const prange &r); + void get_prange (prange &r, tree type) const; + bool equal_p (const prange &r) const; + bool fits_p (const prange &r) const; + void dump () const; +private: + DISABLE_COPY_AND_ASSIGN (prange_storage); + prange_storage (const prange &r); + + enum value_range_kind m_kind : 3; + + // We don't use TRAILING_WIDE_INT_ACCESSOR because the getters here + // must be const. Perhaps TRAILING_WIDE_INT_ACCESSOR could be made + // const and return wide_int instead of trailing_wide_int. + wide_int get_low () const { return m_trailing_ints[0]; } + wide_int get_high () const { return m_trailing_ints[1]; } + wide_int get_value () const { return m_trailing_ints[2]; } + wide_int get_mask () const { return m_trailing_ints[3]; } + template void set_low (const T &x) { m_trailing_ints[0] = x; } + template void set_high (const T &x) { m_trailing_ints[1] = x; } + template void set_value (const T &x) { m_trailing_ints[2] = x; } + template void set_mask (const T &x) { m_trailing_ints[3] = x; } + + static const unsigned int NINTS = 4; + trailing_wide_ints m_trailing_ints; +}; + // Efficient memory storage for an frange. class frange_storage : public vrange_storage From patchwork Sat May 4 08:30:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SZZ7u3hf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgt06DX5z23tp for ; Sat, 4 May 2024 18:33:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0B196386F441 for ; Sat, 4 May 2024 08:33:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by sourceware.org (Postfix) with ESMTPS id 4CF033844767 for ; Sat, 4 May 2024 08:31:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4CF033844767 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4CF033844767 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.139.111.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811469; cv=none; b=pOK2+nevAIe5DiNLGfngCoJrDN7x0Azxr7xUk4kMVJUJiEbyInKziV8PEEfmcZpvG9l6AtHVd0eUcWU+PV6nKR6r2O+ZxkCZwACxhmUGY2FkNLdMxwvZ49Vw9RMwvmf4HJ2XdSph+l8w+5XoP2hhHsLiTZ73T3lHir6mSpb0/jg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811469; c=relaxed/simple; bh=3zTCQBPLKV+iHNlEDvHLIF7AYUDrFQq+Ip9+3V08loc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=f26uNJQwcqV9uTuDfgQ8fgqRHynoa3u4VCrhiOSvwsohscfRoZi2/wQUge7+Tli77QjCnwjj57pfMLVGte11TvEQNaEcpg4g7u/0JEcOiGca9XebTWEW1iRLsJxG2n7QHZg+Z5sUYks4P3wnI6ERoQG5gm5rmuSImLUnWlPY9Tg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811463; 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=yT2nt9SALAKQa9q3/CTXDXQ/Fs9vZQvzlbjNtrJCIw0=; b=SZZ7u3hfp/4rKYlMFsdgG3MKzAbjMQt8Zv0nHwWkSScs3zJtcYEB/gunZeUFQd2VMVtSex JvqNIsBap3T54fUQH9nlOg+ZpYcg1YIO0IZN03qmvrDcEPEyQOC9F18x1eeOH/h14CLZ+c dOieX5aUQG0ifXn/bPnDnKbn7GgXr1c= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-632-9w14QyV5NFiDnd-YhySdhw-1; Sat, 04 May 2024 04:31:01 -0400 X-MC-Unique: 9w14QyV5NFiDnd-YhySdhw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 24E261011351 for ; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C30C7492BC6; Sat, 4 May 2024 08:31:00 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448Uxaj139804 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:30:59 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448UxNK139803; Sat, 4 May 2024 10:30:59 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 05/23] Add hashing support for prange. Date: Sat, 4 May 2024 10:30:33 +0200 Message-ID: <20240504083056.139719-6-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * value-range.cc (add_vrange): Add prange support. --- gcc/value-range.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 84113ccfbd0..62170a438bf 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -346,6 +346,22 @@ add_vrange (const vrange &v, inchash::hash &hstate, hstate.add_wide_int (bm.mask ()); return; } + if (is_a (v)) + { + const prange &r = as_a (v); + if (r.varying_p ()) + hstate.add_int (VR_VARYING); + else + { + hstate.add_int (VR_RANGE); + hstate.add_wide_int (r.lower_bound ()); + hstate.add_wide_int (r.upper_bound ()); + irange_bitmask bm = r.get_bitmask (); + hstate.add_wide_int (bm.value ()); + hstate.add_wide_int (bm.mask ()); + } + return; + } if (is_a (v)) { const frange &r = as_a (v); From patchwork Sat May 4 08:30:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931245 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dhMuEboD; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgvt0xpYz1xnS for ; Sat, 4 May 2024 18:34:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5FF87386F43B for ; Sat, 4 May 2024 08:34:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id 910263844073 for ; Sat, 4 May 2024 08:31:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 910263844073 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 910263844073 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811477; cv=none; b=rxzikeF5ATnqvLApVyzzKEgFwuRqe/D7aeY9N2conOIN4twQFLriwzh2ft2X/NSeDJ6rwam+iaKffWB9yVezipM4YTBAlStZJIrrmelYuIhsJroaMlc3IE/0V4T/punzJxRqWsewhn/o54vADxI6XX4Ud29al2k+aL5gz4pRq8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811477; c=relaxed/simple; bh=IZ5U1+XAKIMHm/Ntt2dq7mTYJUWPvyWUljjW+Y7As2g=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=W/liiF7D7dZ8Cm89iE8IudFymjuL8oXmNibmBijxnrqlQS2w1otNiSnvRYC4gaWy3g5W6GuJ7jtMVIjGsd0zfKJTnJtSF8o3S88NXHlo7kRxv2uubn/aVw1mGz/zh2ArmEfAt+hsM9Yt9D/2YQQ4/UVYvL25wdz7unbezakaFXY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811465; 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=03+mfPUS/IKtFUJo3B9fl13ZJdAS1hguDQgTasgvfzI=; b=dhMuEboDnB6/nfEgplQyRu2rz9DGpNJfI1WEPUxUVlc7/KXyayuO/Km8fwpKcajZBVNDV9 AI9RHEX++qR4njUfN2Oh1tdnJYtyb89kNbx5Y6Xgf5PAjNiWP2O6ZukX7ymbmTPYiEkk+f Te8lb7hs3zREk4qtFud3SnhNyt5S8sU= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-37-IneKZV3ANPSISjEs50eh2Q-1; Sat, 04 May 2024 04:31:01 -0400 X-MC-Unique: IneKZV3ANPSISjEs50eh2Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 389CC3C1014E for ; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E57DA1121312; Sat, 4 May 2024 08:31:00 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448UxXi139808 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:30:59 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448UxVm139807; Sat, 4 May 2024 10:30:59 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 06/23] Add prange implementation for get_legacy_range. Date: Sat, 4 May 2024 10:30:34 +0200 Message-ID: <20240504083056.139719-7-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * value-range.cc (get_legacy_range): New version for prange. --- gcc/value-range.cc | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 62170a438bf..3e1ecf69517 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -1377,6 +1377,38 @@ get_legacy_range (const irange &r, tree &min, tree &max) return VR_RANGE; } +static value_range_kind +get_legacy_range (const prange &r, tree &min, tree &max) +{ + if (r.undefined_p ()) + { + min = NULL_TREE; + max = NULL_TREE; + return VR_UNDEFINED; + } + + tree type = r.type (); + if (r.varying_p ()) + { + min = r.lbound (); + max = r.ubound (); + return VR_VARYING; + } + if (r.zero_p ()) + { + min = max = r.lbound (); + return VR_RANGE; + } + if (r.nonzero_p ()) + { + min = max = build_zero_cst (type); + return VR_ANTI_RANGE; + } + min = r.lbound (); + max = r.ubound (); + return VR_RANGE; +} + // Given a range in V, return an old-style legacy range consisting of // a value_range_kind with a MIN/MAX. This is to maintain // compatibility with passes that still depend on VR_ANTI_RANGE, and @@ -1388,8 +1420,7 @@ get_legacy_range (const vrange &v, tree &min, tree &max) if (is_a (v)) return get_legacy_range (as_a (v), min, max); - gcc_unreachable (); - return VR_UNDEFINED; + return get_legacy_range (as_a (v), min, max); } /* Set value range to the canonical form of {VRTYPE, MIN, MAX, EQUIV}. From patchwork Sat May 4 08:30:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931236 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TQ1W1+Ti; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgs92bFrz1xnS for ; Sat, 4 May 2024 18:32:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C0D5386F460 for ; Sat, 4 May 2024 08:32:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by sourceware.org (Postfix) with ESMTPS id 136C13844764 for ; Sat, 4 May 2024 08:31:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 136C13844764 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 136C13844764 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.139.111.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811470; cv=none; b=dytFWcD6td1pw2/ak8IJx4hLCVEGWsvAG2v0k7zUPpWYXVUqM1FnxYCDdxiVQeyojx47yiMPLjvKw+XoyXGmBufDrZsQINqDcdn1wswo5WJOdvIPVGMTHbR/LpyLPpR6xGqZJzOc1+Ny6QQBfHCmTwklZLzIWOSenz3raV4mWfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811470; c=relaxed/simple; bh=MJqgz+USqRDrtCS4wjWR7bbDGh9PgRGUPfjX9H4jjf0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=IKQsb4hRJDQVVeIClczYe6q96I7WI6FoZvFkQzVywec7jqbMyoJTDo2yhNrdPGgMo9RRMbkm8TYxZzCegpa2UmayC6ZdndtxqbIrfISEj9VsmISQg2ydtOLodi/OmWUY1kP11WRbs9S4/9OEgH6xqeWPRsqn7KKhxECdGfHh0g8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811463; 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=AJYnIrxFNHK+0ixt3sDHTrOkd5oM9bhfkj+M3RN8CMQ=; b=TQ1W1+TiyvYiNQPtIIIfCoqCe9dDa8aJtyOGANClH0aqDhRzmirSJ8hlojirOrRk5kX3GA iXTlCxL7UnPvUAfBIThrSzqVTflF+seV/Tk0gwV1J7lNbPvGaPmxRIzbUUW5bRxnd20L3p 8hzRLYW03kACG5ai4EBd0wWn7aCuwCo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-_GQG1CrlPfOp8KW_At0YSQ-1; Sat, 04 May 2024 04:31:01 -0400 X-MC-Unique: _GQG1CrlPfOp8KW_At0YSQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9E6748001B2 for ; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 102BAEC682; Sat, 4 May 2024 08:31:00 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448Uxrp139812 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:30:59 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448UxRn139811; Sat, 4 May 2024 10:30:59 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 07/23] Implement range-op dispatch for prange. Date: Sat, 4 May 2024 10:30:35 +0200 Message-ID: <20240504083056.139719-8-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch adds the range-op dispatch code for prange, and adds some temporary sanity checks (for flag_checking only) to make sure we handle all the pointer/integer variants. In order to make sure I got all the combinations right, I started with a clean slate, trapping on all pointer operands. Then I added support for each one piecemeal. To verify the work, I added a pointers_handled_p() helper that is implemented for each range-op entry and returns TRUE iff the operator can handle a given combination of pointers. If this helper returns false, we will trap, because it indicates an operator that was not implemented. This is temporary checking code, and I will rip it out once the the dust has settled in a few days. gcc/ChangeLog: * range-op-mixed.h: Add using declarator for all classes. * range-op-ptr.cc (range_operator::pointers_handled_p): New. (range_operator::fold_range): New. (range_operator::op1_op2_relation_effect): New. (range_operator::op1_range): New. (range_operator::op2_range): New. (range_operator::op1_op2_relation): New. (range_operator::lhs_op1_relation): New. (range_operator::update_bitmask): New. (class pointer_plus_operator): New. (class operator_pointer_diff): New. (class hybrid_min_operator): New. (class hybrid_max_operator): New. * range-op.cc: Add RO_PPP, RO_PPI, RO_IPP, RO_IPI, RO_PIP, RO_PII. (range_op_handler::discriminator_fail): New. (has_pointer_operand_p): New. (range_op_handler::fold_range): Add pointer support. (range_op_handler::op1_range): Same. (range_op_handler::op2_range): Same. (range_op_handler::lhs_op1_relation): Same. (range_op_handler::lhs_op2_relation): Same. (range_op_handler::op1_op2_relation): Same. (class operator_div): Add using. (class operator_lshift): Add using. (class operator_rshift):Add using. (class operator_trunc_mod):Add using. (class operator_absu):Add using. * range-op.h (enum range_op_dispatch_type): New. Add extern definitions for RO_*. --- gcc/range-op-mixed.h | 19 ++++ gcc/range-op-ptr.cc | 220 +++++++++++++++++++++++++++++++++++++++++++ gcc/range-op.cc | 124 ++++++++++++++++++++++++ gcc/range-op.h | 111 ++++++++++++++++++++++ 4 files changed, 474 insertions(+) diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index 3ee7c9d6e0d..8163a4b53ca 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -111,6 +111,7 @@ public: using range_operator::op1_range; using range_operator::op2_range; using range_operator::op1_op2_relation; + using range_operator::update_bitmask; bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio = TRIO_VARYING) const final override; @@ -150,6 +151,7 @@ public: using range_operator::op1_range; using range_operator::op2_range; using range_operator::op1_op2_relation; + using range_operator::update_bitmask; bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio = TRIO_VARYING) const final override; @@ -189,6 +191,7 @@ public: using range_operator::op1_range; using range_operator::op2_range; using range_operator::op1_op2_relation; + using range_operator::update_bitmask; bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio = TRIO_VARYING) const final override; @@ -225,6 +228,7 @@ public: using range_operator::op1_range; using range_operator::op2_range; using range_operator::op1_op2_relation; + using range_operator::update_bitmask; bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio = TRIO_VARYING) const final override; @@ -264,6 +268,7 @@ public: using range_operator::op1_range; using range_operator::op2_range; using range_operator::op1_op2_relation; + using range_operator::update_bitmask; bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio = TRIO_VARYING) const final override; @@ -302,6 +307,7 @@ public: using range_operator::op1_range; using range_operator::op2_range; using range_operator::op1_op2_relation; + using range_operator::update_bitmask; bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio = TRIO_VARYING) const final override; @@ -376,6 +382,7 @@ public: using range_operator::fold_range; using range_operator::op1_range; using range_operator::lhs_op1_relation; + using range_operator::update_bitmask; bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio rel = TRIO_VARYING) const final override; @@ -402,6 +409,7 @@ public: using range_operator::op2_range; using range_operator::lhs_op1_relation; using range_operator::lhs_op2_relation; + using range_operator::update_bitmask; bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio) const final override; @@ -445,6 +453,7 @@ class operator_abs : public range_operator public: using range_operator::fold_range; using range_operator::op1_range; + using range_operator::update_bitmask; bool fold_range (frange &r, tree type, const frange &op1, const frange &, relation_trio = TRIO_VARYING) const final override; @@ -473,6 +482,8 @@ public: using range_operator::op1_range; using range_operator::op2_range; using range_operator::lhs_op1_relation; + using range_operator::op1_op2_relation_effect; + using range_operator::update_bitmask; bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio) const final override; @@ -556,6 +567,7 @@ class operator_mult : public cross_product_operator public: using range_operator::op1_range; using range_operator::op2_range; + using range_operator::update_bitmask; bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio) const final override; @@ -608,6 +620,7 @@ class operator_bitwise_not : public range_operator public: using range_operator::fold_range; using range_operator::op1_range; + using range_operator::update_bitmask; bool fold_range (irange &r, tree type, const irange &lh, const irange &rh, relation_trio rel = TRIO_VARYING) const final override; @@ -626,6 +639,8 @@ class operator_bitwise_xor : public range_operator public: using range_operator::op1_range; using range_operator::op2_range; + using range_operator::op1_op2_relation_effect; + using range_operator::update_bitmask; bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio rel = TRIO_VARYING) const final override; @@ -654,6 +669,7 @@ public: using range_operator::op1_range; using range_operator::op2_range; using range_operator::lhs_op1_relation; + using range_operator::update_bitmask; bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio rel = TRIO_VARYING) const override; @@ -682,6 +698,7 @@ class operator_bitwise_or : public range_operator public: using range_operator::op1_range; using range_operator::op2_range; + using range_operator::update_bitmask; bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio rel = TRIO_VARYING) const override; @@ -702,6 +719,7 @@ protected: class operator_min : public range_operator { public: + using range_operator::update_bitmask; void update_bitmask (irange &r, const irange &lh, const irange &rh) const override; // Check compatibility of all operands. @@ -716,6 +734,7 @@ protected: class operator_max : public range_operator { public: + using range_operator::update_bitmask; void update_bitmask (irange &r, const irange &lh, const irange &rh) const override; // Check compatibility of all operands. diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index 7343ef635f3..560c798b90a 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -49,8 +49,222 @@ along with GCC; see the file COPYING3. If not see #include "tree-ssa-ccp.h" #include "range-op-mixed.h" +// Return TRUE if a range-op folder TYPE either handles or can safely +// ignore the dispatch pattern in DISPATCH. Return FALSE for any +// combination not handled, which will result in a hard fail up the +// chain. + +bool +range_operator::pointers_handled_p (range_op_dispatch_type ATTRIBUTE_UNUSED, + unsigned dispatch ATTRIBUTE_UNUSED) const +{ + return false; +} + +bool +range_operator::fold_range (prange &r, tree type, + const prange &op1, + const prange &op2, + relation_trio trio) const +{ + relation_kind rel = trio.op1_op2 (); + r.set_varying (type); + op1_op2_relation_effect (r, type, op1, op2, rel); + return true; +} + +bool +range_operator::fold_range (prange &r, tree type, + const prange &op1, + const irange &op2, + relation_trio trio) const +{ + relation_kind rel = trio.op1_op2 (); + r.set_varying (type); + op1_op2_relation_effect (r, type, op1, op2, rel); + return true; +} + +bool +range_operator::fold_range (irange &r, tree type, + const prange &op1, + const prange &op2, + relation_trio trio) const +{ + relation_kind rel = trio.op1_op2 (); + r.set_varying (type); + op1_op2_relation_effect (r, type, op1, op2, rel); + return true; +} + +bool +range_operator::fold_range (prange &r, tree type, + const irange &op1, + const prange &op2, + relation_trio trio) const +{ + relation_kind rel = trio.op1_op2 (); + r.set_varying (type); + op1_op2_relation_effect (r, type, op1, op2, rel); + return true; +} + +bool +range_operator::fold_range (irange &r, tree type, + const prange &op1, + const irange &op2, + relation_trio trio) const +{ + relation_kind rel = trio.op1_op2 (); + r.set_varying (type); + op1_op2_relation_effect (r, type, op1, op2, rel); + return true; +} + +bool +range_operator::op1_op2_relation_effect (prange &, tree, + const prange &, + const prange &, + relation_kind) const +{ + return false; +} + +bool +range_operator::op1_op2_relation_effect (prange &, tree, + const prange &, + const irange &, + relation_kind) const +{ + return false; +} + +bool +range_operator::op1_op2_relation_effect (irange &, tree, + const prange &, + const prange &, + relation_kind) const +{ + return false; +} + +bool +range_operator::op1_op2_relation_effect (prange &, tree, + const irange &, + const prange &, + relation_kind) const +{ + return false; +} + +bool +range_operator::op1_op2_relation_effect (irange &, tree, + const prange &, + const irange &, + relation_kind) const +{ + return false; +} + +bool +range_operator::op1_range (prange &, tree, + const prange &lhs ATTRIBUTE_UNUSED, + const prange &op2 ATTRIBUTE_UNUSED, + relation_trio) const +{ + return false; +} + +bool +range_operator::op1_range (prange &, tree, + const irange &lhs ATTRIBUTE_UNUSED, + const prange &op2 ATTRIBUTE_UNUSED, + relation_trio) const +{ + return false; +} + +bool +range_operator::op1_range (prange &, tree, + const prange &lhs ATTRIBUTE_UNUSED, + const irange &op2 ATTRIBUTE_UNUSED, + relation_trio) const +{ + return false; +} + +bool +range_operator::op1_range (irange &, tree, + const prange &lhs ATTRIBUTE_UNUSED, + const irange &op2 ATTRIBUTE_UNUSED, + relation_trio) const +{ + return false; +} + +bool +range_operator::op2_range (prange &, tree, + const irange &lhs ATTRIBUTE_UNUSED, + const prange &op1 ATTRIBUTE_UNUSED, + relation_trio) const +{ + return false; +} + +bool +range_operator::op2_range (irange &, tree, + const prange &lhs ATTRIBUTE_UNUSED, + const prange &op1 ATTRIBUTE_UNUSED, + relation_trio) const +{ + return false; +} + +relation_kind +range_operator::op1_op2_relation (const irange &lhs ATTRIBUTE_UNUSED, + const prange &op1 ATTRIBUTE_UNUSED, + const prange &op2 ATTRIBUTE_UNUSED) const +{ + return VREL_VARYING; +} + +relation_kind +range_operator::lhs_op1_relation (const prange &lhs ATTRIBUTE_UNUSED, + const irange &op1 ATTRIBUTE_UNUSED, + const irange &op2 ATTRIBUTE_UNUSED, + relation_kind rel ATTRIBUTE_UNUSED) const +{ + return VREL_VARYING; +} + +relation_kind +range_operator::lhs_op1_relation (const irange &lhs ATTRIBUTE_UNUSED, + const prange &op1 ATTRIBUTE_UNUSED, + const prange &op2 ATTRIBUTE_UNUSED, + relation_kind rel ATTRIBUTE_UNUSED) const +{ + return VREL_VARYING; +} + +relation_kind +range_operator::lhs_op1_relation (const prange &lhs ATTRIBUTE_UNUSED, + const prange &op1 ATTRIBUTE_UNUSED, + const prange &op2 ATTRIBUTE_UNUSED, + relation_kind rel ATTRIBUTE_UNUSED) const +{ + return VREL_VARYING; +} + +void +range_operator::update_bitmask (irange &, + const prange &, + const prange &) const +{ +} + class pointer_plus_operator : public range_operator { + using range_operator::update_bitmask; using range_operator::op2_range; public: virtual void wi_fold (irange &r, tree type, @@ -245,6 +459,8 @@ pointer_or_operator::wi_fold (irange &r, tree type, class operator_pointer_diff : public range_operator { + using range_operator::update_bitmask; + using range_operator::op1_op2_relation_effect; virtual bool op1_op2_relation_effect (irange &lhs_range, tree type, const irange &op1_range, @@ -274,6 +490,7 @@ operator_pointer_diff::op1_op2_relation_effect (irange &lhs_range, tree type, class hybrid_and_operator : public operator_bitwise_and { public: + using range_operator::update_bitmask; using range_operator::op1_range; using range_operator::op2_range; using range_operator::lhs_op1_relation; @@ -330,6 +547,7 @@ public: class hybrid_or_operator : public operator_bitwise_or { public: + using range_operator::update_bitmask; using range_operator::op1_range; using range_operator::op2_range; using range_operator::lhs_op1_relation; @@ -376,6 +594,7 @@ public: class hybrid_min_operator : public operator_min { + using range_operator::update_bitmask; public: void update_bitmask (irange &r, const irange &lh, const irange &rh) const final override @@ -397,6 +616,7 @@ public: class hybrid_max_operator : public operator_max { + using range_operator::update_bitmask; public: void update_bitmask (irange &r, const irange &lh, const irange &rh) const final override diff --git a/gcc/range-op.cc b/gcc/range-op.cc index ab3a4f0b200..65f3843227d 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -181,6 +181,12 @@ const unsigned RO_IFF = dispatch_trio (VR_IRANGE, VR_FRANGE, VR_FRANGE); const unsigned RO_FFF = dispatch_trio (VR_FRANGE, VR_FRANGE, VR_FRANGE); const unsigned RO_FIF = dispatch_trio (VR_FRANGE, VR_IRANGE, VR_FRANGE); const unsigned RO_FII = dispatch_trio (VR_FRANGE, VR_IRANGE, VR_IRANGE); +const unsigned RO_PPP = dispatch_trio (VR_PRANGE, VR_PRANGE, VR_PRANGE); +const unsigned RO_PPI = dispatch_trio (VR_PRANGE, VR_PRANGE, VR_IRANGE); +const unsigned RO_IPP = dispatch_trio (VR_IRANGE, VR_PRANGE, VR_PRANGE); +const unsigned RO_IPI = dispatch_trio (VR_IRANGE, VR_PRANGE, VR_IRANGE); +const unsigned RO_PIP = dispatch_trio (VR_PRANGE, VR_IRANGE, VR_PRANGE); +const unsigned RO_PII = dispatch_trio (VR_PRANGE, VR_IRANGE, VR_IRANGE); // Return a dispatch value for parameter types LHS, OP1 and OP2. @@ -192,6 +198,28 @@ range_op_handler::dispatch_kind (const vrange &lhs, const vrange &op1, op2.m_discriminator); } +void +range_op_handler::discriminator_fail (const vrange &r1, + const vrange &r2, + const vrange &r3) const +{ + const char name[] = "IPF"; + gcc_checking_assert (r1.m_discriminator < sizeof (name) - 1); + gcc_checking_assert (r2.m_discriminator < sizeof (name) - 1); + gcc_checking_assert (r3.m_discriminator < sizeof (name) - 1); + fprintf (stderr, "DISCRIMINATOR FAIL. Dispatch ====> RO_%c%c%c <====\n", + name[r1.m_discriminator], + name[r2.m_discriminator], + name[r3.m_discriminator]); + gcc_unreachable (); +} + +static inline bool +has_pointer_operand_p (const vrange &r1, const vrange &r2, const vrange &r3) +{ + return is_a (r1) || is_a (r2) || is_a (r3); +} + // Dispatch a call to fold_range based on the types of R, LH and RH. bool @@ -204,6 +232,10 @@ range_op_handler::fold_range (vrange &r, tree type, #if CHECKING_P if (!lh.undefined_p () && !rh.undefined_p ()) gcc_assert (m_operator->operand_check_p (type, lh.type (), rh.type ())); + if (has_pointer_operand_p (r, lh, rh) + && !m_operator->pointers_handled_p (DISPATCH_FOLD_RANGE, + dispatch_kind (r, lh, rh))) + discriminator_fail (r, lh, rh); #endif switch (dispatch_kind (r, lh, rh)) { @@ -227,6 +259,26 @@ range_op_handler::fold_range (vrange &r, tree type, return m_operator->fold_range (as_a (r), type, as_a (lh), as_a (rh), rel); + case RO_PPP: + return m_operator->fold_range (as_a (r), type, + as_a (lh), + as_a (rh), rel); + case RO_PPI: + return m_operator->fold_range (as_a (r), type, + as_a (lh), + as_a (rh), rel); + case RO_IPP: + return m_operator->fold_range (as_a (r), type, + as_a (lh), + as_a (rh), rel); + case RO_PIP: + return m_operator->fold_range (as_a (r), type, + as_a (lh), + as_a (rh), rel); + case RO_IPI: + return m_operator->fold_range (as_a (r), type, + as_a (lh), + as_a (rh), rel); default: return false; } @@ -246,6 +298,10 @@ range_op_handler::op1_range (vrange &r, tree type, #if CHECKING_P if (!op2.undefined_p ()) gcc_assert (m_operator->operand_check_p (lhs.type (), type, op2.type ())); + if (has_pointer_operand_p (r, lhs, op2) + && !m_operator->pointers_handled_p (DISPATCH_OP1_RANGE, + dispatch_kind (r, lhs, op2))) + discriminator_fail (r, lhs, op2); #endif switch (dispatch_kind (r, lhs, op2)) { @@ -253,6 +309,22 @@ range_op_handler::op1_range (vrange &r, tree type, return m_operator->op1_range (as_a (r), type, as_a (lhs), as_a (op2), rel); + case RO_PPP: + return m_operator->op1_range (as_a (r), type, + as_a (lhs), + as_a (op2), rel); + case RO_PIP: + return m_operator->op1_range (as_a (r), type, + as_a (lhs), + as_a (op2), rel); + case RO_PPI: + return m_operator->op1_range (as_a (r), type, + as_a (lhs), + as_a (op2), rel); + case RO_IPI: + return m_operator->op1_range (as_a (r), type, + as_a (lhs), + as_a (op2), rel); case RO_FIF: return m_operator->op1_range (as_a (r), type, as_a (lhs), @@ -280,6 +352,10 @@ range_op_handler::op2_range (vrange &r, tree type, #if CHECKING_P if (!op1.undefined_p ()) gcc_assert (m_operator->operand_check_p (lhs.type (), op1.type (), type)); + if (has_pointer_operand_p (r, lhs, op1) + && !m_operator->pointers_handled_p (DISPATCH_OP2_RANGE, + dispatch_kind (r, lhs, op1))) + discriminator_fail (r, lhs, op1); #endif switch (dispatch_kind (r, lhs, op1)) { @@ -287,6 +363,14 @@ range_op_handler::op2_range (vrange &r, tree type, return m_operator->op2_range (as_a (r), type, as_a (lhs), as_a (op1), rel); + case RO_PIP: + return m_operator->op2_range (as_a (r), type, + as_a (lhs), + as_a (op1), rel); + case RO_IPP: + return m_operator->op2_range (as_a (r), type, + as_a (lhs), + as_a (op1), rel); case RO_FIF: return m_operator->op2_range (as_a (r), type, as_a (lhs), @@ -309,6 +393,12 @@ range_op_handler::lhs_op1_relation (const vrange &lhs, relation_kind rel) const { gcc_checking_assert (m_operator); +#if CHECKING_P + if (has_pointer_operand_p (lhs, op1, op2) + && !m_operator->pointers_handled_p (DISPATCH_LHS_OP1_RELATION, + dispatch_kind (lhs, op1, op2))) + discriminator_fail (lhs, op1, op2); +#endif switch (dispatch_kind (lhs, op1, op2)) { @@ -316,6 +406,18 @@ range_op_handler::lhs_op1_relation (const vrange &lhs, return m_operator->lhs_op1_relation (as_a (lhs), as_a (op1), as_a (op2), rel); + case RO_PPP: + return m_operator->lhs_op1_relation (as_a (lhs), + as_a (op1), + as_a (op2), rel); + case RO_IPP: + return m_operator->lhs_op1_relation (as_a (lhs), + as_a (op1), + as_a (op2), rel); + case RO_PII: + return m_operator->lhs_op1_relation (as_a (lhs), + as_a (op1), + as_a (op2), rel); case RO_IFF: return m_operator->lhs_op1_relation (as_a (lhs), as_a (op1), @@ -338,6 +440,12 @@ range_op_handler::lhs_op2_relation (const vrange &lhs, relation_kind rel) const { gcc_checking_assert (m_operator); +#if CHECKING_P + if (has_pointer_operand_p (lhs, op1, op2) + && !m_operator->pointers_handled_p (DISPATCH_LHS_OP2_RELATION, + dispatch_kind (lhs, op1, op2))) + discriminator_fail (lhs, op1, op2); +#endif switch (dispatch_kind (lhs, op1, op2)) { case RO_III: @@ -365,6 +473,12 @@ range_op_handler::op1_op2_relation (const vrange &lhs, const vrange &op2) const { gcc_checking_assert (m_operator); +#if CHECKING_P + if (has_pointer_operand_p (lhs, op1, op2) + && !m_operator->pointers_handled_p (DISPATCH_OP1_OP2_RELATION, + dispatch_kind (lhs, op1, op2))) + discriminator_fail (lhs, op1, op2); +#endif switch (dispatch_kind (lhs, op1, op2)) { case RO_III: @@ -372,6 +486,11 @@ range_op_handler::op1_op2_relation (const vrange &lhs, as_a (op1), as_a (op2)); + case RO_IPP: + return m_operator->op1_op2_relation (as_a (lhs), + as_a (op1), + as_a (op2)); + case RO_IFF: return m_operator->op1_op2_relation (as_a (lhs), as_a (op1), @@ -2327,6 +2446,7 @@ operator_widen_mult_unsigned::wi_fold (irange &r, tree type, class operator_div : public cross_product_operator { + using range_operator::update_bitmask; public: operator_div (tree_code div_kind) { m_code = div_kind; } virtual void wi_fold (irange &r, tree type, @@ -2474,6 +2594,7 @@ class operator_lshift : public cross_product_operator { using range_operator::fold_range; using range_operator::op1_range; + using range_operator::update_bitmask; public: virtual bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio rel = TRIO_VARYING) @@ -2503,6 +2624,7 @@ class operator_rshift : public cross_product_operator using range_operator::fold_range; using range_operator::op1_range; using range_operator::lhs_op1_relation; + using range_operator::update_bitmask; public: virtual bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio rel = TRIO_VARYING) @@ -3883,6 +4005,7 @@ class operator_trunc_mod : public range_operator { using range_operator::op1_range; using range_operator::op2_range; + using range_operator::update_bitmask; public: virtual void wi_fold (irange &r, tree type, const wide_int &lh_lb, @@ -4305,6 +4428,7 @@ operator_abs::update_bitmask (irange &r, const irange &lh, class operator_absu : public range_operator { + using range_operator::update_bitmask; public: virtual void wi_fold (irange &r, tree type, const wide_int &lh_lb, const wide_int &lh_ub, diff --git a/gcc/range-op.h b/gcc/range-op.h index 44a3e4f009f..2bad5a90e11 100644 --- a/gcc/range-op.h +++ b/gcc/range-op.h @@ -22,6 +22,16 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_RANGE_OP_H #define GCC_RANGE_OP_H +enum range_op_dispatch_type +{ + DISPATCH_FOLD_RANGE, + DISPATCH_OP1_RANGE, + DISPATCH_OP2_RANGE, + DISPATCH_LHS_OP1_RELATION, + DISPATCH_LHS_OP2_RELATION, + DISPATCH_OP1_OP2_RELATION +}; + // This class is implemented for each kind of operator supported by // the range generator. It serves various purposes. // @@ -76,6 +86,26 @@ public: const irange &lh, const irange &rh, relation_trio = TRIO_VARYING) const; + virtual bool fold_range (prange &r, tree type, + const prange &lh, + const prange &rh, + relation_trio = TRIO_VARYING) const; + virtual bool fold_range (prange &r, tree type, + const prange &lh, + const irange &rh, + relation_trio = TRIO_VARYING) const; + virtual bool fold_range (irange &r, tree type, + const prange &lh, + const prange &rh, + relation_trio = TRIO_VARYING) const; + virtual bool fold_range (prange &r, tree type, + const irange &lh, + const prange &rh, + relation_trio = TRIO_VARYING) const; + virtual bool fold_range (irange &r, tree type, + const prange &lh, + const irange &rh, + relation_trio = TRIO_VARYING) const; // Return the range for op[12] in the general case. LHS is the range for // the LHS of the expression, OP[12]is the range for the other @@ -92,6 +122,22 @@ public: const irange &lhs, const irange &op2, relation_trio = TRIO_VARYING) const; + virtual bool op1_range (prange &r, tree type, + const prange &lhs, + const prange &op2, + relation_trio = TRIO_VARYING) const; + virtual bool op1_range (prange &r, tree type, + const irange &lhs, + const prange &op2, + relation_trio = TRIO_VARYING) const; + virtual bool op1_range (prange &r, tree type, + const prange &lhs, + const irange &op2, + relation_trio = TRIO_VARYING) const; + virtual bool op1_range (irange &r, tree type, + const prange &lhs, + const irange &op2, + relation_trio = TRIO_VARYING) const; virtual bool op1_range (frange &r, tree type, const frange &lhs, const frange &op2, @@ -106,6 +152,14 @@ public: const irange &lhs, const irange &op1, relation_trio = TRIO_VARYING) const; + virtual bool op2_range (prange &r, tree type, + const irange &lhs, + const prange &op1, + relation_trio = TRIO_VARYING) const; + virtual bool op2_range (irange &r, tree type, + const prange &lhs, + const prange &op1, + relation_trio = TRIO_VARYING) const; virtual bool op2_range (frange &r, tree type, const frange &lhs, const frange &op1, @@ -123,6 +177,18 @@ public: const irange &op1, const irange &op2, relation_kind = VREL_VARYING) const; + virtual relation_kind lhs_op1_relation (const prange &lhs, + const prange &op1, + const prange &op2, + relation_kind = VREL_VARYING) const; + virtual relation_kind lhs_op1_relation (const prange &lhs, + const irange &op1, + const irange &op2, + relation_kind = VREL_VARYING) const; + virtual relation_kind lhs_op1_relation (const irange &lhs, + const prange &op1, + const prange &op2, + relation_kind = VREL_VARYING) const; virtual relation_kind lhs_op1_relation (const frange &lhs, const frange &op1, const frange &op2, @@ -148,6 +214,9 @@ public: virtual relation_kind op1_op2_relation (const irange &lhs, const irange &op1, const irange &op2) const; + virtual relation_kind op1_op2_relation (const irange &lhs, + const prange &op1, + const prange &op2) const; virtual relation_kind op1_op2_relation (const irange &lhs, const frange &op1, const frange &op2) const; @@ -160,6 +229,7 @@ public: // Compatability check for operands. virtual bool operand_check_p (tree, tree, tree) const; + virtual bool pointers_handled_p (enum range_op_dispatch_type, unsigned) const; protected: // Perform an integral operation between 2 sub-ranges and return it. @@ -173,6 +243,26 @@ protected: const irange &op1_range, const irange &op2_range, relation_kind rel) const; + virtual bool op1_op2_relation_effect (prange &lhs_range, tree type, + const prange &op1_range, + const prange &op2_range, + relation_kind rel) const; + virtual bool op1_op2_relation_effect (prange &lhs_range, tree type, + const prange &op1_range, + const irange &op2_range, + relation_kind rel) const; + virtual bool op1_op2_relation_effect (irange &lhs_range, tree type, + const prange &op1_range, + const prange &op2_range, + relation_kind rel) const; + virtual bool op1_op2_relation_effect (prange &lhs_range, tree type, + const irange &op1_range, + const prange &op2_range, + relation_kind rel) const; + virtual bool op1_op2_relation_effect (irange &lhs_range, tree type, + const prange &op1_range, + const irange &op2_range, + relation_kind rel) const; // Called by fold range to split small subranges into parts. void wi_fold_in_parts (irange &r, tree type, const wide_int &lh_lb, @@ -187,6 +277,7 @@ protected: unsigned limit) const; // Apply any bitmasks implied by these ranges. virtual void update_bitmask (irange &, const irange &, const irange &) const; + virtual void update_bitmask (irange &, const prange &, const prange &) const; // Perform an float operation between 2 ranges and return it. virtual void rv_fold (frange &r, tree type, @@ -234,6 +325,9 @@ public: protected: unsigned dispatch_kind (const vrange &lhs, const vrange &op1, const vrange& op2) const; + void discriminator_fail (const vrange &, + const vrange &, + const vrange &) const; range_operator *m_operator; }; @@ -316,4 +410,21 @@ protected: void initialize_pointer_ops (); void initialize_float_ops (); }; + +// Temporary exports so the pointers_handled_p() sanity code can see +// which pointer combination is being attempted. This will be deleted +// once pointers_handled_p is gone. +extern const unsigned RO_III; +extern const unsigned RO_IFI; +extern const unsigned RO_IFF; +extern const unsigned RO_FFF; +extern const unsigned RO_FIF; +extern const unsigned RO_FII; +extern const unsigned RO_PPP; +extern const unsigned RO_PPI; +extern const unsigned RO_IPP; +extern const unsigned RO_IPI; +extern const unsigned RO_PIP; +extern const unsigned RO_PII; + #endif // GCC_RANGE_OP_H From patchwork Sat May 4 08:30:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931252 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bRX2fwZG; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWh0J5Vdsz1ybC for ; Sat, 4 May 2024 18:38:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E9098386F430 for ; Sat, 4 May 2024 08:38:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by sourceware.org (Postfix) with ESMTPS id EED563844033 for ; Sat, 4 May 2024 08:31:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EED563844033 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EED563844033 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.139.111.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811478; cv=none; b=VC5g7AQzA28RgY32NF9+BN5HfVzITEoLFURGWK/GXSMFrg1nEgk14uec4LAWMI6dUUR8SxoFc9PLz0CqL0u6G82UnIaY5r33xbD0FIT0NJAs8C0tkMYpyBrrmJhW3xjRbXNRs+KjgvMenDPJHYkMXr4ognDJyliUyNq5dAM3kQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811478; c=relaxed/simple; bh=1kPXfHg+lu4UOb6l+HIchFvI+3RNuj31eVKrslq4Ass=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gh12a+8fW9ASbuMRiV8s1UWhMI0x3MwYf5VR8BG7Zp/s0iFwQQGFOj271W0aScZA+LPOiY6YYU/zZygE1EECoIqwzmnvnnXHp4jLrMid1CcySfOgAVajlD8JWsuTVQ6UDY9qnP6Tv2WBPA85PwpavHE0UMnHmlVz/+vdcJL7zM8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811465; 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=EIY8AFih4tUTKiCxu/n7RVwcalb7AX0VuM9YCZugpGc=; b=bRX2fwZG63G5QTeiDhZDrvoZX+353QSLN5no60s969al6ItESoFv3BGpeLtL/4cMjLCRK+ aoYkfTk5nP3tLygriTbCiFGUOWzMV4huoeG6gAhJwpzDnOzF6xuEdrsg1yfNYWTEb9O2eQ SxaESc0qcUKh34lRmPsfLYPa3O9Supk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-302-Euw5JgVOPRauzTT4Sp_UcA-1; Sat, 04 May 2024 04:31:01 -0400 X-MC-Unique: Euw5JgVOPRauzTT4Sp_UcA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7E0D9800C8A for ; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 300B9492BC7; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448Uxlg139816 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:30:59 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448UxWQ139815; Sat, 4 May 2024 10:30:59 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 08/23] Implement operator_identity for prange. Date: Sat, 4 May 2024 10:30:36 +0200 Message-ID: <20240504083056.139719-9-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * range-op-mixed.h: Add overloaded declarations for fold_range, op1_range, lhs_op1_relation, pointers_handled_p. * range-op-ptr.cc (operator_identity::fold_range): New. (operator_identity::lhs_op1_relation): New. (operator_identity::op1_range): New. (operator_identity::pointers_handled_p): New. --- gcc/range-op-mixed.h | 10 ++++++++++ gcc/range-op-ptr.cc | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index 8163a4b53ca..60aaea9563d 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -349,18 +349,28 @@ public: bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio rel = TRIO_VARYING) const final override; + bool fold_range (prange &r, tree type, + const prange &op1, const prange &op2, + relation_trio rel = TRIO_VARYING) const final override; bool fold_range (frange &r, tree type ATTRIBUTE_UNUSED, const frange &op1, const frange &op2 ATTRIBUTE_UNUSED, relation_trio = TRIO_VARYING) const final override; bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio rel = TRIO_VARYING) const final override; + bool op1_range (prange &r, tree type, + const prange &lhs, const prange &op2, + relation_trio rel = TRIO_VARYING) const final override; bool op1_range (frange &r, tree type ATTRIBUTE_UNUSED, const frange &lhs, const frange &op2 ATTRIBUTE_UNUSED, relation_trio = TRIO_VARYING) const final override; relation_kind lhs_op1_relation (const irange &lhs, const irange &op1, const irange &op2, relation_kind rel) const final override; + relation_kind lhs_op1_relation (const prange &lhs, + const prange &op1, const prange &op2, + relation_kind rel) const final override; + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; }; class operator_cst : public range_operator diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index 560c798b90a..08419bfc798 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -636,6 +636,53 @@ public: } } op_hybrid_max; +bool +operator_identity::fold_range (prange &r, tree type ATTRIBUTE_UNUSED, + const prange &lh ATTRIBUTE_UNUSED, + const prange &rh ATTRIBUTE_UNUSED, + relation_trio) const +{ + r = lh; + return true; +} + +relation_kind +operator_identity::lhs_op1_relation (const prange &lhs, + const prange &op1 ATTRIBUTE_UNUSED, + const prange &op2 ATTRIBUTE_UNUSED, + relation_kind) const +{ + if (lhs.undefined_p ()) + return VREL_VARYING; + // Simply a copy, so they are equivalent. + return VREL_EQ; +} + +bool +operator_identity::op1_range (prange &r, tree type ATTRIBUTE_UNUSED, + const prange &lhs, + const prange &op2 ATTRIBUTE_UNUSED, + relation_trio) const +{ + r = lhs; + return true; +} + +bool +operator_identity::pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + case DISPATCH_OP1_RANGE: + case DISPATCH_LHS_OP1_RELATION: + return dispatch == RO_PPP; + default: + return true; + } +} + // Initialize any pointer operators to the primary table void From patchwork Sat May 4 08:30:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931247 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KN/v1TYr; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgwT1QcZz23tp for ; Sat, 4 May 2024 18:35:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8CFE9386F420 for ; Sat, 4 May 2024 08:35:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id C4E5A3844754 for ; Sat, 4 May 2024 08:31:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4E5A3844754 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C4E5A3844754 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811468; cv=none; b=n0Lf7R05x/MRJmuSX/dbcQ98ZIgTjxmGlsQ3sxAsdMV7aiaw2WpHiVOCHX7KdF3Gj6wOJPvyF2zTjAHRmJxGkZ4hMZmumccgwaEko0dKF5+YD+8KkqWPGOvDAPuqmAUmm73KxciRIFHeej5JOcDyrOwDRzBYC2Ww8T0VRoNHu8s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811468; c=relaxed/simple; bh=PvuMR0l9H4AxEV8OFBNh+qiCZi+4SFe4oNGTHwVpLn8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=yEbZXYtGUqjqcU9tTOeji1b4B3X7+KDM9Ieio3aMS1ShoJoI7l8zNarWFGXIXJAeuXjfN5aC9guZ8CGVZjKBZyFJ/c9NvxseVEDcDh+4Ayi8pqrZgPhNj2YlfsvRe12us11iNZsK4p81VTgA6xCapamJhd9SdW1X+rzdWnqrXfY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811463; 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=lVsKsEnTiTMVbhob4nVE9cMxOiwuEnKtqbIce1B9p+8=; b=KN/v1TYrbWd0SMtflKNHhe+oHyA6MWhmO4ZeKUXiaN9pWFgQQF3P7QjcknzVYpf8ockPKk iXv11YwT2UjuUPoUViXX8bQJkdgfWFQS7O7Q3Nbr2ZpjNN2HjppZ3W6PlmbzCW5aThdun9 bkbzXnHGoXQjBAJPkesXJoFQ6HvMxrg= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639-LqTZNtFfNS-p4RpxkVbiHQ-1; Sat, 04 May 2024 04:31:01 -0400 X-MC-Unique: LqTZNtFfNS-p4RpxkVbiHQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7E96B3C1014F for ; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3010EC01595; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448Uxax139820 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:31:00 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448UxjU139819; Sat, 4 May 2024 10:30:59 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 09/23] Implement operator_cst for prange. Date: Sat, 4 May 2024 10:30:37 +0200 Message-ID: <20240504083056.139719-10-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * range-op-mixed.h: Add overloaded declarations for pointer variants. * range-op-ptr.cc (operator_cst::fold_range): New. (operator_cst::pointers_handled_p): New. --- gcc/range-op-mixed.h | 4 ++++ gcc/range-op-ptr.cc | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index 60aaea9563d..04c8acbd94a 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -380,9 +380,13 @@ public: bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio rel = TRIO_VARYING) const final override; + bool fold_range (prange &r, tree type, + const prange &op1, const prange &op2, + relation_trio rel = TRIO_VARYING) const final override; bool fold_range (frange &r, tree type, const frange &op1, const frange &op2, relation_trio = TRIO_VARYING) const final override; + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; }; diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index 08419bfc798..e59e278cbd7 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -683,6 +683,29 @@ operator_identity::pointers_handled_p (range_op_dispatch_type type, } } +bool +operator_cst::fold_range (prange &r, tree type ATTRIBUTE_UNUSED, + const prange &lh, + const prange & ATTRIBUTE_UNUSED, + relation_trio) const +{ + r = lh; + return true; +} + +bool +operator_cst::pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + return dispatch == RO_PPP; + default: + return true; + } +} + // Initialize any pointer operators to the primary table void From patchwork Sat May 4 08:30:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931243 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ES0XoirT; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgvB63D2z23tp for ; Sat, 4 May 2024 18:34:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2230E386F44A for ; Sat, 4 May 2024 08:34:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id 4FCD3384476A for ; Sat, 4 May 2024 08:31:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4FCD3384476A Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4FCD3384476A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811472; cv=none; b=rcG8mgqLQ0otJvA+/MiZKQjSaTzmrr7Enl3o19J6yeoQQHRA/q3Twv8CgRvlHIadMpm92xtD7XYZ8ygurjiDYTG68C8R2ewG5pCQOkfHUFIXCjOk5gC6C8naQWmBD3Iq8PWHXiNnSQfrxhBiT7ZkoqX97wEtFCl0g+9TNfpv1R8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811472; c=relaxed/simple; bh=QgcRjhvg80OawwsoVpv7g/T9T9dgfSsHhBdaJSmmucc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=S07kE6cA7y7MyBvr33v8LeoJakOzC6R4eoKY2JFVuv/UoihUNiJyVpfKFvfAcp7iA4mrs7zyuY0mEAsF/dKipdFjwK9nCXQReJvzPgqnrWA4KXelzlK4yFrLk55NWBcVT26ZbN0Eg+0x0FBc3lbQENonujnkZ4TL+V+C6Jo3a/I= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811463; 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=3FkLwShHqoUssgOqMiJeCTslRf034wxlrtFWQ81Yev0=; b=ES0XoirT9RbbKDuuhBS8qXM4WN2jkJaFXiEV7nKeT0e4aZC0dr1R+2e5+2dpkqee/Ejk5S 2FwEW0dqDPy7k3yyw3oACFS6MX+DToZn+v1f46OErfM6fZIH53F4mDuD+Lxi5mM1P+uCUT nmDYHsc2CI2HeJwMpq1Fkler7CJQ16Y= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-85-zSRiS33COLeS4AUEaVj_FQ-1; Sat, 04 May 2024 04:31:01 -0400 X-MC-Unique: zSRiS33COLeS4AUEaVj_FQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9EDE0380621C for ; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F3E21C0654E; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448V05l139824 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:31:00 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448V022139823; Sat, 4 May 2024 10:31:00 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 10/23] Implement operator_cast for prange. Date: Sat, 4 May 2024 10:30:38 +0200 Message-ID: <20240504083056.139719-11-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * range-op-mixed.h: Add overloaded declarations for pointer variants. * range-op-ptr.cc (operator_cast::fold_range): New. (operator_cast::op1_range): New. (operator_cast::lhs_op1_relation): New. (operator_cast::pointers_handled_p): New. --- gcc/range-op-mixed.h | 28 +++++ gcc/range-op-ptr.cc | 245 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 273 insertions(+) diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index 04c8acbd94a..11b1bf0bca4 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -400,14 +400,42 @@ public: bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio rel = TRIO_VARYING) const final override; + bool fold_range (prange &r, tree type, + const prange &op1, const prange &op2, + relation_trio rel = TRIO_VARYING) const final override; + bool fold_range (irange &r, tree type, + const prange &op1, const irange &op2, + relation_trio rel = TRIO_VARYING) const final override; + bool fold_range (prange &r, tree type, + const irange &op1, const prange &op2, + relation_trio rel = TRIO_VARYING) const final override; bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio rel = TRIO_VARYING) const final override; + bool op1_range (prange &r, tree type, + const prange &lhs, const prange &op2, + relation_trio rel = TRIO_VARYING) const final override; + bool op1_range (irange &r, tree type, + const prange &lhs, const irange &op2, + relation_trio rel = TRIO_VARYING) const final override; + bool op1_range (prange &r, tree type, + const irange &lhs, const prange &op2, + relation_trio rel = TRIO_VARYING) const final override; relation_kind lhs_op1_relation (const irange &lhs, const irange &op1, const irange &op2, relation_kind) const final override; + relation_kind lhs_op1_relation (const prange &lhs, + const prange &op1, const prange &op2, + relation_kind) const final override; + relation_kind lhs_op1_relation (const prange &lhs, + const irange &op1, const irange &op2, + relation_kind) const final override; + relation_kind lhs_op1_relation (const irange &lhs, + const prange &op1, const prange &op2, + relation_kind) const final override; void update_bitmask (irange &r, const irange &lh, const irange &rh) const final override; + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; private: bool truncating_cast_p (const irange &inner, const irange &outer) const; bool inside_domain_p (const wide_int &min, const wide_int &max, diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index e59e278cbd7..b8f86c8e838 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -706,6 +706,251 @@ operator_cst::pointers_handled_p (range_op_dispatch_type type, } } +// Cast between pointers. + +bool +operator_cast::fold_range (prange &r, tree type, + const prange &inner, + const prange &outer, + relation_trio) const +{ + if (empty_range_varying (r, type, inner, outer)) + return true; + + r.set (type, inner.lower_bound (), inner.upper_bound ()); + r.update_bitmask (inner.get_bitmask ()); + return true; +} + +// Cast a pointer to an integer. + +bool +operator_cast::fold_range (irange &r, tree type, + const prange &inner, + const irange &outer, + relation_trio) const +{ + if (empty_range_varying (r, type, inner, outer)) + return true; + + // Represent INNER as an integer of the same size, and then cast it + // to the resulting integer type. + tree pointer_uint_type = make_unsigned_type (TYPE_PRECISION (inner.type ())); + r.set (pointer_uint_type, inner.lower_bound (), inner.upper_bound ()); + r.update_bitmask (inner.get_bitmask ()); + range_cast (r, type); + return true; +} + +// Cast an integer to a pointer. + +bool +operator_cast::fold_range (prange &r, tree type, + const irange &inner, + const prange &outer, + relation_trio) const +{ + if (empty_range_varying (r, type, inner, outer)) + return true; + + // Cast INNER to an integer of the same size as the pointer we want, + // and then copy the bounds to the resulting pointer range. + int_range<2> tmp = inner; + tree pointer_uint_type = make_unsigned_type (TYPE_PRECISION (type)); + range_cast (tmp, pointer_uint_type); + r.set (type, tmp.lower_bound (), tmp.upper_bound ()); + r.update_bitmask (tmp.get_bitmask ()); + return true; +} + +bool +operator_cast::op1_range (prange &r, tree type, + const prange &lhs, + const prange &op2, + relation_trio trio) const +{ + if (lhs.undefined_p ()) + return false; + gcc_checking_assert (types_compatible_p (op2.type(), type)); + + // Conversion from other pointers or a constant (including 0/NULL) + // are straightforward. + if (POINTER_TYPE_P (lhs.type ()) + || (lhs.singleton_p () + && TYPE_PRECISION (lhs.type ()) >= TYPE_PRECISION (type))) + fold_range (r, type, lhs, op2, trio); + else + { + // If the LHS is not a pointer nor a singleton, then it is + // either VARYING or non-zero. + if (!lhs.undefined_p () && !range_includes_zero_p (lhs)) + r.set_nonzero (type); + else + r.set_varying (type); + } + r.intersect (op2); + return true; +} + +bool +operator_cast::op1_range (irange &r, tree type, + const prange &lhs, + const irange &op2, + relation_trio trio) const +{ + if (lhs.undefined_p ()) + return false; + gcc_checking_assert (types_compatible_p (op2.type(), type)); + + // Conversion from other pointers or a constant (including 0/NULL) + // are straightforward. + if (POINTER_TYPE_P (lhs.type ()) + || (lhs.singleton_p () + && TYPE_PRECISION (lhs.type ()) >= TYPE_PRECISION (type))) + fold_range (r, type, lhs, op2, trio); + else + { + // If the LHS is not a pointer nor a singleton, then it is + // either VARYING or non-zero. + if (!lhs.undefined_p () && !range_includes_zero_p (lhs)) + r.set_nonzero (type); + else + r.set_varying (type); + } + r.intersect (op2); + return true; +} + +bool +operator_cast::op1_range (prange &r, tree type, + const irange &lhs, + const prange &op2, + relation_trio trio) const +{ + if (lhs.undefined_p ()) + return false; + gcc_checking_assert (types_compatible_p (op2.type(), type)); + + // Conversion from other pointers or a constant (including 0/NULL) + // are straightforward. + if (POINTER_TYPE_P (lhs.type ()) + || (lhs.singleton_p () + && TYPE_PRECISION (lhs.type ()) >= TYPE_PRECISION (type))) + fold_range (r, type, lhs, op2, trio); + else + { + // If the LHS is not a pointer nor a singleton, then it is + // either VARYING or non-zero. + if (!lhs.undefined_p () && !range_includes_zero_p (lhs)) + r.set_nonzero (type); + else + r.set_varying (type); + } + r.intersect (op2); + return true; +} + +relation_kind +operator_cast::lhs_op1_relation (const prange &lhs, + const prange &op1, + const prange &op2 ATTRIBUTE_UNUSED, + relation_kind) const +{ + if (lhs.undefined_p () || op1.undefined_p ()) + return VREL_VARYING; + unsigned lhs_prec = TYPE_PRECISION (lhs.type ()); + unsigned op1_prec = TYPE_PRECISION (op1.type ()); + // If the result gets sign extended into a larger type check first if this + // qualifies as a partial equivalence. + if (TYPE_SIGN (op1.type ()) == SIGNED && lhs_prec > op1_prec) + { + // If the result is sign extended, and the LHS is larger than op1, + // check if op1's range can be negative as the sign extension will + // cause the upper bits to be 1 instead of 0, invalidating the PE. + int_range<3> negs = range_negatives (op1.type ()); + negs.intersect (op1); + if (!negs.undefined_p ()) + return VREL_VARYING; + } + + unsigned prec = MIN (lhs_prec, op1_prec); + return bits_to_pe (prec); +} + +relation_kind +operator_cast::lhs_op1_relation (const prange &lhs, + const irange &op1, + const irange &op2 ATTRIBUTE_UNUSED, + relation_kind) const +{ + if (lhs.undefined_p () || op1.undefined_p ()) + return VREL_VARYING; + unsigned lhs_prec = TYPE_PRECISION (lhs.type ()); + unsigned op1_prec = TYPE_PRECISION (op1.type ()); + // If the result gets sign extended into a larger type check first if this + // qualifies as a partial equivalence. + if (TYPE_SIGN (op1.type ()) == SIGNED && lhs_prec > op1_prec) + { + // If the result is sign extended, and the LHS is larger than op1, + // check if op1's range can be negative as the sign extension will + // cause the upper bits to be 1 instead of 0, invalidating the PE. + int_range<3> negs = range_negatives (op1.type ()); + negs.intersect (op1); + if (!negs.undefined_p ()) + return VREL_VARYING; + } + + unsigned prec = MIN (lhs_prec, op1_prec); + return bits_to_pe (prec); +} + +relation_kind +operator_cast::lhs_op1_relation (const irange &lhs, + const prange &op1, + const prange &op2 ATTRIBUTE_UNUSED, + relation_kind) const +{ + if (lhs.undefined_p () || op1.undefined_p ()) + return VREL_VARYING; + unsigned lhs_prec = TYPE_PRECISION (lhs.type ()); + unsigned op1_prec = TYPE_PRECISION (op1.type ()); + // If the result gets sign extended into a larger type check first if this + // qualifies as a partial equivalence. + if (TYPE_SIGN (op1.type ()) == SIGNED && lhs_prec > op1_prec) + { + // If the result is sign extended, and the LHS is larger than op1, + // check if op1's range can be negative as the sign extension will + // cause the upper bits to be 1 instead of 0, invalidating the PE. + int_range<3> negs = range_negatives (op1.type ()); + negs.intersect (op1); + if (!negs.undefined_p ()) + return VREL_VARYING; + } + + unsigned prec = MIN (lhs_prec, op1_prec); + return bits_to_pe (prec); +} + +bool +operator_cast::pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + case DISPATCH_OP1_RANGE: + return (dispatch == RO_PPP + || dispatch == RO_IPI + || dispatch == RO_PIP); + case DISPATCH_LHS_OP1_RELATION: + return (dispatch == RO_PPP + || dispatch == RO_PII + || dispatch == RO_IPP); + default: + return true; + } +} + // Initialize any pointer operators to the primary table void From patchwork Sat May 4 08:30:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931248 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DpikjvY0; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgxn4VPSz1ybC for ; Sat, 4 May 2024 18:36:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CECDF3844033 for ; Sat, 4 May 2024 08:36:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by sourceware.org (Postfix) with ESMTPS id 0D926384475D for ; Sat, 4 May 2024 08:31:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0D926384475D Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0D926384475D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.139.111.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811468; cv=none; b=ZcP9+1GZCF86ASPdrc5qQ6OPf/uc16ovYvkuWgAF2cg8zkByQOFzbgGnTVG/k6/+sE9OFhqlLjWdQ6Tg4c7AT2ACutREyJZwIfibtGDhEldOK4QdJAWqnBCAXXGvSWorVDZySGUPq1UpmtprMAHcBIC88GsdytBvF0p7ZIHMxpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811468; c=relaxed/simple; bh=76FlNphXa2glvW4erO5XDkNeA5yQ3OexM0+uuRZ96RA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=oDJg9Jk1YjIom4U1g3ZyjsCsFBfG7oyvlYkaC+hboSxfqeKqO3CjX7tnfvpdeLWo7QFo0DXtlzC2IdJF08vyJVWTQqXDMXsUW+IXX2qROtjpkk7TZ3V4cmJWQsqBNvhzNxaZWa/hP84N24HE0X7GJCqs3HuhuxcZiFG4c9h4f68= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811463; 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=g2gS9UqheLwn1dIHqKhiKeL4dHH4X+DvWWD84dXufQo=; b=DpikjvY0iGorwykrtERs6YFY+B/VUPwKGLtaGaXUera8U5+GpRZ1D+28yNCuVhgjYLaOcq xCY3dhlaI/7LUAhOS6gpFnErxl5O0CdyFZX4b7ozUmQiAi9rxEJ+armyEOt0vpu1uY8MW+ lUsfR2j7TFeUpIoa2wIPcLZW2NIUM7A= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-WfeWK7jiNF6evS9jwtxMqA-1; Sat, 04 May 2024 04:31:02 -0400 X-MC-Unique: WfeWK7jiNF6evS9jwtxMqA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B2A813806227 for ; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6F10B210FD25; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448V0jx139828 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:31:00 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448V0OG139827; Sat, 4 May 2024 10:31:00 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 11/23] Implement operator_min and operator_max for prange. Date: Sat, 4 May 2024 10:30:39 +0200 Message-ID: <20240504083056.139719-12-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * range-op-mixed.h: Add overloaded declarations for pointer variants. * range-op-ptr.cc (operator_min::fold_range): New. (operator_min::pointers_handled_p): New. (operator_max::fold_range): New. (operator_max::pointers_handled_p): New. --- gcc/range-op-mixed.h | 12 ++++++++ gcc/range-op-ptr.cc | 70 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index 11b1bf0bca4..b69e674a78b 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -761,12 +761,18 @@ protected: class operator_min : public range_operator { public: + using range_operator::fold_range; using range_operator::update_bitmask; + bool fold_range (prange &r, tree type, + const prange &op1, + const prange &op2, + relation_trio) const final override; void update_bitmask (irange &r, const irange &lh, const irange &rh) const override; // Check compatibility of all operands. bool operand_check_p (tree t1, tree t2, tree t3) const final override { return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); } + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; protected: void wi_fold (irange &r, tree type, const wide_int &lh_lb, const wide_int &lh_ub, const wide_int &rh_lb, @@ -776,12 +782,18 @@ protected: class operator_max : public range_operator { public: + using range_operator::fold_range; using range_operator::update_bitmask; + bool fold_range (prange &r, tree type, + const prange &op1, + const prange &op2, + relation_trio) const final override; void update_bitmask (irange &r, const irange &lh, const irange &rh) const override; // Check compatibility of all operands. bool operand_check_p (tree t1, tree t2, tree t3) const final override { return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); } + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; protected: void wi_fold (irange &r, tree type, const wide_int &lh_lb, const wide_int &lh_ub, const wide_int &rh_lb, diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index b8f86c8e838..0addd1096c2 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -951,6 +951,76 @@ operator_cast::pointers_handled_p (range_op_dispatch_type type, } } +bool +operator_min::fold_range (prange &r, tree type, + const prange &op1, + const prange &op2, + relation_trio) const +{ + // For MIN/MAX expressions with pointers, we only care about + // nullness. If both are non null, then the result is nonnull. + // If both are null, then the result is null. Otherwise they + // are varying. + if (!range_includes_zero_p (op1) + && !range_includes_zero_p (op2)) + r.set_nonzero (type); + else if (op1.zero_p () && op2.zero_p ()) + r.set_zero (type); + else + r.set_varying (type); + + update_known_bitmask (r, MIN_EXPR, op1, op2); + return true; +} + +bool +operator_min::pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + return dispatch == RO_PPP; + default: + return true; + } +} + +bool +operator_max::fold_range (prange &r, tree type, + const prange &op1, + const prange &op2, + relation_trio) const +{ + // For MIN/MAX expressions with pointers, we only care about + // nullness. If both are non null, then the result is nonnull. + // If both are null, then the result is null. Otherwise they + // are varying. + if (!range_includes_zero_p (op1) + && !range_includes_zero_p (op2)) + r.set_nonzero (type); + else if (op1.zero_p () && op2.zero_p ()) + r.set_zero (type); + else + r.set_varying (type); + + update_known_bitmask (r, MAX_EXPR, op1, op2); + return true; +} + +bool +operator_max::pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + return dispatch == RO_PPP; + default: + return true; + } +} + // Initialize any pointer operators to the primary table void From patchwork Sat May 4 08:30:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931242 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MsA+qWmX; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgvB5XMCz1xnS for ; Sat, 4 May 2024 18:34:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F0914386F43B for ; Sat, 4 May 2024 08:34:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id F1EE43844755 for ; Sat, 4 May 2024 08:31:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F1EE43844755 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F1EE43844755 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811467; cv=none; b=LrWhJcJtvgwmvf2dhmUf1f6NnnYuTU9kPzEILSjiHlXLII7xpVAunaOboH5pSElRPTcCBCS4g5Y9mhsldFtelKmSlSz6N4L1Z8A6UWOfJVcz3Zs/ji7YtL1ERAWjxsGXYpU2ATLGXSoJRPakrLpckTv3COO25x8StbLblDGSS1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811467; c=relaxed/simple; bh=5evlB9xbPlzM9T2wHpkrpbpeAL+xGwOnscrjMayEjOU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=SCB5gCXTZsDR+xAzXDjops7kq4T0nvE33X0ln2gs4V7Mjgu4XrNKCBYrNgqVIJo6MLjc6SD1TggJasZ13/qdZeLJ7IwyGj50r92BLtlI0AXtRZHP7v+BGraGzJucDukew3jz5D52DcpJPEt+vl7yhmt9pwVaSM+Ze66VpBxgitI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811463; 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=y7qqdTwpbPnczU65Hao0bSxo5p8dvtVGcxmfLfAEpfQ=; b=MsA+qWmXlbAjllT/p0h3GZVPdVBQeb127LP6xAC6cFQFnmruHdmqKyLIxjGiAxbw82LW+5 LW8mnIzJWGyPIsfTz9aVxYPSbpRAfYnlwrhJ0CB8tYsrhPhdzPKlt59ZqSoF7n8YfpSgsP gAHnXc5JrTmw/PzqlwFdM6Gej9K1ahc= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-493-XFDHywbsONOEE7Q9vCq0iA-1; Sat, 04 May 2024 04:31:02 -0400 X-MC-Unique: XFDHywbsONOEE7Q9vCq0iA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D2A213806700 for ; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8F461400EAE; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448V0YD139832 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:31:00 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448V0LB139831; Sat, 4 May 2024 10:31:00 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 12/23] Implement operator_addr_expr for prange. Date: Sat, 4 May 2024 10:30:40 +0200 Message-ID: <20240504083056.139719-13-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * range-op-mixed.h: Add overloaded declarations for pointer variants. * range-op-ptr.cc (operator_addr_expr::op1_range): New. (operator_addr_expr::pointers_handled_p): New. --- gcc/range-op-mixed.h | 4 ++++ gcc/range-op-ptr.cc | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index b69e674a78b..0df300781f1 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -655,6 +655,10 @@ public: bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio rel = TRIO_VARYING) const final override; + bool op1_range (prange &r, tree type, + const prange &lhs, const prange &op2, + relation_trio rel = TRIO_VARYING) const final override; + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; }; class operator_bitwise_not : public range_operator diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index 0addd1096c2..38d9f65566f 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -1021,6 +1021,44 @@ operator_max::pointers_handled_p (range_op_dispatch_type type, } } +bool +operator_addr_expr::op1_range (prange &r, tree type, + const prange &lhs, + const prange &op2, + relation_trio) const +{ + if (empty_range_varying (r, type, lhs, op2)) + return true; + + // Return a non-null pointer of the LHS type (passed in op2), but only + // if we cant overflow, eitherwise a no-zero offset could wrap to zero. + // See PR 111009. + if (!lhs.undefined_p () + && !range_includes_zero_p (lhs) + && TYPE_OVERFLOW_UNDEFINED (type)) + r.set_nonzero (type); + else + r.set_varying (type); + return true; +} + +bool +operator_addr_expr::pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + // NOTE: It looks like we never generate this combination. + gcc_unreachable (); + return false; + case DISPATCH_OP1_RANGE: + return dispatch == RO_PPP; + default: + return true; + } +} + // Initialize any pointer operators to the primary table void From patchwork Sat May 4 08:30:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931241 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=g+szWsK+; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgtS5sw0z1xnS for ; Sat, 4 May 2024 18:33:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 091D4386F82C for ; Sat, 4 May 2024 08:33:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id 528A5384476C for ; Sat, 4 May 2024 08:31:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 528A5384476C Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 528A5384476C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811474; cv=none; b=t0Op7FTpG2v9vpqM5iYwd4Mr9wx071r839Z2nMV+1VazJrycAy1g0+81So+IUqj58F17ahnd2g9BatT1LeggibqIFQBXO4DEphVdaWYQ8ngjgZ256OtF5/f5Y6odCYPlovojeqoYTCB5yZwa5BacoZhR1F04hTK26D06hph+Sy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811474; c=relaxed/simple; bh=fDrNmHelRXI9IlxhCldq/efGKHCBOu7ZKxirzgCR0w8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jplS+qq6UqHQ8TdHr/uyZNmt019w/5Bd6otpYR3ijiI980zMhGqTgSc0aSL4JWTNUCV/dM4N6TPlTBEb4vRRc1a4K+5M2uHT9Yx6+7Y+U51WQImiUP8dRCoyLmJbt9iATDwgxa0NoSWY7b/FoVgSTr4A5jnhIEuWiU1UFMNU9Xk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811464; 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=/biM3Dqr9XHyXG3DvsvGoFNgg/VIFovQxxr66WMrXmk=; b=g+szWsK+bahyoAGRet1BKLxIoNgQYIxUQMqre4j0hItOBWq/iAYFy82xeTJzB8neteCT/m LImg9VxCzmj5lCEvIkJhfr4X0Q3as3z2gJg2zCmxaqZbg46SQ7naZruJBAvYcmNmHmSog4 mpa+b5ftqZ5aD8WPwS5nd7fY0Ylknxc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-493-5I1TjA7kMVqPxOzqlf-cQw-1; Sat, 04 May 2024 04:31:02 -0400 X-MC-Unique: 5I1TjA7kMVqPxOzqlf-cQw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0A01618065AD for ; Sat, 4 May 2024 08:31:02 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B9A75EC680; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448V037139836 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:31:00 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448V0sH139835; Sat, 4 May 2024 10:31:00 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 13/23] Implement pointer_plus_operator for prange. Date: Sat, 4 May 2024 10:30:41 +0200 Message-ID: <20240504083056.139719-14-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * range-op-ptr.cc (class pointer_plus_operator): Add overloaded declarations for pointer variants. (pointer_plus_operator::fold_range): New. (pointer_plus_operator::op2_range): New. (pointer_plus_operator::pointers_handled_p): New. --- gcc/range-op-ptr.cc | 98 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index 38d9f65566f..a4418215613 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -265,8 +265,17 @@ range_operator::update_bitmask (irange &, class pointer_plus_operator : public range_operator { using range_operator::update_bitmask; + using range_operator::fold_range; using range_operator::op2_range; public: + virtual bool fold_range (prange &r, tree type, + const prange &op1, + const irange &op2, + relation_trio) const final override; + virtual bool op2_range (irange &r, tree type, + const prange &lhs, + const prange &op1, + relation_trio = TRIO_VARYING) const final override; virtual void wi_fold (irange &r, tree type, const wide_int &lh_lb, const wide_int &lh_ub, @@ -276,10 +285,99 @@ public: const irange &lhs, const irange &op1, relation_trio = TRIO_VARYING) const; + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; void update_bitmask (irange &r, const irange &lh, const irange &rh) const { update_known_bitmask (r, POINTER_PLUS_EXPR, lh, rh); } } op_pointer_plus; +bool +pointer_plus_operator::fold_range (prange &r, tree type, + const prange &op1, + const irange &op2, + relation_trio) const +{ + if (empty_range_varying (r, type, op1, op2)) + return true; + + const wide_int lh_lb = op1.lower_bound (); + const wide_int lh_ub = op1.upper_bound (); + const wide_int rh_lb = op2.lower_bound (); + const wide_int rh_ub = op2.upper_bound (); + + // Check for [0,0] + const, and simply return the const. + if (lh_lb == 0 && lh_ub == 0 && rh_lb == rh_ub) + { + r.set (type, rh_lb, rh_lb); + return true; + } + + // For pointer types, we are really only interested in asserting + // whether the expression evaluates to non-NULL. + // + // With -fno-delete-null-pointer-checks we need to be more + // conservative. As some object might reside at address 0, + // then some offset could be added to it and the same offset + // subtracted again and the result would be NULL. + // E.g. + // static int a[12]; where &a[0] is NULL and + // ptr = &a[6]; + // ptr -= 6; + // ptr will be NULL here, even when there is POINTER_PLUS_EXPR + // where the first range doesn't include zero and the second one + // doesn't either. As the second operand is sizetype (unsigned), + // consider all ranges where the MSB could be set as possible + // subtractions where the result might be NULL. + if ((!wi_includes_zero_p (type, lh_lb, lh_ub) + || !wi_includes_zero_p (type, rh_lb, rh_ub)) + && !TYPE_OVERFLOW_WRAPS (type) + && (flag_delete_null_pointer_checks + || !wi::sign_mask (rh_ub))) + r.set_nonzero (type); + else if (lh_lb == lh_ub && lh_lb == 0 + && rh_lb == rh_ub && rh_lb == 0) + r.set_zero (type); + else + r.set_varying (type); + + update_known_bitmask (r, POINTER_PLUS_EXPR, op1, op2); + return true; +} + +bool +pointer_plus_operator::op2_range (irange &r, tree type, + const prange &lhs ATTRIBUTE_UNUSED, + const prange &op1 ATTRIBUTE_UNUSED, + relation_trio trio) const +{ + relation_kind rel = trio.lhs_op1 (); + r.set_varying (type); + + // If the LHS and OP1 are equal, the op2 must be zero. + if (rel == VREL_EQ) + r.set_zero (type); + // If the LHS and OP1 are not equal, the offset must be non-zero. + else if (rel == VREL_NE) + r.set_nonzero (type); + else + return false; + return true; +} + +bool +pointer_plus_operator::pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + return dispatch == RO_PPI; + case DISPATCH_OP2_RANGE: + return dispatch == RO_IPP; + default: + return true; + } +} + void pointer_plus_operator::wi_fold (irange &r, tree type, const wide_int &lh_lb, From patchwork Sat May 4 08:30:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931251 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=h/8oJlHI; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgzJ0Gkrz1ybC for ; Sat, 4 May 2024 18:37:48 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 393FE3844775 for ; Sat, 4 May 2024 08:37:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id B3A243844778 for ; Sat, 4 May 2024 08:31:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B3A243844778 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B3A243844778 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811474; cv=none; b=iBlWLDeSv0sBAKuTGtchW5xf6uZlu80OWGlcefLOuP52gTAOCqaAj4Bn2DsBBImwAHBEfdtLO6Do0PbzTweTdFZaZ6Ksxb4ry3URX+FpdUQpABBqipFeW1fPuLkSaXXQa0NlqmGLo1yBuxApjko9k1FJFupxg3d+QN6Wz/UEqxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811474; c=relaxed/simple; bh=8png+dRwMqmOwdqswstJvZ37L6IArMNyRnlonTBAXys=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=AZXtW5Ls84TFt/lks3s1K9x7zWfcXyNYUkIzx702lph5EKxfLbx3Cn/NFOIZmwO8nPMG+GJlpG5lzDwGtkJbUT9fp4RqmJOQA0KFq3+0gg7i54T5hOSDbGT7Nx9oWQQduEZlwiE5xqhTAXPg1Ldp0AcwpKMAIMwbHv+k9mPNpl8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811464; 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=Wpv8erdXgpXNbla/Pv0tmVBfI8bxSFYWDhiNqEZDevc=; b=h/8oJlHICmyxUwlBeUa0jpw2X4+KsorV/aupf3235Se5ZotRcq+n/UJ11+U+pA4ucl/15L ULOKDNLzul8570k5AmP8rj6LXcC0ygE4KIhc+Q0i2Z/2lSw4dIFhRN4uAI5ayrX9Klo4dk 9HhaCpsYk74ccaqda4GhPTg3FWXYMlI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-99-5vfYP65TP4K4H9qBEEGGnQ-1; Sat, 04 May 2024 04:31:02 -0400 X-MC-Unique: 5vfYP65TP4K4H9qBEEGGnQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 32E518943A2 for ; Sat, 4 May 2024 08:31:02 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E28F820296D3; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448V0rD139840 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:31:00 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448V0ha139839; Sat, 4 May 2024 10:31:00 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 14/23] Implement operator_pointer_diff for prange. Date: Sat, 4 May 2024 10:30:42 +0200 Message-ID: <20240504083056.139719-15-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * range-op-ptr.cc (operator_pointer_diff::op1_op2_relation_effect): New. (operator_pointer_diff::pointers_handled_p): New. --- gcc/range-op-ptr.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index a4418215613..b90b8bb9f65 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -564,10 +564,42 @@ class operator_pointer_diff : public range_operator const irange &op1_range, const irange &op2_range, relation_kind rel) const; + virtual bool op1_op2_relation_effect (irange &lhs_range, + tree type, + const prange &op1_range, + const prange &op2_range, + relation_kind rel) const final override; void update_bitmask (irange &r, const irange &lh, const irange &rh) const { update_known_bitmask (r, POINTER_DIFF_EXPR, lh, rh); } + void update_bitmask (irange &r, + const prange &lh, const prange &rh) const final override + { update_known_bitmask (r, POINTER_DIFF_EXPR, lh, rh); } + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; } op_pointer_diff; +bool +operator_pointer_diff::op1_op2_relation_effect (irange &lhs_range, tree type, + const prange &op1_range, + const prange &op2_range, + relation_kind rel) const +{ + int_range<2> op1, op2, tmp; + range_op_handler cast (CONVERT_EXPR); + + if (!cast.fold_range (op1, type, op1_range, tmp) + || !cast.fold_range (op2, type, op2_range, tmp)) + return false; + + return minus_op1_op2_relation_effect (lhs_range, type, op1, op2, rel); +} + +bool +operator_pointer_diff::pointers_handled_p (range_op_dispatch_type, + unsigned) const +{ + return true; +} + bool operator_pointer_diff::op1_op2_relation_effect (irange &lhs_range, tree type, const irange &op1_range, From patchwork Sat May 4 08:30:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931239 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Bsz0gfRl; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgt668yLz1xnS for ; Sat, 4 May 2024 18:33:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1492E3846079 for ; Sat, 4 May 2024 08:33:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id 9DC32384476F for ; Sat, 4 May 2024 08:31:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9DC32384476F Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9DC32384476F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811472; cv=none; b=C8aKz4Y69j2x0Gf4ri/DDVgpPZKERA7D3fnsbPR4PiHKT4T2tthIXu89JIuJtPBKfFlkicRCrd5pmUgcKtmCYZsxWjOvfWOgudID3M9kCC0gHbVOPxzUcDR317ZLhqfAKY2IlYdA+YuPWgoz2o++G+r8ibp/H7tzJkTZGUOytjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811472; c=relaxed/simple; bh=lIzmzi2Bf4NuRsjxyIe2rcL+/Fn7Sdu9IDU7iKv6Hkc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tNahO5SXvGe0uQQGpxZqUhx1+3T/Z4c3PuI7NONHOgRh5kT7zR7ZanRHuMavUEMkVp8wU8SNuZO8gUYfxP0IVZTCFt8REoDSWv0XNuiGx6DFtaQoYBs3f1kaw2HzFjTf/sH0vTWm+foMrGCnwOUPhxWKp7PpWhWoVxvwdAvYrNM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811464; 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=mecxNRCL5feWVwoCBFo5BuNfGxgYgU3IG9lf/9n4GE4=; b=Bsz0gfRlGE47cFxwxwgNSxOQMsOAxyeoxRLyDJU4YUVFu5KNs+zQPGTac8cN957oOYTgJl QNYK4h1Ia+8wpVyN63uHpKrBZKI5xydVmtC95kmNHjUYrowzTP2CQmn8nGSCXNyb9eZSXo 2gDz5vN6k9wOioD6CT4BPk8/GgosKWo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-513-Cxb2pysjM-O-0po_U9vX5w-1; Sat, 04 May 2024 04:31:02 -0400 X-MC-Unique: Cxb2pysjM-O-0po_U9vX5w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 52AFE834FBE for ; Sat, 4 May 2024 08:31:02 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F359200B08F; Sat, 4 May 2024 08:31:01 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448V0qe139844 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:31:00 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448V0u9139843; Sat, 4 May 2024 10:31:00 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 15/23] Implement operator_bitwise_and for prange. Date: Sat, 4 May 2024 10:30:43 +0200 Message-ID: <20240504083056.139719-16-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * range-op-mixed.h: Add overloaded declarations for pointer variants. * range-op-ptr.cc (operator_bitwise_and::fold_range): New. (operator_bitwise_and::pointers_handled_p): New. --- gcc/range-op-mixed.h | 6 ++++++ gcc/range-op-ptr.cc | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index 0df300781f1..6158fc51f8e 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -712,10 +712,15 @@ private: class operator_bitwise_and : public range_operator { public: + using range_operator::fold_range; using range_operator::op1_range; using range_operator::op2_range; using range_operator::lhs_op1_relation; using range_operator::update_bitmask; + bool fold_range (prange &r, tree type, + const prange &op1, + const prange &op2, + relation_trio) const final override; bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio rel = TRIO_VARYING) const override; @@ -730,6 +735,7 @@ public: // Check compatibility of all operands. bool operand_check_p (tree t1, tree t2, tree t3) const final override { return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); } + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; protected: void wi_fold (irange &r, tree type, const wide_int &lh_lb, const wide_int &lh_ub, const wide_int &rh_lb, diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index b90b8bb9f65..8d5049b1daf 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -1189,6 +1189,36 @@ operator_addr_expr::pointers_handled_p (range_op_dispatch_type type, } } +bool +operator_bitwise_and::fold_range (prange &r, tree type, + const prange &op1, + const prange &op2 ATTRIBUTE_UNUSED, + relation_trio) const +{ + // For pointer types, we are really only interested in asserting + // whether the expression evaluates to non-NULL. + if (op1.zero_p () || op2.zero_p ()) + r.set_zero (type); + else + r.set_varying (type); + + update_known_bitmask (r, BIT_AND_EXPR, op1, op2); + return true; +} + +bool +operator_bitwise_and::pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + return dispatch == RO_PPP; + default: + return true; + } +} + // Initialize any pointer operators to the primary table void From patchwork Sat May 4 08:30:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931240 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EFTWPEop; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgtC32Mcz1xnS for ; Sat, 4 May 2024 18:33:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9AC3F3842435 for ; Sat, 4 May 2024 08:33:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by sourceware.org (Postfix) with ESMTPS id 00A55384477B for ; Sat, 4 May 2024 08:31:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 00A55384477B Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 00A55384477B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.139.111.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811475; cv=none; b=IepoFOPXauQZwFx3+/cCcZoAw9np47JwfXfTRqZxYcR6eaWorDn1Mh+6BNJ2f+z01sy7rcjCxKP7sVwOxoyDprhnU96IAeHs3E11yLdjL++IFPd0trpffEBBdldKSg9f+4pv8602AJoWqbc1+Ki5IR5WoUlmCnh4Val6pPb9BdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811475; c=relaxed/simple; bh=iYB4yOIPhfa0+gSCo1n+QyQXo7R/dFfgdslFhfj4hC0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=mouUVMTy5M8TNJh/Rwq9slbzo4ZKdo3P5Cmcx1zHimOlOyM/GvWt02gqqQVLLjqwzwIruNc1Ca2i/fqfYxZQZSSGWt/7Q66xW79jvMlznkj3FDIDflHs9Y7HTqy7L3QFiqErytYGTPb/YbJlruoJtfuUBH+d69QF0vre3RgGnho= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811464; 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=6v/v22ph9In/GpJuZTLQ14DeOUAiYUjfb5bxivQJjWQ=; b=EFTWPEopRO9/AAQu76I8MaTQGvEH9CwGI0p/H5aVjHmFg1N8Q+ReU2LRy+e1T3AxGeaJyc VSkkGL8NvC7GSUdTcHr0HPecalpLH/htGMVp++tdiJmsABIdn+d4S4d0iM+csJPnA1Q3NV 7RN259fqN5+hOzHg8IjXsYp3Oo8cNyY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-622-N6SWQfsHMN2US7tg0PAX1Q-1; Sat, 04 May 2024 04:31:02 -0400 X-MC-Unique: N6SWQfsHMN2US7tg0PAX1Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 799873C1014F for ; Sat, 4 May 2024 08:31:02 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 34C4D1121312; Sat, 4 May 2024 08:31:02 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448V04m139848 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:31:01 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448V0Lg139847; Sat, 4 May 2024 10:31:00 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 16/23] Implement operator_bitwise_or for prange. Date: Sat, 4 May 2024 10:30:44 +0200 Message-ID: <20240504083056.139719-17-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org We seem to have a range-op entry for pointer bitwise OR that we've inherited from the original VRP implementation, but it never gets used. If this is not valid gimple, we can safely remove this entry. gcc/ChangeLog: * range-op-mixed.h: Add overloaded declarations for pointer variants. * range-op-ptr.cc (operator_bitwise_or::pointers_handled_p): New. --- gcc/range-op-mixed.h | 1 + gcc/range-op-ptr.cc | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index 6158fc51f8e..c45aed93567 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -762,6 +762,7 @@ public: // Check compatibility of all operands. bool operand_check_p (tree t1, tree t2, tree t3) const final override { return range_compatible_p (t1, t2) && range_compatible_p (t1, t3); } + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; protected: void wi_fold (irange &r, tree type, const wide_int &lh_lb, const wide_int &lh_ub, const wide_int &rh_lb, diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index 8d5049b1daf..2f2f4bb2b5d 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -1219,6 +1219,17 @@ operator_bitwise_and::pointers_handled_p (range_op_dispatch_type type, } } +bool +operator_bitwise_or::pointers_handled_p (range_op_dispatch_type, + unsigned) const +{ + // NOTE: It looks like we never generate bitwise OR with pointers. + // If this is indeed the case, we can move operator_bitwise_or from + // range-op-mixed.h to range-op.h. + gcc_unreachable (); + return false; +} + // Initialize any pointer operators to the primary table void From patchwork Sat May 4 08:30:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931246 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fL3kZpT1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgwT1LZRz1ybC for ; Sat, 4 May 2024 18:35:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E1747386F44C for ; Sat, 4 May 2024 08:35:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id A35523844775 for ; Sat, 4 May 2024 08:31:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A35523844775 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A35523844775 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811475; cv=none; b=N1CNo8WJOzzhFb6TE/VLELny4x9XNFSA+Bu1kZeSgWj2hP5X4iOEOVybd6TlWL4XoeMhjQGweJalVKOCmaT0IA/d8dgvpzAr+92fj9nY1zlkeeq2qb6FJyD0vK5IKSiYVMpZWYjBQ6gwLyg5SAOSaG3ZM5UzqdyWAc6XMfQdj+c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811475; c=relaxed/simple; bh=u5x0QPrmn4OprlU1Uh+Tnb33bDcthKfbl3Rah4XOjlg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XDH4Kzh9iNjdw4xsYFjpNzvM4VFNEXR6HPXtLIHzWVGrptuIMiWXLud9mXloJbPhgOkHa9De6zU2+0WBzUHPsOs8aeYjOEr0r18Fbr9HJkJO/+iydxc0I6P32aiSj87I6xTTaN7DXZhkyDC2+y8A2aObKBl0amJZzGlUQssDtbs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811464; 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=ModLhyuxPRieTjJXEfrCq6N7j3ZtWNJTBM5sWdKq9II=; b=fL3kZpT1YWvYg/it71/heXxOMV4VGxmMCjezOmPUUByvsBzaAzuMdGZWuq1aaHdrFt4dga +MJUmjYXQNl06w/1ke7Z4ux0S8pRZ3m9HN8b3E475H/udc4d6Ab1MIxp5poh0hEeMCIbru mFlpritBgCDJJGKHHIneOE9mvFz9UGA= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-625-Mo8mlSjUO-ShOEXUH6m2Jw-1; Sat, 04 May 2024 04:31:02 -0400 X-MC-Unique: Mo8mlSjUO-ShOEXUH6m2Jw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9DE9C29AB3F9 for ; Sat, 4 May 2024 08:31:02 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5A577EC680; Sat, 4 May 2024 08:31:02 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448V16X139852 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:31:01 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448V1BF139851; Sat, 4 May 2024 10:31:01 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 17/23] Implement operator_not_equal for prange. Date: Sat, 4 May 2024 10:30:45 +0200 Message-ID: <20240504083056.139719-18-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * range-op-mixed.h: Add overloaded declarations for pointer variants. * range-op-ptr.cc (operator_not_equal::fold_range): New. (operator_not_equal::op1_range): New. (operator_not_equal::op2_range): New. (operator_not_equal::op1_op2_relation): New. (operator_not_equal::pointers_handled_p): New. --- gcc/range-op-mixed.h | 12 +++++ gcc/range-op-ptr.cc | 118 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index c45aed93567..980611dc339 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -155,6 +155,9 @@ public: bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio = TRIO_VARYING) const final override; + bool fold_range (irange &r, tree type, + const prange &op1, const prange &op2, + relation_trio rel = TRIO_VARYING) const final override; bool fold_range (irange &r, tree type, const frange &op1, const frange &op2, relation_trio rel = TRIO_VARYING) const final override; @@ -162,6 +165,9 @@ public: bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio = TRIO_VARYING) const final override; + bool op1_range (prange &r, tree type, + const irange &lhs, const prange &op2, + relation_trio = TRIO_VARYING) const final override; bool op1_range (frange &r, tree type, const irange &lhs, const frange &op2, relation_trio = TRIO_VARYING) const final override; @@ -169,12 +175,17 @@ public: bool op2_range (irange &r, tree type, const irange &lhs, const irange &op1, relation_trio = TRIO_VARYING) const final override; + bool op2_range (prange &r, tree type, + const irange &lhs, const prange &op1, + relation_trio = TRIO_VARYING) const final override; bool op2_range (frange &r, tree type, const irange &lhs, const frange &op1, relation_trio = TRIO_VARYING) const final override; relation_kind op1_op2_relation (const irange &lhs, const irange &, const irange &) const final override; + relation_kind op1_op2_relation (const irange &lhs, const prange &, + const prange &) const final override; relation_kind op1_op2_relation (const irange &lhs, const frange &, const frange &) const final override; void update_bitmask (irange &r, const irange &lh, @@ -182,6 +193,7 @@ public: // Check op1 and op2 for compatibility. bool operand_check_p (tree, tree t1, tree t2) const final override { return range_compatible_p (t1, t2); } + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; }; class operator_lt : public range_operator diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index 2f2f4bb2b5d..081e8fdba1f 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -1230,6 +1230,124 @@ operator_bitwise_or::pointers_handled_p (range_op_dispatch_type, return false; } +bool +operator_not_equal::fold_range (irange &r, tree type, + const prange &op1, + const prange &op2, + relation_trio rel) const +{ + if (relop_early_resolve (r, type, op1, op2, rel, VREL_NE)) + return true; + + // We can be sure the values are always equal or not if both ranges + // consist of a single value, and then compare them. + bool op1_const = wi::eq_p (op1.lower_bound (), op1.upper_bound ()); + bool op2_const = wi::eq_p (op2.lower_bound (), op2.upper_bound ()); + if (op1_const && op2_const) + { + if (wi::ne_p (op1.lower_bound (), op2.upper_bound())) + r = range_true (); + else + r = range_false (); + } + else + { + // If ranges do not intersect, we know the range is not equal, + // otherwise we don't know anything for sure. + prange tmp = op1; + tmp.intersect (op2); + if (tmp.undefined_p ()) + r = range_true (); + // Check if a constant cannot satisfy the bitmask requirements. + else if (op2_const && !op1.get_bitmask ().member_p (op2.lower_bound ())) + r = range_true (); + else if (op1_const && !op2.get_bitmask ().member_p (op1.lower_bound ())) + r = range_true (); + else + r = range_true_and_false (); + } + + //update_known_bitmask (r, NE_EXPR, op1, op2); + return true; +} + +bool +operator_not_equal::op1_range (prange &r, tree type, + const irange &lhs, + const prange &op2, + relation_trio) const +{ + switch (get_bool_state (r, lhs, type)) + { + case BRS_TRUE: + // If the result is true, the only time we know anything is if + // OP2 is a constant. + if (!op2.undefined_p () + && wi::eq_p (op2.lower_bound(), op2.upper_bound())) + { + r = op2; + r.invert (); + } + else + r.set_varying (type); + break; + + case BRS_FALSE: + // If it's false, the result is the same as OP2. + r = op2; + break; + + default: + break; + } + return true; +} + + +bool +operator_not_equal::op2_range (prange &r, tree type, + const irange &lhs, + const prange &op1, + relation_trio rel) const +{ + return operator_not_equal::op1_range (r, type, lhs, op1, rel.swap_op1_op2 ()); +} + +relation_kind +operator_not_equal::op1_op2_relation (const irange &lhs, const prange &, + const prange &) const +{ + if (lhs.undefined_p ()) + return VREL_UNDEFINED; + + // FALSE = op1 != op2 indicates EQ_EXPR. + if (lhs.zero_p ()) + return VREL_EQ; + + // TRUE = op1 != op2 indicates NE_EXPR. + if (!range_includes_zero_p (lhs)) + return VREL_NE; + return VREL_VARYING; +} + +bool +operator_not_equal::pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + return dispatch == RO_IPP; + case DISPATCH_OP1_RANGE: + case DISPATCH_OP2_RANGE: + return dispatch == RO_PIP; + case DISPATCH_OP1_OP2_RELATION: + return dispatch == RO_IPP; + default: + return true; + } +} + // Initialize any pointer operators to the primary table void From patchwork Sat May 4 08:30:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931254 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=AwxqbuqO; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWh1n1LKJz1ybC for ; Sat, 4 May 2024 18:39:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6EE1D386F429 for ; Sat, 4 May 2024 08:39:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by sourceware.org (Postfix) with ESMTPS id 7BBB3384403B for ; Sat, 4 May 2024 08:31:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7BBB3384403B Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7BBB3384403B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.139.111.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811480; cv=none; b=xW4AS9T4F2Svh4lWDxTcZISHKcZnMG7bF+m3OzVS0bKYYDJLamjSRqM/iVsU5ZRCWIYFREk8tKQiaJWCv5iZrz8bt4EykGrI+IlygMirVPw88Ei7Fb5IW628Tk9DNHqJn2T9ShPxDLPvj2uOdsyC8K1ddiiLNkWuZIvAFlpIEPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811480; c=relaxed/simple; bh=bCur2Kk8vxPoMYyyVl7J1BDqFVLAEExbRKChgCrC3D4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qYtxQd57OGDuGLFgKoiQWt+m8JdATO9Wc5ZJiWsWiLIKGe7e7J5rsdNqke5RZOAqCxsUm7maR88lECRJHJcRUnz68JaHQeByawZWN3wmizLcIlTtOfLbFDtHYs9c03NHnIRe/nNrIzxW13dLf9BRIKbnAzTEMcIXIx85HTicX7s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811465; 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=ALew2/nYdmRyoKvj5kDTZWAf+oVrQ8G+0AUovdb9U9g=; b=AwxqbuqOZAWnw5nhCKP8JpIQxmowhHc2dT8he6FVuO9m9OpmCT4rGBJsxjYrrcGDfkcFlR evKVPL16HDYpV4Ydau4ro6mRxM/db9EnJoNfd+6pOIiSOxMaLc6/uGjkwxxcdwQsFEm8av 7msGCVFMVryYiCuDSVkl4NwNTqNPEQY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-342-BchHCyW3PzK0g44nNbWyCw-1; Sat, 04 May 2024 04:31:03 -0400 X-MC-Unique: BchHCyW3PzK0g44nNbWyCw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CF28F18065AF for ; Sat, 4 May 2024 08:31:02 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 84F8D151EF; Sat, 4 May 2024 08:31:02 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448V1L0139856 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:31:01 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448V1sV139855; Sat, 4 May 2024 10:31:01 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 18/23] Implement operator_equal for prange. Date: Sat, 4 May 2024 10:30:46 +0200 Message-ID: <20240504083056.139719-19-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * range-op-mixed.h: Add overloaded declarations for pointer variants. * range-op-ptr.cc (operator_equal::fold_range): New. (operator_equal::op1_range): New. (operator_equal::op2_range): New. (operator_equal::op1_op2_relation): New. (operator_equal::pointers_handled_p): New. --- gcc/range-op-mixed.h | 12 +++++ gcc/range-op-ptr.cc | 117 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index 980611dc339..ee8d9dd328f 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -115,6 +115,9 @@ public: bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio = TRIO_VARYING) const final override; + bool fold_range (irange &r, tree type, + const prange &op1, const prange &op2, + relation_trio = TRIO_VARYING) const final override; bool fold_range (irange &r, tree type, const frange &op1, const frange &op2, relation_trio = TRIO_VARYING) const final override; @@ -122,6 +125,9 @@ public: bool op1_range (irange &r, tree type, const irange &lhs, const irange &val, relation_trio = TRIO_VARYING) const final override; + bool op1_range (prange &r, tree type, + const irange &lhs, const prange &val, + relation_trio = TRIO_VARYING) const final override; bool op1_range (frange &r, tree type, const irange &lhs, const frange &op2, relation_trio = TRIO_VARYING) const final override; @@ -129,12 +135,17 @@ public: bool op2_range (irange &r, tree type, const irange &lhs, const irange &val, relation_trio = TRIO_VARYING) const final override; + bool op2_range (prange &r, tree type, + const irange &lhs, const prange &val, + relation_trio = TRIO_VARYING) const final override; bool op2_range (frange &r, tree type, const irange &lhs, const frange &op1, relation_trio rel = TRIO_VARYING) const final override; relation_kind op1_op2_relation (const irange &lhs, const irange &, const irange &) const final override; + relation_kind op1_op2_relation (const irange &lhs, const prange &, + const prange &) const final override; relation_kind op1_op2_relation (const irange &lhs, const frange &, const frange &) const final override; void update_bitmask (irange &r, const irange &lh, @@ -142,6 +153,7 @@ public: // Check op1 and op2 for compatibility. bool operand_check_p (tree, tree t1, tree t2) const final override { return range_compatible_p (t1, t2); } + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; }; class operator_not_equal : public range_operator diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index 081e8fdba1f..fb2888bf079 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -1230,6 +1230,123 @@ operator_bitwise_or::pointers_handled_p (range_op_dispatch_type, return false; } +bool +operator_equal::fold_range (irange &r, tree type, + const prange &op1, + const prange &op2, + relation_trio rel) const +{ + if (relop_early_resolve (r, type, op1, op2, rel, VREL_EQ)) + return true; + + // We can be sure the values are always equal or not if both ranges + // consist of a single value, and then compare them. + bool op1_const = wi::eq_p (op1.lower_bound (), op1.upper_bound ()); + bool op2_const = wi::eq_p (op2.lower_bound (), op2.upper_bound ()); + if (op1_const && op2_const) + { + if (wi::eq_p (op1.lower_bound (), op2.upper_bound())) + r = range_true (); + else + r = range_false (); + } + else + { + // If ranges do not intersect, we know the range is not equal, + // otherwise we don't know anything for sure. + prange tmp = op1; + tmp.intersect (op2); + if (tmp.undefined_p ()) + r = range_false (); + // Check if a constant cannot satisfy the bitmask requirements. + else if (op2_const && !op1.get_bitmask ().member_p (op2.lower_bound ())) + r = range_false (); + else if (op1_const && !op2.get_bitmask ().member_p (op1.lower_bound ())) + r = range_false (); + else + r = range_true_and_false (); + } + + //update_known_bitmask (r, EQ_EXPR, op1, op2); + return true; +} + +bool +operator_equal::op1_range (prange &r, tree type, + const irange &lhs, + const prange &op2, + relation_trio) const +{ + switch (get_bool_state (r, lhs, type)) + { + case BRS_TRUE: + // If it's true, the result is the same as OP2. + r = op2; + break; + + case BRS_FALSE: + // If the result is false, the only time we know anything is + // if OP2 is a constant. + if (!op2.undefined_p () + && wi::eq_p (op2.lower_bound(), op2.upper_bound())) + { + r = op2; + r.invert (); + } + else + r.set_varying (type); + break; + + default: + break; + } + return true; +} + +bool +operator_equal::op2_range (prange &r, tree type, + const irange &lhs, + const prange &op1, + relation_trio rel) const +{ + return operator_equal::op1_range (r, type, lhs, op1, rel.swap_op1_op2 ()); +} + +relation_kind +operator_equal::op1_op2_relation (const irange &lhs, const prange &, + const prange &) const +{ + if (lhs.undefined_p ()) + return VREL_UNDEFINED; + + // FALSE = op1 == op2 indicates NE_EXPR. + if (lhs.zero_p ()) + return VREL_NE; + + // TRUE = op1 == op2 indicates EQ_EXPR. + if (!range_includes_zero_p (lhs)) + return VREL_EQ; + return VREL_VARYING; +} + +bool +operator_equal::pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + return dispatch == RO_IPP; + case DISPATCH_OP1_RANGE: + case DISPATCH_OP2_RANGE: + return dispatch == RO_PIP; + case DISPATCH_OP1_OP2_RELATION: + return dispatch == RO_IPP; + default: + return true; + } +} + bool operator_not_equal::fold_range (irange &r, tree type, const prange &op1, From patchwork Sat May 4 08:30:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931244 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=eBUDQKxk; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgvM2cl6z1xnS for ; Sat, 4 May 2024 18:34:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C8CE386F467 for ; Sat, 4 May 2024 08:34:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by sourceware.org (Postfix) with ESMTPS id 11434384477E for ; Sat, 4 May 2024 08:31:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11434384477E Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 11434384477E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.139.111.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811476; cv=none; b=ZoJHQOwj5lhI5kGTMHodFvYPYMllwFgT3BZmJ9OsRW3nxDC5cU/w0X7oLgftMgChNITHlKWUuMAqoLFSAxbbt0vCOfoQQY6q4Rgv4Jn/8hzGqIUJpTaA97HXn2h3Ci1R/dIREK3SP3lSc3nZzcWY7YOX5HN0XkqRXy59+F5TSAk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811476; c=relaxed/simple; bh=Bs8cfFEZMvYED9G5Iz4ZmoacuN42K2x67SB6HZ5AhbM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XKd+N+cdNfkhtAP/+TVglH7NiDdqTl5oqssbOEi2CElKSguIXrqEAulpV/53dcvTR5L7pLXlfNfFQdk7a1O/4oGcX4iYV8YR13/Nq7Qn4OThhclicXY6QjJGXVTVvDB+E/rDh4Tbo0NyW3hZFKKlFYq0w1ZWe5823UFbX91ptwQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811464; 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=FedtA4gKRdO4adKqhCcyCkUqACmU8Hg3QiKa8Xz/gaM=; b=eBUDQKxkB8ExnEN2WbNgClP8PufCtXzSJtkIz5T0avqQS3kLt2slli20G8WvG0TNISolBL hXk1Xx00JWdQ3r12NtQDEh/q0oyh0Dg20/hEXhw+2Ev0GTLwPPIQ/eCMHMXE385JoFFE8H BztnlwyhkM1JfzLz3o38rFvhqli/yrc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-596-1VZ8BxupMKGr6pQSrXfwoQ-1; Sat, 04 May 2024 04:31:03 -0400 X-MC-Unique: 1VZ8BxupMKGr6pQSrXfwoQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E7F9F18065AB for ; Sat, 4 May 2024 08:31:02 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A420A16D94; Sat, 4 May 2024 08:31:02 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448V1YS139860 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:31:01 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448V13K139859; Sat, 4 May 2024 10:31:01 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 19/23] Implement operator_lt for prange. Date: Sat, 4 May 2024 10:30:47 +0200 Message-ID: <20240504083056.139719-20-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * range-op-mixed.h: Add overloaded declarations for pointer variants. * range-op-ptr.cc (max_limit): New. (min_limit): New. (build_lt): New. (build_le): New. (build_gt): New. (build_ge): New. (operator_lt::fold_range): New. (operator_lt::op1_range): New. (operator_lt::op2_range): New. (operator_lt::op1_op2_relation): New. (operator_lt::pointers_handled_p): New. --- gcc/range-op-mixed.h | 12 +++ gcc/range-op-ptr.cc | 174 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 186 insertions(+) diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index ee8d9dd328f..b82d06572a7 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -219,23 +219,34 @@ public: bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio = TRIO_VARYING) const final override; + bool fold_range (irange &r, tree type, + const prange &op1, const prange &op2, + relation_trio = TRIO_VARYING) const final override; bool fold_range (irange &r, tree type, const frange &op1, const frange &op2, relation_trio = TRIO_VARYING) const final override; bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio = TRIO_VARYING) const final override; + bool op1_range (prange &r, tree type, + const irange &lhs, const prange &op2, + relation_trio = TRIO_VARYING) const final override; bool op1_range (frange &r, tree type, const irange &lhs, const frange &op2, relation_trio = TRIO_VARYING) const final override; bool op2_range (irange &r, tree type, const irange &lhs, const irange &op1, relation_trio = TRIO_VARYING) const final override; + bool op2_range (prange &r, tree type, + const irange &lhs, const prange &op1, + relation_trio = TRIO_VARYING) const final override; bool op2_range (frange &r, tree type, const irange &lhs, const frange &op1, relation_trio = TRIO_VARYING) const final override; relation_kind op1_op2_relation (const irange &lhs, const irange &, const irange &) const final override; + relation_kind op1_op2_relation (const irange &lhs, const prange &, + const prange &) const final override; relation_kind op1_op2_relation (const irange &lhs, const frange &, const frange &) const final override; void update_bitmask (irange &r, const irange &lh, @@ -243,6 +254,7 @@ public: // Check op1 and op2 for compatibility. bool operand_check_p (tree, tree t1, tree t2) const final override { return range_compatible_p (t1, t2); } + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; }; class operator_le : public range_operator diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index fb2888bf079..11629ba6d8d 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -262,6 +262,69 @@ range_operator::update_bitmask (irange &, { } +// Return the upper limit for a type. + +static inline wide_int +max_limit (const_tree type) +{ + return wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type)); +} + +// Return the lower limit for a type. + +static inline wide_int +min_limit (const_tree type) +{ + return wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type)); +} + +// Build a range that is < VAL and store it in R. + +static void +build_lt (prange &r, tree type, const prange &val) +{ + wi::overflow_type ov; + wide_int lim = wi::sub (val.upper_bound (), 1, UNSIGNED, &ov); + + // If val - 1 underflows, check if X < MIN, which is an empty range. + if (ov) + r.set_undefined (); + else + r.set (type, min_limit (type), lim); +} + +// Build a range that is <= VAL and store it in R. + +static void +build_le (prange &r, tree type, const prange &val) +{ + r.set (type, min_limit (type), val.upper_bound ()); +} + +// Build a range that is > VAL and store it in R. + +static void +build_gt (prange &r, tree type, const prange &val) +{ + wi::overflow_type ov; + wide_int lim = wi::add (val.lower_bound (), 1, UNSIGNED, &ov); + + // If val + 1 overflows, check is for X > MAX, which is an empty range. + if (ov) + r.set_undefined (); + else + r.set (type, lim, max_limit (type)); + +} + +// Build a range that is >= VAL and store it in R. + +static void +build_ge (prange &r, tree type, const prange &val) +{ + r.set (type, val.lower_bound (), max_limit (type)); +} + class pointer_plus_operator : public range_operator { using range_operator::update_bitmask; @@ -1465,6 +1528,117 @@ operator_not_equal::pointers_handled_p (range_op_dispatch_type type, } } +bool +operator_lt::fold_range (irange &r, tree type, + const prange &op1, + const prange &op2, + relation_trio rel) const +{ + if (relop_early_resolve (r, type, op1, op2, rel, VREL_LT)) + return true; + + signop sign = TYPE_SIGN (op1.type ()); + gcc_checking_assert (sign == TYPE_SIGN (op2.type ())); + + if (wi::lt_p (op1.upper_bound (), op2.lower_bound (), sign)) + r = range_true (); + else if (!wi::lt_p (op1.lower_bound (), op2.upper_bound (), sign)) + r = range_false (); + // Use nonzero bits to determine if < 0 is false. + else if (op2.zero_p () && !wi::neg_p (op1.get_nonzero_bits (), sign)) + r = range_false (); + else + r = range_true_and_false (); + + //update_known_bitmask (r, LT_EXPR, op1, op2); + return true; +} + +bool +operator_lt::op1_range (prange &r, tree type, + const irange &lhs, + const prange &op2, + relation_trio) const +{ + if (op2.undefined_p ()) + return false; + + switch (get_bool_state (r, lhs, type)) + { + case BRS_TRUE: + build_lt (r, type, op2); + break; + + case BRS_FALSE: + build_ge (r, type, op2); + break; + + default: + break; + } + return true; +} + +bool +operator_lt::op2_range (prange &r, tree type, + const irange &lhs, + const prange &op1, + relation_trio) const +{ + if (op1.undefined_p ()) + return false; + + switch (get_bool_state (r, lhs, type)) + { + case BRS_TRUE: + build_gt (r, type, op1); + break; + + case BRS_FALSE: + build_le (r, type, op1); + break; + + default: + break; + } + return true; +} + +relation_kind +operator_lt::op1_op2_relation (const irange &lhs, const prange &, + const prange &) const +{ + if (lhs.undefined_p ()) + return VREL_UNDEFINED; + + // FALSE = op1 < op2 indicates GE_EXPR. + if (lhs.zero_p ()) + return VREL_GE; + + // TRUE = op1 < op2 indicates LT_EXPR. + if (!range_includes_zero_p (lhs)) + return VREL_LT; + return VREL_VARYING; +} + +bool +operator_lt::pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + return dispatch == RO_IPP; + case DISPATCH_OP1_RANGE: + case DISPATCH_OP2_RANGE: + return dispatch == RO_PIP; + case DISPATCH_OP1_OP2_RELATION: + return dispatch == RO_IPP; + default: + return true; + } +} + // Initialize any pointer operators to the primary table void From patchwork Sat May 4 08:30:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931249 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=cAE+jLjU; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgxn6znsz23tp for ; Sat, 4 May 2024 18:36:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4201F386F430 for ; Sat, 4 May 2024 08:36:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by sourceware.org (Postfix) with ESMTPS id 37F28384404C for ; Sat, 4 May 2024 08:31:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37F28384404C Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 37F28384404C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.139.111.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811477; cv=none; b=mdBMPit2JugaVLppPBRMgA1qoXowTlwwph/m8TLZcj7/gq9dzQaovzxBNG/aIl7wsBsl4xRVtV0IyzMzjtSVrDvpm3sx3jN7Sjfgt7HwTaPCZK7vTBakPH5ZrXxDIravBkt4WEKlqEMs7yPUqgb0ICDAV+DvviBNxZZSJ+SjENI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811477; c=relaxed/simple; bh=rqgbsIIZFv3M61Vvj5VYsyHSiwRgg1ZYTbYWaFlFpy0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vVxOgrBPgEMYAwpqGESy1DB3WxX38pb7BoU2RE/nlOmvMCuRjCmPF7jolIcn7WEXP37c3IQQqHxaG4yjTSy8KEd9OohSBke/FuMEImHpxRnXNb+VP/Da6LVWFm4pzNIch9IZYAH9QOrW8X/Z4jc5AH4JXsocsH2fzKCKN2jh8GM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811464; 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=U62yWh/rS5Mw5DbyNgRS5VnFu5NfVHC6U0E5+HNkjKs=; b=cAE+jLjUGohVqMOTNz/N0TwlW2TfdrHqjHDTGr0yU7cgFDTA7H6qerUH68XGDB3yPqiw3S Wr0189J87JhP2vtPfO56L6j73JRRmd818EqvlF+W6WuftDOGVs799tXjWwTHdwR9vsKqY6 +n+pCkCM8DuGkpm8pRleKAXQvY/ibgw= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-596-uBQFQ4xJP3CulBwobYiz8w-1; Sat, 04 May 2024 04:31:03 -0400 X-MC-Unique: uBQFQ4xJP3CulBwobYiz8w-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1798A29AA387 for ; Sat, 4 May 2024 08:31:03 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C813F492BC6; Sat, 4 May 2024 08:31:02 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448V1M1139864 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:31:01 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448V1Wh139863; Sat, 4 May 2024 10:31:01 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 20/23] Implement operator_le for prange. Date: Sat, 4 May 2024 10:30:48 +0200 Message-ID: <20240504083056.139719-21-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * range-op-mixed.h: Add overloaded declarations for pointer variants. * range-op-ptr.cc (operator_le::fold_range): New. (operator_le::op1_range): New. (operator_le::op2_range): New. (operator_le::op1_op2_relation): New. (operator_le::pointers_handled_p): New. --- gcc/range-op-mixed.h | 12 +++++ gcc/range-op-ptr.cc | 108 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index b82d06572a7..571729e2ab6 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -268,6 +268,9 @@ public: bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio = TRIO_VARYING) const final override; + bool fold_range (irange &r, tree type, + const prange &op1, const prange &op2, + relation_trio = TRIO_VARYING) const final override; bool fold_range (irange &r, tree type, const frange &op1, const frange &op2, relation_trio rel = TRIO_VARYING) const final override; @@ -275,6 +278,9 @@ public: bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio = TRIO_VARYING) const final override; + bool op1_range (prange &r, tree type, + const irange &lhs, const prange &op2, + relation_trio = TRIO_VARYING) const final override; bool op1_range (frange &r, tree type, const irange &lhs, const frange &op2, relation_trio rel = TRIO_VARYING) const final override; @@ -282,12 +288,17 @@ public: bool op2_range (irange &r, tree type, const irange &lhs, const irange &op1, relation_trio = TRIO_VARYING) const final override; + bool op2_range (prange &r, tree type, + const irange &lhs, const prange &op1, + relation_trio = TRIO_VARYING) const final override; bool op2_range (frange &r, tree type, const irange &lhs, const frange &op1, relation_trio rel = TRIO_VARYING) const final override; relation_kind op1_op2_relation (const irange &lhs, const irange &, const irange &) const final override; + relation_kind op1_op2_relation (const irange &lhs, const prange &, + const prange &) const final override; relation_kind op1_op2_relation (const irange &lhs, const frange &, const frange &) const final override; void update_bitmask (irange &r, const irange &lh, @@ -295,6 +306,7 @@ public: // Check op1 and op2 for compatibility. bool operand_check_p (tree, tree t1, tree t2) const final override { return range_compatible_p (t1, t2); } + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; }; class operator_gt : public range_operator diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index 11629ba6d8d..eb28211b583 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -1639,6 +1639,114 @@ operator_lt::pointers_handled_p (range_op_dispatch_type type, } } +bool +operator_le::fold_range (irange &r, tree type, + const prange &op1, + const prange &op2, + relation_trio rel) const +{ + if (relop_early_resolve (r, type, op1, op2, rel, VREL_LE)) + return true; + + signop sign = TYPE_SIGN (op1.type ()); + gcc_checking_assert (sign == TYPE_SIGN (op2.type ())); + + if (wi::le_p (op1.upper_bound (), op2.lower_bound (), sign)) + r = range_true (); + else if (!wi::le_p (op1.lower_bound (), op2.upper_bound (), sign)) + r = range_false (); + else + r = range_true_and_false (); + + //update_known_bitmask (r, LE_EXPR, op1, op2); + return true; +} + +bool +operator_le::op1_range (prange &r, tree type, + const irange &lhs, + const prange &op2, + relation_trio) const +{ + if (op2.undefined_p ()) + return false; + + switch (get_bool_state (r, lhs, type)) + { + case BRS_TRUE: + build_le (r, type, op2); + break; + + case BRS_FALSE: + build_gt (r, type, op2); + break; + + default: + break; + } + return true; +} + +bool +operator_le::op2_range (prange &r, tree type, + const irange &lhs, + const prange &op1, + relation_trio) const +{ + if (op1.undefined_p ()) + return false; + + switch (get_bool_state (r, lhs, type)) + { + case BRS_TRUE: + build_ge (r, type, op1); + break; + + case BRS_FALSE: + build_lt (r, type, op1); + break; + + default: + break; + } + return true; +} + +relation_kind +operator_le::op1_op2_relation (const irange &lhs, const prange &, + const prange &) const +{ + if (lhs.undefined_p ()) + return VREL_UNDEFINED; + + // FALSE = op1 <= op2 indicates GT_EXPR. + if (lhs.zero_p ()) + return VREL_GT; + + // TRUE = op1 <= op2 indicates LE_EXPR. + if (!range_includes_zero_p (lhs)) + return VREL_LE; + return VREL_VARYING; +} + +bool +operator_le::pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + return dispatch == RO_IPP; + case DISPATCH_OP1_RANGE: + case DISPATCH_OP2_RANGE: + return dispatch == RO_PIP; + case DISPATCH_OP1_OP2_RELATION: + return dispatch == RO_IPP; + default: + return true; + } +} + // Initialize any pointer operators to the primary table void From patchwork Sat May 4 08:30:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931255 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HXT7+WdH; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWh340TCYz1xnT for ; Sat, 4 May 2024 18:41:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3D486386F42A for ; Sat, 4 May 2024 08:41:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id 9B764384403E for ; Sat, 4 May 2024 08:31:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B764384403E Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9B764384403E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811480; cv=none; b=t5FlKE1tkCre1yHN97K5mYEGe9L63GSlk+wxBGFNFthT3qo7KIFhOO3X7vBlZRWiq+3YpOpaX/EA7S/hEJnRbuVgSj39cH68D5HhPM0RDXOnuGYUTjN7xDYNMmRVqdP05svuxftHDeluasYutnnQ6qW9LVy05WCnCNT4uyhxKc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811480; c=relaxed/simple; bh=Breu3UR05fGzHaJvxvADaBbYaMHGIydfNtq0PLqkpV4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Nqq67Qf5PhX72mynp/KmlmB+h7IuoWge/ORlbzR2Hw2jd7k1EOB6WyoV1fTxl7XgkFAB0/tGqBOYMVofq5C5bGeHNn5s/OAPK0tTDq/T9TKeFAxrGFqrxVwvpKkDcSFnn8m/Z+gju+GDWgm5cTBOXi4SlaypPkP1UK1YjphcBwo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811466; 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=cxcZunfNo9dBQ2uM74/bArVcYkL+f5QyeAVg4C0WxWk=; b=HXT7+WdHxa6EOr8p2l+HrB6qOYNMnN82XNmshitrey3kT2J1cvh8c0n9fgIcwh9wQ4ThTx GbquU4ERGoJWJH+gpAlfIS9/nKKL5Bbh1DFh8cAPnpJE4FNYEzJn09UJwH9l2C7GoRsJp8 4yy0NNvQi8ypH3JLIPA47UjRjwDBPmM= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-547-gIQFf4_GN4eURjf1JLGHsA-1; Sat, 04 May 2024 04:31:03 -0400 X-MC-Unique: gIQFf4_GN4eURjf1JLGHsA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 40902380621C for ; Sat, 4 May 2024 08:31:03 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF80F492BC7; Sat, 4 May 2024 08:31:02 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448V1CD139868 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:31:01 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448V1EZ139867; Sat, 4 May 2024 10:31:01 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 21/23] Implement operator_gt for prange. Date: Sat, 4 May 2024 10:30:49 +0200 Message-ID: <20240504083056.139719-22-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * range-op-mixed.h: Add overloaded declarations for pointer variants. * range-op-ptr.cc (operator_gt::fold_range): New. (operator_gt::op1_range): New. (operator_gt::op2_range): New. (operator_gt::op1_op2_relation): New. (operator_gt::pointers_handled_p): New. --- gcc/range-op-mixed.h | 12 +++++ gcc/range-op-ptr.cc | 106 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index 571729e2ab6..f7a07b19635 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -320,6 +320,9 @@ public: bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio = TRIO_VARYING) const final override; + bool fold_range (irange &r, tree type, + const prange &op1, const prange &op2, + relation_trio = TRIO_VARYING) const final override; bool fold_range (irange &r, tree type, const frange &op1, const frange &op2, relation_trio = TRIO_VARYING) const final override; @@ -327,6 +330,9 @@ public: bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio = TRIO_VARYING) const final override; + bool op1_range (prange &r, tree type, + const irange &lhs, const prange &op2, + relation_trio = TRIO_VARYING) const final override; bool op1_range (frange &r, tree type, const irange &lhs, const frange &op2, relation_trio = TRIO_VARYING) const final override; @@ -334,11 +340,16 @@ public: bool op2_range (irange &r, tree type, const irange &lhs, const irange &op1, relation_trio = TRIO_VARYING) const final override; + bool op2_range (prange &r, tree type, + const irange &lhs, const prange &op1, + relation_trio = TRIO_VARYING) const final override; bool op2_range (frange &r, tree type, const irange &lhs, const frange &op1, relation_trio = TRIO_VARYING) const final override; relation_kind op1_op2_relation (const irange &lhs, const irange &, const irange &) const final override; + relation_kind op1_op2_relation (const irange &lhs, const prange &, + const prange &) const final override; relation_kind op1_op2_relation (const irange &lhs, const frange &, const frange &) const final override; void update_bitmask (irange &r, const irange &lh, @@ -346,6 +357,7 @@ public: // Check op1 and op2 for compatibility. bool operand_check_p (tree, tree t1, tree t2) const final override { return range_compatible_p (t1, t2); } + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; }; class operator_ge : public range_operator diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index eb28211b583..441a18c08c7 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -1747,6 +1747,112 @@ operator_le::pointers_handled_p (range_op_dispatch_type type, } } +bool +operator_gt::fold_range (irange &r, tree type, + const prange &op1, const prange &op2, + relation_trio rel) const +{ + if (relop_early_resolve (r, type, op1, op2, rel, VREL_GT)) + return true; + + signop sign = TYPE_SIGN (op1.type ()); + gcc_checking_assert (sign == TYPE_SIGN (op2.type ())); + + if (wi::gt_p (op1.lower_bound (), op2.upper_bound (), sign)) + r = range_true (); + else if (!wi::gt_p (op1.upper_bound (), op2.lower_bound (), sign)) + r = range_false (); + else + r = range_true_and_false (); + + //update_known_bitmask (r, GT_EXPR, op1, op2); + return true; +} + +bool +operator_gt::op1_range (prange &r, tree type, + const irange &lhs, const prange &op2, + relation_trio) const +{ + if (op2.undefined_p ()) + return false; + + switch (get_bool_state (r, lhs, type)) + { + case BRS_TRUE: + build_gt (r, type, op2); + break; + + case BRS_FALSE: + build_le (r, type, op2); + break; + + default: + break; + } + return true; +} + +bool +operator_gt::op2_range (prange &r, tree type, + const irange &lhs, + const prange &op1, + relation_trio) const +{ + if (op1.undefined_p ()) + return false; + + switch (get_bool_state (r, lhs, type)) + { + case BRS_TRUE: + build_lt (r, type, op1); + break; + + case BRS_FALSE: + build_ge (r, type, op1); + break; + + default: + break; + } + return true; +} + +relation_kind +operator_gt::op1_op2_relation (const irange &lhs, const prange &, + const prange &) const +{ + if (lhs.undefined_p ()) + return VREL_UNDEFINED; + + // FALSE = op1 > op2 indicates LE_EXPR. + if (lhs.zero_p ()) + return VREL_LE; + + // TRUE = op1 > op2 indicates GT_EXPR. + if (!range_includes_zero_p (lhs)) + return VREL_GT; + return VREL_VARYING; +} + +bool +operator_gt::pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + return dispatch == RO_IPP; + case DISPATCH_OP1_RANGE: + case DISPATCH_OP2_RANGE: + return dispatch == RO_PIP; + case DISPATCH_OP1_OP2_RELATION: + return dispatch == RO_IPP; + default: + return true; + } +} + // Initialize any pointer operators to the primary table void From patchwork Sat May 4 08:30:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931253 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gUTAWYXd; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWh0Y61BGz1ybC for ; Sat, 4 May 2024 18:38:53 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0EC7D3844052 for ; Sat, 4 May 2024 08:38:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id A887B3844028 for ; Sat, 4 May 2024 08:31:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A887B3844028 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A887B3844028 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811477; cv=none; b=EpVarDVnnlQH6QxNe2Zc9TjAB5N4yZBAqzwLSm1BkxkT+dpaip+L1BtJIKSSdGgVu29ifPggFpSfTXhXcqvGlo7Xkz0J1yQSXSFDco8hT4iDWKFChBO8d+M7mGeH/aqz5dMRLsc+NaclEYrG3UE5/5LFlv5F1AcvznfDE+E2tq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811477; c=relaxed/simple; bh=q58MqJ7h1XlADptHWCtRkZ6HcXA0RqBRk7oqMjMDQYc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=G/TM6Ik3LKAFfSmNyYbW9W+xqt8ZjkBXPDwkkB3wodEhvjCiI0hbxjYXYTHDN+65ar/g19hkXSPqa2DSzuTz+XfDR0PC1QgDIkPc6Gw9jgmlIUrpU3OZ0Lo/yWkCFtehe2fHoWvHIiwcY9KXglAbx1evpgvlvmTXe2DCp6Lqq9k= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811465; 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=fv5EyNUQ0+eD8QjWiVRzqIrWnp6/VdT4r1O7Wer0eUk=; b=gUTAWYXdta8xol4ZnXZ5QuN+5bkVeRYZXnlMO/Wwmv3bAVbxBQp0WUsP66xSycYn1oYkie SDgbzYkw7WRGCJ4J47bSREBMKxFFIe+xVrT71k4S0c0lFFzzhhKKbSzHHm990uSHwnEvtb RX6ablTzYJPrLHJqf7LT7jG28FO/nKw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-131-QPQFz8CiMeCdgZVkcof-qQ-1; Sat, 04 May 2024 04:31:03 -0400 X-MC-Unique: QPQFz8CiMeCdgZVkcof-qQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5E6D7812C4F for ; Sat, 4 May 2024 08:31:03 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1B2EC2166AF5; Sat, 4 May 2024 08:31:02 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448V1Is139872 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:31:01 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448V1n2139871; Sat, 4 May 2024 10:31:01 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 22/23] Implement operator_ge for prange.... Date: Sat, 4 May 2024 10:30:50 +0200 Message-ID: <20240504083056.139719-23-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * range-op-mixed.h: Add overloaded declarations for pointer variants. * range-op-ptr.cc (operator_ge::fold_range): New. (operator_ge::op1_range): New. (operator_ge::op2_range): New. (operator_ge::op1_op2_relation): New. (operator_ge::pointers_handled_p): New. --- gcc/range-op-mixed.h | 12 +++++ gcc/range-op-ptr.cc | 108 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/gcc/range-op-mixed.h b/gcc/range-op-mixed.h index f7a07b19635..44d51d68655 100644 --- a/gcc/range-op-mixed.h +++ b/gcc/range-op-mixed.h @@ -371,6 +371,9 @@ public: bool fold_range (irange &r, tree type, const irange &op1, const irange &op2, relation_trio = TRIO_VARYING) const final override; + bool fold_range (irange &r, tree type, + const prange &op1, const prange &op2, + relation_trio = TRIO_VARYING) const final override; bool fold_range (irange &r, tree type, const frange &op1, const frange &op2, relation_trio = TRIO_VARYING) const final override; @@ -378,6 +381,9 @@ public: bool op1_range (irange &r, tree type, const irange &lhs, const irange &op2, relation_trio = TRIO_VARYING) const final override; + bool op1_range (prange &r, tree type, + const irange &lhs, const prange &op2, + relation_trio = TRIO_VARYING) const final override; bool op1_range (frange &r, tree type, const irange &lhs, const frange &op2, relation_trio = TRIO_VARYING) const final override; @@ -385,12 +391,17 @@ public: bool op2_range (irange &r, tree type, const irange &lhs, const irange &op1, relation_trio = TRIO_VARYING) const final override; + bool op2_range (prange &r, tree type, + const irange &lhs, const prange &op1, + relation_trio = TRIO_VARYING) const final override; bool op2_range (frange &r, tree type, const irange &lhs, const frange &op1, relation_trio = TRIO_VARYING) const final override; relation_kind op1_op2_relation (const irange &lhs, const irange &, const irange &) const final override; + relation_kind op1_op2_relation (const irange &lhs, const prange &, + const prange &) const final override; relation_kind op1_op2_relation (const irange &lhs, const frange &, const frange &) const final override; void update_bitmask (irange &r, const irange &lh, @@ -398,6 +409,7 @@ public: // Check op1 and op2 for compatibility. bool operand_check_p (tree, tree t1, tree t2) const final override { return range_compatible_p (t1, t2); } + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final override; }; class operator_identity : public range_operator diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index 441a18c08c7..466edc6bf74 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -1853,6 +1853,114 @@ operator_gt::pointers_handled_p (range_op_dispatch_type type, } } +bool +operator_ge::fold_range (irange &r, tree type, + const prange &op1, + const prange &op2, + relation_trio rel) const +{ + if (relop_early_resolve (r, type, op1, op2, rel, VREL_GE)) + return true; + + signop sign = TYPE_SIGN (op1.type ()); + gcc_checking_assert (sign == TYPE_SIGN (op2.type ())); + + if (wi::ge_p (op1.lower_bound (), op2.upper_bound (), sign)) + r = range_true (); + else if (!wi::ge_p (op1.upper_bound (), op2.lower_bound (), sign)) + r = range_false (); + else + r = range_true_and_false (); + + //update_known_bitmask (r, GE_EXPR, op1, op2); + return true; +} + +bool +operator_ge::op1_range (prange &r, tree type, + const irange &lhs, + const prange &op2, + relation_trio) const +{ + if (op2.undefined_p ()) + return false; + + switch (get_bool_state (r, lhs, type)) + { + case BRS_TRUE: + build_ge (r, type, op2); + break; + + case BRS_FALSE: + build_lt (r, type, op2); + break; + + default: + break; + } + return true; +} + +bool +operator_ge::op2_range (prange &r, tree type, + const irange &lhs, + const prange &op1, + relation_trio) const +{ + if (op1.undefined_p ()) + return false; + + switch (get_bool_state (r, lhs, type)) + { + case BRS_TRUE: + build_le (r, type, op1); + break; + + case BRS_FALSE: + build_gt (r, type, op1); + break; + + default: + break; + } + return true; +} + +relation_kind +operator_ge::op1_op2_relation (const irange &lhs, const prange &, + const prange &) const +{ + if (lhs.undefined_p ()) + return VREL_UNDEFINED; + + // FALSE = op1 >= op2 indicates LT_EXPR. + if (lhs.zero_p ()) + return VREL_LT; + + // TRUE = op1 >= op2 indicates GE_EXPR. + if (!range_includes_zero_p (lhs)) + return VREL_GE; + return VREL_VARYING; +} + +bool +operator_ge::pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + return dispatch == RO_IPP; + case DISPATCH_OP1_RANGE: + case DISPATCH_OP2_RANGE: + return dispatch == RO_PIP; + case DISPATCH_OP1_OP2_RELATION: + return dispatch == RO_IPP; + default: + return true; + } +} + // Initialize any pointer operators to the primary table void From patchwork Sat May 4 08:30:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1931250 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=N+as1OEv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWgz16CJ1z1ybC for ; Sat, 4 May 2024 18:37:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D48BF3842FDD for ; Sat, 4 May 2024 08:37:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by sourceware.org (Postfix) with ESMTPS id C8180384402B for ; Sat, 4 May 2024 08:31:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C8180384402B Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=localhost.redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C8180384402B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=207.211.30.44 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811477; cv=none; b=Yv68xg310GSkPxmGucZN+2eVdhArO74UsOMRSXKpW4p8Xlbc0Q8F6brqWR2DatRV/G4og+xx4TX5IF4FiUBgoUnPWWk4epROh+RppEEU1pMBDMBDCoqo8i28TEhhm9uTChxCE8ElcJv/d5g0FHreY9725hA/I9eZ0can2Z0vGX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714811477; c=relaxed/simple; bh=EHSNCay7FrK3X9YVuwnI6lw+NP1o82vuKeQuclhBrJM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=MWedWAWHhREIvp6gOlE3y53NqClXAUMWei2Wv6k87IYkrzmWxuRmXwBDnxWjmaXLOnNw/ZcU7Ntufzxa9aOiZBCxMVPUT017T6U9y7xxjFFem0qAKndZzVrB7ZJ1We3lpK6NbnjnjFmj7XqMpQrENMRjWBANp73Ht4Rju7JmJQg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714811465; 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=v06kmdwlDXaaOgtCfXcGLPWGpAKNlhlxDHvx4qXV2v4=; b=N+as1OEvB7bUUhzBj/lWTbKyoxjSRbl/iAfPaBbqENq2+B1V/gLZvCDs+BfaxvralLxkby Tdc6DKi1D+YUq+uCP1/18BOQBBf4yDILFlTmOD31h08jg/M5xqsVo0GF0pr31P7vjqy6TK wgLuugwsf7aQBdu8CEAGLezWRKY1cKg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-131-WFZzGwLHMxSb-e7-QAUCYQ-1; Sat, 04 May 2024 04:31:03 -0400 X-MC-Unique: WFZzGwLHMxSb-e7-QAUCYQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 82B1A18065AA for ; Sat, 4 May 2024 08:31:03 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F32AEC680; Sat, 4 May 2024 08:31:03 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.18.1/8.17.1) with ESMTPS id 4448V2es139876 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 4 May 2024 10:31:02 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.18.1/8.18.1/Submit) id 4448V2Lh139875; Sat, 4 May 2024 10:31:02 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 23/23] Add prange entries in gimple-range-op.cc. Date: Sat, 4 May 2024 10:30:51 +0200 Message-ID: <20240504083056.139719-24-aldyh@redhat.com> In-Reply-To: <20240504083056.139719-1-aldyh@redhat.com> References: <20240504083056.139719-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NO_DNS_FOR_FROM, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/ChangeLog: * gimple-range-op.cc (class cfn_pass_through_arg1): Add overloads for prange operations. (cfn_strlen): Same. --- gcc/gimple-range-op.cc | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index 587de186db2..55dfbb23ce2 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -311,12 +311,37 @@ public: r = lh; return true; } + virtual bool fold_range (prange &r, tree, const prange &lh, + const prange &, relation_trio) const + { + r = lh; + return true; + } virtual bool op1_range (irange &r, tree, const irange &lhs, const irange &, relation_trio) const { r = lhs; return true; } + virtual bool op1_range (prange &r, tree, const prange &lhs, + const prange &, relation_trio) const + { + r = lhs; + return true; + } + virtual bool pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const + { + switch (type) + { + case DISPATCH_FOLD_RANGE: + return dispatch == RO_PPP; + case DISPATCH_OP1_RANGE: + return dispatch == RO_PPP; + default: + return true; + } + } } op_cfn_pass_through_arg1; // Implement range operator for CFN_BUILT_IN_SIGNBIT. @@ -1107,6 +1132,17 @@ public: r.set (type, wi::zero (TYPE_PRECISION (type)), max - 2); return true; } + virtual bool pointers_handled_p (range_op_dispatch_type type, + unsigned dispatch) const + { + switch (type) + { + case DISPATCH_FOLD_RANGE: + return dispatch == RO_IPI; + default: + return true; + } + } } op_cfn_strlen;