From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 83714 invoked by alias); 22 Jan 2019 09:39:58 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 83682 invoked by uid 89); 22 Jan 2019 09:39:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.2 spammy=powerpc64 X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 Jan 2019 09:39:55 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 131CCADE3; Tue, 22 Jan 2019 09:39:53 +0000 (UTC) Date: Tue, 22 Jan 2019 09:39:00 -0000 From: Richard Biener To: Jakub Jelinek cc: Jan Hubicka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Fix transfer_intrinsic_3.f90 miscompilation on ppc*/s390* (PR tree-optimization/88044) In-Reply-To: <20190118225224.GX30353@tucnak> Message-ID: References: <20190118225224.GX30353@tucnak> User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SW-Source: 2019-01/txt/msg01270.txt.bz2 On Fri, 18 Jan 2019, Jakub Jelinek wrote: > Hi! > > As mentioned in the PR, on the transfer_intrinsic_3.f90 testcase at -O3 > on a few targets we have in number_of_iterations_cond: > code LE_EXPR > iv0->base 0 > iv0->step 0 > iv1->base -1 > iv1->step 1 > every_iteration false > > The loop starts with: > [local count: 8656061039]: > # n_63 = PHI <0(6), _28(23)> > _19 = n_63 + -1; > and ends with > _28 = n_63 + 1; > if (_28 == 4) > goto ; [12.36%] > else > goto ; [87.64%] > > [local count: 7582748748]: > goto ; [100.00%] > and besides the exit at the end has also: > [local count: 3548985018]: > if (_19 > 0) > goto ; [0.04%] > else > goto ; [99.96%] > > [local count: 1419591]: > _gfortran_stop_numeric (1, 0); > > [local count: 5106238449]: > if (_19 < 0) > goto ; [0.04%] > else > goto ; [99.96%] > > [local count: 5104195957]: > goto ; [100.00%] > > [local count: 2042498]: > _gfortran_stop_numeric (2, 0); > > in the middle, so two other loop exits. But, neither bb16, nor bb18 are > executed every iteration, if they were, then because _19 is -1 in the first > iteration would always stop 2 and not iterate further. > > We have: > > /* If the test is not executed every iteration, wrapping may make the test > to pass again. > TODO: the overflow case can be still used as unreliable estimate of upper > bound. But we have no API to pass it down to number of iterations code > and, at present, it will not use it anyway. */ > if (!every_iteration > && (!iv0->no_overflow || !iv1->no_overflow > || code == NE_EXPR || code == EQ_EXPR)) > return false; > > at the start, but that doesn't trigger here, because code is not equality > comparison and no_overflow is set on both IVs. If there would be an > overflow, then maybe it would be right to derive number of iterations from > that. But the condition that returns true is that iv0->base code iv1->base > is false, if that isn't done in every iteration, it means nothing for the > number of iteration analysis. > > Fixed thusly, bootstrapped/regtested on x86_64-linux, i686-linux, > powerpc64{,le}-linux, ok for trunk? OK. Richard. > 2019-01-18 Jakub Jelinek > > PR tree-optimization/88044 > * tree-ssa-loop-niter.c (number_of_iterations_cond): If condition > is false in the first iteration, but !every_iteration, return false > instead of true with niter->niter zero. > > --- gcc/tree-ssa-loop-niter.c.jj 2019-01-10 11:43:02.254577008 +0100 > +++ gcc/tree-ssa-loop-niter.c 2019-01-18 19:51:00.245504728 +0100 > @@ -1824,6 +1824,8 @@ number_of_iterations_cond (struct loop * > tree tem = fold_binary (code, boolean_type_node, iv0->base, iv1->base); > if (tem && integer_zerop (tem)) > { > + if (!every_iteration) > + return false; > niter->niter = build_int_cst (unsigned_type_for (type), 0); > niter->max = 0; > return true; > > Jakub > > -- Richard Biener SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)