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