[2/9] LoongArch: Fix default ISA setting
Checks
Commit Message
When loongarch_arch_target is called, la_target has not been
initialized, thus the macro LARCH_ACTUAL_ARCH always equals to zero.
This commit fixes by expanding the macro and reading the latest value.
It permits -march=loongarch64 when the default target is loongarch32 and
vice versa.
gcc/ChangeLog:
* config/loongarch/loongarch-opts.cc (loongarch_config_target):
Fix -march detection.
gcc/testsuite/ChangeLog:
* gcc.target/loongarch/arch-1.c: New test.
* gcc.target/loongarch/arch-2.c: New test.
* gcc.target/loongarch/arch-3.c: New test.
---
gcc/config/loongarch/loongarch-opts.cc | 5 ++++-
gcc/testsuite/gcc.target/loongarch/arch-1.c | 5 +++++
gcc/testsuite/gcc.target/loongarch/arch-2.c | 5 +++++
gcc/testsuite/gcc.target/loongarch/arch-3.c | 6 ++++++
4 files changed, 20 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.target/loongarch/arch-1.c
create mode 100644 gcc/testsuite/gcc.target/loongarch/arch-2.c
create mode 100644 gcc/testsuite/gcc.target/loongarch/arch-3.c
Comments
On Sun, 2023-08-06 at 20:49 +0800, Jiajie Chen via Gcc-patches wrote:
> When loongarch_arch_target is called, la_target has not been
> initialized, thus the macro LARCH_ACTUAL_ARCH always equals to zero.
>
> This commit fixes by expanding the macro and reading the latest value.
> It permits -march=loongarch64 when the default target is loongarch32 and
> vice versa.
>
> gcc/ChangeLog:
>
> * config/loongarch/loongarch-opts.cc (loongarch_config_target):
> Fix -march detection.
Nit: the first letter 'F' of the second line should align with '*' of
the first line, not 'c'.
/* snip */
> diff --git a/gcc/testsuite/gcc.target/loongarch/arch-3.c b/gcc/testsuite/gcc.target/loongarch/arch-3.c
> new file mode 100644
> index 00000000000..543b93883bd
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/loongarch/arch-3.c
> @@ -0,0 +1,6 @@
> +/* { dg-do compile } */
> +/* { dg-options "-march=loongarch64 -mabi=ilp32d" } */
> +int foo()
> +{
> +}
> +/* { dg-error "unable to implement ABI 'ilp32d' with instruction set 'la64/fpu64'" "" { target *-*-* } 0 } */
This is just wrong. It's absolutely possible to implement ilp32d with
la64/fpu64. LoongArch *.w instructions are always 32-bit operations, no
matter on LA32 or LA64. They are different from RISC-V where many
instructions operate on 32-bit integers on RV32 but 64-bit integers on
RV64.
If you don't want to spend your time to implement it you should use
`sorry ("%<-mabi=ilp32d%> is not implemented for la64");` instead.
Yes, I know there is some (mis)uses of TARGET_64BIT in the
config/loongarch code where TARGET_ABI_LP64 should be actually used
instead. They are bugs preventing us from implementing -mabi=ilp32d -
march=loongarch64 and they should be fixed. They are not our excuse to
blindly "simulate" what RISC-V has.
@@ -246,7 +246,10 @@ loongarch_config_target (struct loongarch_target *target,
config_target_isa:
/* Get default ISA from "-march" or its default value. */
- t.isa = loongarch_cpu_default_isa[LARCH_ACTUAL_ARCH];
+ if (t.cpu_arch == TARGET_ARCH_NATIVE)
+ t.isa = loongarch_cpu_default_isa[t.cpu_native];
+ else
+ t.isa = loongarch_cpu_default_isa[t.cpu_arch];
/* Apply incremental changes. */
/* "-march=native" overrides the default FPU type. */
new file mode 100644
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-march=loongarch64 -mabi=lp64d" } */
+int foo()
+{
+}
new file mode 100644
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-march=loongarch32 -mabi=ilp32d" } */
+int foo()
+{
+}
new file mode 100644
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-march=loongarch64 -mabi=ilp32d" } */
+int foo()
+{
+}
+/* { dg-error "unable to implement ABI 'ilp32d' with instruction set 'la64/fpu64'" "" { target *-*-* } 0 } */