From patchwork Mon May 17 22:13:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1479882 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=2620:52:3:1:0:246e:9693:128c; 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=Xm+pFUGD; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FkYLk5v2Jz9sWF for ; Tue, 18 May 2021 08:13:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92BD1385383B; Mon, 17 May 2021 22:13:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92BD1385383B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1621289626; bh=X8FGLj8wKKlP5kp1LigWbNVoACEYe4Yd2/TJaz7mYUc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Xm+pFUGDL2L+WzAmgvJhNowF7z2X3UeGTQthJy74xEIXJxhXcWt6eO08yj9yPi+bc yUKoeu1NYV//6L/y3AGSrwH7i3tQAbEVOZNTiDAQF7y5dAx39fIRixrNV9BevsSepV VMMa6Pww62DwWtJ/ZM6/j8FjLD+VAItXSOeewoR8= 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 0BB4E385801A for ; Mon, 17 May 2021 22:13:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0BB4E385801A Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-448-PYKHx3CWM3qr1YTW05XHwg-1; Mon, 17 May 2021 18:13:41 -0400 X-MC-Unique: PYKHx3CWM3qr1YTW05XHwg-1 Received: by mail-qk1-f199.google.com with SMTP id u9-20020a05620a4549b02902e956c2a3c8so5714416qkp.20 for ; Mon, 17 May 2021 15:13:41 -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:from:subject:message-id:date:user-agent :mime-version:content-language; bh=X8FGLj8wKKlP5kp1LigWbNVoACEYe4Yd2/TJaz7mYUc=; b=oP3dxpdZvHc1D3beW7E3XL+d+mrB1844whEEqvpMoPX0aFCaX/Kncq7ZOmWtx0PK13 R4nrsp7NOl5XngVYviZZlp8K01WAs9vq9JsqcV5PtE/S0jhXcP71ysOz4z3QrwQj7QEh wnRm13Yhe04ELh/NKHmYsGEKWag5jPAlptEjWLhz+qA5HUkoRavpE6BGcKAuJDkfaDoO ORe2tRntU1xbCV+xScB5Yqd+rYFxILqdXUOHYrRh9sExQRJcvHdXvjKr960Gi9lrNmac jJDv8cfbL7M9eGWwGkK9WY4FzwhFwlSOXMk3cYVp6jR5ydYrNzW/JJjsGGIMm5PElkEF 7XdQ== X-Gm-Message-State: AOAM531AKE2JPyhZDhKir6LfbHoYo6VsF9jXZYN7NKSxlQ4RvuX3j0KL p+K1kpV9f9GrdIp/oODCHXdf2m2Ji1FRi0O/uxzI3tWwy5/3CGlx7JeHMg3CQerZM9kSGkH67Vf pAxp/DWsraFxCKhXtZR7ievWNw9PKWnAe4OviM42EoHegw6VXt0BD1J3zBq1tNnakW8DW0g== X-Received: by 2002:ac8:7442:: with SMTP id h2mr1650449qtr.315.1621289621127; Mon, 17 May 2021 15:13:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOYHJkEzrYI8JMVCMidSgZjooMOzLquOn4hSrHgAxQaE7pndE67bAt7rk6n0J5UIx0dByQSQ== X-Received: by 2002:ac8:7442:: with SMTP id h2mr1650422qtr.315.1621289620858; Mon, 17 May 2021 15:13:40 -0700 (PDT) Received: from ?IPv6:2607:fea8:a25d:e700::2b5? ([2607:fea8:a25d:e700::2b5]) by smtp.gmail.com with ESMTPSA id l197sm11654133qke.121.2021.05.17.15.13.40 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 May 2021 15:13:40 -0700 (PDT) To: gcc-patches Subject: [PATCH] PR tree-optimization/100512: Once a range becomes constant, make it invariant. Message-ID: Date: Mon, 17 May 2021 18:13:39 -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=-11.8 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" The code in PR 100512 triggers an interaction between ranger and the propagation engine related to undefined values. I put the detailed analysis in the PR, but it boils down to the early VRP pass has concluded that something is a constant and can be replaced, and removes the definition expecting the constant to be propagated everywhere. If the code is in an undefined region that the CFG is going to remove, we can find impossible situations,a nd ranger then changes that value ot UNDEFINED..  because, well, it is.  But then the propagation engine panics because it doesnt have a constant any more, so odesnt replace it, and now we have a used but not defined value. Once we get to a globally constant range where further refinements can only end up in an UNDEFINED state, stop further evaluating the range.  This is typically in places which are about to be removed by CFG cleanup anyway, and it will make the propagation engine happy with no surprises. Bootstraps on x86_64-pc-linux-gnu with no regressions, and fixes the PR. Pushed. Andrew commit 3f476de7fd274f619a0b04c2e2f7077ee8ab17a5 Author: Andrew MacLeod Date: Mon May 17 15:53:39 2021 -0400 Once a range becomes constant, make it invariant. Once a range is forced to a constant globally, simply make it invariant. Unify this with the code which makes non-zero pointer ranges invariant. gcc/ PR tree-optimization/100512 * gimple-range-cache.cc (ranger_cache::set_global_range): Mark const and non-zero pointer ranges as invariant. * gimple-range.cc (gimple_ranger::range_of_stmt): Remove pointer processing from here. gcc/testsuite/ PR tree-optimization/100512 * gcc.dg/pr100512.c: New. diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 60e5d66c52d..2c922e32913 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -703,8 +703,19 @@ ranger_cache::set_global_range (tree name, const irange &r) propagate_updated_value (name, bb); } - // Mark the value as up-to-date. - m_temporal->set_timestamp (name); + // Constants no longer need to tracked. Any further refinement has to be + // 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. + 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); } // Register a dependency on DEP to name. If the timestamp for DEP is ever diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 5b288d8e6a7..710bc7f9632 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -1082,11 +1082,6 @@ gimple_ranger::range_of_stmt (irange &r, gimple *s, tree name) r.intersect (tmp); m_cache.set_global_range (name, r); - // Pointers which resolve to non-zero at the defintion point do not need - // tracking in the cache as they will never change. See PR 98866. - if (POINTER_TYPE_P (TREE_TYPE (name)) && r.nonzero_p ()) - m_cache.set_range_invariant (name); - return true; } diff --git a/gcc/testsuite/gcc.dg/pr100512.c b/gcc/testsuite/gcc.dg/pr100512.c new file mode 100644 index 00000000000..70b90e04be9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr100512.c @@ -0,0 +1,25 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -w" } */ + +#include +int a; +void b() { + int16_t *c; + uint16_t d = 2; + if (0 == d) { + uint64_t e; + uint64_t *f = &e; + for (;;) { + if (e += 0 >= 0) + for (;;) + ; + g: + for (; a;) { + int16_t i = &d; + *c = i && *f; + } + } + } + goto g; +} +