public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jiajie Chen <c@jia.je>
To: gcc-patches@gcc.gnu.org
Cc: Jiajie Chen <c@jia.je>
Subject: [PATCH 2/9] LoongArch: Fix default ISA setting
Date: Sun,  6 Aug 2023 20:49:59 +0800	[thread overview]
Message-ID: <20230806125010.283900-2-c@jia.je> (raw)
In-Reply-To: <20230806125010.283900-1-c@jia.je>

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

diff --git a/gcc/config/loongarch/loongarch-opts.cc b/gcc/config/loongarch/loongarch-opts.cc
index 9fc0bbbcb6e..29c0c4468bb 100644
--- a/gcc/config/loongarch/loongarch-opts.cc
+++ b/gcc/config/loongarch/loongarch-opts.cc
@@ -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.  */
diff --git a/gcc/testsuite/gcc.target/loongarch/arch-1.c b/gcc/testsuite/gcc.target/loongarch/arch-1.c
new file mode 100644
index 00000000000..379036ec76f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/arch-1.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-march=loongarch64 -mabi=lp64d" } */
+int foo()
+{
+}
diff --git a/gcc/testsuite/gcc.target/loongarch/arch-2.c b/gcc/testsuite/gcc.target/loongarch/arch-2.c
new file mode 100644
index 00000000000..55d646902a6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/arch-2.c
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+/* { dg-options "-march=loongarch32 -mabi=ilp32d" } */
+int foo()
+{
+}
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 } */
-- 
2.41.0


  reply	other threads:[~2023-08-06 12:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-06 12:49 [PATCH 1/9] LoongArch: Introduce loongarch32 target Jiajie Chen
2023-08-06 12:49 ` Jiajie Chen [this message]
2023-08-09  3:38   ` [PATCH 2/9] LoongArch: Fix default ISA setting Xi Ruoyao
2023-08-06 12:50 ` [PATCH 3/9] LoongArch: Fix SI division for loongarch32 target Jiajie Chen
2023-08-06 12:50 ` [PATCH 4/9] LoongArch: Fix movgr2frh.w operand order Jiajie Chen
2023-08-06 12:50 ` [PATCH 5/9] LoongArch: Fix 64-bit move for loongarch32 target Jiajie Chen
2023-08-06 12:50 ` [PATCH 6/9] LoongArch: Fix 64-bit immediate " Jiajie Chen
2023-08-06 12:50 ` [PATCH 7/9] LoongArch: Fix signed 32-bit overflow " Jiajie Chen
2023-08-06 12:50 ` [PATCH 8/9] LoongArch: Do not emit SF/DF <-> DI conversion in loongarch32 Jiajie Chen
2023-08-06 12:50 ` [PATCH 9/9] LoongArch: Add: Add -march=loongarch64 to tests with -mabi=lp64d Jiajie Chen
2023-08-09  2:50 ` [PATCH 1/9] LoongArch: Introduce loongarch32 target Chenghua Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230806125010.283900-2-c@jia.je \
    --to=c@jia.je \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).