From patchwork Wed Dec 15 15:46:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 75653 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]) by ozlabs.org (Postfix) with SMTP id 505BCB6EF2 for ; Thu, 16 Dec 2010 02:46:18 +1100 (EST) Received: (qmail 19944 invoked by alias); 15 Dec 2010 15:46:16 -0000 Received: (qmail 19932 invoked by uid 22791); 15 Dec 2010 15:46:13 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL, BAYES_00, FSL_RU_URL, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp.ispras.ru (HELO smtp.ispras.ru) (83.149.198.201) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 15 Dec 2010 15:46:07 +0000 Received: from ispserv.ispras.ru (ispserv.ispras.ru [83.149.198.72]) by smtp.ispras.ru (Postfix) with ESMTP id 6E77B5D40BF; Wed, 15 Dec 2010 18:40:02 +0300 (MSK) Received: from monoid.intra.ispras.ru (unknown [83.149.198.236]) by ispserv.ispras.ru (Postfix) with ESMTP id DA9F23FC48; Wed, 15 Dec 2010 18:46:04 +0300 (MSK) Date: Wed, 15 Dec 2010 18:46:04 +0300 (MSK) From: Alexander Monakov To: Richard Guenther cc: Sebastian Pop , gcc-patches@gcc.gnu.org Subject: Re: [PR46761] graphite: fix testing of boundary wrapping In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 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 On Mon, 13 Dec 2010, Richard Guenther wrote: > 2010/12/13 Sebastian Pop : > > On Mon, Dec 13, 2010 at 07:40, Alexander Monakov wrote: > >> Hi, > >> > >> As indicated by the testcase, sometimes Graphite would generate wrong region > >> guards if UB_ONE overflows, but does not become zero (i.e. it is signed). > >> The patch changes the corresponding test to use TREE_OVERFLOW flag. > >> > >> Bootstrapped and regtested on x86_64-linux, OK for trunk? > >> > >> 2010-12-13  Alexander Monakov   > >> > >>        PR middle-end/46761 > >>        * graphite-clast-to-gimple.c (graphite_create_new_loop_guard): Use > >>        TREE_OVERFLOW_P to test overflow. > >> > >> testsuite: > >>        * gcc.dg/graphite/pr46761.c: New. > >> > > > > Ok.  Thanks for fixing this, > > Hmm, I don't like new uses of TREE_OVERFLOW checking. And for > unsigned types it won't be set anyway. Thanks. The following patch changes guard generation so that using unadjusted UB is preferred (if it's an integer constant or an SSA_NAME). If it is neither, it uses the previous behaviour of bumping UB by one and changing the test. Bootstrapped and tested with make -k check RUNTESTFLAGS="graphite.exp", OK for trunk? 2010-12-15 Alexander Monakov        PR middle-end/46761        * graphite-clast-to-gimple.c (graphite_create_new_loop_guard): Prefer        to use unadjusted UB. diff --git a/gcc/graphite-clast-to-gimple.c b/gcc/graphite-clast-to-gimple.c index 4894b52..4725608 100644 --- a/gcc/graphite-clast-to-gimple.c +++ b/gcc/graphite-clast-to-gimple.c @@ -975,20 +975,24 @@ graphite_create_new_loop_guard (sese region, edge entry_edge, newivs_index, params_index); tree ub = clast_to_gcc_expression (type, stmt->UB, region, newivs, newivs_index, params_index); - tree one = POINTER_TYPE_P (type) ? size_one_node - : fold_convert (type, integer_one_node); - /* 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^{32|64}, 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); - - /* When ub + 1 wraps around, use lb <= ub. */ - if (integer_zerop (ub_one)) + /* When ub is simply a constant or a parameter, use lb <= ub. */ + if (TREE_CODE (ub) == INTEGER_CST || TREE_CODE (ub) == SSA_NAME) cond_expr = fold_build2 (LE_EXPR, boolean_type_node, lb, ub); else - cond_expr = fold_build2 (LT_EXPR, boolean_type_node, lb, ub_one); + { + tree one = (POINTER_TYPE_P (type) + ? size_one_node + : fold_convert (type, integer_one_node)); + /* 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 unsigned 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); + + cond_expr = fold_build2 (LT_EXPR, boolean_type_node, lb, ub_one); + } exit_edge = create_empty_if_region_on_edge (entry_edge, cond_expr);