Merge branch 'master' of ssh://crater.dragonflybsd.org/repository/git/dragonfly
[dragonfly.git] / contrib / gcc-3.4 / gcc / sibcall.c
1 /* Generic sibling call optimization support
2    Copyright (C) 1999, 2000, 2001, 2002, 2003
3    Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26
27 #include "rtl.h"
28 #include "regs.h"
29 #include "function.h"
30 #include "hard-reg-set.h"
31 #include "flags.h"
32 #include "insn-config.h"
33 #include "recog.h"
34 #include "basic-block.h"
35 #include "output.h"
36 #include "except.h"
37 #include "tree.h"
38
39 /* In case alternate_exit_block contains copy from pseudo, to return value,
40    record the pseudo here.  In such case the pseudo must be set to function
41    return in the sibcall sequence.  */
42 static rtx return_value_pseudo;
43
44 static int identify_call_return_value (rtx, rtx *, rtx *);
45 static rtx skip_copy_to_return_value (rtx);
46 static rtx skip_use_of_return_value (rtx, enum rtx_code);
47 static rtx skip_stack_adjustment (rtx);
48 static rtx skip_pic_restore (rtx);
49 static rtx skip_jump_insn (rtx);
50 static int call_ends_block_p (rtx, rtx);
51 static int uses_addressof (rtx);
52 static int sequence_uses_addressof (rtx);
53 static void purge_reg_equiv_notes (void);
54 static void purge_mem_unchanging_flag (rtx);
55 static rtx skip_unreturned_value (rtx);
56
57 /* Examine a CALL_PLACEHOLDER pattern and determine where the call's
58    return value is located.  P_HARD_RETURN receives the hard register
59    that the function used; P_SOFT_RETURN receives the pseudo register
60    that the sequence used.  Return nonzero if the values were located.  */
61
62 static int
63 identify_call_return_value (rtx cp, rtx *p_hard_return, rtx *p_soft_return)
64 {
65   rtx insn, set, hard, soft;
66
67   insn = XEXP (cp, 0);
68   /* Search backward through the "normal" call sequence to the CALL insn.  */
69   while (NEXT_INSN (insn))
70     insn = NEXT_INSN (insn);
71   while (GET_CODE (insn) != CALL_INSN)
72     insn = PREV_INSN (insn);
73
74   /* Assume the pattern is (set (dest) (call ...)), or that the first
75      member of a parallel is.  This is the hard return register used
76      by the function.  */
77   if (GET_CODE (PATTERN (insn)) == SET
78       && GET_CODE (SET_SRC (PATTERN (insn))) == CALL)
79     hard = SET_DEST (PATTERN (insn));
80   else if (GET_CODE (PATTERN (insn)) == PARALLEL
81            && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET
82            && GET_CODE (SET_SRC (XVECEXP (PATTERN (insn), 0, 0))) == CALL)
83     hard = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
84   else
85     return 0;
86
87   /* If we didn't get a single hard register (e.g. a parallel), give up.  */
88   if (GET_CODE (hard) != REG)
89     return 0;
90
91   /* Stack adjustment done after call may appear here.  */
92   insn = skip_stack_adjustment (insn);
93   if (! insn)
94     return 0;
95
96   /* Restore of GP register may appear here.  */
97   insn = skip_pic_restore (insn);
98   if (! insn)
99     return 0;
100
101   /* If there's nothing after, there's no soft return value.  */
102   insn = NEXT_INSN (insn);
103   if (! insn)
104     return 0;
105
106   /* We're looking for a source of the hard return register.  */
107   set = single_set (insn);
108   if (! set || SET_SRC (set) != hard)
109     return 0;
110
111   soft = SET_DEST (set);
112   insn = NEXT_INSN (insn);
113
114   /* Allow this first destination to be copied to a second register,
115      as might happen if the first register wasn't the particular pseudo
116      we'd been expecting.  */
117   if (insn
118       && (set = single_set (insn)) != NULL_RTX
119       && SET_SRC (set) == soft)
120     {
121       soft = SET_DEST (set);
122       insn = NEXT_INSN (insn);
123     }
124
125   /* Don't fool with anything but pseudo registers.  */
126   if (GET_CODE (soft) != REG || REGNO (soft) < FIRST_PSEUDO_REGISTER)
127     return 0;
128
129   /* This value must not be modified before the end of the sequence.  */
130   if (reg_set_between_p (soft, insn, NULL_RTX))
131     return 0;
132
133   *p_hard_return = hard;
134   *p_soft_return = soft;
135
136   return 1;
137 }
138
139 /* If the first real insn after ORIG_INSN copies to this function's
140    return value from RETVAL, then return the insn which performs the
141    copy.  Otherwise return ORIG_INSN.  */
142
143 static rtx
144 skip_copy_to_return_value (rtx orig_insn)
145 {
146   rtx insn, set = NULL_RTX;
147   rtx hardret, softret;
148
149   /* If there is no return value, we have nothing to do.  */
150   if (! identify_call_return_value (PATTERN (orig_insn), &hardret, &softret))
151     return orig_insn;
152
153   insn = next_nonnote_insn (orig_insn);
154   if (! insn)
155     return orig_insn;
156
157   set = single_set (insn);
158   if (! set)
159     return orig_insn;
160
161   if (return_value_pseudo)
162     {
163       if (SET_DEST (set) == return_value_pseudo
164           && SET_SRC (set) == softret)
165         return insn;
166       return orig_insn;
167     }
168
169   /* The destination must be the same as the called function's return
170      value to ensure that any return value is put in the same place by the
171      current function and the function we're calling.
172
173      Further, the source must be the same as the pseudo into which the
174      called function's return value was copied.  Otherwise we're returning
175      some other value.  */
176
177 #ifndef OUTGOING_REGNO
178 #define OUTGOING_REGNO(N) (N)
179 #endif
180
181   if (SET_DEST (set) == current_function_return_rtx
182       && REG_P (SET_DEST (set))
183       && OUTGOING_REGNO (REGNO (SET_DEST (set))) == REGNO (hardret)
184       && SET_SRC (set) == softret)
185     return insn;
186
187   /* Recognize the situation when the called function's return value
188      is copied in two steps: first into an intermediate pseudo, then
189      the into the calling functions return value register.  */
190
191   if (REG_P (SET_DEST (set))
192       && SET_SRC (set) == softret)
193     {
194       rtx x = SET_DEST (set);
195
196       insn = next_nonnote_insn (insn);
197       if (! insn)
198         return orig_insn;
199
200       set = single_set (insn);
201       if (! set)
202         return orig_insn;
203
204       if (SET_DEST (set) == current_function_return_rtx
205           && REG_P (SET_DEST (set))
206           && OUTGOING_REGNO (REGNO (SET_DEST (set))) == REGNO (hardret)
207           && SET_SRC (set) == x)
208         return insn;
209     }
210
211   /* It did not look like a copy of the return value, so return the
212      same insn we were passed.  */
213   return orig_insn;
214 }
215
216 /* If the first real insn after ORIG_INSN is a CODE of this function's return
217    value, return insn.  Otherwise return ORIG_INSN.  */
218
219 static rtx
220 skip_use_of_return_value (rtx orig_insn, enum rtx_code code)
221 {
222   rtx insn;
223
224   insn = next_nonnote_insn (orig_insn);
225
226   if (insn
227       && GET_CODE (insn) == INSN
228       && GET_CODE (PATTERN (insn)) == code
229       && (XEXP (PATTERN (insn), 0) == current_function_return_rtx
230           || XEXP (PATTERN (insn), 0) == const0_rtx))
231     return insn;
232
233   return orig_insn;
234 }
235
236 /* In case function does not return value,  we get clobber of pseudo followed
237    by set to hard return value.  */
238 static rtx
239 skip_unreturned_value (rtx orig_insn)
240 {
241   rtx insn = next_nonnote_insn (orig_insn);
242
243   /* Skip possible clobber of pseudo return register.  */
244   if (insn
245       && GET_CODE (insn) == INSN
246       && GET_CODE (PATTERN (insn)) == CLOBBER
247       && REG_P (XEXP (PATTERN (insn), 0))
248       && (REGNO (XEXP (PATTERN (insn), 0)) >= FIRST_PSEUDO_REGISTER))
249     {
250       rtx set_insn = next_nonnote_insn (insn);
251       rtx set;
252       if (!set_insn)
253         return insn;
254       set = single_set (set_insn);
255       if (!set
256           || SET_SRC (set) != XEXP (PATTERN (insn), 0)
257           || SET_DEST (set) != current_function_return_rtx)
258         return insn;
259       return set_insn;
260     }
261   return orig_insn;
262 }
263
264 /* If the first real insn after ORIG_INSN adjusts the stack pointer
265    by a constant, return the insn with the stack pointer adjustment.
266    Otherwise return ORIG_INSN.  */
267
268 static rtx
269 skip_stack_adjustment (rtx orig_insn)
270 {
271   rtx insn, set = NULL_RTX;
272
273   insn = next_nonnote_insn (orig_insn);
274
275   if (insn)
276     set = single_set (insn);
277
278   if (insn
279       && set
280       && GET_CODE (SET_SRC (set)) == PLUS
281       && XEXP (SET_SRC (set), 0) == stack_pointer_rtx
282       && GET_CODE (XEXP (SET_SRC (set), 1)) == CONST_INT
283       && SET_DEST (set) == stack_pointer_rtx)
284     return insn;
285
286   return orig_insn;
287 }
288
289 /* If the first real insn after ORIG_INSN sets the pic register,
290    return it.  Otherwise return ORIG_INSN.  */
291
292 static rtx
293 skip_pic_restore (rtx orig_insn)
294 {
295   rtx insn, set = NULL_RTX;
296
297   insn = next_nonnote_insn (orig_insn);
298
299   if (insn)
300     set = single_set (insn);
301
302   if (insn && set && SET_DEST (set) == pic_offset_table_rtx)
303     return insn;
304
305   return orig_insn;
306 }
307
308 /* If the first real insn after ORIG_INSN is a jump, return the JUMP_INSN.
309    Otherwise return ORIG_INSN.  */
310
311 static rtx
312 skip_jump_insn (rtx orig_insn)
313 {
314   rtx insn;
315
316   insn = next_nonnote_insn (orig_insn);
317
318   if (insn
319       && GET_CODE (insn) == JUMP_INSN
320       && any_uncondjump_p (insn))
321     return insn;
322
323   return orig_insn;
324 }
325 \f
326 /* Using the above functions, see if INSN, skipping any of the above,
327    goes all the way to END, the end of a basic block.  Return 1 if so.  */
328
329 static int
330 call_ends_block_p (rtx insn, rtx end)
331 {
332   rtx new_insn;
333
334   /* END might be a note, so get the last nonnote insn of the block.  */
335   if (NOTE_P (end))
336     end = prev_nonnote_insn (end);
337
338   /* If the call was the end of the block, then we're OK.  */
339   if (insn == end)
340     return 1;
341
342   /* Skip over copying from the call's return value pseudo into
343      this function's hard return register and if that's the end
344      of the block, we're OK.  */
345   new_insn = skip_copy_to_return_value (insn);
346
347   /* In case we return value in pseudo, we must set the pseudo to
348      return value of called function, otherwise we are returning
349      something else.  */
350   if (return_value_pseudo && insn == new_insn)
351     return 0;
352   insn = new_insn;
353
354   if (insn == end)
355     return 1;
356
357   /* Skip any stack adjustment.  */
358   insn = skip_stack_adjustment (insn);
359   if (insn == end)
360     return 1;
361
362   /* Skip over a CLOBBER of the return value as a hard reg.  */
363   insn = skip_use_of_return_value (insn, CLOBBER);
364   if (insn == end)
365     return 1;
366
367   /* Skip over a CLOBBER of the return value as a hard reg.  */
368   insn = skip_unreturned_value (insn);
369   if (insn == end)
370     return 1;
371
372   /* Skip over a USE of the return value (as a hard reg).  */
373   insn = skip_use_of_return_value (insn, USE);
374   if (insn == end)
375     return 1;
376
377   /* Skip over a JUMP_INSN at the end of the block.  If that doesn't end the
378      block, the original CALL_INSN didn't.  */
379   insn = skip_jump_insn (insn);
380   return insn == end;
381 }
382
383 /* Scan the rtx X for ADDRESSOF expressions or
384    current_function_internal_arg_pointer registers.
385    Return nonzero if an ADDRESSOF or current_function_internal_arg_pointer
386    is found outside of some MEM expression, else return zero.  */
387
388 static int
389 uses_addressof (rtx x)
390 {
391   RTX_CODE code;
392   int i, j;
393   const char *fmt;
394
395   if (x == NULL_RTX)
396     return 0;
397
398   code = GET_CODE (x);
399
400   if (code == ADDRESSOF || x == current_function_internal_arg_pointer)
401     return 1;
402
403   if (code == MEM)
404     return 0;
405
406   /* Scan all subexpressions.  */
407   fmt = GET_RTX_FORMAT (code);
408   for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
409     {
410       if (*fmt == 'e')
411         {
412           if (uses_addressof (XEXP (x, i)))
413             return 1;
414         }
415       else if (*fmt == 'E')
416         {
417           for (j = 0; j < XVECLEN (x, i); j++)
418             if (uses_addressof (XVECEXP (x, i, j)))
419               return 1;
420         }
421     }
422   return 0;
423 }
424
425 /* Scan the sequence of insns in SEQ to see if any have an ADDRESSOF
426    rtl expression or current_function_internal_arg_pointer occurrences
427    not enclosed within a MEM.  If an ADDRESSOF expression or
428    current_function_internal_arg_pointer is found, return nonzero, otherwise
429    return zero.
430
431    This function handles CALL_PLACEHOLDERs which contain multiple sequences
432    of insns.  */
433
434 static int
435 sequence_uses_addressof (rtx seq)
436 {
437   rtx insn;
438
439   for (insn = seq; insn; insn = NEXT_INSN (insn))
440     if (INSN_P (insn))
441       {
442         /* If this is a CALL_PLACEHOLDER, then recursively call ourselves
443            with each nonempty sequence attached to the CALL_PLACEHOLDER.  */
444         if (GET_CODE (insn) == CALL_INSN
445             && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
446           {
447             if (XEXP (PATTERN (insn), 0) != NULL_RTX
448                 && sequence_uses_addressof (XEXP (PATTERN (insn), 0)))
449               return 1;
450             if (XEXP (PATTERN (insn), 1) != NULL_RTX
451                 && sequence_uses_addressof (XEXP (PATTERN (insn), 1)))
452               return 1;
453             if (XEXP (PATTERN (insn), 2) != NULL_RTX
454                 && sequence_uses_addressof (XEXP (PATTERN (insn), 2)))
455               return 1;
456           }
457         else if (uses_addressof (PATTERN (insn))
458                  || (REG_NOTES (insn) && uses_addressof (REG_NOTES (insn))))
459           return 1;
460       }
461   return 0;
462 }
463
464 /* Remove all REG_EQUIV notes found in the insn chain.  */
465
466 static void
467 purge_reg_equiv_notes (void)
468 {
469   rtx insn;
470
471   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
472     {
473       while (1)
474         {
475           rtx note = find_reg_note (insn, REG_EQUIV, 0);
476           if (note)
477             {
478               /* Remove the note and keep looking at the notes for
479                  this insn.  */
480               remove_note (insn, note);
481               continue;
482             }
483           break;
484         }
485     }
486 }
487
488 /* Clear RTX_UNCHANGING_P flag of incoming argument MEMs.  */
489
490 static void
491 purge_mem_unchanging_flag (rtx x)
492 {
493   RTX_CODE code;
494   int i, j;
495   const char *fmt;
496
497   if (x == NULL_RTX)
498     return;
499
500   code = GET_CODE (x);
501
502   if (code == MEM)
503     {
504       if (RTX_UNCHANGING_P (x)
505           && (XEXP (x, 0) == current_function_internal_arg_pointer
506               || (GET_CODE (XEXP (x, 0)) == PLUS
507                   && XEXP (XEXP (x, 0), 0) ==
508                      current_function_internal_arg_pointer
509                   && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)))
510         RTX_UNCHANGING_P (x) = 0;
511       return;
512     }
513
514   /* Scan all subexpressions.  */
515   fmt = GET_RTX_FORMAT (code);
516   for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
517     {
518       if (*fmt == 'e')
519         purge_mem_unchanging_flag (XEXP (x, i));
520       else if (*fmt == 'E')
521         for (j = 0; j < XVECLEN (x, i); j++)
522           purge_mem_unchanging_flag (XVECEXP (x, i, j));
523     }
524 }
525
526 /* Replace the CALL_PLACEHOLDER with one of its children.  INSN should be
527    the CALL_PLACEHOLDER insn; USE tells which child to use.  */
528
529 void
530 replace_call_placeholder (rtx insn, sibcall_use_t use)
531 {
532   if (use == sibcall_use_tail_recursion)
533     emit_insn_before (XEXP (PATTERN (insn), 2), insn);
534   else if (use == sibcall_use_sibcall)
535     emit_insn_before (XEXP (PATTERN (insn), 1), insn);
536   else if (use == sibcall_use_normal)
537     emit_insn_before (XEXP (PATTERN (insn), 0), insn);
538   else
539     abort ();
540
541   /* Turn off LABEL_PRESERVE_P for the tail recursion label if it
542      exists.  We only had to set it long enough to keep the jump
543      pass above from deleting it as unused.  */
544   if (XEXP (PATTERN (insn), 3))
545     LABEL_PRESERVE_P (XEXP (PATTERN (insn), 3)) = 0;
546
547   /* "Delete" the placeholder insn.  */
548   remove_insn (insn);
549 }
550
551 /* Given a (possibly empty) set of potential sibling or tail recursion call
552    sites, determine if optimization is possible.
553
554    Potential sibling or tail recursion calls are marked with CALL_PLACEHOLDER
555    insns.  The CALL_PLACEHOLDER insn holds chains of insns to implement a
556    normal call, sibling call or tail recursive call.
557
558    Replace the CALL_PLACEHOLDER with an appropriate insn chain.  */
559
560 void
561 optimize_sibling_and_tail_recursive_calls (void)
562 {
563   rtx insn, insns;
564   basic_block alternate_exit = EXIT_BLOCK_PTR;
565   bool no_sibcalls_this_function = false;
566   bool successful_replacement = false;
567   bool replaced_call_placeholder = false;
568   edge e;
569
570   insns = get_insns ();
571
572   cleanup_cfg (CLEANUP_PRE_SIBCALL | CLEANUP_PRE_LOOP);
573
574   /* If there are no basic blocks, then there is nothing to do.  */
575   if (n_basic_blocks == 0)
576     return;
577
578   /* If we are using sjlj exceptions, we may need to add a call to
579      _Unwind_SjLj_Unregister at exit of the function.  Which means
580      that we cannot do any sibcall transformations.  */
581   if (USING_SJLJ_EXCEPTIONS && current_function_has_exception_handlers ())
582     no_sibcalls_this_function = true;
583
584   return_value_pseudo = NULL_RTX;
585
586   /* Find the exit block.
587
588      It is possible that we have blocks which can reach the exit block
589      directly.  However, most of the time a block will jump (or fall into)
590      N_BASIC_BLOCKS - 1, which in turn falls into the exit block.  */
591   for (e = EXIT_BLOCK_PTR->pred;
592        e && alternate_exit == EXIT_BLOCK_PTR;
593        e = e->pred_next)
594     {
595       rtx insn;
596
597       if (e->dest != EXIT_BLOCK_PTR || e->succ_next != NULL)
598         continue;
599
600       /* Walk forwards through the last normal block and see if it
601          does nothing except fall into the exit block.  */
602       for (insn = BB_HEAD (EXIT_BLOCK_PTR->prev_bb);
603            insn;
604            insn = NEXT_INSN (insn))
605         {
606           rtx set;
607           /* This should only happen once, at the start of this block.  */
608           if (GET_CODE (insn) == CODE_LABEL)
609             continue;
610
611           if (GET_CODE (insn) == NOTE)
612             continue;
613
614           if (GET_CODE (insn) == INSN
615               && GET_CODE (PATTERN (insn)) == USE)
616             continue;
617
618           /* Exit block also may contain copy from pseudo containing
619              return value to hard register.  */
620           if (GET_CODE (insn) == INSN
621               && (set = single_set (insn))
622               && SET_DEST (set) == current_function_return_rtx
623               && REG_P (SET_SRC (set))
624               && !return_value_pseudo)
625             {
626               return_value_pseudo = SET_SRC (set);
627               continue;
628             }
629
630           break;
631         }
632
633       /* If INSN is zero, then the search walked all the way through the
634          block without hitting anything interesting.  This block is a
635          valid alternate exit block.  */
636       if (insn == NULL)
637         alternate_exit = e->src;
638       else
639         return_value_pseudo = NULL;
640     }
641
642   /* If the function uses ADDRESSOF, we can't (easily) determine
643      at this point if the value will end up on the stack.  */
644   no_sibcalls_this_function |= sequence_uses_addressof (insns);
645
646   /* Walk the insn chain and find any CALL_PLACEHOLDER insns.  We need to
647      select one of the insn sequences attached to each CALL_PLACEHOLDER.
648
649      The different sequences represent different ways to implement the call,
650      ie, tail recursion, sibling call or normal call.
651
652      Since we do not create nested CALL_PLACEHOLDERs, the scan
653      continues with the insn that was after a replaced CALL_PLACEHOLDER;
654      we don't rescan the replacement insns.  */
655   for (insn = insns; insn; insn = NEXT_INSN (insn))
656     {
657       if (GET_CODE (insn) == CALL_INSN
658           && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
659         {
660           int sibcall = (XEXP (PATTERN (insn), 1) != NULL_RTX);
661           int tailrecursion = (XEXP (PATTERN (insn), 2) != NULL_RTX);
662           basic_block call_block = BLOCK_FOR_INSN (insn);
663
664           /* alloca (until we have stack slot life analysis) inhibits
665              sibling call optimizations, but not tail recursion.
666              Similarly if we use varargs or stdarg since they implicitly
667              may take the address of an argument.  */
668           if (current_function_calls_alloca || current_function_stdarg)
669             sibcall = 0;
670
671           /* See if there are any reasons we can't perform either sibling or
672              tail call optimizations.  We must be careful with stack slots
673              which are live at potential optimization sites.  */
674           if (no_sibcalls_this_function
675               /* ??? Overly conservative.  */
676               || frame_offset
677               /* Any function that calls setjmp might have longjmp called from
678                  any called function.  ??? We really should represent this
679                  properly in the CFG so that this needn't be special cased.  */
680               || current_function_calls_setjmp
681               /* Can't if more than one successor or single successor is not
682                  exit block.  These two tests prevent tail call optimization
683                  in the presence of active exception handlers.  */
684               || call_block->succ == NULL
685               || call_block->succ->succ_next != NULL
686               || (call_block->succ->dest != EXIT_BLOCK_PTR
687                   && call_block->succ->dest != alternate_exit)
688               /* If this call doesn't end the block, there are operations at
689                  the end of the block which we must execute after returning.  */
690               || ! call_ends_block_p (insn, BB_END (call_block)))
691             sibcall = 0, tailrecursion = 0;
692
693           /* Select a set of insns to implement the call and emit them.
694              Tail recursion is the most efficient, so select it over
695              a tail/sibling call.  */
696
697           if (sibcall || tailrecursion)
698             successful_replacement = true;
699           replaced_call_placeholder = true;
700
701           replace_call_placeholder (insn,
702                                     tailrecursion != 0
703                                       ? sibcall_use_tail_recursion
704                                       : sibcall != 0
705                                          ? sibcall_use_sibcall
706                                          : sibcall_use_normal);
707         }
708     }
709
710   if (successful_replacement)
711     {
712       rtx insn;
713       tree arg;
714
715       /* A sibling call sequence invalidates any REG_EQUIV notes made for
716          this function's incoming arguments.
717
718          At the start of RTL generation we know the only REG_EQUIV notes
719          in the rtl chain are those for incoming arguments, so we can safely
720          flush any REG_EQUIV note.
721
722          This is (slight) overkill.  We could keep track of the highest
723          argument we clobber and be more selective in removing notes, but it
724          does not seem to be worth the effort.  */
725       purge_reg_equiv_notes ();
726
727       /* A sibling call sequence also may invalidate RTX_UNCHANGING_P
728          flag of some incoming arguments MEM RTLs, because it can write into
729          those slots.  We clear all those bits now.
730
731          This is (slight) overkill, we could keep track of which arguments
732          we actually write into.  */
733       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
734         {
735           if (INSN_P (insn))
736             purge_mem_unchanging_flag (PATTERN (insn));
737         }
738
739       /* Similarly, invalidate RTX_UNCHANGING_P for any incoming
740          arguments passed in registers.  */
741       for (arg = DECL_ARGUMENTS (current_function_decl);
742            arg;
743            arg = TREE_CHAIN (arg))
744         {
745           if (REG_P (DECL_RTL (arg)))
746             RTX_UNCHANGING_P (DECL_RTL (arg)) = false;
747         }
748     }
749
750   /* There may have been NOTE_INSN_BLOCK_{BEGIN,END} notes in the
751      CALL_PLACEHOLDER alternatives that we didn't emit.  Rebuild the
752      lexical block tree to correspond to the notes that still exist.  */
753   if (replaced_call_placeholder)
754     reorder_blocks ();
755
756   /* This information will be invalid after inline expansion.  Kill it now.  */
757   free_basic_block_vars (0);
758   free_EXPR_LIST_list (&tail_recursion_label_list);
759 }