OSDN Git Service

* ifcvt.c (cond_exec_process_insns): New argument prob_val.
[pf3gnuchains/gcc-fork.git] / gcc / ifcvt.c
1 /* If-conversion support.
2    Copyright (C) 2000 Free Software Foundation, Inc.
3
4    This file is part of GNU CC.
5
6    GNU CC is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    GNU CC is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with GNU CC; see the file COPYING.  If not, write to
18    the Free Software Foundation, 59 Temple Place - Suite 330,
19    Boston, MA 02111-1307, USA.  */
20
21 #include "config.h"
22 #include "system.h"
23
24 #include "rtl.h"
25 #include "regs.h"
26 #include "function.h"
27 #include "flags.h"
28 #include "insn-config.h"
29 #include "recog.h"
30 #include "basic-block.h"
31 #include "expr.h"
32 #include "output.h"
33 #include "hard-reg-set.h"
34 #include "tm_p.h"
35
36
37 #ifndef HAVE_conditional_execution
38 #define HAVE_conditional_execution 0
39 #endif
40 #ifndef HAVE_conditional_move
41 #define HAVE_conditional_move 0
42 #endif
43 #ifndef HAVE_incscc
44 #define HAVE_incscc 0
45 #endif
46 #ifndef HAVE_decscc
47 #define HAVE_decscc 0
48 #endif
49
50 #ifndef MAX_CONDITIONAL_EXECUTE
51 #define MAX_CONDITIONAL_EXECUTE   (BRANCH_COST + 1)
52 #endif
53
54 #define EDGE_COMPLEX    (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL | EDGE_EH)
55
56 #define NULL_EDGE       ((struct edge_def *)NULL)
57 #define NULL_BLOCK      ((struct basic_block_def *)NULL)
58
59 /* # of IF-THEN or IF-THEN-ELSE blocks we looked at  */
60 static int num_possible_if_blocks;
61
62 /* # of IF-THEN or IF-THEN-ELSE blocks were converted to conditional
63    execution.  */
64 static int num_updated_if_blocks;
65
66 /* # of basic blocks that were removed.  */
67 static int num_removed_blocks;
68
69 /* The post-dominator relation on the original block numbers.  */
70 static sbitmap *post_dominators;
71
72 /* Forward references.  */
73 static int count_bb_insns               PARAMS ((basic_block));
74 static rtx first_active_insn            PARAMS ((basic_block));
75 static int last_active_insn_p           PARAMS ((basic_block, rtx));
76
77 static int cond_exec_process_insns      PARAMS ((rtx, rtx, rtx, rtx, int));
78 static rtx cond_exec_get_condition      PARAMS ((rtx));
79 static int cond_exec_process_if_block   PARAMS ((basic_block, basic_block,
80                                                  basic_block, basic_block));
81
82 static rtx noce_get_condition           PARAMS ((rtx, rtx *));
83 static int noce_process_if_block        PARAMS ((basic_block, basic_block,
84                                                  basic_block, basic_block));
85
86 static int process_if_block             PARAMS ((basic_block, basic_block,
87                                                  basic_block, basic_block));
88 static void merge_if_block              PARAMS ((basic_block, basic_block,
89                                                  basic_block, basic_block));
90
91 static int find_if_header               PARAMS ((basic_block));
92 static int find_if_block                PARAMS ((basic_block, edge, edge));
93 static int find_if_case_1               PARAMS ((basic_block, edge, edge));
94 static int find_if_case_2               PARAMS ((basic_block, edge, edge));
95 static int find_memory                  PARAMS ((rtx *, void *));
96 static int dead_or_predicable           PARAMS ((basic_block, basic_block,
97                                                  basic_block, rtx, int));
98 \f
99 /* Abuse the basic_block AUX field to store the original block index,
100    as well as a flag indicating that the block should be rescaned for
101    life analysis.  */
102
103 #define SET_ORIG_INDEX(BB,I)    ((BB)->aux = (void *)((size_t)(I) << 1))
104 #define ORIG_INDEX(BB)          ((size_t)(BB)->aux >> 1)
105 #define SET_UPDATE_LIFE(BB)     ((BB)->aux = (void *)((size_t)(BB)->aux | 1))
106 #define UPDATE_LIFE(BB)         ((size_t)(BB)->aux & 1)
107
108 \f
109 /* Count the number of non-jump active insns in BB.  */
110
111 static int
112 count_bb_insns (bb)
113      basic_block bb;
114 {
115   int count = 0;
116   rtx insn = bb->head;
117
118   while (1)
119     {
120       if (GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == INSN)
121         count++;
122
123       if (insn == bb->end)
124         break;
125       insn = NEXT_INSN (insn);
126     }
127
128   return count;
129 }
130
131 /* Return the first non-jump active insn in the basic block.  */
132
133 static rtx
134 first_active_insn (bb)
135      basic_block bb;
136 {
137   rtx insn = bb->head;
138
139   if (GET_CODE (insn) == CODE_LABEL)
140     {
141       if (insn == bb->end)
142         return NULL_RTX;
143       insn = NEXT_INSN (insn);
144     }
145
146   while (GET_CODE (insn) == NOTE)
147     {
148       if (insn == bb->end)
149         return NULL_RTX;
150       insn = NEXT_INSN (insn);
151     }
152
153   if (GET_CODE (insn) == JUMP_INSN)
154     return NULL_RTX;
155
156   return insn;
157 }
158
159 /* Return true if INSN is the last active non-jump insn in BB.  */
160
161 static int
162 last_active_insn_p (bb, insn)
163      basic_block bb;
164      rtx insn;
165 {
166   do
167     {
168       if (insn == bb->end)
169         return TRUE;
170       insn = NEXT_INSN (insn);
171     }
172   while (GET_CODE (insn) == NOTE);
173
174   return GET_CODE (insn) == JUMP_INSN;
175 }
176 \f
177 /* Go through a bunch of insns, converting them to conditional
178    execution format if possible.  Return TRUE if all of the non-note
179    insns were processed.  */
180
181 static int
182 cond_exec_process_insns (start, end, test, prob_val, mod_ok)
183      rtx start;                 /* first insn to look at */
184      rtx end;                   /* last insn to look at */
185      rtx test;                  /* conditional execution test */
186      rtx prob_val;              /* probability of branch taken.  */
187      int mod_ok;                /* true if modifications ok last insn.  */
188 {
189   int must_be_last = FALSE;
190   rtx insn;
191
192   for (insn = start; ; insn = NEXT_INSN (insn))
193     {
194       if (GET_CODE (insn) == NOTE)
195         goto insn_done;
196
197       if (GET_CODE (insn) != INSN && GET_CODE (insn) != CALL_INSN)
198         abort ();
199
200       /* Last insn wasn't last?  */
201       if (must_be_last)
202         return FALSE;
203
204       if (modified_in_p (test, insn))
205         {
206           if (!mod_ok)
207             return FALSE;
208           must_be_last = TRUE;
209         }
210
211       /* Now build the conditional form of the instruction.  */
212       validate_change (insn, &PATTERN (insn),
213                        gen_rtx_COND_EXEC (VOIDmode, copy_rtx (test),
214                                           PATTERN (insn)), 1);
215
216       if (GET_CODE (insn) == CALL_INSN && prob_val)
217         validate_change (insn, &REG_NOTES (insn),
218                          alloc_EXPR_LIST (REG_BR_PROB, prob_val,
219                                           REG_NOTES (insn)), 1);
220
221     insn_done:
222       if (insn == end)
223         break;
224     }
225
226   return TRUE;
227 }
228
229 /* Return the condition for a jump.  Do not do any special processing.  */
230
231 static rtx
232 cond_exec_get_condition (jump)
233      rtx jump;
234 {
235   rtx test_if, cond;
236
237   if (condjump_p (jump))
238     test_if = SET_SRC (PATTERN (jump));
239   else if (condjump_in_parallel_p (jump))
240     test_if = SET_SRC (XVECEXP (PATTERN (jump), 0, 0));
241   else
242     return NULL_RTX;
243   cond = XEXP (test_if, 0);
244
245   /* If this branches to JUMP_LABEL when the condition is false,
246      reverse the condition.  */
247   if (GET_CODE (XEXP (test_if, 2)) == LABEL_REF
248       && XEXP (XEXP (test_if, 2), 0) == JUMP_LABEL (jump))
249     cond = gen_rtx_fmt_ee (reverse_condition (GET_CODE (cond)),
250                            GET_MODE (cond), XEXP (cond, 0),
251                            XEXP (cond, 1));
252
253   return cond;
254 }
255
256 /* Given a simple IF-THEN or IF-THEN-ELSE block, attempt to convert it
257    to conditional execution.  Return TRUE if we were successful at
258    converting the the block.  */
259
260 static int
261 cond_exec_process_if_block (test_bb, then_bb, else_bb, join_bb)
262      basic_block test_bb;       /* Basic block test is in */
263      basic_block then_bb;       /* Basic block for THEN block */
264      basic_block else_bb;       /* Basic block for ELSE block */
265      basic_block join_bb;       /* Basic block the join label is in */
266 {
267   rtx test_expr;                /* expression in IF_THEN_ELSE that is tested */
268   rtx then_start;               /* first insn in THEN block */
269   rtx then_end;                 /* last insn + 1 in THEN block */
270   rtx else_start;               /* first insn in ELSE block or NULL */
271   rtx else_end;                 /* last insn + 1 in ELSE block */
272   int max;                      /* max # of insns to convert. */
273   int then_mod_ok;              /* whether conditional mods are ok in THEN */
274   rtx true_expr;                /* test for else block insns */
275   rtx false_expr;               /* test for then block insns */
276   rtx true_prob_val;            /* probability of else block */
277   rtx false_prob_val;           /* probability of then block */
278   int n_insns;
279
280   /* Find the conditional jump to the ELSE or JOIN part, and isolate
281      the test.  */
282   test_expr = cond_exec_get_condition (test_bb->end);
283   if (! test_expr)
284     return FALSE;
285
286   /* Collect the bounds of where we're to search.  */
287
288   then_start = then_bb->head;
289   then_end = then_bb->end;
290
291   /* Skip a (use (const_int 0)) or branch as the final insn.  */
292   if (GET_CODE (then_end) == INSN
293       && GET_CODE (PATTERN (then_end)) == USE
294       && GET_CODE (XEXP (PATTERN (then_end), 0)) == CONST_INT)
295     then_end = PREV_INSN (then_end);
296   else if (GET_CODE (then_end) == JUMP_INSN)
297     then_end = PREV_INSN (then_end);
298
299   if (else_bb)
300     {
301       /* Skip the ELSE block's label.  */
302       else_start = NEXT_INSN (else_bb->head);
303       else_end = else_bb->end;
304
305       /* Skip a (use (const_int 0)) or branch as the final insn.  */
306       if (GET_CODE (else_end) == INSN
307           && GET_CODE (PATTERN (else_end)) == USE
308           && GET_CODE (XEXP (PATTERN (else_end), 0)) == CONST_INT)
309         else_end = PREV_INSN (else_end);
310       else if (GET_CODE (else_end) == JUMP_INSN)
311         else_end = PREV_INSN (else_end);
312     }
313
314   /* How many instructions should we convert in total?  */
315   n_insns = 0;
316   if (else_bb)
317     {
318       max = 2 * MAX_CONDITIONAL_EXECUTE;
319       n_insns = count_bb_insns (else_bb);
320     }
321   else
322     max = MAX_CONDITIONAL_EXECUTE;
323   n_insns += count_bb_insns (then_bb);
324   if (n_insns > max)
325     return FALSE;
326
327   /* Map test_expr/test_jump into the appropriate MD tests to use on
328      the conditionally executed code.  */
329   
330   true_expr = test_expr;
331   false_expr = gen_rtx_fmt_ee (reverse_condition (GET_CODE (true_expr)),
332                                GET_MODE (true_expr), XEXP (true_expr, 0),
333                                XEXP (true_expr, 1));
334
335   true_prob_val = find_reg_note (test_bb->end, REG_BR_PROB, NULL_RTX);
336   if (true_prob_val)
337     {
338       true_prob_val = XEXP (true_prob_val, 0);
339       false_prob_val = GEN_INT (REG_BR_PROB_BASE - INTVAL (true_prob_val));
340     }
341   else
342     false_prob_val = NULL_RTX;
343
344   /* For IF-THEN-ELSE blocks, we don't allow modifications of the test
345      on then THEN block.  */
346   then_mod_ok = (else_bb == NULL_BLOCK);
347
348   /* Go through the THEN and ELSE blocks converting the insns if possible
349      to conditional execution.  */
350
351   if (then_end
352       && ! cond_exec_process_insns (then_start, then_end,
353                                     false_expr, false_prob_val, then_mod_ok))
354     goto fail;
355
356   if (else_bb
357       && ! cond_exec_process_insns (else_start, else_end,
358                                     true_expr, true_prob_val, TRUE))
359     goto fail;
360
361   if (! apply_change_group ())
362     return FALSE;
363
364   /* Conversion succeeded.  */
365   if (rtl_dump_file)
366     fprintf (rtl_dump_file, "%d insn%s converted to conditional execution.\n",
367              n_insns, (n_insns == 1) ? " was" : "s were");
368
369   /* Merge the blocks!  */
370   merge_if_block (test_bb, then_bb, else_bb, join_bb);
371   return TRUE;
372
373  fail:
374   cancel_changes (0);
375   return FALSE;
376 }
377 \f
378 /* Used by noce_process_if_block to communicate with its subroutines. 
379
380    The subroutines know that A and B may be evaluated freely.  They
381    know that X is a register.  They should insert new instructions 
382    before cond_earliest.  */
383
384 struct noce_if_info
385 {
386   rtx insn_a, insn_b;
387   rtx x, a, b;
388   rtx jump, cond, cond_earliest;
389 };
390
391 static rtx noce_emit_store_flag         PARAMS ((struct noce_if_info *,
392                                                  rtx, int, int));
393 static int noce_try_store_flag          PARAMS ((struct noce_if_info *));
394 static int noce_try_store_flag_inc      PARAMS ((struct noce_if_info *));
395 static int noce_try_store_flag_constants PARAMS ((struct noce_if_info *));
396 static int noce_try_store_flag_mask     PARAMS ((struct noce_if_info *));
397 static rtx noce_emit_cmove              PARAMS ((struct noce_if_info *,
398                                                  rtx, enum rtx_code, rtx,
399                                                  rtx, rtx, rtx));
400 static int noce_try_cmove               PARAMS ((struct noce_if_info *));
401 static int noce_try_cmove_arith         PARAMS ((struct noce_if_info *));
402
403 /* Helper function for noce_try_store_flag*.  */
404
405 static rtx
406 noce_emit_store_flag (if_info, x, reversep, normalize)
407      struct noce_if_info *if_info;
408      rtx x;
409      int reversep, normalize;
410 {
411   rtx cond = if_info->cond;
412   int cond_complex;
413   enum rtx_code code;
414
415   cond_complex = (! general_operand (XEXP (cond, 0), VOIDmode)
416                   || ! general_operand (XEXP (cond, 1), VOIDmode));
417
418   /* If earliest == jump, or when the condition is complex, try to
419      build the store_flag insn directly.  */
420
421   if (cond_complex)
422     cond = XEXP (SET_SRC (PATTERN (if_info->jump)), 0);
423
424   if ((if_info->cond_earliest == if_info->jump || cond_complex)
425       && (normalize == 0 || STORE_FLAG_VALUE == normalize))
426     {
427       rtx tmp;
428
429       code = GET_CODE (cond);
430       if (reversep)
431         code = reverse_condition (code);
432
433       tmp = gen_rtx_fmt_ee (code, GET_MODE (x), XEXP (cond, 0),
434                             XEXP (cond, 1));
435       tmp = gen_rtx_SET (VOIDmode, x, tmp);
436
437       start_sequence ();
438       tmp = emit_insn (tmp);
439
440       if (recog_memoized (tmp) >= 0)
441         {
442           tmp = get_insns ();
443           end_sequence ();
444           emit_insns (tmp);
445
446           if_info->cond_earliest = if_info->jump;
447
448           return x;
449         }
450
451       end_sequence ();
452     }
453
454   /* Don't even try if the comparison operands are weird.  */
455   if (cond_complex)
456     return NULL_RTX;
457
458   code = GET_CODE (cond);
459   if (reversep)
460     code = reverse_condition (code);
461
462   return emit_store_flag (x, code, XEXP (cond, 0),
463                           XEXP (cond, 1), VOIDmode,
464                           (code == LTU || code == LEU
465                            || code == GEU || code == GTU), normalize);
466 }
467
468 /* Convert "if (test) x = 1; else x = 0".
469
470    Only try 0 and STORE_FLAG_VALUE here.  Other combinations will be
471    tried in noce_try_store_flag_constants after noce_try_cmove has had
472    a go at the conversion.  */
473
474 static int
475 noce_try_store_flag (if_info)
476      struct noce_if_info *if_info;
477 {
478   int reversep;
479   rtx target, seq;
480
481   if (GET_CODE (if_info->b) == CONST_INT
482       && INTVAL (if_info->b) == STORE_FLAG_VALUE
483       && if_info->a == const0_rtx)
484     reversep = 0;
485   else if (if_info->b == const0_rtx
486            && GET_CODE (if_info->a) == CONST_INT
487            && INTVAL (if_info->a) == STORE_FLAG_VALUE
488            && can_reverse_comparison_p (if_info->cond, if_info->jump))
489     reversep = 1;
490   else
491     return FALSE;
492
493   start_sequence ();
494
495   target = noce_emit_store_flag (if_info, if_info->x, reversep, 0);
496   if (target)
497     {
498       if (target != if_info->x)
499         emit_move_insn (if_info->x, target);
500
501       seq = get_insns ();
502       end_sequence ();
503       emit_insns_before (seq, if_info->cond_earliest);
504
505       return TRUE;
506     }
507   else
508     {
509       end_sequence ();
510       return FALSE;
511     }
512 }
513
514 /* Convert "if (test) x = a; else x = b", for A and B constant.  */
515
516 static int
517 noce_try_store_flag_constants (if_info)
518      struct noce_if_info *if_info;
519 {
520   rtx target, seq;
521   int reversep;
522   HOST_WIDE_INT itrue, ifalse, diff, tmp;
523   int normalize, can_reverse;
524
525   if (! no_new_pseudos
526       && GET_CODE (if_info->a) == CONST_INT
527       && GET_CODE (if_info->b) == CONST_INT)
528     {
529       ifalse = INTVAL (if_info->a);
530       itrue = INTVAL (if_info->b);
531       diff = itrue - ifalse;
532
533       can_reverse = can_reverse_comparison_p (if_info->cond, if_info->jump);
534
535       reversep = 0;
536       if (diff == STORE_FLAG_VALUE || diff == -STORE_FLAG_VALUE)
537         normalize = 0;
538       else if (ifalse == 0 && exact_log2 (itrue) >= 0
539                && (STORE_FLAG_VALUE == 1
540                    || BRANCH_COST >= 2))
541         normalize = 1;
542       else if (itrue == 0 && exact_log2 (ifalse) >= 0 && can_reverse
543                && (STORE_FLAG_VALUE == 1 || BRANCH_COST >= 2))
544         normalize = 1, reversep = 1;
545       else if (itrue == -1
546                && (STORE_FLAG_VALUE == -1
547                    || BRANCH_COST >= 2))
548         normalize = -1;
549       else if (ifalse == -1 && can_reverse
550                && (STORE_FLAG_VALUE == -1 || BRANCH_COST >= 2))
551         normalize = -1, reversep = 1;
552       else if ((BRANCH_COST >= 2 && STORE_FLAG_VALUE == -1)
553                || BRANCH_COST >= 3)
554         normalize = -1;
555       else
556         return FALSE;
557
558       if (reversep)
559         {
560           tmp = itrue; itrue = ifalse; ifalse = tmp;
561           diff = -diff;
562         }
563
564       start_sequence ();
565       target = noce_emit_store_flag (if_info, if_info->x, reversep, normalize);
566       if (! target)
567         {
568           end_sequence ();
569           return FALSE;
570         }
571
572       /* if (test) x = 3; else x = 4;
573          =>   x = 3 + (test == 0);  */
574       if (diff == STORE_FLAG_VALUE || diff == -STORE_FLAG_VALUE)
575         {
576           target = expand_binop (GET_MODE (if_info->x),
577                                  (diff == STORE_FLAG_VALUE
578                                   ? add_optab : sub_optab),
579                                  GEN_INT (ifalse), target, if_info->x, 0,
580                                  OPTAB_WIDEN);
581         }
582
583       /* if (test) x = 8; else x = 0;
584          =>   x = (test != 0) << 3;  */
585       else if (ifalse == 0 && (tmp = exact_log2 (itrue)) >= 0)
586         {
587           target = expand_binop (GET_MODE (if_info->x), ashl_optab,
588                                  target, GEN_INT (tmp), if_info->x, 0,
589                                  OPTAB_WIDEN);
590         }
591
592       /* if (test) x = -1; else x = b;
593          =>   x = -(test != 0) | b;  */
594       else if (itrue == -1)
595         {
596           target = expand_binop (GET_MODE (if_info->x), ior_optab,
597                                  target, GEN_INT (ifalse), if_info->x, 0,
598                                  OPTAB_WIDEN);
599         }
600
601       /* if (test) x = a; else x = b;
602          =>   x = (-(test != 0) & (b - a)) + a;  */
603       else
604         {
605           target = expand_binop (GET_MODE (if_info->x), and_optab,
606                                  target, GEN_INT (diff), if_info->x, 0,
607                                  OPTAB_WIDEN);
608           if (target)
609             target = expand_binop (GET_MODE (if_info->x), add_optab,
610                                    target, GEN_INT (ifalse), if_info->x, 0,
611                                    OPTAB_WIDEN);
612         }
613
614       if (! target)
615         {
616           end_sequence ();
617           return FALSE;
618         }
619
620       if (target != if_info->x)
621         emit_move_insn (if_info->x, target);
622
623       seq = get_insns ();
624       end_sequence ();
625       emit_insns_before (seq, if_info->cond_earliest);
626
627       return TRUE;
628     }
629
630   return FALSE;
631 }
632
633 /* Convert "if (test) foo++" into "foo += (test != 0)", and 
634    similarly for "foo--".  */
635
636 static int
637 noce_try_store_flag_inc (if_info)
638      struct noce_if_info *if_info;
639 {
640   rtx target, seq;
641   int subtract, normalize;
642
643   if (! no_new_pseudos
644       && (BRANCH_COST >= 2
645           || HAVE_incscc
646           || HAVE_decscc)
647       /* Should be no `else' case to worry about.  */
648       && if_info->b == if_info->x
649       && GET_CODE (if_info->a) == PLUS
650       && (XEXP (if_info->a, 1) == const1_rtx
651           || XEXP (if_info->a, 1) == constm1_rtx)
652       && rtx_equal_p (XEXP (if_info->a, 0), if_info->x)
653       && can_reverse_comparison_p (if_info->cond, if_info->jump))
654     {
655       if (STORE_FLAG_VALUE == INTVAL (XEXP (if_info->a, 1)))
656         subtract = 0, normalize = 0;
657       else if (-STORE_FLAG_VALUE == INTVAL (XEXP (if_info->a, 1)))
658         subtract = 1, normalize = 0;
659       else
660         subtract = 0, normalize = INTVAL (XEXP (if_info->a, 1));
661       
662       start_sequence ();
663
664       target = noce_emit_store_flag (if_info,
665                                      gen_reg_rtx (GET_MODE (if_info->x)),
666                                      1, normalize);
667
668       if (target)
669         target = expand_binop (GET_MODE (if_info->x),
670                                subtract ? sub_optab : add_optab,
671                                if_info->x, target, if_info->x, 0, OPTAB_WIDEN);
672       if (target)
673         {
674           if (target != if_info->x)
675             emit_move_insn (if_info->x, target);
676
677           seq = get_insns ();
678           end_sequence ();
679           emit_insns_before (seq, if_info->cond_earliest);
680
681           return TRUE;
682         }
683
684       end_sequence ();
685     }
686
687   return FALSE;
688 }
689
690 /* Convert "if (test) x = 0;" to "x &= -(test == 0);"  */
691
692 static int
693 noce_try_store_flag_mask (if_info)
694      struct noce_if_info *if_info;
695 {
696   rtx target, seq;
697   int reversep;
698
699   reversep = 0;
700   if (! no_new_pseudos
701       && (BRANCH_COST >= 2
702           || STORE_FLAG_VALUE == -1)
703       && ((if_info->a == const0_rtx
704            && rtx_equal_p (if_info->b, if_info->x))
705           || ((reversep = can_reverse_comparison_p (if_info->cond,
706                                                     if_info->jump))
707               && if_info->b == const0_rtx
708               && rtx_equal_p (if_info->a, if_info->x))))
709     {
710       start_sequence ();
711       target = noce_emit_store_flag (if_info,
712                                      gen_reg_rtx (GET_MODE (if_info->x)),
713                                      reversep, -1);
714       if (target)
715         target = expand_binop (GET_MODE (if_info->x), and_optab,
716                                if_info->x, target, if_info->x, 0,
717                                OPTAB_WIDEN);
718
719       if (target)
720         {
721           if (target != if_info->x)
722             emit_move_insn (if_info->x, target);
723
724           seq = get_insns ();
725           end_sequence ();
726           emit_insns_before (seq, if_info->cond_earliest);
727
728           return TRUE;
729         }
730
731       end_sequence ();
732     }
733
734   return FALSE;
735 }
736
737 /* Helper function for noce_try_cmove and noce_try_cmove_arith.  */
738
739 static rtx
740 noce_emit_cmove (if_info, x, code, cmp_a, cmp_b, vfalse, vtrue)
741      struct noce_if_info *if_info;
742      rtx x, cmp_a, cmp_b, vfalse, vtrue;
743      enum rtx_code code;
744 {
745   /* If earliest == jump, try to build the cmove insn directly.
746      This is helpful when combine has created some complex condition
747      (like for alpha's cmovlbs) that we can't hope to regenerate
748      through the normal interface.  */
749
750   if (if_info->cond_earliest == if_info->jump)
751     {
752       rtx tmp;
753
754       tmp = gen_rtx_fmt_ee (code, GET_MODE (if_info->cond), cmp_a, cmp_b);
755       tmp = gen_rtx_IF_THEN_ELSE (GET_MODE (x), tmp, vtrue, vfalse);
756       tmp = gen_rtx_SET (VOIDmode, x, tmp);
757
758       start_sequence ();
759       tmp = emit_insn (tmp);
760
761       if (recog_memoized (tmp) >= 0)
762         {
763           tmp = get_insns ();
764           end_sequence ();
765           emit_insns (tmp);
766
767           return x;
768         }
769
770       end_sequence ();
771     }
772
773   /* Don't even try if the comparison operands are weird.  */
774   if (! general_operand (cmp_a, GET_MODE (cmp_a))
775       || ! general_operand (cmp_b, GET_MODE (cmp_b)))
776     return NULL_RTX;
777
778 #if HAVE_conditional_move
779   return emit_conditional_move (x, code, cmp_a, cmp_b, VOIDmode,
780                                 vtrue, vfalse, GET_MODE (x),
781                                 (code == LTU || code == GEU
782                                  || code == LEU || code == GTU));
783 #else
784   /* We'll never get here, as noce_process_if_block doesn't call the
785      functions involved.  Ifdef code, however, should be discouraged
786      because it leads to typos in the code not selected.  However, 
787      emit_conditional_move won't exist either.  */
788   return NULL_RTX;
789 #endif
790 }
791
792 /* Try only simple constants and registers here.  More complex cases
793    are handled in noce_try_cmove_arith after noce_try_store_flag_arith
794    has had a go at it.  */
795
796 static int
797 noce_try_cmove (if_info)
798      struct noce_if_info *if_info;
799 {
800   enum rtx_code code;
801   rtx target, seq;
802
803   if ((CONSTANT_P (if_info->a) || register_operand (if_info->a, VOIDmode))
804       && (CONSTANT_P (if_info->b) || register_operand (if_info->b, VOIDmode)))
805     {
806       start_sequence ();
807
808       code = GET_CODE (if_info->cond);
809       target = noce_emit_cmove (if_info, if_info->x, code,
810                                 XEXP (if_info->cond, 0),
811                                 XEXP (if_info->cond, 1),
812                                 if_info->a, if_info->b);
813
814       if (target)
815         {
816           if (target != if_info->x)
817             emit_move_insn (if_info->x, target);
818
819           seq = get_insns ();
820           end_sequence ();
821           emit_insns_before (seq, if_info->cond_earliest);
822           return TRUE;
823         }
824       else
825         {
826           end_sequence ();
827           return FALSE;
828         }
829     }
830
831   return FALSE;
832 }
833
834 /* Try more complex cases involving conditional_move.  */
835
836 static int
837 noce_try_cmove_arith (if_info)
838      struct noce_if_info *if_info;
839 {
840   rtx a = if_info->a;
841   rtx b = if_info->b;
842   rtx x = if_info->x;
843   rtx insn_a, insn_b;
844   rtx tmp, target;
845   int is_mem = 0;
846   enum rtx_code code;
847
848   /* A conditional move from two memory sources is equivalent to a
849      conditional on their addresses followed by a load.  Don't do this
850      early because it'll screw alias analysis.  Note that we've
851      already checked for no side effects.  */
852   if (! no_new_pseudos && cse_not_expected
853       && GET_CODE (a) == MEM && GET_CODE (b) == MEM
854       && BRANCH_COST >= 5)
855     {
856       a = XEXP (a, 0);
857       b = XEXP (b, 0);
858       x = gen_reg_rtx (Pmode);
859       is_mem = 1;
860     }
861
862   /* ??? We could handle this if we knew that a load from A or B could
863      not fault.  This is also true if we've already loaded
864      from the address along the path from ENTRY.  */
865   else if (may_trap_p (a) || may_trap_p (b))
866     return FALSE;
867
868   /* if (test) x = a + b; else x = c - d;
869      => y = a + b;
870         x = c - d;
871         if (test)
872           x = y;
873   */
874   
875   code = GET_CODE (if_info->cond);
876   insn_a = if_info->insn_a;
877   insn_b = if_info->insn_b;
878
879   /* Possibly rearrange operands to make things come out more natural.  */
880   if (can_reverse_comparison_p (if_info->cond, if_info->jump))
881     {
882       int reversep = 0;
883       if (rtx_equal_p (b, x))
884         reversep = 1;
885       else if (general_operand (b, GET_MODE (b)))
886         reversep = 1;
887
888       if (reversep)
889         {
890           code = reverse_condition (code);
891           tmp = a, a = b, b = tmp;
892           tmp = insn_a, insn_a = insn_b, insn_b = tmp;
893         }
894     }
895
896   start_sequence ();
897
898   /* If either operand is complex, load it into a register first.
899      The best way to do this is to copy the original insn.  In this
900      way we preserve any clobbers etc that the insn may have had.  
901      This is of course not possible in the IS_MEM case.  */
902   if (! general_operand (a, GET_MODE (a)))
903     {
904       rtx set;
905
906       if (no_new_pseudos)
907         goto end_seq_and_fail;
908
909       if (is_mem)
910         {
911           tmp = gen_reg_rtx (GET_MODE (a));
912           tmp = emit_insn (gen_rtx_SET (VOIDmode, tmp, a));
913         }
914       else if (! insn_a)
915         goto end_seq_and_fail;
916       else
917         {
918           a = gen_reg_rtx (GET_MODE (a));
919           tmp = copy_rtx (insn_a);
920           set = single_set (tmp);
921           SET_DEST (set) = a;
922           tmp = emit_insn (PATTERN (tmp));
923         }
924       if (recog_memoized (tmp) < 0)
925         goto end_seq_and_fail;
926     }
927   if (! general_operand (b, GET_MODE (b)))
928     {
929       rtx set;
930
931       if (no_new_pseudos)
932         goto end_seq_and_fail;
933
934       if (is_mem)
935         {
936           tmp = gen_reg_rtx (GET_MODE (b));
937           tmp = emit_insn (gen_rtx_SET (VOIDmode, tmp, b));
938         }
939       else if (! insn_b)
940         goto end_seq_and_fail;
941       else
942         {
943           b = gen_reg_rtx (GET_MODE (b));
944           tmp = copy_rtx (insn_b);
945           set = single_set (tmp);
946           SET_DEST (set) = b;
947           tmp = emit_insn (PATTERN (tmp));
948         }
949       if (recog_memoized (tmp) < 0)
950         goto end_seq_and_fail;
951     }
952
953   target = noce_emit_cmove (if_info, x, code, XEXP (if_info->cond, 0),
954                             XEXP (if_info->cond, 1), a, b);
955
956   if (! target)
957     goto end_seq_and_fail;
958
959   /* If we're handling a memory for above, emit the load now.  */
960   if (is_mem)
961     {
962       tmp = gen_rtx_MEM (GET_MODE (if_info->x), target);
963
964       /* Copy over flags as appropriate.  */
965       if (MEM_VOLATILE_P (if_info->a) || MEM_VOLATILE_P (if_info->b))
966         MEM_VOLATILE_P (tmp) = 1;
967       if (MEM_IN_STRUCT_P (if_info->a) && MEM_IN_STRUCT_P (if_info->b))
968         MEM_IN_STRUCT_P (tmp) = 1;
969       if (MEM_SCALAR_P (if_info->a) && MEM_SCALAR_P (if_info->b))
970         MEM_SCALAR_P (tmp) = 1;
971       if (MEM_ALIAS_SET (if_info->a) == MEM_ALIAS_SET (if_info->b))
972         MEM_ALIAS_SET (tmp) = MEM_ALIAS_SET (if_info->a);
973
974       emit_move_insn (if_info->x, tmp);
975     }
976   else if (target != x)
977     emit_move_insn (x, target);
978
979   tmp = get_insns ();
980   end_sequence ();
981   emit_insns_before (tmp, if_info->cond_earliest);
982   return TRUE;
983
984  end_seq_and_fail:
985   end_sequence ();
986   return FALSE;
987 }
988
989 /* Look for the condition for the jump first.  We'd prefer to avoid
990    get_condition if we can -- it tries to look back for the contents
991    of an original compare.  On targets that use normal integers for
992    comparisons, e.g. alpha, this is wasteful.  */
993
994 static rtx
995 noce_get_condition (jump, earliest)
996      rtx jump;
997      rtx *earliest;
998 {
999   rtx cond;
1000
1001   /* If the condition variable is a register and is MODE_INT, accept it.
1002      Otherwise, fall back on get_condition.  */
1003
1004   if (! condjump_p (jump))
1005     return NULL_RTX;
1006
1007   cond = XEXP (SET_SRC (PATTERN (jump)), 0);
1008   if (GET_CODE (XEXP (cond, 0)) == REG
1009       && GET_MODE_CLASS (GET_MODE (XEXP (cond, 0))) == MODE_INT)
1010     {
1011       *earliest = jump;
1012
1013       /* If this branches to JUMP_LABEL when the condition is false,
1014          reverse the condition.  */
1015       if (GET_CODE (XEXP (SET_SRC (PATTERN (jump)), 2)) == LABEL_REF
1016           && XEXP (XEXP (SET_SRC (PATTERN (jump)), 2), 0) == JUMP_LABEL (jump))
1017         cond = gen_rtx_fmt_ee (reverse_condition (GET_CODE (cond)),
1018                                GET_MODE (cond), XEXP (cond, 0),
1019                                XEXP (cond, 1));
1020     }
1021   else
1022     cond = get_condition (jump, earliest);
1023
1024   return cond;
1025 }
1026
1027 /* Given a simple IF-THEN or IF-THEN-ELSE block, attempt to convert it
1028    without using conditional execution.  Return TRUE if we were
1029    successful at converting the the block.  */
1030
1031 static int
1032 noce_process_if_block (test_bb, then_bb, else_bb, join_bb)
1033      basic_block test_bb;       /* Basic block test is in */
1034      basic_block then_bb;       /* Basic block for THEN block */
1035      basic_block else_bb;       /* Basic block for ELSE block */
1036      basic_block join_bb;       /* Basic block the join label is in */
1037 {
1038   /* We're looking for patterns of the form
1039
1040      (1) if (...) x = a; else x = b;
1041      (2) x = b; if (...) x = a;
1042      (3) if (...) x = a;   // as if with an initial x = x.
1043
1044      The later patterns require jumps to be more expensive.
1045
1046      ??? For future expansion, look for multiple X in such patterns.  */
1047
1048   struct noce_if_info if_info;
1049   rtx insn_a, insn_b;
1050   rtx set_a, set_b;
1051   rtx orig_x, x, a, b;
1052   rtx jump, cond, insn;
1053
1054   /* If this is not a standard conditional jump, we can't parse it.  */
1055   jump = test_bb->end;
1056   cond = noce_get_condition (jump, &if_info.cond_earliest);
1057   if (! cond)
1058     return FALSE;
1059
1060   /* We must be comparing objects whose modes imply the size.  */
1061   if (GET_MODE (XEXP (cond, 0)) == BLKmode)
1062     return FALSE;
1063
1064   /* Look for one of the potential sets.  */
1065   insn_a = first_active_insn (then_bb);
1066   if (! insn_a
1067       || ! last_active_insn_p (then_bb, insn_a)
1068       || (set_a = single_set (insn_a)) == NULL_RTX)
1069     return FALSE;
1070
1071   x = SET_DEST (set_a);
1072   a = SET_SRC (set_a);
1073
1074   /* Look for the other potential set.  Make sure we've got equivalent
1075      destinations.  */
1076   /* ??? This is overconservative.  Storing to two different mems is
1077      as easy as conditionally computing the address.  Storing to a
1078      single mem merely requires a scratch memory to use as one of the
1079      destination addresses; often the memory immediately below the
1080      stack pointer is available for this.  */
1081   set_b = NULL_RTX;
1082   if (else_bb)
1083     {
1084       insn_b = first_active_insn (else_bb);
1085       if (! insn_b
1086           || ! last_active_insn_p (else_bb, insn_b)
1087           || (set_b = single_set (insn_b)) == NULL_RTX
1088           || ! rtx_equal_p (x, SET_DEST (set_b)))
1089         return FALSE;
1090     }
1091   else
1092     {
1093       insn_b = prev_nonnote_insn (if_info.cond_earliest);
1094       if (! insn_b
1095           || GET_CODE (insn_b) != INSN
1096           || (set_b = single_set (insn_b)) == NULL_RTX
1097           || ! rtx_equal_p (x, SET_DEST (set_b))
1098           || reg_mentioned_p (x, cond)
1099           || reg_mentioned_p (x, a)
1100           || reg_mentioned_p (x, SET_SRC (set_b)))
1101         insn_b = set_b = NULL_RTX;
1102     }
1103   b = (set_b ? SET_SRC (set_b) : x);
1104
1105   /* X may not be mentioned in the range (cond_earliest, jump].  */
1106   for (insn = jump; insn != if_info.cond_earliest; insn = PREV_INSN (insn))
1107     if (INSN_P (insn) && reg_mentioned_p (x, insn))
1108       return FALSE;
1109
1110   /* A and B may not be modified in the range [cond_earliest, jump).  */
1111   for (insn = if_info.cond_earliest; insn != jump; insn = NEXT_INSN (insn))
1112     if (INSN_P (insn)
1113         && (modified_in_p (a, insn) || modified_in_p (b, insn)))
1114       return FALSE;
1115
1116   /* Only operate on register destinations, and even then avoid extending
1117      the lifetime of hard registers on small register class machines.  */
1118   orig_x = x;
1119   if (GET_CODE (x) != REG
1120       || (SMALL_REGISTER_CLASSES
1121           && REGNO (x) < FIRST_PSEUDO_REGISTER))
1122     {
1123       if (no_new_pseudos)
1124         return FALSE;
1125       x = gen_reg_rtx (GET_MODE (x));
1126     }
1127
1128   /* Don't operate on sources that may trap or are volatile.  */
1129   if (side_effects_p (a) || side_effects_p (b)
1130       || (GET_CODE (a) != MEM && may_trap_p (a))
1131       || (GET_CODE (b) != MEM && may_trap_p (b)))
1132     return FALSE;
1133
1134   /* Set up the info block for our subroutines.  */
1135   if_info.cond = cond;
1136   if_info.jump = jump;
1137   if_info.insn_a = insn_a;
1138   if_info.insn_b = insn_b;
1139   if_info.x = x;
1140   if_info.a = a;
1141   if_info.b = b;
1142
1143   /* Try optimizations in some approximation of a useful order.  */
1144   /* ??? Should first look to see if X is live incoming at all.  If it
1145      isn't, we don't need anything but an unconditional set.  */
1146
1147   /* Look and see if A and B are really the same.  Avoid creating silly
1148      cmove constructs that no one will fix up later.  */
1149   if (rtx_equal_p (a, b))
1150     {
1151       /* If we have an INSN_B, we don't have to create any new rtl.  Just
1152          move the instruction that we already have.  If we don't have an
1153          INSN_B, that means that A == X, and we've got a noop move.  In
1154          that case don't do anything and let the code below delete INSN_A.  */
1155       if (insn_b && else_bb)
1156         {
1157           if (else_bb && insn_b == else_bb->end)
1158             else_bb->end = PREV_INSN (insn_b);
1159           reorder_insns (insn_b, insn_b, PREV_INSN (if_info.cond_earliest));
1160           insn_b = NULL_RTX;
1161         }
1162       x = orig_x;
1163       goto success;
1164     }
1165
1166   if (noce_try_store_flag (&if_info))
1167     goto success;
1168   if (HAVE_conditional_move
1169       && noce_try_cmove (&if_info))
1170     goto success;
1171   if (! HAVE_conditional_execution)
1172     {
1173       if (noce_try_store_flag_constants (&if_info))
1174         goto success;
1175       if (noce_try_store_flag_inc (&if_info))
1176         goto success;
1177       if (noce_try_store_flag_mask (&if_info))
1178         goto success;
1179       if (HAVE_conditional_move
1180           && noce_try_cmove_arith (&if_info))
1181         goto success;
1182     }
1183
1184   return FALSE;
1185
1186  success:
1187   /* The original sets may now be killed.  */
1188   if (insn_a == then_bb->end)
1189     then_bb->end = PREV_INSN (insn_a);
1190   flow_delete_insn (insn_a);
1191
1192   /* Several special cases here: First, we may have reused insn_b above,
1193      in which case insn_b is now NULL.  Second, we want to delete insn_b
1194      if it came from the ELSE block, because follows the now correct
1195      write that appears in the TEST block.  However, if we got insn_b from
1196      the TEST block, it may in fact be loading data needed for the comparison.
1197      We'll let life_analysis remove the insn if it's really dead.  */
1198   if (insn_b && else_bb)
1199     {
1200       if (insn_b == else_bb->end)
1201         else_bb->end = PREV_INSN (insn_b);
1202       flow_delete_insn (insn_b);
1203     }
1204
1205   /* The new insns will have been inserted before cond_earliest.  We should
1206      be able to remove the jump with impunity, but the condition itself may
1207      have been modified by gcse to be shared across basic blocks.  */
1208   test_bb->end = PREV_INSN (jump);
1209   flow_delete_insn (jump);
1210
1211   /* If we used a temporary, fix it up now.  */
1212   if (orig_x != x)
1213     {
1214       start_sequence ();
1215       emit_move_insn (orig_x, x);
1216       insn_b = gen_sequence ();
1217       end_sequence ();
1218
1219       test_bb->end = emit_insn_after (insn_b, test_bb->end);
1220     }
1221
1222   /* Merge the blocks!  */
1223   merge_if_block (test_bb, then_bb, else_bb, join_bb);
1224
1225   return TRUE;
1226 }
1227 \f
1228 /* Attempt to convert an IF-THEN or IF-THEN-ELSE block into
1229    straight line code.  Return true if successful.  */
1230
1231 static int
1232 process_if_block (test_bb, then_bb, else_bb, join_bb)
1233      basic_block test_bb;       /* Basic block test is in */
1234      basic_block then_bb;       /* Basic block for THEN block */
1235      basic_block else_bb;       /* Basic block for ELSE block */
1236      basic_block join_bb;       /* Basic block the join label is in */
1237 {
1238   if (! reload_completed
1239       && noce_process_if_block (test_bb, then_bb, else_bb, join_bb))
1240     return TRUE;
1241
1242   if (HAVE_conditional_execution
1243       && reload_completed
1244       && cond_exec_process_if_block (test_bb, then_bb, else_bb, join_bb))
1245     return TRUE;
1246
1247   return FALSE;
1248 }
1249
1250 /* Merge the blocks and mark for local life update.  */
1251
1252 static void
1253 merge_if_block (test_bb, then_bb, else_bb, join_bb)
1254      basic_block test_bb;       /* Basic block test is in */
1255      basic_block then_bb;       /* Basic block for THEN block */
1256      basic_block else_bb;       /* Basic block for ELSE block */
1257      basic_block join_bb;       /* Basic block the join label is in */
1258 {
1259   basic_block combo_bb;
1260
1261   /* All block merging is done into the lower block numbers.  */
1262
1263   combo_bb = test_bb;
1264
1265   /* First merge TEST block into THEN block.  This is a no-brainer since
1266      the THEN block did not have a code label to begin with.  */
1267
1268   if (combo_bb->global_live_at_end)
1269     COPY_REG_SET (combo_bb->global_live_at_end, then_bb->global_live_at_end);
1270   merge_blocks_nomove (combo_bb, then_bb);
1271   num_removed_blocks++;
1272
1273   /* The ELSE block, if it existed, had a label.  That label count
1274      will almost always be zero, but odd things can happen when labels
1275      get their addresses taken.  */
1276   if (else_bb)
1277     {
1278       if (LABEL_NUSES (else_bb->head) == 0
1279           && ! LABEL_PRESERVE_P (else_bb->head)
1280           && ! LABEL_NAME (else_bb->head))
1281         {
1282           /* We can merge the ELSE.  */
1283           merge_blocks_nomove (combo_bb, else_bb);
1284           num_removed_blocks++;
1285         }
1286       else
1287         {
1288           /* We cannot merge the ELSE.  */
1289
1290           /* Properly rewire the edge out of the now combined
1291              TEST-THEN block to point here.  */
1292           remove_edge (combo_bb->succ);
1293           if (combo_bb->succ || else_bb->pred)
1294             abort ();
1295           make_edge (NULL, combo_bb, else_bb, EDGE_FALLTHRU);
1296
1297           /* Remove the jump and cruft from the end of the TEST-THEN block.  */
1298           tidy_fallthru_edge (combo_bb->succ, combo_bb, else_bb);
1299
1300           /* Make sure we update life info properly.  */
1301           SET_UPDATE_LIFE(combo_bb);
1302           if (else_bb->global_live_at_end)
1303             COPY_REG_SET (else_bb->global_live_at_start,
1304                           else_bb->global_live_at_end);
1305
1306           /* The ELSE is the new combo block.  */
1307           combo_bb = else_bb;
1308         }
1309     }
1310
1311   /* If there was no join block reported, that means it was not adjacent
1312      to the others, and so we cannot merge them.  */
1313
1314   if (! join_bb)
1315     {
1316       /* The outgoing edge for the current COMBO block should already
1317          be correct.  Verify this.  */
1318       if (combo_bb->succ == NULL_EDGE)
1319         abort ();
1320
1321       /* There should sill be a branch at the end of the THEN or ELSE
1322          blocks taking us to our final destination.  */
1323       if (! simplejump_p (combo_bb->end)
1324           && ! returnjump_p (combo_bb->end))
1325         abort ();
1326     }
1327
1328   /* The JOIN block had a label.  It may have had quite a number
1329      of other predecessors too, but probably not.  See if we can
1330      merge this with the others.  */
1331   else if (LABEL_NUSES (join_bb->head) == 0
1332       && ! LABEL_PRESERVE_P (join_bb->head)
1333       && ! LABEL_NAME (join_bb->head))
1334     {
1335       /* We can merge the JOIN.  */
1336       if (combo_bb->global_live_at_end)
1337         COPY_REG_SET (combo_bb->global_live_at_end,
1338                       join_bb->global_live_at_end);
1339       merge_blocks_nomove (combo_bb, join_bb);
1340       num_removed_blocks++;
1341     }
1342   else
1343     {
1344       /* We cannot merge the JOIN.  */
1345
1346       /* The outgoing edge for the current COMBO block should already
1347          be correct.  Verify this.  */
1348       if (combo_bb->succ->succ_next != NULL_EDGE
1349           || combo_bb->succ->dest != join_bb)
1350         abort ();
1351
1352       /* Remove the jump and cruft from the end of the COMBO block.  */
1353       tidy_fallthru_edge (combo_bb->succ, combo_bb, join_bb);
1354     }
1355
1356   /* Make sure we update life info properly.  */
1357   SET_UPDATE_LIFE (combo_bb);
1358
1359   num_updated_if_blocks++;
1360 }
1361 \f
1362 /* Find a block ending in a simple IF condition.  Return TRUE if
1363    we were able to transform it in some way.  */
1364
1365 static int
1366 find_if_header (test_bb)
1367      basic_block test_bb;
1368 {
1369   edge then_edge;
1370   edge else_edge;
1371
1372   /* The kind of block we're looking for has exactly two successors.  */
1373   if ((then_edge = test_bb->succ) == NULL_EDGE
1374       || (else_edge = then_edge->succ_next) == NULL_EDGE
1375       || else_edge->succ_next != NULL_EDGE)
1376     return FALSE;
1377
1378   /* Neither edge should be abnormal.  */
1379   if ((then_edge->flags & EDGE_COMPLEX)
1380       || (else_edge->flags & EDGE_COMPLEX))
1381     return FALSE;
1382
1383   /* The THEN edge is canonically the one that falls through.  */
1384   if (then_edge->flags & EDGE_FALLTHRU)
1385     ;
1386   else if (else_edge->flags & EDGE_FALLTHRU)
1387     {
1388       edge e = else_edge;
1389       else_edge = then_edge;
1390       then_edge = e;
1391     }
1392   else
1393     /* Otherwise this must be a multiway branch of some sort.  */
1394     return FALSE;
1395
1396   if (find_if_block (test_bb, then_edge, else_edge))
1397     goto success;
1398   if (post_dominators
1399       && (! HAVE_conditional_execution || reload_completed))
1400     {
1401       if (find_if_case_1 (test_bb, then_edge, else_edge))
1402         goto success;
1403       if (find_if_case_2 (test_bb, then_edge, else_edge))
1404         goto success;
1405     }
1406
1407   return FALSE;
1408
1409  success:
1410   if (rtl_dump_file)
1411     fprintf (rtl_dump_file, "Conversion succeeded.\n");
1412   return TRUE;
1413 }
1414
1415 /* Determine if a given basic block heads a simple IF-THEN or IF-THEN-ELSE
1416    block.  If so, we'll try to convert the insns to not require the branch.
1417    Return TRUE if we were successful at converting the the block.  */
1418
1419 static int
1420 find_if_block (test_bb, then_edge, else_edge)
1421       basic_block test_bb;
1422       edge then_edge, else_edge;
1423 {
1424   basic_block then_bb = then_edge->dest;
1425   basic_block else_bb = else_edge->dest;
1426   basic_block join_bb = NULL_BLOCK;
1427   edge then_succ = then_bb->succ;
1428   edge else_succ = else_bb->succ;
1429   int next_index;
1430
1431   /* The THEN block of an IF-THEN combo must have exactly one predecessor.  */
1432   if (then_bb->pred->pred_next != NULL_EDGE)
1433     return FALSE;
1434
1435   /* The THEN block of an IF-THEN combo must have exactly one successor.  */
1436   if (then_succ == NULL_EDGE
1437       || then_succ->succ_next != NULL_EDGE
1438       || (then_succ->flags & EDGE_COMPLEX))
1439     return FALSE;
1440
1441   /* The THEN block may not start with a label, as might happen with an
1442      unused user label that has had its address taken.  */
1443   if (GET_CODE (then_bb->head) == CODE_LABEL)
1444     return FALSE;
1445
1446   /* If the THEN block's successor is the other edge out of the TEST block,
1447      then we have an IF-THEN combo without an ELSE.  */
1448   if (then_succ->dest == else_bb)
1449     {
1450       join_bb = else_bb;
1451       else_bb = NULL_BLOCK;
1452     }
1453
1454   /* If the THEN and ELSE block meet in a subsequent block, and the ELSE
1455      has exactly one predecessor and one successor, and the outgoing edge
1456      is not complex, then we have an IF-THEN-ELSE combo.  */
1457   else if (else_succ != NULL_EDGE
1458            && then_succ->dest == else_succ->dest
1459            && else_bb->pred->pred_next == NULL_EDGE
1460            && else_succ->succ_next == NULL_EDGE
1461            && ! (else_succ->flags & EDGE_COMPLEX))
1462     join_bb = else_succ->dest;
1463
1464   /* Otherwise it is not an IF-THEN or IF-THEN-ELSE combination.  */
1465   else
1466     return FALSE;          
1467
1468   num_possible_if_blocks++;
1469
1470   if (rtl_dump_file)
1471     {
1472       if (else_bb)
1473         fprintf (rtl_dump_file,
1474                  "\nIF-THEN-ELSE block found, start %d, then %d, else %d, join %d\n",
1475                  test_bb->index, then_bb->index, else_bb->index,
1476                  join_bb->index);
1477       else
1478         fprintf (rtl_dump_file,
1479                  "\nIF-THEN block found, start %d, then %d, join %d\n",
1480                  test_bb->index, then_bb->index, join_bb->index);
1481     }
1482
1483   /* Make sure IF, THEN, and ELSE, blocks are adjacent.  Actually, we
1484      get the first condition for free, since we've already asserted that
1485      there's a fallthru edge from IF to THEN.  */
1486   /* ??? As an enhancement, move the ELSE block.  Have to deal with EH and
1487      BLOCK notes, if by no other means than aborting the merge if they
1488      exist.  Sticky enough I don't want to think about it now.  */
1489   next_index = then_bb->index;
1490   if (else_bb && ++next_index != else_bb->index)
1491     return FALSE;
1492   if (++next_index != join_bb->index)
1493     {
1494       if (else_bb)
1495         join_bb = NULL;
1496       else
1497         return FALSE;
1498     }
1499
1500   /* Do the real work.  */
1501   return process_if_block (test_bb, then_bb, else_bb, join_bb);
1502 }
1503
1504 /* Look for IF-THEN-ELSE cases in which one of THEN or ELSE is
1505    transformable, but not necessarily the other.  There need be no
1506    JOIN block.
1507
1508    Return TRUE if we were successful at converting the the block.
1509
1510    Cases we'd like to look at:
1511
1512    (1)
1513         if (test) goto over; // x not live
1514         x = a;
1515         goto label;
1516         over:
1517
1518    becomes
1519
1520         x = a;
1521         if (! test) goto label;
1522
1523    (2)
1524         if (test) goto E; // x not live
1525         x = big();
1526         goto L;
1527         E:
1528         x = b;
1529         goto M;
1530
1531    becomes
1532
1533         x = b;
1534         if (test) goto M;
1535         x = big();
1536         goto L;
1537
1538    (3) // This one's really only interesting for targets that can do
1539        // multiway branching, e.g. IA-64 BBB bundles.  For other targets
1540        // it results in multiple branches on a cache line, which often
1541        // does not sit well with predictors.
1542
1543         if (test1) goto E; // predicted not taken
1544         x = a;
1545         if (test2) goto F;
1546         ...
1547         E:
1548         x = b;
1549         J:
1550
1551    becomes
1552
1553         x = a;
1554         if (test1) goto E;
1555         if (test2) goto F;
1556
1557    Notes:
1558
1559    (A) Don't do (2) if the branch is predicted against the block we're
1560    eliminating.  Do it anyway if we can eliminate a branch; this requires
1561    that the sole successor of the eliminated block postdominate the other
1562    side of the if.
1563
1564    (B) With CE, on (3) we can steal from both sides of the if, creating
1565
1566         if (test1) x = a;
1567         if (!test1) x = b;
1568         if (test1) goto J;
1569         if (test2) goto F;
1570         ...
1571         J:
1572
1573    Again, this is most useful if J postdominates.
1574
1575    (C) CE substitutes for helpful life information.
1576
1577    (D) These heuristics need a lot of work.  */
1578
1579 /* Tests for case 1 above.  */
1580
1581 static int
1582 find_if_case_1 (test_bb, then_edge, else_edge)
1583       basic_block test_bb;
1584       edge then_edge, else_edge;
1585 {
1586   basic_block then_bb = then_edge->dest;
1587   basic_block else_bb = else_edge->dest;
1588   edge then_succ = then_bb->succ;
1589   rtx new_lab;
1590
1591   /* THEN has one successor.  */
1592   if (!then_succ || then_succ->succ_next != NULL)
1593     return FALSE;
1594
1595   /* THEN does not fall through, but is not strange either.  */
1596   if (then_succ->flags & (EDGE_COMPLEX | EDGE_FALLTHRU))
1597     return FALSE;
1598
1599   /* THEN has one predecessor.  */
1600   if (then_bb->pred->pred_next != NULL)
1601     return FALSE;
1602
1603   /* THEN has no label.  */
1604   if (GET_CODE (then_bb->head) == CODE_LABEL)
1605     return FALSE;
1606
1607   /* ELSE follows THEN.  (??? could be moved)  */
1608   if (else_bb->index != then_bb->index + 1)
1609     return FALSE;
1610
1611   num_possible_if_blocks++;
1612   if (rtl_dump_file)
1613     fprintf (rtl_dump_file,
1614              "\nIF-CASE-1 found, start %d, then %d\n",
1615              test_bb->index, then_bb->index);
1616
1617   /* THEN is small.  */
1618   if (count_bb_insns (then_bb) > BRANCH_COST)
1619     return FALSE;
1620
1621   /* Find the label for THEN's destination.  */
1622   if (then_succ->dest == EXIT_BLOCK_PTR)
1623     new_lab = NULL_RTX;
1624   else
1625     {
1626       new_lab = JUMP_LABEL (then_bb->end);
1627       if (! new_lab)
1628         abort ();
1629     }
1630
1631   /* Registers set are dead, or are predicable.  */
1632   if (! dead_or_predicable (test_bb, then_bb, else_bb, new_lab, 1))
1633     return FALSE;
1634
1635   /* Conversion went ok, including moving the insns and fixing up the
1636      jump.  Adjust the CFG to match.  */
1637
1638   SET_UPDATE_LIFE (test_bb);
1639   bitmap_operation (test_bb->global_live_at_end,
1640                     else_bb->global_live_at_start,
1641                     then_bb->global_live_at_end, BITMAP_IOR);
1642   
1643   make_edge (NULL, test_bb, then_succ->dest, 0);
1644   flow_delete_block (then_bb);
1645   tidy_fallthru_edge (else_edge, test_bb, else_bb);
1646
1647   num_removed_blocks++;
1648   num_updated_if_blocks++;
1649
1650   return TRUE;
1651 }
1652
1653 /* Test for case 2 above.  */
1654
1655 static int
1656 find_if_case_2 (test_bb, then_edge, else_edge)
1657       basic_block test_bb;
1658       edge then_edge, else_edge;
1659 {
1660   basic_block then_bb = then_edge->dest;
1661   basic_block else_bb = else_edge->dest;
1662   edge else_succ = else_bb->succ;
1663   rtx new_lab, note;
1664
1665   /* ELSE has one successor.  */
1666   if (!else_succ || else_succ->succ_next != NULL)
1667     return FALSE;
1668
1669   /* ELSE outgoing edge is not complex.  */
1670   if (else_succ->flags & EDGE_COMPLEX)
1671     return FALSE;
1672
1673   /* ELSE has one predecessor.  */
1674   if (else_bb->pred->pred_next != NULL)
1675     return FALSE;
1676
1677   /* ELSE has a label we can delete.  */
1678   if (LABEL_NUSES (else_bb->head) > 1
1679       || LABEL_PRESERVE_P (else_bb->head)
1680       || LABEL_NAME (else_bb->head))
1681     return FALSE;
1682
1683   /* ELSE is predicted or SUCC(ELSE) postdominates THEN.  */
1684   note = find_reg_note (test_bb->end, REG_BR_PROB, NULL_RTX);
1685   if (note && INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2)
1686     ;
1687   else if (else_succ->dest->index < 0
1688            || (then_bb->index >= 0
1689                && TEST_BIT (post_dominators[ORIG_INDEX (then_bb)], 
1690                             ORIG_INDEX (else_succ->dest))))
1691     ;
1692   else
1693     return FALSE;
1694
1695   num_possible_if_blocks++;
1696   if (rtl_dump_file)
1697     fprintf (rtl_dump_file,
1698              "\nIF-CASE-2 found, start %d, else %d\n",
1699              test_bb->index, else_bb->index);
1700
1701   /* ELSE is small.  */
1702   if (count_bb_insns (then_bb) > BRANCH_COST)
1703     return FALSE;
1704
1705   /* Find the label for ELSE's destination.  */
1706   if (else_succ->dest == EXIT_BLOCK_PTR)
1707     new_lab = NULL_RTX;
1708   else
1709     {
1710       if (else_succ->flags & EDGE_FALLTHRU)
1711         {
1712           new_lab = else_succ->dest->head;
1713           if (GET_CODE (new_lab) != CODE_LABEL)
1714             abort ();
1715         }
1716       else
1717         {
1718           new_lab = JUMP_LABEL (else_bb->end);
1719           if (! new_lab)
1720             abort ();
1721         }
1722     }
1723
1724   /* Registers set are dead, or are predicable.  */
1725   if (! dead_or_predicable (test_bb, else_bb, then_bb, new_lab, 0))
1726     return FALSE;
1727
1728   /* Conversion went ok, including moving the insns and fixing up the
1729      jump.  Adjust the CFG to match.  */
1730
1731   SET_UPDATE_LIFE (test_bb);
1732   bitmap_operation (test_bb->global_live_at_end,
1733                     then_bb->global_live_at_start,
1734                     else_bb->global_live_at_end, BITMAP_IOR);
1735   
1736   remove_edge (else_edge);
1737   make_edge (NULL, test_bb, else_succ->dest, 0);
1738   flow_delete_block (else_bb);
1739
1740   num_removed_blocks++;
1741   num_updated_if_blocks++;
1742
1743   /* ??? We may now fallthru from one of THEN's successors into a join
1744      block.  Rerun cleanup_cfg?  Examine things manually?  Wait?  */
1745
1746   return TRUE;
1747 }
1748
1749 /* A subroutine of dead_or_predicable called through for_each_rtx.
1750    Return 1 if a memory is found.  */
1751
1752 static int
1753 find_memory (px, data)
1754      rtx *px;
1755      void *data ATTRIBUTE_UNUSED;
1756 {
1757   return GET_CODE (*px) == MEM;
1758 }
1759
1760 /* Used by the code above to perform the actual rtl transformations.
1761    Return TRUE if successful.
1762
1763    TEST_BB is the block containing the conditional branch.  MERGE_BB
1764    is the block containing the code to manipulate.  NEW_DEST is the
1765    label TEST_BB should be branching to after the conversion.
1766    REVERSEP is true if the sense of the branch should be reversed.  */
1767
1768 static int
1769 dead_or_predicable (test_bb, merge_bb, other_bb, new_dest, reversep)
1770      basic_block test_bb, merge_bb, other_bb;
1771      rtx new_dest;
1772      int reversep;
1773 {
1774   rtx head, end, jump, earliest, old_dest;
1775
1776   jump = test_bb->end;
1777
1778   /* Find the extent of the real code in the merge block.  */
1779   head = merge_bb->head;
1780   end = merge_bb->end;
1781
1782   if (GET_CODE (head) == CODE_LABEL)
1783     head = NEXT_INSN (head);
1784   if (GET_CODE (head) == NOTE)
1785     {
1786       if (head == end)
1787         {
1788           head = end = NULL_RTX;
1789           goto no_body;
1790         }
1791       head = NEXT_INSN (head);
1792     }
1793
1794   if (GET_CODE (end) == JUMP_INSN)
1795     {
1796       if (head == end)
1797         {
1798           head = end = NULL_RTX;
1799           goto no_body;
1800         }
1801       end = PREV_INSN (end);
1802     }
1803
1804   if (HAVE_conditional_execution)
1805     {
1806       /* In the conditional execution case, we have things easy.  We know
1807          the condition is reversable.  We don't have to check life info,
1808          becase we're going to conditionally execute the code anyway.
1809          All that's left is making sure the insns involved can actually
1810          be predicated.  */
1811
1812       rtx cond, prob_val;
1813
1814       cond = cond_exec_get_condition (jump);
1815
1816       prob_val = find_reg_note (jump, REG_BR_PROB, NULL_RTX);
1817       if (prob_val)
1818         prob_val = XEXP (prob_val, 0);
1819
1820       if (reversep)
1821         {
1822           cond = gen_rtx_fmt_ee (reverse_condition (GET_CODE (cond)),
1823                                  GET_MODE (cond), XEXP (cond, 0),
1824                                  XEXP (cond, 1));
1825           if (prob_val)
1826             prob_val = GEN_INT (REG_BR_PROB_BASE - INTVAL (prob_val));
1827         }
1828
1829       if (! cond_exec_process_insns (head, end, cond, prob_val, 0))
1830         goto cancel;
1831
1832       earliest = jump;
1833     }
1834   else
1835     {
1836       /* In the non-conditional execution case, we have to verify that there
1837          are no trapping operations, no calls, no references to memory, and
1838          that any registers modified are dead at the branch site.  */
1839
1840       rtx insn, cond, prev;
1841       regset_head merge_set_head, tmp_head, test_live_head, test_set_head;
1842       regset merge_set, tmp, test_live, test_set;
1843       struct propagate_block_info *pbi;
1844       int i, fail = 0;
1845
1846       /* Check for no calls or trapping operations.  */
1847       for (insn = head; ; insn = NEXT_INSN (insn))
1848         {
1849           if (GET_CODE (insn) == CALL_INSN)
1850             return FALSE;
1851           if (INSN_P (insn))
1852             {
1853               if (may_trap_p (PATTERN (insn)))
1854                 return FALSE;
1855
1856               /* ??? Even non-trapping memories such as stack frame
1857                  references must be avoided.  For stores, we collect
1858                  no lifetime info; for reads, we'd have to assert
1859                  true_dependance false against every store in the
1860                  TEST range.  */
1861               if (for_each_rtx (&PATTERN (insn), find_memory, NULL))
1862                 return FALSE;
1863             }
1864           if (insn == end)
1865             break;
1866         }
1867
1868       if (! condjump_p (jump))
1869         return FALSE;
1870
1871       /* Find the extent of the conditional.  */
1872       cond = noce_get_condition (jump, &earliest);
1873       if (! cond)
1874         return FALSE;
1875
1876       /* Collect:
1877            MERGE_SET = set of registers set in MERGE_BB
1878            TEST_LIVE = set of registers live at EARLIEST
1879            TEST_SET  = set of registers set between EARLIEST and the
1880                        end of the block.  */
1881
1882       tmp = INITIALIZE_REG_SET (tmp_head);
1883       merge_set = INITIALIZE_REG_SET (merge_set_head);
1884       test_live = INITIALIZE_REG_SET (test_live_head);
1885       test_set = INITIALIZE_REG_SET (test_set_head);
1886
1887       /* ??? bb->local_set is only valid during calculate_global_regs_live,
1888          so we must recompute usage for MERGE_BB.  Not so bad, I suppose, 
1889          since we've already asserted that MERGE_BB is small.  */
1890       propagate_block (merge_bb, tmp, merge_set, 0);
1891
1892       /* For small register class machines, don't lengthen lifetimes of
1893          hard registers before reload.  */
1894       if (SMALL_REGISTER_CLASSES && ! reload_completed)
1895         {
1896           EXECUTE_IF_SET_IN_BITMAP
1897             (merge_set, 0, i,
1898              {
1899                if (i < FIRST_PSEUDO_REGISTER
1900                    && ! fixed_regs[i]
1901                    && ! global_regs[i])
1902                 fail = 1;
1903              });
1904         }
1905
1906       /* For TEST, we're interested in a range of insns, not a whole block.
1907          Moreover, we're interested in the insns live from OTHER_BB.  */
1908
1909       COPY_REG_SET (test_live, other_bb->global_live_at_start);
1910       pbi = init_propagate_block_info (test_bb, test_live, test_set, 0);
1911
1912       for (insn = jump; ; insn = prev)
1913         {
1914           prev = propagate_one_insn (pbi, insn);
1915           if (insn == earliest)
1916             break;
1917         }
1918
1919       free_propagate_block_info (pbi);
1920
1921       /* We can perform the transformation if
1922            MERGE_SET & (TEST_SET | TEST_LIVE)
1923          and
1924            TEST_SET & merge_bb->global_live_at_start
1925          are empty.  */
1926
1927       bitmap_operation (tmp, test_set, test_live, BITMAP_IOR);
1928       bitmap_operation (tmp, tmp, merge_set, BITMAP_AND);
1929       EXECUTE_IF_SET_IN_BITMAP(tmp, 0, i, fail = 1);
1930
1931       bitmap_operation (tmp, test_set, merge_bb->global_live_at_start,
1932                         BITMAP_AND);
1933       EXECUTE_IF_SET_IN_BITMAP(tmp, 0, i, fail = 1);
1934
1935       FREE_REG_SET (tmp);
1936       FREE_REG_SET (merge_set);
1937       FREE_REG_SET (test_live);
1938       FREE_REG_SET (test_set);
1939
1940       if (fail)
1941         return FALSE;
1942     }
1943
1944  no_body:
1945   /* We don't want to use normal invert_jump or redirect_jump because
1946      we don't want to delete_insn called.  Also, we want to do our own
1947      change group management.  */
1948
1949   old_dest = JUMP_LABEL (jump);
1950   if (reversep
1951       ? ! invert_jump_1 (jump, new_dest)
1952       : ! redirect_jump_1 (jump, new_dest))
1953     goto cancel;
1954
1955   if (! apply_change_group ())
1956     return FALSE;
1957
1958   if (old_dest)
1959     LABEL_NUSES (old_dest) -= 1;
1960   if (new_dest)
1961     LABEL_NUSES (new_dest) += 1;
1962   JUMP_LABEL (jump) = new_dest;
1963
1964   if (reversep)
1965     {
1966       rtx note = find_reg_note (jump, REG_BR_PROB, NULL_RTX);
1967       if (note)
1968         XEXP (note, 0) = GEN_INT (REG_BR_PROB_BASE - INTVAL (XEXP (note, 0)));
1969     }
1970
1971   /* Move the insns out of MERGE_BB to before the branch.  */
1972   if (head != NULL)
1973     {
1974       if (end == merge_bb->end)
1975         merge_bb->end = PREV_INSN (head);
1976
1977       head = squeeze_notes (head, end);
1978       if (GET_CODE (end) == NOTE
1979           && (NOTE_LINE_NUMBER (end) == NOTE_INSN_BLOCK_END
1980               || NOTE_LINE_NUMBER (end) == NOTE_INSN_BLOCK_BEG
1981               || NOTE_LINE_NUMBER (end) == NOTE_INSN_LOOP_BEG
1982               || NOTE_LINE_NUMBER (end) == NOTE_INSN_LOOP_END
1983               || NOTE_LINE_NUMBER (end) == NOTE_INSN_LOOP_CONT
1984               || NOTE_LINE_NUMBER (end) == NOTE_INSN_LOOP_VTOP))
1985         {
1986           if (head == end)
1987             return TRUE;
1988           end = PREV_INSN (end);
1989         }
1990
1991       reorder_insns (head, end, PREV_INSN (earliest));
1992     }
1993   return TRUE;
1994
1995  cancel:
1996   cancel_changes (0);
1997   return FALSE;
1998 }
1999 \f
2000 /* Main entry point for all if-conversion.  */
2001
2002 void
2003 if_convert (life_data_ok)
2004      int life_data_ok;
2005 {
2006   int block_num;
2007
2008   num_possible_if_blocks = 0;
2009   num_updated_if_blocks = 0;
2010   num_removed_blocks = 0;
2011
2012   /* Free up basic_block_for_insn so that we don't have to keep it 
2013      up to date, either here or in merge_blocks_nomove.  */
2014   free_basic_block_vars (1);
2015
2016   /* Compute postdominators if we think we'll use them.  */
2017   post_dominators = NULL;
2018   if (HAVE_conditional_execution || life_data_ok)
2019     {
2020       post_dominators = sbitmap_vector_alloc (n_basic_blocks, n_basic_blocks);
2021       compute_flow_dominators (NULL, post_dominators);
2022     }
2023
2024   /* Record initial block numbers.  */
2025   for (block_num = 0; block_num < n_basic_blocks; block_num++)
2026     SET_ORIG_INDEX (BASIC_BLOCK (block_num), block_num);
2027
2028   /* Go through each of the basic blocks looking for things to convert.  */
2029   for (block_num = 0; block_num < n_basic_blocks; )
2030     {
2031       basic_block bb = BASIC_BLOCK (block_num);
2032       if (find_if_header (bb))
2033         block_num = bb->index;
2034       else 
2035         block_num++;
2036     }
2037
2038   sbitmap_vector_free (post_dominators);
2039
2040   if (rtl_dump_file)
2041     fflush (rtl_dump_file);
2042
2043   /* Rebuild basic_block_for_insn for update_life_info and for gcse.  */
2044   compute_bb_for_insn (get_max_uid ());
2045
2046   /* Rebuild life info for basic blocks that require it.  */
2047   if (num_removed_blocks && life_data_ok)
2048     {
2049       sbitmap update_life_blocks = sbitmap_alloc (n_basic_blocks);
2050       sbitmap_zero (update_life_blocks);
2051
2052       /* If we allocated new pseudos, we must resize the array for sched1.  */
2053       if (max_regno < max_reg_num ())
2054         {
2055           max_regno = max_reg_num ();
2056           allocate_reg_info (max_regno, FALSE, FALSE);
2057         }
2058
2059       for (block_num = 0; block_num < n_basic_blocks; block_num++)
2060         if (UPDATE_LIFE (BASIC_BLOCK (block_num)))
2061           SET_BIT (update_life_blocks, block_num);
2062
2063       count_or_remove_death_notes (update_life_blocks, 1);
2064       update_life_info (update_life_blocks, UPDATE_LIFE_LOCAL,
2065                         PROP_DEATH_NOTES);
2066
2067       sbitmap_free (update_life_blocks);
2068     }
2069
2070   /* Write the final stats.  */
2071   if (rtl_dump_file && num_possible_if_blocks > 0)
2072     {
2073       fprintf (rtl_dump_file,
2074                "\n%d possible IF blocks searched.\n",
2075                num_possible_if_blocks);
2076       fprintf (rtl_dump_file,
2077                "%d IF blocks converted.\n",
2078                num_updated_if_blocks);
2079       fprintf (rtl_dump_file,
2080                "%d basic blocks deleted.\n\n\n",
2081                num_removed_blocks);
2082     }
2083
2084 #ifdef ENABLE_CHECKING
2085   verify_flow_info ();
2086 #endif
2087 }