diff mbox series

x86: Don't enable APX_F in 32-bit mode.

Message ID DM4PR11MB5487C6264BE76CC89A2CF716ECAC2@DM4PR11MB5487.namprd11.prod.outlook.com
State New
Headers show
Series x86: Don't enable APX_F in 32-bit mode. | expand

Commit Message

Kong, Lingling July 18, 2024, 9:28 a.m. UTC
I adjusted my patch based on the comments by H.J.
And I will add the testcase like  gcc.target/i386/pr101395-1.c when the march for APX is determined.

Ok for trunk?

Thanks,
Lingling

gcc/ChangeLog:

	PR target/115978
	* config/i386/driver-i386.cc (host_detect_local_cpu): Enable
	APX_F only for 64-bit codegen.
	* config/i386/i386-options.cc (DEF_PTA): Skip PTA_APX_F if
	not in 64-bit mode.

gcc/testsuite/ChangeLog:

	PR target/115978
	* gcc.target/i386/pr115978-1.c: New test.
	* gcc.target/i386/pr115978-2.c: Ditto.
---
 gcc/config/i386/driver-i386.cc             |  3 ++-
 gcc/config/i386/i386-options.cc            |  3 ++-
 gcc/testsuite/gcc.target/i386/pr115978-1.c | 22 ++++++++++++++++++++++ 
 gcc/testsuite/gcc.target/i386/pr115978-2.c |  6 ++++++
 4 files changed, 32 insertions(+), 2 deletions(-) 
 create mode 100644 gcc/testsuite/gcc.target/i386/pr115978-1.c
 create mode 100644 gcc/testsuite/gcc.target/i386/pr115978-2.c

--
2.31.1

Comments

