[gcc r8-10556] x86: Use SET operation in MOVDIRI and MOVDIR64B
H.J. Lu
hjl@gcc.gnu.org
Wed Sep 30 12:57:52 GMT 2020
https://gcc.gnu.org/g:b0e6f198547d423b24520c13e3c29f3712026fce
commit r8-10556-gb0e6f198547d423b24520c13e3c29f3712026fce
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Wed Sep 23 12:11:45 2020 -0700
x86: Use SET operation in MOVDIRI and MOVDIR64B
Since MOVDIRI and MOVDIR64B write to memory, similar to UNSPEC_MOVNT,
use SET operation in MOVDIRI and MOVDIR64B patterns with UNSPEC instead
of UNSPECV.
gcc/
PR target/97184
* config/i386/i386.md (UNSPECV_MOVDIRI): Renamed to ...
(UNSPEC_MOVDIRI): This.
(UNSPECV_MOVDIR64B): Renamed to ...
(UNSPEC_MOVDIR64B): This.
(movdiri<mode>): Use SET operation.
(@movdir64b_<mode>): Likewise.
gcc/testsuite/
PR target/97184
* gcc.target/i386/movdir64b.c: New test.
* gcc.target/i386/movdiri32.c: Likewise.
* gcc.target/i386/movdiri64.c: Likewise.
* lib/target-supports.exp (check_effective_target_movdir): New.
(cherry picked from commit 5521e8a629f8bee3a7778d69521d857496556d1f)
Diff:
---
gcc/config/i386/i386.md | 18 ++++++++++--------
gcc/testsuite/gcc.target/i386/movdir64b.c | 29 +++++++++++++++++++++++++++++
gcc/testsuite/gcc.target/i386/movdiri32.c | 26 ++++++++++++++++++++++++++
gcc/testsuite/gcc.target/i386/movdiri64.c | 26 ++++++++++++++++++++++++++
gcc/testsuite/lib/target-supports.exp | 16 ++++++++++++++++
5 files changed, 107 insertions(+), 8 deletions(-)
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 11d69e997bb..c17ae94f90d 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -196,6 +196,10 @@
;; IRET support
UNSPEC_INTERRUPT_RETURN
+
+ ;; For MOVDIRI and MOVDIR64B support
+ UNSPEC_MOVDIRI
+ UNSPEC_MOVDIR64B
])
(define_c_enum "unspecv" [
@@ -289,8 +293,6 @@
UNSPECV_WRUSS
UNSPECV_SETSSBSY
UNSPECV_CLRSSBSY
- UNSPECV_MOVDIRI
- UNSPECV_MOVDIR64B
])
;; Constants to represent rounding modes in the ROUND instruction
@@ -20782,17 +20784,17 @@
[(set_attr "type" "other")])
(define_insn "movdiri<mode>"
- [(unspec_volatile:SWI48[(match_operand:SWI48 0 "memory_operand" "m")
- (match_operand:SWI48 1 "register_operand" "r")]
- UNSPECV_MOVDIRI)]
+ [(set (match_operand:SWI48 0 "memory_operand" "=m")
+ (unspec:SWI48 [(match_operand:SWI48 1 "register_operand" "r")]
+ UNSPEC_MOVDIRI))]
"TARGET_MOVDIRI"
"movdiri\t{%1, %0|%0, %1}"
[(set_attr "type" "other")])
(define_insn "movdir64b_<mode>"
- [(unspec_volatile:XI[(match_operand:P 0 "register_operand" "r")
- (match_operand:XI 1 "memory_operand")]
- UNSPECV_MOVDIR64B)]
+ [(set (mem:XI (match_operand:P 0 "register_operand" "r"))
+ (unspec:XI [(match_operand:XI 1 "memory_operand" "m")]
+ UNSPEC_MOVDIR64B))]
"TARGET_MOVDIR64B"
"movdir64b\t{%1, %0|%0, %1}"
[(set_attr "type" "other")])
diff --git a/gcc/testsuite/gcc.target/i386/movdir64b.c b/gcc/testsuite/gcc.target/i386/movdir64b.c
new file mode 100644
index 00000000000..01451a8eb9b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/movdir64b.c
@@ -0,0 +1,29 @@
+/* { dg-do run { target movdir } } */
+/* { dg-options "-mmovdir64b -O2" } */
+
+#include <x86intrin.h>
+#include <cpuid.h>
+#include <string.h>
+
+unsigned long long int src[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+unsigned long long int dest[8] __attribute__ ((aligned (64)))
+ = {-1, -1, -1, -1, -1, -1, -1, -1};
+
+int
+main ()
+{
+ unsigned int eax, ebx, ecx, edx;
+
+ if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
+ return 0;
+
+ if ((ecx & bit_MOVDIR64B) == 0)
+ return 0;
+
+ _movdir64b (dest, src);
+
+ if (memcmp (dest, src, sizeof (dest)) != 0)
+ abort ();
+
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.target/i386/movdiri32.c b/gcc/testsuite/gcc.target/i386/movdiri32.c
new file mode 100644
index 00000000000..04a412f9bf3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/movdiri32.c
@@ -0,0 +1,26 @@
+/* { dg-do run { target movdir } } */
+/* { dg-options "-mmovdiri -O2" } */
+
+#include <x86intrin.h>
+#include <cpuid.h>
+
+unsigned int dest = -1;
+
+int
+main ()
+{
+ unsigned int eax, ebx, ecx, edx;
+
+ if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
+ return 0;
+
+ if ((ecx & bit_MOVDIRI) == 0)
+ return 0;
+
+ _directstoreu_u32 (&dest, 0xbadbeef);
+
+ if (dest != 0xbadbeef)
+ abort ();
+
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.target/i386/movdiri64.c b/gcc/testsuite/gcc.target/i386/movdiri64.c
new file mode 100644
index 00000000000..e0cb6081496
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/movdiri64.c
@@ -0,0 +1,26 @@
+/* { dg-do run { target { movdir && { ! ia32 } } } } */
+/* { dg-options "-mmovdiri -O2" } */
+
+#include <x86intrin.h>
+#include <cpuid.h>
+
+unsigned long long int dest = -1LL;
+
+int
+main ()
+{
+ unsigned int eax, ebx, ecx, edx;
+
+ if (!__get_cpuid_count (7, 0, &eax, &ebx, &ecx, &edx))
+ return 0;
+
+ if ((ecx & bit_MOVDIRI) == 0)
+ return 0;
+
+ _directstoreu_u64 (&dest, 0x12345678badbeef);
+
+ if (dest != 0x12345678badbeef)
+ abort ();
+
+ return 0;
+}
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 8c6db512c63..4516cfc49e4 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -9464,3 +9464,19 @@ foreach N {df} {
}]
}
+# Return 1 if we're able to assemble movdiri and movdir64b
+
+proc check_effective_target_movdir { } {
+ return [check_no_compiler_messages movdir object {
+ void
+ foo (unsigned int *d, unsigned int s)
+ {
+ __builtin_ia32_directstoreu_u32 (d, s);
+ }
+ void
+ bar (void *d, const void *s)
+ {
+ __builtin_ia32_movdir64b (d, s);
+ }
+ } "-mmovdiri -mmovdir64b" ]
+}
More information about the Gcc-cvs
mailing list