From patchwork Fri Jul 28 20:38:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1814439 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.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=xruOwQW5; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RCKGs2nmGz1yYq for ; Sat, 29 Jul 2023 06:38:45 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6505E385483E for ; Fri, 28 Jul 2023 20:38:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6505E385483E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690576723; bh=fj6p6ScekJQuz9c4FfEnZG2MQJZRMJ/cAiO0Bqnh0bg=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=xruOwQW5z8E3UP76wS5YavmZyUr5MH+aF/UzCE/E37Oa8oi0HkXzB+gKgRhpQVIsK 71WjUPuklhy6Y9IZJZ/M0TS93z8MMjnUNKEx+TG6M19FjLbwm/98Ck7ZwHIKLD1zz5 Vwpo3tqhVsKjRuC627OYIIn79G8SwfoHyp4Pa9mY= 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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id ACE5F3854C68 for ; Fri, 28 Jul 2023 20:38:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ACE5F3854C68 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-54-Zw9ahF9qM5GT5PWXIOQamg-1; Fri, 28 Jul 2023 16:38:17 -0400 X-MC-Unique: Zw9ahF9qM5GT5PWXIOQamg-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-767564705f5so304681785a.1 for ; Fri, 28 Jul 2023 13:38:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690576696; x=1691181496; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=cgG27mE/Cjev4FtUgJuzPr7AOObKZFCXg7TVPq1Tnho=; b=jQU40zJh1CzVoezMkawKDVVmwOXfUF9rTyOW9GMuMsUZztFjAL7sDgEcJIv+m4heqJ GoKgIKfmdfE8i/jBd9g6IQ0K2IwEozcqZHmKDUX0gDX5Wg9dJ2ELazp0uqG3w8gmkWyO Gr6YtdjNy+j9QRC/ucLeFLhIzeWJIIg0W3AHNT2eQrs1uW8stotCt0NJHtc94PHqDmn0 ZIjew6+EotNdaBUX4yMErMKsYWArGpSBjumTQb6TXdDRTIT1GWE4y8HAmF8bUW4okARQ w0SUm4HNvHDFyoDbd9uw/131Tci4J9DeJmHYwbEhQJJROZ5X+PQLJPUYpoqJMDSbOgY1 8P7A== X-Gm-Message-State: ABy/qLa4XTTKQo/bPenDLE9dMw378AWVYubf0hIcwgw3NkD8s4XvFmi2 ehb/QjYVPntE3k5O47o2yeU/2YVtp6YB3dJnCdRdciKdsm5tI3z128Cq8remchHo1ev7oaIqamm 6m5ESHXnbaO0/MDEih3Wq0Vjo8L/IiHyXYsc22CujL3BE+NI+VQJEyYYoyB9/iXu1k+z4w7bTC9 9MQA== X-Received: by 2002:a05:620a:2411:b0:766:fe28:35a3 with SMTP id d17-20020a05620a241100b00766fe2835a3mr4552568qkn.32.1690576695849; Fri, 28 Jul 2023 13:38:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlGipiC5hr6fTZPDNc1+VB42i4w+ymZFQ7I0+CSWkMdg+9eZiyxlP5VxhSgK4vNLC97JDjiYog== X-Received: by 2002:a05:620a:2411:b0:766:fe28:35a3 with SMTP id d17-20020a05620a241100b00766fe2835a3mr4552554qkn.32.1690576695538; Fri, 28 Jul 2023 13:38:15 -0700 (PDT) Received: from ?IPV6:2607:fea8:51e0:8e00::8eb7? ([2607:fea8:51e0:8e00::8eb7]) by smtp.gmail.com with ESMTPSA id pc19-20020a05620a841300b00767d6ec578csm1397028qkn.20.2023.07.28.13.38.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Jul 2023 13:38:15 -0700 (PDT) Message-ID: <4378bf33-4718-ff59-4083-769d4485c352@redhat.com> Date: Fri, 28 Jul 2023 16:38:13 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 To: gcc-patches Cc: "hernandez, aldy" Subject: [COMMITTED] Add a merge_range to ssa_cache and use it. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.4 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This adds some tweaks to the ssa-range cache. 1)   Adds a new merge_range which works like set_range, except if there is already a value, the two values are merged via intersection and stored.   THis avpoids having to check if there is a value, load it, intersect it then store that in the client. There is one usage pattern (but more to come) in the code base.. change to use it. 2)  The range_of_expr() method in ssa_cache does not set the stmt to a default of NULL.  Correct that oversight. 3)  the method empty_p() is added to the ssa_lazy_cache class so we can detect if the lazy cache has any active elements in it or not. Bootstrapped on 86_64-pc-linux-gnu with no regressions.   Pushed. Andrew From 72fb44ca53fda15024e0c272052b74b1f32735b1 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Fri, 28 Jul 2023 11:00:57 -0400 Subject: [PATCH 3/3] Add a merge_range to ssa_cache and use it. add empty_p and param tweaks. * gimple-range-cache.cc (ssa_cache::merge_range): New. (ssa_lazy_cache::merge_range): New. * gimple-range-cache.h (class ssa_cache): Adjust protoypes. (class ssa_lazy_cache): Ditto. * gimple-range.cc (assume_query::calculate_op): Use merge_range. --- gcc/gimple-range-cache.cc | 45 +++++++++++++++++++++++++++++++++++++++ gcc/gimple-range-cache.h | 6 ++++-- gcc/gimple-range.cc | 6 ++---- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 52165d2405b..5b74681b61a 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -605,6 +605,32 @@ ssa_cache::set_range (tree name, const vrange &r) return m != NULL; } +// If NAME has a range, intersect it with R, otherwise set it to R. +// Return TRUE if there was already a range set, otherwise false. + +bool +ssa_cache::merge_range (tree name, const vrange &r) +{ + unsigned v = SSA_NAME_VERSION (name); + if (v >= m_tab.length ()) + m_tab.safe_grow_cleared (num_ssa_names + 1); + + vrange_storage *m = m_tab[v]; + if (m) + { + Value_Range curr (TREE_TYPE (name)); + m->get_vrange (curr, TREE_TYPE (name)); + curr.intersect (r); + if (m->fits_p (curr)) + m->set_vrange (curr); + else + m_tab[v] = m_range_allocator->clone (curr); + } + else + m_tab[v] = m_range_allocator->clone (r); + return m != NULL; +} + // Set the range for NAME to R in the ssa cache. void @@ -689,6 +715,25 @@ ssa_lazy_cache::set_range (tree name, const vrange &r) return false; } +// If NAME has a range, intersect it with R, otherwise set it to R. +// Return TRUE if there was already a range set, otherwise false. + +bool +ssa_lazy_cache::merge_range (tree name, const vrange &r) +{ + unsigned v = SSA_NAME_VERSION (name); + if (!bitmap_set_bit (active_p, v)) + { + // There is already an entry, simply merge it. + gcc_checking_assert (v < m_tab.length ()); + return ssa_cache::merge_range (name, r); + } + if (v >= m_tab.length ()) + m_tab.safe_grow (num_ssa_names + 1); + m_tab[v] = m_range_allocator->clone (r); + return false; +} + // Return TRUE if NAME has a range, and return it in R. bool diff --git a/gcc/gimple-range-cache.h b/gcc/gimple-range-cache.h index a0f436b5723..bbb9b18a10c 100644 --- a/gcc/gimple-range-cache.h +++ b/gcc/gimple-range-cache.h @@ -61,11 +61,11 @@ public: virtual bool has_range (tree name) const; virtual bool get_range (vrange &r, tree name) const; virtual bool set_range (tree name, const vrange &r); + virtual bool merge_range (tree name, const vrange &r); virtual void clear_range (tree name); virtual void clear (); void dump (FILE *f = stderr); - virtual bool range_of_expr (vrange &r, tree expr, gimple *stmt); - + virtual bool range_of_expr (vrange &r, tree expr, gimple *stmt = NULL); protected: vec m_tab; vrange_allocator *m_range_allocator; @@ -80,8 +80,10 @@ class ssa_lazy_cache : public ssa_cache public: inline ssa_lazy_cache () { active_p = BITMAP_ALLOC (NULL); } inline ~ssa_lazy_cache () { BITMAP_FREE (active_p); } + inline bool empty_p () const { return bitmap_empty_p (active_p); } virtual bool has_range (tree name) const; virtual bool set_range (tree name, const vrange &r); + virtual bool merge_range (tree name, const vrange &r); virtual bool get_range (vrange &r, tree name) const; virtual void clear_range (tree name); virtual void clear (); diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 01e62d3ff39..01173c58f02 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -809,10 +809,8 @@ assume_query::calculate_op (tree op, gimple *s, vrange &lhs, fur_source &src) if (m_gori.compute_operand_range (op_range, s, lhs, op, src) && !op_range.varying_p ()) { - Value_Range range (TREE_TYPE (op)); - if (global.get_range (range, op)) - op_range.intersect (range); - global.set_range (op, op_range); + // Set the global range, merging if there is already a range. + global.merge_range (op, op_range); gimple *def_stmt = SSA_NAME_DEF_STMT (op); if (def_stmt && gimple_get_lhs (def_stmt) == op) calculate_stmt (def_stmt, op_range, src); -- 2.40.1