1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
From c19afda0ee549d294fd5714c63db24bcd4570d03 Mon Sep 17 00:00:00 2001
From: Haochen Jiang <haochen.jiang@intel.com>
Date: Thu, 25 Jul 2024 16:16:05 +0800
Subject: [PATCH 2/2] i386: Add non-optimize prefetchi intrins
Under -O0, with the "newly" introduced intrins, the variable will be
transformed as mem instead of the origin symbol_ref. The compiler will
then treat the operand as invalid and turn the operation into nop, which
is not expected. Use macro for non-optimize to keep the variable as
symbol_ref just as how prefetch intrin does.
gcc/ChangeLog:
* config/i386/prfchiintrin.h
(_m_prefetchit0): Add macro for non-optimized option.
(_m_prefetchit1): Ditto.
gcc/testsuite/ChangeLog:
* gcc.target/i386/prefetchi-1b.c: New test.
Reference:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=
b4524c4430ba9771265bd9fc31e69a3f35dfe117
---
gcc/config/i386/prfchiintrin.h | 9 +++++++
gcc/testsuite/gcc.target/i386/prefetchi-1b.c | 26 ++++++++++++++++++++
2 files changed, 35 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/i386/prefetchi-1b.c
diff --git a/gcc/config/i386/prfchiintrin.h b/gcc/config/i386/prfchiintrin.h
index 06deef488..1e3d42dc3 100644
--- a/gcc/config/i386/prfchiintrin.h
+++ b/gcc/config/i386/prfchiintrin.h
@@ -30,6 +30,7 @@
#ifdef __x86_64__
+#ifdef __OPTIMIZE__
extern __inline void
__attribute__((__gnu_inline__, __always_inline__, __artificial__))
_m_prefetchit0 (void* __P)
@@ -43,6 +44,14 @@ _m_prefetchit1 (void* __P)
{
__builtin_ia32_prefetchi (__P, 2);
}
+#else
+#define _m_prefetchit0(P) \
+ __builtin_ia32_prefetchi(P, 3)
+
+#define _m_prefetchit1(P) \
+ __builtin_ia32_prefetchi(P, 2)
+
+#endif
#endif
diff --git a/gcc/testsuite/gcc.target/i386/prefetchi-1b.c b/gcc/testsuite/gcc.target/i386/prefetchi-1b.c
new file mode 100644
index 000000000..93139554d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/prefetchi-1b.c
@@ -0,0 +1,26 @@
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-options "-mprefetchi -O0" } */
+/* { dg-final { scan-assembler-times "\[ \\t\]+prefetchit0\[ \\t\]+bar\\(%rip\\)" 1 } } */
+/* { dg-final { scan-assembler-times "\[ \\t\]+prefetchit1\[ \\t\]+bar\\(%rip\\)" 1 } } */
+
+#include <x86intrin.h>
+
+int
+bar (int a)
+{
+ return a + 1;
+}
+
+int
+foo1 (int b)
+{
+ _m_prefetchit0 (bar);
+ return bar (b) + 1;
+}
+
+int
+foo2 (int b)
+{
+ _m_prefetchit1 (bar);
+ return bar (b) + 1;
+}
--
2.31.1
|