https://gcc.gnu.org/g:b3974356b0981c7caf9694fe4c2faad902169c00

commit r15-2476-gb3974356b0981c7caf9694fe4c2faad902169c00
Author: Richard Biener <rguent...@suse.de>
Date:   Mon Jul 29 13:06:52 2024 +0200

    Add TARGET_MODE_CAN_TRANSFER_BITS
    
    The following adds a target hook to specify whether regs of MODE can be
    used to transfer bits.  The hook is supposed to be used for value-numbering
    to decide whether a value loaded in such mode can be punned to another
    mode instead of re-loading the value in the other mode and for SRA to
    decide whether MODE is suitable as container holding a value to be
    used in different modes.
    
            * target.def (mode_can_transfer_bits): New target hook.
            * target.h (mode_can_transfer_bits): New function wrapping the
            hook and providing default behavior.
            * doc/tm.texi.in: Update.
            * doc/tm.texi: Re-generate.

Diff:
---
 gcc/doc/tm.texi    | 11 +++++++++++
 gcc/doc/tm.texi.in |  2 ++
 gcc/target.def     | 13 +++++++++++++
 gcc/target.h       | 16 ++++++++++++++++
 4 files changed, 42 insertions(+)

diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index c7535d07f4dd..cc33084ed322 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -4545,6 +4545,17 @@ is either a declaration of type int or accessed by 
dereferencing
 a pointer to int.
 @end deftypefn
 
+@deftypefn {Target Hook} bool TARGET_MODE_CAN_TRANSFER_BITS (machine_mode 
@var{mode})
+Define this to return false if the mode @var{mode} cannot be used
+for memory copying of @code{GET_MODE_SIZE (mode)} units.  This might be
+because a register class allowed for @var{mode} has registers that do
+not transparently transfer every bit pattern or because the load or
+store patterns available for @var{mode} have this issue.
+
+The default is to assume modes with the same precision as size are fine
+to be used.
+@end deftypefn
+
 @deftypefn {Target Hook} machine_mode TARGET_TRANSLATE_MODE_ATTRIBUTE 
(machine_mode @var{mode})
 Define this hook if during mode attribute processing, the port should
 translate machine_mode @var{mode} to another mode.  For example, rs6000's
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 64cea3b1edaf..8af3f4145058 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -3455,6 +3455,8 @@ stack.
 
 @hook TARGET_REF_MAY_ALIAS_ERRNO
 
+@hook TARGET_MODE_CAN_TRANSFER_BITS
+
 @hook TARGET_TRANSLATE_MODE_ATTRIBUTE
 
 @hook TARGET_SCALAR_MODE_SUPPORTED_P
diff --git a/gcc/target.def b/gcc/target.def
index 3de1aad4c84d..1d0ea6f30caf 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -3363,6 +3363,19 @@ a pointer to int.",
  bool, (ao_ref *ref),
  default_ref_may_alias_errno)
 
+DEFHOOK
+(mode_can_transfer_bits,
+ "Define this to return false if the mode @var{mode} cannot be used\n\
+for memory copying of @code{GET_MODE_SIZE (mode)} units.  This might be\n\
+because a register class allowed for @var{mode} has registers that do\n\
+not transparently transfer every bit pattern or because the load or\n\
+store patterns available for @var{mode} have this issue.\n\
+\n\
+The default is to assume modes with the same precision as size are fine\n\
+to be used.",
+ bool, (machine_mode mode),
+ NULL)
+
 /* Support for named address spaces.  */
 #undef HOOK_PREFIX
 #define HOOK_PREFIX "TARGET_ADDR_SPACE_"
diff --git a/gcc/target.h b/gcc/target.h
index c1f99b97b864..837651d273af 100644
--- a/gcc/target.h
+++ b/gcc/target.h
@@ -312,6 +312,22 @@ estimated_poly_value (poly_int64 x,
     return targetm.estimated_poly_value (x, kind);
 }
 
+/* Return true when MODE can be used to copy GET_MODE_BITSIZE bits
+   unchanged.  */
+
+inline bool
+mode_can_transfer_bits (machine_mode mode)
+{
+  if (mode == BLKmode)
+    return true;
+  if (maybe_ne (GET_MODE_BITSIZE (mode),
+               GET_MODE_UNIT_PRECISION (mode) * GET_MODE_NUNITS (mode)))
+    return false;
+  if (targetm.mode_can_transfer_bits)
+    return targetm.mode_can_transfer_bits (mode);
+  return true;
+}
+
 #ifdef GCC_TM_H
 
 #ifndef CUMULATIVE_ARGS_MAGIC

Reply via email to