From patchwork Mon Dec 19 14:56:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 62148 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 40C3B3858C66 for ; Mon, 19 Dec 2022 14:57:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 40C3B3858C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671461850; bh=QZow2uR0wpZHVyK0DHlnpZSn+XygsvI6qq5eySI/w2c=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=SbzM9N1jkXrtCcGVOgfliqrLIfi2z/OAHgC0J2lWySpog2tlvXFR/ymIPNuE22xh/ BQc7pk52gL3LKGHMpvz4lQU9EVMHFv5odVsnEd96lIUtcYxuVNKGtdUDzYQAuxSn4a OG1p8b3R05yOKslEqCRGlKy0S5Bwl4kOYJrX75QY= 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 78C573858D1E for ; Mon, 19 Dec 2022 14:57:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 78C573858D1E Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-436-XKthmYX9NfKo-GBzHVwjIQ-1; Mon, 19 Dec 2022 09:56:59 -0500 X-MC-Unique: XKthmYX9NfKo-GBzHVwjIQ-1 Received: by mail-io1-f72.google.com with SMTP id s22-20020a6bdc16000000b006e2d7c78010so4141231ioc.21 for ; Mon, 19 Dec 2022 06:56:59 -0800 (PST) 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=2vA3whYfKSERA6sO5i57Or4dGx4fwyJm2mE5PICdRjA=; b=iKJdicQ2ou0K0d281d81Q2rvKAun7ktOxWD9DiQKOkRFLbZpfrnLIkdIBM/sbVWUbZ dfEBdLT+zGVbbX5aMjwVlVIg5cq4+TSY34isOp6JoVbKfWU3ssBVJ+n0AaV4pAGUUw73 fM4t2GwFWbhr/n18BfI7WU9XRanpefF4oKshfVpqOdhMvEsPUMsnB9/j5oiq5CLkaQui vOPXXzUVB5TlWpC4qYujpDuj18Wf2SAbhvlGKlBIDC3esqSDFloWI73KqJRMPgpcCGNf SjI/5S3zwQbkleSwqJNlTv1RpSUU6l3vNWMJASCwSqxWRsQ+uoH9c8/Wg4F3ljtI3ZCz ln0g== X-Gm-Message-State: AFqh2ko48G5uFyQK5Cnlgv7azxQXOQcpbwlpN5xpDzUm+P5D5WvoNOWI BMIPYheoGWUN17Wfs1Fnep5Y+3xRp8y7mHIlIv/qxYHCgh4bYIL5dDw30YyQv/F/n+WwYNDDXYv oS4leehr1lLWfvJSVkQDOdLnS4LPY1kLxCpEOqSAgb0UOXih8P2Z93pwP1qBCmV7WkkM/hA== X-Received: by 2002:a05:6e02:1414:b0:30b:b95c:e10d with SMTP id n20-20020a056e02141400b0030bb95ce10dmr1352002ilo.8.1671461818053; Mon, 19 Dec 2022 06:56:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXupld9H59BnWpRXv5+WfNs3DFUxmWwK6VXzjCmWgqbuLZUxJBqXX/UHMqdh8mFdf21oLPzaWQ== X-Received: by 2002:a05:6e02:1414:b0:30b:b95c:e10d with SMTP id n20-20020a056e02141400b0030bb95ce10dmr1351990ilo.8.1671461817643; Mon, 19 Dec 2022 06:56:57 -0800 (PST) Received: from ?IPV6:2607:fea8:a263:f600::6c01? ([2607:fea8:a263:f600::6c01]) by smtp.gmail.com with ESMTPSA id w15-20020a056e0213ef00b003024928a9afsm3306748ilj.83.2022.12.19.06.56.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Dec 2022 06:56:56 -0800 (PST) Message-ID: Date: Mon, 19 Dec 2022 09:56:55 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 To: gcc-patches Cc: "hernandez, aldy" Subject: [PATCH] PR tree-optimization/108139 - Don't use PHI equivalences in range-on-entry. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.5 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, RCVD_IN_MSPIKE_H2, 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" our use of equivalences on range-on-entry calculations cause an issue through a PHI node when a back edge is involved.  ie    a = VARYING    <...> bb5    b = PHI bb6    if (a != 0)      goto bb5 since the value of b is undefined on the edge 2->5, we ignore it. The range of a on the edge 6->5 is ~[0,0] we calculate the range of b to be ~[0,0].   we also provide an equivalency between a and b. Unfortunately the on-entry code looks at equivalencies, and says, "hey, a and b are equivalent, so we can use the range of b instead" So it now thinks a is ~[0,0] and folds away the condition. The problem is that b can be considered equivalent to a, but the converse is not true, because there is a path (2->5) upon which a is not equivalent to b.  we have no way to represent a one way equivalence at the moment. This patch avoid using that relation in range-on-entry calculations. Perhaps next release I'll add a specific kind of one way equivalence for this kind of situation. Bootstraps on x86_64-pc-linux-gnu with no regressions. OK? Andrew commit ecf19b6eb6f8e17d8d148e3c6627bd2151766420 Author: Andrew MacLeod Date: Fri Dec 16 16:53:31 2022 -0500 Don't use PHI equivalences in range-on-entry. If there is only one argument to a PHI which is defined, an equivalency is created between the def and the argument. It is safe to consider the def equal to the argument, but it is dangerous to assume the argument is also equivalent to the def as there may be branches which change the range on the path to the PHI on that argument This patch avoid using that relation in range-on-entry calculations. PR tree-optimization/108139 gcc/ * gimple-range-cache.cc (ranger_cache::fill_block_cache): Do not use equivalences originating from PHIS. gcc/testsuite/ * gcc.dg/pr108139.c: New. diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index ce5a0c8155e..9848d140242 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -1235,6 +1235,13 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) if (!m_gori.has_edge_range_p (equiv_name)) continue; + // PR 108139. It is hazardous to assume an equivalence with + // a PHI is the same value. The PHI may be an equivalence + // via UNDEFINED arguments which is really a one way equivalence. + // PHIDEF == name, but name may not be == PHIDEF. + if (is_a (SSA_NAME_DEF_STMT (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))) diff --git a/gcc/testsuite/gcc.dg/pr108139.c b/gcc/testsuite/gcc.dg/pr108139.c new file mode 100644 index 00000000000..6f224e3ce62 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108139.c @@ -0,0 +1,18 @@ +/* { dg-do compile { target int128 } } */ +/* { dg-options "-O1 -ftree-vrp -fdump-tree-vrp" } */ + +int a, b; +int main() { + int c; + if (a > 1) + a++; + while (a) + if (c == b) + c = a; + return 0; +} + + +/* { dg-final { scan-tree-dump-not "Folding predicate" "vrp2" } } */ + +