diff mbox series

[v2] i386: Add non-optimize prefetchi intrins

Message ID 20240726085317.4167932-1-haochen.jiang@intel.com
State New
Headers show
Series [v2] i386: Add non-optimize prefetchi intrins | expand

Commit Message

Haochen Jiang July 26, 2024, 8:53 a.m. UTC
Hi all,

I added related O0 testcase in this patch.

Ok for trunk and backport to GCC 14 and GCC 13?

Thx,
Haochen

---

Changes in v2: Add testcases.

---

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.
---
 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

Comments

Hongtao Liu July 30, 2024, 1:27 a.m. UTC | #1
On Fri, Jul 26, 2024 at 4:55 PM Haochen Jiang <haochen.jiang@intel.com> wrote:
>
> Hi all,
>
> I added related O0 testcase in this patch.
>
> Ok for trunk and backport to GCC 14 and GCC 13?
Ok.
>
> Thx,
> Haochen
>
> ---
>
> Changes in v2: Add testcases.
>
> ---
>
> 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.
> ---
>  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 dfca89c7d16..d6580e504c0 100644
> --- a/gcc/config/i386/prfchiintrin.h
> +++ b/gcc/config/i386/prfchiintrin.h
> @@ -37,6 +37,7 @@
>  #define __DISABLE_PREFETCHI__
>  #endif /* __PREFETCHI__ */
>
> +#ifdef __OPTIMIZE__
>  extern __inline void
>  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
>  _m_prefetchit0 (void* __P)
> @@ -50,6 +51,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
>
>  #ifdef __DISABLE_PREFETCHI__
>  #undef __DISABLE_PREFETCHI__
> 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 00000000000..93139554d3c
> --- /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
>
Hongtao Liu July 30, 2024, 1:28 a.m. UTC | #2
On Tue, Jul 30, 2024 at 9:27 AM Hongtao Liu <crazylht@gmail.com> wrote:
>
> On Fri, Jul 26, 2024 at 4:55 PM Haochen Jiang <haochen.jiang@intel.com> wrote:
> >
> > Hi all,
> >
> > I added related O0 testcase in this patch.
> >
> > Ok for trunk and backport to GCC 14 and GCC 13?
> Ok.
I mean for trunk, and it needs jakub's approval to backport to GCC14.2.
> >
> > Thx,
> > Haochen
> >
> > ---
> >
> > Changes in v2: Add testcases.
> >
> > ---
> >
> > 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.
> > ---
> >  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 dfca89c7d16..d6580e504c0 100644
> > --- a/gcc/config/i386/prfchiintrin.h
> > +++ b/gcc/config/i386/prfchiintrin.h
> > @@ -37,6 +37,7 @@
> >  #define __DISABLE_PREFETCHI__
> >  #endif /* __PREFETCHI__ */
> >
> > +#ifdef __OPTIMIZE__
> >  extern __inline void
> >  __attribute__((__gnu_inline__, __always_inline__, __artificial__))
> >  _m_prefetchit0 (void* __P)
> > @@ -50,6 +51,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
> >
> >  #ifdef __DISABLE_PREFETCHI__
> >  #undef __DISABLE_PREFETCHI__
> > 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 00000000000..93139554d3c
> > --- /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
> >
>
>
> --
> BR,
> Hongtao
Jakub Jelinek July 30, 2024, 6:57 a.m. UTC | #3
On Tue, Jul 30, 2024 at 09:28:46AM +0800, Hongtao Liu wrote:
> On Tue, Jul 30, 2024 at 9:27 AM Hongtao Liu <crazylht@gmail.com> wrote:
> >
> > On Fri, Jul 26, 2024 at 4:55 PM Haochen Jiang <haochen.jiang@intel.com> wrote:
> > >
> > > Hi all,
> > >
> > > I added related O0 testcase in this patch.
> > >
> > > Ok for trunk and backport to GCC 14 and GCC 13?
> > Ok.
> I mean for trunk, and it needs jakub's approval to backport to GCC14.2.

IMHO this needs to wait for GCC 14.3 (aka can be committed to 14 branch
after the 14.2 release).

	Jakub
Haochen Jiang July 30, 2024, 7:18 a.m. UTC | #4
> -----Original Message-----
> From: Jakub Jelinek <jakub@redhat.com>
> Sent: Tuesday, July 30, 2024 2:57 PM
> To: Hongtao Liu <crazylht@gmail.com>
> Cc: Jiang, Haochen <haochen.jiang@intel.com>; gcc-patches@gcc.gnu.org;
> Liu, Hongtao <hongtao.liu@intel.com>; ubizjak@gmail.com
> Subject: Re: [PATCH v2] i386: Add non-optimize prefetchi intrins
> 
> On Tue, Jul 30, 2024 at 09:28:46AM +0800, Hongtao Liu wrote:
> > On Tue, Jul 30, 2024 at 9:27 AM Hongtao Liu <crazylht@gmail.com> wrote:
> > >
> > > On Fri, Jul 26, 2024 at 4:55 PM Haochen Jiang <haochen.jiang@intel.com>
> wrote:
> > > >
> > > > Hi all,
> > > >
> > > > I added related O0 testcase in this patch.
> > > >
> > > > Ok for trunk and backport to GCC 14 and GCC 13?
> > > Ok.
> > I mean for trunk, and it needs jakub's approval to backport to GCC14.2.
> 
> IMHO this needs to wait for GCC 14.3 (aka can be committed to 14 branch
> after the 14.2 release).

Ok, for GCC14, I will wait until the release happen.

Thx,
Haochen

> 
> 	Jakub
diff mbox series

Patch

diff --git a/gcc/config/i386/prfchiintrin.h b/gcc/config/i386/prfchiintrin.h
index dfca89c7d16..d6580e504c0 100644
--- a/gcc/config/i386/prfchiintrin.h
+++ b/gcc/config/i386/prfchiintrin.h
@@ -37,6 +37,7 @@ 
 #define __DISABLE_PREFETCHI__
 #endif /* __PREFETCHI__ */
 
+#ifdef __OPTIMIZE__
 extern __inline void
 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
 _m_prefetchit0 (void* __P)
@@ -50,6 +51,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
 
 #ifdef __DISABLE_PREFETCHI__
 #undef __DISABLE_PREFETCHI__
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 00000000000..93139554d3c
--- /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;
+}