[gcc r11-7860] aarch64: Cost comparisons embedded in COND_EXPRs

Richard Sandiford rsandifo@gcc.gnu.org
Fri Mar 26 16:11:01 GMT 2021


https://gcc.gnu.org/g:99f94ae5018e915d0c1db1b6d4110d68bc4d242e

commit r11-7860-g99f94ae5018e915d0c1db1b6d4110d68bc4d242e
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Fri Mar 26 16:08:36 2021 +0000

    aarch64: Cost comparisons embedded in COND_EXPRs
    
    So far the costing of COND_EXPRs hasn't distinguished between
    cases in which the condition is calculated separately or is
    built into the COND_EXPR itself.  This patch adds the cost
    of any embedded comparison.
    
    Like with the previous patches, this one only becomes active if
    a CPU selects use_new_vector_costs.  It should therefore have
    a very low impact on other CPUs.
    
    gcc/
            * config/aarch64/aarch64.c (aarch64_embedded_comparison_type): New
            function.
            (aarch64_adjust_stmt_cost): Add the costs of embedded scalar and
            vector comparisons.

Diff:
---
 gcc/config/aarch64/aarch64.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index e2d92f0c136..e97e71b6e3d 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -14392,6 +14392,21 @@ aarch64_ld234_st234_vectors (vect_cost_for_stmt kind, stmt_vec_info stmt_info)
   return 0;
 }
 
+/* If STMT_INFO is a COND_EXPR that includes an embedded comparison, return the
+   scalar type of the values being compared.  Return null otherwise.  */
+static tree
+aarch64_embedded_comparison_type (stmt_vec_info stmt_info)
+{
+  if (auto *assign = dyn_cast<gassign *> (stmt_info->stmt))
+    if (gimple_assign_rhs_code (assign) == COND_EXPR)
+      {
+	tree cond = gimple_assign_rhs1 (assign);
+	if (COMPARISON_CLASS_P (cond))
+	  return TREE_TYPE (TREE_OPERAND (cond, 0));
+      }
+  return NULL_TREE;
+}
+
 /* Return true if creating multiple copies of STMT_INFO for Advanced SIMD
    vectors would produce a series of LDP or STP operations.  KIND is the
    kind of statement that STMT_INFO represents.  */
@@ -14685,8 +14700,26 @@ aarch64_adjust_stmt_cost (vect_cost_for_stmt kind, stmt_vec_info stmt_info,
 	  stmt_cost += simd_costs->ld4_st4_permute_cost;
 	  break;
 	}
+
+      if (kind == vector_stmt || kind == vec_to_scalar)
+	if (tree cmp_type = aarch64_embedded_comparison_type (stmt_info))
+	  {
+	    if (FLOAT_TYPE_P (cmp_type))
+	      stmt_cost += simd_costs->fp_stmt_cost;
+	    else
+	      stmt_cost += simd_costs->int_stmt_cost;
+	  }
     }
 
+  if (kind == scalar_stmt)
+    if (tree cmp_type = aarch64_embedded_comparison_type (stmt_info))
+      {
+	if (FLOAT_TYPE_P (cmp_type))
+	  stmt_cost += aarch64_tune_params.vec_costs->scalar_fp_stmt_cost;
+	else
+	  stmt_cost += aarch64_tune_params.vec_costs->scalar_int_stmt_cost;
+      }
+
   return stmt_cost;
 }


More information about the Gcc-cvs mailing list