From patchwork Wed Jun 29 21:17:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Pop X-Patchwork-Id: 102669 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 5B8FDB6F62 for ; Thu, 30 Jun 2011 07:17:37 +1000 (EST) Received: (qmail 17107 invoked by alias); 29 Jun 2011 21:17:35 -0000 Received: (qmail 17097 invoked by uid 22791); 29 Jun 2011 21:17:34 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-gy0-f175.google.com (HELO mail-gy0-f175.google.com) (209.85.160.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 29 Jun 2011 21:17:16 +0000 Received: by gyd12 with SMTP id 12so743614gyd.20 for ; Wed, 29 Jun 2011 14:17:16 -0700 (PDT) Received: by 10.236.170.167 with SMTP id p27mr1575655yhl.222.1309382235746; Wed, 29 Jun 2011 14:17:15 -0700 (PDT) Received: from napoca ([163.181.251.115]) by mx.google.com with ESMTPS id h70sm1139971yhk.1.2011.06.29.14.17.13 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 29 Jun 2011 14:17:15 -0700 (PDT) Received: by napoca (sSMTP sendmail emulation); Wed, 29 Jun 2011 16:17:12 -0500 From: Sebastian Pop To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, Sebastian Pop Subject: [PATCH] Sign extend before converting constants to GMP values. Date: Wed, 29 Jun 2011 16:17:10 -0500 Message-Id: <1309382231-19263-1-git-send-email-sebpop@gmail.com> X-IsSubscribed: yes 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 Hi, This patch fixes PR47653 by sign extending the double int constants before converting them to a GMP value. There still are some places where we should not sign extend the values converted: upper bounds of unsigned types should for example not be sign extended. The patch passed make -k check RUNTESTFLAGS=graphite.exp on c,c++,fortran. Regstrap with all languages in progress on amd64-linux. Ok for trunk? Thanks, Sebastian 2011-06-29 Sebastian Pop PR tree-optimization/47653 * graphite-ppl.h (tree_int_to_gmp): Sign extend before converting constants to GMP values. Add a sext parameter. (ppl_set_inhomogeneous_tree): Add sext parameter. (ppl_set_coef_tree): Removed. * graphite-sese-to-poly.c (scan_tree_for_params_right_scev): Adjust call to tree_int_to_gmp. (scan_tree_for_params_int): Use tree_int_to_gmp. (scan_tree_for_params): Adjust call to tree_int_to_gmp. (build_loop_iteration_domains): Adjust call to ppl_set_inhomogeneous_tree. (add_param_constraints): Same. (pdr_add_data_dimensions): Same. * gcc.dg/graphite/run-id-pr47653.c: New. --- gcc/ChangeLog | 16 ++++++++++++ gcc/graphite-ppl.h | 30 +++++++++-------------- gcc/graphite-sese-to-poly.c | 27 ++++++++++----------- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.dg/graphite/run-id-pr47653.c | 17 +++++++++++++ 5 files changed, 63 insertions(+), 32 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/graphite/run-id-pr47653.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e37d823..bed0070 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,19 @@ +2011-06-29 Sebastian Pop + + PR tree-optimization/47653 + * graphite-ppl.h (tree_int_to_gmp): Sign extend before converting + constants to GMP values. Add a sext parameter. + (ppl_set_inhomogeneous_tree): Add sext parameter. + (ppl_set_coef_tree): Removed. + * graphite-sese-to-poly.c (scan_tree_for_params_right_scev): Adjust + call to tree_int_to_gmp. + (scan_tree_for_params_int): Use tree_int_to_gmp. + (scan_tree_for_params): Adjust call to tree_int_to_gmp. + (build_loop_iteration_domains): Adjust call to + ppl_set_inhomogeneous_tree. + (add_param_constraints): Same. + (pdr_add_data_dimensions): Same. + 2011-06-29 Eric Botcazou PR tree-optimization/49539 diff --git a/gcc/graphite-ppl.h b/gcc/graphite-ppl.h index 695d01f..4ae9f63 100644 --- a/gcc/graphite-ppl.h +++ b/gcc/graphite-ppl.h @@ -50,13 +50,18 @@ void debug_gmp_value (mpz_t); bool ppl_powerset_is_empty (ppl_Pointset_Powerset_C_Polyhedron_t); -/* Assigns to RES the value of the INTEGER_CST T. */ +/* Assigns to RES the value of the INTEGER_CST T. When SEXT is true, + sign extend the value of T to not get "-1 = 2^n - 1". */ static inline void -tree_int_to_gmp (tree t, mpz_t res) +tree_int_to_gmp (tree t, mpz_t res, bool sext) { + tree type = TREE_TYPE (t); double_int di = tree_to_double_int (t); - mpz_set_double_int (res, di, TYPE_UNSIGNED (TREE_TYPE (t))); + + if (sext) + di = double_int_sext (di, TYPE_PRECISION (type)); + mpz_set_double_int (res, di, false); } /* Converts a GMP constant VAL to a tree and returns it. */ @@ -88,14 +93,15 @@ ppl_set_inhomogeneous (ppl_Linear_Expression_t e, int x) mpz_clear (v); } -/* Set the inhomogeneous term of E to the tree X. */ +/* Set the inhomogeneous term of E to the tree X. When SEXT is true, + sign extend the value of X. */ static inline void -ppl_set_inhomogeneous_tree (ppl_Linear_Expression_t e, tree x) +ppl_set_inhomogeneous_tree (ppl_Linear_Expression_t e, tree x, bool sext) { mpz_t v; mpz_init (v); - tree_int_to_gmp (x, v); + tree_int_to_gmp (x, v, sext); ppl_set_inhomogeneous_gmp (e, v); mpz_clear (v); } @@ -112,18 +118,6 @@ ppl_set_coef (ppl_Linear_Expression_t e, ppl_dimension_type i, int x) mpz_clear (v); } -/* Set E[I] to tree X. */ - -static inline void -ppl_set_coef_tree (ppl_Linear_Expression_t e, ppl_dimension_type i, tree x) -{ - mpz_t v; - mpz_init (v); - tree_int_to_gmp (x, v); - ppl_set_coef_gmp (e, i, v); - mpz_clear (v); -} - /* Sets RES to the max of V1 and V2. */ static inline void diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c index 7e23c9d..5f8188b 100644 --- a/gcc/graphite-sese-to-poly.c +++ b/gcc/graphite-sese-to-poly.c @@ -633,7 +633,7 @@ scan_tree_for_params_right_scev (sese s, tree e, int var, gcc_assert (TREE_CODE (e) == INTEGER_CST); mpz_init (val); - tree_int_to_gmp (e, val); + tree_int_to_gmp (e, val, true); add_value_to_dim (l, expr, val); mpz_clear (val); } @@ -647,14 +647,9 @@ scan_tree_for_params_int (tree cst, ppl_Linear_Expression_t expr, mpz_t k) { mpz_t val; ppl_Coefficient_t coef; - tree type = TREE_TYPE (cst); mpz_init (val); - - /* Necessary to not get "-1 = 2^n - 1". */ - mpz_set_double_int (val, double_int_sext (tree_to_double_int (cst), - TYPE_PRECISION (type)), false); - + tree_int_to_gmp (cst, val, true); mpz_mul (val, val, k); ppl_new_Coefficient (&coef); ppl_assign_Coefficient_from_mpz_t (coef, val); @@ -731,7 +726,7 @@ scan_tree_for_params (sese s, tree e, ppl_Linear_Expression_t c, mpz_t val; gcc_assert (host_integerp (TREE_OPERAND (e, 1), 0)); mpz_init (val); - tree_int_to_gmp (TREE_OPERAND (e, 1), val); + tree_int_to_gmp (TREE_OPERAND (e, 1), val, true); mpz_mul (val, val, k); scan_tree_for_params (s, TREE_OPERAND (e, 0), c, val); mpz_clear (val); @@ -746,7 +741,7 @@ scan_tree_for_params (sese s, tree e, ppl_Linear_Expression_t c, mpz_t val; gcc_assert (host_integerp (TREE_OPERAND (e, 0), 0)); mpz_init (val); - tree_int_to_gmp (TREE_OPERAND (e, 0), val); + tree_int_to_gmp (TREE_OPERAND (e, 0), val, true); mpz_mul (val, val, k); scan_tree_for_params (s, TREE_OPERAND (e, 1), c, val); mpz_clear (val); @@ -1072,7 +1067,9 @@ build_loop_iteration_domains (scop_p scop, struct loop *loop, /* loop_i <= cst_nb_iters */ ppl_set_coef (ub_expr, nb, -1); - ppl_set_inhomogeneous_tree (ub_expr, nb_iters); + /* The number of iterations should not be sign extended as it is + a positive number. */ + ppl_set_inhomogeneous_tree (ub_expr, nb_iters, false); ppl_new_Constraint (&ub, ub_expr, PPL_CONSTRAINT_TYPE_GREATER_OR_EQUAL); ppl_Polyhedron_add_constraint (ph, ub); ppl_delete_Linear_Expression (ub_expr); @@ -1448,7 +1445,7 @@ add_param_constraints (scop_p scop, ppl_Polyhedron_t context, graphite_dim_t p) { ppl_new_Linear_Expression_with_dimension (&le, scop_nb_params (scop)); ppl_set_coef (le, p, -1); - ppl_set_inhomogeneous_tree (le, lb); + ppl_set_inhomogeneous_tree (le, lb, true); ppl_new_Constraint (&cstr, le, PPL_CONSTRAINT_TYPE_LESS_OR_EQUAL); ppl_Polyhedron_add_constraint (context, cstr); ppl_delete_Linear_Expression (le); @@ -1459,7 +1456,9 @@ add_param_constraints (scop_p scop, ppl_Polyhedron_t context, graphite_dim_t p) { ppl_new_Linear_Expression_with_dimension (&le, scop_nb_params (scop)); ppl_set_coef (le, p, -1); - ppl_set_inhomogeneous_tree (le, ub); + /* Do not sign extend the upper bound of an unsigned type, as + that would become -1. */ + ppl_set_inhomogeneous_tree (le, ub, !TYPE_UNSIGNED (type)); ppl_new_Constraint (&cstr, le, PPL_CONSTRAINT_TYPE_GREATER_OR_EQUAL); ppl_Polyhedron_add_constraint (context, cstr); ppl_delete_Linear_Expression (le); @@ -1641,7 +1640,7 @@ pdr_add_data_dimensions (ppl_Polyhedron_t accesses, data_reference_p dr, ppl_set_coef (expr, subscript, 1); minus_low = fold_build1 (NEGATE_EXPR, TREE_TYPE (low), low); - ppl_set_inhomogeneous_tree (expr, minus_low); + ppl_set_inhomogeneous_tree (expr, minus_low, true); ppl_new_Constraint (&cstr, expr, PPL_CONSTRAINT_TYPE_GREATER_OR_EQUAL); ppl_Polyhedron_add_constraint (accesses, cstr); @@ -1661,7 +1660,7 @@ pdr_add_data_dimensions (ppl_Polyhedron_t accesses, data_reference_p dr, ppl_new_Linear_Expression_with_dimension (&expr, accessp_nb_dims); ppl_set_coef (expr, subscript, -1); - ppl_set_inhomogeneous_tree (expr, high); + ppl_set_inhomogeneous_tree (expr, high, true); ppl_new_Constraint (&cstr, expr, PPL_CONSTRAINT_TYPE_GREATER_OR_EQUAL); ppl_Polyhedron_add_constraint (accesses, cstr); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d30d8b0..6d48df4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-06-29 Sebastian Pop + + PR tree-optimization/47653 + * gcc.dg/graphite/run-id-pr47653.c: New. + 2011-06-29 Jason Merrill PR c++/45923 diff --git a/gcc/testsuite/gcc.dg/graphite/run-id-pr47653.c b/gcc/testsuite/gcc.dg/graphite/run-id-pr47653.c new file mode 100644 index 0000000..b62b891 --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/run-id-pr47653.c @@ -0,0 +1,17 @@ +/* { dg-options "-O -fstack-check=generic -ftree-pre -fgraphite-identity" } */ + +int main () +{ + int i, j; + int x[8][8]; + for (i = 0; i < 8; i++) + for (j = i; j < 8; j++) + x[i][j] = 4; + + for (i = 0; i < 8; i++) + for (j = i; j < 8; j++) + if (x[i][j] != 4) + __builtin_abort (); + + return 0; +}