public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-7462] aarch64: Allow compiler to define ls64 builtins [PR110132]
@ 2023-06-20 21:22 Alex Coplan
  0 siblings, 0 replies; only message in thread
From: Alex Coplan @ 2023-06-20 21:22 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4eb01f987606e82ba4b7696f6cf79266d9e242ad

commit r13-7462-g4eb01f987606e82ba4b7696f6cf79266d9e242ad
Author: Alex Coplan <alex.coplan@arm.com>
Date:   Tue Jun 6 15:19:03 2023 +0100

    aarch64: Allow compiler to define ls64 builtins [PR110132]
    
    This patch refactors the ls64 builtins to allow the compiler to define them
    directly instead of having wrapper functions in arm_acle.h. This should be not
    only easier to maintain, but it makes two important correctness fixes:
     - It fixes PR110132, where the builtins ended up getting declared with
       invisible bindings in the C FE, so the FE ended up synthesizing
       incompatible implicit definitions for these builtins.
     - It allows the builtins to be used with LTO, which didn't work previously.
    
    We also take the opportunity to add test coverage from C++ for these
    builtins.
    
    gcc/ChangeLog:
    
            PR target/110132
            * config/aarch64/aarch64-builtins.cc (aarch64_general_simulate_builtin):
            New. Use it ...
            (aarch64_init_ls64_builtins): ... here. Switch to declaring public ACLE
            names for builtins.
            (aarch64_general_init_builtins): Ensure we invoke the arm_acle.h
            setup if in_lto_p, just like we do for SVE.
            * config/aarch64/arm_acle.h: (__arm_ld64b): Delete.
            (__arm_st64b): Delete.
            (__arm_st64bv): Delete.
            (__arm_st64bv0): Delete.
    
    gcc/testsuite/ChangeLog:
    
            PR target/110132
            * lib/target-supports.exp (check_effective_target_aarch64_asm_FUNC_ok):
            Extend to ls64.
            * g++.target/aarch64/acle/acle.exp: New.
            * g++.target/aarch64/acle/ls64.C: New test.
            * g++.target/aarch64/acle/ls64_lto.C: New test.
            * gcc.target/aarch64/acle/ls64_lto.c: New test.
            * gcc.target/aarch64/acle/pr110132.c: New test.
    
    (cherry picked from commit 9963029a24f2d2510b82e7106fae3f364da33c5d)

Diff:
---
 gcc/config/aarch64/aarch64-builtins.cc           | 24 ++++++++++++----
 gcc/config/aarch64/arm_acle.h                    | 33 ----------------------
 gcc/testsuite/g++.target/aarch64/acle/acle.exp   | 35 ++++++++++++++++++++++++
 gcc/testsuite/g++.target/aarch64/acle/ls64.C     | 10 +++++++
 gcc/testsuite/g++.target/aarch64/acle/ls64_lto.C | 10 +++++++
 gcc/testsuite/gcc.target/aarch64/acle/ls64_lto.c | 10 +++++++
 gcc/testsuite/gcc.target/aarch64/acle/pr110132.c | 15 ++++++++++
 gcc/testsuite/lib/target-supports.exp            |  2 +-
 8 files changed, 100 insertions(+), 39 deletions(-)

diff --git a/gcc/config/aarch64/aarch64-builtins.cc b/gcc/config/aarch64/aarch64-builtins.cc
index 285a43e3cbd..dd9f1150165 100644
--- a/gcc/config/aarch64/aarch64-builtins.cc
+++ b/gcc/config/aarch64/aarch64-builtins.cc
@@ -933,6 +933,16 @@ aarch64_general_add_builtin (const char *name, tree type, unsigned int code,
 			       NULL, attrs);
 }
 
