On 11/11/26 08:28, Torbjorn SVENSSON wrote:
Hi Christophe,

On 2026-11-10 15:37, Christophe Lyon wrote:
When running the testsute with non-default RUNTESTFLAGS,
arm_fp16_ok_nocache may insert -mfpu=vfpv4 if needed.

However, if RUNTESTFLAGS uses an incompatible -mcpu, we can end up
generating invalid code.

For instance, if RUNTESTFLAGS uses
-mthumb/-mcpu=cortex-m33/-mfloat-abi=hard/-march=unset,
we compile gcc.target/arm/aapcs/vfp19.c with
-mthumb -mcpu=cortex-m33 -mfloat-abi=hard -march=unset [...] - mfpu=vfpv4 -mfp16-format=ieee
and this enables GCC to generate instructions such as
vmov    d17, r0, r1
which is incorrect because cortex-m33 supports only 16 D registers.

This patch avoid this by not adding -mfpu=vfpv4 to the list if the
user forced a -mcpu flag.  This is conservative, but there is no way
to reliably detect whether -mfpu=vfpv4 is compatible with the current
flags.

With the patch, vfp18.c, vfp19.c, vfp22.c and vfp23.c are now
UNSUPPORTED in this configuration, instead of failing at execution
time.

I've tested this with my usual targets on arm-none-eabi and it resolves most
of the failures, but I still see these:

FAIL: gcc.target/arm/aapcs/vfp18.c execution test
FAIL: gcc.target/arm/aapcs/vfp19.c execution test
FAIL: gcc.target/arm/aapcs/vfp22.c execution test
FAIL: gcc.target/arm/aapcs/vfp23.c execution test

for:

thumb/arch=armv7e-m+fp/tune=cortex-m4/float-abi=hard/fpu=auto
thumb/arch=armv8-m.main+dsp+fp/tune=cortex-m33/float-abi=hard/fpu=auto

maybe these are expected, maybe the are supposed to pass.

If I instead use

thumb/arch=armv7e-m+fp/cpu=cortex-m4/float-abi=hard/fpu=auto

then the same tests are marked as unsupported.


Yes, that's what I tried to explain with:
    This is conservative, but there is no way to reliably detect
    whether -mfpu=vfpv4 is compatible with the current flags

The configurations we use for testing use -mcpu instead of the -march/-mtune combination (-mtune has proven to cause quite a few problems with tests where codegen is sensitive to that setting, but does not actually impact what the test is supposed to check).




gcc/testsuite/ChangeLog:

    PR testsuite/126082
    * lib/target-supports.exp (arm_fp16_ok_nocache): Try -mfpu=vfpv4
    only if -mcpu is not overridden.
---
  gcc/testsuite/lib/target-supports.exp | 13 +++++++++----
  1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/ lib/target-supports.exp
index 3ce06189d2e..1f61da72aea 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -6481,14 +6481,19 @@ proc check_effective_target_arm_fp16_ok_nocache { } {
      }
      global et_arm_fp16_flags
      set et_arm_fp16_flags ""
-    foreach flags {
+    set flags_list {
      ""
      "-mfloat-abi=softfp"
      "-mfpu=auto"
      "-mfloat-abi=softfp -mfpu=auto"
-    "-mfpu=vfpv4"
-    "-mfloat-abi=softfp -mfpu=vfpv4"
-    } {
+    }
+
+    if { ![check-flags [list "" { *-*-* } { "-mcpu=*" } { "" } ]] } {

To resolve the 2 targets that are failing, I think this also needs to
check for -mtune, but I could be wrong.

That would probably work in your case, since you use -mtune and arm_fp16_ok would no longer try to add -mfpu=vfpv4.


For -mcpu, the arm_fp16_ok check fails.

+    lappend flags_list "-mfpu=vfpv4"

For -march only, the above flags makes the arm_fp16_ok check succeed,
but it does not work for execution.


Yes, that's the same problem as this patch is trying to avoid: GCC is able to generate code with incompatible -march and -mfpu settings (incompatible in the sense that no HW supports that combo). So we enable -mfpu=vfpv4 and execute the resulting code on an arch which does not support it (assuming your execution engine matches what you have in -march)

A more conservative approach would be not to add -mfpu=vfpv4 if any of -mcpu/-mtune/-march is present, but that would reduce our coverage (making the tests UNSUPPORTED for most/all the configurations we use).

We cannot exclude M-profile, because for instance cortex-m55 has support for FP16. It would be easier if GCC rejected incompatible -mfpu and -mcpu/-march flags :-)

Thanks,

Christophe


Kind regards,
Torbjörn


+    lappend flags_list "-mfloat-abi=softfp -mfpu=vfpv4"
+    }
+
+    foreach flags $flags_list {
      if { [check_no_compiler_messages_nocache arm_fp16_ok assembly {
          #ifndef __ARM_FP
          #error __ARM_FP not defined


Reply via email to