public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: avoid unnecessary register saves for setjmp
@ 2003-11-27  9:19 Chris Lattner
  2003-11-27  9:21 ` Andrew Haley
  0 siblings, 1 reply; 33+ messages in thread
From: Chris Lattner @ 2003-11-27  9:19 UTC (permalink / raw)
  To: Zack Weinberg; +Cc: Richard.Earnshaw, Jim Wilson, gcc-patches


Zack Weinberg said:
> I'm going to take this opportunity to throw in a suggestion I've made
> before, which is that setjmp/longjmp should - always, not just when
> special variants are used - be converted by the front end into
> invocations of the exception-unwinding facility, which gives us tons
> more control.

This is exactly what we do in LLVM, which makes a lot of things much
nicer.  For example, because it uses the normal EH facilities in LLVM,
inlining a longjmp'ing function into the setjmp'ing function automatically
turns the stack unwinding operation into a direct branch, same as normal
EH.

This allows us to do aggressive optimizations on both the setjmp'ing and
longjmp'ing functions: there are no special cases needed or optimizations
disabled.  The only negative of doing this is that it adds a lot of edges
to the CFG's of some functions, but you have to represent the possible
control flow SOMEHOW.  :)  Also, the normal LLVM EH pruner automatically
deletes the edges from function calls that provably cannot unwind, so it
gets rid of a lot of the problem.

Just food for thought,

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/

^ permalink raw reply	[flat|nested] 33+ messages in thread
* Re: avoid unnecessary register saves for setjmp
@ 2003-11-22  4:13 Richard Kenner
  2003-12-01  3:29 ` Jim Wilson
  0 siblings, 1 reply; 33+ messages in thread
From: Richard Kenner @ 2003-11-22  4:13 UTC (permalink / raw)
  To: geoffk; +Cc: gcc-patches

    I've looked at this some time in the past (I don't remember the exact
    circumstances).  I came to the same conclusion as you, except in the
    case when NON_SAVING_SETJMP is defined, when we do need to save any
    call-saved registers.

Well, you certainly need to save all the caller-saved registers if there
are any nonlocal gotos (which you have in the Ada exception case), but,
as I understand this change, it still does.

^ permalink raw reply	[flat|nested] 33+ messages in thread
* avoid unnecessary register saves for setjmp
@ 2003-11-21  5:54 Jim Wilson
  2003-11-21 18:39 ` Daniel Jacobowitz
  2003-11-21 20:14 ` Geoff Keating
  0 siblings, 2 replies; 33+ messages in thread
From: Jim Wilson @ 2003-11-21  5:54 UTC (permalink / raw)
  To: gcc-patches

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

This is for PR c/13133.

Gcc saves and restores all call-saved registers around a call to
setjmp.  This is unnecessary, and is a performance regression from
gcc-3.0 and earlier.  This showed up on IA-64 as a libpthread
performance problem, as some critical paths in libpthread use setjmp,
and IA-64 has lots of registers that get saved and restored.  This has
also been reported as a problem for PowerPC with Altivec.  See PR 12817.

The code in question was originally added Feb 23, 1996 by Richard
Kenner.  He modified the builtin setjmp expander to emit a CONST_CALL_P
NOTE_INSN_SETJMP note, and he added code to reload to mark all call
saved registers as live when one of these notes was seen.

On Nov 1, 1997, Jeff Law deleted the code in the buildint setjmp
expander that was emitting the CONST_CALL_P NOTE_INSN_SETJMP note, but
the code in reload remained.  It now did nothing.  A little bit later,
the expander was modified to set current_function_has_nonlocal_label
which gives the same effect as the reload code, but in a way that flow
can understand.

On Aug 7, 2001, Jan Hubicka checked in a patch that removed
NOTE_INSN_SETJMP notes and replaced them with REG_SETJMP reg notes. 
When this change was made, the CONST_CALL_P test in the reload code was
lost, and now the code was enabled for every setjmp call, which was not
the intent of the code.

The proper fix here is to just delete the long obsolete reload code for
REG_SETJMP.

This was tested with a ia64-linux bootstrap and make check.  There were
no regressions.  This was also tested with the testcase in PR 13133.

I realize this is a bit risky, since running the testsuite does not
really test setjmp.  So I am interested in hearing about any problems
this might cause.

