From patchwork Tue Dec 9 13:50:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 419072 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6401714009B for ; Wed, 10 Dec 2014 00:57:35 +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=K14SB6ZzlcWbGfUQe2yqfC3o/4NDrOgNPauoeRnZ/TUUlD8cdU6EW TQKMda366wUQpppxnyc/UgfEnvr1qZqb2OZJsuGPykad5X0LRsUrwq3Yo71BVx+9 hodsXggdqqb1Z1N7SoAan+4WJZEM99VMvC8i5+9BmNbLlAeMmudFq8= 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=XXEfZSD4bgAantjooDrNc1KpugE=; b=aUlM9LRnADpNY0/I4AZZ 7VmaJtNoQP2BkvFMj6NMbGRDw40UMDWCU2VYJXpTU74EmwCxSdQWIXnd5AWn8+n3 BdUDQbVt2Eyl8Uv58YMpyDnc//TjV0h7M+dCByKreGNHuWGAxR6DHYMjmTOOhoMi PNjwdCh3NXtBJHJ+GTuQoFc= Received: (qmail 958 invoked by alias); 9 Dec 2014 13:57:28 -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 946 invoked by uid 89); 9 Dec 2014 13:57:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx2.suse.de Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Tue, 09 Dec 2014 13:57:26 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 61055AC6A for ; Tue, 9 Dec 2014 13:57:23 +0000 (UTC) Date: Tue, 9 Dec 2014 14:50:54 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR42108 Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 The following finally fixes PR42108 (well, hopefully...) by using range-information on SSA names to allow the integer divisions introduced by Fortran array lowering being hoisted out of loops, thus detecting them as not trapping. I chose to enhance tree_single_nonzero_warnv_p for this and adjusted operation_could_trap_helper_p to use this helper. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. Richard. 2014-12-09 Richard Biener PR tree-optimization/42108 * fold-const.c (tree_single_nonzero_warnv_p): Use range information associated with SSA names. * tree-eh.c (operation_could_trap_helper_p): Use tree_single_nonzero_warnv_p to check for trapping non-fp operation. * tree-vrp.c (remove_range_assertions): Remove bogus assert. * gfortran.dg/pr42108.f90: Adjust testcase. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 218479) +++ gcc/fold-const.c (working copy) @@ -83,6 +83,8 @@ along with GCC; see the file COPYING3. #include "cgraph.h" #include "generic-match.h" #include "optabs.h" +#include "stringpool.h" +#include "tree-ssanames.h" /* Nonzero if we are folding constants inside an initializer; zero otherwise. */ @@ -15362,6 +15381,26 @@ tree_single_nonzero_warnv_p (tree t, boo } break; + case SSA_NAME: + if (INTEGRAL_TYPE_P (TREE_TYPE (t))) + { + wide_int minv, maxv; + enum value_range_type rtype = get_range_info (t, &minv, &maxv); + if (rtype == VR_RANGE) + { + if (wi::lt_p (maxv, 0, TYPE_SIGN (TREE_TYPE (t))) + || wi::gt_p (minv, 0, TYPE_SIGN (TREE_TYPE (t)))) + return true; + } + else if (rtype == VR_ANTI_RANGE) + { + if (wi::le_p (minv, 0, TYPE_SIGN (TREE_TYPE (t))) + && wi::ge_p (maxv, 0, TYPE_SIGN (TREE_TYPE (t)))) + return true; + } + } + break; + default: break; } Index: gcc/tree-eh.c =================================================================== --- gcc/tree-eh.c (revision 218479) +++ gcc/tree-eh.c (working copy) @@ -2440,13 +2440,16 @@ operation_could_trap_helper_p (enum tree case ROUND_MOD_EXPR: case TRUNC_MOD_EXPR: case RDIV_EXPR: - if (honor_snans || honor_trapv) - return true; - if (fp_operation) - return flag_trapping_math; - if (!TREE_CONSTANT (divisor) || integer_zerop (divisor)) - return true; - return false; + { + if (honor_snans || honor_trapv) + return true; + if (fp_operation) + return flag_trapping_math; + bool sop; + if (!tree_single_nonzero_warnv_p (divisor, &sop)) + return true; + return false; + } case LT_EXPR: case LE_EXPR: Index: gcc/testsuite/gfortran.dg/pr42108.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr42108.f90 (revision 218479) +++ gcc/testsuite/gfortran.dg/pr42108.f90 (working copy) @@ -1,5 +1,5 @@ ! { dg-do compile } -! { dg-options "-O2 -fdump-tree-fre1" } +! { dg-options "-O2 -fdump-tree-fre1 -fdump-tree-lim1-details" } subroutine eval(foo1,foo2,foo3,foo4,x,n,nnd) implicit real*8 (a-h,o-z) @@ -21,7 +21,10 @@ subroutine eval(foo1,foo2,foo3,foo4,x,n end do end subroutine eval -! There should be only one load from n left +! There should be only one load from n left and the division should +! be hoisted out of the loop ! { dg-final { scan-tree-dump-times "\\*n_" 1 "fre1" } } +! { dg-final { scan-tree-dump-times "Moving statement" 5 "lim1" } } ! { dg-final { cleanup-tree-dump "fre1" } } +! { dg-final { cleanup-tree-dump "lim1" } } Index: gcc/tree-vrp.c =================================================================== --- gcc/tree-vrp.c (revision 218479) +++ gcc/tree-vrp.c (working copy) @@ -6866,12 +6866,9 @@ remove_range_assertions (void) tree lhs = gimple_assign_lhs (stmt); tree rhs = gimple_assign_rhs1 (stmt); tree var; - tree cond = fold (ASSERT_EXPR_COND (rhs)); use_operand_p use_p; imm_use_iterator iter; - gcc_assert (cond != boolean_false_node); - var = ASSERT_EXPR_VAR (rhs); gcc_assert (TREE_CODE (var) == SSA_NAME);