]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LoongArch: Fix ISA base not being updated in loongarch_option_restore [PR123171]
authorWANG Xuerui <git@xen0n.name>
Thu, 18 Dec 2025 05:42:33 +0000 (13:42 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Thu, 18 Dec 2025 09:10:28 +0000 (17:10 +0800)
Fixes switching between LA32S and LA32R base arches with target pragmas
or attributes.

Bootstrapped and regtested on loongarch64-linux-gnu.

PR target/123171
gcc/ChangeLog:

* config/loongarch/loongarch.cc (loongarch_option_restore): Add
missing update to la_target.isa.base.

gcc/testsuite/ChangeLog:

* gcc.target/loongarch/pr123171.c: New test.

Suggested-by: Lulu Cheng <chenglulu@loongson.cn>
Signed-off-by: WANG Xuerui <git@xen0n.name>
gcc/config/loongarch/loongarch.cc
gcc/testsuite/gcc.target/loongarch/pr123171.c [new file with mode: 0644]

index 06d0dcc5efdabb8dc226e25b1656c4fc9b6d9441..0b50aa214fdccafe79283024c7bfae5717259e7c 100644 (file)
@@ -8444,6 +8444,7 @@ loongarch_option_restore (struct gcc_options *,
   la_target.cpu_arch = ptr->x_la_opt_cpu_arch;
   la_target.cpu_tune = ptr->x_la_opt_cpu_tune;
 
+  la_target.isa.base = loongarch_cpu_default_isa[la_target.cpu_arch].base;
   la_target.isa.fpu = ptr->x_la_opt_fpu;
   la_target.isa.simd = ptr->x_la_opt_simd;
   la_target.isa.evolution = ptr->x_la_isa_evolution;
diff --git a/gcc/testsuite/gcc.target/loongarch/pr123171.c b/gcc/testsuite/gcc.target/loongarch/pr123171.c
new file mode 100644 (file)
index 0000000..8c555c2
--- /dev/null
@@ -0,0 +1,54 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=la32v1.0" } */
+/* { dg-final { check-function-bodies "**" "" } } */
+
+/*
+** orn_la32r:
+**     nor     \$r5,\$r0,\$r5
+**     or      \$r4,\$r5,\$r4
+**     jr      \$r1
+*/
+#pragma GCC push_options
+#pragma GCC target "arch=la32rv1.0"
+int
+orn_la32r (int a, int b)
+{
+  return a | ~b;
+}
+
+/*
+** orn_la32s_attr:
+**     orn     \$r4,\$r4,\$r5
+**     jr      \$r1
+*/
+int
+__attribute__ ((target ("arch=la32v1.0")))
+orn_la32s_attr (int a, int b)
+{
+  return a | ~b;
+}
+#pragma GCC pop_options
+
+/*
+** orn_la32s:
+**     orn     \$r4,\$r4,\$r5
+**     jr      \$r1
+*/
+int
+orn_la32s (int a, int b)
+{
+  return a | ~b;
+}
+
+/*
+** orn_la32r_attr:
+**     nor     \$r5,\$r0,\$r5
+**     or      \$r4,\$r5,\$r4
+**     jr      \$r1
+*/
+int
+__attribute__ ((target ("arch=la32rv1.0")))
+orn_la32r_attr (int a, int b)
+{
+  return a | ~b;
+}