I have checked in the attached patch for this problem.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com

[-- Attachment #2: patch.reload.setjmp --]
[-- Type: text/plain, Size: 1908 bytes --]

2003-11-20  James E Wilson  <wilson@specifixinc.com>

	PR c/13133
	* reload1.c (reload): Delete special handling for setjmp.

Index: reload1.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/reload1.c,v
retrieving revision 1.408
diff -p -r1.408 reload1.c
*** reload1.c	27 Oct 2003 10:52:46 -0000	1.408
--- reload1.c	16 Nov 2003 07:45:13 -0000
*************** reload (rtx first, int global)
*** 698,706 ****
    /* Look for REG_EQUIV notes; record what each pseudo is equivalent to.
       Also find all paradoxical subregs and find largest such for each pseudo.
       On machines with small register classes, record hard registers that
!      are used for user variables.  These can never be used for spills.
!      Also look for a "constant" REG_SETJMP.  This means that all
!      caller-saved registers must be marked live.  */
  
    num_eliminable_invariants = 0;
    for (insn = first; insn; insn = NEXT_INSN (insn))
--- 698,704 ----
    /* Look for REG_EQUIV notes; record what each pseudo is equivalent to.
       Also find all paradoxical subregs and find largest such for each pseudo.
       On machines with small register classes, record hard registers that
!      are used for user variables.  These can never be used for spills.  */
  
    num_eliminable_invariants = 0;
    for (insn = first; insn; insn = NEXT_INSN (insn))
*************** reload (rtx first, int global)
*** 713,724 ****
        if (INSN_P (insn) && GET_CODE (PATTERN (insn)) == USE
  	  && GET_MODE (insn) != VOIDmode)
  	PUT_MODE (insn, VOIDmode);
- 
-       if (GET_CODE (insn) == CALL_INSN
- 	  && find_reg_note (insn, REG_SETJMP, NULL))
- 	for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
- 	  if (! call_used_regs[i])
- 	    regs_ever_live[i] = 1;
  
        if (set != 0 && GET_CODE (SET_DEST (set)) == REG)
  	{
--- 711,716 ----

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

end of thread, other threads:[~2003-12-01  3:29 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <5cad8ef043da68f2a3332f00bd6a186a3fc6195b@mail.esmertec.com>
2003-11-27 20:44 ` avoid unnecessary register saves for setjmp Chris Lattner
2003-11-27  9:19 Chris Lattner
2003-11-27  9:21 ` Andrew Haley
2003-11-27  9:22   ` Chris Lattner
2003-11-27  9:39     ` Andrew Haley
2003-11-27  9:43       ` Chris Lattner
2003-11-27 10:14       ` Zack Weinberg
2003-11-27 10:15         ` Chris Lattner
2003-11-27 11:01           ` Zack Weinberg
2003-11-27 20:28             ` Chris Lattner
2003-11-27 20:51               ` Gabriel Dos Reis
2003-11-27 15:41           ` Jan Vroonhof
2003-11-27 16:23           ` Jan Vroonhof
2003-11-27 10:31         ` Andrew Haley
2003-11-27 10:53           ` Zack Weinberg
  -- strict thread matches above, loose matches on Subject: below --
2003-11-22  4:13 Richard Kenner
2003-12-01  3:29 ` Jim Wilson
2003-11-21  5:54 Jim Wilson
2003-11-21 18:39 ` Daniel Jacobowitz
2003-11-22  0:22   ` Jim Wilson
2003-11-22  3:57     ` Daniel Jacobowitz
2003-11-22  9:06       ` Jim Wilson
2003-11-22 14:37         ` Richard Earnshaw
2003-11-22 16:33           ` Daniel Jacobowitz
2003-11-27  9:11             ` Zack Weinberg
2003-11-27 17:11               ` Andrew Pinski
2003-11-27 18:23                 ` Zack Weinberg
2003-11-28  5:15                   ` Geert Bosch
2003-11-28 11:14                   ` Richard Earnshaw
2003-11-28 14:02             ` Richard Earnshaw
2003-11-21 20:14 ` Geoff Keating
2003-11-22  0:20   ` Jim Wilson
2003-11-30  9:23   ` Jim Wilson

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