On 17/11/26 17:01, Kyrylo Tkachov wrote:


On 16 Nov 2026, at 10:28, Dhruv Chawla <[email protected]> wrote:

From: Dhruv Chawla <[email protected]>

Now that f.ret_type is its own member and no longer has to be derived
from TREE_TYPE (lhs), usage sites that make local variables to store the value
of that expression can be simplified to refer to the member variable
directly.

Bootstrapped and regtested on aarch64-linux-gnu.


Ok.
Thanks,
Kyrill

Thanks Kyrill, committed as:
- r17-6344-gcf7bfcf51fcfaf
- r17-6345-ge9e93f88ac49bf

--
Regards,
Dhruv


Signed-off-by: Dhruv Chawla <[email protected]>

gcc/ChangeLog:

* config/aarch64/aarch64-acle-builtins.cc
(gimple_folder::convert_and_fold): Use ret_type directly instead of
copying it into a local.
* config/aarch64/aarch64-neon-builtins-base.cc (gimple_combine::fold)
(gimple_dup::fold, gimple_dup_lane::fold, gimple_bsl::fold)
(gimple_eor3::fold, gimple_xar::fold, gimple_ifn::fold)
(gimple_permute_pair::fold, gimple_reinterpret::fold)
(multiply_accumulate::fold, gimple_fused_mla::fold)
(gimple_minmax::fold, gimple_reduce_minmax::fold)
(gimple_shift_imm::fold): Likewise.
* config/aarch64/aarch64-sve-builtins-base.cc (svcreate_impl::fold)
(svdup_impl::fold, svdupq_impl::fold_nonconst_dupq)
(svdupq_impl::fold, svindex_impl::fold, svld1rq_impl::fold)
(svld234_impl::fold): Likewise.
---
gcc/config/aarch64/aarch64-acle-builtins.cc   |  5 +-
.../aarch64/aarch64-neon-builtins-base.cc     | 76 ++++++++-----------
.../aarch64/aarch64-sve-builtins-base.cc      | 42 +++++-----
3 files changed, 51 insertions(+), 72 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-acle-builtins.cc 
b/gcc/config/aarch64/aarch64-acle-builtins.cc
index da63366ace0..692b1c818b3 100644
--- a/gcc/config/aarch64/aarch64-acle-builtins.cc
+++ b/gcc/config/aarch64/aarch64-acle-builtins.cc
@@ -3010,8 +3010,7 @@ gimple_folder::convert_and_fold (tree type,
{
   gcc_assert (VECTOR_TYPE_P (type)
      && TYPE_MODE (type) != VNx16BImode);
-  tree old_ty = ret_type;
-  bool convert_lhs_p = !useless_type_conversion_p (type, old_ty);
+  bool convert_lhs_p = !useless_type_conversion_p (type, ret_type);
   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;
@@ -3030,7 +3029,7 @@ gimple_folder::convert_and_fold (tree type,
   gimple *new_stmt = fp (*this, lhs_conv, args_conv);
   if (convert_lhs_p)
     {
-      tree t = build1 (VIEW_CONVERT_EXPR, old_ty, lhs_conv);
+      tree t = build1 (VIEW_CONVERT_EXPR, ret_type, lhs_conv);
       gimple *g = gimple_build_assign (lhs (), VIEW_CONVERT_EXPR, t);
       gsi_insert_after (gsi, g, GSI_SAME_STMT);
     }
diff --git a/gcc/config/aarch64/aarch64-neon-builtins-base.cc 
b/gcc/config/aarch64/aarch64-neon-builtins-base.cc
index 9ac6347493e..95568731615 100644
--- a/gcc/config/aarch64/aarch64-neon-builtins-base.cc
+++ b/gcc/config/aarch64/aarch64-neon-builtins-base.cc
@@ -550,7 +550,6 @@ 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 = f.ret_type;

     if (known_eq (TYPE_VECTOR_SUBPARTS (arg_type), 1U))
       {
@@ -562,7 +561,7 @@ struct gimple_combine : public gimple_function_base
       std::swap (arg1, arg2);

     return gimple_build_assign (f.lhs (),
- build_constructor_va (ret_type, 2, NULL_TREE,
+ build_constructor_va (f.ret_type, 2, NULL_TREE,
      arg1, NULL_TREE, arg2));
   }
};
@@ -624,8 +623,7 @@ 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 = f.ret_type;
-    return gimple_build_assign (f.lhs (), build_vec_dup (ret_type, elem));
+    return gimple_build_assign (f.lhs (), build_vec_dup (f.ret_type, elem));
   }
};

@@ -635,13 +633,12 @@ 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 = 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 (f.ret_type, tmp1));
   }
};

