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: 34599 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2435128wrn; Mon, 19 Dec 2022 06:57:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXunV2p/2bX5ib3kGzvcDSZVXOu1Rj83VmqMM47JVr4l20nPSN1vqEI6NA8oB4F5S46yYfiy X-Received: by 2002:a05:6402:c4f:b0:47a:a75a:d99b with SMTP id cs15-20020a0564020c4f00b0047aa75ad99bmr2968880edb.38.1671461869620; Mon, 19 Dec 2022 06:57:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671461869; cv=none; d=google.com; s=arc-20160816; b=PhXEWf5cVL2Vx0RKBMPmrU5rgvvPEmgP5xnUKKxS+oDSDZ7BKzOWfuNb+ffZE8eJEC t2RZ5o3/uMK5fT8SnsdYEsk6wmu3O0WrrDrsPdGfef4A2RWepk20kpvlAT613vCMG/kd 0vg+vs6hkIAaE6yr7qO3ojhvv5uLPn7+rRNwVAAXozmNrdDme8lm4+7MsOQuMbgzJKFB QFtaJn8l93k8ASGidbdZ2SR+Br01At80TWPG3hAjJiVfI4Pb52lYjJqgu1aZ/OEKsRqc 0/8cXb4X1JJ9H17809MtpB3Q0SvVF6ybLdhy0pFCZcOuANiHgyamtO4PiZ/C3rq+lpm9 ADKQ== 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:cc:to:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=QZow2uR0wpZHVyK0DHlnpZSn+XygsvI6qq5eySI/w2c=; b=rSHT5tnRAPljcvxpW5kcCvS6NRZTzrfnKzA2fzy9XZHIbcF6A8MoZvXNt8IhFIOVH+ 2H9ks70s2g4sCDjoBJKVCzJD4DGzggMOW8MM0brQU8h57ygioPumlPUk+vyRHlanNdAo L+r21jVWbJhKobhFHLIaPik0YxWmkruYaaWjrOnjc2/2V+Gz8/zDoeTXVo/KCmMWTJ5p 8xnaeuMHOZF3vf//Grm8lRQqmT+3GeFHgVvpd+8BBR5dftBzfWo/uPsZlVUFhyH53QIe 1vHeUDiQtgN1V8JXiG2/opfHM8EtyUFrR8LFD3YkE65IctRuAff92Cx6nfTwFXiA/bhD H6jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GD8M5ATz; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id ec32-20020a0564020d6000b0046dc6205bc3si7869101edb.460.2022.12.19.06.57.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Dec 2022 06:57:49 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GD8M5ATz; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 A89533858C83 for ; Mon, 19 Dec 2022 14:57:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A89533858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671461868; 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=GD8M5ATzstRYzjv6qHL8HWLo//xA2YJOY9zCXahvHEA353/UnDDCbX5nKQ5wMi7Zl 9Fl7du0VoEZ4nExK6xRm9CnmyVr8dcj/N3HLNDB+nItn+rTmGpK784k4HlGswVR2Nw N0k5xUBSISCLgcyJ3wyVqtJQ/AKOtI0DUwdg8gLI= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752654801453360212?= X-GMAIL-MSGID: =?utf-8?q?1752654801453360212?= 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" } } */ + +