From patchwork Thu May 12 15:46:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Richard Thomas X-Patchwork-Id: 95335 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 A91EBB6F5D for ; Fri, 13 May 2011 01:47:24 +1000 (EST) Received: (qmail 4733 invoked by alias); 12 May 2011 15:47:21 -0000 Received: (qmail 4713 invoked by uid 22791); 12 May 2011 15:47:19 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RFC_ABUSE_POST X-Spam-Check-By: sourceware.org Received: from mail-bw0-f47.google.com (HELO mail-bw0-f47.google.com) (209.85.214.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 12 May 2011 15:46:42 +0000 Received: by bwz5 with SMTP id 5so1717881bwz.20 for ; Thu, 12 May 2011 08:46:40 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.76.83 with SMTP id b19mr355940bkk.126.1305215200296; Thu, 12 May 2011 08:46:40 -0700 (PDT) Received: by 10.204.55.14 with HTTP; Thu, 12 May 2011 08:46:40 -0700 (PDT) Date: Thu, 12 May 2011 17:46:40 +0200 Message-ID: Subject: [Patch, fortran] PR48955 [4.6/4.7 Regression] Wrong result for array assignment due to missing temporary From: Paul Richard Thomas To: fortran@gcc.gnu.org, gcc-patches 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 This patch fixes the problem in two steps: (i) It reverts r162289; and (ii) It adds the correct initialization for loop.reverse[] in gfc_trans_assignment_1.  This was implemented incorrectly in the fix for PR24524 (in spite of the correct comment in dependency.c!) and removed at sometime, I do not know why. Bootstraps and regtests on x86_64/FC9. OK for trunk and 4.6? Paul 2011-05-12 Paul Thomas PR fortran/48955 * dependency.c (gfc_dep_resolver): Revert r162829 which changed the condition for setting this_dep to GFC_DEP_OVERLAP. * trans-expr.c (gfc_trans_assignment_1): Enable loop reversal. 2011-05-12 Paul Thomas PR fortran/48955 * gfortran.dg/dependency_40.f90 : New test. Index: gcc/fortran/trans-expr.c =================================================================== *** gcc/fortran/trans-expr.c (revision 173649) --- gcc/fortran/trans-expr.c (working copy) *************** gfc_trans_assignment_1 (gfc_expr * expr1 *** 6052,6057 **** --- 6052,6061 ---- /* Initialize the scalarizer. */ gfc_init_loopinfo (&loop); + /* Enable loop reversal. */ + for (n = 0; n < GFC_MAX_DIMENSIONS; n++) + loop.reverse[n] = GFC_CAN_REVERSE; + /* Walk the rhs. */ rss = gfc_walk_expr (expr2); if (rss == gfc_ss_terminator) Index: gcc/fortran/dependency.c =================================================================== *** gcc/fortran/dependency.c (revision 173649) --- gcc/fortran/dependency.c (working copy) *************** gfc_dep_resolver (gfc_ref *lref, gfc_ref *** 1832,1839 **** /* If no intention of reversing or reversing is explicitly inhibited, convert backward dependence to overlap. */ ! if (this_dep == GFC_DEP_BACKWARD ! && (reverse == NULL || reverse[n] == GFC_CANNOT_REVERSE)) this_dep = GFC_DEP_OVERLAP; } --- 1832,1839 ---- /* If no intention of reversing or reversing is explicitly inhibited, convert backward dependence to overlap. */ ! if ((reverse == NULL && this_dep == GFC_DEP_BACKWARD) ! || (reverse != NULL && reverse[n] == GFC_CANNOT_REVERSE)) this_dep = GFC_DEP_OVERLAP; } Index: gcc/testsuite/gfortran.dg/dependency_40.f90 =================================================================== *** gcc/testsuite/gfortran.dg/dependency_40.f90 (revision 0) --- gcc/testsuite/gfortran.dg/dependency_40.f90 (revision 0) *************** *** 0 **** --- 1,17 ---- + ! { dg-do run } + !Test the fix for PR48955, in which a temporary was not being generated for + ! the dependent assignment to 'V1'. + ! + ! Reported by Tobias Burnus + ! + program ala + implicit none + integer, parameter :: n = 8 + real, dimension(n) :: v0, v1, v2 + v0 = [-10.0, -10., -10., -10., 10., 10., 10., 10.] + v1 = v0 + v2 = v0 + v1(2:n-1) = 0.5*(v1(1:n-2) + v1(3:n) + 2.0*v1(2:n-1)) ! Needs temporary + v2(2:n-1) = 0.5*(v0(1:n-2) + v0(3:n) + 2.0*v0(2:n-1)) + if (any (v1 .ne. v2)) call abort + end program ala