From patchwork Mon Nov 28 10:16:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 61144 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 D934D3858020 for ; Mon, 28 Nov 2022 10:17:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D934D3858020 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669630643; bh=lAazTd+EfHIHBZoSzHgxtmRsvfpyhWE/5yTkk2qLF4M=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=hd+0+AQYfgMbR+imtRcSJEXN4Le0z833l3+M8uDgRRNteaxSJqwFW6WhJdhWDHNMb RekAfRh6bbdg8wZV3XV/Y/YSuVJ/J3fpUWnOZ1rDW//7RviJGAIDyos2FUlr+QgifT gxY3iatL0k41MZEPiB7vdMvVUn5rYjqI8lT1WOVk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 632A43858CDB for ; Mon, 28 Nov 2022 10:16:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 632A43858CDB Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 173C91F898 for ; Mon, 28 Nov 2022 10:16:53 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0419F1326E for ; Mon, 28 Nov 2022 10:16:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id k5dzO5SKhGMWGQAAMHmgww (envelope-from ) for ; Mon, 28 Nov 2022 10:16:52 +0000 Date: Mon, 28 Nov 2022 11:16:52 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/107493 - SCEV analysis with conversions MIME-Version: 1.0 Message-Id: <20221128101653.0419F1326E@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 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. --- gcc/testsuite/gcc.dg/torture/pr107493.c | 13 +++++++++++++ gcc/tree-scalar-evolution.cc | 10 ++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr107493.c 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; }