From patchwork Mon Dec 11 15:25:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 847097 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-468913-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.b="NcdQaEbI"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ywRbq6htVz9s5L for ; Tue, 12 Dec 2017 02:25:27 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=C/krNewsRcNrOa5y48oLf5d/sJ7Zrv2BNqOLb5MYkI8VfVaRJbEV7 cPbUnb3VBy4QHwGkwLkyhBvsjSXX/v9H7ukMug8aAS+EN6xzdHudEswIDaajav0z iqbGpXcdoRh0mCkpa8crk5kxR0t93dS7eZQ92MM0pW0h+h6qnSnk24= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=emr/vTkQoEfUuA43JRDHg2c44o4=; b=NcdQaEbIshHve/kzSvEm Voi+UBSMEHfUgkKk8ySnFA/ZizMbkRXKJpMSDaE1HwQ+38lNCjTqRXB2FYj8Vj80 6VaWJQF+z5FFeEhv1spRa0d6GcIPT8KVAR1cQLPzebWb5c91szMNew4igIBlAB2S ooD5hjHC2pQEbCI/GfZgoAc= Received: (qmail 70299 invoked by alias); 11 Dec 2017 15:25:19 -0000 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 Received: (qmail 70267 invoked by uid 89); 11 Dec 2017 15:25:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=participating, sum X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 11 Dec 2017 15:25:13 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id F05B6ACD4 for ; Mon, 11 Dec 2017 15:25:10 +0000 (UTC) Date: Mon, 11 Dec 2017 16:25:10 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR81889 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Unrolling often has only rudimentary info for the upper bound of a loop even though VRP would compute reasonable bounds for the variables participating in the loop exit test. This causes excessive peeling and thus warnings from array bound and uninit warning code. The following mitigates missing range-info somewhat because range-info from early often persists on IV computation statements. We already use "ranges" on them but only their natural range. The following makes us use range info properly. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2017-12-11 Richard Biener PR tree-optimization/81889 * tree-ssa-loop-niter.c (infer_loop_bounds_from_signedness): Use range info from the non-wrapping IV instead of just the range of the type. * gfortran.dg/pr81889.f90: New testcase. Index: gcc/tree-ssa-loop-niter.c =================================================================== --- gcc/tree-ssa-loop-niter.c (revision 255539) +++ gcc/tree-ssa-loop-niter.c (working copy) @@ -3510,6 +3510,12 @@ infer_loop_bounds_from_signedness (struc low = lower_bound_in_type (type, type); high = upper_bound_in_type (type, type); + wide_int minv, maxv; + if (get_range_info (def, &minv, &maxv) == VR_RANGE) + { + low = wide_int_to_tree (type, minv); + high = wide_int_to_tree (type, maxv); + } record_nonwrapping_iv (loop, base, step, stmt, low, high, false, true); } Index: gcc/testsuite/gfortran.dg/pr81889.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr81889.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr81889.f90 (working copy) @@ -0,0 +1,29 @@ +! { dg-do compile } +! { dg-options "-O3 -Wall" } + +module m + + type t + integer, dimension(:), pointer :: list + end type + +contains + + subroutine s(n, p, Y) + integer, intent(in) :: n + type(t) :: p + real, dimension(:) :: Y + + real, dimension(1:16) :: xx + + if (n > 3) then + xx(1:n) = 0. + print *, xx(1:n) + else + xx(1:n) = Y(p%list(1:n)) ! { dg-bogus "uninitialized" } + print *, sum(xx(1:n)) + end if + + end subroutine + +end module