From: Karl Meakin <[email protected]>

Change `aarch64_update_ipa_fn_target_info` to set `AARCH64_IPA_SM_FIXED`
when the call's decl is null.

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

        PR 126133

gcc/ChangeLog:

        * config/aarch64/aarch64.cc (aarch64_update_ipa_fn_target_info):

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                 |  6 ++++--
 gcc/testsuite/gcc.target/aarch64/pr126133-1.c | 19 +++++++++++++++++++
 gcc/testsuite/gcc.target/aarch64/pr126133-2.c | 19 +++++++++++++++++++
 gcc/testsuite/gcc.target/aarch64/pr126133-3.c | 19 +++++++++++++++++++
 4 files changed, 61 insertions(+), 2 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 40b68709dbb1..391dfc9ee6f3 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -22185,15 +22185,17 @@ 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))
+      if (tree decl = gimple_call_fndecl (call))
        {
          /* 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;
        }
+      /* All functions not otherwise annotated are considered non-streaming.  
*/
+      else
+       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..332b15659da2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/pr126133-2.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
+add_helper (uint8x16_t x,uint8x16_t y) /* { dg-error "inlining failed" } */
+{
+  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