From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=WINDOWS-1252; x-default=true 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 List-Id: gcc/ChangeLog: =09* range-op-mixed.h: Add overloaded declarations for pointer variants. =09* range-op-ptr.cc (operator_equal::fold_range): New. =09(operator_equal::op1_range): New. =09(operator_equal::op2_range): New. =09(operator_equal::op1_op2_relation): New. =09(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, =09=09 const irange &op1, const irange &op2, =09=09 relation_trio =3D TRIO_VARYING) const final override; + bool fold_range (irange &r, tree type, +=09=09 const prange &op1, const prange &op2, +=09=09 relation_trio =3D TRIO_VARYING) const final override; bool fold_range (irange &r, tree type, =09=09 const frange &op1, const frange &op2, =09=09 relation_trio =3D TRIO_VARYING) const final override; @@ -122,6 +125,9 @@ public: bool op1_range (irange &r, tree type, =09=09 const irange &lhs, const irange &val, =09=09 relation_trio =3D TRIO_VARYING) const final override; + bool op1_range (prange &r, tree type, +=09=09 const irange &lhs, const prange &val, +=09=09 relation_trio =3D TRIO_VARYING) const final override; bool op1_range (frange &r, tree type, =09=09 const irange &lhs, const frange &op2, =09=09 relation_trio =3D TRIO_VARYING) const final override; @@ -129,12 +135,17 @@ public: bool op2_range (irange &r, tree type, =09=09 const irange &lhs, const irange &val, =09=09 relation_trio =3D TRIO_VARYING) const final override; + bool op2_range (prange &r, tree type, +=09=09 const irange &lhs, const prange &val, +=09=09 relation_trio =3D TRIO_VARYING) const final override; bool op2_range (frange &r, tree type, =09=09 const irange &lhs, const frange &op1, =09=09 relation_trio rel =3D TRIO_VARYING) const final override; =20 relation_kind op1_op2_relation (const irange &lhs, const irange &, =09=09=09=09 const irange &) const final override; + relation_kind op1_op2_relation (const irange &lhs, const prange &, +=09=09=09=09 const prange &) const final override; relation_kind op1_op2_relation (const irange &lhs, const frange &, =09=09=09=09 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 o= verride; }; =20 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_d= ispatch_type, return false; } =20 +bool +operator_equal::fold_range (irange &r, tree type, +=09=09=09 const prange &op1, +=09=09=09 const prange &op2, +=09=09=09 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 =3D wi::eq_p (op1.lower_bound (), op1.upper_bound ()); + bool op2_const =3D wi::eq_p (op2.lower_bound (), op2.upper_bound ()); + if (op1_const && op2_const) + { + if (wi::eq_p (op1.lower_bound (), op2.upper_bound())) +=09r =3D range_true (); + else +=09r =3D 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 =3D op1; + tmp.intersect (op2); + if (tmp.undefined_p ()) +=09r =3D range_false (); + // Check if a constant cannot satisfy the bitmask requirements. + else if (op2_const && !op1.get_bitmask ().member_p (op2.lower_bound = ())) +=09 r =3D range_false (); + else if (op1_const && !op2.get_bitmask ().member_p (op1.lower_bound = ())) +=09 r =3D range_false (); + else +=09r =3D range_true_and_false (); + } + + //update_known_bitmask (r, EQ_EXPR, op1, op2); + return true; +} + +bool +operator_equal::op1_range (prange &r, tree type, +=09=09=09 const irange &lhs, +=09=09=09 const prange &op2, +=09=09=09 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 =3D 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 () +=09 && wi::eq_p (op2.lower_bound(), op2.upper_bound())) +=09{ +=09 r =3D op2; +=09 r.invert (); +=09} + else +=09r.set_varying (type); + break; + + default: + break; + } + return true; +} + +bool +operator_equal::op2_range (prange &r, tree type, +=09=09=09 const irange &lhs, +=09=09=09 const prange &op1, +=09=09=09 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 &, +=09=09=09=09 const prange &) const +{ + if (lhs.undefined_p ()) + return VREL_UNDEFINED; + + // FALSE =3D op1 =3D=3D op2 indicates NE_EXPR. + if (lhs.zero_p ()) + return VREL_NE; + + // TRUE =3D op1 =3D=3D 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, +=09=09=09=09 unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + return dispatch =3D=3D RO_IPP; + case DISPATCH_OP1_RANGE: + case DISPATCH_OP2_RANGE: + return dispatch =3D=3D RO_PIP; + case DISPATCH_OP1_OP2_RELATION: + return dispatch =3D=3D RO_IPP; + default: + return true; + } +} + bool operator_not_equal::fold_range (irange &r, tree type, =09=09=09=09const prange &op1, --=20 2.44.0