]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
arm: [MVE intrinsics] Avoid warnings when floating-point is not supported [PR 117814]
authorChristophe Lyon <christophe.lyon@linaro.org>
Thu, 18 Sep 2025 23:16:32 +0000 (23:16 +0000)
committerChristophe Lyon <christophe.lyon@linaro.org>
Tue, 18 Nov 2025 17:02:32 +0000 (17:02 +0000)
If the target does not support floating-point, we register FP vector
types as 'void' (see register_vector_type).

This leads to warnings about 'pure attribute on function returning
void' when we declare the various load intrinsics because their
call_properties say CP_READ_MEMORY (thus giving them the 'pure'
attribute), but their return type is void.  This happens for instance
in gcc.target/arm/pr112337.c, depending on how GCC is built (I didn't
notice the warnings because arm_mve.h is considered as a system
include in my environment, and the warning is not emitted, but CI
reported it).

To avoid such warnings, declare floating-point scalar and vector types
even if the target does not have an FPU.

Note that since an FPU can be activated via #pragma GCC target
("arch=armv8.1-m.main+mve.fp" for instance), it means that such types
cannot appear and disappear withing a single TU, they have to be
available in all contexts.  This implies a noteworthy change for
__fp16: it not longer depends on using -mfp16-format=ieee or
alternative.  Also note that if the target ISA has the fp16 bit set,
we already silently activate -mfp16-format=ieee (with an error if
-mfp16-format=alternative was supplied).  The patch now enforces
-mfp16-format=none if the option was used.

In arm-mve-builtins.cc (register_builtin_types, register_vector_type,
register_builtin_tuple_types), this means simply removing the early
exits.  However, for this to work, we need to update
arm_vector_mode_supported_p, so that vector floating-point types are
always defined, and __fp16 must always be registered by
arm_init_fp16_builtins (as it is the base type for vectors of
float16_t.  Another side effect is that the declaration of float16_t
and float32_t typedefs is now unconditional.

The new tests verify that:
- we emit an error if the code tries to use floating-point intrinsics
  and the target does not have the floating-point extension
- we emit the expected code when activating the floating-point
  expected via a pragma
- we emit the expected code when the target supports floating-point
  (no pragma needed)
- we apply -mfp16-format=none where we used to default to ieee

An update is needed in g++.target/arm/mve/general-c++/nomve_fp_1.c,
because the error message now correctly uses float16x8_t instead of
void as return type.

The patch removes gcc.target/arm/fp16-compile-none-1.c which tests
that using __fp16 produces an error with -mfp16-format=none, since it
is no longer the case.

gcc/ChangeLog:

PR target/117814
* config/arm/arm-builtins.cc (arm_init_fp16_builtins): Always
register __fp16 type.
* config/arm/arm-mve-builtins.cc (register_builtin_tuple_types):
Remove special handling when TARGET_HAVE_MVE_FLOAT is false.
(register_vector_type): Likewise.
(register_builtin_tuple_types): Likewise.
* config/arm/arm-opts.h (arm_fp16_format_type): Add
ARM_FP16_FORMAT_DEFAULT.
* config/arm/arm.cc (arm_vector_mode_supported_p): Accept
floating-point vector modes even if TARGET_HAVE_MVE_FLOAT is
false.
(arm_option_reconfigure_globals): Apply ARM_FP16_FORMAT_NONE if
requested.
* config/arm/arm.opt (mfp16-format): Default to
ARM_FP16_FORMAT_DEFAULT.
* config/arm/arm_mve_types.h (float16_t, float32_t): Define
unconditionally.
* doc/sourcebuild.texi (ARM-specific attributes): Document
arm_v8_1m_mve_nofp_ok.

gcc/testsuite/ChangeLog:

PR target/117814
* gcc.target/arm/mve/intrinsics/pr117814-f16.c: New test.
* gcc.target/arm/mve/intrinsics/pr117814-2-f16.c: New test.
* gcc.target/arm/mve/intrinsics/pr117814-3-f16.c: New test.
* gcc.target/arm/mve/intrinsics/pr117814-4-f16.c: New test.
* gcc.target/arm/mve/intrinsics/pr117814-f32.c: New test.
* gcc.target/arm/mve/intrinsics/pr117814-2-f32.c: New test.
* gcc.target/arm/mve/intrinsics/pr117814-3-f32.c: New test.
* gcc.target/arm/fp16-compile-none-1.c: Delete.
* g++.target/arm/mve/general-c++/nomve_fp_1.c: Fix expected error
message.
* lib/target-supports.exp
(check_effective_target_arm_v8_1m_mve_nofp_ok_nocache): New.
(check_effective_target_arm_v8_1m_mve_nofp_ok): New.
(add_options_for_arm_v8_1m_mve_nofp): New.

17 files changed:
gcc/config/arm/arm-builtins.cc
gcc/config/arm/arm-mve-builtins.cc
gcc/config/arm/arm-opts.h
gcc/config/arm/arm.cc
gcc/config/arm/arm.opt
gcc/config/arm/arm_mve_types.h
gcc/doc/sourcebuild.texi
gcc/testsuite/g++.target/arm/mve/general-c++/nomve_fp_1.c
gcc/testsuite/gcc.target/arm/fp16-compile-none-1.c [deleted file]
gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-2-f16.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-2-f32.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-3-f16.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-3-f32.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-4-f16.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-f16.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-f32.c [new file with mode: 0644]
gcc/testsuite/lib/target-supports.exp

index 3bb2566f9a2f38363bbc754d7503563d158f7f52..b0bbb32644c5dab231d0546cb5c1b19a1d502671 100644 (file)
@@ -1685,9 +1685,7 @@ arm_init_fp16_builtins (void)
   arm_fp16_type_node = make_node (REAL_TYPE);
   TYPE_PRECISION (arm_fp16_type_node) = GET_MODE_PRECISION (HFmode);
   layout_type (arm_fp16_type_node);
-  if (arm_fp16_format)
-    (*lang_hooks.types.register_builtin_type) (arm_fp16_type_node,
-                                              "__fp16");
+  (*lang_hooks.types.register_builtin_type) (arm_fp16_type_node, "__fp16");
 }
 
 void
