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 [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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=WINDOWS-1252; x-default=true 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 List-Id: gcc/ChangeLog: =09* range-op-ptr.cc (class pointer_plus_operator): Add overloaded declarat= ions =09for pointer variants. =09(pointer_plus_operator::fold_range): New. =09(pointer_plus_operator::op2_range): New. =09(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, +=09=09=09 const prange &op1, +=09=09=09 const irange &op2, +=09=09=09 relation_trio) const final override; + virtual bool op2_range (irange &r, tree type, +=09=09=09 const prange &lhs, +=09=09=09 const prange &op1, +=09=09=09 relation_trio =3D TRIO_VARYING) const final override; virtual void wi_fold (irange &r, tree type, =09=09=09const wide_int &lh_lb, =09=09=09const wide_int &lh_ub, @@ -276,10 +285,99 @@ public: =09=09=09 const irange &lhs, =09=09=09 const irange &op1, =09=09=09 relation_trio =3D TRIO_VARYING) const; + bool pointers_handled_p (range_op_dispatch_type, unsigned) const final o= verride; void update_bitmask (irange &r, const irange &lh, const irange &rh) cons= t { update_known_bitmask (r, POINTER_PLUS_EXPR, lh, rh); } } op_pointer_plus; =20 +bool +pointer_plus_operator::fold_range (prange &r, tree type, +=09=09=09=09 const prange &op1, +=09=09=09=09 const irange &op2, +=09=09=09=09 relation_trio) const +{ + if (empty_range_varying (r, type, op1, op2)) + return true; + + const wide_int lh_lb =3D op1.lower_bound (); + const wide_int lh_ub =3D op1.upper_bound (); + const wide_int rh_lb =3D op2.lower_bound (); + const wide_int rh_ub =3D op2.upper_bound (); + + // Check for [0,0] + const, and simply return the const. + if (lh_lb =3D=3D 0 && lh_ub =3D=3D 0 && rh_lb =3D=3D 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 =3D &a[6]; + // ptr -=3D 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 +=09 || !wi::sign_mask (rh_ub))) + r.set_nonzero (type); + else if (lh_lb =3D=3D lh_ub && lh_lb =3D=3D 0 +=09 && rh_lb =3D=3D rh_ub && rh_lb =3D=3D 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, +=09=09=09=09 const prange &lhs ATTRIBUTE_UNUSED, +=09=09=09=09 const prange &op1 ATTRIBUTE_UNUSED, +=09=09=09=09 relation_trio trio) const +{ + relation_kind rel =3D trio.lhs_op1 (); + r.set_varying (type); + + // If the LHS and OP1 are equal, the op2 must be zero. + if (rel =3D=3D VREL_EQ) + r.set_zero (type); + // If the LHS and OP1 are not equal, the offset must be non-zero. + else if (rel =3D=3D VREL_NE) + r.set_nonzero (type); + else + return false; + return true; +} + +bool +pointer_plus_operator::pointers_handled_p (range_op_dispatch_type type, +=09=09=09=09=09 unsigned dispatch) const +{ + switch (type) + { + case DISPATCH_FOLD_RANGE: + return dispatch =3D=3D RO_PPI; + case DISPATCH_OP2_RANGE: + return dispatch =3D=3D RO_IPP; + default: + return true; + } +} + void pointer_plus_operator::wi_fold (irange &r, tree type, =09=09=09=09const wide_int &lh_lb, --=20 2.44.0