This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [green@cygnus.com: g++ ICE]
- To: Mark Mitchell <mark at codesourcery dot com>
- Subject: Re: [green@cygnus.com: g++ ICE]
- From: Richard Henderson <rth at cygnus dot com>
- Date: Sun, 26 Mar 2000 16:52:46 -0800
- Cc: Anthony Green <green at cygnus dot com>, gcc-patches at gcc dot gnu dot org
- References: <200003222221.OAA18365@hoser.cygnus.com> <20000325194820B.mitchell@codesourcery.com>
On Sat, Mar 25, 2000 at 07:48:20PM -0800, Mark Mitchell wrote:
> Anthony> See http://www.cygnus.com/~green/natClass.ii.gz
[...]
> o However, we then call `optimize_tail_recursion', passing it
> the original CALL_EXPR, which has the arguments without the
> UNSAVE_EXPR.
This fixes the test case. Bootstrapped on alphaev6-linux.
r~
* calls.c (expand_call): Pass parms not original exp to
optimize_tail_recursion. Mind return value instead of looking
for a barrier.
* stmt.c (optimize_tail_recursion): Take parameter list, not entire
call_expr. Move checks for call_expr and current_function_decl ...
(expand_return): ... here.
Index: calls.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/calls.c,v
retrieving revision 1.104
diff -c -p -d -r1.104 calls.c
*** calls.c 2000/03/25 01:06:35 1.104
--- calls.c 2000/03/27 00:47:12
*************** expand_call (exp, target, ignore)
*** 2099,2125 ****
recursion call can be ignored if we indeed use the tail recursion
call expansion. */
int save_pending_stack_adjust = pending_stack_adjust;
- rtx last;
/* Use a new sequence to hold any RTL we generate. We do not even
know if we will use this RTL yet. The final decision can not be
made until after RTL generation for the entire function is
complete. */
! push_to_sequence (0);
/* Emit the pending stack adjustments before we expand any arguments. */
do_pending_stack_adjust ();
! optimize_tail_recursion (exp, get_last_insn ());
!
! last = get_last_insn ();
! tail_recursion_insns = get_insns ();
end_sequence ();
-
- /* If the last insn on the tail recursion sequence is not a
- BARRIER, then tail recursion optimization failed. */
- if (last == NULL_RTX || GET_CODE (last) != BARRIER)
- tail_recursion_insns = NULL_RTX;
/* Restore the original pending stack adjustment for the sibling and
normal call cases below. */
--- 2099,2117 ----
recursion call can be ignored if we indeed use the tail recursion
call expansion. */
int save_pending_stack_adjust = pending_stack_adjust;
/* Use a new sequence to hold any RTL we generate. We do not even
know if we will use this RTL yet. The final decision can not be
made until after RTL generation for the entire function is
complete. */
! start_sequence ();
/* Emit the pending stack adjustments before we expand any arguments. */
do_pending_stack_adjust ();
! if (optimize_tail_recursion (actparms, get_last_insn ()))
! tail_recursion_insns = get_insns ();
end_sequence ();
/* Restore the original pending stack adjustment for the sibling and
normal call cases below. */
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/stmt.c,v
retrieving revision 1.133
diff -c -p -d -r1.133 stmt.c
*** stmt.c 2000/03/25 18:34:04 1.133
--- stmt.c 2000/03/27 00:47:12
*************** expand_return (retval)
*** 2872,2878 ****
}
/* Attempt to optimize the call if it is tail recursive. */
! if (optimize_tail_recursion (retval_rhs, last_insn))
return;
#ifdef HAVE_return
--- 2872,2885 ----
}
/* Attempt to optimize the call if it is tail recursive. */
! if (optimize
! && retval_rhs != NULL_TREE
! && frame_offset == 0
! && TREE_CODE (retval_rhs) == CALL_EXPR
! && TREE_CODE (TREE_OPERAND (retval_rhs, 0)) == ADDR_EXPR
! && (TREE_OPERAND (TREE_OPERAND (retval_rhs, 0), 0)
! == current_function_decl)
! && optimize_tail_recursion (TREE_OPERAND (retval_rhs, 1), last_insn))
return;
#ifdef HAVE_return
*************** drop_through_at_end_p ()
*** 3084,3116 ****
return insn && GET_CODE (insn) != BARRIER;
}
! /* Test CALL_EXPR to determine if it is a potential tail recursion call
! and emit code to optimize the tail recursion. LAST_INSN indicates where
! to place the jump to the tail recursion label. Return TRUE if the
! call was optimized into a goto.
!
! This is only used by expand_return, but expand_call is expected to
! use it soon. */
int
! optimize_tail_recursion (call_expr, last_insn)
! tree call_expr;
rtx last_insn;
{
! /* For tail-recursive call to current function,
! just jump back to the beginning.
! It's unsafe if any auto variable in this function
! has its address taken; for simplicity,
! require stack frame to be empty. */
! if (optimize && call_expr != 0
! && frame_offset == 0
! && TREE_CODE (call_expr) == CALL_EXPR
! && TREE_CODE (TREE_OPERAND (call_expr, 0)) == ADDR_EXPR
! && TREE_OPERAND (TREE_OPERAND (call_expr, 0), 0) == current_function_decl
! /* Finish checking validity, and if valid emit code
! to set the argument variables for the new call. */
! && tail_recursion_args (TREE_OPERAND (call_expr, 1),
! DECL_ARGUMENTS (current_function_decl)))
{
if (tail_recursion_label == 0)
{
--- 3091,3110 ----
return insn && GET_CODE (insn) != BARRIER;
}
! /* Attempt to optimize a potential tail recursion call into a goto.
! ARGUMENTS are the arguments to a CALL_EXPR; LAST_INSN indicates
! where to place the jump to the tail recursion label.
!
! Return TRUE if the call was optimized into a goto. */
int
! optimize_tail_recursion (arguments, last_insn)
! tree arguments;
rtx last_insn;
{
! /* Finish checking validity, and if valid emit code to set the
! argument variables for the new call. */
! if (tail_recursion_args (arguments, DECL_ARGUMENTS (current_function_decl)))
{
if (tail_recursion_label == 0)
{
*************** optimize_tail_recursion (call_expr, last
*** 3123,3129 ****
emit_barrier ();
return 1;
}
-
return 0;
}
--- 3117,3122 ----