From patchwork Wed May 24 12:42:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 98472 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2817763vqo; Wed, 24 May 2023 05:44:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6MY+m1FKriInRQSGLbtkvgGzVTsE4eIF9HeIjkyzISapDxHs14dDrzsNYOEKo6nS3xIhOg X-Received: by 2002:a17:907:6da9:b0:96f:bab6:4db5 with SMTP id sb41-20020a1709076da900b0096fbab64db5mr14150871ejc.28.1684932271327; Wed, 24 May 2023 05:44:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684932271; cv=none; d=google.com; s=arc-20160816; b=DIjxyJHOtV5heIUybS5k7VPuaFaKDFQm5UUKTgidiycEmRKJZu0pJ8gq52iB32ZiFY 4yu7hgWPW63h8C2jEZtGHbwnor1jSdTs2cR9KShaHbO3p35EkjTQ1Jowo9f/bM5z5uYR IQsVW1daeWY4Ng6o86uO+5Y+xvhjIvPrln1ahSsU1TT4XGQu+K92l0jc6E2v7MopoWrd LNQ3T/d5+s47VFFiEECe9IWjj9mNlgbEtVTB/ogspubm16I0GDtHjJkFjWqXzX4/TFKz AYu9SggSw1DY6nUTgN/cLaC6KHlNxMC0GjP5UQ2ux9u5X+couaYvNnqglG6YWNE7qAyw RHMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:content-language :subject:cc:to:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=gVf7tqErHsBZHxmzEEKk6pGABNqwmCuYDt34riCixzE=; b=bGx2sDGn9SBTo60D8T0tV2okTmRiFO8ZuNkp2i01DFdS9D2Ng92+EZ1mAa+XHgmhOF 6CPzPU6MtnOF4ytP5PrkEewjp0KRMPkdEXApH0cC7MCMG7O4o/nWwvNzAcbtKUKkuczY BYllZ4n0qXHpfUE7qRaXk40BNNRXCjwQM3qlL4uMbrGtwhaKZDKfZ1/sT693lgqzKDUo s7idI+zEu0JzxZZOegyD0cTwsFH9fpqm/2YCOg6VQZWyEQLcyru1lySNZlFZy5+jDImK +ulJ4zgd+cCHxtPzP4DCgF6AWy4+CzfizkZvOm/3WFbV/pWUNX+zOq7gMMp6umbwl87D 8IKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vMdwsf0F; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id sb27-20020a1709076d9b00b0097381ff4686si1390497ejc.643.2023.05.24.05.44.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 May 2023 05:44:31 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vMdwsf0F; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95549385842D for ; Wed, 24 May 2023 12:43:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95549385842D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684932205; bh=gVf7tqErHsBZHxmzEEKk6pGABNqwmCuYDt34riCixzE=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=vMdwsf0FK2EKIJ5dTuTdql3jVfCXDpF/NF9T1p/nRk/+I2iq89Hq5u0SlixOuvvwf lMTojtGvB+w6rblUyHl2fp5QO3L9u3bKHpjvt9Ag2qCB/1eSWPMVifMFlwjNRff1Z2 S0hezcwuvSxuMgE/bSRbqVyCnYoc7qcK7hpyBkzA= 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 C63A83856DC7 for ; Wed, 24 May 2023 12:42:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C63A83856DC7 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-195-oI-Ps45tN2Oig3TI-oWGTw-1; Wed, 24 May 2023 08:42:30 -0400 X-MC-Unique: oI-Ps45tN2Oig3TI-oWGTw-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-623998c0d33so7244546d6.0 for ; Wed, 24 May 2023 05:42:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684932149; x=1687524149; 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=vIvi355OMzO2Ail3uJWMGHtsoGkczA4zlYlopkq3RCY=; b=Vu1wJ98c0uZ/128z4ejcY8h2t1tNUDoLLo1MFGMiZ54gtUOiMEYg19Bgn5cLBbfeXw gaLWIl5JKMS+vH3JcfCbeNgQcL5gTLRP1Jv5P8Co95ZjJ8EHkq5axpOctyi3ieCc4EhW diD6sXiYdg+H22X62sCmpx1glwt9hF+XfVsoCYRD/aXPlBtqAhGBXNoac9w7fhygaU/H IyqZS3b4WbrcRaIFdbBc+PYmV8XSymm/sI1aVCjUjBn+aESWz7cXW6koaTTL3f8vv5ch HNZD71nVIWaoYE0VQ+Sdn7yv4ckcjbPc8E6JWqCrmtpNL1wvhXXQ0fEr66O0AIbNqPG+ DENw== X-Gm-Message-State: AC+VfDxQQc48YCb3Bc3+ygzJBUTT/TbiF0Jnq0DSMJhe96sCcnn2odHS i7nk+imo8KyJpxYnqVRsTJnXmB8dckO2QP2zCbf8beI99TPodj18aZoVgF4kuAVDaReH9jM2T4d sLEQX9VLBw1OzbakqU0g5iPZVqMqyk8v+LW/CRTqDVrAT86DzClUS6XkAsSAAo2HGCz4uGrZDMp KZlw== X-Received: by 2002:a05:6214:410d:b0:625:9578:990e with SMTP id kc13-20020a056214410d00b006259578990emr5294091qvb.23.1684932149661; Wed, 24 May 2023 05:42:29 -0700 (PDT) X-Received: by 2002:a05:6214:410d:b0:625:9578:990e with SMTP id kc13-20020a056214410d00b006259578990emr5294071qvb.23.1684932149275; Wed, 24 May 2023 05:42:29 -0700 (PDT) Received: from ?IPV6:2607:fea8:51df:4200::933? ([2607:fea8:51df:4200::933]) by smtp.gmail.com with ESMTPSA id mm19-20020a0562145e9300b00623927281c2sm3536239qvb.40.2023.05.24.05.42.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 May 2023 05:42:28 -0700 (PDT) Message-ID: <419533f4-b632-ad55-f225-8f8dd6fd709b@redhat.com> Date: Wed, 24 May 2023 08:42:27 -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 3/3] PR tree-optimization/109695 - Only update global value if it changes. 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766779541265805476?= X-GMAIL-MSGID: =?utf-8?q?1766779541265805476?= This patch implements suggestion 1) from the PR: 1) We unconditionally write the new value calculated to the global cache once the dependencies are resolved.  This gives it a new timestamp, and thus makes any other values which used it out of date when they really aren't.   This causes a lot of extra churn. TODO: This should be changed to only update it when it actually changes.  Client code shouldn't have to do this, it should be handled right int the cache's set_global_value (). It turns out it is about a 3% compilation speed hit to compare the ranges every time we set them, which loses any gains we see. As such, I changed it so that set_global_range takes an extra parameter which indicates whether the value has changed or not. In all cases, we have the result of intersection which gives us the information for free, so we might as well take advantage of it.  instead we get about a 2.7% improvement in speed in VRP and another 0.7% in threading. set_global_range now checks the changed flag, and if it hasnt changed, checks to see if the value is current or not, and only gives the result a new timestamp if its out of date.  I found many cases where we   1) initally calculate the result, give it a timestamp,   2) then evaluate the dependencies.. which get fresher timestamps than the result   3) the initial result turns out to still be right, so we dont have to propagate the value or change it. However, if we do not give it a fresh time stamp in this case, it wil be out of date if we ever check is sine the dependencies are fresher.   So in this case, we give it a new timestamp so we wont re-evaluate it. The 3 patches together result in VRP being just 0.15% slower, threading being 0.6% faster, and overall compilation improves by 0.05% It will also compile the testcase from the PR with issues after reverting Aldy's memory work and using int_range_max as int_range<255> again.. so that is also an indication the results are worthwhile. At this point, I don't think its worth pursuing suggestion 4 from the PR.. it is wrought with dependency issues that I don't think we need to deal with at this moment.  When I have more time I will give it more consideration. Bootstraps on x86_64-pc-linux-gnu with no regressions.   Pushed. Andrew From c3c1499498ff8f465ec7eacce6681c5c2da03a92 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 23 May 2023 15:41:03 -0400 Subject: [PATCH 3/3] Only update global value if it changes. Do not update and propagate a global value if it hasn't changed. PR tree-optimization/109695 * gimple-range-cache.cc (ranger_cache::get_global_range): Add changed param. * gimple-range-cache.h (ranger_cache::get_global_range): Ditto. * gimple-range.cc (gimple_ranger::range_of_stmt): Pass changed flag to set_global_range. (gimple_ranger::prefill_stmt_dependencies): Ditto. --- gcc/gimple-range-cache.cc | 10 +++++++++- gcc/gimple-range-cache.h | 2 +- gcc/gimple-range.cc | 8 ++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index db7ee8eab4e..e069241bc9d 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -992,10 +992,18 @@ ranger_cache::get_global_range (vrange &r, tree name, bool ¤t_p) // Set the global range of NAME to R and give it a timestamp. void -ranger_cache::set_global_range (tree name, const vrange &r) +ranger_cache::set_global_range (tree name, const vrange &r, bool changed) { // Setting a range always clears the always_current flag. m_temporal->set_always_current (name, false); + if (!changed) + { + // If there are dependencies, make sure this is not out of date. + if (!m_temporal->current_p (name, m_gori.depend1 (name), + m_gori.depend2 (name))) + m_temporal->set_timestamp (name); + return; + } if (m_globals.set_range (name, r)) { // If there was already a range set, propagate the new value. diff --git a/gcc/gimple-range-cache.h b/gcc/gimple-range-cache.h index 946fbc51465..871255a8116 100644 --- a/gcc/gimple-range-cache.h +++ b/gcc/gimple-range-cache.h @@ -117,7 +117,7 @@ public: bool get_global_range (vrange &r, tree name) const; bool get_global_range (vrange &r, tree name, bool ¤t_p); - void set_global_range (tree name, const vrange &r); + void set_global_range (tree name, const vrange &r, bool changed = true); void propagate_updated_value (tree name, basic_block bb); diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index a275c090e4b..4fae3f95e6a 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -320,8 +320,8 @@ gimple_ranger::range_of_stmt (vrange &r, gimple *s, tree name) // Combine the new value with the old value. This is required because // the way value propagation works, when the IL changes on the fly we // can sometimes get different results. See PR 97741. - r.intersect (tmp); - m_cache.set_global_range (name, r); + bool changed = r.intersect (tmp); + m_cache.set_global_range (name, r, changed); res = true; } @@ -393,8 +393,8 @@ gimple_ranger::prefill_stmt_dependencies (tree ssa) // Make sure we don't lose any current global info. Value_Range tmp (TREE_TYPE (name)); m_cache.get_global_range (tmp, name); - r.intersect (tmp); - m_cache.set_global_range (name, r); + bool changed = tmp.intersect (r); + m_cache.set_global_range (name, tmp, changed); } continue; } -- 2.40.1