public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] x86: Check interrupt instead of noreturn attribute
@ 2024-02-25 16:01 H.J. Lu
  2024-02-25 16:54 ` Uros Bizjak
  0 siblings, 1 reply; 3+ messages in thread
From: H.J. Lu @ 2024-02-25 16:01 UTC (permalink / raw)
  To: gcc-patches; +Cc: ubizjak, hongtao.liu

ix86_set_func_type checks noreturn attribute to avoid incompatible
attribute error in LTO1 on interrupt functions.  Since TREE_THIS_VOLATILE
is set also for _Noreturn without noreturn attribute, check interrupt
attribute for interrupt functions instead.

gcc/

	PR target/114097
	* config/i386/i386-options.cc (ix86_set_func_type): Check
	interrupt instead of noreturn attribute.

gcc/testsuite/

	PR target/114097
	* gcc.target/i386/pr114097-1.c: New test.
---
 gcc/config/i386/i386-options.cc            |  3 ++-
 gcc/testsuite/gcc.target/i386/pr114097-1.c | 26 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr114097-1.c

diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
index 93a01146db7..82fe0d228cd 100644
--- a/gcc/config/i386/i386-options.cc
+++ b/gcc/config/i386/i386-options.cc
@@ -3395,7 +3395,8 @@ ix86_set_func_type (tree fndecl)
      incompatible attribute error in LTO1.  */
   bool has_no_callee_saved_registers
     = ((TREE_THIS_VOLATILE (fndecl)
-	&& lookup_attribute ("noreturn", DECL_ATTRIBUTES (fndecl))
+	&& !lookup_attribute ("interrupt",
+			      TYPE_ATTRIBUTES (TREE_TYPE (fndecl)))
 	&& optimize
 	&& !optimize_debug
 	&& (TREE_NOTHROW (fndecl) || !flag_exceptions))
diff --git a/gcc/testsuite/gcc.target/i386/pr114097-1.c b/gcc/testsuite/gcc.target/i386/pr114097-1.c
new file mode 100644
index 00000000000..b14c7b6214d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr114097-1.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mtune-ctrl=^prologue_using_move,^epilogue_using_move -fomit-frame-pointer" } */
+
+#define ARRAY_SIZE 256
+
+extern int array[ARRAY_SIZE][ARRAY_SIZE][ARRAY_SIZE];
+extern int value (int, int, int)
+#ifndef __x86_64__
+__attribute__ ((regparm(3)))
+#endif
+;
+
+void
+_Noreturn
+no_return_to_caller (void)
+{
+  unsigned i, j, k;
+  for (i = ARRAY_SIZE; i > 0; --i)
+    for (j = ARRAY_SIZE; j > 0; --j)
+      for (k = ARRAY_SIZE; k > 0; --k)
+	array[i - 1][j - 1][k - 1] = value (i, j, k);
+  while (1);
+}
+
+/* { dg-final { scan-assembler-not "push" } } */
+/* { dg-final { scan-assembler-not "pop" } } */
-- 
2.43.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86: Check interrupt instead of noreturn attribute
  2024-02-25 16:01 [PATCH] x86: Check interrupt instead of noreturn attribute H.J. Lu
@ 2024-02-25 16:54 ` Uros Bizjak
  2024-02-25 17:03   ` H.J. Lu
  0 siblings, 1 reply; 3+ messages in thread
From: Uros Bizjak @ 2024-02-25 16:54 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches, hongtao.liu

On Sun, Feb 25, 2024 at 5:01 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> ix86_set_func_type checks noreturn attribute to avoid incompatible
> attribute error in LTO1 on interrupt functions.  Since TREE_THIS_VOLATILE
> is set also for _Noreturn without noreturn attribute, check interrupt
> attribute for interrupt functions instead.

Please also adjust the comment above the change. The current comment
even explains why the "noreturn" attribute is checked instead of
"interrupt" attribute.

Uros.

>
> gcc/
>
>         PR target/114097
>         * config/i386/i386-options.cc (ix86_set_func_type): Check
>         interrupt instead of noreturn attribute.
>
> gcc/testsuite/
>
>         PR target/114097
>         * gcc.target/i386/pr114097-1.c: New test.
> ---
>  gcc/config/i386/i386-options.cc            |  3 ++-
>  gcc/testsuite/gcc.target/i386/pr114097-1.c | 26 ++++++++++++++++++++++
>  2 files changed, 28 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.target/i386/pr114097-1.c
>
> diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
> index 93a01146db7..82fe0d228cd 100644
> --- a/gcc/config/i386/i386-options.cc
> +++ b/gcc/config/i386/i386-options.cc
> @@ -3395,7 +3395,8 @@ ix86_set_func_type (tree fndecl)
>       incompatible attribute error in LTO1.  */
>    bool has_no_callee_saved_registers
>      = ((TREE_THIS_VOLATILE (fndecl)
> -       && lookup_attribute ("noreturn", DECL_ATTRIBUTES (fndecl))
> +       && !lookup_attribute ("interrupt",
> +                             TYPE_ATTRIBUTES (TREE_TYPE (fndecl)))
>         && optimize
>         && !optimize_debug
>         && (TREE_NOTHROW (fndecl) || !flag_exceptions))
> diff --git a/gcc/testsuite/gcc.target/i386/pr114097-1.c b/gcc/testsuite/gcc.target/i386/pr114097-1.c
> new file mode 100644
> index 00000000000..b14c7b6214d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr114097-1.c
> @@ -0,0 +1,26 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -mtune-ctrl=^prologue_using_move,^epilogue_using_move -fomit-frame-pointer" } */
> +
> +#define ARRAY_SIZE 256
> +
> +extern int array[ARRAY_SIZE][ARRAY_SIZE][ARRAY_SIZE];
> +extern int value (int, int, int)
> +#ifndef __x86_64__
> +__attribute__ ((regparm(3)))
> +#endif
> +;
> +
> +void
> +_Noreturn
> +no_return_to_caller (void)
> +{
> +  unsigned i, j, k;
> +  for (i = ARRAY_SIZE; i > 0; --i)
> +    for (j = ARRAY_SIZE; j > 0; --j)
> +      for (k = ARRAY_SIZE; k > 0; --k)
> +       array[i - 1][j - 1][k - 1] = value (i, j, k);
> +  while (1);
> +}
> +
> +/* { dg-final { scan-assembler-not "push" } } */
> +/* { dg-final { scan-assembler-not "pop" } } */
> --
> 2.43.2
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86: Check interrupt instead of noreturn attribute
  2024-02-25 16:54 ` Uros Bizjak
