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: 26608 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5557393wrr; Mon, 28 Nov 2022 02:17:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf4fWYB/LOUQ3gRvfU6LqSgG7IKeFC2ZOi9hg75FNkazUksfbuTTUegjn3q9FHpBROXyIjad X-Received: by 2002:a05:6402:3711:b0:461:b6a9:c5cb with SMTP id ek17-20020a056402371100b00461b6a9c5cbmr32226460edb.148.1669630659602; Mon, 28 Nov 2022 02:17:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669630659; cv=none; d=google.com; s=arc-20160816; b=Mby+kemsNDuIa+uzvt/zCDWGDs5CIfzwTYkq/VCzJEMCtCfNEE4CyPfVk9TXIV0KgL egMuKKZuQbyY8X4skYBnJjay0r5uO3PRtH24rjtL9wRE/aSStzQfO2U9JMq87Hlm9KhX T6mp016wWzxMjPbzciIlmYTqRLcPfQm6JNwRSLaz5jUl0vxoxcLaD3PkbWxZfwBxCT8v eZA4/1EoWPwVmbJeaykXj/YjlNRYbXPDvpNAx33riVIsOoxHOClcpqmCJQ81KqkDkeUI 6G7ZeqrYJ66gJG6ox0ef9P0lGrYs30Uyy2L2sqwRKzUuPpt1S29XlvrOh4i3CtE209KD 3qxQ== 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:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=lAazTd+EfHIHBZoSzHgxtmRsvfpyhWE/5yTkk2qLF4M=; b=lLfwZrvuoeErGtbZLex6tVaU2Z8S362bP0Lfn+QNqMJAvKjOv8oC8b1UaV13NA47GT rByNFy59u3HDS7avrHkyKeuRB4izN8Tt12xsBfsYmc+r6A4xNWKve5blk6y+JPyrSyKk gOfalpmXN/oxY0V3O18MmhVK6VecYvdRWEYIs0geDmnyVh+v3jdzdWmmE8UoXIADEIYm c2P9pQDaE7vwQKNVmObmfJstvJayHLZ7A6Q2+qQpEBeGHtA5v+GSiypCaEi99GLSoIVb DRS7RupIOMDTN38LexFc20wT5NuCDb0x6B/a8oorV9eskwKjyQMH31AP2MEk2zQ7YuP8 FpWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TsjQiiTu; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f16-20020a0564021e9000b004680b40d2ecsi10589461edf.235.2022.11.28.02.17.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 02:17:39 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=TsjQiiTu; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 658D9385B1A1 for ; Mon, 28 Nov 2022 10:17:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 658D9385B1A1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669630658; 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=TsjQiiTu7Ex2JiVOrAUNVNCWjUcNgsycJcDa28kNm/lsR+eaMvrMqrj2Y9m4rR8bp Bg+X8aAMNL0iT3qbk2RbFtuCd0iMCM7MEmf7bwlHrq87zO1AtInoJtMVNPmpPzMGIV e0MIuEGwoxnUn4ihD3aIDZjVKRWqFvj8SXTBXei4= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750734638718062596?= X-GMAIL-MSGID: =?utf-8?q?1750734638718062596?= 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; }