[v2,3/4] LoongArch: After setting the compilation options, update the predefined macros.
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_simplebootstrap_build--master-aarch64-bootstrap |
success
|
Build passed
|
Commit Message
PR target/118828
gcc/ChangeLog:
* config/loongarch/loongarch-c.cc (loongarch_pragma_target_parse):
Update the predefined macros.
gcc/testsuite/ChangeLog:
* gcc.target/loongarch/pr118828.c: New test.
* gcc.target/loongarch/pr118828-2.c: New test.
* gcc.target/loongarch/pr118828-3.c: New test.
* gcc.target/loongarch/pr118828-4.c: New test.
Change-Id: I13f7b44b11bba2080db797157a0389cc1bd65ac6
---
gcc/config/loongarch/loongarch-c.cc | 14 +++++
.../gcc.target/loongarch/pr118828-2.c | 30 ++++++++++
.../gcc.target/loongarch/pr118828-3.c | 55 +++++++++++++++++++
.../gcc.target/loongarch/pr118828-4.c | 55 +++++++++++++++++++
gcc/testsuite/gcc.target/loongarch/pr118828.c | 34 ++++++++++++
5 files changed, 188 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/loongarch/pr118828-2.c
create mode 100644 gcc/testsuite/gcc.target/loongarch/pr118828-3.c
create mode 100644 gcc/testsuite/gcc.target/loongarch/pr118828-4.c
create mode 100644 gcc/testsuite/gcc.target/loongarch/pr118828.c
Comments
On Wed, 2025-02-12 at 18:03 +0800, Lulu Cheng wrote:
/* snip */
> diff --git a/gcc/testsuite/gcc.target/loongarch/pr118828-3.c b/gcc/testsuite/gcc.target/loongarch/pr118828-3.c
> new file mode 100644
> index 00000000000..a682ae4a356
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/loongarch/pr118828-3.c
> @@ -0,0 +1,55 @@
> +/* { dg-do run } */
> +/* { dg-options "-march=loongarch64" } */
> +
> +#include <string.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +
> +#ifndef __loongarch_arch
> +#error __loongarch_arch should not be available here
> +#endif
Hmm this seems not correct? __loongarch_arch should be just
"loongarch64" here (at least it is "loongarch64" with GCC <= 14).
And a dg-do test with explicit -march= in dg-options is problematic
because it'll fail on less-capable CPUs (in this case, after we add
LA32). We can change this to something like:
/* { dg-do compile } */
/* { dg-options "-O2 -march=loongarch64" } */
/* { dg-final { scan-assembler "t1: loongarch64" } } */
/* { dg-final { scan-assembler "t2: la64v1.1" } } */
/* { dg-final { scan-assembler "t3: loongarch64" } } */
void
t1 (void)
{
asm volatile ("# t1: " __loongarch_arch);
}
#pragma GCC push_options
#pragma GCC target("arch=la64v1.1")
void
t2 (void)
{
asm volatile ("# t2: " __loongarch_arch);
}
#pragma GCC pop_options
void
t3 (void)
{
asm volatile ("# t3: " __loongarch_arch);
}
... ...
/* snip */
> diff --git a/gcc/testsuite/gcc.target/loongarch/pr118828-4.c b/gcc/testsuite/gcc.target/loongarch/pr118828-4.c
> new file mode 100644
> index 00000000000..3b3a7c6078c
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/loongarch/pr118828-4.c
> @@ -0,0 +1,55 @@
> +/* { dg-do run } */
> +/* { dg-options "-mtune=la464" } */
> +
> +#include <string.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +
> +#ifndef __loongarch_tune
> +#error __loongarch_tune should not be available here
Likewise.
在 2025/2/12 下午6:19, Xi Ruoyao 写道:
> On Wed, 2025-02-12 at 18:03 +0800, Lulu Cheng wrote:
>
> /* snip */
>
>> diff --git a/gcc/testsuite/gcc.target/loongarch/pr118828-3.c b/gcc/testsuite/gcc.target/loongarch/pr118828-3.c
>> new file mode 100644
>> index 00000000000..a682ae4a356
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.target/loongarch/pr118828-3.c
>> @@ -0,0 +1,55 @@
>> +/* { dg-do run } */
>> +/* { dg-options "-march=loongarch64" } */
>> +
>> +#include <string.h>
>> +#include <stdio.h>
>> +#include <stdlib.h>
>> +
>> +#ifndef __loongarch_arch
>> +#error __loongarch_arch should not be available here
>> +#endif
> Hmm this seems not correct? __loongarch_arch should be just
> "loongarch64" here (at least it is "loongarch64" with GCC <= 14).
Well, because this predefined macro must be defined in any case, I added
this check here.
But it seems a bit redundant. I will delete it in v3.
>
> And a dg-do test with explicit -march= in dg-options is problematic
> because it'll fail on less-capable CPUs (in this case, after we add
> LA32). We can change this to something like:
What I didn't take into account was...
>
> /* { dg-do compile } */
> /* { dg-options "-O2 -march=loongarch64" } */
> /* { dg-final { scan-assembler "t1: loongarch64" } } */
> /* { dg-final { scan-assembler "t2: la64v1.1" } } */
> /* { dg-final { scan-assembler "t3: loongarch64" } } */
>
> void
> t1 (void)
> {
> asm volatile ("# t1: " __loongarch_arch);
> }
>
> #pragma GCC push_options
> #pragma GCC target("arch=la64v1.1")
>
> void
> t2 (void)
> {
> asm volatile ("# t2: " __loongarch_arch);
> }
>
> #pragma GCC pop_options
>
> void
> t3 (void)
> {
> asm volatile ("# t3: " __loongarch_arch);
> }
>
> ... ...
>
> /* snip */
>
>> diff --git a/gcc/testsuite/gcc.target/loongarch/pr118828-4.c b/gcc/testsuite/gcc.target/loongarch/pr118828-4.c
>> new file mode 100644
>> index 00000000000..3b3a7c6078c
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.target/loongarch/pr118828-4.c
>> @@ -0,0 +1,55 @@
>> +/* { dg-do run } */
>> +/* { dg-options "-mtune=la464" } */
>> +
>> +#include <string.h>
>> +#include <stdio.h>
>> +#include <stdlib.h>
>> +
>> +#ifndef __loongarch_tune
>> +#error __loongarch_tune should not be available here
> Likewise.
>
On Thu, 2025-02-13 at 09:24 +0800, Lulu Cheng wrote:
>
> 在 2025/2/12 下午6:19, Xi Ruoyao 写道:
> > On Wed, 2025-02-12 at 18:03 +0800, Lulu Cheng wrote:
> >
> > /* snip */
> >
> > > diff --git a/gcc/testsuite/gcc.target/loongarch/pr118828-3.c b/gcc/testsuite/gcc.target/loongarch/pr118828-3.c
> > > new file mode 100644
> > > index 00000000000..a682ae4a356
> > > --- /dev/null
> > > +++ b/gcc/testsuite/gcc.target/loongarch/pr118828-3.c
> > > @@ -0,0 +1,55 @@
> > > +/* { dg-do run } */
> > > +/* { dg-options "-march=loongarch64" } */
> > > +
> > > +#include <string.h>
> > > +#include <stdio.h>
> > > +#include <stdlib.h>
> > > +
> > > +#ifndef __loongarch_arch
> > > +#error __loongarch_arch should not be available here
> > > +#endif
> > Hmm this seems not correct? __loongarch_arch should be just
> > "loongarch64" here (at least it is "loongarch64" with GCC <= 14).
>
> Well, because this predefined macro must be defined in any case, I added
> this check here.
>
> But it seems a bit redundant. I will delete it in v3.
Oh, no need to delete it. Just change "should not" to "should" :).
I misunderstand the check due to this typo.
@@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see
#include "tm.h"
#include "c-family/c-common.h"
#include "cpplib.h"
+#include "c-family/c-pragma.h"
#include "tm_p.h"
#define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
@@ -212,6 +213,19 @@ loongarch_pragma_target_parse (tree args, tree pop_target)
loongarch_reset_previous_fndecl ();
+ /* For the definitions, ensure all newly defined macros are considered
+ as used for -Wunused-macros. There is no point warning about the
+ compiler predefined macros. */
+ cpp_options *cpp_opts = cpp_get_options (parse_in);
+ unsigned char saved_warn_unused_macros = cpp_opts->warn_unused_macros;
+ cpp_opts->warn_unused_macros = 0;
+
+ cpp_force_token_locations (parse_in, BUILTINS_LOCATION);
+ loongarch_update_cpp_builtins (parse_in);
+ cpp_stop_forcing_token_locations (parse_in);
+
+ cpp_opts->warn_unused_macros = saved_warn_unused_macros;
+
/* If we're popping or reseting make sure to update the globals so that
the optab availability predicates get recomputed. */
if (pop_target)
new file mode 100644
@@ -0,0 +1,30 @@
+/* { dg-do preprocess } */
+/* { dg-options "-mno-lsx" } */
+
+#ifdef __loongarch_sx
+#error LSX should not be available here
+#endif
+
+#ifdef __loongarch_simd_width
+#error simd width shuold not be available here
+#endif
+
+#pragma GCC push_options
+#pragma GCC target("lsx")
+#ifndef __loongarch_sx
+#error LSX should be available here
+#endif
+#ifndef __loongarch_simd_width
+#error simd width should be available here
+#elif __loongarch_simd_width != 128
+#error simd width should be 128
+#endif
+#pragma GCC pop_options
+
+#ifdef __loongarch_sx
+#error LSX should become unavailable again
+#endif
+
+#ifdef __loongarch_simd_width
+#error simd width shuold become unavailable again
+#endif
new file mode 100644
@@ -0,0 +1,55 @@
+/* { dg-do run } */
+/* { dg-options "-march=loongarch64" } */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef __loongarch_arch
+#error __loongarch_arch should not be available here
+#endif
+
+void
+test1 (void)
+{
+ if (strcmp (__loongarch_arch, "loongarch64") != 0)
+ {
+ printf ("__loongarch_arch should be loongarch64 here.\n");
+ abort ();
+ }
+}
+
+
+#pragma GCC push_options
+#pragma GCC target("arch=la64v1.1")
+
+void
+test2 (void)
+{
+ if (strcmp (__loongarch_arch, "la64v1.1") != 0)
+ {
+ printf ("__loongarch_arch should be la464 here.\n");
+ abort ();
+ }
+}
+#pragma GCC pop_options
+
+void
+test3 (void)
+{
+ if (strcmp (__loongarch_arch, "loongarch64") != 0)
+ {
+ printf ("__loongarch_arch should be loongarch64 here.\n");
+ abort ();
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ test1 ();
+ test2 ();
+ test3 ();
+
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,55 @@
+/* { dg-do run } */
+/* { dg-options "-mtune=la464" } */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifndef __loongarch_tune
+#error __loongarch_tune should not be available here
+#endif
+
+void
+test1 (void)
+{
+ if (strcmp (__loongarch_tune, "la464") != 0)
+ {
+ printf ("__loongarch_tune should be la464 here.\n");
+ abort ();
+ }
+}
+
+
+#pragma GCC push_options
+#pragma GCC target("arch=la664")
+
+void
+test2 (void)
+{
+ if (strcmp (__loongarch_tune, "la664") != 0)
+ {
+ printf ("__loongarch_tune should be la664 here.\n");
+ abort ();
+ }
+}
+#pragma GCC pop_options
+
+void
+test3 (void)
+{
+ if (strcmp (__loongarch_tune, "la464") != 0)
+ {
+ printf ("__loongarch_tune should be la464 here.\n");
+ abort ();
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ test1 ();
+ test2 ();
+ test3 ();
+
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,34 @@
+/* { dg-do preprocess } */
+/* { dg-options "-mno-lasx" } */
+
+#ifdef __loongarch_asx
+#error LASX should not be available here
+#endif
+
+#ifdef __loongarch_simd_width
+#if __loongarch_simd_width == 256
+#error simd width shuold not be 256
+#endif
+#endif
+
+#pragma GCC push_options
+#pragma GCC target("lasx")
+#ifndef __loongarch_asx
+#error LASX should be available here
+#endif
+#ifndef __loongarch_simd_width
+#error simd width should be available here
+#elif __loongarch_simd_width != 256
+#error simd width should be 256
+#endif
+#pragma GCC pop_options
+
+#ifdef __loongarch_asx
+#error LASX should become unavailable again
+#endif
+
+#ifdef __loongarch_simd_width
+#if __loongarch_simd_width == 256
+#error simd width shuold not be 256 again
+#endif
+#endif