From patchwork Tue Aug 2 18:33:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 359 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp3147572pxt; Tue, 2 Aug 2022 11:34:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u/JIHRDoc0+KsVTYBQZ5nAsAXWF8KJ8ksQAG7ykdQKVvGo5d2JiiFmTu3+lBUbB7MrIWe0 X-Received: by 2002:a05:6402:3785:b0:435:5d0e:2a2e with SMTP id et5-20020a056402378500b004355d0e2a2emr22725921edb.307.1659465246431; Tue, 02 Aug 2022 11:34:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659465246; cv=none; d=google.com; s=arc-20160816; b=rTYF4l4CrhEsscyW+xkTZ3kwziQzWBCJqSwZIkCS3XE5eQfaF6WD8HzenmaX6CUf1l e6NqYfl7NpHaxtEzHnDCF+VvwlScAFCXVyVrwnrndFJz3I8DqOhR59Ac1+AQvgLPa0g+ WQvDTKBSrbEGscQgZbQR0SvMeD39rlPki4lNf088eU3F6YQZta4ObKsrToE2HFk/FgQ9 hMEL4BYgjwkf+R9ToSSRt0kubyDKzpaJynwtVUoLNLm+SOXQKyFKLI/GQIk9f0WZw/O9 IJtfuU74keDcDyHM2HI9oeJhKKr6OzQR/fGzLrReKzGTykPdobphVvuRK3ayCnFsDOkD l/qQ== 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:to:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=ryuF/Sp/SVfYUJHx9e496N3P4P0r9qU75dFQNp3VIC8=; b=cFBJzMbOlu1cUzqP0ivly/2fnWae3hLITbiLLsq9FPLXpqT9W4LqqDxcG1/ojAfzZB IZKGUpjSzBMHbyBE0zOpfv4YioOaAyDNpwHrEt8sPkx7W0CpSA85s1mWJfXdlsNTraad HBrKTWNHx6CAIE7IouG2TcGGIUO7XJeOIqC768XMnje4kJKfbQscICmOlCgJEUSCIyma xEgIvu3HXCxiC4NLLksMlVMeB1Wcfc9wwz5FOn88tLVvFBQYWCi5KVc/4xshEQwZtS9h ReGgiCh+TDhttB4NXPrj8AdIYN47dVfKTk5hYPq1uWymLAhG0wPt3YnCycWePiA+ON0E X9cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NKAZrV8D; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id x5-20020a05640226c500b0043e2f1b306esi409198edd.215.2022.08.02.11.34.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 11:34:06 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NKAZrV8D; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 BE7C5385625E for ; Tue, 2 Aug 2022 18:34:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE7C5385625E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1659465244; bh=ryuF/Sp/SVfYUJHx9e496N3P4P0r9qU75dFQNp3VIC8=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=NKAZrV8DJvXo73dNo9TNbi6BrL0CdgGzq2MtfFn4oOKjJDcN+98XEPDRJJiFXjR8r Zhp+gYzu94TYjn9okZ6dnNjRHYBug6tJ5KcfYYmwE8x1xLDnNvlWpLusnuluYwkECA q+28eUcKOcbT5QUu3/thzD+HDtPxyK1w/DoeZllY= 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 D68DB3858296 for ; Tue, 2 Aug 2022 18:33:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D68DB3858296 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-330-pp8GUKNLPwqYSduWz03mOA-1; Tue, 02 Aug 2022 14:33:17 -0400 X-MC-Unique: pp8GUKNLPwqYSduWz03mOA-1 Received: by mail-qv1-f71.google.com with SMTP id er2-20020a056214190200b00474479acbcfso8836718qvb.23 for ; Tue, 02 Aug 2022 11:33:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:from:subject; bh=fFh808DfGSM7525sqDeyLoH2qiSBMtPG9fJyBvqOydE=; b=M4P9EfLjyPbKCstpAne4sc08wuXAxqDGCAi5ZB7lyBW7I6djK8WfhtAOXgSzOrwYmc scBing80wuibOqTylJQpFTDPfGElMoAeXh1gsjngWUK3Qm8Lq/mOyqIws/EDIkwnawX1 SihKddkR63jQPaCLCsing4D4ZXaxKqA1AHCO6ZOvSs+0paudPd2WJNmorCtJOUMYxN4o dbo5gE8atjagvpQZEgZMf/CsykXMsgSrLIB8EkA3vvBQ3lBcM/3PTmtqPzP7GLs20UAy szjLZn3YGUrsoYYqChKlXNC+r322ki4ioe9hbqPQ+gPXnb9wTD92StV/fi/+KjUimD8e 1wVA== X-Gm-Message-State: AJIora87GWl+zvZaQnzDHd8WMNf7FF4WmC5pgHTVcWtkBKbnCYhPuotC YvpaQkwD3jVs62MvTzTGx6zkz02IHxKOv+/gEXoIrN4ZACnuMHwB8yguWdHwHcvohYujpsVFead 7Ld5tiqgNkUWiOrxDVTyJltTZslJRrVkXY1+HaYVZLAMxqO9lzvj515VjdhJxW+oZi5Hjjg== X-Received: by 2002:a05:620a:31c:b0:6b5:d5a5:687f with SMTP id s28-20020a05620a031c00b006b5d5a5687fmr16094231qkm.375.1659465196859; Tue, 02 Aug 2022 11:33:16 -0700 (PDT) X-Received: by 2002:a05:620a:31c:b0:6b5:d5a5:687f with SMTP id s28-20020a05620a031c00b006b5d5a5687fmr16094211qkm.375.1659465196519; Tue, 02 Aug 2022 11:33:16 -0700 (PDT) Received: from [192.168.0.135] ([104.219.120.152]) by smtp.gmail.com with ESMTPSA id de33-20020a05620a372100b006b8b3f2772bsm3663762qkb.44.2022.08.02.11.33.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Aug 2022 11:33:15 -0700 (PDT) Message-ID: <6ac18e26-9691-cdc1-496e-123290c3d541@redhat.com> Date: Tue, 2 Aug 2022 14:33:13 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 To: gcc-patches Subject: [COMMITTED] PR tree-optimization/106474 - Check equivalencies when calculating range on entry. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.6 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, SPF_HELO_NONE, SPF_NONE, TXREP 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1740075430032005948?= X-GMAIL-MSGID: =?utf-8?q?1740075430032005948?= This PR demonstrates a case where evaluating equivalencies can assist VRP in refining values. Previous revisions did not do this due to the expense of calculating or checking for equivalencies everytime we process a use. Earlier change to range_from_dom provided modes for the cache to query, and in particular, it has a mode which can query the DOM tree, but not update the cache.   This tends to be quite quick, and will not cause any memory increases. We can also check if an ssa-name has had any outgoing range calculated thus far, and can significantly trim the number of equivalences that need to be examined. This patch adjusts the on-entry propagator to check if there are any existing equivalence ranges before it updates the cache and returns the on-entry value to ranger. This causes a very marginal slowdown of 0.34% building gcc across the 2 VRP passes using ranger.. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew commit 53f7b80929978dd2773f58cfd0c2cfa49f54538e Author: Andrew MacLeod Date: Fri Jul 29 12:05:38 2022 -0400 Check equivalencies when calculating range on entry. When propagating on-entry values in the cache, checking if any equivalence has a known value can improve results. No new calculations are made. Only queries via dominators which do not populate the cache are checked. PR tree-optimization/106474 gcc/ * gimple-range-cache.cc (ranger_cache::fill_block_cache): Query range of equivalences that may contribute to the range. gcc/testsuite/ * g++.dg/pr106474.C: New. diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index d9e160c9a2a..4782d47265e 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -1211,13 +1211,56 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) // Check if a dominators can supply the range. if (range_from_dom (block_result, name, bb, RFD_FILL)) { - m_on_entry.set_bb_range (name, bb, block_result); if (DEBUG_RANGE_CACHE) { fprintf (dump_file, "Filled from dominator! : "); block_result.dump (dump_file); fprintf (dump_file, "\n"); } + // See if any equivalences can refine it. + if (m_oracle) + { + unsigned i; + bitmap_iterator bi; + // Query equivalences in read-only mode. + const_bitmap equiv = m_oracle->equiv_set (name, bb); + EXECUTE_IF_SET_IN_BITMAP (equiv, 0, i, bi) + { + if (i == SSA_NAME_VERSION (name)) + continue; + tree equiv_name = ssa_name (i); + basic_block equiv_bb = gimple_bb (SSA_NAME_DEF_STMT (equiv_name)); + + // Check if the equiv has any ranges calculated. + if (!m_gori.has_edge_range_p (equiv_name)) + continue; + + // Check if the equiv definition dominates this block + if (equiv_bb == bb || + (equiv_bb && !dominated_by_p (CDI_DOMINATORS, bb, equiv_bb))) + continue; + + Value_Range equiv_range (TREE_TYPE (equiv_name)); + if (range_from_dom (equiv_range, equiv_name, bb, RFD_READ_ONLY)) + { + if (block_result.intersect (equiv_range)) + { + if (DEBUG_RANGE_CACHE) + { + fprintf (dump_file, "Equivalence update! : "); + print_generic_expr (dump_file, equiv_name, TDF_SLIM); + fprintf (dump_file, "had range : "); + equiv_range.dump (dump_file); + fprintf (dump_file, " refining range to :"); + block_result.dump (dump_file); + fprintf (dump_file, "\n"); + } + } + } + } + } + + m_on_entry.set_bb_range (name, bb, block_result); gcc_checking_assert (m_workback.length () == 0); return; } diff --git a/gcc/testsuite/g++.dg/pr106474.C b/gcc/testsuite/g++.dg/pr106474.C new file mode 100644 index 00000000000..6cd37a20643 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr106474.C @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-evrp " } */ + +void foo(); +static void __attribute__ ((noinline)) DCEMarker0_() {foo ();} + +void f(bool s, bool c) { + if ((!c == !s) && !c) { + if (s) { + DCEMarker0_(); + } + } +} + +// With equivalences, vrp should be able to remove all IFs. +/* { dg-final { scan-tree-dump-not "goto" "evrp" } } */