From: Saurabh Jha <[email protected]>

Currently, we model vector comparison costs in a generic way, with two
additional fields, int_cmp_pred_ops and fp_cmp_pred_ops, handling
predication costs. But we sometimes need to handle general ops of vector
compares separately as they might have more than one general op.

We add two new fields, int_cmp_ops and fp_cmp_ops, that model the
general cost of vector comparisons. We initialise these fields to 1
in the tuning models for all cores, with the assumption that these
instructions count as 1 general_op by default.

Regression tested on aarch64-linux-gnu and found no regressions.

gcc/ChangeLog:

        * config/aarch64/aarch64-json-schema.h: Add fields int_cmp_ops
        and fp_cmp_ops.
        * config/aarch64/aarch64-json-tunings-parser-generated.inc
        (parse_vec_costs_issue_info_sve): Regenerated.
        * config/aarch64/aarch64-json-tunings-printer-generated.inc
        (serialize_vec_costs_issue_info_sve): Regenerated.
        * config/aarch64/aarch64-protos.h
        (struct aarch64_sve_vec_issue_info): Add fields int_cmp_ops and
        fp_cmp_ops.
        * config/aarch64/aarch64.cc
        (aarch64_vector_costs::count_ops): Include the cost of
        int_cmp_ops and fp_cmp_ops in general cost.
        * config/aarch64/tuning_models/cortexx925.h: Add new cmp fields.
        * config/aarch64/tuning_models/generic_armv9_a.h: Likewise.
        * config/aarch64/tuning_models/hip12.h: Likewise.
        * config/aarch64/tuning_models/neoverse512tvb.h: Likewise.
        * config/aarch64/tuning_models/neoversen2.h: Likewise.
        * config/aarch64/tuning_models/neoversen3.h: Likewise.
        * config/aarch64/tuning_models/neoversev1.h: Likewise.
        * config/aarch64/tuning_models/neoversev2.h: Likewise.
        * config/aarch64/tuning_models/neoversev3.h: Likewise.
        * config/aarch64/tuning_models/neoversev3ae.h: Likewise.
        * config/aarch64/tuning_models/olympus.h: Likewise.
---
 gcc/config/aarch64/aarch64-json-schema.h       |  4 +++-
 .../aarch64-json-tunings-parser-generated.inc  |  2 ++
 .../aarch64-json-tunings-printer-generated.inc |  2 ++
 gcc/config/aarch64/aarch64-protos.h            | 12 ++++++++++++
 gcc/config/aarch64/aarch64.cc                  | 18 +++++++++++++-----
 gcc/config/aarch64/tuning_models/cortexx925.h  |  2 ++
 .../aarch64/tuning_models/generic_armv9_a.h    |  2 ++
 gcc/config/aarch64/tuning_models/hip12.h       |  2 ++
 .../aarch64/tuning_models/neoverse512tvb.h     |  2 ++
 gcc/config/aarch64/tuning_models/neoversen2.h  |  2 ++
 gcc/config/aarch64/tuning_models/neoversen3.h  |  2 ++
 gcc/config/aarch64/tuning_models/neoversev1.h  |  2 ++
 gcc/config/aarch64/tuning_models/neoversev2.h  |  2 ++
 gcc/config/aarch64/tuning_models/neoversev3.h  |  2 ++
 .../aarch64/tuning_models/neoversev3ae.h       |  2 ++
 gcc/config/aarch64/tuning_models/olympus.h     |  2 ++
 16 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-json-schema.h 
b/gcc/config/aarch64/aarch64-json-schema.h
index 9b6c5478d1581..223884f123c3b 100644
--- a/gcc/config/aarch64/aarch64-json-schema.h
+++ b/gcc/config/aarch64/aarch64-json-schema.h
@@ -235,7 +235,9 @@ static const char *schema_json = R"json(
          "ld4_st4_general_ops": "uint",
          "pred_ops_per_cycle": "uint",
          "while_pred_ops": "uint",
+         "int_cmp_ops": "uint",
          "int_cmp_pred_ops": "uint",
+         "fp_cmp_ops": "uint",
          "fp_cmp_pred_ops": "uint",
          "gather_scatter_pair_general_ops": "uint",
          "gather_scatter_pair_pred_ops": "uint"
@@ -285,4 +287,4 @@ static const char *schema_json = R"json(
   }
 })json";
 
