1 /* If-conversion support.
2 Copyright (C) 2000 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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)
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.
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. */
28 #include "insn-config.h"
30 #include "hard-reg-set.h"
31 #include "basic-block.h"
37 #ifndef HAVE_conditional_execution
38 #define HAVE_conditional_execution 0
40 #ifndef HAVE_conditional_move
41 #define HAVE_conditional_move 0
50 #ifndef MAX_CONDITIONAL_EXECUTE
51 #define MAX_CONDITIONAL_EXECUTE (BRANCH_COST + 1)
54 #define EDGE_COMPLEX (EDGE_ABNORMAL | EDGE_ABNORMAL_CALL | EDGE_EH)
56 #define NULL_EDGE ((struct edge_def *)NULL)
57 #define NULL_BLOCK ((struct basic_block_def *)NULL)
59 /* # of IF-THEN or IF-THEN-ELSE blocks we looked at */
60 static int num_possible_if_blocks;
62 /* # of IF-THEN or IF-THEN-ELSE blocks were converted to conditional
64 static int num_updated_if_blocks;
66 /* # of basic blocks that were removed. */
67 static int num_removed_blocks;
69 /* The post-dominator relation on the original block numbers. */
70 static sbitmap *post_dominators;
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));
77 static int cond_exec_process_insns PARAMS ((rtx, rtx, rtx, rtx, int));
78 static rtx cond_exec_get_condition PARAMS ((rtx));
79 static int cond_exec_process_if_block PARAMS ((basic_block, basic_block,
80 basic_block, basic_block));
82 static rtx noce_get_condition PARAMS ((rtx, rtx *));
83 static int noce_process_if_block PARAMS ((basic_block, basic_block,
84 basic_block, basic_block));
86 static int process_if_block PARAMS ((basic_block, basic_block,
87 basic_block, basic_block));
88 static void merge_if_block PARAMS ((basic_block, basic_block,
89 basic_block, basic_block));
91 static int find_if_header PARAMS ((basic_block));
92 static int find_if_block PARAMS ((basic_block, edge, edge));
93 static int find_if_case_1 PARAMS ((basic_block, edge, edge));
94 static int find_if_case_2 PARAMS ((basic_block, edge, edge));
95 static int find_memory PARAMS ((rtx *, void *));
96 static int dead_or_predicable PARAMS ((basic_block, basic_block,
97 basic_block, rtx, int));
99 /* Abuse the basic_block AUX field to store the original block index,
100 as well as a flag indicating that the block should be rescaned for
103 #define SET_ORIG_INDEX(BB,I) ((BB)->aux = (void *)((size_t)(I) << 1))
104 #define ORIG_INDEX(BB) ((size_t)(BB)->aux >> 1)
105 #define SET_UPDATE_LIFE(BB) ((BB)->aux = (void *)((size_t)(BB)->aux | 1))
106 #define UPDATE_LIFE(BB) ((size_t)(BB)->aux & 1)
109 /* Count the number of non-jump active insns in BB. */
120 if (GET_CODE (insn) == CALL_INSN || GET_CODE (insn) == INSN)
125 insn = NEXT_INSN (insn);
131 /* Return the first non-jump active insn in the basic block. */
134 first_active_insn (bb)
139 if (GET_CODE (insn) == CODE_LABEL)
143 insn = NEXT_INSN (insn);
146 while (GET_CODE (insn) == NOTE)
150 insn = NEXT_INSN (insn);
153 if (GET_CODE (insn) == JUMP_INSN)
159 /* Return true if INSN is the last active non-jump insn in BB. */
162 last_active_insn_p (bb, insn)
170 insn = NEXT_INSN (insn);
172 while (GET_CODE (insn) == NOTE);
174 return GET_CODE (insn) == JUMP_INSN;
177 /* Go through a bunch of insns, converting them to conditional
178 execution format if possible. Return TRUE if all of the non-note
179 insns were processed. */
182 cond_exec_process_insns (start, end, test, prob_val, mod_ok)
183 rtx start; /* first insn to look at */
184 rtx end; /* last insn to look at */
185 rtx test; /* conditional execution test */
186 rtx prob_val; /* probability of branch taken. */
187 int mod_ok; /* true if modifications ok last insn. */
189 int must_be_last = FALSE;
192 for (insn = start; ; insn = NEXT_INSN (insn))
194 if (GET_CODE (insn) == NOTE)
197 if (GET_CODE (insn) != INSN && GET_CODE (insn) != CALL_INSN)
200 /* Remove USE and CLOBBER insns that get in the way. */
202 && (GET_CODE (PATTERN (insn)) == USE
203 || GET_CODE (PATTERN (insn)) == CLOBBER))
205 /* ??? Ug. Actually unlinking the thing is problematic,
206 given what we'd have to coordinate with our callers. */
207 PUT_CODE (insn, NOTE);
208 NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
209 NOTE_SOURCE_FILE (insn) = 0;
213 /* Last insn wasn't last? */
217 if (modified_in_p (test, insn))
224 /* Now build the conditional form of the instruction. */
225 validate_change (insn, &PATTERN (insn),
226 gen_rtx_COND_EXEC (VOIDmode, copy_rtx (test),
229 if (GET_CODE (insn) == CALL_INSN && prob_val)
230 validate_change (insn, ®_NOTES (insn),
231 alloc_EXPR_LIST (REG_BR_PROB, prob_val,
232 REG_NOTES (insn)), 1);
242 /* Return the condition for a jump. Do not do any special processing. */
245 cond_exec_get_condition (jump)
250 if (any_condjump_p (jump))
251 test_if = pc_set (jump);
254 cond = XEXP (test_if, 0);
256 /* If this branches to JUMP_LABEL when the condition is false,
257 reverse the condition. */
258 if (GET_CODE (XEXP (test_if, 2)) == LABEL_REF
259 && XEXP (XEXP (test_if, 2), 0) == JUMP_LABEL (jump))
260 cond = gen_rtx_fmt_ee (reverse_condition (GET_CODE (cond)),
261 GET_MODE (cond), XEXP (cond, 0),
267 /* Given a simple IF-THEN or IF-THEN-ELSE block, attempt to convert it
268 to conditional execution. Return TRUE if we were successful at
269 converting the the block. */
272 cond_exec_process_if_block (test_bb, then_bb, else_bb, join_bb)
273 basic_block test_bb; /* Basic block test is in */
274 basic_block then_bb; /* Basic block for THEN block */
275 basic_block else_bb; /* Basic block for ELSE block */
276 basic_block join_bb; /* Basic block the join label is in */
278 rtx test_expr; /* expression in IF_THEN_ELSE that is tested */
279 rtx then_start; /* first insn in THEN block */
280 rtx then_end; /* last insn + 1 in THEN block */
281 rtx else_start; /* first insn in ELSE block or NULL */
282 rtx else_end; /* last insn + 1 in ELSE block */
283 int max; /* max # of insns to convert. */
284 int then_mod_ok; /* whether conditional mods are ok in THEN */
285 rtx true_expr; /* test for else block insns */
286 rtx false_expr; /* test for then block insns */
287 rtx true_prob_val; /* probability of else block */
288 rtx false_prob_val; /* probability of then block */
291 /* Find the conditional jump to the ELSE or JOIN part, and isolate
293 test_expr = cond_exec_get_condition (test_bb->end);
297 /* Collect the bounds of where we're to search. */
299 then_start = then_bb->head;
300 then_end = then_bb->end;
302 /* Skip a label heading THEN block. */
303 if (GET_CODE (then_start) == CODE_LABEL)
304 then_start = NEXT_INSN (then_start);
306 /* Skip a (use (const_int 0)) or branch as the final insn. */
307 if (GET_CODE (then_end) == INSN
308 && GET_CODE (PATTERN (then_end)) == USE
309 && GET_CODE (XEXP (PATTERN (then_end), 0)) == CONST_INT)
310 then_end = PREV_INSN (then_end);
311 else if (GET_CODE (then_end) == JUMP_INSN)
312 then_end = PREV_INSN (then_end);
316 /* Skip the ELSE block's label. */
317 else_start = NEXT_INSN (else_bb->head);
318 else_end = else_bb->end;
320 /* Skip a (use (const_int 0)) or branch as the final insn. */
321 if (GET_CODE (else_end) == INSN
322 && GET_CODE (PATTERN (else_end)) == USE
323 && GET_CODE (XEXP (PATTERN (else_end), 0)) == CONST_INT)
324 else_end = PREV_INSN (else_end);
325 else if (GET_CODE (else_end) == JUMP_INSN)
326 else_end = PREV_INSN (else_end);
329 /* How many instructions should we convert in total? */
333 max = 2 * MAX_CONDITIONAL_EXECUTE;
334 n_insns = count_bb_insns (else_bb);
337 max = MAX_CONDITIONAL_EXECUTE;
338 n_insns += count_bb_insns (then_bb);
342 /* Map test_expr/test_jump into the appropriate MD tests to use on
343 the conditionally executed code. */
345 true_expr = test_expr;
346 false_expr = gen_rtx_fmt_ee (reverse_condition (GET_CODE (true_expr)),
347 GET_MODE (true_expr), XEXP (true_expr, 0),
348 XEXP (true_expr, 1));
350 true_prob_val = find_reg_note (test_bb->end, REG_BR_PROB, NULL_RTX);
353 true_prob_val = XEXP (true_prob_val, 0);
354 false_prob_val = GEN_INT (REG_BR_PROB_BASE - INTVAL (true_prob_val));
357 false_prob_val = NULL_RTX;
359 /* For IF-THEN-ELSE blocks, we don't allow modifications of the test
360 on then THEN block. */
361 then_mod_ok = (else_bb == NULL_BLOCK);
363 /* Go through the THEN and ELSE blocks converting the insns if possible
364 to conditional execution. */
367 && ! cond_exec_process_insns (then_start, then_end,
368 false_expr, false_prob_val, then_mod_ok))
372 && ! cond_exec_process_insns (else_start, else_end,
373 true_expr, true_prob_val, TRUE))
376 if (! apply_change_group ())
379 /* Conversion succeeded. */
381 fprintf (rtl_dump_file, "%d insn%s converted to conditional execution.\n",
382 n_insns, (n_insns == 1) ? " was" : "s were");
384 /* Merge the blocks! */
385 merge_if_block (test_bb, then_bb, else_bb, join_bb);
393 /* Used by noce_process_if_block to communicate with its subroutines.
395 The subroutines know that A and B may be evaluated freely. They
396 know that X is a register. They should insert new instructions
397 before cond_earliest. */
403 rtx jump, cond, cond_earliest;
406 static rtx noce_emit_store_flag PARAMS ((struct noce_if_info *,
408 static int noce_try_store_flag PARAMS ((struct noce_if_info *));
409 static int noce_try_store_flag_inc PARAMS ((struct noce_if_info *));
410 static int noce_try_store_flag_constants PARAMS ((struct noce_if_info *));
411 static int noce_try_store_flag_mask PARAMS ((struct noce_if_info *));
412 static rtx noce_emit_cmove PARAMS ((struct noce_if_info *,
413 rtx, enum rtx_code, rtx,
415 static int noce_try_cmove PARAMS ((struct noce_if_info *));
416 static int noce_try_cmove_arith PARAMS ((struct noce_if_info *));
418 /* Helper function for noce_try_store_flag*. */
421 noce_emit_store_flag (if_info, x, reversep, normalize)
422 struct noce_if_info *if_info;
424 int reversep, normalize;
426 rtx cond = if_info->cond;
430 cond_complex = (! general_operand (XEXP (cond, 0), VOIDmode)
431 || ! general_operand (XEXP (cond, 1), VOIDmode));
433 /* If earliest == jump, or when the condition is complex, try to
434 build the store_flag insn directly. */
437 cond = XEXP (SET_SRC (PATTERN (if_info->jump)), 0);
439 if ((if_info->cond_earliest == if_info->jump || cond_complex)
440 && (normalize == 0 || STORE_FLAG_VALUE == normalize))
444 code = GET_CODE (cond);
446 code = reverse_condition (code);
448 tmp = gen_rtx_fmt_ee (code, GET_MODE (x), XEXP (cond, 0),
450 tmp = gen_rtx_SET (VOIDmode, x, tmp);
453 tmp = emit_insn (tmp);
455 if (recog_memoized (tmp) >= 0)
461 if_info->cond_earliest = if_info->jump;
469 /* Don't even try if the comparison operands are weird. */
473 code = GET_CODE (cond);
475 code = reverse_condition (code);
477 return emit_store_flag (x, code, XEXP (cond, 0),
478 XEXP (cond, 1), VOIDmode,
479 (code == LTU || code == LEU
480 || code == GEU || code == GTU), normalize);
483 /* Convert "if (test) x = 1; else x = 0".
485 Only try 0 and STORE_FLAG_VALUE here. Other combinations will be
486 tried in noce_try_store_flag_constants after noce_try_cmove has had
487 a go at the conversion. */
490 noce_try_store_flag (if_info)
491 struct noce_if_info *if_info;
496 if (GET_CODE (if_info->b) == CONST_INT
497 && INTVAL (if_info->b) == STORE_FLAG_VALUE
498 && if_info->a == const0_rtx)
500 else if (if_info->b == const0_rtx
501 && GET_CODE (if_info->a) == CONST_INT
502 && INTVAL (if_info->a) == STORE_FLAG_VALUE
503 && can_reverse_comparison_p (if_info->cond, if_info->jump))
510 target = noce_emit_store_flag (if_info, if_info->x, reversep, 0);
513 if (target != if_info->x)
514 emit_move_insn (if_info->x, target);
518 emit_insns_before (seq, if_info->cond_earliest);
529 /* Convert "if (test) x = a; else x = b", for A and B constant. */
532 noce_try_store_flag_constants (if_info)
533 struct noce_if_info *if_info;
537 HOST_WIDE_INT itrue, ifalse, diff, tmp;
538 int normalize, can_reverse;
541 && GET_CODE (if_info->a) == CONST_INT
542 && GET_CODE (if_info->b) == CONST_INT)
544 ifalse = INTVAL (if_info->a);
545 itrue = INTVAL (if_info->b);
546 diff = itrue - ifalse;
548 can_reverse = can_reverse_comparison_p (if_info->cond, if_info->jump);
551 if (diff == STORE_FLAG_VALUE || diff == -STORE_FLAG_VALUE)
553 else if (ifalse == 0 && exact_log2 (itrue) >= 0
554 && (STORE_FLAG_VALUE == 1
555 || BRANCH_COST >= 2))
557 else if (itrue == 0 && exact_log2 (ifalse) >= 0 && can_reverse
558 && (STORE_FLAG_VALUE == 1 || BRANCH_COST >= 2))
559 normalize = 1, reversep = 1;
561 && (STORE_FLAG_VALUE == -1
562 || BRANCH_COST >= 2))
564 else if (ifalse == -1 && can_reverse
565 && (STORE_FLAG_VALUE == -1 || BRANCH_COST >= 2))
566 normalize = -1, reversep = 1;
567 else if ((BRANCH_COST >= 2 && STORE_FLAG_VALUE == -1)
575 tmp = itrue; itrue = ifalse; ifalse = tmp;
580 target = noce_emit_store_flag (if_info, if_info->x, reversep, normalize);
587 /* if (test) x = 3; else x = 4;
588 => x = 3 + (test == 0); */
589 if (diff == STORE_FLAG_VALUE || diff == -STORE_FLAG_VALUE)
591 target = expand_binop (GET_MODE (if_info->x),
592 (diff == STORE_FLAG_VALUE
593 ? add_optab : sub_optab),
594 GEN_INT (ifalse), target, if_info->x, 0,
598 /* if (test) x = 8; else x = 0;
599 => x = (test != 0) << 3; */
600 else if (ifalse == 0 && (tmp = exact_log2 (itrue)) >= 0)
602 target = expand_binop (GET_MODE (if_info->x), ashl_optab,
603 target, GEN_INT (tmp), if_info->x, 0,
607 /* if (test) x = -1; else x = b;
608 => x = -(test != 0) | b; */
609 else if (itrue == -1)
611 target = expand_binop (GET_MODE (if_info->x), ior_optab,
612 target, GEN_INT (ifalse), if_info->x, 0,
616 /* if (test) x = a; else x = b;
617 => x = (-(test != 0) & (b - a)) + a; */
620 target = expand_binop (GET_MODE (if_info->x), and_optab,
621 target, GEN_INT (diff), if_info->x, 0,
624 target = expand_binop (GET_MODE (if_info->x), add_optab,
625 target, GEN_INT (ifalse), if_info->x, 0,
635 if (target != if_info->x)
636 emit_move_insn (if_info->x, target);
640 emit_insns_before (seq, if_info->cond_earliest);
648 /* Convert "if (test) foo++" into "foo += (test != 0)", and
649 similarly for "foo--". */
652 noce_try_store_flag_inc (if_info)
653 struct noce_if_info *if_info;
656 int subtract, normalize;
662 /* Should be no `else' case to worry about. */
663 && if_info->b == if_info->x
664 && GET_CODE (if_info->a) == PLUS
665 && (XEXP (if_info->a, 1) == const1_rtx
666 || XEXP (if_info->a, 1) == constm1_rtx)
667 && rtx_equal_p (XEXP (if_info->a, 0), if_info->x)
668 && can_reverse_comparison_p (if_info->cond, if_info->jump))
670 if (STORE_FLAG_VALUE == INTVAL (XEXP (if_info->a, 1)))
671 subtract = 0, normalize = 0;
672 else if (-STORE_FLAG_VALUE == INTVAL (XEXP (if_info->a, 1)))
673 subtract = 1, normalize = 0;
675 subtract = 0, normalize = INTVAL (XEXP (if_info->a, 1));
679 target = noce_emit_store_flag (if_info,
680 gen_reg_rtx (GET_MODE (if_info->x)),
684 target = expand_binop (GET_MODE (if_info->x),
685 subtract ? sub_optab : add_optab,
686 if_info->x, target, if_info->x, 0, OPTAB_WIDEN);
689 if (target != if_info->x)
690 emit_move_insn (if_info->x, target);
694 emit_insns_before (seq, if_info->cond_earliest);
705 /* Convert "if (test) x = 0;" to "x &= -(test == 0);" */
708 noce_try_store_flag_mask (if_info)
709 struct noce_if_info *if_info;
717 || STORE_FLAG_VALUE == -1)
718 && ((if_info->a == const0_rtx
719 && rtx_equal_p (if_info->b, if_info->x))
720 || ((reversep = can_reverse_comparison_p (if_info->cond,
722 && if_info->b == const0_rtx
723 && rtx_equal_p (if_info->a, if_info->x))))
726 target = noce_emit_store_flag (if_info,
727 gen_reg_rtx (GET_MODE (if_info->x)),
730 target = expand_binop (GET_MODE (if_info->x), and_optab,
731 if_info->x, target, if_info->x, 0,
736 if (target != if_info->x)
737 emit_move_insn (if_info->x, target);
741 emit_insns_before (seq, if_info->cond_earliest);
752 /* Helper function for noce_try_cmove and noce_try_cmove_arith. */
755 noce_emit_cmove (if_info, x, code, cmp_a, cmp_b, vfalse, vtrue)
756 struct noce_if_info *if_info;
757 rtx x, cmp_a, cmp_b, vfalse, vtrue;
760 /* If earliest == jump, try to build the cmove insn directly.
761 This is helpful when combine has created some complex condition
762 (like for alpha's cmovlbs) that we can't hope to regenerate
763 through the normal interface. */
765 if (if_info->cond_earliest == if_info->jump)
769 tmp = gen_rtx_fmt_ee (code, GET_MODE (if_info->cond), cmp_a, cmp_b);
770 tmp = gen_rtx_IF_THEN_ELSE (GET_MODE (x), tmp, vtrue, vfalse);
771 tmp = gen_rtx_SET (VOIDmode, x, tmp);
774 tmp = emit_insn (tmp);
776 if (recog_memoized (tmp) >= 0)
788 /* Don't even try if the comparison operands are weird. */
789 if (! general_operand (cmp_a, GET_MODE (cmp_a))
790 || ! general_operand (cmp_b, GET_MODE (cmp_b)))
793 #if HAVE_conditional_move
794 return emit_conditional_move (x, code, cmp_a, cmp_b, VOIDmode,
795 vtrue, vfalse, GET_MODE (x),
796 (code == LTU || code == GEU
797 || code == LEU || code == GTU));
799 /* We'll never get here, as noce_process_if_block doesn't call the
800 functions involved. Ifdef code, however, should be discouraged
801 because it leads to typos in the code not selected. However,
802 emit_conditional_move won't exist either. */
807 /* Try only simple constants and registers here. More complex cases
808 are handled in noce_try_cmove_arith after noce_try_store_flag_arith
809 has had a go at it. */
812 noce_try_cmove (if_info)
813 struct noce_if_info *if_info;
818 if ((CONSTANT_P (if_info->a) || register_operand (if_info->a, VOIDmode))
819 && (CONSTANT_P (if_info->b) || register_operand (if_info->b, VOIDmode)))
823 code = GET_CODE (if_info->cond);
824 target = noce_emit_cmove (if_info, if_info->x, code,
825 XEXP (if_info->cond, 0),
826 XEXP (if_info->cond, 1),
827 if_info->a, if_info->b);
831 if (target != if_info->x)
832 emit_move_insn (if_info->x, target);
836 emit_insns_before (seq, if_info->cond_earliest);
849 /* Try more complex cases involving conditional_move. */
852 noce_try_cmove_arith (if_info)
853 struct noce_if_info *if_info;
863 /* A conditional move from two memory sources is equivalent to a
864 conditional on their addresses followed by a load. Don't do this
865 early because it'll screw alias analysis. Note that we've
866 already checked for no side effects. */
867 if (! no_new_pseudos && cse_not_expected
868 && GET_CODE (a) == MEM && GET_CODE (b) == MEM
873 x = gen_reg_rtx (Pmode);
877 /* ??? We could handle this if we knew that a load from A or B could
878 not fault. This is also true if we've already loaded
879 from the address along the path from ENTRY. */
880 else if (may_trap_p (a) || may_trap_p (b))
883 /* if (test) x = a + b; else x = c - d;
890 code = GET_CODE (if_info->cond);
891 insn_a = if_info->insn_a;
892 insn_b = if_info->insn_b;
894 /* Possibly rearrange operands to make things come out more natural. */
895 if (can_reverse_comparison_p (if_info->cond, if_info->jump))
898 if (rtx_equal_p (b, x))
900 else if (general_operand (b, GET_MODE (b)))
905 code = reverse_condition (code);
906 tmp = a, a = b, b = tmp;
907 tmp = insn_a, insn_a = insn_b, insn_b = tmp;
913 /* If either operand is complex, load it into a register first.
914 The best way to do this is to copy the original insn. In this
915 way we preserve any clobbers etc that the insn may have had.
916 This is of course not possible in the IS_MEM case. */
917 if (! general_operand (a, GET_MODE (a)))
922 goto end_seq_and_fail;
926 tmp = gen_reg_rtx (GET_MODE (a));
927 tmp = emit_insn (gen_rtx_SET (VOIDmode, tmp, a));
930 goto end_seq_and_fail;
933 a = gen_reg_rtx (GET_MODE (a));
934 tmp = copy_rtx (insn_a);
935 set = single_set (tmp);
937 tmp = emit_insn (PATTERN (tmp));
939 if (recog_memoized (tmp) < 0)
940 goto end_seq_and_fail;
942 if (! general_operand (b, GET_MODE (b)))
947 goto end_seq_and_fail;
951 tmp = gen_reg_rtx (GET_MODE (b));
952 tmp = emit_insn (gen_rtx_SET (VOIDmode, tmp, b));
955 goto end_seq_and_fail;
958 b = gen_reg_rtx (GET_MODE (b));
959 tmp = copy_rtx (insn_b);
960 set = single_set (tmp);
962 tmp = emit_insn (PATTERN (tmp));
964 if (recog_memoized (tmp) < 0)
965 goto end_seq_and_fail;
968 target = noce_emit_cmove (if_info, x, code, XEXP (if_info->cond, 0),
969 XEXP (if_info->cond, 1), a, b);
972 goto end_seq_and_fail;
974 /* If we're handling a memory for above, emit the load now. */
977 tmp = gen_rtx_MEM (GET_MODE (if_info->x), target);
979 /* Copy over flags as appropriate. */
980 if (MEM_VOLATILE_P (if_info->a) || MEM_VOLATILE_P (if_info->b))
981 MEM_VOLATILE_P (tmp) = 1;
982 if (MEM_IN_STRUCT_P (if_info->a) && MEM_IN_STRUCT_P (if_info->b))
983 MEM_IN_STRUCT_P (tmp) = 1;
984 if (MEM_SCALAR_P (if_info->a) && MEM_SCALAR_P (if_info->b))
985 MEM_SCALAR_P (tmp) = 1;
986 if (MEM_ALIAS_SET (if_info->a) == MEM_ALIAS_SET (if_info->b))
987 MEM_ALIAS_SET (tmp) = MEM_ALIAS_SET (if_info->a);
989 emit_move_insn (if_info->x, tmp);
991 else if (target != x)
992 emit_move_insn (x, target);
996 emit_insns_before (tmp, if_info->cond_earliest);
1004 /* Look for the condition for the jump first. We'd prefer to avoid
1005 get_condition if we can -- it tries to look back for the contents
1006 of an original compare. On targets that use normal integers for
1007 comparisons, e.g. alpha, this is wasteful. */
1010 noce_get_condition (jump, earliest)
1017 /* If the condition variable is a register and is MODE_INT, accept it.
1018 Otherwise, fall back on get_condition. */
1020 if (! any_condjump_p (jump))
1023 set = pc_set (jump);
1025 cond = XEXP (SET_SRC (set), 0);
1026 if (GET_CODE (XEXP (cond, 0)) == REG
1027 && GET_MODE_CLASS (GET_MODE (XEXP (cond, 0))) == MODE_INT)
1031 /* If this branches to JUMP_LABEL when the condition is false,
1032 reverse the condition. */
1033 if (GET_CODE (XEXP (SET_SRC (set), 2)) == LABEL_REF
1034 && XEXP (XEXP (SET_SRC (set), 2), 0) == JUMP_LABEL (jump))
1035 cond = gen_rtx_fmt_ee (reverse_condition (GET_CODE (cond)),
1036 GET_MODE (cond), XEXP (cond, 0),
1040 cond = get_condition (jump, earliest);
1045 /* Given a simple IF-THEN or IF-THEN-ELSE block, attempt to convert it
1046 without using conditional execution. Return TRUE if we were
1047 successful at converting the the block. */
1050 noce_process_if_block (test_bb, then_bb, else_bb, join_bb)
1051 basic_block test_bb; /* Basic block test is in */
1052 basic_block then_bb; /* Basic block for THEN block */
1053 basic_block else_bb; /* Basic block for ELSE block */
1054 basic_block join_bb; /* Basic block the join label is in */
1056 /* We're looking for patterns of the form
1058 (1) if (...) x = a; else x = b;
1059 (2) x = b; if (...) x = a;
1060 (3) if (...) x = a; // as if with an initial x = x.
1062 The later patterns require jumps to be more expensive.
1064 ??? For future expansion, look for multiple X in such patterns. */
1066 struct noce_if_info if_info;
1069 rtx orig_x, x, a, b;
1070 rtx jump, cond, insn;
1072 /* If this is not a standard conditional jump, we can't parse it. */
1073 jump = test_bb->end;
1074 cond = noce_get_condition (jump, &if_info.cond_earliest);
1078 /* We must be comparing objects whose modes imply the size. */
1079 if (GET_MODE (XEXP (cond, 0)) == BLKmode)
1082 /* Look for one of the potential sets. */
1083 insn_a = first_active_insn (then_bb);
1085 || ! last_active_insn_p (then_bb, insn_a)
1086 || (set_a = single_set (insn_a)) == NULL_RTX)
1089 x = SET_DEST (set_a);
1090 a = SET_SRC (set_a);
1092 /* Look for the other potential set. Make sure we've got equivalent
1094 /* ??? This is overconservative. Storing to two different mems is
1095 as easy as conditionally computing the address. Storing to a
1096 single mem merely requires a scratch memory to use as one of the
1097 destination addresses; often the memory immediately below the
1098 stack pointer is available for this. */
1102 insn_b = first_active_insn (else_bb);
1104 || ! last_active_insn_p (else_bb, insn_b)
1105 || (set_b = single_set (insn_b)) == NULL_RTX
1106 || ! rtx_equal_p (x, SET_DEST (set_b)))
1111 insn_b = prev_nonnote_insn (if_info.cond_earliest);
1113 || GET_CODE (insn_b) != INSN
1114 || (set_b = single_set (insn_b)) == NULL_RTX
1115 || ! rtx_equal_p (x, SET_DEST (set_b))
1116 || reg_mentioned_p (x, cond)
1117 || reg_mentioned_p (x, a)
1118 || reg_mentioned_p (x, SET_SRC (set_b)))
1119 insn_b = set_b = NULL_RTX;
1121 b = (set_b ? SET_SRC (set_b) : x);
1123 /* X may not be mentioned in the range (cond_earliest, jump]. */
1124 for (insn = jump; insn != if_info.cond_earliest; insn = PREV_INSN (insn))
1125 if (INSN_P (insn) && reg_mentioned_p (x, insn))
1128 /* A and B may not be modified in the range [cond_earliest, jump). */
1129 for (insn = if_info.cond_earliest; insn != jump; insn = NEXT_INSN (insn))
1131 && (modified_in_p (a, insn) || modified_in_p (b, insn)))
1134 /* Only operate on register destinations, and even then avoid extending
1135 the lifetime of hard registers on small register class machines. */
1137 if (GET_CODE (x) != REG
1138 || (SMALL_REGISTER_CLASSES
1139 && REGNO (x) < FIRST_PSEUDO_REGISTER))
1143 x = gen_reg_rtx (GET_MODE (x));
1146 /* Don't operate on sources that may trap or are volatile. */
1147 if (side_effects_p (a) || side_effects_p (b)
1148 || (GET_CODE (a) != MEM && may_trap_p (a))
1149 || (GET_CODE (b) != MEM && may_trap_p (b)))
1152 /* Set up the info block for our subroutines. */
1153 if_info.cond = cond;
1154 if_info.jump = jump;
1155 if_info.insn_a = insn_a;
1156 if_info.insn_b = insn_b;
1161 /* Try optimizations in some approximation of a useful order. */
1162 /* ??? Should first look to see if X is live incoming at all. If it
1163 isn't, we don't need anything but an unconditional set. */
1165 /* Look and see if A and B are really the same. Avoid creating silly
1166 cmove constructs that no one will fix up later. */
1167 if (rtx_equal_p (a, b))
1169 /* If we have an INSN_B, we don't have to create any new rtl. Just
1170 move the instruction that we already have. If we don't have an
1171 INSN_B, that means that A == X, and we've got a noop move. In
1172 that case don't do anything and let the code below delete INSN_A. */
1173 if (insn_b && else_bb)
1175 if (else_bb && insn_b == else_bb->end)
1176 else_bb->end = PREV_INSN (insn_b);
1177 reorder_insns (insn_b, insn_b, PREV_INSN (if_info.cond_earliest));
1184 if (noce_try_store_flag (&if_info))
1186 if (HAVE_conditional_move
1187 && noce_try_cmove (&if_info))
1189 if (! HAVE_conditional_execution)
1191 if (noce_try_store_flag_constants (&if_info))
1193 if (noce_try_store_flag_inc (&if_info))
1195 if (noce_try_store_flag_mask (&if_info))
1197 if (HAVE_conditional_move
1198 && noce_try_cmove_arith (&if_info))
1205 /* The original sets may now be killed. */
1206 if (insn_a == then_bb->end)
1207 then_bb->end = PREV_INSN (insn_a);
1208 flow_delete_insn (insn_a);
1210 /* Several special cases here: First, we may have reused insn_b above,
1211 in which case insn_b is now NULL. Second, we want to delete insn_b
1212 if it came from the ELSE block, because follows the now correct
1213 write that appears in the TEST block. However, if we got insn_b from
1214 the TEST block, it may in fact be loading data needed for the comparison.
1215 We'll let life_analysis remove the insn if it's really dead. */
1216 if (insn_b && else_bb)
1218 if (insn_b == else_bb->end)
1219 else_bb->end = PREV_INSN (insn_b);
1220 flow_delete_insn (insn_b);
1223 /* The new insns will have been inserted before cond_earliest. We should
1224 be able to remove the jump with impunity, but the condition itself may
1225 have been modified by gcse to be shared across basic blocks. */
1226 test_bb->end = PREV_INSN (jump);
1227 flow_delete_insn (jump);
1229 /* If we used a temporary, fix it up now. */
1233 emit_move_insn (orig_x, x);
1234 insn_b = gen_sequence ();
1237 test_bb->end = emit_insn_after (insn_b, test_bb->end);
1240 /* Merge the blocks! */
1241 merge_if_block (test_bb, then_bb, else_bb, join_bb);
1246 /* Attempt to convert an IF-THEN or IF-THEN-ELSE block into
1247 straight line code. Return true if successful. */
1250 process_if_block (test_bb, then_bb, else_bb, join_bb)
1251 basic_block test_bb; /* Basic block test is in */
1252 basic_block then_bb; /* Basic block for THEN block */
1253 basic_block else_bb; /* Basic block for ELSE block */
1254 basic_block join_bb; /* Basic block the join label is in */
1256 if (! reload_completed
1257 && noce_process_if_block (test_bb, then_bb, else_bb, join_bb))
1260 if (HAVE_conditional_execution
1262 && cond_exec_process_if_block (test_bb, then_bb, else_bb, join_bb))
1268 /* Merge the blocks and mark for local life update. */
1271 merge_if_block (test_bb, then_bb, else_bb, join_bb)
1272 basic_block test_bb; /* Basic block test is in */
1273 basic_block then_bb; /* Basic block for THEN block */
1274 basic_block else_bb; /* Basic block for ELSE block */
1275 basic_block join_bb; /* Basic block the join label is in */
1277 basic_block combo_bb;
1279 /* All block merging is done into the lower block numbers. */
1283 /* First merge TEST block into THEN block. This is a no-brainer since
1284 the THEN block did not have a code label to begin with. */
1286 if (combo_bb->global_live_at_end)
1287 COPY_REG_SET (combo_bb->global_live_at_end, then_bb->global_live_at_end);
1288 merge_blocks_nomove (combo_bb, then_bb);
1289 num_removed_blocks++;
1291 /* The ELSE block, if it existed, had a label. That label count
1292 will almost always be zero, but odd things can happen when labels
1293 get their addresses taken. */
1296 merge_blocks_nomove (combo_bb, else_bb);
1297 num_removed_blocks++;
1300 /* If there was no join block reported, that means it was not adjacent
1301 to the others, and so we cannot merge them. */
1305 /* The outgoing edge for the current COMBO block should already
1306 be correct. Verify this. */
1307 if (combo_bb->succ == NULL_EDGE)
1310 /* There should sill be a branch at the end of the THEN or ELSE
1311 blocks taking us to our final destination. */
1312 if (! simplejump_p (combo_bb->end)
1313 && ! returnjump_p (combo_bb->end))
1317 /* The JOIN block may have had quite a number of other predecessors too.
1318 Since we've already merged the TEST, THEN and ELSE blocks, we should
1319 have only one remaining edge from our if-then-else diamond. If there
1320 is more than one remaining edge, it must come from elsewhere. */
1321 else if (join_bb->pred->pred_next == NULL)
1323 /* We can merge the JOIN. */
1324 if (combo_bb->global_live_at_end)
1325 COPY_REG_SET (combo_bb->global_live_at_end,
1326 join_bb->global_live_at_end);
1327 merge_blocks_nomove (combo_bb, join_bb);
1328 num_removed_blocks++;
1332 /* We cannot merge the JOIN. */
1334 /* The outgoing edge for the current COMBO block should already
1335 be correct. Verify this. */
1336 if (combo_bb->succ->succ_next != NULL_EDGE
1337 || combo_bb->succ->dest != join_bb)
1340 /* Remove the jump and cruft from the end of the COMBO block. */
1341 tidy_fallthru_edge (combo_bb->succ, combo_bb, join_bb);
1344 /* Make sure we update life info properly. */
1345 SET_UPDATE_LIFE (combo_bb);
1347 num_updated_if_blocks++;
1350 /* Find a block ending in a simple IF condition. Return TRUE if
1351 we were able to transform it in some way. */
1354 find_if_header (test_bb)
1355 basic_block test_bb;
1360 /* The kind of block we're looking for has exactly two successors. */
1361 if ((then_edge = test_bb->succ) == NULL_EDGE
1362 || (else_edge = then_edge->succ_next) == NULL_EDGE
1363 || else_edge->succ_next != NULL_EDGE)
1366 /* Neither edge should be abnormal. */
1367 if ((then_edge->flags & EDGE_COMPLEX)
1368 || (else_edge->flags & EDGE_COMPLEX))
1371 /* The THEN edge is canonically the one that falls through. */
1372 if (then_edge->flags & EDGE_FALLTHRU)
1374 else if (else_edge->flags & EDGE_FALLTHRU)
1377 else_edge = then_edge;
1381 /* Otherwise this must be a multiway branch of some sort. */
1384 if (find_if_block (test_bb, then_edge, else_edge))
1387 && (! HAVE_conditional_execution || reload_completed))
1389 if (find_if_case_1 (test_bb, then_edge, else_edge))
1391 if (find_if_case_2 (test_bb, then_edge, else_edge))
1399 fprintf (rtl_dump_file, "Conversion succeeded.\n");
1403 /* Determine if a given basic block heads a simple IF-THEN or IF-THEN-ELSE
1404 block. If so, we'll try to convert the insns to not require the branch.
1405 Return TRUE if we were successful at converting the the block. */
1408 find_if_block (test_bb, then_edge, else_edge)
1409 basic_block test_bb;
1410 edge then_edge, else_edge;
1412 basic_block then_bb = then_edge->dest;
1413 basic_block else_bb = else_edge->dest;
1414 basic_block join_bb = NULL_BLOCK;
1415 edge then_succ = then_bb->succ;
1416 edge else_succ = else_bb->succ;
1419 /* The THEN block of an IF-THEN combo must have exactly one predecessor. */
1420 if (then_bb->pred->pred_next != NULL_EDGE)
1423 /* The THEN block of an IF-THEN combo must have exactly one successor. */
1424 if (then_succ == NULL_EDGE
1425 || then_succ->succ_next != NULL_EDGE
1426 || (then_succ->flags & EDGE_COMPLEX))
1429 /* If the THEN block's successor is the other edge out of the TEST block,
1430 then we have an IF-THEN combo without an ELSE. */
1431 if (then_succ->dest == else_bb)
1434 else_bb = NULL_BLOCK;
1437 /* If the THEN and ELSE block meet in a subsequent block, and the ELSE
1438 has exactly one predecessor and one successor, and the outgoing edge
1439 is not complex, then we have an IF-THEN-ELSE combo. */
1440 else if (else_succ != NULL_EDGE
1441 && then_succ->dest == else_succ->dest
1442 && else_bb->pred->pred_next == NULL_EDGE
1443 && else_succ->succ_next == NULL_EDGE
1444 && ! (else_succ->flags & EDGE_COMPLEX))
1445 join_bb = else_succ->dest;
1447 /* Otherwise it is not an IF-THEN or IF-THEN-ELSE combination. */
1451 num_possible_if_blocks++;
1456 fprintf (rtl_dump_file,
1457 "\nIF-THEN-ELSE block found, start %d, then %d, else %d, join %d\n",
1458 test_bb->index, then_bb->index, else_bb->index,
1461 fprintf (rtl_dump_file,
1462 "\nIF-THEN block found, start %d, then %d, join %d\n",
1463 test_bb->index, then_bb->index, join_bb->index);
1466 /* Make sure IF, THEN, and ELSE, blocks are adjacent. Actually, we
1467 get the first condition for free, since we've already asserted that
1468 there's a fallthru edge from IF to THEN. */
1469 /* ??? As an enhancement, move the ELSE block. Have to deal with EH and
1470 BLOCK notes, if by no other means than aborting the merge if they
1471 exist. Sticky enough I don't want to think about it now. */
1472 next_index = then_bb->index;
1473 if (else_bb && ++next_index != else_bb->index)
1475 if (++next_index != join_bb->index)
1483 /* Do the real work. */
1484 return process_if_block (test_bb, then_bb, else_bb, join_bb);
1487 /* Look for IF-THEN-ELSE cases in which one of THEN or ELSE is
1488 transformable, but not necessarily the other. There need be no
1491 Return TRUE if we were successful at converting the the block.
1493 Cases we'd like to look at:
1496 if (test) goto over; // x not live
1504 if (! test) goto label;
1507 if (test) goto E; // x not live
1521 (3) // This one's really only interesting for targets that can do
1522 // multiway branching, e.g. IA-64 BBB bundles. For other targets
1523 // it results in multiple branches on a cache line, which often
1524 // does not sit well with predictors.
1526 if (test1) goto E; // predicted not taken
1542 (A) Don't do (2) if the branch is predicted against the block we're
1543 eliminating. Do it anyway if we can eliminate a branch; this requires
1544 that the sole successor of the eliminated block postdominate the other
1547 (B) With CE, on (3) we can steal from both sides of the if, creating
1556 Again, this is most useful if J postdominates.
1558 (C) CE substitutes for helpful life information.
1560 (D) These heuristics need a lot of work. */
1562 /* Tests for case 1 above. */
1565 find_if_case_1 (test_bb, then_edge, else_edge)
1566 basic_block test_bb;
1567 edge then_edge, else_edge;
1569 basic_block then_bb = then_edge->dest;
1570 basic_block else_bb = else_edge->dest;
1571 edge then_succ = then_bb->succ;
1574 /* THEN has one successor. */
1575 if (!then_succ || then_succ->succ_next != NULL)
1578 /* THEN does not fall through, but is not strange either. */
1579 if (then_succ->flags & (EDGE_COMPLEX | EDGE_FALLTHRU))
1582 /* THEN has one predecessor. */
1583 if (then_bb->pred->pred_next != NULL)
1586 /* ELSE follows THEN. (??? could be moved) */
1587 if (else_bb->index != then_bb->index + 1)
1590 num_possible_if_blocks++;
1592 fprintf (rtl_dump_file,
1593 "\nIF-CASE-1 found, start %d, then %d\n",
1594 test_bb->index, then_bb->index);
1596 /* THEN is small. */
1597 if (count_bb_insns (then_bb) > BRANCH_COST)
1600 /* Find the label for THEN's destination. */
1601 if (then_succ->dest == EXIT_BLOCK_PTR)
1605 new_lab = JUMP_LABEL (then_bb->end);
1610 /* Registers set are dead, or are predicable. */
1611 if (! dead_or_predicable (test_bb, then_bb, else_bb, new_lab, 1))
1614 /* Conversion went ok, including moving the insns and fixing up the
1615 jump. Adjust the CFG to match. */
1617 SET_UPDATE_LIFE (test_bb);
1618 bitmap_operation (test_bb->global_live_at_end,
1619 else_bb->global_live_at_start,
1620 then_bb->global_live_at_end, BITMAP_IOR);
1622 make_edge (NULL, test_bb, then_succ->dest, 0);
1623 flow_delete_block (then_bb);
1624 tidy_fallthru_edge (else_edge, test_bb, else_bb);
1626 num_removed_blocks++;
1627 num_updated_if_blocks++;
1632 /* Test for case 2 above. */
1635 find_if_case_2 (test_bb, then_edge, else_edge)
1636 basic_block test_bb;
1637 edge then_edge, else_edge;
1639 basic_block then_bb = then_edge->dest;
1640 basic_block else_bb = else_edge->dest;
1641 edge else_succ = else_bb->succ;
1644 /* ELSE has one successor. */
1645 if (!else_succ || else_succ->succ_next != NULL)
1648 /* ELSE outgoing edge is not complex. */
1649 if (else_succ->flags & EDGE_COMPLEX)
1652 /* ELSE has one predecessor. */
1653 if (else_bb->pred->pred_next != NULL)
1656 /* THEN is not EXIT. */
1657 if (then_bb->index < 0)
1660 /* ELSE is predicted or SUCC(ELSE) postdominates THEN. */
1661 note = find_reg_note (test_bb->end, REG_BR_PROB, NULL_RTX);
1662 if (note && INTVAL (XEXP (note, 0)) >= REG_BR_PROB_BASE / 2)
1664 else if (else_succ->dest->index < 0
1665 || TEST_BIT (post_dominators[ORIG_INDEX (then_bb)],
1666 ORIG_INDEX (else_succ->dest)))
1671 num_possible_if_blocks++;
1673 fprintf (rtl_dump_file,
1674 "\nIF-CASE-2 found, start %d, else %d\n",
1675 test_bb->index, else_bb->index);
1677 /* ELSE is small. */
1678 if (count_bb_insns (then_bb) > BRANCH_COST)
1681 /* Find the label for ELSE's destination. */
1682 if (else_succ->dest == EXIT_BLOCK_PTR)
1686 if (else_succ->flags & EDGE_FALLTHRU)
1688 new_lab = else_succ->dest->head;
1689 if (GET_CODE (new_lab) != CODE_LABEL)
1694 new_lab = JUMP_LABEL (else_bb->end);
1700 /* Registers set are dead, or are predicable. */
1701 if (! dead_or_predicable (test_bb, else_bb, then_bb, new_lab, 0))
1704 /* Conversion went ok, including moving the insns and fixing up the
1705 jump. Adjust the CFG to match. */
1707 SET_UPDATE_LIFE (test_bb);
1708 bitmap_operation (test_bb->global_live_at_end,
1709 then_bb->global_live_at_start,
1710 else_bb->global_live_at_end, BITMAP_IOR);
1712 remove_edge (else_edge);
1713 make_edge (NULL, test_bb, else_succ->dest, 0);
1714 flow_delete_block (else_bb);
1716 num_removed_blocks++;
1717 num_updated_if_blocks++;
1719 /* ??? We may now fallthru from one of THEN's successors into a join
1720 block. Rerun cleanup_cfg? Examine things manually? Wait? */
1725 /* A subroutine of dead_or_predicable called through for_each_rtx.
1726 Return 1 if a memory is found. */
1729 find_memory (px, data)
1731 void *data ATTRIBUTE_UNUSED;
1733 return GET_CODE (*px) == MEM;
1736 /* Used by the code above to perform the actual rtl transformations.
1737 Return TRUE if successful.
1739 TEST_BB is the block containing the conditional branch. MERGE_BB
1740 is the block containing the code to manipulate. NEW_DEST is the
1741 label TEST_BB should be branching to after the conversion.
1742 REVERSEP is true if the sense of the branch should be reversed. */
1745 dead_or_predicable (test_bb, merge_bb, other_bb, new_dest, reversep)
1746 basic_block test_bb, merge_bb, other_bb;
1750 rtx head, end, jump, earliest, old_dest;
1752 jump = test_bb->end;
1754 /* Find the extent of the real code in the merge block. */
1755 head = merge_bb->head;
1756 end = merge_bb->end;
1758 if (GET_CODE (head) == CODE_LABEL)
1759 head = NEXT_INSN (head);
1760 if (GET_CODE (head) == NOTE)
1764 head = end = NULL_RTX;
1767 head = NEXT_INSN (head);
1770 if (GET_CODE (end) == JUMP_INSN)
1774 head = end = NULL_RTX;
1777 end = PREV_INSN (end);
1780 if (HAVE_conditional_execution)
1782 /* In the conditional execution case, we have things easy. We know
1783 the condition is reversable. We don't have to check life info,
1784 becase we're going to conditionally execute the code anyway.
1785 All that's left is making sure the insns involved can actually
1790 cond = cond_exec_get_condition (jump);
1792 prob_val = find_reg_note (jump, REG_BR_PROB, NULL_RTX);
1794 prob_val = XEXP (prob_val, 0);
1798 cond = gen_rtx_fmt_ee (reverse_condition (GET_CODE (cond)),
1799 GET_MODE (cond), XEXP (cond, 0),
1802 prob_val = GEN_INT (REG_BR_PROB_BASE - INTVAL (prob_val));
1805 if (! cond_exec_process_insns (head, end, cond, prob_val, 0))
1812 /* In the non-conditional execution case, we have to verify that there
1813 are no trapping operations, no calls, no references to memory, and
1814 that any registers modified are dead at the branch site. */
1816 rtx insn, cond, prev;
1817 regset_head merge_set_head, tmp_head, test_live_head, test_set_head;
1818 regset merge_set, tmp, test_live, test_set;
1819 struct propagate_block_info *pbi;
1822 /* Check for no calls or trapping operations. */
1823 for (insn = head; ; insn = NEXT_INSN (insn))
1825 if (GET_CODE (insn) == CALL_INSN)
1829 if (may_trap_p (PATTERN (insn)))
1832 /* ??? Even non-trapping memories such as stack frame
1833 references must be avoided. For stores, we collect
1834 no lifetime info; for reads, we'd have to assert
1835 true_dependance false against every store in the
1837 if (for_each_rtx (&PATTERN (insn), find_memory, NULL))
1844 if (! any_condjump_p (jump))
1847 /* Find the extent of the conditional. */
1848 cond = noce_get_condition (jump, &earliest);
1853 MERGE_SET = set of registers set in MERGE_BB
1854 TEST_LIVE = set of registers live at EARLIEST
1855 TEST_SET = set of registers set between EARLIEST and the
1856 end of the block. */
1858 tmp = INITIALIZE_REG_SET (tmp_head);
1859 merge_set = INITIALIZE_REG_SET (merge_set_head);
1860 test_live = INITIALIZE_REG_SET (test_live_head);
1861 test_set = INITIALIZE_REG_SET (test_set_head);
1863 /* ??? bb->local_set is only valid during calculate_global_regs_live,
1864 so we must recompute usage for MERGE_BB. Not so bad, I suppose,
1865 since we've already asserted that MERGE_BB is small. */
1866 propagate_block (merge_bb, tmp, merge_set, 0);
1868 /* For small register class machines, don't lengthen lifetimes of
1869 hard registers before reload. */
1870 if (SMALL_REGISTER_CLASSES && ! reload_completed)
1872 EXECUTE_IF_SET_IN_BITMAP
1875 if (i < FIRST_PSEUDO_REGISTER
1877 && ! global_regs[i])
1882 /* For TEST, we're interested in a range of insns, not a whole block.
1883 Moreover, we're interested in the insns live from OTHER_BB. */
1885 COPY_REG_SET (test_live, other_bb->global_live_at_start);
1886 pbi = init_propagate_block_info (test_bb, test_live, test_set, 0);
1888 for (insn = jump; ; insn = prev)
1890 prev = propagate_one_insn (pbi, insn);
1891 if (insn == earliest)
1895 free_propagate_block_info (pbi);
1897 /* We can perform the transformation if
1898 MERGE_SET & (TEST_SET | TEST_LIVE)
1900 TEST_SET & merge_bb->global_live_at_start
1903 bitmap_operation (tmp, test_set, test_live, BITMAP_IOR);
1904 bitmap_operation (tmp, tmp, merge_set, BITMAP_AND);
1905 EXECUTE_IF_SET_IN_BITMAP(tmp, 0, i, fail = 1);
1907 bitmap_operation (tmp, test_set, merge_bb->global_live_at_start,
1909 EXECUTE_IF_SET_IN_BITMAP(tmp, 0, i, fail = 1);
1912 FREE_REG_SET (merge_set);
1913 FREE_REG_SET (test_live);
1914 FREE_REG_SET (test_set);
1921 /* We don't want to use normal invert_jump or redirect_jump because
1922 we don't want to delete_insn called. Also, we want to do our own
1923 change group management. */
1925 old_dest = JUMP_LABEL (jump);
1927 ? ! invert_jump_1 (jump, new_dest)
1928 : ! redirect_jump_1 (jump, new_dest))
1931 if (! apply_change_group ())
1935 LABEL_NUSES (old_dest) -= 1;
1937 LABEL_NUSES (new_dest) += 1;
1938 JUMP_LABEL (jump) = new_dest;
1942 rtx note = find_reg_note (jump, REG_BR_PROB, NULL_RTX);
1944 XEXP (note, 0) = GEN_INT (REG_BR_PROB_BASE - INTVAL (XEXP (note, 0)));
1947 /* Move the insns out of MERGE_BB to before the branch. */
1950 if (end == merge_bb->end)
1951 merge_bb->end = PREV_INSN (head);
1953 head = squeeze_notes (head, end);
1954 if (GET_CODE (end) == NOTE
1955 && (NOTE_LINE_NUMBER (end) == NOTE_INSN_BLOCK_END
1956 || NOTE_LINE_NUMBER (end) == NOTE_INSN_BLOCK_BEG
1957 || NOTE_LINE_NUMBER (end) == NOTE_INSN_LOOP_BEG
1958 || NOTE_LINE_NUMBER (end) == NOTE_INSN_LOOP_END
1959 || NOTE_LINE_NUMBER (end) == NOTE_INSN_LOOP_CONT
1960 || NOTE_LINE_NUMBER (end) == NOTE_INSN_LOOP_VTOP))
1964 end = PREV_INSN (end);
1967 reorder_insns (head, end, PREV_INSN (earliest));
1976 /* Main entry point for all if-conversion. */
1979 if_convert (life_data_ok)
1984 num_possible_if_blocks = 0;
1985 num_updated_if_blocks = 0;
1986 num_removed_blocks = 0;
1988 /* Free up basic_block_for_insn so that we don't have to keep it
1989 up to date, either here or in merge_blocks_nomove. */
1990 free_basic_block_vars (1);
1992 /* Compute postdominators if we think we'll use them. */
1993 post_dominators = NULL;
1994 if (HAVE_conditional_execution || life_data_ok)
1996 post_dominators = sbitmap_vector_alloc (n_basic_blocks, n_basic_blocks);
1997 compute_flow_dominators (NULL, post_dominators);
2000 /* Record initial block numbers. */
2001 for (block_num = 0; block_num < n_basic_blocks; block_num++)
2002 SET_ORIG_INDEX (BASIC_BLOCK (block_num), block_num);
2004 /* Go through each of the basic blocks looking for things to convert. */
2005 for (block_num = 0; block_num < n_basic_blocks; )
2007 basic_block bb = BASIC_BLOCK (block_num);
2008 if (find_if_header (bb))
2009 block_num = bb->index;
2014 if (post_dominators)
2015 sbitmap_vector_free (post_dominators);
2018 fflush (rtl_dump_file);
2020 /* Rebuild basic_block_for_insn for update_life_info and for gcse. */
2021 compute_bb_for_insn (get_max_uid ());
2023 /* Rebuild life info for basic blocks that require it. */
2024 if (num_removed_blocks && life_data_ok)
2026 sbitmap update_life_blocks = sbitmap_alloc (n_basic_blocks);
2027 sbitmap_zero (update_life_blocks);
2029 /* If we allocated new pseudos, we must resize the array for sched1. */
2030 if (max_regno < max_reg_num ())
2032 max_regno = max_reg_num ();
2033 allocate_reg_info (max_regno, FALSE, FALSE);
2036 for (block_num = 0; block_num < n_basic_blocks; block_num++)
2037 if (UPDATE_LIFE (BASIC_BLOCK (block_num)))
2038 SET_BIT (update_life_blocks, block_num);
2040 count_or_remove_death_notes (update_life_blocks, 1);
2041 /* ??? See about adding a mode that verifies that the initial
2042 set of blocks don't let registers come live. */
2043 update_life_info (update_life_blocks, UPDATE_LIFE_GLOBAL,
2044 PROP_DEATH_NOTES | PROP_SCAN_DEAD_CODE
2045 | PROP_KILL_DEAD_CODE);
2047 sbitmap_free (update_life_blocks);
2050 /* Write the final stats. */
2051 if (rtl_dump_file && num_possible_if_blocks > 0)
2053 fprintf (rtl_dump_file,
2054 "\n%d possible IF blocks searched.\n",
2055 num_possible_if_blocks);
2056 fprintf (rtl_dump_file,
2057 "%d IF blocks converted.\n",
2058 num_updated_if_blocks);
2059 fprintf (rtl_dump_file,
2060 "%d basic blocks deleted.\n\n\n",
2061 num_removed_blocks);
2064 #ifdef ENABLE_CHECKING
2065 verify_flow_info ();