public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR rtl-optimization/16294
@ 2004-07-11 23:49 Eric Botcazou
  2004-07-18  2:04 ` Zack Weinberg
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Botcazou @ 2004-07-11 23:49 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1785 bytes --]

Hi,

This is the code quality regression introduced my RTL prologue/epilogue patch 
on SPARC, which shows up in about a dozen of testcases of the C testsuite 
gcc.c-torture/compile at -O2.  It's typically:

@@ -26,7 +24,8 @@
 	mov	1024, %o2
 	ldsh	[%fp-1056], %l4
 	cmp	%l4, 0
-	ble,pn	%icc, .LL1
+	ble,pn	%icc, .LL10
+	nop
 	mov	1024, %l3
 	add	%fp, -1064, %i5
 	add	%fp, -1072, %l7
@@ -59,8 +58,8 @@
 	cmp	%l4, 0
 	bg,pt	%icc, .LL4
 	add	%l5, 4, %l5
-.LL1:
+.LL10:
 	return	%i7+8
-	nop
+	 nop
 	.size	sdbm__splpage, .-sdbm__splpage

that is, the slot of branches targetting the return is not filled anymore.


The problem lies in resource.c and is twofold:
- mark_target_live_regs pessimizes way too much when computing the liveness 
information for the return (it may end up scanning forwards from the 
beginning of the function!).  The proposed fix is basically to reuse the 
liveness information computed for the end of the function.
- the liveness information computed for the end of the function is awful when 
the epilogue is emitted in the middle of the function: the function is 
scanned til the end!

The patch cures all code quality regressions in the gcc.c-torture/compile 
testsuite at -O2 except one (a corner case with ill-formed code).  I think 
an additional win could be to apply the trick to every insn in the epilogue, 
scanning backwards from the return.  I'll be experimenting this.

Bootstrapped/regtested on sparc64-sun-solaris2.9 and sparc-sun-solaris2.8.  
OK for mainline?


2004-07-11  Eric Botcazou  <ebotcazou@libertysurf.fr>

	PR rtl-optimization/16294
	* resource.c (return_insn_p): New predicate.
	(mark_target_live_regs): Use it.  Special-case return insns.
	(init_resource_info): Use it.  Don't scan the epilogue past
	a return.


-- 
Eric Botcazou

[-- Attachment #2: pr16294-2.diff --]
[-- Type: text/x-diff, Size: 1677 bytes --]

Index: resource.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/resource.c,v
retrieving revision 1.71
diff -u -p -r1.71 resource.c
--- resource.c	9 Jul 2004 03:29:34 -0000	1.71
+++ resource.c	11 Jul 2004 09:05:07 -0000
@@ -836,6 +836,20 @@ mark_set_resources (rtx x, struct resour
       }
 }
 \f
+/* Return TRUE if INSN is a return, possibly with a filled delay slot.  */
+
+static bool
+return_insn_p (rtx insn)
+{
+  if (GET_CODE (insn) == JUMP_INSN && GET_CODE (PATTERN (insn)) == RETURN)
+    return true;
+
+  if (GET_CODE (insn) == INSN && GET_CODE (PATTERN (insn)) == SEQUENCE)
+    return return_insn_p (XVECEXP (PATTERN (insn), 0, 0));
+
+  return false;
+}
+
 /* Set the resources that are live at TARGET.
 
    If TARGET is zero, we refer to the end of the current function and can
@@ -894,6 +908,14 @@ mark_target_live_regs (rtx insns, rtx ta
       return;
     }
 
+  /* Handle return insn.  */
+  else if (return_insn_p (target))
+    {
+      *res = end_of_function_needs;
+      mark_referenced_resources (target, res, 0);
+      return;
+    }
+
   /* We have to assume memory is needed, but the CC isn't.  */
   res->memory = 1;
   res->volatil = res->unch_memory = 0;
@@ -1203,7 +1225,8 @@ init_resource_info (rtx epilogue_insn)
 
   start_of_epilogue_needs = end_of_function_needs;
 
-  while ((epilogue_insn = next_nonnote_insn (epilogue_insn)))
+  while ((epilogue_insn = next_nonnote_insn (epilogue_insn)) != NULL_RTX
+	 && ! return_insn_p (epilogue_insn))
     mark_set_resources (epilogue_insn, &end_of_function_needs, 0,
 			MARK_SRC_DEST_CALL);
 

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

* Re: [PATCH] Fix PR rtl-optimization/16294
  2004-07-11 23:49 [PATCH] Fix PR rtl-optimization/16294 Eric Botcazou
@ 2004-07-18  2:04 ` Zack Weinberg
  0 siblings, 0 replies; 2+ messages in thread
From: Zack Weinberg @ 2004-07-18  2:04 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches

Eric Botcazou <ebotcazou@libertysurf.fr> writes:

> 2004-07-11  Eric Botcazou  <ebotcazou@libertysurf.fr>
>
> 	PR rtl-optimization/16294
> 	* resource.c (return_insn_p): New predicate.
> 	(mark_target_live_regs): Use it.  Special-case return insns.
> 	(init_resource_info): Use it.  Don't scan the epilogue past
> 	a return.

OK mainline.

zw

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

end of thread, other threads:[~2004-07-17 17:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-11 23:49 [PATCH] Fix PR rtl-optimization/16294 Eric Botcazou
2004-07-18  2:04 ` Zack Weinberg

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