+static tree
+aarch64_general_simulate_builtin (const char *name, tree fntype,
+				  unsigned int code,
+				  tree attrs = NULL_TREE)
+{
+  code = (code << AARCH64_BUILTIN_SHIFT) | AARCH64_BUILTIN_GENERAL;
+  return simulate_builtin_function_decl (input_location, name, fntype,
+					 code, NULL, attrs);
+}
+
 static const char *
 aarch64_mangle_builtin_scalar_type (const_tree type)
 {
@@ -1856,23 +1866,24 @@ aarch64_init_ls64_builtins (void)
   aarch64_init_ls64_builtins_types ();
 
   ls64_builtins_data data[4] = {
-    {"__builtin_aarch64_ld64b", AARCH64_LS64_BUILTIN_LD64B,
+    {"__arm_ld64b", AARCH64_LS64_BUILTIN_LD64B,
      build_function_type_list (ls64_arm_data_t,
 			       const_ptr_type_node, NULL_TREE)},
-    {"__builtin_aarch64_st64b", AARCH64_LS64_BUILTIN_ST64B,
+    {"__arm_st64b", AARCH64_LS64_BUILTIN_ST64B,
      build_function_type_list (void_type_node, ptr_type_node,
 			       ls64_arm_data_t, NULL_TREE)},
-    {"__builtin_aarch64_st64bv", AARCH64_LS64_BUILTIN_ST64BV,
+    {"__arm_st64bv", AARCH64_LS64_BUILTIN_ST64BV,
      build_function_type_list (uint64_type_node, ptr_type_node,
 			       ls64_arm_data_t, NULL_TREE)},
-    {"__builtin_aarch64_st64bv0", AARCH64_LS64_BUILTIN_ST64BV0,
+    {"__arm_st64bv0", AARCH64_LS64_BUILTIN_ST64BV0,
      build_function_type_list (uint64_type_node, ptr_type_node,
 			       ls64_arm_data_t, NULL_TREE)},
   };
 
   for (size_t i = 0; i < ARRAY_SIZE (data); ++i)
     aarch64_builtin_decls[data[i].code]
-      = aarch64_general_add_builtin (data[i].name, data[i].type, data[i].code);
+      = aarch64_general_simulate_builtin (data[i].name, data[i].type,
+					  data[i].code);
 }
 
 static void
@@ -2005,6 +2016,9 @@ aarch64_general_init_builtins (void)
 
   if (TARGET_MEMTAG)
     aarch64_init_memtag_builtins ();
+
+  if (in_lto_p)
+    handle_arm_acle_h ();
 }
 
 /* Implement TARGET_BUILTIN_DECL for the AARCH64_BUILTIN_GENERAL group.  */
diff --git a/gcc/config/aarch64/arm_acle.h b/gcc/config/aarch64/arm_acle.h
index e0ac591d2c8..3b6b63e6805 100644
--- a/gcc/config/aarch64/arm_acle.h
+++ b/gcc/config/aarch64/arm_acle.h
@@ -270,40 +270,7 @@ __ttest (void)
 #endif
 
 #ifdef __ARM_FEATURE_LS64
-#pragma GCC push_options
-#pragma GCC target ("+nothing+ls64")
-
 typedef __arm_data512_t data512_t;
-
-__extension__ extern __inline data512_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-__arm_ld64b (const void *__addr)
-{
-  return __builtin_aarch64_ld64b (__addr);
-}
-
-__extension__ extern __inline void
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-__arm_st64b (void *__addr, data512_t __value)
-{
-  __builtin_aarch64_st64b (__addr, __value);
-}
-
-__extension__ extern __inline uint64_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-__arm_st64bv (void *__addr, data512_t __value)
-{
-  return __builtin_aarch64_st64bv (__addr, __value);
-}
-
-__extension__ extern __inline uint64_t
-__attribute__ ((__always_inline__, __gnu_inline__, __artificial__))
-__arm_st64bv0 (void *__addr, data512_t __value)
-{
-  return __builtin_aarch64_st64bv0 (__addr, __value);
-}
-
-#pragma GCC pop_options
 #endif
 
 #pragma GCC push_options
diff --git a/gcc/testsuite/g++.target/aarch64/acle/acle.exp b/gcc/testsuite/g++.target/aarch64/acle/acle.exp
new file mode 100644
index 00000000000..9e1cbf4a0c6
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/acle/acle.exp
@@ -0,0 +1,35 @@
+# Copyright (C) 2014-2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Exit immediately if this isn't an AArch64 target.
+if ![istarget aarch64*-*-*] then {
+  return
+}
+
+# Load support procs.
+load_lib g++-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cCS\]]] \
+	"" ""
+
+# All done.
+dg-finish
diff --git a/gcc/testsuite/g++.target/aarch64/acle/ls64.C b/gcc/testsuite/g++.target/aarch64/acle/ls64.C
new file mode 100644
index 00000000000..d9002785b57
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/acle/ls64.C
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=armv8.7-a" } */
+#include <arm_acle.h>
+int main()
+{
+  data512_t d = __arm_ld64b ((const void *)0x1000);
+  __arm_st64b ((void *)0x2000, d);
+  uint64_t x = __arm_st64bv ((void *)0x3000, d);
+  x += __arm_st64bv0 ((void *)0x4000, d);
+}
diff --git a/gcc/testsuite/g++.target/aarch64/acle/ls64_lto.C b/gcc/testsuite/g++.target/aarch64/acle/ls64_lto.C
new file mode 100644
index 00000000000..274a4771e1c
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/acle/ls64_lto.C
@@ -0,0 +1,10 @@
+/* { dg-do link { target aarch64_asm_ls64_ok } } */
+/* { dg-additional-options "-march=armv8.7-a -flto" } */
+#include <arm_acle.h>
+int main()
+{
+  data512_t d = __arm_ld64b ((const void *)0x1000);
+  __arm_st64b ((void *)0x2000, d);
+  uint64_t x = __arm_st64bv ((void *)0x3000, d);
+  x += __arm_st64bv0 ((void *)0x4000, d);
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/acle/ls64_lto.c b/gcc/testsuite/gcc.target/aarch64/acle/ls64_lto.c
new file mode 100644
index 00000000000..8b4f2427771
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/acle/ls64_lto.c
@@ -0,0 +1,10 @@
+/* { dg-do link { target aarch64_asm_ls64_ok } } */
+/* { dg-additional-options "-march=armv8.7-a -flto" } */
+#include <arm_acle.h>
+int main(void)
+{
+  data512_t d = __arm_ld64b ((const void *)0x1000);
+  __arm_st64b ((void *)0x2000, d);
+  uint64_t x = __arm_st64bv ((void *)0x3000, d);
+  x += __arm_st64bv0 ((void *)0x4000, d);
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/acle/pr110132.c b/gcc/testsuite/gcc.target/aarch64/acle/pr110132.c
new file mode 100644
index 00000000000..fb88d633dd2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/acle/pr110132.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=armv8.7-a" } */
+
+/* Check that ls64 builtins can be invoked using a preprocesed testcase
+   without triggering bogus builtin warnings, see PR110132.
+
+   Note that this is purely to test GCC internals and user code should
+   include arm_acle.h to make use of these builtins.  */
+
+#pragma GCC aarch64 "arm_acle.h"
+typedef __arm_data512_t data512_t;
+void f(void *p, data512_t d)
+{
+  __arm_st64b (p, d);
+}
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 868e2c4f092..40f71e9ed8b 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -10953,7 +10953,7 @@ proc check_effective_target_aarch64_tiny { } {
 # various architecture extensions via the .arch_extension pseudo-op.
 
 foreach { aarch64_ext } { "fp" "simd" "crypto" "crc" "lse" "dotprod" "sve"
-			  "i8mm" "f32mm" "f64mm" "bf16" "sb" "sve2" } {
+			  "i8mm" "f32mm" "f64mm" "bf16" "sb" "sve2" "ls64" } {
     eval [string map [list FUNC $aarch64_ext] {
 	proc check_effective_target_aarch64_asm_FUNC_ok { } {
 	  if { [istarget aarch64*-*-*] } {

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-20 21:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-20 21:22 [gcc r13-7462] aarch64: Allow compiler to define ls64 builtins [PR110132] Alex Coplan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).