index 42b53cc05e777e8c63789784e10cfcc9a0190154..b37c91c541bc1a7ff72a3771413db9b5afaaedc8 100644 (file)
@@ -410,8 +410,6 @@ register_builtin_types ()
 #include "arm-mve-builtins.def"
   for (unsigned int i = 0; i < NUM_VECTOR_TYPES; ++i)
     {
-      if (vector_types[i].requires_float && !TARGET_HAVE_MVE_FLOAT)
-       continue;
       tree eltype = scalar_types[i];
       tree vectype;
       if (eltype == boolean_type_node)
@@ -433,18 +431,6 @@ register_builtin_types ()
 static void
 register_vector_type (vector_type_index type)
 {
-
-  /* If the target does not have the mve.fp extension, but the type requires
-     it, then it needs to be assigned a non-dummy type so that functions
-     with those types in their signature can be registered.  This allows for
-     diagnostics about the missing extension, rather than about a missing
-     function definition.  */
-  if (vector_types[type].requires_float && !TARGET_HAVE_MVE_FLOAT)
-    {
-      acle_vector_types[0][type] = void_type_node;
-      return;
-    }
-
   tree vectype = abi_vector_types[type];
   tree id = get_identifier (vector_types[type].acle_name);
   tree decl = build_decl (input_location, TYPE_DECL, id, vectype);
@@ -470,13 +456,7 @@ register_builtin_tuple_types (vector_type_index type)
 {
   const vector_type_info* info = &vector_types[type];
 
-  /* If the target does not have the mve.fp extension, but the type requires
-     it, then it needs to be assigned a non-dummy type so that functions
-     with those types in their signature can be registered.  This allows for
-     diagnostics about the missing extension, rather than about a missing
-     function definition.  */
-  if (scalar_types[type] == boolean_type_node
-      || (info->requires_float && !TARGET_HAVE_MVE_FLOAT))
+  if (scalar_types[type] == boolean_type_node)
     {
       for (unsigned int num_vectors = 2; num_vectors <= 4; num_vectors += 2)
        acle_vector_types[num_vectors >> 1][type] = void_type_node;
index 5c543bf52466726d94f673993f9e19475576b706..d2384edb542b9a41d611bd368950453fd8fb7a50 100644 (file)
@@ -35,6 +35,7 @@
  */
 enum arm_fp16_format_type
 {
+  ARM_FP16_FORMAT_DEFAULT = -1,
   ARM_FP16_FORMAT_NONE = 0,
   ARM_FP16_FORMAT_IEEE = 1,
   ARM_FP16_FORMAT_ALTERNATIVE = 2
index 9dbc3f9befafc7a11c7f3bacb5463645bc154e64..07d24d1f67ed6ac310eadd5c202585f18f43ad6a 100644 (file)
@@ -3923,13 +3923,19 @@ arm_option_reconfigure_globals (void)
   arm_arch_bf16 = bitmap_bit_p (arm_active_target.isa, isa_bit_bf16);
 
   arm_fp16_inst = bitmap_bit_p (arm_active_target.isa, isa_bit_fp16);
-  if (arm_fp16_inst)
+
+  /* Set arm_fp16_format to IEEE if the target has fp16 support unless user
+     forced ARM_FP16_FORMAT_NONE.  */
+  if (arm_fp16_inst && (arm_fp16_format != ARM_FP16_FORMAT_NONE))
     {
       if (arm_fp16_format == ARM_FP16_FORMAT_ALTERNATIVE)
        error ("selected fp16 options are incompatible");
       arm_fp16_format = ARM_FP16_FORMAT_IEEE;
     }
 
+  if (arm_fp16_format == ARM_FP16_FORMAT_DEFAULT)
+    arm_fp16_format = ARM_FP16_FORMAT_NONE;
+
   arm_arch_cde = 0;
   arm_arch_cde_coproc = 0;
   int cde_bits[] = {isa_bit_cdecp0, isa_bit_cdecp1, isa_bit_cdecp2,
@@ -29639,11 +29645,7 @@ arm_vector_mode_supported_p (machine_mode mode)
     return true;
 
   if (TARGET_HAVE_MVE
-      && (VALID_MVE_SI_MODE (mode) || VALID_MVE_PRED_MODE (mode)))
-    return true;
-
-  if (TARGET_HAVE_MVE_FLOAT
-      && (mode == V2DFmode || mode == V4SFmode || mode == V8HFmode))
+      && (VALID_MVE_MODE (mode) || VALID_MVE_PRED_MODE (mode)))
     return true;
 
   return false;
index d5eeeae7eaefa9354edede6f1919c4b663059f7c..caa08d120cef1b7884522c280852df3cad6f66ae 100644 (file)
@@ -139,7 +139,7 @@ Target Var(TARGET_FLIP_THUMB) Undocumented
 Switch ARM/Thumb modes on alternating functions for compiler testing.
 
 mfp16-format=
-Target RejectNegative Joined Enum(arm_fp16_format_type) Var(arm_fp16_format) Init(ARM_FP16_FORMAT_NONE)
+Target RejectNegative Joined Enum(arm_fp16_format_type) Var(arm_fp16_format) Init(ARM_FP16_FORMAT_DEFAULT)
 Specify the __fp16 floating-point format.
 
 Enum
index 42e74666e80b28ae15937aeb34afb369287ab3f2..d1889c68ac53f4a333562da1513d2524aef12ade 100644 (file)
 #ifndef _GCC_ARM_MVE_TYPES_H
 #define _GCC_ARM_MVE_TYPES_H
 
-#if (__ARM_FEATURE_MVE & 2) /* MVE Floating point.  */
 typedef __fp16 float16_t;
 typedef float float32_t;
-#endif
 
 #pragma GCC arm "arm_mve_types.h"
 
index fc1d52c42c9ed828bd3088edcaeba13546f5975b..c51c8f3c4424c2b142a3749e1c523f76469f0314 100644 (file)
@@ -2219,6 +2219,12 @@ the Half-precision floating-point instructions (HP), Floating-point Extension
 (FP) along with M-Profile Vector Extension (MVE). Some multilibs may be
 incompatible with these options.
 
+@item arm_v8_1m_mve_nofp_ok
+ARM target supports options to generate instructions from ARMv8.1-M
+with the M-Profile Vector Extension (MVE) but without the
+Half-precision floating-point instructions (HP) and Floating-point
+Extension (FP). Some multilibs may be incompatible with these options.
+
 @item arm_mve_hw
 Test system supports executing MVE instructions.
 
index fd8c05b0eed4ecc7c41cf9caf9cf875fcc4c97b1..4b91e0c6327b4203c350bcac1d8e6e75431181ed 100644 (file)
@@ -12,6 +12,6 @@
 void
 f1 (uint8x16_t v)
 {
-  vreinterpretq_f16 (v); /* { dg-error {ACLE function 'void vreinterpretq_f16\(uint8x16_t\)' requires ISA extension 'mve.fp'} } */
+  vreinterpretq_f16 (v); /* { dg-error {ACLE function 'float16x8_t vreinterpretq_f16\(uint8x16_t\)' requires ISA extension 'mve.fp'} } */
   /* { dg-message {note: you can enable mve.fp by using the command-line option '-march', or by using the 'target' attribute or pragma} "" {target *-*-*} .-1 } */
 }
diff --git a/gcc/testsuite/gcc.target/arm/fp16-compile-none-1.c b/gcc/testsuite/gcc.target/arm/fp16-compile-none-1.c
deleted file mode 100644 (file)
index 9472249..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-/* { dg-do compile } */
-/* { dg-require-effective-target arm_fp16_none_ok } */
-/* { dg-options "-mfp16-format=none" } */
-
-/* __fp16 type name is not recognized unless you explicitly enable it
-   by selecting -mfp16-format=ieee or -mfp16-format=alternative.  */
-__fp16 xx = 0.0;  /* { dg-error "unknown type name" } */
diff --git a/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-2-f16.c b/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-2-f16.c
new file mode 100644 (file)
index 0000000..046cad0
--- /dev/null
@@ -0,0 +1,30 @@
+/* Check that we can compile if the target does not support floating-point, but
+   we use a pragma to enable FP support locally.  */
+
+/* { dg-require-effective-target arm_v8_1m_mve_nofp_ok } */
+/* { dg-add-options arm_v8_1m_mve_nofp } */
+/* { dg-additional-options "-O2" } */
+
+#include "arm_mve.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#pragma GCC target ("arch=armv8.1-m.main+mve.fp")
+
+/*
+**foo:
+**     ...
+**     vldrh.16        q[0-9]+, \[(?:ip|fp|r[0-9]+)\](?:       @.*|) 
+**     ...
+*/
+float16x8_t
+foo (float16_t const *base)
+{
+  return vld1q_f16 (base);
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-2-f32.c b/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-2-f32.c
new file mode 100644 (file)
index 0000000..6856e8e
--- /dev/null
@@ -0,0 +1,30 @@
+/* Check that we can compile if the target does not support floating-point, but
+   we use a pragma to enable FP support locally.  */
+
+/* { dg-require-effective-target arm_v8_1m_mve_nofp_ok } */
+/* { dg-add-options arm_v8_1m_mve_nofp } */
+/* { dg-additional-options "-O2" } */
+
+#include "arm_mve.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#pragma GCC target ("arch=armv8.1-m.main+mve.fp")
+
+/*
+**foo:
+**     ...
+**     vldrw.32        q[0-9]+, \[(?:ip|fp|r[0-9]+)\](?:       @.*|)
+**     ...
+*/
+float32x4_t
+foo (float32_t const *base)
+{
+  return vld1q_f32 (base);
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-3-f16.c b/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-3-f16.c
new file mode 100644 (file)
index 0000000..bcb0dd6
--- /dev/null
@@ -0,0 +1,21 @@
+/* Check that we can compile if the target supports floating-point.  */
+
+/* { dg-require-effective-target arm_v8_1m_mve_fp_ok } */
+/* { dg-add-options arm_v8_1m_mve_fp } */
+/* { dg-additional-options "-O2" } */
+
+#include "arm_mve.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+float16x8_t
+foo (float16_t const *base)
+{
+  return vld1q_f16 (base);
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-3-f32.c b/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-3-f32.c
new file mode 100644 (file)
index 0000000..7e02816
--- /dev/null
@@ -0,0 +1,21 @@
+/* Check that we can compile if the target supports floating-point.  */
+
+/* { dg-require-effective-target arm_v8_1m_mve_fp_ok } */
+/* { dg-add-options arm_v8_1m_mve_fp } */
+/* { dg-additional-options "-O2" } */
+
+#include "arm_mve.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+float32x4_t
+foo (float32_t const *base)
+{
+  return vld1q_f32 (base);
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-4-f16.c b/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-4-f16.c
new file mode 100644 (file)
index 0000000..b266f1b
--- /dev/null
@@ -0,0 +1,23 @@
+/* Check that -mfp16-format=none works.  */
+
+/* { dg-require-effective-target arm_v8_1m_mve_fp_ok } */
+/* { dg-add-options arm_v8_1m_mve_fp } */
+/* { dg-additional-options "-O2 -mfp16-format=none" } */
+
+#include "arm_mve.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+float16x8_t
+foo (float16_t const *base)
+{
+  return vld1q_f16 (base);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+/* { dg-final { scan-assembler-not {eabi_attribute 38,} } } */
diff --git a/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-f16.c b/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-f16.c
new file mode 100644 (file)
index 0000000..88930c1
--- /dev/null
@@ -0,0 +1,22 @@
+/* Check that we get an error if the target does not support floating-point: we
+   force +mve to cancel a possible implicit +mve.fp.  */
+
+/* { dg-require-effective-target arm_v8_1m_mve_nofp_ok } */
+/* { dg-add-options arm_v8_1m_mve_nofp } */
+/* { dg-additional-options "-O2" } */
+
+#include "arm_mve.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+float16x8_t
+foo (float16_t const *base)
+{
+  return vld1q_f16 (base);  /* { dg-error {ACLE function '.*vld1q_f16.*' requires ISA extension 'mve.fp'} } */
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-f32.c b/gcc/testsuite/gcc.target/arm/mve/intrinsics/pr117814-f32.c
new file mode 100644 (file)
index 0000000..814e781
--- /dev/null
@@ -0,0 +1,22 @@
+/* Check that we get an error if the target does not support floating-point: we
+   force +mve to cancel a possible implicit +mve.fp.  */
+
+/* { dg-require-effective-target arm_v8_1m_mve_nofp_ok } */
+/* { dg-add-options arm_v8_1m_mve_nofp } */
+/* { dg-additional-options "-O2" } */
+
+#include "arm_mve.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+float32x4_t
+foo (float32_t const *base)
+{
+  return vld1q_f32 (base);  /* { dg-error {ACLE function '.*vld1q_f32.*' requires ISA extension 'mve.fp'} } */
+}
+
+#ifdef __cplusplus
+}
+#endif
index 67f1a3c82303caa8f5e520dde977caabe0d2c61d..b00e11e2ae525fe03e32635e2cf36cf21eac7cf4 100644 (file)
@@ -6963,6 +6963,60 @@ proc add_options_for_arm_v8_1m_mve { flags } {
     return "$flags $et_arm_v8_1m_mve_flags"
 }
 
+# Return 1 if the target supports ARMv8.1-M MVE without floating point
+# instructions, 0 otherwise.  The test is valid for ARM.
+# Record the command line options needed.
+
+proc check_effective_target_arm_v8_1m_mve_nofp_ok_nocache { } {
+    global et_arm_v8_1m_mve_nofp_flags
+    set et_arm_v8_1m_mve_nofp_flags ""
+
+    if { ![istarget arm*-*-*] } {
+       return 0;
+    }
+
+    # Iterate through sets of options to find the compiler flags that
+    # need to be added to the -march option.
+    foreach flags {
+       ""
+       "-mfloat-abi=softfp"
+       "-mfpu=auto -mcpu=unset -march=armv8.1-m.main+mve"
+       "-mfpu=auto -mcpu=unset -march=armv8.1-m.main+mve -mfloat-abi=softfp"
+    } {
+       if { [check_no_compiler_messages_nocache \
+                 arm_v8_1m_mve_ok object {
+           #if !defined (__ARM_FEATURE_MVE)
+           #error "__ARM_FEATURE_MVE not defined"
+           #endif
+           #if (__ARM_FEATURE_MVE & 2)
+           #error "__ARM_FEATURE_MVE for floating point defined"
+           #endif
+           #if __ARM_BIG_ENDIAN
+           #error "MVE intrinsics are not supported in Big-Endian mode."
+           #endif
+           #include <arm_mve.h>
+       } "$flags -mthumb"] } {
+           set et_arm_v8_1m_mve_nofp_flags "$flags -mthumb --save-temps"
+           return 1
+       }
+    }
+
+    return 0;
+}
+
+proc check_effective_target_arm_v8_1m_mve_nofp_ok { } {
+    return [check_cached_effective_target arm_v8_1m_mve_nofp_ok \
+               check_effective_target_arm_v8_1m_mve_nofp_ok_nocache]
+}
+
+proc add_options_for_arm_v8_1m_mve_nofp { flags } {
+    if { ! [check_effective_target_arm_v8_1m_mve_nofp_ok] } {
+       return "$flags"
+    }
+    global et_arm_v8_1m_mve_nofp_flags
+    return "$flags $et_arm_v8_1m_mve_nofp_flags"
+}
+
 proc check_effective_target_arm_v8_2a_dotprod_neon_ok { } {
     return [check_cached_effective_target arm_v8_2a_dotprod_neon_ok \
                check_effective_target_arm_v8_2a_dotprod_neon_ok_nocache]