From patchwork Wed May 24 12:42:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1785722 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=8.43.85.97; helo=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=RahJ7RTr; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 4QR9pD69lRz20Q6 for ; Wed, 24 May 2023 22:43:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C947238323E8 for ; Wed, 24 May 2023 12:43:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C947238323E8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684932194; bh=SB6aJ9+TpVuZ72vuAaQ9b5EW/ZwbM0kRma/a5rJQ4to=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=RahJ7RTrKG8EPnJoumOLrOnK0aKCURAoB3+t58PPIywLLcA3cGou7UumMyIIgjAS5 qO1I+yxDVLsFHXWj4HI8r03p9EGmwRrJ3CD5i6zbxSjaEe4kgyNT3fO6GWnW83o5uz Cz0n3dOPqKHgvBgHGxdEOMnq85mq5fQl8d0147O0= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id A91FD385770B for ; Wed, 24 May 2023 12:42:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A91FD385770B Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-267-EaFm-y-_O82BKFoyIIzRiQ-1; Wed, 24 May 2023 08:42:24 -0400 X-MC-Unique: EaFm-y-_O82BKFoyIIzRiQ-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3f6afd58c32so5941991cf.3 for ; Wed, 24 May 2023 05:42:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684932143; x=1687524143; 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=82uwTGn6LION0y0K0UhqBP+mObU6kRmu2onRvFS+xho=; b=mHA5fwn2QZedTu13GHzbqptGuZWR99Zn7eFF1ymBLm1wl7JrJFIVkcWAnHwHMjIblR GTxdjzsKGwt9FA20xrr7PHwWERvXIYsL+Dcj6adRnpb7vNywKMqHKOZ7w7X/gpDETyJV IF8jhWpj0duZeiuZjrWfIOqCouAKU/2PBjDBuha9eVQvEjoQ2TnuGEkcCa67GtShrleC 94uZbLHuuP/mp0SvdHQwWYaLzVNRZ7E9s0U/YMU1JpbVPGIntAelB+rYRO8ev/mKQpLf qq6vIvDjQyMdAwnHzwq8dq5wZ3+icXMyfZc6+80wQvGmIV/jIIZg8OAciy0WaTASc70y mVxw== X-Gm-Message-State: AC+VfDwXW3plB5Z/3ysLLIpm9XQPHnTpUeqBy1jGJClOTL0IKQKL/O+h GHlOtttZVN70yCgdHqKSxNqVFbH9gQS/uIHjE+3u65ztVqVT5rSi4ROI7Eht7GyWgp45cS+Xy/d cVg9GgwemwDxWE5EH0U7RZeSvEAbACdQWJXVNhUdNHMQiQYFXYhlSP30gygMep3GsFjicjEAE/W rYHg== X-Received: by 2002:ac8:7f48:0:b0:3f6:c609:e9da with SMTP id g8-20020ac87f48000000b003f6c609e9damr1507174qtk.44.1684932143653; Wed, 24 May 2023 05:42:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6kyPC6oogRnY3M4hjglLQraQGt6Fxr66Z+6IETPwOeVdVc8zOYg+4Wm3TrQLC7cXszxKzjCQ== X-Received: by 2002:ac8:7f48:0:b0:3f6:c609:e9da with SMTP id g8-20020ac87f48000000b003f6c609e9damr1507126qtk.44.1684932143091; Wed, 24 May 2023 05:42:23 -0700 (PDT) Received: from ?IPV6:2607:fea8:51df:4200::933? ([2607:fea8:51df:4200::933]) by smtp.gmail.com with ESMTPSA id mx15-20020a0562142e0f00b0061fb6cc2051sm3538968qvb.15.2023.05.24.05.42.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 May 2023 05:42:22 -0700 (PDT) Message-ID: <74f5eb7b-fd29-640c-9704-4756d36e207a@redhat.com> Date: Wed, 24 May 2023 08:42:21 -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 2/3] PR tree-optimization/109695 - Use negative values to reflect always_current in the, temporal cache. 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, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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-Content-Filtered-By: Mailman/MimeDel 2.1.29 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 implements suggestion 3) from the PR: 3) When we first set the intial value for _1947 and give it the ALWAYS_CURRENT timestamp, we lose the context of when the initial value was set.  So even with 1) & 2) implemented, we are *still* need to set a timestamp for it when its finally calculated, even though it is the same as the original.  This will cause any names already evaluated using its range to become stale because we can't leave it as ALWAYS_CURRENT.    (There are other places where we do need to be able to re-evaluate.. there are 2 testsuite failures caused by this if we just leave it as always_current) TODO: Alter the implementation of ALWAYS_CURRENT such that a name is also given a timestamp at the time of setting the initial value.   Then set_global_range() will clear the ALWAYS_CURRENT tag unconditionally, but leave the original timestamp if the value hasn't changed.  This will then provide an accurate timestamp for the initial_value. Instead of using 0, I changed the timestamp from unsigned to an integer, and used a negative value to indicate it is always current.  This has very little performance impact.  Bootstraps on x86_64-pc-linux-gnu with no regressions.   Pushed. Andrew From 5ed159fdda4d898bdda49469073b9202f5a349bf Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 23 May 2023 15:20:56 -0400 Subject: [PATCH 2/3] Use negative values to reflect always_current in the temporal cache. Instead of using 0, use negative timestamps to reflect always_current state. If the value doesn't change, keep the timestamp rather than creating a new one and invalidating any dependencies. PR tree-optimization/109695 * gimple-range-cache.cc (temporal_cache::temporal_value): Return a positive int. (temporal_cache::current_p): Check always_current method. (temporal_cache::set_always_current): Add param and set value appropriately. (temporal_cache::always_current_p): New. (ranger_cache::get_global_range): Adjust. (ranger_cache::set_global_range): set always current first. --- gcc/gimple-range-cache.cc | 43 +++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 8ddfd9426c0..db7ee8eab4e 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -701,12 +701,12 @@ public: ~temporal_cache (); bool current_p (tree name, tree dep1, tree dep2) const; void set_timestamp (tree name); - void set_always_current (tree name); + void set_always_current (tree name, bool value); + bool always_current_p (tree name) const; private: - unsigned temporal_value (unsigned ssa) const; - - unsigned m_current_time; - vec m_timestamp; + int temporal_value (unsigned ssa) const; + int m_current_time; + vec m_timestamp; }; inline @@ -725,12 +725,12 @@ temporal_cache::~temporal_cache () // Return the timestamp value for SSA, or 0 if there isn't one. -inline unsigned +inline int temporal_cache::temporal_value (unsigned ssa) const { if (ssa >= m_timestamp.length ()) return 0; - return m_timestamp[ssa]; + return abs (m_timestamp[ssa]); } // Return TRUE if the timestamp for NAME is newer than any of its dependents. @@ -739,13 +739,12 @@ temporal_cache::temporal_value (unsigned ssa) const bool temporal_cache::current_p (tree name, tree dep1, tree dep2) const { - unsigned ts = temporal_value (SSA_NAME_VERSION (name)); - if (ts == 0) + if (always_current_p (name)) return true; // Any non-registered dependencies will have a value of 0 and thus be older. // Return true if time is newer than either dependent. - + int ts = temporal_value (SSA_NAME_VERSION (name)); if (dep1 && ts < temporal_value (SSA_NAME_VERSION (dep1))) return false; if (dep2 && ts < temporal_value (SSA_NAME_VERSION (dep2))) @@ -768,12 +767,28 @@ temporal_cache::set_timestamp (tree name) // Set the timestamp to 0, marking it as "always up to date". inline void -temporal_cache::set_always_current (tree name) +temporal_cache::set_always_current (tree name, bool value) { unsigned v = SSA_NAME_VERSION (name); if (v >= m_timestamp.length ()) m_timestamp.safe_grow_cleared (num_ssa_names + 20); - m_timestamp[v] = 0; + + int ts = abs (m_timestamp[v]); + // If this does not have a timestamp, create one. + if (ts == 0) + ts = ++m_current_time; + m_timestamp[v] = value ? -ts : ts; +} + +// Return true if NAME is always current. + +inline bool +temporal_cache::always_current_p (tree name) const +{ + unsigned v = SSA_NAME_VERSION (name); + if (v >= m_timestamp.length ()) + return false; + return m_timestamp[v] <= 0; } // -------------------------------------------------------------------------- @@ -970,7 +985,7 @@ ranger_cache::get_global_range (vrange &r, tree name, bool ¤t_p) // If the existing value was not current, mark it as always current. if (!current_p) - m_temporal->set_always_current (name); + m_temporal->set_always_current (name, true); return had_global; } @@ -979,6 +994,8 @@ ranger_cache::get_global_range (vrange &r, tree name, bool ¤t_p) void ranger_cache::set_global_range (tree name, const vrange &r) { + // Setting a range always clears the always_current flag. + m_temporal->set_always_current (name, false); if (m_globals.set_range (name, r)) { // If there was already a range set, propagate the new value. -- 2.40.1