From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1011) id 9F1403858421; Tue, 20 Dec 2022 14:27:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F1403858421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671546477; bh=pKxdmEZ5atsorX7OAOd5M17tfU2p6Lp1UsQW0BCWpmk=; h=From:To:Subject:Date:From; b=EGYX4ED0HzQhbzEXinnM+TuzVSs3AiHQWUQ7sj5MoZpf0y7XTDumMV7S2MwYbUbM1 6nY8xtoUUvE/0WAEWfs329tiDyiH50P8ilaUlUBu5kSnnT8AUdQyyXWlxGgqHAPRYa bjb0wl1yZN9rXvSKj2U3wMkFyO3FQvTOnGwtkz18= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Macleod To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4806] Don't use PHI equivalences in range-on-entry. X-Act-Checkin: gcc X-Git-Author: Andrew MacLeod X-Git-Refname: refs/heads/master X-Git-Oldrev: 05b7cf52e1b640271900894a894da2d27ef90092 X-Git-Newrev: 0bdd2261c254f08b0f4437c156b79711d68c6e7f Message-Id: <20221220142757.9F1403858421@sourceware.org> Date: Tue, 20 Dec 2022 14:27:57 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0bdd2261c254f08b0f4437c156b79711d68c6e7f commit r13-4806-g0bdd2261c254f08b0f4437c156b79711d68c6e7f 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: --- gcc/gimple-range-cache.cc | 7 +++++++ gcc/testsuite/gcc.dg/pr108139.c | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) 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" } } */ + +