Add general_regs_only attribute to MWAIT intrinsics for callers with
general-regs-only target attribute.
gcc/
PR target/9974
* config/i386/mwaitintrin.h (_mm_monitor): Add general_regs_only
attribute.
(_mm_mwait): Likewise.
gcc/testsuite/
PR target/9974
* gcc.target/i386/pr99744-5.c: New test.
---
gcc/config/i386/mwaitintrin.h | 6 ++++--
gcc/testsuite/gcc.target/i386/pr99744-5.c | 25 +++++++++++++++++++++++
2 files changed, 29 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/i386/pr99744-5.c
diff --git a/gcc/config/i386/mwaitintrin.h b/gcc/config/i386/mwaitintrin.h
index 1ecbc4abb69..d5007875914 100644
--- a/gcc/config/i386/mwaitintrin.h
+++ b/gcc/config/i386/mwaitintrin.h
@@ -31,14 +31,16 @@
#endif /* __MWAIT__ */
extern __inline void
-__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__attribute__((__gnu_inline__, __always_inline__, __artificial__,
+ __general_regs_only__))
_mm_monitor (void const * __P, unsigned int __E, unsigned int __H)
{
__builtin_ia32_monitor (__P, __E, __H);
}
extern __inline void
-__attribute__((__gnu_inline__, __always_inline__, __artificial__))
+__attribute__((__gnu_inline__, __always_inline__, __artificial__,
+ __general_regs_only__))
_mm_mwait (unsigned int __E, unsigned int __H)
{
__builtin_ia32_mwait (__E, __H);
diff --git a/gcc/testsuite/gcc.target/i386/pr99744-5.c
b/gcc/testsuite/gcc.target/i386/pr99744-5.c
new file mode 100644
index 00000000000..9e40e5ef428
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr99744-5.c
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mmwait" } */
+
+/* Test calling MWAIT intrinsics from functions with general-regs-only
+ target attribute. */
+
+#include <x86gprintrin.h>
+
+#define _CONCAT(x,y) x ## y
+
+#define test_2(func, type, op1_type, op2_type) \
+ __attribute__ ((target("general-regs-only")))
\
+ type _CONCAT(do_,func) (op1_type A, op2_type B) \
+ { return func (A, B); }
+
+#define test_3(func, type, op1_type, op2_type, op3_type) \
+ __attribute__ ((target("general-regs-only")))
\
+ type _CONCAT(do_,func) (op1_type A, op2_type B, op3_type C) \
+ { return func (A, B, C); }
+
+#ifndef __iamcu__
+/* mwaitintrin.h */
+test_3 (_mm_monitor, void, void const *, unsigned int, unsigned int)
+test_2 (_mm_mwait, void, unsigned int, unsigned int)
+#endif
--
2.30.2