From patchwork Fri Dec 17 19:50:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 75973 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]) by ozlabs.org (Postfix) with SMTP id CECAB1007D6 for ; Sat, 18 Dec 2010 06:50:47 +1100 (EST) Received: (qmail 3809 invoked by alias); 17 Dec 2010 19:50:45 -0000 Received: (qmail 3795 invoked by uid 22791); 17 Dec 2010 19:50:44 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 17 Dec 2010 19:50:38 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oBHJoaR3007032 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 17 Dec 2010 14:50:36 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oBHJoZpM005311 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 17 Dec 2010 14:50:36 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id oBHJoUMM011548; Fri, 17 Dec 2010 20:50:30 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id oBHJoPUi011547; Fri, 17 Dec 2010 20:50:25 +0100 Date: Fri, 17 Dec 2010 20:50:25 +0100 From: Jakub Jelinek To: Sebastian Pop Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ICE in scev analysis (PR tree-optimization/46985) Message-ID: <20101217195024.GF2198@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! On this testcase, we have x_1 = &tar[0].i + y_2; stmt in a loop and when trying to find out if it is constant during the loop, during scev processing folding of &tar[0].i + a multiplication folds it into the COMPONENT_REF. As COMPONENT_REF has TREE_CODE_LENGTH 3, instantiate_scev_r calls instantiate_scev_3 on it. COMPONENT_REF has just 2 mandated arguments though and the third one is optional (I think there is a lot of other tree codes with similar optional arguments) and thus instantiate_scev_r that is called on the last argument which is missing (NULL) ICEs. Fixed by passing through NULL_TREE, which means it handles all optional arguments nicely. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2010-12-17 Jakub Jelinek PR tree-optimization/46985 * tree-scalar-evolution.c (instantiate_scev_r): If chrec is NULL, return it immediately. * gfortran.dg/pr46985.f90: New test. Jakub --- gcc/tree-scalar-evolution.c.jj 2010-12-06 08:08:55.000000000 +0100 +++ gcc/tree-scalar-evolution.c 2010-12-17 13:30:27.000000000 +0100 @@ -2616,7 +2616,8 @@ instantiate_scev_r (basic_block instanti if (size_expr++ > PARAM_VALUE (PARAM_SCEV_MAX_EXPR_SIZE)) return chrec_dont_know; - if (automatically_generated_chrec_p (chrec) + if (chrec == NULL_TREE + || automatically_generated_chrec_p (chrec) || is_gimple_min_invariant (chrec)) return chrec; --- gcc/testsuite/gfortran.dg/pr46985.f90.jj 2010-12-17 13:56:03.000000000 +0100 +++ gcc/testsuite/gfortran.dg/pr46985.f90 2010-12-17 13:53:59.000000000 +0100 @@ -0,0 +1,17 @@ +! PR tree-optimization/46985 +! { dg-do compile } +! { dg-options "-O -ftree-pre -ftree-vrp -fno-tree-ccp -fno-tree-dominator-opts -fno-tree-fre" } + + type :: t + integer :: i + end type t + type(t), target :: tar(2) = (/t(2), t(4)/) + integer, pointer :: ptr(:) + ptr => tar%i + call foo (ptr) +contains + subroutine foo (arg) + integer :: arg(:) + arg = arg - 1 + end subroutine +end