https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98135

            Bug ID: 98135
           Summary: arm: Inconsistent automatic selection of FPU variant
                    from -mcpu= and -march= options
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sebastian.hu...@embedded-brains.de
  Target Milestone: ---

Since GCC 8, the FPU variant is derived from -mcpu= and -march= options. This
works well for the code generation by the compiler, but it doesn't work well
for the assembler if -mfpu=auto is not specified on the command line. For
example:

arm-rtems6-gcc -save-temps -c test.c -mthumb -march=armv8-r+crc+simd
-mfloat-abi=hard -wrapper echo
/tmp/sh/rtems/6/lib/gcc/arm-rtems6/10.2.1/cc1 -E -quiet -D__USES_INITFINI__
test.c -mthumb -mfloat-abi=hard -march=armv8-r+crc+simd -fpch-preprocess -o
test.i
/tmp/sh/rtems/6/lib/gcc/arm-rtems6/10.2.1/cc1 -fpreprocessed test.i -quiet
-dumpbase test.c -mthumb -mfloat-abi=hard -march=armv8-r+crc+simd -auxbase test
-o test.s
/tmp/sh/rtems/6/lib64/gcc/arm-rtems6/10.2.1/../../../../arm-rtems6/bin/as
-march=armv8-r+crc -mfloat-abi=hard -meabi=5 -o test.o test.s

The assembler is called without the "+simd".

It is discarded by arm_rewrite_selected_arch() probably because

(gdb) p *entry
$16 = {name = 0x4c1acc "simd", remove = false, alias = false, isa_bits =
{isa_bit_fp_d32, isa_bit_fp_dbl, isa_bit_fp16conv, isa_bit_fpv5, isa_bit_vfpv2,
isa_bit_vfpv3, isa_bit_vfpv4, isa_bit_neon, isa_nobit <repeats 54 times>}}

and

#define ISA_ALL_FPU_INTERNAL \
  isa_bit_fp16conv, \
  isa_bit_crypto, \
  isa_bit_vfpv2, \
  isa_bit_vfpv3, \
  isa_bit_vfpv4, \
  isa_bit_fpv5, \
  isa_bit_neon, \
  isa_bit_fp_dbl, \
  isa_bit_fp_d32

So

(gdb) p/x fpu_bits
$17 = {m_bitmap = 0x778e60}
(gdb) p/x opt_bits
$18 = {m_bitmap = 0x778e20}

    if (!bitmap_subset_p (opt_bits, fpu_bits))
        optlist.push_back (entry->name);

doesn't push back entry->name.

The assembler doesn't complain about a -march=armv8-r+crc+simd and it makes the
assembler error go away. Probably older assembler versions doesn't support it.

What fixes the problem is adding the "-mfpu=auto" option. For example:

arm-rtems6-gcc -save-temps -c test.c -mthumb -march=armv8-a+crc+simd
-mfloat-abi=hard -mfpu=auto -wrapper echo
/tmp/sh/rtems/6/lib/gcc/arm-rtems6/10.2.1/cc1 -E -quiet -D__USES_INITFINI__
test.c -mthumb -mfloat-abi=hard -mfpu=auto -march=armv8-a+crc+simd
-fpch-preprocess -o test.i
/tmp/sh/rtems/6/lib/gcc/arm-rtems6/10.2.1/cc1 -fpreprocessed test.i -quiet
-dumpbase test.c -mthumb -mfloat-abi=hard -mfpu=auto -march=armv8-a+crc+simd
-auxbase test -o test.s
/tmp/sh/rtems/6/lib64/gcc/arm-rtems6/10.2.1/../../../../arm-rtems6/bin/as
-mfpu=neon-fp-armv8 -march=armv8-a+crc -mfloat-abi=hard -meabi=5 -o test.o
test.s

This is not really nice since the -mfpu=auto option seems to have no effect on
the code generation (compiler):

arm-rtems6-gcc -save-temps -E -P -v -dD test.c -mthumb -march=armv8-a+crc+simd
-mfloat-abi=hard -mfpu=auto > auto.txt 2>&1

arm-rtems6-gcc -save-temps -E -P -v -dD test.c -mthumb -march=armv8-a+crc+simd
-mfloat-abi=hard  > noauto.txt 2>&1