-#endif
\ No newline at end of file
+#endif
diff --git a/gcc/config/aarch64/aarch64-json-tunings-parser-generated.inc 
b/gcc/config/aarch64/aarch64-json-tunings-parser-generated.inc
index 1a615ac7d2036..0e89e27afd97e 100644
--- a/gcc/config/aarch64/aarch64-json-tunings-parser-generated.inc
+++ b/gcc/config/aarch64/aarch64-json-tunings-parser-generated.inc
@@ -245,7 +245,9 @@ parse_vec_costs_issue_info_sve (gcc_json_context &ctxt, 
const json::object &jo,
   PARSE_UNSIGNED_INTEGER_FIELD (ctxt, jo, "ld4_st4_general_ops", 
sve.ld4_st4_general_ops);
   PARSE_UNSIGNED_INTEGER_FIELD (ctxt, jo, "pred_ops_per_cycle", 
sve.pred_ops_per_cycle);
   PARSE_UNSIGNED_INTEGER_FIELD (ctxt, jo, "while_pred_ops", 
sve.while_pred_ops);
+  PARSE_UNSIGNED_INTEGER_FIELD (ctxt, jo, "int_cmp_ops", sve.int_cmp_ops);
   PARSE_UNSIGNED_INTEGER_FIELD (ctxt, jo, "int_cmp_pred_ops", 
sve.int_cmp_pred_ops);
+  PARSE_UNSIGNED_INTEGER_FIELD (ctxt, jo, "fp_cmp_ops", sve.fp_cmp_ops);
   PARSE_UNSIGNED_INTEGER_FIELD (ctxt, jo, "fp_cmp_pred_ops", 
sve.fp_cmp_pred_ops);
   PARSE_UNSIGNED_INTEGER_FIELD (ctxt, jo, "gather_scatter_pair_general_ops", 
sve.gather_scatter_pair_general_ops);
   PARSE_UNSIGNED_INTEGER_FIELD (ctxt, jo, "gather_scatter_pair_pred_ops", 
sve.gather_scatter_pair_pred_ops);
diff --git a/gcc/config/aarch64/aarch64-json-tunings-printer-generated.inc 
b/gcc/config/aarch64/aarch64-json-tunings-printer-generated.inc
index e619a39749dd1..1ed0ed4e0e329 100644
--- a/gcc/config/aarch64/aarch64-json-tunings-printer-generated.inc
+++ b/gcc/config/aarch64/aarch64-json-tunings-printer-generated.inc
@@ -291,7 +291,9 @@ serialize_vec_costs_issue_info_sve (const T &sve)
   SERIALIZE_UNSIGNED_INTEGER_FIELD (sve_obj, "ld4_st4_general_ops", 
sve.ld4_st4_general_ops);
   SERIALIZE_UNSIGNED_INTEGER_FIELD (sve_obj, "pred_ops_per_cycle", 
sve.pred_ops_per_cycle);
   SERIALIZE_UNSIGNED_INTEGER_FIELD (sve_obj, "while_pred_ops", 
sve.while_pred_ops);
+  SERIALIZE_UNSIGNED_INTEGER_FIELD (sve_obj, "int_cmp_ops", sve.int_cmp_ops);
   SERIALIZE_UNSIGNED_INTEGER_FIELD (sve_obj, "int_cmp_pred_ops", 
sve.int_cmp_pred_ops);
+  SERIALIZE_UNSIGNED_INTEGER_FIELD (sve_obj, "fp_cmp_ops", sve.fp_cmp_ops);
   SERIALIZE_UNSIGNED_INTEGER_FIELD (sve_obj, "fp_cmp_pred_ops", 
sve.fp_cmp_pred_ops);
   SERIALIZE_UNSIGNED_INTEGER_FIELD (sve_obj, 
"gather_scatter_pair_general_ops", sve.gather_scatter_pair_general_ops);
   SERIALIZE_UNSIGNED_INTEGER_FIELD (sve_obj, "gather_scatter_pair_pred_ops", 
sve.gather_scatter_pair_pred_ops);
diff --git a/gcc/config/aarch64/aarch64-protos.h 
b/gcc/config/aarch64/aarch64-protos.h
index 99342ccb1b6cd..1f004e8743675 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -403,14 +403,18 @@ struct aarch64_sve_vec_issue_info : 
aarch64_simd_vec_issue_info
     (aarch64_simd_vec_issue_info base,
      unsigned int pred_ops_per_cycle,
      unsigned int while_pred_ops,
+     unsigned int int_cmp_ops,
      unsigned int int_cmp_pred_ops,
+     unsigned int fp_cmp_ops,
      unsigned int fp_cmp_pred_ops,
      unsigned int gather_scatter_pair_general_ops,
      unsigned int gather_scatter_pair_pred_ops)
     : aarch64_simd_vec_issue_info (base),
       pred_ops_per_cycle (pred_ops_per_cycle),
       while_pred_ops (while_pred_ops),
+      int_cmp_ops (int_cmp_ops),
       int_cmp_pred_ops (int_cmp_pred_ops),
+      fp_cmp_ops (fp_cmp_ops),
       fp_cmp_pred_ops (fp_cmp_pred_ops),
       gather_scatter_pair_general_ops (gather_scatter_pair_general_ops),
       gather_scatter_pair_pred_ops (gather_scatter_pair_pred_ops)
@@ -423,10 +427,18 @@ struct aarch64_sve_vec_issue_info : 
aarch64_simd_vec_issue_info
      instruction.  */
   unsigned int while_pred_ops;
 
+  /* How many general operations are generated by an integer
+     comparison instruction.  */
+  unsigned int int_cmp_ops;
+
   /* How many predicate operations are generated by an integer
      comparison instruction.  */
   unsigned int int_cmp_pred_ops;
 
+  /* How many general operations are generated by a floating-point
+     comparison instruction.  */
+  unsigned int fp_cmp_ops;
+
   /* How many predicate operations are generated by a floating-point
      comparison instruction.  */
   unsigned int fp_cmp_pred_ops;
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 5a0bc214f13aa..b7ea06912e887 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -18878,16 +18878,24 @@ aarch64_vector_costs::count_ops (unsigned int count, 
vect_cost_for_stmt kind,
       && vect_reduc_type (m_vinfo, node) == COND_REDUCTION)
     ops->general_ops += count;
 
-  /* Count the predicate operations needed by an SVE comparison.  */
+  /* Count the general and predicate operations needed by an SVE comparison.  
*/
   if (stmt_info
       && sve_issue
       && (kind == vector_stmt || kind == vec_to_scalar))
     if (tree type = vect_comparison_type (stmt_info))
       {
-       unsigned int base = (FLOAT_TYPE_P (type)
-                            ? sve_issue->fp_cmp_pred_ops
-                            : sve_issue->int_cmp_pred_ops);
-       ops->pred_ops += base * count;
+       auto cmp_ops = (FLOAT_TYPE_P (type)
+                       ? sve_issue->fp_cmp_ops
+                       : sve_issue->int_cmp_ops);
+       /* Subtracting 1 from cmp_ops because the basic operation count is
+          already included above.  The effect of this is now the additional
+          cost of cmp instructions.  */
+       ops->general_ops += (cmp_ops - 1) * count;
+
+       auto cmp_pred_ops = (FLOAT_TYPE_P (type)
+                           ? sve_issue->fp_cmp_pred_ops
+                           : sve_issue->int_cmp_pred_ops);
+       ops->pred_ops += cmp_pred_ops * count;
       }
 
   /* Add any extra overhead associated with LD[234] and ST[234] operations.  */
diff --git a/gcc/config/aarch64/tuning_models/cortexx925.h 
b/gcc/config/aarch64/tuning_models/cortexx925.h
index 2a73b36970655..b17f6971fab7e 100644
--- a/gcc/config/aarch64/tuning_models/cortexx925.h
+++ b/gcc/config/aarch64/tuning_models/cortexx925.h
@@ -161,7 +161,9 @@ static const aarch64_sve_vec_issue_info 
cortexx925_sve_issue_info =
   },
   2, /* pred_ops_per_cycle  */
   1, /* while_pred_ops  */
