public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Disable -fipa-ra for naked functions (PR target/85593)
@ 2018-12-06 23:34 Jakub Jelinek
  2018-12-06 23:36 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2018-12-06 23:34 UTC (permalink / raw)
  To: Richard Biener, Jeff Law; +Cc: gcc-patches

Hi!

The only documented supported content of naked functions is basic asm
statement(s).  Those don't have clobbers though, so we should ignore
naked functions for IPA-RA; if they are written the only supported way,
they will appear not to clobber any registers at all and IPA-RA will then
assume they don't clobber any registers.
While naked is a target attribute supported only on a subset of targets,
the generic code already handles it in multiple spots, so I think we can add
another spot rather than introducing a target hook for it.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2018-12-07  Jakub Jelinek  <jakub@redhat.com>

	PR target/85593
	* final.c (rest_of_handle_final): Don't call collect_fn_hard_reg_usage
	for functions with naked attribute.

	* gcc.target/i386/pr85593.c: New test.

--- gcc/final.c.jj	2018-11-21 19:38:50.264064648 +0100
+++ gcc/final.c	2018-12-06 19:01:39.052525201 +0100
@@ -4659,7 +4659,11 @@ rest_of_handle_final (void)
   final_start_function_1 (&first, asm_out_file, &seen, optimize);
   final_1 (first, asm_out_file, seen, optimize);
   if (flag_ipa_ra
-      && !lookup_attribute ("noipa", DECL_ATTRIBUTES (current_function_decl)))
+      && !lookup_attribute ("noipa", DECL_ATTRIBUTES (current_function_decl))
+      /* Functions with naked attributes are supported only with basic asm
+	 statements in the body, thus for supported use cases the information
+	 on clobbered registers is not available.  */
+      && !lookup_attribute ("naked", DECL_ATTRIBUTES (current_function_decl)))
     collect_fn_hard_reg_usage ();
   final_end_function ();
 
--- gcc/testsuite/gcc.target/i386/pr85593.c.jj	2018-12-06 19:19:17.286362641 +0100
+++ gcc/testsuite/gcc.target/i386/pr85593.c	2018-12-06 19:18:47.188850564 +0100
@@ -0,0 +1,30 @@
+/* PR target/85593 */
+/* { dg-do run { target { { i?86-*-linux* x86_64-*-linux* } && lp64 } } } */
+/* { dg-options "-O2" } */
+
+__attribute__((naked)) void
+bar (void)
+{
+  asm ("xorl %eax, %eax\n\t"
+       "xorl %edx, %edx\n\t"
+       "xorl %ecx, %ecx\n\t"
+       "xorl %esi, %esi\n\t"
+       "xorl %edi, %edi\n\t"
+       "xorl %r8d, %r8d\n\t"
+       "xorl %r9d, %r9d\n\t"
+       "xorl %r10d, %r10d\n\t"
+       "xorl %r11d, %r11d\n\t"
+       "ret");
+}
+
+int
+main ()
+{
+  int a = 42;
+  asm ("" : "+r" (a));
+  bar ();
+  asm ("" : "+r" (a));
+  if (a != 42)
+    __builtin_abort ();
+  return 0;
+}

	Jakub

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

* Re: [PATCH] Disable -fipa-ra for naked functions (PR target/85593)
  2018-12-06 23:34 [PATCH] Disable -fipa-ra for naked functions (PR target/85593) Jakub Jelinek
@ 2018-12-06 23:36 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2018-12-06 23:36 UTC (permalink / raw)
  To: Jakub Jelinek, Richard Biener; +Cc: gcc-patches

On 12/6/18 4:34 PM, Jakub Jelinek wrote:
> Hi!
> 
> The only documented supported content of naked functions is basic asm
> statement(s).  Those don't have clobbers though, so we should ignore
> naked functions for IPA-RA; if they are written the only supported way,
> they will appear not to clobber any registers at all and IPA-RA will then
> assume they don't clobber any registers.
> While naked is a target attribute supported only on a subset of targets,
> the generic code already handles it in multiple spots, so I think we can add
> another spot rather than introducing a target hook for it.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2018-12-07  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR target/85593
> 	* final.c (rest_of_handle_final): Don't call collect_fn_hard_reg_usage
> 	for functions with naked attribute.
> 
> 	* gcc.target/i386/pr85593.c: New test.
OK
jeff

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

end of thread, other threads:[~2018-12-06 23:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-06 23:34 [PATCH] Disable -fipa-ra for naked functions (PR target/85593) Jakub Jelinek
2018-12-06 23:36 ` Jeff Law

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