diff -u auto.txt noauto.txt
--- auto.txt    2020-12-03 15:18:46.466141382 +0100
+++ noauto.txt  2020-12-03 15:18:52.282185710 +0100
@@ -5,8 +5,8 @@
 Thread model: rtems
 Supported LTO compression algorithms: zlib
 gcc version 10.2.1 20201203 [releases/gcc-10 revision
75a5af680a1:72d226ca97d:3444cb38a4d8df2c198ae5b4bdc747ff0c42a940] (GCC)
-COLLECT_GCC_OPTIONS='-save-temps' '-E' '-P' '-v' '-dD' '-mthumb'
'-mfloat-abi=hard' '-mfpu=auto' '-march=armv8-a+crc+simd'
- /tmp/sh/rtems/6/lib/gcc/arm-rtems6/10.2.1/cc1 -E -quiet -v -P
-D__USES_INITFINI__ test.c -mthumb -mfloat-abi=hard -mfpu=auto
-march=armv8-a+crc+simd -fpch-preprocess -dD
+COLLECT_GCC_OPTIONS='-save-temps' '-E' '-P' '-v' '-dD' '-mthumb'
'-mfloat-abi=hard' '-march=armv8-a+crc+simd'
+ /tmp/sh/rtems/6/lib/gcc/arm-rtems6/10.2.1/cc1 -E -quiet -v -P
-D__USES_INITFINI__ test.c -mthumb -mfloat-abi=hard -march=armv8-a+crc+simd
-fpch-preprocess -dD
 ignoring nonexistent directory
"/tmp/sh/rtems/6/lib64/gcc/arm-rtems6/10.2.1/../../../../arm-rtems6/sys-include"
 #include "..." search starts here:
 #include <...> search starts here:
@@ -466,4 +466,4 @@
 #define __USES_INITFINI__ 1

COMPILER_PATH=/tmp/sh/rtems/6/lib/gcc/arm-rtems6/10.2.1/:/tmp/sh/rtems/6/lib/gcc/arm-rtems6/10.2.1/:/tmp/sh/rtems/6/lib/gcc/arm-rtems6/:/tmp/sh/rtems/6/lib64/gcc/arm-rtems6/10.2.1/:/tmp/sh/rtems/6/lib64/gcc/arm-rtems6/:/tmp/sh/rtems/6/lib64/gcc/arm-rtems6/10.2.1/../../../../arm-rtems6/bin/

LIBRARY_PATH=/tmp/sh/rtems/6/lib64/gcc/arm-rtems6/10.2.1/:/tmp/sh/rtems/6/lib64/gcc/arm-rtems6/10.2.1/../../../../arm-rtems6/lib/
-COLLECT_GCC_OPTIONS='-save-temps' '-E' '-P' '-v' '-dD' '-mthumb'
'-mfloat-abi=hard' '-mfpu=auto' '-march=armv8-a+crc+simd'
+COLLECT_GCC_OPTIONS='-save-temps' '-E' '-P' '-v' '-dD' '-mthumb'
'-mfloat-abi=hard' '-march=armv8-a+crc+simd'

In the documentation

https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html

we have

"The setting ‘auto’ is the default and is special. It causes the compiler to
select the floating-point and Advanced SIMD instructions based on the settings
of -mcpu and -march."

What does "is the default" mean here? Does the mean that it is the behaviour if
-mfpu= is not given? If yes, then I think it doesn't work properly.

The comment before arm_rewrite_selected_arch() is:

/* Rewrite the architecture string for passing to the assembler.
   Although the syntax is similar we cannot assume that it supports
   the newer FP related options.  So strip any option that only
   defines features in the standard -mfpu options out.  We'll generate
   a suitable -mfpu option elsewhere to carry that information.  NAME
   should already have been canonicalized, so we do not expect to
   encounter +no.. options that remove features.  A final problem is
   that the assembler expects the feature extensions to be listed
   alphabetically, so we build a list of required options and then
   sort them into canonical order in the resulting string.  */

Where is the "elsewhere" in "We'll generate a suitable -mfpu option elsewhere
to carry that information."?

Reply via email to