From patchwork Tue Jun 1 01:32:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1485822 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; 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=SKmw9EeT; 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 4FvF5K03k0z9sXM for ; Tue, 1 Jun 2021 11:32:19 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9F906386FC07; Tue, 1 Jun 2021 01:32:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F906386FC07 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622511136; bh=BcgaHVh3MepytBud5ExSa+L5EU2nNxGpZRXjvTienck=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=SKmw9EeTCraHWcgZoPGX/bLRdHSwARDmG+UVcnGydv8gbXMm+JltbqvOHw+6+etyZ o2j2I5WAiuRLgyRxDPRNdwTkR6L1y1elOrgMv92/CztZek615lLJmV+PL5l/dqkRPz nm3fXJ9IAQlCI9CaOSCwRR5ltKTE/ogzqJStHPN4= 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 ESMTP id 2B0C2385E440 for ; Tue, 1 Jun 2021 01:32:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2B0C2385E440 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-324-MvrM1WHZO0yV3G4HbSFUSQ-1; Mon, 31 May 2021 21:32:11 -0400 X-MC-Unique: MvrM1WHZO0yV3G4HbSFUSQ-1 Received: by mail-qv1-f69.google.com with SMTP id k6-20020a0cd6860000b029021936c6e8ffso2517225qvi.7 for ; Mon, 31 May 2021 18:32:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=BcgaHVh3MepytBud5ExSa+L5EU2nNxGpZRXjvTienck=; b=P16zlpVBQxQ6tdJmctb3+COKdSa+dqe8AKwN4rOsraFtTHvWNlKQ1UKER4FBW5CBZh tkM43OqG9T7b1MRHKCR42VPxOkRpZdQQw/Ssy7nH0dgOfn//+uSB+il2IvCeJCXqizkQ Y+QpWD0+aZ8OB6rAFAFmPIYjLDzbvnlHueuWuzebfga1qvnAPYLO0f0p1LOTGz7hBwTw oewtI3w5M8j+s8JFjej+nt47ZLkzpvTpvQ31RDFa4qCDwguPM7VEKGrAPi76Lw/JL3Hp vtopDl6nj5xfG3jKVqBWxz9K3KwA6VN8dLlVFuWnGWgABv2yZB8vHgv27/rrXMuc2dBH 3lhQ== X-Gm-Message-State: AOAM530k9WcxR26Q4YWH7o+pdwURgm2oWhqrPKoVKwfqJhdy3H42my1f ok3lFVrdnpkNSNUj5qoKeEmISYh81zGsIj9s+ZEQN0pDWuvxsBjySiqnAdGPFsm7M99fakQuS7y 2TH1gx3DTBL8VXClTBQ== X-Received: by 2002:a05:622a:100e:: with SMTP id d14mr17305356qte.192.1622511128596; Mon, 31 May 2021 18:32:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdSUJgCgwZLi5rnU+Fa3bLGTTlYSSEID22J5OMwhA/pEjQIyN5ts0gMh0fcvjGs47p/SJLxg== X-Received: by 2002:a05:622a:100e:: with SMTP id d14mr17305345qte.192.1622511128434; Mon, 31 May 2021 18:32:08 -0700 (PDT) Received: from ?IPv6:2607:fea8:a25d:e700::ef8c? ([2607:fea8:a25d:e700::ef8c]) by smtp.gmail.com with ESMTPSA id k23sm10483612qkk.71.2021.05.31.18.32.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 31 May 2021 18:32:08 -0700 (PDT) To: gcc-patches Subject: [PATCH] PR tree-optimization/100774- Range invariant global values are also always current. Message-ID: <562febbf-c48a-8274-d6f8-339efd809572@redhat.com> Date: Mon, 31 May 2021 21:32:06 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-12.7 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_LOW, RCVD_IN_MSPIKE_H4, 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" When a range evolves to the point where it becomes a constant, it is marked as invariant.  Rather than marking it as always_current in the timestamp, give it the correct timestamp and just never flag it as stale. This will allow other names which use this value to become stale and be recomputed using the newly invariant value. Furthermore, any range which has evolved to a constant should also be considered non-stale. Bootstrapped on x86_64-pc-linux-gnu, with no new regressions. This picks up a couple of cases we had started missing.  pushed. Andrew From 1ffbfc2659e7e8fa5c5d633869870af8fca5e8ee Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Thu, 27 May 2021 11:19:10 -0400 Subject: [PATCH 1/4] Range invariant global values are also always current. when a range evolves to the point where it becomes a constant, it is marked as invariant. Rather than marking it as always_current in the timestamp, give it the correct timestamp and just never flag it as stale. This will allow other names which use this value to become stale and be recomputed using the newly invariant value. gcc/ PR tree-optimization/100774 * gimple-range-cache.cc (ranger_cache::get_non_stale_global_range): Constant values are also not stale. (ranger_cache::set_global_range): Range invariant values should also have the correct timestamp. gcc/testsuite PR tree-optimization/100774 * g++.dg/pr100774.C: New. --- gcc/gimple-range-cache.cc | 16 ++++++++-------- gcc/testsuite/g++.dg/pr100774.C | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr100774.C diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 889cac1ea65..ef3bc044891 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -639,7 +639,9 @@ ranger_cache::get_non_stale_global_range (irange &r, tree name) { if (m_globals.get_global_range (r, name)) { - if (m_temporal->current_p (name, depend1 (name), depend2 (name))) + // Use this value if the range is constant or current. + if (r.singleton_p () + || m_temporal->current_p (name, depend1 (name), depend2 (name))) return true; } else @@ -674,15 +676,13 @@ ranger_cache::set_global_range (tree name, const irange &r) // undefined. Propagation works better with constants. PR 100512. // Pointers which resolve to non-zero also do not need // tracking in the cache as they will never change. See PR 98866. - // Otherwise mark the value as up-to-date. + // Timestamp must always be updated, or dependent calculations may + // not include this latest value. PR 100774. + if (r.singleton_p () || (POINTER_TYPE_P (TREE_TYPE (name)) && r.nonzero_p ())) - { - set_range_invariant (name); - m_temporal->set_always_current (name); - } - else - m_temporal->set_timestamp (name); + set_range_invariant (name); + m_temporal->set_timestamp (name); } // Push a request for a new lookup in block BB of name. Return true if diff --git a/gcc/testsuite/g++.dg/pr100774.C b/gcc/testsuite/g++.dg/pr100774.C new file mode 100644 index 00000000000..345fcfa0d01 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr100774.C @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-forwprop --param=evrp-mode=ranger -fcompare-debug " } */ + +extern void __attribute__((noreturn)) error(); + +int x; + +static inline int bar(void) { + char n = 1; + int i = x & 1U << n - 1; + return i; +} + +void foo() +{ + int a = bar(); + for (;;) { + bool b; + int d = a; + b = a < 2; + if (!b) + error(); + } +} -- 2.17.2