@@ -679,7 +676,6 @@ public:
     auto m = gimple_call_arg (f.call, 2);

     auto uint_type = TREE_TYPE (d);
-    auto ret_type = f.ret_type;

     // Cast to unsigned integer type if necessary.
     m = f.force_val (build_cast (uint_type, m));
@@ -694,7 +690,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 (f.ret_type, tmp3));
   }
};

@@ -713,10 +709,9 @@ 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 = f.ret_type;

     // tmp1 = n ^ m
-    auto tmp1 = f.force_val (fold_build2 (BIT_XOR_EXPR, type, n, m));
+    auto tmp1 = f.force_val (fold_build2 (BIT_XOR_EXPR, f.ret_type, n, m));

     // lhs = (n ^ m) ^ a
     return gimple_build_assign (f.lhs (), BIT_XOR_EXPR, tmp1, a);
@@ -797,10 +792,9 @@ 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 = f.ret_type;

     // tmp1 = n ^ m
-    auto tmp1 = f.force_val (fold_build2 (BIT_XOR_EXPR, type, n, m));
+    auto tmp1 = f.force_val (fold_build2 (BIT_XOR_EXPR, f.ret_type, n, m));

     // lhs = rotr (n ^ m, imm6)
     return gimple_build_assign (f.lhs (), RROTATE_EXPR, tmp1, imm6);
@@ -825,7 +819,6 @@ public:

   gimple *fold (gimple_folder &f) const override
   {
-    tree lhs_type = f.ret_type;
     auto_vec<tree> args{};
     for (unsigned i = 0; i < gimple_call_num_args (f.call); i++)
       {
@@ -838,7 +831,7 @@ public:
args.safe_push (arg);
       }
     return gimple_build_assign (f.lhs (), build_ifn_call (f, this->m_ifn,
-  lhs_type, args));
+  f.ret_type, args));
   }
};

@@ -891,9 +884,8 @@ public:
     auto arg_type = TREE_TYPE (a);
     gcc_assert (types_compatible_p (arg_type, TREE_TYPE (b)));

-    auto tuple_type = f.ret_type;
-    auto tuple = build_var (tuple_type);
-    f.assign (tuple, build_clobber (tuple_type));
+    auto tuple = build_var (f.ret_type);
+    f.assign (tuple, build_clobber (f.ret_type));
     for (auto i = 0; i < 2; i++)
       {
auto mask = i == 0 ? this->m_mask_fn_1 (f) : this->m_mask_fn_2 (f);
@@ -1224,8 +1216,7 @@ 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 = f.ret_type;
-    auto reinterpret = fold_build1 (VIEW_CONVERT_EXPR, ret_type, input);
+    auto reinterpret = fold_build1 (VIEW_CONVERT_EXPR, f.ret_type, input);
     return gimple_build_assign (f.lhs (), reinterpret);
   }
};
@@ -1306,7 +1297,6 @@ 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 = f.ret_type;

     switch (kind)
       {
@@ -1320,26 +1310,26 @@ struct multiply_accumulate : public gimple_function_base
       case arith_kind::lane:
lane_index = gimple_call_arg (f.call, 3);
rhs = f.force_val (build_lane_get (rhs, lane_index));
- if (VECTOR_TYPE_P (ret_type))
+ if (VECTOR_TYPE_P (f.ret_type))
  rhs = f.force_val (build_vec_dup (TREE_TYPE (lhs), rhs));
break;
       }

     tree_code code = negate ? MINUS_EXPR : PLUS_EXPR;
