From patchwork Sun Aug 28 22:43:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 663466 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 3sMqZX32Fcz9sBM for ; Mon, 29 Aug 2016 08:43:45 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=oo83yg14; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=q/DinBA1Mfrxr6aLJ 5E4MVEQqenplbWcCKA+fmb/ePxGGt1mEkDudUSBMBUwsHEwYANFAnx8w9pWbc+cV o1wyAlxPNi39IwSuLhSMthXfVR7nGvnHEhWlF6tzE27u4ugdlW5DPjW2ti8mCCR5 VgVAdz259O/3s9U8S0p0j/j2og= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=43aJUFupZjHUiqWRzAyvsO0 phaw=; b=oo83yg14uZcIBYPQPFKz3qXCLsSvc4Fu5AnfVnEqzGvOB9xj2VVNeTg o+Xrvx2R0SqbgyaqZFOzzY+D3EBTj/rawRBnmuh+qQhvO+cy4DNFI6/G3RxYagSI Lu6A0KdQ5nFfeL0u5S4aewb8X32dlBAHDg3DRSWXFSO7gbzA+oXY= Received: (qmail 114440 invoked by alias); 28 Aug 2016 22:43:34 -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 114420 invoked by uid 89); 28 Aug 2016 22:43:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.1 required=5.0 tests=AWL, BAYES_05, RCVD_IN_DNSWL_NONE, SPF_PASS, UNSUBSCRIBE_BODY autolearn=no version=3.3.2 spammy=Pop, strip, sebastian, Sebastian X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 28 Aug 2016 22:43:23 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-03.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1be8nO-00055l-UD from Tom_deVries@mentor.com ; Sun, 28 Aug 2016 15:43:19 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-03.mgc.mentorg.com (137.202.0.108) with Microsoft SMTP Server id 14.3.224.2; Sun, 28 Aug 2016 23:43:15 +0100 Subject: backport PR61929 fix to 5 branch To: Tobias Grosser , , , References: <1437085407-5254-1-git-send-email-s.pop@samsung.com> <55A8851F.8050708@grosser.es> CC: From: Tom de Vries Message-ID: <18cd03d9-14db-54e0-ea73-0e012fc44101@mentor.com> Date: Mon, 29 Aug 2016 00:43:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <55A8851F.8050708@grosser.es> [was: Re: [PATCH] [graphite] fix pr61929] On 17/07/15 06:31, Tobias Grosser wrote: > On 07/17/2015 12:23 AM, Sebastian Pop wrote: >> This fixes bootstrap of GCC with BOOT_CFLAGS="-g -O2 -fgraphite-identity >> -floop-nest-optimize -floop-block -floop-interchange -floop-strip-mine". >> It passes regstrap on amd64-linux. >> >> Ok to commit to trunk? > > Very nice. > > this but seems to include multiple fixes and refactorings at the same > time. I personally would prefer to at least separate the functional and > non-functional changes, such that the actual bug fixed becomes clear. > If splitting the patch is difficult, can you at least point out in the > commit message, which of your changes now actually fixed the bootstrap? > Hi, We've run into this PR on the gcc-5-branch (PR71506). I've applied the fix ( https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=225942 ) locally on top of gcc-5-branch (which applied cleanly), and bootstrapped and reg-tested it on x86_64, no issues found. OK to backport gcc-5-branch, or should I try to strip it down? Thanks, - Tom [ r225942 patch attached. ] [graphite] fix pr61929 This fixes bootstrap of GCC with BOOT_CFLAGS="-g -O2 -fgraphite-identity -floop-nest-optimize -floop-block -floop-interchange -floop-strip-mine". It passes regstrap on amd64-linux. A previous change (https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=213816), replaced isl_int with isl_val because isl_int would be deprecated. Since isl_val has stricter checks, it exposed the bug. In the test case (isl_set_max_val) would return infinity which would remain unchecked. We now check if the value returned is an integer or not, and bail out if it isn't. The other problem was that we were allowing all kinds of data-refs in a scop. Now we discard a scop if it has any date-ref other than (ARRAY_REF, MEM_REF, COMPONENT_REF). PR middle-end/61929 * graphite-dependences.c (add_pdr_constraints): Renamed pdr->extent to pdr->subscript_sizes. * graphite-interchange.c (build_linearized_memory_access): Add back all gcc_assert's that the "isl_int to isl_val conversion" patch has removed. Refactored. (pdr_stride_in_loop): Renamed pdr->extent to pdr->subscript_sizes. * graphite-poly.c (new_poly_dr): Same. (free_poly_dr): Same. * graphite-poly.h (struct poly_dr): Same. * graphite-scop-detection.c (stmt_has_simple_data_refs_p): Ignore all data references other than ARRAY_REF, MEM_REF, and COMPONENT_REF. * graphite-scop-detection.h: Fix space. * graphite-sese-to-poly.c (build_pbb_scattering_polyhedrons): Add back all gcc_assert's removed by a previous patch. (wrap): Remove the_isl_ctx global variable that the same patch has added. (build_loop_iteration_domains): Same. (add_param_constraints): Same. (pdr_add_data_dimensions): Same. Refactored. (build_poly_dr): Renamed extent to subscript_sizes. testsuite/ PR middle-end/61929 * gcc.dg/graphite/pr61929.c: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@225942 138bc75d-0d04-0410-961f-82ee72b054a4 diff --git a/gcc/graphite-dependences.c b/gcc/graphite-dependences.c index 50fe73e..af18ecb 100644 --- a/gcc/graphite-dependences.c +++ b/gcc/graphite-dependences.c @@ -88,13 +88,13 @@ constrain_domain (isl_map *map, isl_set *s) return isl_map_intersect_domain (map, s); } -/* Constrain pdr->accesses with pdr->extent and pbb->domain. */ +/* Constrain pdr->accesses with pdr->subscript_sizes and pbb->domain. */ static isl_map * add_pdr_constraints (poly_dr_p pdr, poly_bb_p pbb) { isl_map *x = isl_map_intersect_range (isl_map_copy (pdr->accesses), - isl_set_copy (pdr->extent)); + isl_set_copy (pdr->subscript_sizes)); x = constrain_domain (x, isl_set_copy (pbb->domain)); return x; } diff --git a/gcc/graphite-interchange.c b/gcc/graphite-interchange.c index aee51a8..03c2c63 100644 --- a/gcc/graphite-interchange.c +++ b/gcc/graphite-interchange.c @@ -79,37 +79,40 @@ extern "C" { static isl_constraint * build_linearized_memory_access (isl_map *map, poly_dr_p pdr) { - isl_constraint *res; isl_local_space *ls = isl_local_space_from_space (isl_map_get_space (map)); - unsigned offset, nsubs; - int i; - isl_ctx *ctx; + isl_constraint *res = isl_equality_alloc (ls); + isl_val *size = isl_val_int_from_ui (isl_map_get_ctx (map), 1); - isl_val *size, *subsize, *size1; - - res = isl_equality_alloc (ls); - ctx = isl_local_space_get_ctx (ls); - size = isl_val_int_from_ui (ctx, 1); - - nsubs = isl_set_dim (pdr->extent, isl_dim_set); + unsigned nsubs = isl_set_dim (pdr->subscript_sizes, isl_dim_set); /* -1 for the already included L dimension. */ - offset = isl_map_dim (map, isl_dim_out) - 1 - nsubs; + unsigned offset = isl_map_dim (map, isl_dim_out) - 1 - nsubs; res = isl_constraint_set_coefficient_si (res, isl_dim_out, offset + nsubs, -1); - /* Go through all subscripts from last to first. First dimension + /* Go through all subscripts from last to first. The dimension "i=0" is the alias set, ignore it. */ - for (i = nsubs - 1; i >= 1; i--) + for (int i = nsubs - 1; i >= 1; i--) { - isl_space *dc; - isl_aff *aff; - - size1 = isl_val_copy (size); - res = isl_constraint_set_coefficient_val (res, isl_dim_out, offset + i, size); - dc = isl_set_get_space (pdr->extent); - aff = isl_aff_zero_on_domain (isl_local_space_from_space (dc)); - aff = isl_aff_set_coefficient_si (aff, isl_dim_in, i, 1); - subsize = isl_set_max_val (pdr->extent, aff); - isl_aff_free (aff); - size = isl_val_mul (size1, subsize); + isl_aff *extract_dim; + res = isl_constraint_set_coefficient_val (res, isl_dim_out, offset + i, + isl_val_copy (size)); + isl_space *dc = isl_set_get_space (pdr->subscript_sizes); + extract_dim = isl_aff_zero_on_domain (isl_local_space_from_space (dc)); + extract_dim = isl_aff_set_coefficient_si (extract_dim, isl_dim_in, i, 1); + isl_val *max = isl_set_max_val (pdr->subscript_sizes, extract_dim); + isl_aff_free (extract_dim); + + /* The result is NULL in case of an error, the optimal value in case there + is one, negative infinity or infinity if the problem is unbounded and + NaN if the problem is empty. */ + gcc_assert (max); + + /* When one of the dimensions cannot be computed, we cannot build the size + of the array for any outer dimensions. */ + if (!isl_val_is_int (max)) + { + isl_val_free (max); + break; + } + size = isl_val_mul (size, max); } isl_val_free (size); @@ -176,7 +179,7 @@ pdr_stride_in_loop (mpz_t stride, graphite_dim_t depth, poly_dr_p pdr) /* pdr->accesses: [P1..nb_param,I1..nb_domain]->[a,S1..nb_subscript] ??? [P] not used for PDRs? - pdr->extent: [a,S1..nb_subscript] + pdr->subscript_sizes: [a,S1..nb_subscript] pbb->domain: [P1..nb_param,I1..nb_domain] pbb->transformed: [P1..nb_param,I1..nb_domain]->[T1..Tnb_sctr] [T] includes local vars (currently unused) diff --git a/gcc/graphite-poly.c b/gcc/graphite-poly.c index bcd08d8..2eff5a5a 100644 --- a/gcc/graphite-poly.c +++ b/gcc/graphite-poly.c @@ -270,7 +270,7 @@ apply_poly_transforms (scop_p scop) void new_poly_dr (poly_bb_p pbb, int dr_base_object_set, enum poly_dr_type type, void *cdr, graphite_dim_t nb_subscripts, - isl_map *acc, isl_set *extent) + isl_map *acc, isl_set *subscript_sizes) { static int id = 0; poly_dr_p pdr = XNEW (struct poly_dr); @@ -280,7 +280,7 @@ new_poly_dr (poly_bb_p pbb, int dr_base_object_set, PDR_NB_REFS (pdr) = 1; PDR_PBB (pdr) = pbb; pdr->accesses = acc; - pdr->extent = extent; + pdr->subscript_sizes = subscript_sizes; PDR_TYPE (pdr) = type; PDR_CDR (pdr) = cdr; PDR_NB_SUBSCRIPTS (pdr) = nb_subscripts; @@ -293,7 +293,7 @@ void free_poly_dr (poly_dr_p pdr) { isl_map_free (pdr->accesses); - isl_set_free (pdr->extent); + isl_set_free (pdr->subscript_sizes); XDELETE (pdr); } diff --git a/gcc/graphite-poly.h b/gcc/graphite-poly.h index 7ffd18e..82e1217 100644 --- a/gcc/graphite-poly.h +++ b/gcc/graphite-poly.h @@ -177,7 +177,7 @@ struct poly_dr In the example, the vector "R C O I L P" is "7 7 3 2 0 1". */ isl_map *accesses; - isl_set *extent; + isl_set *subscript_sizes; /* Data reference's base object set number, we must assure 2 pdrs are in the same base object set before dependency checking. */ diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c index 4fb4e02..28de4ab 100644 --- a/gcc/graphite-scop-detection.c +++ b/gcc/graphite-scop-detection.c @@ -289,7 +289,6 @@ stmt_has_simple_data_refs_p (loop_p outermost_loop ATTRIBUTE_UNUSED, gimple stmt) { data_reference_p dr; - unsigned i; int j; bool res = true; vec drs = vNULL; @@ -302,18 +301,29 @@ stmt_has_simple_data_refs_p (loop_p outermost_loop ATTRIBUTE_UNUSED, stmt, &drs); FOR_EACH_VEC_ELT (drs, j, dr) - for (i = 0; i < DR_NUM_DIMENSIONS (dr); i++) - if (!graphite_can_represent_scev (DR_ACCESS_FN (dr, i))) + { + int nb_subscripts = DR_NUM_DIMENSIONS (dr); + tree ref = DR_REF (dr); + + for (int i = nb_subscripts - 1; i >= 0; i--) { - res = false; - goto done; + if (!graphite_can_represent_scev (DR_ACCESS_FN (dr, i)) + || (TREE_CODE (ref) != ARRAY_REF + && TREE_CODE (ref) != MEM_REF + && TREE_CODE (ref) != COMPONENT_REF)) + { + free_data_refs (drs); + return false; + } + + ref = TREE_OPERAND (ref, 0); } + } free_data_refs (drs); drs.create (0); } - done: free_data_refs (drs); return res; } diff --git a/gcc/graphite-scop-detection.h b/gcc/graphite-scop-detection.h index 8e794c3..4511796 100644 --- a/gcc/graphite-scop-detection.h +++ b/gcc/graphite-scop-detection.h @@ -23,7 +23,7 @@ along with GCC; see the file COPYING3. If not see #define GCC_GRAPHITE_SCOP_DETECTION_H extern void build_scops (vec *); -extern void dot_all_scops (vec ); +extern void dot_all_scops (vec); extern void dot_scop (scop_p); #endif /* GCC_GRAPHITE_SCOP_DETECTION_H */ diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c index aaecab4..1e234fe 100644 --- a/gcc/graphite-sese-to-poly.c +++ b/gcc/graphite-sese-to-poly.c @@ -497,6 +497,7 @@ build_pbb_scattering_polyhedrons (isl_aff *static_sched, (isl_local_space_from_space (isl_map_get_space (pbb->schedule))); val = isl_aff_get_coefficient_val (static_sched, isl_dim_in, i / 2); + gcc_assert (val && isl_val_is_int (val)); val = isl_val_neg (val); c = isl_constraint_set_constant_val (c, val); @@ -719,14 +720,12 @@ extract_affine_int (tree e, __isl_take isl_space *space) /* Compute pwaff mod 2^width. */ -extern isl_ctx *the_isl_ctx; - static isl_pw_aff * wrap (isl_pw_aff *pwaff, unsigned width) { isl_val *mod; - mod = isl_val_int_from_ui(the_isl_ctx, width); + mod = isl_val_int_from_ui (isl_pw_aff_get_ctx (pwaff), width); mod = isl_val_2exp (mod); pwaff = isl_pw_aff_mod_val (pwaff, mod); @@ -1012,7 +1011,7 @@ build_loop_iteration_domains (scop_p scop, struct loop *loop, (isl_local_space_from_space (isl_space_copy (space))); c = isl_constraint_set_coefficient_si (c, isl_dim_set, pos, -1); tree_int_to_gmp (nb_iters, g); - v = isl_val_int_from_gmp (the_isl_ctx, g); + v = isl_val_int_from_gmp (scop->ctx, g); c = isl_constraint_set_constant_val (c, v); inner = isl_set_add_constraint (inner, c); } @@ -1067,7 +1066,7 @@ build_loop_iteration_domains (scop_p scop, struct loop *loop, c = isl_inequality_alloc (isl_local_space_from_space (isl_space_copy (space))); c = isl_constraint_set_coefficient_si (c, isl_dim_set, pos, -1); - v = isl_val_int_from_gmp (the_isl_ctx, g); + v = isl_val_int_from_gmp (scop->ctx, g); mpz_clear (g); c = isl_constraint_set_constant_val (c, v); inner = isl_set_add_constraint (inner, c); @@ -1335,7 +1334,7 @@ add_param_constraints (scop_p scop, graphite_dim_t p) c = isl_inequality_alloc (isl_local_space_from_space (space)); mpz_init (g); tree_int_to_gmp (lb, g); - v = isl_val_int_from_gmp (the_isl_ctx, g); + v = isl_val_int_from_gmp (scop->ctx, g); v = isl_val_neg (v); mpz_clear (g); c = isl_constraint_set_constant_val (c, v); @@ -1355,7 +1354,7 @@ add_param_constraints (scop_p scop, graphite_dim_t p) mpz_init (g); tree_int_to_gmp (ub, g); - v = isl_val_int_from_gmp (the_isl_ctx, g); + v = isl_val_int_from_gmp (scop->ctx, g); mpz_clear (g); c = isl_constraint_set_constant_val (c, v); c = isl_constraint_set_coefficient_si (c, isl_dim_param, p, -1); @@ -1491,20 +1490,19 @@ pdr_add_memory_accesses (isl_map *acc, data_reference_p dr, poly_bb_p pbb) domain. */ static isl_set * -pdr_add_data_dimensions (isl_set *extent, scop_p scop, data_reference_p dr) +pdr_add_data_dimensions (isl_set *subscript_sizes, scop_p scop, + data_reference_p dr) { tree ref = DR_REF (dr); - int i, nb_subscripts = DR_NUM_DIMENSIONS (dr); - for (i = nb_subscripts - 1; i >= 0; i--, ref = TREE_OPERAND (ref, 0)) + int nb_subscripts = DR_NUM_DIMENSIONS (dr); + for (int i = nb_subscripts - 1; i >= 0; i--, ref = TREE_OPERAND (ref, 0)) { - tree low, high; - if (TREE_CODE (ref) != ARRAY_REF) - break; + return subscript_sizes; - low = array_ref_low_bound (ref); - high = array_ref_up_bound (ref); + tree low = array_ref_low_bound (ref); + tree high = array_ref_up_bound (ref); /* XXX The PPL code dealt separately with subscript - low >= 0 and high - subscript >= 0 in case one of @@ -1522,10 +1520,10 @@ pdr_add_data_dimensions (isl_set *extent, scop_p scop, data_reference_p dr) isl_aff *aff; isl_set *univ, *lbs, *ubs; isl_pw_aff *index; - isl_space *space; isl_set *valid; - isl_pw_aff *lb = extract_affine_int (low, isl_set_get_space (extent)); - isl_pw_aff *ub = extract_affine_int (high, isl_set_get_space (extent)); + isl_space *space = isl_set_get_space (subscript_sizes); + isl_pw_aff *lb = extract_affine_int (low, isl_space_copy (space)); + isl_pw_aff *ub = extract_affine_int (high, isl_space_copy (space)); /* high >= 0 */ valid = isl_pw_aff_nonneg_set (isl_pw_aff_copy (ub)); @@ -1533,25 +1531,24 @@ pdr_add_data_dimensions (isl_set *extent, scop_p scop, data_reference_p dr) isl_set_dim (valid, isl_dim_set)); scop->context = isl_set_intersect (scop->context, valid); - space = isl_set_get_space (extent); aff = isl_aff_zero_on_domain (isl_local_space_from_space (space)); aff = isl_aff_add_coefficient_si (aff, isl_dim_in, i + 1, 1); univ = isl_set_universe (isl_space_domain (isl_aff_get_space (aff))); index = isl_pw_aff_alloc (univ, aff); - id = isl_set_get_tuple_id (extent); + id = isl_set_get_tuple_id (subscript_sizes); lb = isl_pw_aff_set_tuple_id (lb, isl_dim_in, isl_id_copy (id)); ub = isl_pw_aff_set_tuple_id (ub, isl_dim_in, id); /* low <= sub_i <= high */ lbs = isl_pw_aff_ge_set (isl_pw_aff_copy (index), lb); ubs = isl_pw_aff_le_set (index, ub); - extent = isl_set_intersect (extent, lbs); - extent = isl_set_intersect (extent, ubs); + subscript_sizes = isl_set_intersect (subscript_sizes, lbs); + subscript_sizes = isl_set_intersect (subscript_sizes, ubs); } } - return extent; + return subscript_sizes; } /* Build data accesses for DR in PBB. */ @@ -1561,7 +1558,7 @@ build_poly_dr (data_reference_p dr, poly_bb_p pbb) { int dr_base_object_set; isl_map *acc; - isl_set *extent; + isl_set *subscript_sizes; scop_p scop = PBB_SCOP (pbb); { @@ -1588,9 +1585,10 @@ build_poly_dr (data_reference_p dr, poly_bb_p pbb) alias_set_num = *(bap->alias_set); space = isl_space_set_tuple_id (space, isl_dim_set, id); - extent = isl_set_nat_universe (space); - extent = isl_set_fix_si (extent, isl_dim_set, 0, alias_set_num); - extent = pdr_add_data_dimensions (extent, scop, dr); + subscript_sizes = isl_set_nat_universe (space); + subscript_sizes = isl_set_fix_si (subscript_sizes, isl_dim_set, 0, + alias_set_num); + subscript_sizes = pdr_add_data_dimensions (subscript_sizes, scop, dr); } gcc_assert (dr->aux); @@ -1598,7 +1596,7 @@ build_poly_dr (data_reference_p dr, poly_bb_p pbb) new_poly_dr (pbb, dr_base_object_set, DR_IS_READ (dr) ? PDR_READ : PDR_WRITE, - dr, DR_NUM_DIMENSIONS (dr), acc, extent); + dr, DR_NUM_DIMENSIONS (dr), acc, subscript_sizes); } /* Write to FILE the alias graph of data references in DIMACS format. */ diff --git a/gcc/testsuite/gcc.dg/graphite/pr61929.c b/gcc/testsuite/gcc.dg/graphite/pr61929.c new file mode 100644 index 0000000..9999ebf --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/pr61929.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-loop-linear -floop-strip-mine" } */ + +typedef struct m { + char *A; + char *B; +} mystruct; +mystruct arr[52]; + +void main () {} +void generateICE (void) +{ + int i; + for (i=0; i<52; i++) + { + arr[i].A = ""; + arr[i].B = 0; + } +}