From: Karl Meakin <[email protected]>

Make `aarch64_update_ipa_fn_target_info` more conservative, by setting
the `AARCH64_IPA_SM_FIXED` bit by default. The bit will only be unset if
the function is annotated with `[[arm::streaming_compatible]]`. This
matches the ACLE's specification which states that functions are by
default non-streaming.

This fixes PR 126133 by causing inlining to fail, even with
`[[gnu::always_inline]]`, because the target features do not match.

gcc/ChangeLog:

        * config/aarch64/aarch64.cc (aarch64_update_ipa_fn_target_info):
        set the `AARCH64_IPA_SM_FIXED` bit unless the function is
        annotated with `[[arm::streaming_compatible]]`.

gcc/testsuite/ChangeLog:

        * gcc.target/aarch64/pr126133-1.c: New test.
        * gcc.target/aarch64/pr126133-2.c: New test.
        * gcc.target/aarch64/pr126133-3.c: New test.
---
 gcc/config/aarch64/aarch64.cc                 | 15 ++++++-------
 gcc/testsuite/gcc.target/aarch64/pr126133-1.c | 19 +++++++++++++++++
 gcc/testsuite/gcc.target/aarch64/pr126133-2.c | 21 +++++++++++++++++++
 gcc/testsuite/gcc.target/aarch64/pr126133-3.c | 19 +++++++++++++++++
 4 files changed, 65 insertions(+), 9 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/pr126133-1.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/pr126133-2.c
 create mode 100644 gcc/testsuite/gcc.target/aarch64/pr126133-3.c

diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index 61562c94a553..d4ed42ce73e1 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -22185,15 +22185,12 @@ aarch64_update_ipa_fn_target_info (unsigned int 
&info, const gimple *stmt)
     }
   if (auto *call = dyn_cast<const gcall *> (stmt))
     {
-      if (gimple_call_builtin_p (call, BUILT_IN_MD))
-       {
-         /* The attributes on AArch64 builtins are supposed to be accurate.
-            If the function isn't marked streaming-compatible then it
-            needs whichever SM mode it selects.  */
-         tree decl = gimple_call_fndecl (call);
-         if (aarch64_fndecl_pstate_sm (decl) != 0)
-           info |= AARCH64_IPA_SM_FIXED;
-       }
+      /* Assume functions are non-streaming by default.
+       They are only streaming or streaming-compatible if they have the
+       corresponding attribute.  */
+      tree decl = gimple_call_fndecl (call);
+      if (!decl || aarch64_fndecl_pstate_sm (decl) != 0)
+       info |= AARCH64_IPA_SM_FIXED;
     }
   return true;
 }
diff --git a/gcc/testsuite/gcc.target/aarch64/pr126133-1.c 
b/gcc/testsuite/gcc.target/aarch64/pr126133-1.c
new file mode 100644
index 000000000000..c07edea63c57
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr126133-1.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=armv8-a+sme" } */
+
+#include <arm_neon.h>
+
+#define ALWAYS_INLINE [[gnu::always_inline]] inline
+
+ALWAYS_INLINE
+uint8x16_t
+cnt_helper (uint8x16_t x) /* { dg-error "inlining failed" } */
+{
+  return vcntq_u8 (x);
+}
+
+uint8x16_t
+cnt (uint8x16_t x) [[arm::streaming]]
+{
+  return cnt_helper (x);
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/pr126133-2.c 
b/gcc/testsuite/gcc.target/aarch64/pr126133-2.c
new file mode 100644
index 000000000000..6c830f92abe0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr126133-2.c
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=armv8-a+sme" } */
+
+#include <arm_neon.h>
+
+#define ALWAYS_INLINE [[gnu::always_inline]] inline
+
+/* Gets expanded to addition early, so no error.
+   An error would be more correct though.  */
+ALWAYS_INLINE
+uint8x16_t
+add_helper (uint8x16_t x, uint8x16_t y)
+{
+  return vaddq_u8 (x, y);
+}
+
+uint8x16_t
+add (uint8x16_t x, uint8x16_t y) [[arm::streaming]]
+{
+  return add_helper (x, y);
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/pr126133-3.c 
b/gcc/testsuite/gcc.target/aarch64/pr126133-3.c
new file mode 100644
index 000000000000..932e4ec11f5f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr126133-3.c
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=armv8-a+sme" } */
+
+#include <arm_neon.h>
+
+#define ALWAYS_INLINE [[gnu::always_inline]] inline
+
+ALWAYS_INLINE
+uint8_t
+addv_helper (uint8x16_t x) /* { dg-error "inlining failed" } */
+{
+  return vaddvq_u8 (x);
+}
+
+uint8_t
+addv (uint8x16_t x) [[arm::streaming]]
+{
+  return addv_helper (x);
+}
-- 
2.54.0

Reply via email to