From patchwork Thu May 13 20:15:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1478183 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=m0FovEWI; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Fh2w35WWgz9sVv for ; Fri, 14 May 2021 06:15:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A2C14385802A; Thu, 13 May 2021 20:15:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A2C14385802A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1620936929; bh=A1k80Uxo4kWJhzmCWslnPIxXPbf1JbHdWHRx1mq74OA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=m0FovEWIwdx9PKrgmWBCt5YdUCec9Ii0Y/xuz4NWwiiEOtaCIroHnbR3EkLZYFCHc 2PjysGIQJqS4xz9FVayyxrQ7uDjlJc2Mqqf9DNJd2JwkmT5hTk/aGcXuEEY+gTQH6O pgo7bMWcipsDTB7XcYVjPU8u2ss4hiGB/WR55+z0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id DBC7A385800A for ; Thu, 13 May 2021 20:15:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DBC7A385800A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-LdtrALqsN36Ct9tYFm-mXw-1; Thu, 13 May 2021 16:15:25 -0400 X-MC-Unique: LdtrALqsN36Ct9tYFm-mXw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 68C2B6D5CB for ; Thu, 13 May 2021 20:15:24 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.22.8.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2E0623807; Thu, 13 May 2021 20:15:24 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.16.1/8.15.2) with ESMTPS id 14DKFMFa334507 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 13 May 2021 16:15:23 -0400 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 14DKFMIK334506; Thu, 13 May 2021 16:15:22 -0400 To: GCC patches Subject: [PATCH] Bail in bounds_of_var_in_loop if scev returns NULL. Date: Thu, 13 May 2021 16:15:19 -0400 Message-Id: <20210513201519.334441-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Both initial_condition_in_loop_num and evolution_part_in_loop_num can return NULL. This patch exits if either one is NULL. Presumably this didn't happen before, because adjust_range_with_scev was called far less frequently than in ranger, which can call it for every PHI. OK pending tests? gcc/ChangeLog: PR tree-optimization/100349 * vr-values.c (bounds_of_var_in_loop): Bail if scev returns NULL. gcc/testsuite/ChangeLog: * gcc.dg/pr100349.c: New test. --- gcc/testsuite/gcc.dg/pr100349.c | 16 ++++++++++++++++ gcc/vr-values.c | 3 +++ 2 files changed, 19 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr100349.c diff --git a/gcc/testsuite/gcc.dg/pr100349.c b/gcc/testsuite/gcc.dg/pr100349.c new file mode 100644 index 00000000000..dd7977ac0f9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr100349.c @@ -0,0 +1,16 @@ +// { dg-do compile } +// { dg-options "-O2 -w" } + +#include +uint8_t a; +b(int8_t c) { + int d; +e: + uint32_t f; + for (;;) + for (c = 10; c; c++) + if (0 > (a = c) ?: d) { + f = a; + goto e; + } +} diff --git a/gcc/vr-values.c b/gcc/vr-values.c index 08b237b2632..b1bf53af9e0 100644 --- a/gcc/vr-values.c +++ b/gcc/vr-values.c @@ -1650,6 +1650,9 @@ bounds_of_var_in_loop (tree *min, tree *max, range_query *query, init = initial_condition_in_loop_num (chrec, loop->num); step = evolution_part_in_loop_num (chrec, loop->num); + if (!init || !step) + return false; + /* If INIT is an SSA with a singleton range, set INIT to said singleton, otherwise leave INIT alone. */ if (TREE_CODE (init) == SSA_NAME)