From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id E028E385B181; Mon, 28 Nov 2022 10:17:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E028E385B181 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669630658; bh=PVQZItCYoNIFG0zjQN7ybYJeKicZO3WsF/xBbGJNw94=; h=From:To:Subject:Date:From; b=YsmTpWqJSUSPu9+3hZDO8jYEf4clmbykLbqlE0xx9JjUmF0t561XB26ymuRw3OLYQ ZsKTllBqXrcdIC1ffJ53Es/hzh/ZpIxzGzO0rx9bP8LvuZxPDXtLjtxGG4nBuYPx+s ciyF907Qap01dPNCXGE3YHUUBAqayhEin3kQEj98= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4357] tree-optimization/107493 - SCEV analysis with conversions X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: 9fa67f1c1228a852e23943a41e68b664172c654c X-Git-Newrev: 2b293a949c0fbe21e47c4bc99f807dc941c02bb6 Message-Id: <20221128101738.E028E385B181@sourceware.org> Date: Mon, 28 Nov 2022 10:17:38 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2b293a949c0fbe21e47c4bc99f807dc941c02bb6 commit r13-4357-g2b293a949c0fbe21e47c4bc99f807dc941c02bb6 Author: Richard Biener Date: Mon Nov 28 10:25:44 2022 +0100 tree-optimization/107493 - SCEV analysis with conversions This shows another case where trying to validate conversions during the CHREC SCC analysis fails because said analysis assumes we are converting a complete SCC. Like the constraint on the initial conversion seen restrict all conversions handled to sign-changes. PR tree-optimization/107493 * tree-scalar-evolution.cc (scev_dfs::follow_ssa_edge_expr): Only handle no-op and sign-changing conversions. * gcc.dg/torture/pr107493.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/torture/pr107493.c | 13 +++++++++++++ gcc/tree-scalar-evolution.cc | 10 ++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr107493.c b/gcc/testsuite/gcc.dg/torture/pr107493.c new file mode 100644 index 00000000000..b36692133d8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr107493.c @@ -0,0 +1,13 @@ +/* { dg-do run { target int32plus } } */ + +int a; +int b(int c) { return c; } +int main() +{ + a = -21; + for (; a <= 0; a = (unsigned short)(b(a + 2) + 8)) + ; + if (a != 65525) + __builtin_abort(); + return 0; +} diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc index 60060337804..f75398afb7c 100644 --- a/gcc/tree-scalar-evolution.cc +++ b/gcc/tree-scalar-evolution.cc @@ -1227,10 +1227,16 @@ scev_dfs::follow_ssa_edge_expr (gimple *at_stmt, tree expr, { CASE_CONVERT: { - /* This assignment is under the form "a_1 = (cast) rhs. */ + /* This assignment is under the form "a_1 = (cast) rhs. We cannot + validate any precision altering conversion during the SCC + analysis, so don't even try. */ + if (!tree_nop_conversion_p (type, TREE_TYPE (rhs0))) + return t_false; t_bool res = follow_ssa_edge_expr (at_stmt, rhs0, evolution_of_loop, limit); - *evolution_of_loop = chrec_convert (type, *evolution_of_loop, at_stmt); + if (res == t_true) + *evolution_of_loop = chrec_convert (type, *evolution_of_loop, + at_stmt); return res; }