From patchwork Sun Jul 4 16:09:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 1500449 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+incoming=patchwork.ozlabs.org@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=fqfouMQU; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.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 4GHv206gQcz9sj5 for ; Mon, 5 Jul 2021 02:11:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1BBFE384B808 for ; Sun, 4 Jul 2021 16:10:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1BBFE384B808 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1625415058; bh=/d34OIbG3/snJy2wbm2UBps2ypSgzcoi6l6DjCS8Tic=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=fqfouMQUvctXx4VWFj0N0qN4fYS9MS50R8OwcOwguIMz7tOiEzayVP9aM1byHELWo HxUETWrfsuzXzvmMeNGQ0scEa62M7iPnVMBr3A3GJKXL6/b59pdWb4U+CCfnBFv9an jakZlEJU9iIDqdlFltrXXjuWN7H2ad9tjT0AZtXQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cc-smtpout2.netcologne.de (cc-smtpout2.netcologne.de [89.1.8.212]) by sourceware.org (Postfix) with ESMTPS id 22C8E385703F; Sun, 4 Jul 2021 16:09:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 22C8E385703F Received: from cc-smtpin3.netcologne.de (cc-smtpin3.netcologne.de [89.1.8.203]) by cc-smtpout2.netcologne.de (Postfix) with ESMTP id 8ED4B1264E; Sun, 4 Jul 2021 18:09:52 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cc-smtpin3.netcologne.de (Postfix) with ESMTP id 807D711E13; Sun, 4 Jul 2021 18:09:52 +0200 (CEST) Received: from [2001:4dd7:30c8:0:7285:c2ff:fe6c:992d] (helo=cc-smtpin3.netcologne.de) by localhost with ESMTP (eXpurgate 4.27.0) (envelope-from ) id 60e1dd50-4412-7f0000012729-7f000001e3e4-1 for ; Sun, 04 Jul 2021 18:09:52 +0200 Received: from [IPv6:2001:4dd7:30c8:0:7285:c2ff:fe6c:992d] (2001-4dd7-30c8-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de [IPv6:2001:4dd7:30c8:0:7285:c2ff:fe6c:992d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cc-smtpin3.netcologne.de (Postfix) with ESMTPSA; Sun, 4 Jul 2021 18:09:51 +0200 (CEST) To: "fortran@gcc.gnu.org" , gcc-patches Subject: [patch, fortran] Fix PR 100227, write with implied DO loop Message-ID: <849f630f-e6fe-c3c3-e46a-3a64a86db4e3@netcologne.de> Date: Sun, 4 Jul 2021 18:09:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Thomas Koenig via Gcc-patches From: Thomas Koenig Reply-To: Thomas Koenig Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hello world, after a bit of an absence, I am now back, at least for some regression fixing (and for reviewing patches, if that is called for). So, here's a regression fix to start with. OK for trunk and affected branches (down to 9)? Best regards Thomas Do not replace variable op variable in I/O implied DO loop replacement. This PR came about because index expressions of the form k+k in implied DO loops in I/O statements were considered for replacement by array slices. Fixed by only doing the transformation if the expression is of the type expr OP contastant. gcc/fortran/ChangeLog: PR fortran/100227 * frontend-passes.c (traverse_io_block): Adjust test for when a variable is eligible for the transformation to array slice. gcc/testsuite/ChangeLog: PR fortran/100227 * gfortran.dg/implied_do_io_7.f90: New test. diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index 72a4e0410b1..996dcc2e547 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -1299,8 +1299,8 @@ traverse_io_block (gfc_code *code, bool *has_reached, gfc_code *prev) std::swap (start->value.op.op1, start->value.op.op2); gcc_fallthrough (); case INTRINSIC_MINUS: - if ((start->value.op.op1->expr_type!= EXPR_VARIABLE - && start->value.op.op2->expr_type != EXPR_CONSTANT) + if (start->value.op.op1->expr_type!= EXPR_VARIABLE + || start->value.op.op2->expr_type != EXPR_CONSTANT || start->value.op.op1->ref) return false; if (!stack_top || !stack_top->iter diff --git a/gcc/testsuite/gfortran.dg/implied_do_io_7.f90 b/gcc/testsuite/gfortran.dg/implied_do_io_7.f90 new file mode 100644 index 00000000000..63927aafea9 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/implied_do_io_7.f90 @@ -0,0 +1,16 @@ +! { dg-do run } +! PR 100227 - this was falsely optimized, leading to nonsense results. +! Original test case by "Mathieu". + +program p + implicit none + integer, parameter :: nbmode = 3 + integer :: k + real :: mass(nbmode*2) + character (len=80) :: line + do k = 1, nbmode*2 + mass(k) = k + end do + write (unit=line,fmt='(*(F6.2))') (mass(k+k), k=1,nbmode) + if (line /= ' 2.00 4.00 6.00') stop 1 +end program