-    if (FLOAT_TYPE_P (ret_type))
+    if (FLOAT_TYPE_P (f.ret_type))
       {
/* Use a PAREN_EXPR (equivalent to C's `__builtin_assoc_barrier`) to
   prevent floating-point add and mul being transformed to an FMA.  */
- auto mul = f.force_val (fold_build2 (MULT_EXPR, ret_type, lhs, rhs));
- auto paren = f.force_val (fold_build1 (PAREN_EXPR, ret_type, mul));
- auto addsub = f.force_val (fold_build2 (code, ret_type, acc, paren));
+ auto mul = f.force_val (fold_build2 (MULT_EXPR, f.ret_type, lhs, rhs));
+ auto paren = f.force_val (fold_build1 (PAREN_EXPR, f.ret_type, mul));
+ auto addsub = f.force_val (fold_build2 (code, f.ret_type, acc, paren));
return this->maybe_optimization_barrier (f, addsub);
       }
-    else if (!TYPE_UNSIGNED (ret_type))
+    else if (!TYPE_UNSIGNED (f.ret_type))
       {
/* Convert signed inputs to unsigned first, to avoid undefined behaviour
   on overflow.  */
- auto signed_type = ret_type;
+ auto signed_type = f.ret_type;
auto unsigned_type = unsigned_type_for (signed_type);
lhs = f.force_val (build_cast (unsigned_type, lhs));
rhs = f.force_val (build_cast (unsigned_type, rhs));
@@ -1350,7 +1340,7 @@ struct multiply_accumulate : public gimple_function_base
       }
     else
       {
- auto mul = f.force_val (fold_build2 (MULT_EXPR, ret_type, lhs, rhs));
+ auto mul = f.force_val (fold_build2 (MULT_EXPR, f.ret_type, lhs, rhs));
return gimple_build_assign (f.lhs (), code, acc, mul);
       }
   }
@@ -1367,7 +1357,6 @@ 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 = f.ret_type;

     switch (kind)
       {
@@ -1381,7 +1370,7 @@ struct gimple_fused_mla : public gimple_function_base
       case arith_kind::lane:
lane_index = gimple_call_arg (f.call, 3);
rhs = f.force_val (build_lane_get (rhs, lane_index));
- if (VECTOR_TYPE_P (ret_type))
+ if (VECTOR_TYPE_P (f.ret_type))
  rhs = f.force_val (build_vec_dup (TREE_TYPE (lhs), rhs));
break;
       }
@@ -1390,7 +1379,8 @@ struct gimple_fused_mla : public gimple_function_base
     args.safe_push (lhs);
     args.safe_push (rhs);
     args.safe_push (acc);
-    auto ret = build_ifn_call (f, negate ? IFN_FNMA : IFN_FMA, ret_type, args);
+    auto ret
+      = build_ifn_call (f, negate ? IFN_FNMA : IFN_FMA, f.ret_type, args);
     return this->maybe_optimization_barrier (f, ret);
   }
};
@@ -1427,8 +1417,7 @@ 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 = f.ret_type;
-    if (FLOAT_TYPE_P (ret_type))
+    if (FLOAT_TYPE_P (f.ret_type))
       return nullptr;
     return gimple_build_assign (f.lhs (), min_p ? MIN_EXPR : MAX_EXPR, lhs,
rhs);
@@ -1450,15 +1439,14 @@ 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 = f.ret_type;
-    if (FLOAT_TYPE_P (ret_type))
+    if (FLOAT_TYPE_P (f.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));
+ build_ifn_call (f, ifn, f.ret_type, args));
   }
};

