https://gcc.gnu.org/g:cf7bfcf51fcfaf7af15e72f760d88fa5712a4f88
commit r17-6344-gcf7bfcf51fcfaf7af15e72f760d88fa5712a4f88 Author: Dhruv Chawla <[email protected]> Date: Tue Oct 27 09:29:44 2026 +0000 aarch64: Fix ICE on discarded intrinsic result [PR127771] r17-4816-gb24418a2212866 gives a call whose result is discarded a placeholder lhs using create_tmp_var, which gives a VAR_DECL. This ends up setting ssa_renaming_needed and subsequent passes which fold do not set TODO_update_ssa, so execute_todo ICEs. This is not necessary for aggregate types, so this only requires a check of is_gimple_reg_type. To fix this, this patch makes lhs a member function of the same name, which fills in the destination the first time a fold asks for it and makes it an SSA name for register types. Since lhs is only called by folds that produce a value, a fold that declines no longer leaves a temporary behind. This patch also adds a new ret_type member taken from the function declaration, so that folds no longer have to query the lhs at all. This also allows making the m_lhs member variable private as there are no external references to it anymore. Instead of trying to decide when to drop the call based on side effects, just generate the placeholder and let DCE choose. Bootstrapped and regtested on aarch64-linux-gnu. Signed-off-by: Dhruv Chawla <[email protected]> gcc/ChangeLog: PR target/127771 * config/aarch64/aarch64-acle-builtins.h (build_var): Declare. (gimple_folder::lhs): Change from a member variable to a member function. (gimple_folder::ret_type): New member variable. (gimple_folder::m_lhs): New private member variable. * config/aarch64/aarch64-acle-builtins.cc (build_var): Move here from aarch64-neon-builtins-base.cc and add a comment. (gimple_folder::gimple_folder): Initialize ret_type. (gimple_folder::lhs): New function. (gimple_folder::force_val): Use build_var. (gimple_folder::fold): Do not create a placeholder lhs. (gimple_folder::fold_contiguous_load, gimple_folder::fold_pfalse) (gimple_folder::convert_and_fold, gimple_folder::fold_to_cstu) (gimple_folder::fold_to_ptrue, gimple_folder::fold_to_pfalse) (gimple_folder::fold_to_vl_pred, gimple_folder::fold_const_binary) (gimple_folder::fold_active_lanes_to, gimple_folder::fold_call_to): Use ret_type and lhs. * config/aarch64/aarch64-neon-builtins-base.cc: Likewise. (build_var): Move to aarch64-acle-builtins.cc. * config/aarch64/aarch64-sve-builtins-base.cc: Likewise. * config/aarch64/aarch64-sve-builtins-functions.h: Likewise. * config/aarch64/aarch64-sve-builtins-sve2.cc: Likewise. gcc/testsuite/ChangeLog: PR target/127771 * gcc.target/aarch64/sve/acle/general/pr127771.c: New test. Diff: --- gcc/config/aarch64/aarch64-acle-builtins.cc | 84 ++++++------ gcc/config/aarch64/aarch64-acle-builtins.h | 13 +- gcc/config/aarch64/aarch64-neon-builtins-base.cc | 132 +++++++++---------- gcc/config/aarch64/aarch64-sve-builtins-base.cc | 144 ++++++++++----------- .../aarch64/aarch64-sve-builtins-functions.h | 6 +- gcc/config/aarch64/aarch64-sve-builtins-sve2.cc | 13 +- .../gcc.target/aarch64/sve/acle/general/pr127771.c | 21 +++ 7 files changed, 224 insertions(+), 189 deletions(-) diff --git a/gcc/config/aarch64/aarch64-acle-builtins.cc b/gcc/config/aarch64/aarch64-acle-builtins.cc index 1a4d473891cd..da63366ace09 100644 --- a/gcc/config/aarch64/aarch64-acle-builtins.cc +++ b/gcc/config/aarch64/aarch64-acle-builtins.cc @@ -2784,6 +2784,17 @@ function_checker::check () return shape->check (*this); } +/* Return a variable of type TYPE that is suitable for holding an + intermediate value, in a form appropriate to the current stage of + compilation. */ +tree +build_var (tree type) +{ + return gimple_in_ssa_p (cfun) && is_gimple_reg_type (type) + ? make_ssa_name (type) + : create_tmp_var (type); +} + /* Return true if V is a vector constant and if, for every in-range integer I, element STEP*I is equal to element 0. */ bool @@ -2827,8 +2838,8 @@ is_pfalse (tree v) gimple_folder::gimple_folder (const function_instance &instance, tree fndecl, gimple_stmt_iterator *gsi_in, gcall *call_in) : function_call_info (gimple_location (call_in), instance, fndecl), - gsi (gsi_in), call (call_in), lhs (gimple_call_lhs (call_in)), - stmts (nullptr) + gsi (gsi_in), call (call_in), m_lhs (gimple_call_lhs (call_in)), + ret_type (TREE_TYPE (TREE_TYPE (fndecl))), stmts (nullptr) { } @@ -2892,7 +2903,7 @@ gimple_folder::fold_contiguous_load (internal_fn ifn_code) tree cookie = load_store_cookie (TREE_TYPE (vectype)); gcall *new_call = gimple_build_call_internal (ifn_code, 4, base, cookie, pred, els); - gimple_call_set_lhs (new_call, lhs); + gimple_call_set_lhs (new_call, lhs ()); return new_call; } @@ -2973,15 +2984,14 @@ gimple_folder::fold_pfalse () return nullptr; } if ((pred == PRED_x || pred == PRED_z) && is_pfalse (gp)) - return fold_call_to (build_zero_cst (TREE_TYPE (lhs))); + return fold_call_to (build_zero_cst (ret_type)); if (pred == PRED_implicit && is_pfalse (gp)) { unsigned int flags = call_properties (); /* Folding to lhs = {0, ...} is not appropriate for intrinsics with AGGREGATE types as lhs. */ - if ((flags & CP_READ_MEMORY) - && !AGGREGATE_TYPE_P (TREE_TYPE (lhs))) - return fold_call_to (build_zero_cst (TREE_TYPE (lhs))); + if ((flags & CP_READ_MEMORY) && !AGGREGATE_TYPE_P (ret_type)) + return fold_call_to (build_zero_cst (ret_type)); if (flags & (CP_WRITE_MEMORY | CP_PREFETCH_MEMORY)) return gimple_build_nop (); } @@ -3000,9 +3010,9 @@ gimple_folder::convert_and_fold (tree type, { gcc_assert (VECTOR_TYPE_P (type) && TYPE_MODE (type) != VNx16BImode); - tree old_ty = TREE_TYPE (lhs); + tree old_ty = ret_type; bool convert_lhs_p = !useless_type_conversion_p (type, old_ty); - tree lhs_conv = convert_lhs_p ? make_ssa_name (type) : lhs; + tree lhs_conv = convert_lhs_p ? make_ssa_name (type) : lhs (); unsigned int num_args = gimple_call_num_args (call); auto_vec<tree, 16> args_conv; args_conv.safe_grow (num_args); @@ -3021,7 +3031,7 @@ gimple_folder::convert_and_fold (tree type, if (convert_lhs_p) { tree t = build1 (VIEW_CONVERT_EXPR, old_ty, lhs_conv); - gimple *g = gimple_build_assign (lhs, VIEW_CONVERT_EXPR, t); + gimple *g = gimple_build_assign (lhs (), VIEW_CONVERT_EXPR, t); gsi_insert_after (gsi, g, GSI_SAME_STMT); } return new_stmt; @@ -3031,14 +3041,14 @@ gimple_folder::convert_and_fold (tree type, gimple * gimple_folder::fold_to_cstu (poly_uint64 val) { - return gimple_build_assign (lhs, build_int_cstu (TREE_TYPE (lhs), val)); + return gimple_build_assign (lhs (), build_int_cstu (ret_type, val)); } /* Fold the call to a PTRUE, taking the element size from type suffix 0. */ gimple * gimple_folder::fold_to_ptrue () { - tree svbool_type = TREE_TYPE (lhs); + tree svbool_type = ret_type; tree bool_type = TREE_TYPE (svbool_type); unsigned int element_bytes = type_suffix (0).element_bytes; @@ -3048,7 +3058,7 @@ gimple_folder::fold_to_ptrue () builder.quick_push (build_all_ones_cst (bool_type)); for (unsigned int i = 1; i < element_bytes; ++i) builder.quick_push (build_zero_cst (bool_type)); - return gimple_build_assign (lhs, builder.build ()); + return gimple_build_assign (lhs (), builder.build ()); } /* Fold the call to a PFALSE. */ @@ -3056,7 +3066,7 @@ gimple * gimple_folder::fold_to_pfalse () { if (type_suffix (0).tclass == TYPE_bool) - return gimple_build_assign (lhs, build_zero_cst (TREE_TYPE (lhs))); + return gimple_build_assign (lhs (), build_zero_cst (ret_type)); if (type_suffix (0).tclass == TYPE_count) { @@ -3073,10 +3083,10 @@ gimple_folder::fold_to_pfalse () gimple * gimple_folder::fold_to_vl_pred (unsigned int vl) { - tree vectype = TREE_TYPE (lhs); + tree vectype = ret_type; unsigned int element_bytes = type_suffix (0).element_bytes; tree pred = aarch64_fold_sve_ptrue_vl (vectype, vl, element_bytes); - return gimple_build_assign (lhs, pred); + return gimple_build_assign (lhs (), pred); } /* Try to fold the call to a constant, given that, for integers, the call @@ -3093,7 +3103,7 @@ gimple_folder::fold_const_binary (enum tree_code code) if (type_suffix (0).integer_p && (pred == PRED_x || is_ptrue (pg, type_suffix (0).element_bytes))) if (tree res = vector_const_binop (code, op1, op2, aarch64_const_binop)) - return gimple_build_assign (lhs, res); + return gimple_build_assign (lhs (), res); return NULL; } @@ -3106,33 +3116,44 @@ gimple_folder::fold_active_lanes_to (tree x) /* If predication is _x or the predicate is ptrue, fold to X. */ if (pred == PRED_x || is_ptrue (gimple_call_arg (call, 0), type_suffix (0).element_bytes)) - return gimple_build_assign (lhs, x); + return gimple_build_assign (lhs (), x); /* If the predication is _z or _m, calculate a vector that supplies the values of inactive lanes (the first vector argument for m and a zero vector from z). */ tree vec_inactive; if (pred == PRED_z) - vec_inactive = build_zero_cst (TREE_TYPE (lhs)); + vec_inactive = build_zero_cst (ret_type); else vec_inactive = gimple_call_arg (call, 1); if (operand_equal_p (x, vec_inactive, 0)) - return gimple_build_assign (lhs, x); + return gimple_build_assign (lhs (), x); tree pred = convert_pred (vector_type (0), 0); - x = force_vector (TREE_TYPE (lhs), x); - return gimple_build_assign (lhs, VEC_COND_EXPR, pred, x, vec_inactive); + x = force_vector (ret_type, x); + return gimple_build_assign (lhs (), VEC_COND_EXPR, pred, x, vec_inactive); } /* Fold call to assignment statement lhs = t. */ gimple * gimple_folder::fold_call_to (tree t) { - if (types_compatible_p (TREE_TYPE (lhs), TREE_TYPE (t))) - return gimple_build_assign (lhs, t); + if (types_compatible_p (ret_type, TREE_TYPE (t))) + return gimple_build_assign (lhs (), t); - tree rhs = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (lhs), t); - return gimple_build_assign (lhs, VIEW_CONVERT_EXPR, rhs); + tree rhs = build1 (VIEW_CONVERT_EXPR, ret_type, t); + return gimple_build_assign (lhs (), VIEW_CONVERT_EXPR, rhs); +} + +/* Return an lhs that callers can use to represent the result of the call. + If the original call had no lhs, create a temporary of the appropriate + form for the current stage of compilation. */ +tree +gimple_folder::lhs () const +{ + if (!m_lhs) + m_lhs = build_var (ret_type); + return m_lhs; } /* Try to fold the call. Return the new statement on success and null @@ -3145,12 +3166,6 @@ gimple_folder::fold () if (!TARGET_SIMD && !TARGET_SVE) return NULL; - /* Create a placeholder variable for the result. - This allows implementers of `fold` to assume `lhs` will never be null. - If the result is unused, it will be optimized away later. */ - if (!lhs && TREE_TYPE (gimple_call_fntype (call)) != void_type_node) - lhs = create_tmp_var (TREE_TYPE (gimple_call_fntype (call))); - /* First try some simplifications that are common to many functions. */ gimple *res = redirect_pred_x (); if (!res) @@ -3181,10 +3196,7 @@ gimple_folder::force_val (tree expr) if (is_gimple_val (expr)) return expr; - auto type = TREE_TYPE (expr); - auto var = gimple_in_ssa_p (cfun) && is_gimple_reg_type (type) - ? make_ssa_name (type) - : create_tmp_var (type); + auto var = build_var (TREE_TYPE (expr)); auto stmt = gimple_build_assign (var, expr); gimple_seq_add_stmt_without_update (&stmts, stmt); return var; diff --git a/gcc/config/aarch64/aarch64-acle-builtins.h b/gcc/config/aarch64/aarch64-acle-builtins.h index 744ac7071d8f..c15a4ad3598f 100644 --- a/gcc/config/aarch64/aarch64-acle-builtins.h +++ b/gcc/config/aarch64/aarch64-acle-builtins.h @@ -672,14 +672,22 @@ public: gimple *fold (); + tree lhs () const; + /* Where to insert extra statements that feed the final replacement. */ gimple_stmt_iterator *gsi; /* The call we're folding. */ gcall *call; - /* The result of the call, or null if none. */ - tree lhs; +private: + /* The result of the call, or null if none. Call lhs() instead of referring + to this directly. Filled in lazily hence mutable. */ + mutable tree m_lhs; + +public: + /* The type that the function returns. */ + tree ret_type; /* The sequence of statements that should be emitted before the original call. */ @@ -861,6 +869,7 @@ extern tree acle_vector_types[MAX_TUPLE_SIZE][NUM_VECTOR_TYPES + 1]; extern tree acle_svpattern; extern tree acle_svprfop; +tree build_var (tree); bool vector_cst_all_same (tree, unsigned int); bool is_ptrue (tree, unsigned int); bool is_pfalse (tree); diff --git a/gcc/config/aarch64/aarch64-neon-builtins-base.cc b/gcc/config/aarch64/aarch64-neon-builtins-base.cc index 4dd4f684fed2..4c5e4c0593be 100644 --- a/gcc/config/aarch64/aarch64-neon-builtins-base.cc +++ b/gcc/config/aarch64/aarch64-neon-builtins-base.cc @@ -216,14 +216,6 @@ one_element_vector_type_p (tree type) return VECTOR_TYPE_P (type) && known_eq (TYPE_VECTOR_SUBPARTS (type), 1U); } -tree -build_var (tree type) -{ - return gimple_in_ssa_p (cfun) && is_gimple_reg_type (type) - ? make_ssa_name (type) - : create_tmp_var (type); -} - /* Build a call to the internal function IFN. Handles singleton vector arguments specially: they are cast to their inner element type before the function is called, and then the return value @@ -270,11 +262,11 @@ public: { if (f.call_properties () & CP_RAISE_FP_EXCEPTIONS) { - f.assign (f.lhs, ret); - return build_optimization_barrier (f.lhs); + f.assign (f.lhs (), ret); + return build_optimization_barrier (f.lhs ()); } else - return gimple_build_assign (f.lhs, ret); + return gimple_build_assign (f.lhs (), ret); } tree memory_scalar_type (const function_instance &f) const override @@ -467,11 +459,11 @@ public: { case TYPE_signed: case TYPE_unsigned: - return gimple_build_assign (f.lhs, m_int_code, arg0, arg1, arg2); + return gimple_build_assign (f.lhs (), m_int_code, arg0, arg1, arg2); case TYPE_float: - return gimple_build_assign (f.lhs, m_float_code, arg0, arg1, arg2); + return gimple_build_assign (f.lhs (), m_float_code, arg0, arg1, arg2); case TYPE_poly: - return gimple_build_assign (f.lhs, m_poly_code, arg0, arg1, arg2); + return gimple_build_assign (f.lhs (), m_poly_code, arg0, arg1, arg2); default: gcc_unreachable (); } @@ -570,8 +562,8 @@ struct gimple_create : public gimple_function_base gimple *fold (gimple_folder &f) const override { auto arg = gimple_call_arg (f.call, 0); - return gimple_build_assign (f.lhs, fold_build1 (VIEW_CONVERT_EXPR, - TREE_TYPE (f.lhs), arg)); + return gimple_build_assign (f.lhs (), fold_build1 (VIEW_CONVERT_EXPR, + f.ret_type, arg)); } }; @@ -583,7 +575,7 @@ struct gimple_combine : public gimple_function_base auto arg2 = gimple_call_arg (f.call, 1); auto arg_type = TREE_TYPE (arg1); auto elem_type = TREE_TYPE (arg_type); - auto ret_type = TREE_TYPE (f.lhs); + auto ret_type = f.ret_type; if (known_eq (TYPE_VECTOR_SUBPARTS (arg_type), 1U)) { @@ -594,7 +586,7 @@ struct gimple_combine : public gimple_function_base if (BYTES_BIG_ENDIAN) std::swap (arg1, arg2); - return gimple_build_assign (f.lhs, + return gimple_build_assign (f.lhs (), build_constructor_va (ret_type, 2, NULL_TREE, arg1, NULL_TREE, arg2)); } @@ -606,7 +598,7 @@ struct gimple_get_lane : public gimple_function_base { auto src = gimple_call_arg (f.call, 0); auto lane = gimple_call_arg (f.call, 1); - return gimple_build_assign (f.lhs, build_lane_get (src, lane)); + return gimple_build_assign (f.lhs (), build_lane_get (src, lane)); } }; @@ -617,9 +609,9 @@ struct gimple_get_half : public gimple_function_base { auto src = gimple_call_arg (f.call, 0); auto half - = fold_build3 (BIT_FIELD_REF, TREE_TYPE (f.lhs), src, bitsize_int (64), + = fold_build3 (BIT_FIELD_REF, f.ret_type, src, bitsize_int (64), bitsize_int (high_half_p ^ BYTES_BIG_ENDIAN ? 64 : 0)); - return gimple_build_assign (f.lhs, half); + return gimple_build_assign (f.lhs (), half); } }; @@ -630,7 +622,7 @@ struct gimple_set_lane : public gimple_function_base auto elem = gimple_call_arg (f.call, 0); auto src = gimple_call_arg (f.call, 1); auto lane = gimple_call_arg (f.call, 2); - return gimple_build_assign (f.lhs, build_lane_set (src, lane, elem)); + return gimple_build_assign (f.lhs (), build_lane_set (src, lane, elem)); } }; @@ -648,7 +640,7 @@ struct gimple_copy_lane : public gimple_function_base // vec1[lane1] = tmp1 // lhs = vec1 - return gimple_build_assign (f.lhs, build_lane_set (vec1, lane1, tmp1)); + return gimple_build_assign (f.lhs (), build_lane_set (vec1, lane1, tmp1)); } }; @@ -657,8 +649,8 @@ struct gimple_dup : public gimple_function_base gimple *fold (gimple_folder &f) const override { auto elem = gimple_call_arg (f.call, 0); - auto ret_type = TREE_TYPE (f.lhs); - return gimple_build_assign (f.lhs, build_vec_dup (ret_type, elem)); + auto ret_type = f.ret_type; + return gimple_build_assign (f.lhs (), build_vec_dup (ret_type, elem)); } }; @@ -668,13 +660,13 @@ struct gimple_dup_lane : public gimple_function_base { auto vec = gimple_call_arg (f.call, 0); auto lane = gimple_call_arg (f.call, 1); - auto type = TREE_TYPE (f.lhs); + auto type = f.ret_type; // tmp1 = vec[lane] auto tmp1 = f.force_val (build_lane_get (vec, lane)); // lhs = VEC_DUP (vec[lane]) - return gimple_build_assign (f.lhs, build_vec_dup (type, tmp1)); + return gimple_build_assign (f.lhs (), build_vec_dup (type, tmp1)); } }; @@ -697,7 +689,7 @@ public: // tmp1 = ~rhs auto tmp1 = f.force_val (fold_build1 (BIT_NOT_EXPR, type, rhs)); - return gimple_build_assign (f.lhs, this->m_code, lhs, tmp1); + return gimple_build_assign (f.lhs (), this->m_code, lhs, tmp1); } }; @@ -712,7 +704,7 @@ public: auto m = gimple_call_arg (f.call, 2); auto uint_type = TREE_TYPE (d); - auto ret_type = TREE_TYPE (f.lhs); + auto ret_type = f.ret_type; // Cast to unsigned integer type if necessary. m = f.force_val (build_cast (uint_type, m)); @@ -727,7 +719,7 @@ public: // tmp3 = m ^ ((m ^ n) & d) auto tmp3 = f.force_val (fold_build2 (BIT_XOR_EXPR, uint_type, m, tmp2)); - return gimple_build_assign (f.lhs, build_cast (ret_type, tmp3)); + return gimple_build_assign (f.lhs (), build_cast (ret_type, tmp3)); } }; @@ -746,13 +738,13 @@ public: auto n = gimple_call_arg (f.call, 0); auto m = gimple_call_arg (f.call, 1); auto a = gimple_call_arg (f.call, 2); - auto type = TREE_TYPE (f.lhs); + auto type = f.ret_type; // tmp1 = n ^ m auto tmp1 = f.force_val (fold_build2 (BIT_XOR_EXPR, type, n, m)); // lhs = (n ^ m) ^ a - return gimple_build_assign (f.lhs, BIT_XOR_EXPR, tmp1, a); + return gimple_build_assign (f.lhs (), BIT_XOR_EXPR, tmp1, a); } rtx expand (function_expander &e) const override @@ -782,7 +774,7 @@ public: auto tmp2 = f.force_val (fold_build2 (BIT_AND_EXPR, arg_type, m, tmp1)); // lhs = n ^ (m & ~a) - return gimple_build_assign (f.lhs, BIT_XOR_EXPR, n, tmp2); + return gimple_build_assign (f.lhs (), BIT_XOR_EXPR, n, tmp2); } rtx expand (function_expander &e) const override @@ -809,7 +801,7 @@ public: fold_build2 (LROTATE_EXPR, arg_type, m, build_one_cst (arg_type))); // lhs = n ^ rotl (m, 1) - return gimple_build_assign (f.lhs, BIT_XOR_EXPR, n, tmp1); + return gimple_build_assign (f.lhs (), BIT_XOR_EXPR, n, tmp1); } rtx expand (function_expander &e) const override @@ -830,13 +822,13 @@ public: auto n = gimple_call_arg (f.call, 0); auto m = gimple_call_arg (f.call, 1); auto imm6 = gimple_call_arg (f.call, 2); - auto type = TREE_TYPE (f.lhs); + auto type = f.ret_type; // tmp1 = n ^ m auto tmp1 = f.force_val (fold_build2 (BIT_XOR_EXPR, type, n, m)); // lhs = rotr (n ^ m, imm6) - return gimple_build_assign (f.lhs, RROTATE_EXPR, tmp1, imm6); + return gimple_build_assign (f.lhs (), RROTATE_EXPR, tmp1, imm6); } rtx expand (function_expander &e) const override @@ -858,7 +850,7 @@ public: gimple *fold (gimple_folder &f) const override { - tree lhs_type = TREE_TYPE (f.lhs); + tree lhs_type = f.ret_type; auto_vec<tree> args{}; for (unsigned i = 0; i < gimple_call_num_args (f.call); i++) { @@ -870,8 +862,8 @@ public: arg)); args.safe_push (arg); } - return gimple_build_assign (f.lhs, build_ifn_call (f, this->m_ifn, lhs_type, - args)); + return gimple_build_assign (f.lhs (), build_ifn_call (f, this->m_ifn, + lhs_type, args)); } }; @@ -899,7 +891,7 @@ public: std::swap (a, b); auto mask = this->m_mask_fn (f); - return gimple_build_assign (f.lhs, VEC_PERM_EXPR, a, b, mask); + return gimple_build_assign (f.lhs (), VEC_PERM_EXPR, a, b, mask); } }; @@ -924,7 +916,7 @@ public: auto arg_type = TREE_TYPE (a); gcc_assert (types_compatible_p (arg_type, TREE_TYPE (b))); - auto tuple_type = TREE_TYPE (f.lhs); + auto tuple_type = f.ret_type; auto tuple = build_var (tuple_type); f.assign (tuple, build_clobber (tuple_type)); for (auto i = 0; i < 2; i++) @@ -935,7 +927,7 @@ public: build_tuple_set (f, tuple, size_int (i), permuted); } - return gimple_build_assign (f.lhs, tuple); + return gimple_build_assign (f.lhs (), tuple); } }; @@ -1257,9 +1249,9 @@ struct gimple_reinterpret : public gimple_function_base gimple *fold (gimple_folder &f) const override { auto input = gimple_call_arg (f.call, 0); - auto ret_type = TREE_TYPE (f.lhs); + auto ret_type = f.ret_type; auto reinterpret = fold_build1 (VIEW_CONVERT_EXPR, ret_type, input); - return gimple_build_assign (f.lhs, reinterpret); + return gimple_build_assign (f.lhs (), reinterpret); } }; @@ -1272,9 +1264,9 @@ struct gimple_abs : public gimple_function_base if (!FLOAT_TYPE_P (arg_type)) return gimple_build_assign ( - f.lhs, build_cast (arg_type, - f.force_val (fold_build1 ( - ABSU_EXPR, unsigned_type_for (arg_type), arg)))); + f.lhs (), build_cast (arg_type, f.force_val (fold_build1 ( + ABSU_EXPR, + unsigned_type_for (arg_type), arg)))); auto ret = fold_build1 (ABS_EXPR, arg_type, arg); return this->maybe_optimization_barrier (f, ret); @@ -1346,7 +1338,7 @@ struct multiply_accumulate : public gimple_function_base tree lhs = gimple_call_arg (f.call, 1); tree rhs = gimple_call_arg (f.call, 2); tree lane_index; - tree ret_type = TREE_TYPE (f.lhs); + tree ret_type = f.ret_type; switch (kind) { @@ -1386,12 +1378,12 @@ struct multiply_accumulate : public gimple_function_base acc = f.force_val (build_cast (unsigned_type, acc)); auto mul = f.force_val (fold_build2 (MULT_EXPR, unsigned_type, lhs, rhs)); auto addsub = f.force_val (fold_build2 (code, unsigned_type, acc, mul)); - return gimple_build_assign (f.lhs, build_cast (signed_type, addsub)); + return gimple_build_assign (f.lhs (), build_cast (signed_type, addsub)); } else { auto mul = f.force_val (fold_build2 (MULT_EXPR, ret_type, lhs, rhs)); - return gimple_build_assign (f.lhs, code, acc, mul); + return gimple_build_assign (f.lhs (), code, acc, mul); } } }; @@ -1407,7 +1399,7 @@ struct gimple_fused_mla : public gimple_function_base tree lhs = gimple_call_arg (f.call, 1); tree rhs = gimple_call_arg (f.call, 2); tree lane_index; - tree ret_type = TREE_TYPE (f.lhs); + tree ret_type = f.ret_type; switch (kind) { @@ -1470,10 +1462,11 @@ struct gimple_minmax : public gimple_function_base { auto lhs = gimple_call_arg (f.call, 0); auto rhs = gimple_call_arg (f.call, 1); - auto ret_type = TREE_TYPE (f.lhs); + auto ret_type = f.ret_type; if (FLOAT_TYPE_P (ret_type)) return nullptr; - return gimple_build_assign (f.lhs, min_p ? MIN_EXPR : MAX_EXPR, lhs, rhs); + return gimple_build_assign (f.lhs (), min_p ? MIN_EXPR : MAX_EXPR, lhs, + rhs); } }; @@ -1493,14 +1486,15 @@ struct gimple_reduce_minmax : public gimple_function_base gimple *fold (gimple_folder &f) const override { auto arg = gimple_call_arg (f.call, 0); - auto ret_type = TREE_TYPE (f.lhs); + auto ret_type = f.ret_type; if (FLOAT_TYPE_P (ret_type)) return nullptr; auto_vec<tree> args{}; args.safe_push (arg); auto ifn = min_p ? IFN_REDUC_MIN : IFN_REDUC_MAX; - return gimple_build_assign (f.lhs, build_ifn_call (f, ifn, ret_type, args)); + return gimple_build_assign (f.lhs (), + build_ifn_call (f, ifn, ret_type, args)); } }; @@ -1527,14 +1521,15 @@ struct gimple_load_store_multiple : public gimple_function_base { auto ptr = gimple_call_arg (f.call, 0); auto mem_type - = load_p ? TREE_TYPE (f.lhs) : TREE_TYPE (gimple_call_arg (f.call, 1)); + = load_p ? f.ret_type : TREE_TYPE (gimple_call_arg (f.call, 1)); /* LD1x1 and LDR are just a normal load. */ if (load_p && !AGGREGATE_TYPE_P (mem_type)) { if (VECTOR_TYPE_P (mem_type)) aarch64_record_vector_load_arg (ptr); - return gimple_build_assign (f.lhs, aarch64_dereference (ptr, mem_type)); + return gimple_build_assign (f.lhs (), + aarch64_dereference (ptr, mem_type)); } /* ST1x1 and STR are just a normal store. */ @@ -1567,7 +1562,7 @@ public: gimple *fold (gimple_folder &f) const override { - auto type = TREE_TYPE (f.lhs); + auto type = f.ret_type; int first = first_shift_arg (); auto val = gimple_call_arg (f.call, first); auto amount = gimple_call_arg (f.call, first + 1); @@ -1578,7 +1573,7 @@ public: /* Non-accumulating intrinsic. */ if (m_acc_code == ERROR_MARK) - return gimple_build_assign (f.lhs, shifted); + return gimple_build_assign (f.lhs (), shifted); /* Accumulating intrinsic. */ auto acc = gimple_call_arg (f.call, 0); @@ -1595,8 +1590,8 @@ public: } return gimple_build_assign ( - f.lhs, build_cast (type, f.force_val (fold_build2 (m_acc_code, utype, acc, - shifted)))); + f.lhs (), build_cast (type, f.force_val (fold_build2 (m_acc_code, utype, + acc, shifted)))); } }; @@ -1623,13 +1618,13 @@ public: return nullptr; if (!wi::neg_p (wcst)) - return gimple_build_assign (f.lhs, LSHIFT_EXPR, val, amount); + return gimple_build_assign (f.lhs (), LSHIFT_EXPR, val, amount); /* A negative amount shifts right by its magnitude. */ auto rhs = build_uniform_cst (TREE_TYPE (amount), wide_int_to_tree (TREE_TYPE (cst), wi::abs (wcst))); - return gimple_build_assign (f.lhs, RSHIFT_EXPR, val, rhs); + return gimple_build_assign (f.lhs (), RSHIFT_EXPR, val, rhs); } }; @@ -1670,7 +1665,8 @@ struct gimple_load_store_interleaved : public gimple_function_base gimple *fold (gimple_folder &f) const override { auto ptr = gimple_call_arg (f.call, 0); - auto tuple_type = load_p ? TREE_TYPE (f.lhs) : TREE_TYPE (gimple_call_arg (f.call, 1)); + auto tuple_type + = load_p ? f.ret_type : TREE_TYPE (gimple_call_arg (f.call, 1)); auto array_type = TREE_TYPE (tuple_type_field (tuple_type)); auto vec_type = TREE_TYPE (array_type); @@ -1688,7 +1684,7 @@ struct gimple_load_store_interleaved : public gimple_function_base auto call = gimple_build_call_internal (IFN_LOAD_LANES, 1, deref); gimple_seq_add_stmt_without_update (&f.stmts,call); gimple_call_set_lhs (call, array); - return gimple_build_assign (f.lhs, build_cast (tuple_type, array)); + return gimple_build_assign (f.lhs (), build_cast (tuple_type, array)); } else { @@ -1738,7 +1734,7 @@ public: auto deref = aarch64_dereference (ptr, elem_type); if (load_p) /* tuple[lane] = *ptr; */ - return gimple_build_assign (f.lhs, + return gimple_build_assign (f.lhs (), build_lane_set (tuple, index, f.force_val (deref))); else @@ -1796,7 +1792,7 @@ struct gimple_load_dup : public gimple_function_base gimple *fold (gimple_folder &f) const override { auto ptr = gimple_call_arg (f.call, 0); - auto ret_type = TREE_TYPE (f.lhs); + auto ret_type = f.ret_type; auto elem_type = this->memory_scalar_type (f); auto vec_count = tuple_len (ret_type); @@ -1804,7 +1800,7 @@ struct gimple_load_dup : public gimple_function_base { /* lhs = dup (*ptr) */ auto load = f.force_val (aarch64_dereference (ptr, elem_type)); - return gimple_build_assign (f.lhs, build_vec_dup (ret_type, load)); + return gimple_build_assign (f.lhs (), build_vec_dup (ret_type, load)); } return nullptr; diff --git a/gcc/config/aarch64/aarch64-sve-builtins-base.cc b/gcc/config/aarch64/aarch64-sve-builtins-base.cc index 93443751b19f..81867d5e39b0 100644 --- a/gcc/config/aarch64/aarch64-sve-builtins-base.cc +++ b/gcc/config/aarch64/aarch64-sve-builtins-base.cc @@ -267,7 +267,7 @@ public: fold (gimple_folder &f) const override { if (is_pfalse (gimple_call_arg (f.call, 0))) - return f.fold_call_to (build_zero_cst (TREE_TYPE (f.lhs))); + return f.fold_call_to (build_zero_cst (f.ret_type)); return NULL; } }; @@ -304,7 +304,7 @@ public: fold (gimple_folder &f) const override { if (is_pfalse (gimple_call_arg (f.call, 0))) - return f.fold_call_to (build_all_ones_cst (TREE_TYPE (f.lhs))); + return f.fold_call_to (build_all_ones_cst (f.ret_type)); return NULL; } }; @@ -507,7 +507,7 @@ public: && f.type_suffix (0).integer_p) { rhs2 = f.force_vector (TREE_TYPE (rhs1), rhs2); - return gimple_build_assign (f.lhs, m_code, rhs1, rhs2); + return gimple_build_assign (f.lhs (), m_code, rhs1, rhs2); } if (is_pfalse (pg)) @@ -711,7 +711,7 @@ public: { tree pg = gimple_call_arg (f.call, 0); if (is_pfalse (pg)) - return f.fold_call_to (build_zero_cst (TREE_TYPE (f.lhs))); + return f.fold_call_to (build_zero_cst (f.ret_type)); return NULL; } @@ -738,7 +738,7 @@ public: fold (gimple_folder &f) const override { if (is_pfalse (gimple_call_arg (f.call, 0))) - return f.fold_call_to (build_zero_cst (TREE_TYPE (f.lhs))); + return f.fold_call_to (build_zero_cst (f.ret_type)); return NULL; } }; @@ -753,7 +753,7 @@ public: fold (gimple_folder &f) const override { unsigned int nargs = gimple_call_num_args (f.call); - tree lhs_type = TREE_TYPE (f.lhs); + tree lhs_type = f.ret_type; /* Replace the call with a clobber of the result (to prevent it from becoming upwards exposed) followed by stores into each individual @@ -762,14 +762,14 @@ public: The fold routines expect the replacement statement to have the same lhs as the original call, so return the clobber statement rather than the final vector store. */ - gassign *clobber = gimple_build_assign (f.lhs, build_clobber (lhs_type)); + gassign *clobber = gimple_build_assign (f.lhs (), build_clobber (lhs_type)); for (unsigned int i = nargs; i-- > 0; ) { tree rhs_vector = gimple_call_arg (f.call, i); - tree field = tuple_type_field (TREE_TYPE (f.lhs)); + tree field = tuple_type_field (f.ret_type); tree lhs_array = build3 (COMPONENT_REF, TREE_TYPE (field), - unshare_expr (f.lhs), field, NULL_TREE); + unshare_expr (f.lhs ()), field, NULL_TREE); tree lhs_vector = build4 (ARRAY_REF, TREE_TYPE (rhs_vector), lhs_array, size_int (i), NULL_TREE, NULL_TREE); @@ -905,7 +905,7 @@ public: /* If one of the operands is all zeros, fold to zero vector. */ if (integer_zerop (op1) || integer_zerop (op2)) - return f.fold_active_lanes_to (build_zero_cst (TREE_TYPE (f.lhs))); + return f.fold_active_lanes_to (build_zero_cst (f.ret_type)); /* If the divisor is all integer -1, fold to svneg. */ tree pg = gimple_call_arg (f.call, 0); @@ -1032,7 +1032,7 @@ public: gimple * fold (gimple_folder &f) const override { - tree vec_type = TREE_TYPE (f.lhs); + tree vec_type = f.ret_type; tree rhs = gimple_call_arg (f.call, f.pred == PRED_none ? 0 : 1); if (f.pred == PRED_none || f.pred == PRED_x) @@ -1045,14 +1045,14 @@ public: : f.fold_to_pfalse ()); tree rhs_vector = build_vector_from_val (vec_type, rhs); - return gimple_build_assign (f.lhs, rhs_vector); + return gimple_build_assign (f.lhs (), rhs_vector); } /* Avoid folding _b to a VEC_DUPLICATE_EXPR, since to do that we would need to introduce an extra and unwanted conversion to the truth vector element type. */ if (!f.type_suffix (0).bool_p) - return gimple_build_assign (f.lhs, VEC_DUPLICATE_EXPR, rhs); + return gimple_build_assign (f.lhs (), VEC_DUPLICATE_EXPR, rhs); } /* svdup_z (pg, x) == VEC_COND_EXPR <pg, VEC_DUPLICATE_EXPR <x>, 0>. */ @@ -1060,7 +1060,7 @@ public: { tree pred = f.convert_pred (vec_type, 0); rhs = f.force_vector (vec_type, rhs); - return gimple_build_assign (f.lhs, VEC_COND_EXPR, pred, rhs, + return gimple_build_assign (f.lhs (), VEC_COND_EXPR, pred, rhs, build_zero_cst (vec_type)); } @@ -1140,8 +1140,8 @@ private: || BYTES_BIG_ENDIAN) return NULL; - tree lhs = gimple_call_lhs (f.call); - tree lhs_type = TREE_TYPE (lhs); + tree lhs = f.lhs (); + tree lhs_type = f.ret_type; tree elt_type = TREE_TYPE (lhs_type); scalar_mode elt_mode = SCALAR_TYPE_MODE (elt_type); machine_mode vq_mode = aarch64_v128_mode (elt_mode).require (); @@ -1174,7 +1174,7 @@ public: gimple * fold (gimple_folder &f) const override { - tree vec_type = TREE_TYPE (f.lhs); + tree vec_type = f.ret_type; unsigned int nargs = gimple_call_num_args (f.call); /* For predicates, pad out each argument so that we have one element per bit. */ @@ -1190,7 +1190,7 @@ public: for (unsigned int j = 1; j < factor; ++j) builder.quick_push (build_zero_cst (TREE_TYPE (vec_type))); } - return gimple_build_assign (f.lhs, builder.build ()); + return gimple_build_assign (f.lhs (), builder.build ()); } rtx @@ -1308,7 +1308,7 @@ public: fold (gimple_folder &f) const override { if (is_pfalse (gimple_call_arg (f.call, 0))) - return f.fold_call_to (build_zero_cst (TREE_TYPE (f.lhs))); + return f.fold_call_to (build_zero_cst (f.ret_type)); return NULL; } }; @@ -1321,7 +1321,7 @@ public: fold (gimple_folder &f) const override { if (is_pfalse (gimple_call_arg (f.call, 0))) - return f.fold_call_to (build_zero_cst (TREE_TYPE (f.lhs))); + return f.fold_call_to (build_zero_cst (f.ret_type)); return NULL; } }; @@ -1346,10 +1346,10 @@ public: return NULL; tree op = gimple_call_arg (f.call, 2); - tree mask = build_int_cstu (TREE_TYPE (TREE_TYPE (f.lhs)), - GET_MODE_MASK (m_from_mode)); - tree mask_vec = build_vector_from_val (TREE_TYPE (f.lhs), mask); - return gimple_build_assign (f.lhs, BIT_AND_EXPR, op, mask_vec); + tree mask + = build_int_cstu (TREE_TYPE (f.ret_type), GET_MODE_MASK (m_from_mode)); + tree mask_vec = build_vector_from_val (f.ret_type, mask); + return gimple_build_assign (f.lhs (), BIT_AND_EXPR, op, mask_vec); } rtx @@ -1402,9 +1402,9 @@ public: tree field = tuple_type_field (TREE_TYPE (rhs_tuple)); tree rhs_array = build3 (COMPONENT_REF, TREE_TYPE (field), rhs_tuple, field, NULL_TREE); - tree rhs_vector = build4 (ARRAY_REF, TREE_TYPE (f.lhs), - rhs_array, index, NULL_TREE, NULL_TREE); - return gimple_build_assign (f.lhs, rhs_vector); + tree rhs_vector + = build4 (ARRAY_REF, f.ret_type, rhs_array, index, NULL_TREE, NULL_TREE); + return gimple_build_assign (f.lhs (), rhs_vector); } rtx @@ -1425,9 +1425,9 @@ public: if (BYTES_BIG_ENDIAN) return NULL; tree rhs_sve_vector = gimple_call_arg (f.call, 0); - tree rhs_vector = build3 (BIT_FIELD_REF, TREE_TYPE (f.lhs), - rhs_sve_vector, bitsize_int (128), bitsize_int (0)); - return gimple_build_assign (f.lhs, rhs_vector); + tree rhs_vector = build3 (BIT_FIELD_REF, f.ret_type, rhs_sve_vector, + bitsize_int (128), bitsize_int (0)); + return gimple_build_assign (f.lhs (), rhs_vector); } rtx @@ -1493,15 +1493,13 @@ public: tree rhs_vector = gimple_call_arg (f.call, 0); unsigned HOST_WIDE_INT neon_nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (rhs_vector)).to_constant (); - poly_uint64 sve_nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (f.lhs)); + poly_uint64 sve_nelts = TYPE_VECTOR_SUBPARTS (f.ret_type); vec_perm_builder builder (sve_nelts, neon_nelts, 1); for (unsigned int i = 0; i < neon_nelts; i++) builder.quick_push (i); vec_perm_indices indices (builder, 1, neon_nelts); tree perm_type = build_vector_type (ssizetype, sve_nelts); - return gimple_build_assign (f.lhs, VEC_PERM_EXPR, - rhs_vector, - rhs_vector, + return gimple_build_assign (f.lhs (), VEC_PERM_EXPR, rhs_vector, rhs_vector, vec_perm_indices_to_tree (perm_type, indices)); } @@ -1535,12 +1533,12 @@ public: fold (gimple_folder &f) const override { /* Apply constant folding if base and step are integer constants. */ - tree vec_type = TREE_TYPE (f.lhs); + tree vec_type = f.ret_type; tree base = gimple_call_arg (f.call, 0); tree step = gimple_call_arg (f.call, 1); if (TREE_CODE (base) != INTEGER_CST || TREE_CODE (step) != INTEGER_CST) return NULL; - return gimple_build_assign (f.lhs, + return gimple_build_assign (f.lhs (), build_vec_series (vec_type, base, step)); } @@ -1561,7 +1559,7 @@ public: gcall *new_call = gimple_build_call_internal (IFN_VEC_SHL_INSERT, 2, gimple_call_arg (f.call, 0), gimple_call_arg (f.call, 1)); - gimple_call_set_lhs (new_call, f.lhs); + gimple_call_set_lhs (new_call, f.lhs ()); return new_call; } @@ -1610,9 +1608,9 @@ public: 2. LASTA if predicate all false, return element 0. */ if (is_lasta () && vector_cst_all_same (pred, step_1)) { - b = build3 (BIT_FIELD_REF, TREE_TYPE (f.lhs), val, + b = build3 (BIT_FIELD_REF, f.ret_type, val, bitsize_int (step * BITS_PER_UNIT), bitsize_int (0)); - return gimple_build_assign (f.lhs, b); + return gimple_build_assign (f.lhs (), b); } /* Handle the all-false case for LASTB where SVE VL == 128b - @@ -1621,11 +1619,11 @@ public: && vector_cst_all_same (pred, step_1) && integer_zerop (VECTOR_CST_ENCODED_ELT (pred, 0))) { - b = build3 (BIT_FIELD_REF, TREE_TYPE (f.lhs), val, + b = build3 (BIT_FIELD_REF, f.ret_type, val, bitsize_int (step * BITS_PER_UNIT), bitsize_int ((16 - step) * BITS_PER_UNIT)); - return gimple_build_assign (f.lhs, b); + return gimple_build_assign (f.lhs (), b); } /* Determine if there are any repeating non-zero elements in variable @@ -1692,11 +1690,11 @@ public: if (pos < 0 || pos > 15) return NULL; - b = build3 (BIT_FIELD_REF, TREE_TYPE (f.lhs), val, + b = build3 (BIT_FIELD_REF, f.ret_type, val, bitsize_int (step * BITS_PER_UNIT), bitsize_int (pos * BITS_PER_UNIT)); - return gimple_build_assign (f.lhs, b); + return gimple_build_assign (f.lhs (), b); } return NULL; } @@ -1854,8 +1852,8 @@ public: && integer_all_onesp (arg0) && !flag_non_call_exceptions) { - tree lhs = gimple_call_lhs (f.call); - tree lhs_type = TREE_TYPE (lhs); + tree lhs = f.lhs (); + tree lhs_type = f.ret_type; poly_uint64 lhs_len = TYPE_VECTOR_SUBPARTS (lhs_type); tree eltype = TREE_TYPE (lhs_type); @@ -1938,7 +1936,7 @@ public: gimple * fold (gimple_folder &f) const override { - tree tuple_type = TREE_TYPE (f.lhs); + tree tuple_type = f.ret_type; tree vectype = f.vector_type (0); /* Get the predicate and base pointer. */ @@ -1952,12 +1950,13 @@ public: The fold routines expect the replacement statement to have the same lhs as the original call, so return the clobber statement rather than the load. */ - gimple *clobber = gimple_build_assign (f.lhs, build_clobber (tuple_type)); + gimple *clobber + = gimple_build_assign (f.lhs (), build_clobber (tuple_type)); /* View the loaded data as an array of vectors. */ tree field = tuple_type_field (tuple_type); - tree lhs_array = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (field), - unshare_expr (f.lhs)); + tree lhs_array + = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (field), unshare_expr (f.lhs ())); /* Emit the load itself. */ tree cookie = f.load_store_cookie (TREE_TYPE (vectype)); @@ -2119,9 +2118,8 @@ public: { /* The argument only exists for its type. */ tree rhs_type = TREE_TYPE (gimple_call_arg (f.call, 0)); - tree count = build_int_cstu (TREE_TYPE (f.lhs), - TYPE_VECTOR_SUBPARTS (rhs_type)); - return gimple_build_assign (f.lhs, count); + tree count = build_int_cstu (f.ret_type, TYPE_VECTOR_SUBPARTS (rhs_type)); + return gimple_build_assign (f.lhs (), count); } rtx @@ -2167,8 +2165,8 @@ public: if (is_pfalse (gimple_call_arg (f.call, 0))) { tree rhs = f.type_suffix (0).integer_p - ? TYPE_MAX_VALUE (TREE_TYPE (f.lhs)) - : build_real (TREE_TYPE (f.lhs), dconstinf); + ? TYPE_MAX_VALUE (f.ret_type) + : build_real (f.ret_type, dconstinf); return f.fold_call_to (rhs); } return NULL; @@ -2186,7 +2184,7 @@ public: { REAL_VALUE_TYPE rnan = dconst0; rnan.cl = rvc_nan; - return f.fold_call_to (build_real (TREE_TYPE (f.lhs), rnan)); + return f.fold_call_to (build_real (f.ret_type, rnan)); } return NULL; } @@ -2204,8 +2202,8 @@ public: if (is_pfalse (gimple_call_arg (f.call, 0))) { tree rhs = f.type_suffix (0).integer_p - ? TYPE_MIN_VALUE (TREE_TYPE (f.lhs)) - : build_real (TREE_TYPE (f.lhs), dconstninf); + ? TYPE_MIN_VALUE (f.ret_type) + : build_real (f.ret_type, dconstninf); return f.fold_call_to (rhs); } return NULL; @@ -2223,7 +2221,7 @@ public: { REAL_VALUE_TYPE rnan = dconst0; rnan.cl = rvc_nan; - return f.fold_call_to (build_real (TREE_TYPE (f.lhs), rnan)); + return f.fold_call_to (build_real (f.ret_type, rnan)); } return NULL; } @@ -2276,7 +2274,7 @@ public: gimple * fold (gimple_folder &f) const override { - return gimple_build_assign (f.lhs, BIT_AND_EXPR, + return gimple_build_assign (f.lhs (), BIT_AND_EXPR, gimple_call_arg (f.call, 0), gimple_call_arg (f.call, 1)); } @@ -2371,7 +2369,7 @@ public: /* If one of the operands is all zeros, fold to zero vector. */ if (integer_zerop (op1) || integer_zerop (op2)) - return f.fold_active_lanes_to (build_zero_cst (TREE_TYPE (f.lhs))); + return f.fold_active_lanes_to (build_zero_cst (f.ret_type)); /* If one of the operands is all integer -1, fold to svneg. */ if (integer_minus_onep (op1) || integer_minus_onep (op2)) @@ -2515,7 +2513,7 @@ public: fold (gimple_folder &f) const override { if (is_pfalse (gimple_call_arg (f.call, 0))) - return f.fold_call_to (build_zero_cst (TREE_TYPE (f.lhs))); + return f.fold_call_to (build_zero_cst (f.ret_type)); return NULL; } }; @@ -2898,9 +2896,9 @@ public: /* Otherwise svreinterpret corresponds directly to a VIEW_CONVERT_EXPR reinterpretation. */ - tree rhs = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (f.lhs), - gimple_call_arg (f.call, 0)); - return gimple_build_assign (f.lhs, VIEW_CONVERT_EXPR, rhs); + tree rhs + = build1 (VIEW_CONVERT_EXPR, f.ret_type, gimple_call_arg (f.call, 0)); + return gimple_build_assign (f.lhs (), VIEW_CONVERT_EXPR, rhs); } rtx @@ -2926,7 +2924,7 @@ public: return NULL; /* Permute as { nelts - 1, nelts - 2, nelts - 3, ... }. */ - poly_int64 nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (f.lhs)); + poly_int64 nelts = TYPE_VECTOR_SUBPARTS (f.ret_type); vec_perm_builder builder (nelts, 1, 3); for (int i = 0; i < 3; ++i) builder.quick_push (nelts - i - 1); @@ -2976,7 +2974,7 @@ public: /* svsel corresponds exactly to VEC_COND_EXPR. */ tree pred = f.convert_pred (f.vector_type (0), 0); - return gimple_build_assign (f.lhs, VEC_COND_EXPR, pred, + return gimple_build_assign (f.lhs (), VEC_COND_EXPR, pred, gimple_call_arg (f.call, 1), gimple_call_arg (f.call, 2)); } @@ -3014,12 +3012,12 @@ public: The fold routines expect the replacement statement to have the same lhs as the original call, so return the copy statement rather than the field update. */ - gassign *copy = gimple_build_assign (f.lhs, rhs_tuple); + gassign *copy = gimple_build_assign (f.lhs (), rhs_tuple); /* Get a reference to the individual vector. */ - tree field = tuple_type_field (TREE_TYPE (f.lhs)); + tree field = tuple_type_field (f.ret_type); tree lhs_array = build3 (COMPONENT_REF, TREE_TYPE (field), - unshare_expr (f.lhs), field, NULL_TREE); + unshare_expr (f.lhs ()), field, NULL_TREE); tree lhs_vector = build4 (ARRAY_REF, TREE_TYPE (rhs_vector), lhs_array, index, NULL_TREE, NULL_TREE); gassign *update = gimple_build_assign (lhs_vector, rhs_vector); @@ -3266,7 +3264,7 @@ public: { /* svtrn1: { 0, nelts, 2, nelts + 2, 4, nelts + 4, ... } svtrn2: as for svtrn1, but with 1 added to each index. */ - poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (f.lhs)); + poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (f.ret_type); vec_perm_builder builder (nelts, 2, 3); for (unsigned int i = 0; i < 3; ++i) { @@ -3313,7 +3311,7 @@ public: and VEC_UNPACK_HI_EXPR for big-endian. */ bool high_p = BYTES_BIG_ENDIAN ? !m_high_p : m_high_p; tree_code code = high_p ? VEC_UNPACK_HI_EXPR : VEC_UNPACK_LO_EXPR; - return gimple_build_assign (f.lhs, code, gimple_call_arg (f.call, 0)); + return gimple_build_assign (f.lhs (), code, gimple_call_arg (f.call, 0)); } rtx @@ -3377,7 +3375,7 @@ public: { /* svuzp1: { 0, 2, 4, 6, ... } svuzp2: { 1, 3, 5, 7, ... }. */ - poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (f.lhs)); + poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (f.ret_type); vec_perm_builder builder (nelts, 1, 3); for (unsigned int i = 0; i < 3; ++i) builder.quick_push (m_base + i * 2); @@ -3503,7 +3501,7 @@ public: { /* svzip1: { 0, nelts, 1, nelts + 1, 2, nelts + 2, ... } svzip2: as for svzip1, but with nelts / 2 added to each index. */ - poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (f.lhs)); + poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (f.ret_type); poly_uint64 base = m_base * exact_div (nelts, 2); vec_perm_builder builder (nelts, 2, 3); for (unsigned int i = 0; i < 3; ++i) diff --git a/gcc/config/aarch64/aarch64-sve-builtins-functions.h b/gcc/config/aarch64/aarch64-sve-builtins-functions.h index 9fe8e5dcccec..fc968bccc867 100644 --- a/gcc/config/aarch64/aarch64-sve-builtins-functions.h +++ b/gcc/config/aarch64/aarch64-sve-builtins-functions.h @@ -688,10 +688,10 @@ public: return NULL; unsigned int nargs = gimple_call_num_args (f.call); - poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (f.lhs)); + poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (f.ret_type); vec_perm_indices indices (builder, nargs, nelts); tree perm_type = build_vector_type (ssizetype, nelts); - return gimple_build_assign (f.lhs, VEC_PERM_EXPR, + return gimple_build_assign (f.lhs (), VEC_PERM_EXPR, gimple_call_arg (f.call, 0), gimple_call_arg (f.call, nargs == 1 ? 0 : 1), vec_perm_indices_to_tree (perm_type, indices)); @@ -942,7 +942,7 @@ public: fold (gimple_folder &f) const override { if (f.pred == PRED_x && is_pfalse (gimple_call_arg (f.call, 1))) - return f.fold_call_to (build_zero_cst (TREE_TYPE (f.lhs))); + return f.fold_call_to (build_zero_cst (f.ret_type)); return NULL; } diff --git a/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc b/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc index 5b9e6161fc1f..8b368743be2b 100644 --- a/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc +++ b/gcc/config/aarch64/aarch64-sve-builtins-sve2.cc @@ -339,7 +339,7 @@ public: gcc_assert (TYPE_MODE (TREE_TYPE (pg)) == TYPE_MODE (TREE_TYPE (pn))); if (is_pfalse (pg) || is_pfalse (pn)) - return f.fold_call_to (build_minus_one_cst (TREE_TYPE (f.lhs))); + return f.fold_call_to (build_minus_one_cst (f.ret_type)); if (TREE_CODE (pg) != VECTOR_CST || TREE_CODE (pn) != VECTOR_CST) @@ -359,14 +359,13 @@ public: { unsigned int idx = m_first ? i : nelts - 1 - i; if (tree_to_shwi (VECTOR_CST_ENCODED_ELT (pa, idx)) != 0) - return f.fold_call_to (build_int_cst (TREE_TYPE (f.lhs), - m_first - ? i / elt_size - : (nelts_full_vector - 1 - - i / elt_size))); + return f.fold_call_to ( + build_int_cst (f.ret_type, + m_first ? i / elt_size + : (nelts_full_vector - 1 - i / elt_size))); } - return f.fold_call_to (build_minus_one_cst (TREE_TYPE (f.lhs))); + return f.fold_call_to (build_minus_one_cst (f.ret_type)); } rtx diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr127771.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr127771.c new file mode 100644 index 000000000000..f8cb79a5f472 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr127771.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O1" } */ + +#include <arm_sve.h> + +/* PR target/127771. */ + +void +g (svbool_t p, svuint32_t a) +{ + svmul_x (p, a, svdup_u32 (1)); +} + +/* The placeholder for a discarded result cannot be an SSA name when the + return type is an aggregate. */ + +void +h (svuint32_t a, svuint32_t b) +{ + svcreate2_u32 (a, b); +}
