OSDN Git Service

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