From patchwork Mon Feb 20 07:43:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 59351 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1230102wrn; Mon, 20 Feb 2023 02:23:46 -0800 (PST) X-Google-Smtp-Source: AK7set8eg2/iNQVgLwewGwW/RO8m+j3qo9w0j/PK0w8MJNCyTny72HlhSleFxjyOZadb+0Itzrps X-Received: by 2002:a05:6402:4499:b0:4a3:43c1:8431 with SMTP id er25-20020a056402449900b004a343c18431mr2205285edb.5.1676888626160; Mon, 20 Feb 2023 02:23:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676888626; cv=none; d=google.com; s=arc-20160816; b=1KPFwx3wC+YHkkP7q+NIXAyfQtRQTEbXm77CzAVk1fjentrW5emmuVcWE+5ffnPxVg uJxd72s3vPSRaZPJH82yQgAwGRNV4FVuJLXHDMzTsoqt+5Mi/GvNBoMMOW7+Vn5PdopG 4cuGMEbdxFlLGBGbIi+TTQJjh5iDkeTR1shk4vx6WNW22fneCNbgXTZKlDeA6pFg5WCd yU67cwknvkayNJSAVuuYmQFma62ZuIcTzDJRe77bjj4DB1fia7faw7ZFJhvZ8e2BDVVK ai58mt23KPfZog/RguYWSASrPqqs38Ur3DTJtt7eukH2CYJo9Cxt4nC3G0DogP51xn7X ppcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=yTMiIzLTC79oqUciqu3bWTRUzxfGbYbXO7s9eJ227z4=; b=RelB/JJ5XrTWql2B4kOtr+F7N9dcSW2KTBHfv99vmXK+ZxgaGz55TeUGjp6OqECcV1 Ipd+QfbauNO+Uu9iDYggb4KqeOiBRaNqqoUbPIZr+ydV1IWgHnEkMuZpZQkNGMejLPEG Letxids00FAHOrU5DSTODsg+PMwSxrcSboh1IRgH8f678LojyCo9TXZZzOD0nJ46sgSA EL7+Kt5paR0sjdbz8gz1nWqBN1YRY1FO3cwF0BzE30h6yisy8Rzbje5ascdS5E3XkmDS 1dzOLq+uY1q5ZZH4ta5u4Uak2ewk498bDH7y7CkNhvLnASK8Ru7ZjD3OIKZCWwt644Fm ZdLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pfpzQetN; 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 h15-20020a50ed8f000000b004acc6c7a631si4040119edr.179.2023.02.20.02.23.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 02:23:46 -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=pfpzQetN; 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 E5776396E47E for ; Mon, 20 Feb 2023 10:11:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E5776396E47E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676887872; bh=yTMiIzLTC79oqUciqu3bWTRUzxfGbYbXO7s9eJ227z4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pfpzQetNatHB+72uLVg74uyz6hXqcVTrHdEWlywlw/Y6wakCKRXJu/bvcJPWHfgrJ SFpDX+DtgIhZ6ws6X8UU6KhKFNxNi4VuRNBqq5wPjF+VYMTiV1f7KXk0JkjW7cttkJ FDN64kAuddkPa3ZoVtO6USLpDf5PBNna3UM+kpDc= 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 EEF8C38A815A for ; Mon, 20 Feb 2023 10:10:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EEF8C38A815A Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 0C7D91F896 for ; Mon, 20 Feb 2023 07:43:14 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 01A772C141 for ; Mon, 20 Feb 2023 07:43:13 +0000 (UTC) Date: Mon, 20 Feb 2023 07:43:13 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/108819 - niter analysis ICE with unexpected constant User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable 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" Message-Id: <20230220101112.E5776396E47E@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758345167812612598?= X-GMAIL-MSGID: =?utf-8?q?1758345167812612598?= The following makes sure we do not ICE on unfolded stmts like _1 = 1 & 1. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/108819 * tree-ssa-loop-niter.cc (number_of_iterations_cltz): Check we have an SSA name as iv_2 as expected. * gcc.dg/pr108819.c: New testcase. --- gcc/testsuite/gcc.dg/pr108819.c | 14 ++++++++++++++ gcc/tree-ssa-loop-niter.cc | 6 ++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr108819.c diff --git a/gcc/testsuite/gcc.dg/pr108819.c b/gcc/testsuite/gcc.dg/pr108819.c new file mode 100644 index 00000000000..a651f819908 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr108819.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fno-tree-ccp -fno-tree-forwprop" } */ + +int a, b; +int main() { + int d = 1; + for (; b; b++) + if (a < 1) + while (d <= a && a <= 0UL) { + int *e = &d; + *e = 0; + } + return 0; +} diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc index 581bf5d067b..1ce5e736ce3 100644 --- a/gcc/tree-ssa-loop-niter.cc +++ b/gcc/tree-ssa-loop-niter.cc @@ -2354,7 +2354,8 @@ number_of_iterations_cltz (loop_p loop, edge exit, gimple *and_stmt = SSA_NAME_DEF_STMT (gimple_cond_lhs (cond_stmt)); if (!is_gimple_assign (and_stmt) || gimple_assign_rhs_code (and_stmt) != BIT_AND_EXPR - || !integer_pow2p (gimple_assign_rhs2 (and_stmt))) + || !integer_pow2p (gimple_assign_rhs2 (and_stmt)) + || TREE_CODE (gimple_assign_rhs1 (and_stmt)) != SSA_NAME) return false; checked_bit = tree_log2 (gimple_assign_rhs2 (and_stmt)); @@ -2382,7 +2383,8 @@ number_of_iterations_cltz (loop_p loop, edge exit, precision. */ iv_2 = gimple_assign_rhs1 (test_value_stmt); tree rhs_type = TREE_TYPE (iv_2); - if (TREE_CODE (rhs_type) != INTEGER_TYPE + if (TREE_CODE (iv_2) != SSA_NAME + || TREE_CODE (rhs_type) != INTEGER_TYPE || (TYPE_PRECISION (rhs_type) != TYPE_PRECISION (test_value_type))) return false;