From patchwork Tue Oct 20 13:59:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1384949 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=cOAYOFNP; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CFwGr4KQZz9sRk for ; Wed, 21 Oct 2020 00:59:32 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4B0D639450EE; Tue, 20 Oct 2020 13:59:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B0D639450EE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1603202370; bh=htrkGXSxyFIdc++NjEfmZy47EI+XLYRVUM9OO19B99A=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=cOAYOFNPjAD+yA2svkHp5YJUXo8IVRodXwzYu/e2xUt9iqzYH6EtNmnQNWRlurEw9 39d8q7j7wy4Eap8N9ampZSPvRgDvXDQl9MoXlshRNodPxSuHK8c3zes0h7gbvt/nV6 9uP0WOxEJwKJ46sGCWVqM2DJC0teztWh1FOOOqko= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id E5635385782C for ; Tue, 20 Oct 2020 13:59:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E5635385782C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-524-lQIcYiRHM3OqJOxxgS-E1A-1; Tue, 20 Oct 2020 09:59:20 -0400 X-MC-Unique: lQIcYiRHM3OqJOxxgS-E1A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B5C8C8463DD for ; Tue, 20 Oct 2020 13:59:19 +0000 (UTC) Received: from abulafia.quesejoda.com (ovpn-115-3.ams2.redhat.com [10.36.115.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5877160C0F; Tue, 20 Oct 2020 13:59:19 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.15.2/8.15.2) with ESMTPS id 09KDxGVX333145 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 20 Oct 2020 15:59:17 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.15.2/8.15.2/Submit) id 09KDxGsD333144; Tue, 20 Oct 2020 15:59:16 +0200 To: GCC patches Subject: [PATCH] Simplify and split irange::copy_legacy_range into two functions. Date: Tue, 20 Oct 2020 15:59:11 +0200 Message-Id: <20201020135911.333093-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" copy_legacy_range was a small but complex function. It was tricky to understand, and easy to introduce bugs into it. It also did unnecessary work on some code paths. This patch splits the function into two functions that are more efficient and easier to read (copy_to_legacy and copy_legacy_to_multi_range). Pushed. gcc/ChangeLog: * value-range.cc (irange::operator=): Split up call to copy_legacy_range into... (irange::copy_to_legacy): ...this. (irange::copy_legacy_to_multi_range): ...and this. (irange::copy_legacy_range): Remove. * value-range.h: Remove copoy_legacy_range. Add copy_legacy_to_multi_range and copy_to_legacy. --- gcc/value-range.cc | 72 +++++++++++++++++++++++++++------------------- gcc/value-range.h | 3 +- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index cdcc6c65594..7847104050c 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -35,18 +35,14 @@ along with GCC; see the file COPYING3. If not see irange & irange::operator= (const irange &src) { - if (legacy_mode_p () != src.legacy_mode_p ()) + if (legacy_mode_p ()) { - copy_legacy_range (src); + copy_to_legacy (src); return *this; } - if (legacy_mode_p ()) + if (src.legacy_mode_p ()) { - gcc_checking_assert (src.legacy_mode_p ()); - m_num_ranges = src.m_num_ranges; - m_base[0] = src.m_base[0]; - m_base[1] = src.m_base[1]; - m_kind = src.m_kind; + copy_legacy_to_multi_range (src); return *this; } @@ -81,44 +77,60 @@ irange::maybe_anti_range () const && upper_bound () == wi::max_value (precision, sign)); } -// Copy between a legacy and a multi-range, or vice-versa. - void -irange::copy_legacy_range (const irange &src) +irange::copy_legacy_to_multi_range (const irange &src) { - gcc_checking_assert (src.legacy_mode_p () != legacy_mode_p ()); + gcc_checking_assert (src.legacy_mode_p ()); + gcc_checking_assert (!legacy_mode_p ()); if (src.undefined_p ()) set_undefined (); else if (src.varying_p ()) set_varying (src.type ()); - else if (src.kind () == VR_ANTI_RANGE) - { - if (src.legacy_mode_p () && !range_has_numeric_bounds_p (&src)) - set_varying (src.type ()); - else - set (src.min (), src.max (), VR_ANTI_RANGE); - } - else if (legacy_mode_p () && src.maybe_anti_range ()) - { - int_range<3> tmp (src); - tmp.invert (); - set (tmp.min (), wide_int_to_tree (src.type (), tmp.upper_bound (0)), - VR_ANTI_RANGE); - } else { - // If copying legacy to int_range, normalize any symbolics. - if (src.legacy_mode_p () && !range_has_numeric_bounds_p (&src)) + if (range_has_numeric_bounds_p (&src)) + set (src.min (), src.max (), src.kind ()); + else { value_range cst (src); cst.normalize_symbolics (); + gcc_checking_assert (cst.varying_p () || cst.kind () == VR_RANGE); set (cst.min (), cst.max ()); - return; } - set (src.min (), src.max ()); } } +// Copy any type of irange into a legacy. + +void +irange::copy_to_legacy (const irange &src) +{ + gcc_checking_assert (legacy_mode_p ()); + // Copy legacy to legacy. + if (src.legacy_mode_p ()) + { + m_num_ranges = src.m_num_ranges; + m_base[0] = src.m_base[0]; + m_base[1] = src.m_base[1]; + m_kind = src.m_kind; + return; + } + // Copy multi-range to legacy. + if (src.undefined_p ()) + set_undefined (); + else if (src.varying_p ()) + set_varying (src.type ()); + else if (src.maybe_anti_range ()) + { + int_range<3> r (src); + r.invert (); + // Use tree variants to save on tree -> wi -> tree conversions. + set (r.tree_lower_bound (0), r.tree_upper_bound (0), VR_ANTI_RANGE); + } + else + set (src.tree_lower_bound (), src.tree_upper_bound ()); +} + // Swap min/max if they are out of order. Return TRUE if further // processing of the range is necessary, FALSE otherwise. diff --git a/gcc/value-range.h b/gcc/value-range.h index 63c96204cda..760ee772316 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -124,7 +124,8 @@ protected: wide_int legacy_upper_bound (unsigned) const; int value_inside_range (tree) const; bool maybe_anti_range () const; - void copy_legacy_range (const irange &); + void copy_to_legacy (const irange &); + void copy_legacy_to_multi_range (const irange &); private: unsigned char m_num_ranges;