OSDN Git Service

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