From patchwork Thu Oct 13 15:31:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 2075 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp341541wrs; Thu, 13 Oct 2022 08:33:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7M6AFmlLK9wAgs5DgVLERkhekFO/cZjalNHJFlFYJfCdXfeldk8Yycii7UdPSjgjWvcpgQ X-Received: by 2002:a17:907:1dde:b0:78d:9725:cc69 with SMTP id og30-20020a1709071dde00b0078d9725cc69mr233058ejc.305.1665675181316; Thu, 13 Oct 2022 08:33:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665675181; cv=none; d=google.com; s=arc-20160816; b=MKACPQLiPUKUozbxkYZbBskBJUXtiTlohd+CqrLdCXXx/ck8qrjbMfBFnVKTpqpsP5 6+GlqUvbe6kmwVwwBLich7170ufj1hURcoIQMLNEJxrqM4esdMR82ZAIRDBDFRUATFHl TmGkETEkssPBmNy9WS+2uHu4rzih5E1QDh6LxeMn0Pi0StRViezYKxwCqp2Sev3zXEc9 orx5WDXH0XrpkKCtQlgluS9ZccKu+tCAef9WGqKKQIYOnw0GT+ZTY+7FfNrhSAOVhsZ1 FHlzJdr2nsPZ9ooPdrMPc9bpiyQXV94Pd2r0UcIuySlUxA2BB5Rn2TVa3vk6zuLf23rG j+/Q== 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=Fhj8+a0wAuUHYEQgIkRiODo86vszpqovS8+uYYy8jtY=; b=PyG6va0omV+fqXCxPoL13yfoKzAJhxBQxpJqtkhg2nByzBMu97ji5M5DF8tNyb4IVp ZJIEarBgx5tkQAxzo02RLE2m9GZrRlfIeAxuF+xRTSsErjrQtLg3prJxYIyooC4s4hYD I1urXFmySGP5zNI4RzzZuAC0Jif4RrSZEpdgqMmOMDfn1oQocRbVRYCm469f0/Ws8/3K bt0qipHFG6KQ3Y+Xiwu0cBbPZgEkr9ADGUZRfJmW3zXrzh70tsUTey8QQ8MeGRq9FQDe zxKRzmxXX1b+sopziOITmtwOomRtpVC4uJgfbD8U5Y42LDaCWNDRNTI9/7xiJfKb9n2f fcjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yVRMSgcI; 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 f16-20020a056402151000b0045bdc422aeesi32614edw.292.2022.10.13.08.33.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 08:33:01 -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=yVRMSgcI; 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 91FC0384D1AE for ; Thu, 13 Oct 2022 15:32:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 91FC0384D1AE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665675149; bh=Fhj8+a0wAuUHYEQgIkRiODo86vszpqovS8+uYYy8jtY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=yVRMSgcIGYbLErACMufPTdJAoUYNMe9MbKDzXruPJJ7zMMYnT5cen2kP9oh0jU8r3 dV4LGa5LhjROWfZgfB/nMquiGmWIjtkA4SyWLWqQkeyD7oEyRY5bvJjNAkVzwPEvV8 SuQRRkIL58317OMQ/H9BfMBfoFr+HDOs+EAKq8Yk= 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 C4D9C3860771 for ; Thu, 13 Oct 2022 15:31:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C4D9C3860771 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-31-t9QiBiuQMXCsxjT4YHgxcA-1; Thu, 13 Oct 2022 11:31:44 -0400 X-MC-Unique: t9QiBiuQMXCsxjT4YHgxcA-1 Received: by mail-qt1-f198.google.com with SMTP id g21-20020ac87d15000000b0035bb6f08778so1556106qtb.2 for ; Thu, 13 Oct 2022 08:31:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=3n7wwLBavjl1yOg6F6cTdgV7zfuhtOWvjc9sV3e9p+k=; b=InC4t0npHoswBijYKSYaDPfBQgdOvafhel58/+U46x78YG+aZa//JdAcNfkTYcjXxy +sBALrstwvA8DDgEd1pMKrz3uYbJNBErNalU89aZhQSL2edf+D+8O/rS5nUNMQYc6BzR vcASm9z94WhBadOb23dQ50AUmYnreq50xZCR62MUFIwsnkvVsBq47YTpJbWbrrF7J7IX t2OkMEJixFu0+UOnct1RbFqgea4a2m0TwGI5AHs0gcqJAG0yWVdXPNa/JmKl83n6RpAj mm22h9hNrhT27C3mmCGDsW3s2+tkQHhfqqe9crfCPcVUY5unDlyOOCjc5nXgb0Thpvxk CCqw== X-Gm-Message-State: ACrzQf1J3XOw9CuRFG4cCPG1JgVJdTG9GqC6K26JUF2FazBaI7/aqWaN wc7RiI4RGcAHMqhymjknXYxhPEdwAkHHOUonPDHYNNEPmDTuTSo+CmLUsIN6Eouus/YpGwn+kCR Ux1MkMVBIV9PQJdZszBIXwGuvIiWx4xbrFqSY/2/jalbqGFvdChgznfChofScI6hEldheSw== X-Received: by 2002:a05:6214:29ef:b0:4b4:5d8c:637c with SMTP id jv15-20020a05621429ef00b004b45d8c637cmr164015qvb.77.1665675102836; Thu, 13 Oct 2022 08:31:42 -0700 (PDT) X-Received: by 2002:a05:6214:29ef:b0:4b4:5d8c:637c with SMTP id jv15-20020a05621429ef00b004b45d8c637cmr163989qvb.77.1665675102525; Thu, 13 Oct 2022 08:31:42 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::50d4? ([2607:fea8:a263:f600::50d4]) by smtp.gmail.com with ESMTPSA id j4-20020a05620a410400b006eea4b5abcesm4172552qko.89.2022.10.13.08.31.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Oct 2022 08:31:41 -0700 (PDT) Message-ID: <8fef9e41-6f71-c3d8-09b9-419201b6c9e7@redhat.com> Date: Thu, 13 Oct 2022 11:31:40 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 To: gcc-patches Subject: [COMMITTED 4/4] PR tree-optimization/102540 - propagate partial equivs in the cache. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.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_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?1746587019061028760?= X-GMAIL-MSGID: =?utf-8?q?1746587019061028760?= Rangers on entry cache propagation already evaluates equivalences when calculating values. This patch also allows it to work with partial equivalences, and if the bit sizes are compatible, make use of those ranges as well. It attempts to be conservative, so should be safe. This resolves regressions in both PR 102540 and PR 102872. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed Andrew From 6cc3394507a2303a18891d34222c53f679256c37 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 5 Oct 2022 10:42:07 -0400 Subject: [PATCH 4/4] propagate partial equivs in the cache. Adjust on-entry cache propagation to look for and propagate both full and partial equivalences. gcc/ PR tree-optimization/102540 PR tree-optimization/102872 * gimple-range-cache.cc (ranger_cache::fill_block_cache): Handle partial equivs. (ranger_cache::range_from_dom): Cleanup dump output. gcc/testsuite/ * gcc.dg/pr102540.c: New. * gcc.dg/pr102872.c: New. --- gcc/gimple-range-cache.cc | 37 +++++++++++++++++++++++++++------ gcc/testsuite/gcc.dg/pr102540.c | 19 +++++++++++++++++ gcc/testsuite/gcc.dg/pr102872.c | 16 ++++++++++++++ 3 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr102540.c create mode 100644 gcc/testsuite/gcc.dg/pr102872.c diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 8c80ba6cd14..0b9aa3639c5 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -1189,8 +1189,9 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) { edge_iterator ei; edge e; - Value_Range block_result (TREE_TYPE (name)); - Value_Range undefined (TREE_TYPE (name)); + tree type = TREE_TYPE (name); + Value_Range block_result (type); + Value_Range undefined (type); // At this point we shouldn't be looking at the def, entry or exit block. gcc_checking_assert (bb != def_bb && bb != ENTRY_BLOCK_PTR_FOR_FN (cfun) && @@ -1221,10 +1222,16 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) if (m_oracle) { tree equiv_name; - FOR_EACH_EQUIVALENCE (m_oracle, bb, name, equiv_name) + relation_kind rel; + int prec = TYPE_PRECISION (type); + FOR_EACH_PARTIAL_AND_FULL_EQUIV (m_oracle, bb, name, equiv_name, rel) { basic_block equiv_bb = gimple_bb (SSA_NAME_DEF_STMT (equiv_name)); + // Ignore partial equivs that are smaller than this object. + if (rel != VREL_EQ && prec > pe_to_bits (rel)) + continue; + // Check if the equiv has any ranges calculated. if (!m_gori.has_edge_range_p (equiv_name)) continue; @@ -1234,16 +1241,32 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) (equiv_bb && !dominated_by_p (CDI_DOMINATORS, bb, equiv_bb))) continue; + if (DEBUG_RANGE_CACHE) + { + if (rel == VREL_EQ) + fprintf (dump_file, "Checking Equivalence ("); + else + fprintf (dump_file, "Checking Partial equiv ("); + print_relation (dump_file, rel); + fprintf (dump_file, ") "); + print_generic_expr (dump_file, equiv_name, TDF_SLIM); + fprintf (dump_file, "\n"); + } Value_Range equiv_range (TREE_TYPE (equiv_name)); if (range_from_dom (equiv_range, equiv_name, bb, RFD_READ_ONLY)) { + if (rel != VREL_EQ) + range_cast (equiv_range, type); if (block_result.intersect (equiv_range)) { if (DEBUG_RANGE_CACHE) { - fprintf (dump_file, "Equivalence update! : "); + if (rel == VREL_EQ) + fprintf (dump_file, "Equivalence update! : "); + else + fprintf (dump_file, "Partial equiv update! : "); print_generic_expr (dump_file, equiv_name, TDF_SLIM); - fprintf (dump_file, "had range : "); + fprintf (dump_file, " has range : "); equiv_range.dump (dump_file); fprintf (dump_file, " refining range to :"); block_result.dump (dump_file); @@ -1458,7 +1481,9 @@ ranger_cache::range_from_dom (vrange &r, tree name, basic_block start_bb, if (DEBUG_RANGE_CACHE) { - fprintf (dump_file, "CACHE: BB %d DOM query, found ", start_bb->index); + fprintf (dump_file, "CACHE: BB %d DOM query for ", start_bb->index); + print_generic_expr (dump_file, name, TDF_SLIM); + fprintf (dump_file, ", found "); r.dump (dump_file); if (bb) fprintf (dump_file, " at BB%d\n", bb->index); diff --git a/gcc/testsuite/gcc.dg/pr102540.c b/gcc/testsuite/gcc.dg/pr102540.c new file mode 100644 index 00000000000..c12f8fcebfb --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr102540.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-tree-evrp" } */ + + +void kill(); + +static long a; +static unsigned b; +int test1 () { + long c, e; + c = b = a; + e = c ? 2 / (c + 1) : 0; + if (e && !b) + kill (); + a = 0; +} + +/* { dg-final { scan-tree-dump-not "kill" "evrp" } } */ + diff --git a/gcc/testsuite/gcc.dg/pr102872.c b/gcc/testsuite/gcc.dg/pr102872.c new file mode 100644 index 00000000000..971bb03a5a7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr102872.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-evrp" } */ + +void foo(void); + +static int a, b; +int main() { + for (; a; ++a) { + unsigned short d = a; + if (!(b | d) && d) + foo(); + } +} + +/* { dg-final { scan-tree-dump-not "foo" "evrp" } } */ + -- 2.37.3