@@ -1481,14 +1469,13 @@ public:

   gimple *fold (gimple_folder &f) const override
   {
-    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);

     auto shifted = m_code == LSHIFT_EXPR
-     ? fold_build2 (LSHIFT_EXPR, type, val, amount)
-     : build_shift_right (type, val, amount);
+     ? fold_build2 (LSHIFT_EXPR, f.ret_type, val, amount)
+     : build_shift_right (f.ret_type, val, amount);

     /* Non-accumulating intrinsic.  */
     if (m_acc_code == ERROR_MARK)
@@ -1500,17 +1487,16 @@ public:

     /* Accumulate in an unsigned type so that signed overflow wraps as the
        ACLE requires.  */
-    auto utype = type;
-    if (!TYPE_UNSIGNED (type))
+    auto utype = f.ret_type;
+    if (!TYPE_UNSIGNED (f.ret_type))
       {
- utype = unsigned_type_for (type);
+ utype = unsigned_type_for (f.ret_type);
acc = f.force_val (build_cast (utype, acc));
shifted = f.force_val (build_cast (utype, shifted));
       }

-    return gimple_build_assign (
-      f.lhs (), build_cast (type, f.force_val (fold_build2 (m_acc_code, utype,
-    acc, shifted))));
+    auto acc_expr = f.force_val (fold_build2 (m_acc_code, utype, acc, 
shifted));
+    return gimple_build_assign (f.lhs (), build_cast (f.ret_type, acc_expr));
   }
};

diff --git a/gcc/config/aarch64/aarch64-sve-builtins-base.cc 
b/gcc/config/aarch64/aarch64-sve-builtins-base.cc
index 81867d5e39b..be32cbd56f1 100644
--- a/gcc/config/aarch64/aarch64-sve-builtins-base.cc
+++ b/gcc/config/aarch64/aarch64-sve-builtins-base.cc
@@ -753,7 +753,6 @@ public:
   fold (gimple_folder &f) const override
   {
     unsigned int nargs = gimple_call_num_args (f.call);
-    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,7 +761,8 @@ 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 (f.ret_type));

     for (unsigned int i = nargs; i-- > 0; )
       {
@@ -1032,7 +1032,6 @@ public:
   gimple *
   fold (gimple_folder &f) const override
   {
-    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)
@@ -1044,7 +1043,7 @@ public:
      ? f.fold_to_ptrue ()
      : f.fold_to_pfalse ());

-    tree rhs_vector = build_vector_from_val (vec_type, rhs);
+    tree rhs_vector = build_vector_from_val (f.ret_type, rhs);
    return gimple_build_assign (f.lhs (), rhs_vector);
  }

@@ -1058,10 +1057,10 @@ public:
     /* svdup_z (pg, x) == VEC_COND_EXPR <pg, VEC_DUPLICATE_EXPR <x>, 0>.  */
     if (f.pred == PRED_z)
       {
- tree pred = f.convert_pred (vec_type, 0);
- rhs = f.force_vector (vec_type, rhs);
+ tree pred = f.convert_pred (f.ret_type, 0);
+ rhs = f.force_vector (f.ret_type, rhs);
return gimple_build_assign (f.lhs (), VEC_COND_EXPR, pred, rhs,
-    build_zero_cst (vec_type));
+    build_zero_cst (f.ret_type));
       }

     return NULL;
@@ -1141,8 +1140,7 @@ private:
       return NULL;

     tree lhs = f.lhs ();
-    tree lhs_type = f.ret_type;
-    tree elt_type = TREE_TYPE (lhs_type);
+    tree elt_type = TREE_TYPE (f.ret_type);
     scalar_mode elt_mode = SCALAR_TYPE_MODE (elt_type);
     machine_mode vq_mode = aarch64_v128_mode (elt_mode).require ();
     tree vq_type = build_vector_type_for_mode (elt_type, vq_mode);
