* [PATCH] x86: Don't enable UINTR in 32-bit mode
@ 2021-07-11 13:06 H.J. Lu
0 siblings, 0 replies; only message in thread
From: H.J. Lu @ 2021-07-11 13:06 UTC (permalink / raw)
To: gcc-patches; +Cc: Uros Bizjak, Hongyu Wang
UINTR is available only in 64-bit mode. Since the codegen target is
unknown when the the gcc driver is processing -march=native, to properly
handle UINTR for -march=native:
1. Add an undocumented option, -muintr-native.
2. Update the gcc driver to pass -muintr-native with -march=native if
UINTR is available.
3. Change ix86_option_override_internal to
a. Turn on UINTR in 64-bit mode for -muintr-native.
b. Enable UINTR only in 64-bit mode for -march=CPU when PTA_CPU
includes PTA_UINTR.
gcc/
PR target/101395
* config/i386/driver-i386.c (host_detect_local_cpu): Add
-muintr-native for FEATURE_UINTR.
* config/i386/i386-options.c (ix86_option_override_internal):
Move -muintr check after -march processing and turn on UINTR in
64-bit mode for -muintr-native if it has not been disabled
explicitly.
(DEF_PTA): Skip PTA_UINTR if not in 64-bit mode.
* config/i386/i386.opt (muintr-native): New. Undocumented to
enable -muintr only in 64-bit mode with -march=native.
gcc/testsuite/
PR target/101395
* gcc.target/i386/pr101395-1.c: New test.
* gcc.target/i386/pr101395-2.c: Likewise.
* gcc.target/i386/pr101395-3.c: Likewise.
---
gcc/config/i386/driver-i386.c | 10 ++++++++--
gcc/config/i386/i386-options.c | 14 +++++++++++---
gcc/config/i386/i386.opt | 4 ++++
gcc/testsuite/gcc.target/i386/pr101395-1.c | 12 ++++++++++++
gcc/testsuite/gcc.target/i386/pr101395-2.c | 22 ++++++++++++++++++++++
gcc/testsuite/gcc.target/i386/pr101395-3.c | 6 ++++++
6 files changed, 63 insertions(+), 5 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/i386/pr101395-1.c
create mode 100644 gcc/testsuite/gcc.target/i386/pr101395-2.c
create mode 100644 gcc/testsuite/gcc.target/i386/pr101395-3.c
diff --git a/gcc/config/i386/driver-i386.c b/gcc/config/i386/driver-i386.c
index dd9236616b4..7ade90a088d 100644
--- a/gcc/config/i386/driver-i386.c
+++ b/gcc/config/i386/driver-i386.c
@@ -804,8 +804,14 @@ const char *host_detect_local_cpu (int argc, const char **argv)
if (isa_names_table[i].option)
{
if (has_feature (isa_names_table[i].feature))
- options = concat (options, " ",
- isa_names_table[i].option, NULL);
+ {
+ const char *option;
+ if (isa_names_table[i].feature == FEATURE_UINTR)
+ option = "-muintr-native";
+ else
+ option = isa_names_table[i].option;
+ options = concat (options, " ", option, NULL);
+ }
else
options = concat (options, neg_option,
isa_names_table[i].option + 2, NULL);
diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c
index 7a35c468da3..6b12f030f0c 100644
--- a/gcc/config/i386/i386-options.c
+++ b/gcc/config/i386/i386-options.c
@@ -1920,9 +1920,6 @@ ix86_option_override_internal (bool main_args_p,
opts->x_ix86_stringop_alg = no_stringop;
}
- if (TARGET_UINTR && !TARGET_64BIT)
- error ("%<-muintr%> not supported for 32-bit code");
-
if (!opts->x_ix86_arch_string)
opts->x_ix86_arch_string
= TARGET_64BIT_P (opts->x_ix86_isa_flags)
@@ -2109,6 +2106,7 @@ 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_EXPLICIT_ ## NAME ## _P (opts)) \
SET_TARGET_ ## NAME (opts);
#include "i386-isa.def"
@@ -2184,6 +2182,16 @@ ix86_option_override_internal (bool main_args_p,
XDELETEVEC (s);
}
+ if (TARGET_64BIT)
+ {
+ /* Turn on UINTR in 64-bit mode for -muintr-native if it has not
+ been set explicitly. */
+ if (ix86_uintr_native && !TARGET_EXPLICIT_UINTR_P (opts))
+ SET_TARGET_UINTR (opts);
+ }
+ else if (TARGET_UINTR)
+ error ("%<-muintr%> not supported for 32-bit code");
+
ix86_arch_mask = HOST_WIDE_INT_1U << ix86_arch;
for (i = 0; i < X86_ARCH_LAST; ++i)
ix86_arch_features[i] = !!(initial_ix86_arch_features[i] & ix86_arch_mask);
diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt
index 7b8547bb1c3..5923bbfb40e 100644
--- a/gcc/config/i386/i386.opt
+++ b/gcc/config/i386/i386.opt
@@ -802,6 +802,10 @@ muintr
Target Mask(ISA2_UINTR) Var(ix86_isa_flags2) Save
Support UINTR built-in functions and code generation.
+; Used to enable -muintr only in 64-bit mode with -march=native.
+muintr-native
+Target Undocumented RejectNegative Var(ix86_uintr_native)
+
msgx
Target Mask(ISA2_SGX) Var(ix86_isa_flags2) Save
Support SGX built-in functions and code generation.
diff --git a/gcc/testsuite/gcc.target/i386/pr101395-1.c b/gcc/testsuite/gcc.target/i386/pr101395-1.c
new file mode 100644
index 00000000000..74c8bfe891a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr101395-1.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=sapphirerapids" } */
+
+#ifdef __x86_64__
+# ifndef __UINTR__
+# error UINTR is not enabled for Sapphirerapids
+# endif
+#else
+# ifdef __UINTR__
+# error UINTR is not usable in 32-bit mode
+# endif
+#endif
diff --git a/gcc/testsuite/gcc.target/i386/pr101395-2.c b/gcc/testsuite/gcc.target/i386/pr101395-2.c
new file mode 100644
index 00000000000..f2b677f8c80
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr101395-2.c
@@ -0,0 +1,22 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -march=native" } */
+
+int
+main ()
+{
+ if (__builtin_cpu_supports ("uintr"))
+ {
+#ifdef __x86_64__
+# ifndef __UINTR__
+ __builtin_abort ();
+# endif
+#else
+# ifdef __UINTR__
+ __builtin_abort ();
+# endif
+#endif
+ return 0;
+ }
+
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr101395-3.c b/gcc/testsuite/gcc.target/i386/pr101395-3.c
new file mode 100644
index 00000000000..bc6ab423c93
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr101395-3.c
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=native -mno-uintr" } */
+
+#ifdef __UINTR__
+# error UINTR should be disabled
+#endif
--
2.31.1
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-07-11 13:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-11 13:06 [PATCH] x86: Don't enable UINTR in 32-bit mode H.J. Lu
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).