From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 73444 invoked by alias); 4 Dec 2017 14:01:46 -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 73427 invoked by uid 89); 4 Dec 2017 14:01:45 -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=k1, sk:transla 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, 04 Dec 2017 14:01:35 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 453D3ADD5 for ; Mon, 4 Dec 2017 14:01:33 +0000 (UTC) Date: Mon, 04 Dec 2017 14:01:00 -0000 From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR83255 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SW-Source: 2017-12/txt/msg00141.txt.bz2 Been sitting in my tree (fixes SPEC 2k6 miscompares). Bootstrapped and tested on x86-64-unknown-linux-gnu, applied. Richard. 2017-12-04 Richard Biener PR tree-optimization/83255 * graphite-isl-ast-to-gimple.c (translate_isl_ast_node_for): Re-add zero-iteration check. * gcc.dg/graphite/pr83255.c: New testcase. Index: gcc/graphite-isl-ast-to-gimple.c =================================================================== --- gcc/graphite-isl-ast-to-gimple.c (revision 255375) +++ gcc/graphite-isl-ast-to-gimple.c (working copy) @@ -720,6 +720,32 @@ translate_isl_ast_node_for (loop_p conte ub = integer_zero_node; edge last_e = single_succ_edge (split_edge (next_e)); + + /* Compensate for the fact that we emit a do { } while loop from + a for ISL AST. + ??? We often miss constraints on niter because the SESE region + doesn't cover loop header copies. Ideally we'd add constraints + for all relevant dominating conditions. */ + if (TREE_CODE (lb) == INTEGER_CST && TREE_CODE (ub) == INTEGER_CST + && tree_int_cst_compare (lb, ub) <= 0) + ; + else + { + tree one = build_one_cst (POINTER_TYPE_P (type) ? sizetype : type); + /* Adding +1 and using LT_EXPR helps with loop latches that have a + loop iteration count of "PARAMETER - 1". For PARAMETER == 0 this + becomes 2^k-1 due to integer overflow, and the condition lb <= ub + is true, even if we do not want this. However lb < ub + 1 is false, + as expected. */ + tree ub_one = fold_build2 (POINTER_TYPE_P (type) + ? POINTER_PLUS_EXPR : PLUS_EXPR, + type, ub, one); + create_empty_if_region_on_edge (next_e, + fold_build2 (LT_EXPR, boolean_type_node, + lb, ub_one)); + next_e = get_true_edge_from_guard_bb (next_e->dest); + } + translate_isl_ast_for_loop (context_loop, node, next_e, type, lb, ub, ip); return last_e; Index: gcc/testsuite/gcc.dg/graphite/pr83255.c =================================================================== --- gcc/testsuite/gcc.dg/graphite/pr83255.c (nonexistent) +++ gcc/testsuite/gcc.dg/graphite/pr83255.c (working copy) @@ -0,0 +1,28 @@ +/* { dg-do run } */ +/* { dg-options "-O -floop-nest-optimize -fdump-tree-graphite-details" } */ + +int rx, in; + +int +main (void) +{ + const int tj = 3; + int as[tj]; + static int l4; + + while (l4 < 1) + { + for (rx = 0; rx < tj; ++rx) + { + for (in = 0; in < tj; ++in) + as[in] = 1; + as[rx] = 0; + } + ++l4; + } + + if (as[tj - 1] != 0) + __builtin_abort (); +} + +/* { dg-final { scan-tree-dump "loop nest optimized" "graphite" } } */