@@ -1158,7 +1156,7 @@ private:

     gimple_seq_add_stmt_without_update (&f.stmts, g);

-    poly_uint64 lhs_len = TYPE_VECTOR_SUBPARTS (lhs_type);
+    poly_uint64 lhs_len = TYPE_VECTOR_SUBPARTS (f.ret_type);
     vec_perm_builder sel (lhs_len, nargs, 1);
     for (unsigned i = 0; i < nargs; i++)
       sel.quick_push (i);
@@ -1174,13 +1172,12 @@ public:
   gimple *
   fold (gimple_folder &f) const override
   {
-    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.  */
     unsigned int factor = (f.type_suffix (0).bool_p
   ? f.type_suffix (0).element_bytes : 1);
-    tree_vector_builder builder (vec_type, nargs * factor, 1);
+    tree_vector_builder builder (f.ret_type, nargs * factor, 1);
     for (unsigned int i = 0; i < nargs; ++i)
       {
tree elt = gimple_call_arg (f.call, i);
@@ -1188,7 +1185,7 @@ public:
  return fold_nonconst_dupq (f);
builder.quick_push (elt);
for (unsigned int j = 1; j < factor; ++j)
-  builder.quick_push (build_zero_cst (TREE_TYPE (vec_type)));
+  builder.quick_push (build_zero_cst (TREE_TYPE (f.ret_type)));
       }
     return gimple_build_assign (f.lhs (), builder.build ());
   }
@@ -1533,13 +1530,12 @@ public:
   fold (gimple_folder &f) const override
   {
     /* Apply constant folding if base and step are integer constants.  */
-    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 (),
- build_vec_series (vec_type, base, step));
+ build_vec_series (f.ret_type, base, step));
   }

public:
@@ -1853,11 +1849,10 @@ public:
&& !flag_non_call_exceptions)
       {
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);
+ poly_uint64 lhs_len = TYPE_VECTOR_SUBPARTS (f.ret_type);
+ tree eltype = TREE_TYPE (f.ret_type);

- scalar_mode elmode = GET_MODE_INNER (TYPE_MODE (lhs_type));
+ scalar_mode elmode = GET_MODE_INNER (TYPE_MODE (f.ret_type));
machine_mode vq_mode = aarch64_v128_mode (elmode).require ();
tree vectype = build_vector_type_for_mode (eltype, vq_mode);

@@ -1884,14 +1879,14 @@ public:
   loaded value from the Advanced SIMD type to the SVE type.  */
if (known_eq (lhs_len, (unsigned int) source_nelts))
  return gimple_build_assign (lhs, build1 (VIEW_CONVERT_EXPR,
-   lhs_type, mem_ref_lhs));
+   f.ret_type, mem_ref_lhs));

vec_perm_builder sel (lhs_len, source_nelts, 1);
for (int i = 0; i < source_nelts; i++)
  sel.quick_push (i);

vec_perm_indices indices (sel, 1, source_nelts);
- gcc_checking_assert (can_vec_perm_const_p (TYPE_MODE (lhs_type),
+ gcc_checking_assert (can_vec_perm_const_p (TYPE_MODE (f.ret_type),
   TYPE_MODE (access_type),
   indices));
tree mask_type = build_vector_type (ssizetype, lhs_len);
@@ -1936,7 +1931,6 @@ public:
   gimple *
   fold (gimple_folder &f) const override
   {
-    tree tuple_type = f.ret_type;
     tree vectype = f.vector_type (0);

     /* Get the predicate and base pointer.  */
@@ -1951,10 +1945,10 @@ public:
        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_build_assign (f.lhs (), build_clobber (f.ret_type));

     /* View the loaded data as an array of vectors.  */
-    tree field = tuple_type_field (tuple_type);
+    tree field = tuple_type_field (f.ret_type);
     tree lhs_array
       = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (field), unshare_expr (f.lhs ()));

--
2.43.0


Reply via email to