+  1, /* int_cmp_ops  */
   0, /* int_cmp_pred_ops  */
+  1, /* fp_cmp_ops  */
   0, /* fp_cmp_pred_ops  */
   1, /* gather_scatter_pair_general_ops  */
   1 /* gather_scatter_pair_pred_ops  */
diff --git a/gcc/config/aarch64/tuning_models/generic_armv9_a.h 
b/gcc/config/aarch64/tuning_models/generic_armv9_a.h
index 05e777d20efb3..ce0d281c8e681 100644
--- a/gcc/config/aarch64/tuning_models/generic_armv9_a.h
+++ b/gcc/config/aarch64/tuning_models/generic_armv9_a.h
@@ -180,7 +180,9 @@ static const aarch64_sve_vec_issue_info 
generic_armv9_a_sve_issue_info =
   },
   2, /* pred_ops_per_cycle  */
   2, /* while_pred_ops  */
+  1, /* int_cmp_ops  */
   2, /* int_cmp_pred_ops  */
+  1, /* fp_cmp_ops  */
   1, /* fp_cmp_pred_ops  */
   1, /* gather_scatter_pair_general_ops  */
   1 /* gather_scatter_pair_pred_ops  */
diff --git a/gcc/config/aarch64/tuning_models/hip12.h 
b/gcc/config/aarch64/tuning_models/hip12.h
index 30d07d990a063..8a3b52bbac8ab 100644
--- a/gcc/config/aarch64/tuning_models/hip12.h
+++ b/gcc/config/aarch64/tuning_models/hip12.h
@@ -159,7 +159,9 @@ static const aarch64_sve_vec_issue_info 
hip12_sve_issue_info =
   },
   2, /* pred_ops_per_cycle  */
   2, /* while_pred_ops  */
