From: Richard Sandiford Date: Sat, 13 Jan 2018 17:59:08 +0000 (+0000) Subject: Allow ADDR_EXPRs of TARGET_MEM_REFs X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=65dd1346027bb5dd54d5bfea0c35a3d52f8af416;p=gcc.git Allow ADDR_EXPRs of TARGET_MEM_REFs This patch allows ADDR_EXPR , which is useful when calling internal functions that take pointers to memory that is conditionally loaded or stored. This is a prerequisite to the following ivopts patch. 2018-01-13 Richard Sandiford Alan Hayward David Sherwood gcc/ * expr.c (expand_expr_addr_expr_1): Handle ADDR_EXPRs of TARGET_MEM_REFs. * gimple-expr.h (is_gimple_addressable: Likewise. * gimple-expr.c (is_gimple_address): Likewise. * internal-fn.c (expand_call_mem_ref): New function. (expand_mask_load_optab_fn): Use it. (expand_mask_store_optab_fn): Likewise. Co-Authored-By: Alan Hayward Co-Authored-By: David Sherwood From-SVN: r256627 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c08d2b35e5e..79ddaf32d89 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2018-01-13 Richard Sandiford + Alan Hayward + David Sherwood + + * expr.c (expand_expr_addr_expr_1): Handle ADDR_EXPRs of + TARGET_MEM_REFs. + * gimple-expr.h (is_gimple_addressable: Likewise. + * gimple-expr.c (is_gimple_address): Likewise. + * internal-fn.c (expand_call_mem_ref): New function. + (expand_mask_load_optab_fn): Use it. + (expand_mask_store_optab_fn): Likewise. + 2018-01-13 Richard Sandiford Alan Hayward David Sherwood diff --git a/gcc/expr.c b/gcc/expr.c index cd1e57d0eec..42f889f318c 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -7885,6 +7885,9 @@ expand_expr_addr_expr_1 (tree exp, rtx target, scalar_int_mode tmode, return expand_expr (tem, target, tmode, modifier); } + case TARGET_MEM_REF: + return addr_for_mem_ref (exp, as, true); + case CONST_DECL: /* Expand the initializer like constants above. */ result = XEXP (expand_expr_constant (DECL_INITIAL (exp), diff --git a/gcc/gimple-expr.c b/gcc/gimple-expr.c index 7c0f831c785..56caacabba2 100644 --- a/gcc/gimple-expr.c +++ b/gcc/gimple-expr.c @@ -631,7 +631,9 @@ is_gimple_address (const_tree t) op = TREE_OPERAND (op, 0); } - if (CONSTANT_CLASS_P (op) || TREE_CODE (op) == MEM_REF) + if (CONSTANT_CLASS_P (op) + || TREE_CODE (op) == TARGET_MEM_REF + || TREE_CODE (op) == MEM_REF) return true; switch (TREE_CODE (op)) diff --git a/gcc/gimple-expr.h b/gcc/gimple-expr.h index 7d0445458fb..96733bdd7b4 100644 --- a/gcc/gimple-expr.h +++ b/gcc/gimple-expr.h @@ -119,6 +119,7 @@ static inline bool is_gimple_addressable (tree t) { return (is_gimple_id (t) || handled_component_p (t) + || TREE_CODE (t) == TARGET_MEM_REF || TREE_CODE (t) == MEM_REF); } diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index bc4027bd603..86a19644249 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -2412,15 +2412,54 @@ expand_LOOP_DIST_ALIAS (internal_fn, gcall *) gcc_unreachable (); } +/* Return a memory reference of type TYPE for argument INDEX of STMT. + Use argument INDEX + 1 to derive the second (TBAA) operand. */ + +static tree +expand_call_mem_ref (tree type, gcall *stmt, int index) +{ + tree addr = gimple_call_arg (stmt, index); + tree alias_ptr_type = TREE_TYPE (gimple_call_arg (stmt, index + 1)); + unsigned int align = tree_to_shwi (gimple_call_arg (stmt, index + 1)); + if (TYPE_ALIGN (type) != align) + type = build_aligned_type (type, align); + + tree tmp = addr; + if (TREE_CODE (tmp) == SSA_NAME) + { + gimple *def = SSA_NAME_DEF_STMT (tmp); + if (gimple_assign_single_p (def)) + tmp = gimple_assign_rhs1 (def); + } + + if (TREE_CODE (tmp) == ADDR_EXPR) + { + tree mem = TREE_OPERAND (tmp, 0); + if (TREE_CODE (mem) == TARGET_MEM_REF + && types_compatible_p (TREE_TYPE (mem), type)) + { + tree offset = TMR_OFFSET (mem); + if (alias_ptr_type != TREE_TYPE (offset) || !integer_zerop (offset)) + { + mem = copy_node (mem); + TMR_OFFSET (mem) = wide_int_to_tree (alias_ptr_type, + wi::to_poly_wide (offset)); + } + return mem; + } + } + + return fold_build2 (MEM_REF, type, addr, build_int_cst (alias_ptr_type, 0)); +} + /* Expand MASK_LOAD{,_LANES} call STMT using optab OPTAB. */ static void expand_mask_load_optab_fn (internal_fn, gcall *stmt, convert_optab optab) { struct expand_operand ops[3]; - tree type, lhs, rhs, maskt, ptr; + tree type, lhs, rhs, maskt; rtx mem, target, mask; - unsigned align; insn_code icode; maskt = gimple_call_arg (stmt, 2); @@ -2428,11 +2467,7 @@ expand_mask_load_optab_fn (internal_fn, gcall *stmt, convert_optab optab) if (lhs == NULL_TREE) return; type = TREE_TYPE (lhs); - ptr = build_int_cst (TREE_TYPE (gimple_call_arg (stmt, 1)), 0); - align = tree_to_shwi (gimple_call_arg (stmt, 1)); - if (TYPE_ALIGN (type) != align) - type = build_aligned_type (type, align); - rhs = fold_build2 (MEM_REF, type, gimple_call_arg (stmt, 0), ptr); + rhs = expand_call_mem_ref (type, stmt, 0); if (optab == vec_mask_load_lanes_optab) icode = get_multi_vector_move (type, optab); @@ -2458,19 +2493,14 @@ static void expand_mask_store_optab_fn (internal_fn, gcall *stmt, convert_optab optab) { struct expand_operand ops[3]; - tree type, lhs, rhs, maskt, ptr; + tree type, lhs, rhs, maskt; rtx mem, reg, mask; - unsigned align; insn_code icode; maskt = gimple_call_arg (stmt, 2); rhs = gimple_call_arg (stmt, 3); type = TREE_TYPE (rhs); - ptr = build_int_cst (TREE_TYPE (gimple_call_arg (stmt, 1)), 0); - align = tree_to_shwi (gimple_call_arg (stmt, 1)); - if (TYPE_ALIGN (type) != align) - type = build_aligned_type (type, align); - lhs = fold_build2 (MEM_REF, type, gimple_call_arg (stmt, 0), ptr); + lhs = expand_call_mem_ref (type, stmt, 0); if (optab == vec_mask_store_lanes_optab) icode = get_multi_vector_move (type, optab);