Hongtao Liu July 23, 2024, 3:20 a.m. UTC | #1
On Thu, Jul 18, 2024 at 5:29 PM Kong, Lingling <lingling.kong@intel.com> wrote:
>
> I adjusted my patch based on the comments by H.J.
> And I will add the testcase like  gcc.target/i386/pr101395-1.c when the march for APX is determined.
>
> Ok for trunk?
Synced with LLVM folks, they agreed to this solution.
Ok.
>
> Thanks,
> Lingling
>
> gcc/ChangeLog:
>
>         PR target/115978
>         * config/i386/driver-i386.cc (host_detect_local_cpu): Enable
>         APX_F only for 64-bit codegen.
>         * config/i386/i386-options.cc (DEF_PTA): Skip PTA_APX_F if
>         not in 64-bit mode.
>
> gcc/testsuite/ChangeLog:
>
>         PR target/115978
>         * gcc.target/i386/pr115978-1.c: New test.
>         * gcc.target/i386/pr115978-2.c: Ditto.
> ---
>  gcc/config/i386/driver-i386.cc             |  3 ++-
>  gcc/config/i386/i386-options.cc            |  3 ++-
>  gcc/testsuite/gcc.target/i386/pr115978-1.c | 22 ++++++++++++++++++++++
>  gcc/testsuite/gcc.target/i386/pr115978-2.c |  6 ++++++
>  4 files changed, 32 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr115978-1.c
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr115978-2.c
>
> diff --git a/gcc/config/i386/driver-i386.cc b/gcc/config/i386/driver-i386.cc index 11470eaea12..445f5640155 100644
> --- a/gcc/config/i386/driver-i386.cc
> +++ b/gcc/config/i386/driver-i386.cc
> @@ -900,7 +900,8 @@ const char *host_detect_local_cpu (int argc, const char **argv)
>             if (has_feature (isa_names_table[i].feature))
>               {
>                 if (codegen_x86_64
> -                   || isa_names_table[i].feature != FEATURE_UINTR)
> +                   || (isa_names_table[i].feature != FEATURE_UINTR
> +                       && isa_names_table[i].feature != FEATURE_APX_F))
>                   options = concat (options, " ",
>                                     isa_names_table[i].option, NULL);
>               }
> diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc index 059ef3ae6ad..1c8f7835af2 100644
> --- a/gcc/config/i386/i386-options.cc
> +++ b/gcc/config/i386/i386-options.cc
> @@ -2351,7 +2351,8 @@ ix86_option_override_internal (bool main_args_p,  #define DEF_PTA(NAME) \
>         if (((processor_alias_table[i].flags & PTA_ ## NAME) != 0) \
>             && PTA_ ## NAME != PTA_64BIT \
> -           && (TARGET_64BIT || PTA_ ## NAME != PTA_UINTR) \
> +           && (TARGET_64BIT || (PTA_ ## NAME != PTA_UINTR \
> +                                && PTA_ ## NAME != PTA_APX_F))\
>             && !TARGET_EXPLICIT_ ## NAME ## _P (opts)) \
>           SET_TARGET_ ## NAME (opts);
>  #include "i386-isa.def"
> diff --git a/gcc/testsuite/gcc.target/i386/pr115978-1.c b/gcc/testsuite/gcc.target/i386/pr115978-1.c
> new file mode 100644
> index 00000000000..18a1c5f153a
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr115978-1.c
> @@ -0,0 +1,22 @@
> +/* { dg-do run } */
> +/* { dg-options "-O2 -march=native" } */
> +
> +int
> +main ()
> +{
> +  if (__builtin_cpu_supports ("apxf"))
> +    {
> +#ifdef __x86_64__
> +# ifndef __APX_F__
> +      __builtin_abort ();
> +# endif
> +#else
> +# ifdef __APX_F__
> +      __builtin_abort ();
> +# endif
> +#endif
> +      return 0;
> +    }
> +
> +  return 0;
> +}
> diff --git a/gcc/testsuite/gcc.target/i386/pr115978-2.c b/gcc/testsuite/gcc.target/i386/pr115978-2.c
> new file mode 100644
> index 00000000000..900d6eb096a
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr115978-2.c
> @@ -0,0 +1,6 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -march=native -mno-apxf" } */
> +
> +#ifdef __APX_F__
> +# error APX_F should be disabled
> +#endif
> --
> 2.31.1
>
diff mbox series

Patch

diff --git a/gcc/config/i386/driver-i386.cc b/gcc/config/i386/driver-i386.cc index 11470eaea12..445f5640155 100644
--- a/gcc/config/i386/driver-i386.cc
+++ b/gcc/config/i386/driver-i386.cc
@@ -900,7 +900,8 @@  const char *host_detect_local_cpu (int argc, const char **argv)
 	    if (has_feature (isa_names_table[i].feature))
 	      {
 		if (codegen_x86_64
-		    || isa_names_table[i].feature != FEATURE_UINTR)
+		    || (isa_names_table[i].feature != FEATURE_UINTR
+			&& isa_names_table[i].feature != FEATURE_APX_F))
 		  options = concat (options, " ",
 				    isa_names_table[i].option, NULL);
 	      }
diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc index 059ef3ae6ad..1c8f7835af2 100644
--- a/gcc/config/i386/i386-options.cc
+++ b/gcc/config/i386/i386-options.cc
@@ -2351,7 +2351,8 @@  ix86_option_override_internal (bool main_args_p,  #define DEF_PTA(NAME) \
 	if (((processor_alias_table[i].flags & PTA_ ## NAME) != 0) \
 	    && PTA_ ## NAME != PTA_64BIT \
-	    && (TARGET_64BIT || PTA_ ## NAME != PTA_UINTR) \
+	    && (TARGET_64BIT || (PTA_ ## NAME != PTA_UINTR \
+				 && PTA_ ## NAME != PTA_APX_F))\
 	    && !TARGET_EXPLICIT_ ## NAME ## _P (opts)) \
 	  SET_TARGET_ ## NAME (opts);
 #include "i386-isa.def"
diff --git a/gcc/testsuite/gcc.target/i386/pr115978-1.c b/gcc/testsuite/gcc.target/i386/pr115978-1.c
new file mode 100644
index 00000000000..18a1c5f153a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr115978-1.c
@@ -0,0 +1,22 @@ 
+/* { dg-do run } */
+/* { dg-options "-O2 -march=native" } */
+
+int
+main ()
+{
+  if (__builtin_cpu_supports ("apxf"))
+    {
+#ifdef __x86_64__
+# ifndef __APX_F__
+      __builtin_abort ();
+# endif
+#else
+# ifdef __APX_F__
+      __builtin_abort ();
+# endif
+#endif
+      return 0;
+    }
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr115978-2.c b/gcc/testsuite/gcc.target/i386/pr115978-2.c
new file mode 100644
index 00000000000..900d6eb096a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr115978-2.c
@@ -0,0 +1,6 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=native -mno-apxf" } */
+
+#ifdef __APX_F__
+# error APX_F should be disabled
+#endif