From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23063 invoked by alias); 12 Apr 2011 13:25:04 -0000 Received: (qmail 23012 invoked by uid 22791); 12 Apr 2011 13:25:02 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,TW_TM,TW_VP X-Spam-Check-By: sourceware.org Received: from mail-wy0-f175.google.com (HELO mail-wy0-f175.google.com) (74.125.82.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 Apr 2011 13:24:55 +0000 Received: by wye20 with SMTP id 20so6716309wye.20 for ; Tue, 12 Apr 2011 06:24:54 -0700 (PDT) Received: by 10.227.1.151 with SMTP id 23mr1342181wbf.175.1302614694248; Tue, 12 Apr 2011 06:24:54 -0700 (PDT) Received: from richards-thinkpad (gbibp9ph1--blueice2n1.emea.ibm.com [195.212.29.75]) by mx.google.com with ESMTPS id u9sm4037744wbg.17.2011.04.12.06.24.52 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 12 Apr 2011 06:24:53 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org,patches@linaro.org, richard.sandiford@linaro.org Cc: patches@linaro.org Subject: [1/9] Generalise vect_create_data_ref_ptr References: Date: Tue, 12 Apr 2011 13:25:00 -0000 In-Reply-To: (Richard Sandiford's message of "Tue, 12 Apr 2011 14:20:54 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 X-SW-Source: 2011-04/txt/msg00874.txt.bz2 This first patch generalises vect_create_data_ref_ptr & bump_data_ref_ptr so that they can handle array as well as vector types. The two cases are so similar that it's mostly a renaming exercise. Tested on x86_64-linux-gnu and arm-linux-gnueabi. OK to install? Richard gcc/ * tree-vectorizer.h (vect_create_data_ref_ptr): Add an extra type parameter. * tree-vect-data-refs.c (vect_create_data_ref_ptr): Add an aggr_type parameter. Generalise code to handle arrays as well as vectors. (vect_setup_realignment): Update accordingly. * tree-vect-stmts.c (vectorizable_store): Likewise. (vectorizable_load): Likewise. Index: gcc/tree-vectorizer.h =================================================================== --- gcc/tree-vectorizer.h 2011-04-12 11:53:54.000000000 +0100 +++ gcc/tree-vectorizer.h 2011-04-12 11:55:07.000000000 +0100 @@ -823,9 +823,9 @@ extern bool vect_verify_datarefs_alignme extern bool vect_analyze_data_ref_accesses (loop_vec_info, bb_vec_info); extern bool vect_prune_runtime_alias_test_list (loop_vec_info); extern bool vect_analyze_data_refs (loop_vec_info, bb_vec_info, int *); -extern tree vect_create_data_ref_ptr (gimple, struct loop *, tree, tree *, - gimple_stmt_iterator *, gimple *, - bool, bool *); +extern tree vect_create_data_ref_ptr (gimple, tree, struct loop *, tree, + tree *, gimple_stmt_iterator *, + gimple *, bool, bool *); extern tree bump_vector_ptr (tree, gimple, gimple_stmt_iterator *, gimple, tree); extern tree vect_create_destination_var (tree, tree); extern bool vect_strided_store_supported (tree); Index: gcc/tree-vect-data-refs.c =================================================================== --- gcc/tree-vect-data-refs.c 2011-04-12 11:53:54.000000000 +0100 +++ gcc/tree-vect-data-refs.c 2011-04-12 11:55:07.000000000 +0100 @@ -2911,32 +2911,33 @@ vect_create_addr_base_for_vector_ref (gi /* Function vect_create_data_ref_ptr. - Create a new pointer to vector type (vp), that points to the first location - accessed in the loop by STMT, along with the def-use update chain to - appropriately advance the pointer through the loop iterations. Also set - aliasing information for the pointer. This vector pointer is used by the - callers to this function to create a memory reference expression for vector - load/store access. + Create a new pointer-to-TYPE variable (ap), that points to the first + location accessed in the loop by STMT, along with the def-use update + chain to appropriately advance the pointer through the loop iterations. + Also set aliasing information for the pointer. This pointer is used by + the callers to this function to create a memory reference expression for + vector load/store access. Input: 1. STMT: a stmt that references memory. Expected to be of the form GIMPLE_ASSIGN or GIMPLE_ASSIGN . - 2. AT_LOOP: the loop where the vector memref is to be created. - 3. OFFSET (optional): an offset to be added to the initial address accessed + 2. AGGR_TYPE: the type of the reference, which should be either a vector + or an array. + 3. AT_LOOP: the loop where the vector memref is to be created. + 4. OFFSET (optional): an offset to be added to the initial address accessed by the data-ref in STMT. - 4. BSI: location where the new stmts are to be placed if there is no loop - 5. ONLY_INIT: indicate if vp is to be updated in the loop, or remain + 5. BSI: location where the new stmts are to be placed if there is no loop + 6. ONLY_INIT: indicate if ap is to be updated in the loop, or remain pointing to the initial address. - 6. TYPE: if not NULL indicates the required type of the data-ref. Output: 1. Declare a new ptr to vector_type, and have it point to the base of the data reference (initial addressed accessed by the data reference). For example, for vector of type V8HI, the following code is generated: - v8hi *vp; - vp = (v8hi *)initial_address; + v8hi *ap; + ap = (v8hi *)initial_address; if OFFSET is not supplied: initial_address = &a[init]; @@ -2956,9 +2957,10 @@ vect_create_addr_base_for_vector_ref (gi 4. Return the pointer. */ tree -vect_create_data_ref_ptr (gimple stmt, struct loop *at_loop, tree offset, - tree *initial_address, gimple_stmt_iterator *gsi, - gimple *ptr_incr, bool only_init, bool *inv_p) +vect_create_data_ref_ptr (gimple stmt, tree aggr_type, struct loop *at_loop, + tree offset, tree *initial_address, + gimple_stmt_iterator *gsi, gimple *ptr_incr, + bool only_init, bool *inv_p) { tree base_name; stmt_vec_info stmt_info = vinfo_for_stmt (stmt); @@ -2966,17 +2968,16 @@ vect_create_data_ref_ptr (gimple stmt, s struct loop *loop = NULL; bool nested_in_vect_loop = false; struct loop *containing_loop = NULL; - tree vectype = STMT_VINFO_VECTYPE (stmt_info); - tree vect_ptr_type; - tree vect_ptr; + tree aggr_ptr_type; + tree aggr_ptr; tree new_temp; gimple vec_stmt; gimple_seq new_stmt_list = NULL; edge pe = NULL; basic_block new_bb; - tree vect_ptr_init; + tree aggr_ptr_init; struct data_reference *dr = STMT_VINFO_DATA_REF (stmt_info); - tree vptr; + tree aptr; gimple_stmt_iterator incr_gsi; bool insert_after; bool negative; @@ -2986,6 +2987,9 @@ vect_create_data_ref_ptr (gimple stmt, s bb_vec_info bb_vinfo = STMT_VINFO_BB_VINFO (stmt_info); tree base; + gcc_assert (TREE_CODE (aggr_type) == ARRAY_TYPE + || TREE_CODE (aggr_type) == VECTOR_TYPE); + if (loop_vinfo) { loop = LOOP_VINFO_LOOP (loop_vinfo); @@ -3020,8 +3024,9 @@ vect_create_data_ref_ptr (gimple stmt, s if (vect_print_dump_info (REPORT_DETAILS)) { tree data_ref_base = base_name; - fprintf (vect_dump, "create vector-pointer variable to type: "); - print_generic_expr (vect_dump, vectype, TDF_SLIM); + fprintf (vect_dump, "create %s-pointer variable to type: ", + tree_code_name[(int) TREE_CODE (aggr_type)]); + print_generic_expr (vect_dump, aggr_type, TDF_SLIM); if (TREE_CODE (data_ref_base) == VAR_DECL || TREE_CODE (data_ref_base) == ARRAY_REF) fprintf (vect_dump, " vectorizing an array ref: "); @@ -3032,27 +3037,28 @@ vect_create_data_ref_ptr (gimple stmt, s print_generic_expr (vect_dump, base_name, TDF_SLIM); } - /* (1) Create the new vector-pointer variable. */ - vect_ptr_type = build_pointer_type (vectype); + /* (1) Create the new aggregate-pointer variable. */ + aggr_ptr_type = build_pointer_type (aggr_type); base = get_base_address (DR_REF (dr)); if (base && TREE_CODE (base) == MEM_REF) - vect_ptr_type - = build_qualified_type (vect_ptr_type, + aggr_ptr_type + = build_qualified_type (aggr_ptr_type, TYPE_QUALS (TREE_TYPE (TREE_OPERAND (base, 0)))); - vect_ptr = vect_get_new_vect_var (vect_ptr_type, vect_pointer_var, + aggr_ptr = vect_get_new_vect_var (aggr_ptr_type, vect_pointer_var, get_name (base_name)); - /* Vector types inherit the alias set of their component type by default so - we need to use a ref-all pointer if the data reference does not conflict - with the created vector data reference because it is not addressable. */ - if (!alias_sets_conflict_p (get_deref_alias_set (vect_ptr), + /* Vector and array types inherit the alias set of their component + type by default so we need to use a ref-all pointer if the data + reference does not conflict with the created aggregated data + reference because it is not addressable. */ + if (!alias_sets_conflict_p (get_deref_alias_set (aggr_ptr), get_alias_set (DR_REF (dr)))) { - vect_ptr_type - = build_pointer_type_for_mode (vectype, - TYPE_MODE (vect_ptr_type), true); - vect_ptr = vect_get_new_vect_var (vect_ptr_type, vect_pointer_var, + aggr_ptr_type + = build_pointer_type_for_mode (aggr_type, + TYPE_MODE (aggr_ptr_type), true); + aggr_ptr = vect_get_new_vect_var (aggr_ptr_type, vect_pointer_var, get_name (base_name)); } @@ -3063,14 +3069,14 @@ vect_create_data_ref_ptr (gimple stmt, s do { tree lhs = gimple_assign_lhs (orig_stmt); - if (!alias_sets_conflict_p (get_deref_alias_set (vect_ptr), + if (!alias_sets_conflict_p (get_deref_alias_set (aggr_ptr), get_alias_set (lhs))) { - vect_ptr_type - = build_pointer_type_for_mode (vectype, - TYPE_MODE (vect_ptr_type), true); - vect_ptr - = vect_get_new_vect_var (vect_ptr_type, vect_pointer_var, + aggr_ptr_type + = build_pointer_type_for_mode (aggr_type, + TYPE_MODE (aggr_ptr_type), true); + aggr_ptr + = vect_get_new_vect_var (aggr_ptr_type, vect_pointer_var, get_name (base_name)); break; } @@ -3080,7 +3086,7 @@ vect_create_data_ref_ptr (gimple stmt, s while (orig_stmt); } - add_referenced_var (vect_ptr); + add_referenced_var (aggr_ptr); /* Note: If the dataref is in an inner-loop nested in LOOP, and we are vectorizing LOOP (i.e., outer-loop vectorization), we need to create two @@ -3113,8 +3119,8 @@ vect_create_data_ref_ptr (gimple stmt, s vp2 = vp1 + step if () goto LOOP */ - /* (2) Calculate the initial address the vector-pointer, and set - the vector-pointer to point to it before the loop. */ + /* (2) Calculate the initial address of the aggregate-pointer, and set + the aggregate-pointer to point to it before the loop. */ /* Create: (&(base[init_val+offset]) in the loop preheader. */ @@ -3133,17 +3139,17 @@ vect_create_data_ref_ptr (gimple stmt, s *initial_address = new_temp; - /* Create: p = (vectype *) initial_base */ + /* Create: p = (aggr_type *) initial_base */ if (TREE_CODE (new_temp) != SSA_NAME - || !useless_type_conversion_p (vect_ptr_type, TREE_TYPE (new_temp))) + || !useless_type_conversion_p (aggr_ptr_type, TREE_TYPE (new_temp))) { - vec_stmt = gimple_build_assign (vect_ptr, - fold_convert (vect_ptr_type, new_temp)); - vect_ptr_init = make_ssa_name (vect_ptr, vec_stmt); + vec_stmt = gimple_build_assign (aggr_ptr, + fold_convert (aggr_ptr_type, new_temp)); + aggr_ptr_init = make_ssa_name (aggr_ptr, vec_stmt); /* Copy the points-to information if it exists. */ if (DR_PTR_INFO (dr)) - duplicate_ssa_name_ptr_info (vect_ptr_init, DR_PTR_INFO (dr)); - gimple_assign_set_lhs (vec_stmt, vect_ptr_init); + duplicate_ssa_name_ptr_info (aggr_ptr_init, DR_PTR_INFO (dr)); + gimple_assign_set_lhs (vec_stmt, aggr_ptr_init); if (pe) { new_bb = gsi_insert_on_edge_immediate (pe, vec_stmt); @@ -3153,19 +3159,19 @@ vect_create_data_ref_ptr (gimple stmt, s gsi_insert_before (gsi, vec_stmt, GSI_SAME_STMT); } else - vect_ptr_init = new_temp; + aggr_ptr_init = new_temp; - /* (3) Handle the updating of the vector-pointer inside the loop. + /* (3) Handle the updating of the aggregate-pointer inside the loop. This is needed when ONLY_INIT is false, and also when AT_LOOP is the inner-loop nested in LOOP (during outer-loop vectorization). */ /* No update in loop is required. */ if (only_init && (!loop_vinfo || at_loop == loop)) - vptr = vect_ptr_init; + aptr = aggr_ptr_init; else { - /* The step of the vector pointer is the Vector Size. */ - tree step = TYPE_SIZE_UNIT (vectype); + /* The step of the aggregate pointer is the type size. */ + tree step = TYPE_SIZE_UNIT (aggr_type); /* One exception to the above is when the scalar step of the load in LOOP is zero. In this case the step here is also zero. */ if (*inv_p) @@ -3175,9 +3181,9 @@ vect_create_data_ref_ptr (gimple stmt, s standard_iv_increment_position (loop, &incr_gsi, &insert_after); - create_iv (vect_ptr_init, - fold_convert (vect_ptr_type, step), - vect_ptr, loop, &incr_gsi, insert_after, + create_iv (aggr_ptr_init, + fold_convert (aggr_ptr_type, step), + aggr_ptr, loop, &incr_gsi, insert_after, &indx_before_incr, &indx_after_incr); incr = gsi_stmt (incr_gsi); set_vinfo_for_stmt (incr, new_stmt_vec_info (incr, loop_vinfo, NULL)); @@ -3191,14 +3197,14 @@ vect_create_data_ref_ptr (gimple stmt, s if (ptr_incr) *ptr_incr = incr; - vptr = indx_before_incr; + aptr = indx_before_incr; } if (!nested_in_vect_loop || only_init) - return vptr; + return aptr; - /* (4) Handle the updating of the vector-pointer inside the inner-loop + /* (4) Handle the updating of the aggregate-pointer inside the inner-loop nested in LOOP, if exists. */ gcc_assert (nested_in_vect_loop); @@ -3206,7 +3212,7 @@ vect_create_data_ref_ptr (gimple stmt, s { standard_iv_increment_position (containing_loop, &incr_gsi, &insert_after); - create_iv (vptr, fold_convert (vect_ptr_type, DR_STEP (dr)), vect_ptr, + create_iv (aptr, fold_convert (aggr_ptr_type, DR_STEP (dr)), aggr_ptr, containing_loop, &incr_gsi, insert_after, &indx_before_incr, &indx_after_incr); incr = gsi_stmt (incr_gsi); @@ -3674,8 +3680,9 @@ vect_setup_realignment (gimple stmt, gim gcc_assert (!compute_in_loop); vec_dest = vect_create_destination_var (scalar_dest, vectype); - ptr = vect_create_data_ref_ptr (stmt, loop_for_initial_load, NULL_TREE, - &init_addr, NULL, &inc, true, &inv_p); + ptr = vect_create_data_ref_ptr (stmt, vectype, loop_for_initial_load, + NULL_TREE, &init_addr, NULL, &inc, + true, &inv_p); new_stmt = gimple_build_assign_with_ops (BIT_AND_EXPR, NULL_TREE, ptr, build_int_cst (TREE_TYPE (ptr), Index: gcc/tree-vect-stmts.c =================================================================== --- gcc/tree-vect-stmts.c 2011-04-12 11:55:07.000000000 +0100 +++ gcc/tree-vect-stmts.c 2011-04-12 11:55:07.000000000 +0100 @@ -3581,9 +3581,9 @@ vectorizable_store (gimple stmt, gimple_ /* We should have catched mismatched types earlier. */ gcc_assert (useless_type_conversion_p (vectype, TREE_TYPE (vec_oprnd))); - dataref_ptr = vect_create_data_ref_ptr (first_stmt, NULL, NULL_TREE, - &dummy, gsi, &ptr_incr, false, - &inv_p); + dataref_ptr = vect_create_data_ref_ptr (first_stmt, vectype, NULL, + NULL_TREE, &dummy, gsi, + &ptr_incr, false, &inv_p); gcc_assert (bb_vinfo || !inv_p); } else @@ -4109,9 +4109,9 @@ vectorizable_load (gimple stmt, gimple_s { /* 1. Create the vector pointer update chain. */ if (j == 0) - dataref_ptr = vect_create_data_ref_ptr (first_stmt, at_loop, offset, - &dummy, gsi, &ptr_incr, false, - &inv_p); + dataref_ptr = vect_create_data_ref_ptr (first_stmt, vectype, at_loop, + offset, &dummy, gsi, + &ptr_incr, false, &inv_p); else dataref_ptr = bump_vector_ptr (dataref_ptr, ptr_incr, gsi, stmt, NULL_TREE);