The VCTP instruction creates a Vector Tail Predicate in VPR.P0, based
on the input value, but also constrained by a VPT block (if present),
or if used within a DLSTP/LETP loop.

Therefore we need to inform the compiler that this intrinsic reads the
FPCXT register, otherwise it could make incorrect assumptions: for
instance in test7() from gcc.target/arm/mve/dlstp-compile-asm-2.c it
would hoist p1 = vctp32q (g) outside of the loop.

The patch introduces a new flag CP_READ_FPCXT, which is handled
similarly to CP_READ_MEMORY.

        gcc/ChangeLog:

        PR target/117814
        * config/arm/arm-mve-builtins-base.cc (vctpq_impl): Implement
        call_properties.
        * config/arm/arm-mve-builtins.cc
        (function_instance::reads_global_state_p): Handle CP_READ_FPCXT.
        * config/arm/arm-mve-builtins.h (CP_READ_FPCXT): New flag.
---
 gcc/config/arm/arm-mve-builtins-base.cc | 6 ++++++
 gcc/config/arm/arm-mve-builtins.cc      | 3 ++-
 gcc/config/arm/arm-mve-builtins.h       | 1 +
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/gcc/config/arm/arm-mve-builtins-base.cc 
b/gcc/config/arm/arm-mve-builtins-base.cc
index 723004b53d7..bc9dcc77515 100644
--- a/gcc/config/arm/arm-mve-builtins-base.cc
+++ b/gcc/config/arm/arm-mve-builtins-base.cc
@@ -541,6 +541,12 @@ public:
   /* Mode this intrinsic operates on.  */
   machine_mode m_mode;
 
+  unsigned int
+  call_properties (const function_instance &) const override
+  {
+    return CP_READ_FPCXT;
+  }
+
   rtx
   expand (function_expander &e) const override
   {
diff --git a/gcc/config/arm/arm-mve-builtins.cc 
b/gcc/config/arm/arm-mve-builtins.cc
index 30b103ec086..8bbcedd2f15 100644
--- a/gcc/config/arm/arm-mve-builtins.cc
+++ b/gcc/config/arm/arm-mve-builtins.cc
@@ -785,7 +785,8 @@ function_instance::reads_global_state_p () const
   if (flags & CP_READ_FPCR)
     return true;
 
-  return flags & CP_READ_MEMORY;
+  /* Handle direct reads of global state.  */
+  return flags & (CP_READ_MEMORY | CP_READ_FPCXT);
 }
 
 /* Return true if calls to the function could modify some form of
diff --git a/gcc/config/arm/arm-mve-builtins.h 
b/gcc/config/arm/arm-mve-builtins.h
index cdc07b4e51f..d76a10516ba 100644
--- a/gcc/config/arm/arm-mve-builtins.h
+++ b/gcc/config/arm/arm-mve-builtins.h
@@ -93,6 +93,7 @@ const unsigned int CP_READ_FPCR = 1U << 0;
 const unsigned int CP_RAISE_FP_EXCEPTIONS = 1U << 1;
 const unsigned int CP_READ_MEMORY = 1U << 2;
 const unsigned int CP_WRITE_MEMORY = 1U << 3;
+const unsigned int CP_READ_FPCXT = 1U << 4;
 
 /* Enumerates the MVE predicate and (data) vector types, together called
    "vector types" for brevity.  */
-- 
2.34.1

Reply via email to