@ 2024-02-25 17:03   ` H.J. Lu
  0 siblings, 0 replies; 3+ messages in thread
From: H.J. Lu @ 2024-02-25 17:03 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: gcc-patches, hongtao.liu

On Sun, Feb 25, 2024 at 8:54 AM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> On Sun, Feb 25, 2024 at 5:01 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > ix86_set_func_type checks noreturn attribute to avoid incompatible
> > attribute error in LTO1 on interrupt functions.  Since TREE_THIS_VOLATILE
> > is set also for _Noreturn without noreturn attribute, check interrupt
> > attribute for interrupt functions instead.
>
> Please also adjust the comment above the change. The current comment
> even explains why the "noreturn" attribute is checked instead of
> "interrupt" attribute.

How about this?

     NB: Can't use just TREE_THIS_VOLATILE to check if this is a noreturn
     function.  The local-pure-const pass turns an interrupt function
     into a noreturn function by setting TREE_THIS_VOLATILE.  Normally
     the local-pure-const pass is run after ix86_set_func_type is called.
     When the local-pure-const pass is enabled for LTO, the interrupt
     function is marked with TREE_THIS_VOLATILE in the IR output, which
     leads to the incompatible attribute error in LTO1.  Ignore the
     interrupt function in this case.

Thanks.

> Uros.
>
> >
> > gcc/
> >
> >         PR target/114097
> >         * config/i386/i386-options.cc (ix86_set_func_type): Check
> >         interrupt instead of noreturn attribute.
> >
> > gcc/testsuite/
> >
> >         PR target/114097
> >         * gcc.target/i386/pr114097-1.c: New test.
> > ---
> >  gcc/config/i386/i386-options.cc            |  3 ++-
> >  gcc/testsuite/gcc.target/i386/pr114097-1.c | 26 ++++++++++++++++++++++
> >  2 files changed, 28 insertions(+), 1 deletion(-)
> >  create mode 100644 gcc/testsuite/gcc.target/i386/pr114097-1.c
> >
> > diff --git a/gcc/config/i386/i386-options.cc b/gcc/config/i386/i386-options.cc
> > index 93a01146db7..82fe0d228cd 100644
> > --- a/gcc/config/i386/i386-options.cc
> > +++ b/gcc/config/i386/i386-options.cc
> > @@ -3395,7 +3395,8 @@ ix86_set_func_type (tree fndecl)
> >       incompatible attribute error in LTO1.  */
> >    bool has_no_callee_saved_registers
> >      = ((TREE_THIS_VOLATILE (fndecl)
> > -       && lookup_attribute ("noreturn", DECL_ATTRIBUTES (fndecl))
> > +       && !lookup_attribute ("interrupt",
> > +                             TYPE_ATTRIBUTES (TREE_TYPE (fndecl)))
> >         && optimize
> >         && !optimize_debug
> >         && (TREE_NOTHROW (fndecl) || !flag_exceptions))
> > diff --git a/gcc/testsuite/gcc.target/i386/pr114097-1.c b/gcc/testsuite/gcc.target/i386/pr114097-1.c
> > new file mode 100644
> > index 00000000000..b14c7b6214d
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/i386/pr114097-1.c
> > @@ -0,0 +1,26 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-O2 -mtune-ctrl=^prologue_using_move,^epilogue_using_move -fomit-frame-pointer" } */
> > +
> > +#define ARRAY_SIZE 256
> > +
> > +extern int array[ARRAY_SIZE][ARRAY_SIZE][ARRAY_SIZE];
> > +extern int value (int, int, int)
> > +#ifndef __x86_64__
> > +__attribute__ ((regparm(3)))
> > +#endif
> > +;
> > +
> > +void
> > +_Noreturn
> > +no_return_to_caller (void)
> > +{
> > +  unsigned i, j, k;
> > +  for (i = ARRAY_SIZE; i > 0; --i)
> > +    for (j = ARRAY_SIZE; j > 0; --j)
> > +      for (k = ARRAY_SIZE; k > 0; --k)
> > +       array[i - 1][j - 1][k - 1] = value (i, j, k);
> > +  while (1);
> > +}
> > +
> > +/* { dg-final { scan-assembler-not "push" } } */
> > +/* { dg-final { scan-assembler-not "pop" } } */
> > --
> > 2.43.2
> >



-- 
H.J.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-25 17:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-25 16:01 [PATCH] x86: Check interrupt instead of noreturn attribute H.J. Lu
2024-02-25 16:54 ` Uros Bizjak
2024-02-25 17:03   ` 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).