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 4651F3858C52 for ; Sun, 28 Apr 2024 19:06:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4651F3858C52 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 4651F3858C52 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=1714331168; cv=none; b=IvU2X5KiXiYJgqiliXLNoH9RUoWR1fx5liTL3YsYmZZvCflzf9OolKowj8/Vv62Ofk2SO/4fxpkwR+58ICQG8UG+ec96t4bIrgnMG0EMsYCUEZWOnn9vKgx1AB+vDZNogCviAD84znM8fEg31EUWlSBB0kzkix3OAHUcOI8hw1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714331168; c=relaxed/simple; bh=aNIMNUdnG95M+2vvmnHJ3qR82V8edarK1IwpjBM28ck=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=iGYz2p5Lg+i3iCH+6r0r8LTsLJXMsK1DS4SkZGbr5+AcVx6vLM3ROImRoht5s6oJmHmC0eOOijfHYDnxsWayNm9+11ongBzn5DDOSRH6CCsjxmhwRHSbLnl2A7JY2Y7ODh9PqutLiE9Oi++BmFCNChC3QHBmc+8S+59SNmVdgEc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714331164; 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=e+1fbQYcUjH5ONUrj80u7t/TNbtdk25AxC6pOhLnzHc=; b=hmh6dC5NZrbDT2ZsKy9zlrygP6whqKYBZnyjDw/E18tilmkoLEP9MXHfOpH4PPNfzyFJdG gmvh4loA2WJhC9hnOqWhHzjZttg889pIb9xUZFYpkZBIxWmvyylfaPB7b9vcSMSz+TPkWz SW7IiRgOVxifxTs0Rqvc8CTBeVv2yWQ= 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-448-gckogbKtOqqSy-MWWY6uEw-1; Sun, 28 Apr 2024 15:06:02 -0400 X-MC-Unique: gckogbKtOqqSy-MWWY6uEw-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 DB201101042D for ; Sun, 28 Apr 2024 19:06:01 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.56]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8C14F202450F; Sun, 28 Apr 2024 19:06:01 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.2/8.17.1) with ESMTPS id 43SJ600Q1209652 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 28 Apr 2024 21:06:00 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.2/8.17.2/Submit) id 43SJ60ok1209651; Sun, 28 Apr 2024 21:06:00 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED 04/16] Add tree versions of lower and upper bounds to vrange. Date: Sun, 28 Apr 2024 21:05:42 +0200 Message-ID: <20240428190557.1209586-5-aldyh@redhat.com> In-Reply-To: <20240428190557.1209586-1-aldyh@redhat.com> References: <20240428190557.1209586-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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=WINDOWS-1252; x-default=true X-Spam-Status: No, score=-12.0 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: This patch adds vrange::lbound() and vrange::ubound() that return trees. These can be used in generic code that is type agnostic, and avoids special casing for pointers and integers in places where we handle both. It also cleans up a wart in the Value_Range class. gcc/ChangeLog: =09* tree-ssa-loop-niter.cc (refine_value_range_using_guard): Convert =09bound to wide_int. =09* value-range.cc (Value_Range::lower_bound): Remove. =09(Value_Range::upper_bound): Remove. =09(unsupported_range::lbound): New. =09(unsupported_range::ubound): New. =09(frange::lbound): New. =09(frange::ubound): New. =09(irange::lbound): New. =09(irange::ubound): New. =09* value-range.h (class vrange): Add lbound() and ubound(). =09(class irange): Same. =09(class frange): Same. =09(class unsupported_range): Same. =09(class Value_Range): Rename lower_bound and upper_bound to lbound =09and ubound respectively. --- gcc/tree-ssa-loop-niter.cc | 4 +-- gcc/value-range.cc | 56 ++++++++++++++++++++++++-------------- gcc/value-range.h | 13 +++++++-- 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc index cbc9dbc5a1f..adbc1936982 100644 --- a/gcc/tree-ssa-loop-niter.cc +++ b/gcc/tree-ssa-loop-niter.cc @@ -4067,7 +4067,7 @@ record_nonwrapping_iv (class loop *loop, tree base, t= ree step, gimple *stmt, Value_Range base_range (TREE_TYPE (orig_base)); if (get_range_query (cfun)->range_of_expr (base_range, orig_base) =09 && !base_range.undefined_p ()) -=09max =3D base_range.upper_bound (); +=09max =3D wi::to_wide (base_range.ubound ()); extreme =3D fold_convert (unsigned_type, low); if (TREE_CODE (orig_base) =3D=3D SSA_NAME =09 && TREE_CODE (high) =3D=3D INTEGER_CST @@ -4090,7 +4090,7 @@ record_nonwrapping_iv (class loop *loop, tree base, t= ree step, gimple *stmt, Value_Range base_range (TREE_TYPE (orig_base)); if (get_range_query (cfun)->range_of_expr (base_range, orig_base) =09 && !base_range.undefined_p ()) -=09min =3D base_range.lower_bound (); +=09min =3D wi::to_wide (base_range.lbound ()); extreme =3D fold_convert (unsigned_type, high); if (TREE_CODE (orig_base) =3D=3D SSA_NAME =09 && TREE_CODE (low) =3D=3D INTEGER_CST diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 632d77305cc..ccac517d4c4 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -37,26 +37,6 @@ irange::accept (const vrange_visitor &v) const v.visit (*this); } =20 -// Convenience function only available for integers and pointers. - -wide_int -Value_Range::lower_bound () const -{ - if (is_a (*m_vrange)) - return as_a (*m_vrange).lower_bound (); - gcc_unreachable (); -} - -// Convenience function only available for integers and pointers. - -wide_int -Value_Range::upper_bound () const -{ - if (is_a (*m_vrange)) - return as_a (*m_vrange).upper_bound (); - gcc_unreachable (); -} - void Value_Range::dump (FILE *out) const { @@ -211,6 +191,18 @@ unsupported_range::operator=3D (const vrange &r) return *this; } =20 +tree +unsupported_range::lbound () const +{ + return NULL; +} + +tree +unsupported_range::ubound () const +{ + return NULL; +} + // Assignment operator for generic ranges. Copying incompatible types // is not allowed. =20 @@ -957,6 +949,18 @@ frange::set_nonnegative (tree type) set (type, dconst0, frange_val_max (type)); } =20 +tree +frange::lbound () const +{ + return build_real (type (), lower_bound ()); +} + +tree +frange::ubound () const +{ + return build_real (type (), upper_bound ()); +} + // Here we copy between any two irange's. =20 irange & @@ -2086,6 +2090,18 @@ irange::union_bitmask (const irange &r) return true; } =20 +tree +irange::lbound () const +{ + return wide_int_to_tree (type (), lower_bound ()); +} + +tree +irange::ubound () const +{ + return wide_int_to_tree (type (), upper_bound ()); +} + void irange_bitmask::verify_mask () const { diff --git a/gcc/value-range.h b/gcc/value-range.h index b7c83982385..f216f1b82c1 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -96,6 +96,8 @@ public: virtual void set_nonnegative (tree type) =3D 0; virtual bool fits_p (const vrange &r) const =3D 0; virtual ~vrange () { } + virtual tree lbound () const =3D 0; + virtual tree ubound () const =3D 0; =20 bool varying_p () const; bool undefined_p () const; @@ -298,6 +300,8 @@ public: wide_int lower_bound (unsigned =3D 0) const; wide_int upper_bound (unsigned) const; wide_int upper_bound () const; + virtual tree lbound () const override; + virtual tree ubound () const override; =20 // Predicates. virtual bool zero_p () const override; @@ -419,6 +423,8 @@ public: void set_nonnegative (tree type) final override; bool fits_p (const vrange &) const final override; unsupported_range& operator=3D (const vrange &r); + tree lbound () const final override; + tree ubound () const final override; }; =20 // The NAN state as an opaque object. @@ -526,6 +532,8 @@ public: bool operator!=3D (const frange &r) const { return !(*this =3D=3D r); } const REAL_VALUE_TYPE &lower_bound () const; const REAL_VALUE_TYPE &upper_bound () const; + virtual tree lbound () const override; + virtual tree ubound () const override; nan_state get_nan_state () const; void update_nan (); void update_nan (bool sign); @@ -710,7 +718,6 @@ public: void dump (FILE *) const; static bool supports_type_p (const_tree type); =20 - // Convenience methods for vrange compatibility. tree type () { return m_vrange->type (); } bool varying_p () const { return m_vrange->varying_p (); } bool undefined_p () const { return m_vrange->undefined_p (); } @@ -726,8 +733,8 @@ public: { init (type); return m_vrange->set_nonzero (type); } bool nonzero_p () const { return m_vrange->nonzero_p (); } bool zero_p () const { return m_vrange->zero_p (); } - wide_int lower_bound () const; // For irange/prange comparability. - wide_int upper_bound () const; // For irange/prange comparability. + tree lbound () const { return m_vrange->lbound (); } + tree ubound () const { return m_vrange->ubound (); } void accept (const vrange_visitor &v) const { m_vrange->accept (v); } private: void init (tree type); --=20 2.44.0