]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[APX CCMP] Add targetm.have_ccmp hook [PR115370]
authorHongyu Wang <hongyu.wang@intel.com>
Wed, 12 Jun 2024 16:18:32 +0000 (00:18 +0800)
committerHongyu Wang <hongyu.wang@intel.com>
Thu, 13 Jun 2024 14:04:08 +0000 (22:04 +0800)
In cfgexpand, there is an optimization for branch which tests
targetm.gen_ccmp_first == NULL. However for target like x86-64, the
hook was implemented but it does not indicate that ccmp was enabled.
Add a new target hook TARGET_HAVE_CCMP and replace the middle-end
check for the existance of gen_ccmp_first to avoid misoptimization.

gcc/ChangeLog:

PR target/115370
PR target/115463
* target.def (have_ccmp): New target hook.
* targhooks.cc (default_have_ccmp): New function.
* targhooks.h (default_have_ccmp): New prototype.
* doc/tm.texi.in: Add TARGET_HAVE_CCMP.
* doc/tm.texi: Regenerate.
* cfgexpand.cc (expand_gimple_cond): Call targetm.have_ccmp
instead of checking if targetm.gen_ccmp_first exists.
* expr.cc (expand_expr_real_gassign): Likewise.
* config/i386/i386.cc (ix86_have_ccmp): New target hook to
check if APX_CCMP enabled.
(TARGET_HAVE_CCMP): Define.

gcc/cfgexpand.cc
gcc/config/i386/i386.cc
gcc/doc/tm.texi
gcc/doc/tm.texi.in
gcc/expr.cc
gcc/target.def
gcc/targhooks.cc
gcc/targhooks.h

index 8de5f2ba58b7ef9944a82e459819d2088889164e..dad3ae1b7c6e1318788dbf021ef7ebfc99e580cf 100644 (file)
@@ -2646,7 +2646,7 @@ expand_gimple_cond (basic_block bb, gcond *stmt)
          /* If jumps are cheap and the target does not support conditional
             compare, turn some more codes into jumpy sequences.  */
          else if (BRANCH_COST (optimize_insn_for_speed_p (), false) < 4
-                  && targetm.gen_ccmp_first == NULL)
+                  && !targetm.have_ccmp ())
            {
              if ((code2 == BIT_AND_EXPR
                   && TYPE_PRECISION (TREE_TYPE (op0)) == 1
index 173db213d14ec3cb195549a99aca3a960ed86111..c72f64da983dc4053164e65569bb310df27abd2c 100644 (file)
@@ -26204,6 +26204,13 @@ ix86_memtag_add_tag (rtx base, poly_int64 offset, unsigned char tag_offset)
   return plus_constant (Pmode, tagged_addr, offset);
 }
 
+/* Implement TARGET_HAVE_CCMP.  */
+static bool
+ix86_have_ccmp ()
+{
+  return (bool) TARGET_APX_CCMP;
+}
+
 /* Target-specific selftests.  */
 
 #if CHECKING_P
@@ -27043,6 +27050,8 @@ ix86_libgcc_floating_mode_supported_p
 #undef TARGET_GEN_CCMP_NEXT
 #define TARGET_GEN_CCMP_NEXT ix86_gen_ccmp_next
 
+#undef TARGET_HAVE_CCMP
+#define TARGET_HAVE_CCMP ix86_have_ccmp
 
 static bool
 ix86_libc_has_fast_function (int fcode ATTRIBUTE_UNUSED)
index 8a7aa70d605bac27fd94bc37744ad61ae9faab6c..be5543b72f85f987f18ddc9fb73ff439ec18bf75 100644 (file)
@@ -12354,6 +12354,13 @@ This function prepares to emit a conditional comparison within a sequence
  @var{bit_code} is @code{AND} or @code{IOR}, which is the op on the compares.
 @end deftypefn
 
+@deftypefn {Target Hook} bool TARGET_HAVE_CCMP (void)
+This target hook returns true if the target supports conditional compare.
+This target hook is required only when the ccmp support is conditionally
+enabled, such as in response to command-line flags. The default implementation
+returns true iff @code{TARGET_GEN_CCMP_FIRST} is defined.
+@end deftypefn
+
 @deftypefn {Target Hook} unsigned TARGET_LOOP_UNROLL_ADJUST (unsigned @var{nunroll}, class loop *@var{loop})
 This target hook returns a new value for the number of times @var{loop}
 should be unrolled. The parameter @var{nunroll} is the number of times
index 9e0830758aeea295673912eb5485e08c7a1a60ec..87a7f8951741ac016f665e31eaef081fb5808d90 100644 (file)
@@ -7923,6 +7923,8 @@ lists.
 
 @hook TARGET_GEN_CCMP_NEXT
 
+@hook TARGET_HAVE_CCMP
+
 @hook TARGET_LOOP_UNROLL_ADJUST
 
 @defmac POWI_MAX_MULTS
index 1baa39b98eba3cb1d9c76fdbecaa03ec85ef5066..04bad5e1425d8c20e80ac4be42685a9e2fbb9934 100644 (file)
@@ -11089,7 +11089,7 @@ expand_expr_real_gassign (gassign *g, rtx target, machine_mode tmode,
       ops.op1 = gimple_assign_rhs2 (g);
 
       /* Try to expand conditonal compare.  */
-      if (targetm.gen_ccmp_first)
+      if (targetm.have_ccmp ())
        {
          gcc_checking_assert (targetm.gen_ccmp_next != NULL);
          r = expand_ccmp_expr (g, TYPE_MODE (ops.type));
index 70070caebc76832f5a2561dea8f937a69f925c7c..e5a9b52676e4b568bb38960708f6003c0d1592d3 100644 (file)
@@ -2783,6 +2783,16 @@ DEFHOOK
  rtx, (rtx_insn **prep_seq, rtx_insn **gen_seq, rtx prev, rtx_code cmp_code, tree op0, tree op1, rtx_code bit_code),
  NULL)
 
+/* Return true if the target supports conditional compare.  */
+DEFHOOK
+(have_ccmp,
+ "This target hook returns true if the target supports conditional compare.\n\
+This target hook is required only when the ccmp support is conditionally\n\
+enabled, such as in response to command-line flags. The default implementation\n\
+returns true iff @code{TARGET_GEN_CCMP_FIRST} is defined.",
+ bool, (void),
+ default_have_ccmp)
+
 /* Return a new value for loop unroll size.  */
 DEFHOOK
 (loop_unroll_adjust,
index fb339bf75dd8325548583c183bb3ba46a11d494c..4f53257e55c0382665dcfcc85862e364377438d6 100644 (file)
@@ -1887,6 +1887,12 @@ default_have_conditional_execution (void)
   return HAVE_conditional_execution;
 }
 
+bool
+default_have_ccmp (void)
+{
+  return targetm.gen_ccmp_first != NULL;
+}
+
 /* By default we assume that c99 functions are present at the runtime,
    but sincos is not.  */
 bool
index 85f3817c176e90bce8f88038ced6faaf4b7d9e3f..f53913ebdfaddedebbb65d7f2750f1597df0d469 100644 (file)
@@ -216,6 +216,7 @@ extern void default_addr_space_diagnose_usage (addr_space_t, location_t);
 extern rtx default_addr_space_convert (rtx, tree, tree);
 extern unsigned int default_case_values_threshold (void);
 extern bool default_have_conditional_execution (void);
+extern bool default_have_ccmp (void);
 
 extern bool default_libc_has_function (enum function_class, tree);
 extern bool default_libc_has_fast_function (int fcode);