]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Fix __builtin_apply with -mgeneral-regs-only [PR113486]
authorAndrew Pinski <quic_apinski@quicinc.com>
Thu, 18 Jan 2024 18:40:04 +0000 (10:40 -0800)
committerAndrew Pinski <quic_apinski@quicinc.com>
Wed, 24 Jan 2024 17:49:24 +0000 (09:49 -0800)
The problem here is the builtin apply mechanism thinks the FP registers
are to be used due to get_raw_arg_mode not returning VOIDmode. This
fixes that oversight and the backend now returns VOIDmode for non-general-regs
if TARGET_GENERAL_REGS_ONLY is true.

Built and tested for aarch64-linux-gnu with no regressions.

PR target/113486

gcc/ChangeLog:

* config/aarch64/aarch64.cc (aarch64_get_reg_raw_mode): For
TARGET_GENERAL_REGS_ONLY, return VOIDmode for non-GP_REGNUM_P regno.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/builtin_apply-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/config/aarch64/aarch64.cc
gcc/testsuite/gcc.target/aarch64/builtin_apply-1.c [new file with mode: 0644]

index c54b6067949a19641fabbe43636efca8cc85abd4..3d6dd98c5c5b79388a706f9abf353704035f9546 100644 (file)
@@ -7221,6 +7221,10 @@ aarch64_function_arg_boundary (machine_mode mode, const_tree type)
 static fixed_size_mode
 aarch64_get_reg_raw_mode (int regno)
 {
+  /* Don't use any non GP registers for __builtin_apply and
+     __builtin_return if general registers only mode is requested. */
+  if (TARGET_GENERAL_REGS_ONLY && !GP_REGNUM_P (regno))
+    return as_a <fixed_size_mode> (VOIDmode);
   if (TARGET_SVE && FP_REGNUM_P (regno))
     /* Don't use the SVE part of the register for __builtin_apply and
        __builtin_return.  The SVE registers aren't used by the normal PCS,
diff --git a/gcc/testsuite/gcc.target/aarch64/builtin_apply-1.c b/gcc/testsuite/gcc.target/aarch64/builtin_apply-1.c
new file mode 100644 (file)
index 0000000..d70abe0
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-mgeneral-regs-only" } */
+/* PR target/113486 */
+
+
+/* __builtin_apply should not use FP registers if 
+   general registers only mode is requested. */
+void
+foo (void)
+{
+  __builtin_apply (foo, 0, 0);
+}