From patchwork Wed Dec 2 08:33:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 551244 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A05031401DA for ; Wed, 2 Dec 2015 19:33:49 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=yMEaSLmZ; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=U5rtF6szFwG+ZYKo d40Oxpyki7dJECZDvnA8GghE6gfDaxDalzUghegKvXoFbmlU/dYsg8iXMetUZ9ip TvPNmxtfpz6myZSSqtq0IOXAzvow2iq/SwGirqvQF3xwfMLLv2Vgozmc9mlYNcWg jrLexg1GMSOgmHJiK6Gaq64oqwo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=QaBsT/4wis8lXvDetk/0MN sPxGY=; b=yMEaSLmZazSSmX1hkAcMiik7R/ZOw/dh3u91IyUQSy7m84vVBc5eUQ tnERoVzaktniQG8quO5lkeUKRGcjdHX6nCq09o6DzRMIxtyfHrR0MfzIxEwpxZ6F OV2FX0zdG3a9sgkg/5RNaCcVCQLVg1plLoNr72dpjRM9ToF5xA67s= Received: (qmail 1550 invoked by alias); 2 Dec 2015 08:33:42 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 1537 invoked by uid 89); 2 Dec 2015 08:33:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (207.82.80.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 02 Dec 2015 08:33:39 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-34-95WdUHGES9KRcV7_J_SZRg-1; Wed, 02 Dec 2015 08:33:34 +0000 Received: from localhost ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 2 Dec 2015 08:33:34 +0000 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: PR68146: Check for null SSA_NAME_DEF_STMTs in fold-const.c Date: Wed, 02 Dec 2015 08:33:34 +0000 Message-ID: <87fuzlckrl.fsf@e105548-lin.cambridge.arm.com> User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-MC-Unique: 95WdUHGES9KRcV7_J_SZRg-1 The problem in the testcase was that tree-complex.c was trying to fold ABS_EXPRs of SSA names that didn't yet have a definition (because the SSA names were real and imaginary parts of a complex SSA name whose definition hadn't yet been visited by the pass). tree-complex.c uses a straightforward walk in index order: /* ??? Ideally we'd traverse the blocks in breadth-first order. */ old_last_basic_block = last_basic_block_for_fn (cfun); FOR_EACH_BB_FN (bb, cfun) { and in the testcase, we have a block A with a single successor B that comes before it. B has no other predecessor and has a complex division that uses an SSA name X defined in A, so we split the components of X before we reach the definition of X. (I imagine cfgcleanup would clean this up by joining A and B.) Tested on x86_64-linux-gnu. OK to install? Thanks, Richard gcc/ PR tree-optimization/68146 * fold-const.c (tree_binary_nonnegative_warnv_p): Check for null SSA_NAME_DEF_STMTs. (integer_valued_real_call_p): Likewise. gcc/testsuite/ * gfortran.fortran-torture/compile/pr68146.f90: New test. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 16bff5f..c99e78e 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -12867,6 +12867,8 @@ tree_binary_nonnegative_warnv_p (enum tree_code code, tree type, tree op0, bool tree_single_nonnegative_warnv_p (tree t, bool *strict_overflow_p, int depth) { + gimple *stmt; + if (TYPE_UNSIGNED (TREE_TYPE (t))) return true; @@ -12892,8 +12894,9 @@ tree_single_nonnegative_warnv_p (tree t, bool *strict_overflow_p, int depth) to provide it through dataflow propagation. */ return (!name_registered_for_update_p (t) && depth < PARAM_VALUE (PARAM_MAX_SSA_NAME_QUERY_DEPTH) - && gimple_stmt_nonnegative_warnv_p (SSA_NAME_DEF_STMT (t), - strict_overflow_p, depth)); + && (stmt = SSA_NAME_DEF_STMT (t)) + && gimple_stmt_nonnegative_warnv_p (stmt, strict_overflow_p, + depth)); default: return tree_simple_nonnegative_warnv_p (TREE_CODE (t), TREE_TYPE (t)); @@ -13508,6 +13511,7 @@ integer_valued_real_call_p (combined_fn fn, tree arg0, tree arg1, int depth) bool integer_valued_real_single_p (tree t, int depth) { + gimple *stmt; switch (TREE_CODE (t)) { case REAL_CST: @@ -13524,8 +13528,8 @@ integer_valued_real_single_p (tree t, int depth) to provide it through dataflow propagation. */ return (!name_registered_for_update_p (t) && depth < PARAM_VALUE (PARAM_MAX_SSA_NAME_QUERY_DEPTH) - && gimple_stmt_integer_valued_real_p (SSA_NAME_DEF_STMT (t), - depth)); + && (stmt = SSA_NAME_DEF_STMT (t)) + && gimple_stmt_integer_valued_real_p (stmt, depth)); default: break; diff --git a/gcc/testsuite/gfortran.fortran-torture/compile/pr68146.f90 b/gcc/testsuite/gfortran.fortran-torture/compile/pr68146.f90 new file mode 100644 index 0000000..7f75ec0 --- /dev/null +++ b/gcc/testsuite/gfortran.fortran-torture/compile/pr68146.f90 @@ -0,0 +1,11 @@ +subroutine foo(a1, a2, s1, s2, n) + integer :: n + complex(kind=8) :: a1(n), a2(n), s1, s2 + do i = 1, n + a1(i) = i + end do + s1 = 20.0 / s2 + do i = 1, n + a2(i) = i / s2 + end do +end subroutine foo