From patchwork Mon Apr 4 20:26:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 89707 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 34905B6F8C for ; Tue, 5 Apr 2011 06:26:54 +1000 (EST) Received: (qmail 21103 invoked by alias); 4 Apr 2011 20:26:52 -0000 Received: (qmail 21091 invoked by uid 22791); 4 Apr 2011 20:26:51 -0000 X-SWARE-Spam-Status: No, hits=-0.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cc-smtpout2.netcologne.de (HELO cc-smtpout2.netcologne.de) (89.1.8.212) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 04 Apr 2011 20:26:46 +0000 Received: from cc-smtpin3.netcologne.de (cc-smtpin3.netcologne.de [89.1.8.203]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id 5EA151281A; Mon, 4 Apr 2011 22:26:45 +0200 (CEST) Received: from [192.168.0.197] (xdsl-78-35-154-196.netcologne.de [78.35.154.196]) by cc-smtpin3.netcologne.de (Postfix) with ESMTPSA id 341CA11E81; Mon, 4 Apr 2011 22:26:43 +0200 (CEST) Message-ID: <4D9A2983.4020502@netcologne.de> Date: Mon, 04 Apr 2011 22:26:43 +0200 From: Thomas Koenig User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.14) Gecko/20110221 SUSE/3.1.8 Thunderbird/3.1.8 MIME-Version: 1.0 To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, fortran, committed] Fix regression PR 48412 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 Hello world, I have committed the attached patch to trunk as obvious after regression-testing. The problem was that the assignment statements had been added in the wrong order, which was fixed by reversing the order of the loops looking for common function calls in cfe_expr_0. Many thanks to Joost for finding the bug in the first place and for reducing that far! Thomas 2011-04-04 Thomas Koenig PR fortran/48412 * frontend-passes (cfe_expr_0): Reverse the order of going through the loops. 2011-04-04 Thomas Koenig PR fortran/48412 * function_optimize_4.f90: New test. ! { dg-do run } ! { dg-options "-O" } ! PR 48412 - function elimination got temporary varibles in the wrong order. ! Test case contributed by Joost VandeVondele. INTEGER FUNCTION S1(m,ma,lx) INTEGER :: m,ma,lx IF (((m < 0).AND.(MODULO(ABS(ma-lx),2) == 1)).OR.& ((m > 0).AND.(MODULO(ABS(ma-lx),2) == 0))) THEN S1=1 ELSE S1=0 ENDIF END FUNCTION INTEGER :: s1 IF (S1(1,2,1).NE.0) CALL ABORT() END Index: frontend-passes.c =================================================================== --- frontend-passes.c (Revision 171913) +++ frontend-passes.c (Arbeitskopie) @@ -295,16 +295,16 @@ cfe_expr_0 (gfc_expr **e, int *walk_subtrees, gfc_expr_walker (e, cfe_register_funcs, NULL); - /* Walk backwards through all the functions to make sure we - catch the leaf functions first. */ - for (i=expr_count-1; i>=1; i--) + /* Walk through all the functions. */ + + for (i=1; iexpr_type == EXPR_VARIABLE) continue; newvar = NULL; - for (j=i-1; j>=0; j--) + for (j=0; j