+  1, /* int_cmp_ops  */
   2, /* int_cmp_pred_ops  */
+  1, /* fp_cmp_ops  */
   1, /* fp_cmp_pred_ops  */
   1, /* gather_scatter_pair_general_ops  */
   1 /* gather_scatter_pair_pred_ops  */
diff --git a/gcc/config/aarch64/tuning_models/neoverse512tvb.h 
b/gcc/config/aarch64/tuning_models/neoverse512tvb.h
index d6e2c2e8120d7..69ec531d99c86 100644
--- a/gcc/config/aarch64/tuning_models/neoverse512tvb.h
+++ b/gcc/config/aarch64/tuning_models/neoverse512tvb.h
@@ -100,7 +100,9 @@ static const aarch64_sve_vec_issue_info 
neoverse512tvb_sve_issue_info =
   },
   2, /* pred_ops_per_cycle  */
   2, /* while_pred_ops  */
+  1, /* int_cmp_ops  */
   2, /* int_cmp_pred_ops  */
+  1, /* fp_cmp_ops  */
   1, /* fp_cmp_pred_ops  */
   1, /* gather_scatter_pair_general_ops  */
   1 /* gather_scatter_pair_pred_ops  */
diff --git a/gcc/config/aarch64/tuning_models/neoversen2.h 
b/gcc/config/aarch64/tuning_models/neoversen2.h
index 21597e6b50f83..2e58c9ec0329d 100644
--- a/gcc/config/aarch64/tuning_models/neoversen2.h
+++ b/gcc/config/aarch64/tuning_models/neoversen2.h
@@ -161,7 +161,9 @@ static const aarch64_sve_vec_issue_info 
neoversen2_sve_issue_info =
   },
   2, /* pred_ops_per_cycle  */
   2, /* while_pred_ops  */
+  1, /* int_cmp_ops  */
   2, /* int_cmp_pred_ops  */
+  1, /* fp_cmp_ops  */
   1, /* fp_cmp_pred_ops  */
   1, /* gather_scatter_pair_general_ops  */
   1 /* gather_scatter_pair_pred_ops  */
diff --git a/gcc/config/aarch64/tuning_models/neoversen3.h 
b/gcc/config/aarch64/tuning_models/neoversen3.h
index 37f9819148f66..e50517f019138 100644
--- a/gcc/config/aarch64/tuning_models/neoversen3.h
+++ b/gcc/config/aarch64/tuning_models/neoversen3.h
@@ -161,7 +161,9 @@ static const aarch64_sve_vec_issue_info 
neoversen3_sve_issue_info =
   },
   2, /* pred_ops_per_cycle  */
   1, /* while_pred_ops  */
+  1, /* int_cmp_ops  */
   0, /* int_cmp_pred_ops  */
+  1, /* fp_cmp_ops  */
   0, /* fp_cmp_pred_ops  */
   1, /* gather_scatter_pair_general_ops  */
   1 /* gather_scatter_pair_pred_ops  */
diff --git a/gcc/config/aarch64/tuning_models/neoversev1.h 
b/gcc/config/aarch64/tuning_models/neoversev1.h
index 004676a8dbacf..b5b83919532e8 100644
--- a/gcc/config/aarch64/tuning_models/neoversev1.h
+++ b/gcc/config/aarch64/tuning_models/neoversev1.h
@@ -170,7 +170,9 @@ static const aarch64_sve_vec_issue_info 
neoversev1_sve_issue_info =
   },
   1, /* pred_ops_per_cycle  */
   2, /* while_pred_ops  */
+  1, /* int_cmp_ops  */
   2, /* int_cmp_pred_ops  */
+  1, /* fp_cmp_ops  */
   1, /* fp_cmp_pred_ops  */
   1, /* gather_scatter_pair_general_ops  */
   1 /* gather_scatter_pair_pred_ops  */
diff --git a/gcc/config/aarch64/tuning_models/neoversev2.h 
b/gcc/config/aarch64/tuning_models/neoversev2.h
index 734089772517e..fc3dd80fc6be4 100644
--- a/gcc/config/aarch64/tuning_models/neoversev2.h
+++ b/gcc/config/aarch64/tuning_models/neoversev2.h
@@ -163,7 +163,9 @@ static const aarch64_sve_vec_issue_info 
neoversev2_sve_issue_info =
   },
   2, /* pred_ops_per_cycle  */
   2, /* while_pred_ops  */
+  1, /* int_cmp_ops  */
   2, /* int_cmp_pred_ops  */
+  1, /* fp_cmp_ops  */
   1, /* fp_cmp_pred_ops  */
   1, /* gather_scatter_pair_general_ops  */
   1 /* gather_scatter_pair_pred_ops  */
diff --git a/gcc/config/aarch64/tuning_models/neoversev3.h 
b/gcc/config/aarch64/tuning_models/neoversev3.h
index 8d31c58f70d8f..f88d74da50acb 100644
--- a/gcc/config/aarch64/tuning_models/neoversev3.h
+++ b/gcc/config/aarch64/tuning_models/neoversev3.h
@@ -151,7 +151,9 @@ static const aarch64_sve_vec_issue_info 
neoversev3_sve_issue_info =
   },
   2, /* pred_ops_per_cycle  */
   1, /* while_pred_ops  */
+  1, /* int_cmp_ops  */
   0, /* int_cmp_pred_ops  */
+  1, /* fp_cmp_ops  */
   0, /* fp_cmp_pred_ops  */
   1, /* gather_scatter_pair_general_ops  */
   1 /* gather_scatter_pair_pred_ops  */
diff --git a/gcc/config/aarch64/tuning_models/neoversev3ae.h 
b/gcc/config/aarch64/tuning_models/neoversev3ae.h
index bbe4dc5470152..41a2626e4c8c6 100644
--- a/gcc/config/aarch64/tuning_models/neoversev3ae.h
+++ b/gcc/config/aarch64/tuning_models/neoversev3ae.h
@@ -161,7 +161,9 @@ static const aarch64_sve_vec_issue_info 
neoversev3ae_sve_issue_info =
   },
   2, /* pred_ops_per_cycle  */
   1, /* while_pred_ops  */
+  1, /* int_cmp_ops  */
   0, /* int_cmp_pred_ops  */
+  1, /* fp_cmp_ops  */
   0, /* fp_cmp_pred_ops  */
   1, /* gather_scatter_pair_general_ops  */
   1 /* gather_scatter_pair_pred_ops  */
diff --git a/gcc/config/aarch64/tuning_models/olympus.h 
b/gcc/config/aarch64/tuning_models/olympus.h
index 1e701722e2248..de8028f619926 100644
--- a/gcc/config/aarch64/tuning_models/olympus.h
+++ b/gcc/config/aarch64/tuning_models/olympus.h
@@ -132,7 +132,9 @@ static aarch64_sve_vec_issue_info olympus_sve_issue_info =
   },
   2, /* pred_ops_per_cycle  */
   1, /* while_pred_ops  */
+  1, /* int_cmp_ops  */
   0, /* int_cmp_pred_ops  */
+  1, /* fp_cmp_ops  */
   0, /* fp_cmp_pred_ops  */
   1, /* gather_scatter_pair_general_ops  */
   1 /* gather_scatter_pair_pred_ops  */
-- 
2.56.0

Reply via email to