1 /* If-conversion for vectorizer.
2 Copyright (C) 2004-2013 Free Software Foundation, Inc.
3 Contributed by Devang Patel <dpatel@apple.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* This pass implements a tree level if-conversion of loops. Its
22 initial goal is to help the vectorizer to vectorize loops with
25 A short description of if-conversion:
27 o Decide if a loop is if-convertible or not.
28 o Walk all loop basic blocks in breadth first order (BFS order).
29 o Remove conditional statements (at the end of basic block)
30 and propagate condition into destination basic blocks'
32 o Replace modify expression with conditional modify expression
33 using current basic block's condition.
34 o Merge all basic blocks
35 o Replace phi nodes with conditional modify expr
36 o Merge all basic blocks into header
38 Sample transformation:
43 # i_23 = PHI <0(0), i_18(10)>;
46 if (j_15 > 41) goto <L1>; else goto <L17>;
53 # iftmp.2_4 = PHI <0(8), 42(2)>;
57 if (i_18 <= 15) goto <L19>; else goto <L18>;
67 # i_23 = PHI <0(0), i_18(10)>;
72 iftmp.2_4 = j_15 > 41 ? 42 : 0;
75 if (i_18 <= 15) goto <L19>; else goto <L18>;
85 #include "coretypes.h"
89 #include "basic-block.h"
90 #include "gimple-pretty-print.h"
92 #include "gimple-iterator.h"
93 #include "gimple-ssa.h"
95 #include "tree-phinodes.h"
96 #include "ssa-iterators.h"
97 #include "tree-ssanames.h"
98 #include "tree-into-ssa.h"
101 #include "tree-chrec.h"
102 #include "tree-data-ref.h"
103 #include "tree-scalar-evolution.h"
104 #include "tree-pass.h"
107 /* List of basic blocks in if-conversion-suitable order. */
108 static basic_block
*ifc_bbs
;
110 /* Structure used to predicate basic blocks. This is attached to the
111 ->aux field of the BBs in the loop to be if-converted. */
112 typedef struct bb_predicate_s
{
114 /* The condition under which this basic block is executed. */
117 /* PREDICATE is gimplified, and the sequence of statements is
118 recorded here, in order to avoid the duplication of computations
119 that occur in previous conditions. See PR44483. */
120 gimple_seq predicate_gimplified_stmts
;
123 /* Returns true when the basic block BB has a predicate. */
126 bb_has_predicate (basic_block bb
)
128 return bb
->aux
!= NULL
;
131 /* Returns the gimplified predicate for basic block BB. */
134 bb_predicate (basic_block bb
)
136 return ((bb_predicate_p
) bb
->aux
)->predicate
;
139 /* Sets the gimplified predicate COND for basic block BB. */
142 set_bb_predicate (basic_block bb
, tree cond
)
144 gcc_assert ((TREE_CODE (cond
) == TRUTH_NOT_EXPR
145 && is_gimple_condexpr (TREE_OPERAND (cond
, 0)))
146 || is_gimple_condexpr (cond
));
147 ((bb_predicate_p
) bb
->aux
)->predicate
= cond
;
150 /* Returns the sequence of statements of the gimplification of the
151 predicate for basic block BB. */
153 static inline gimple_seq
154 bb_predicate_gimplified_stmts (basic_block bb
)
156 return ((bb_predicate_p
) bb
->aux
)->predicate_gimplified_stmts
;
159 /* Sets the sequence of statements STMTS of the gimplification of the
160 predicate for basic block BB. */
163 set_bb_predicate_gimplified_stmts (basic_block bb
, gimple_seq stmts
)
165 ((bb_predicate_p
) bb
->aux
)->predicate_gimplified_stmts
= stmts
;
168 /* Adds the sequence of statements STMTS to the sequence of statements
169 of the predicate for basic block BB. */
172 add_bb_predicate_gimplified_stmts (basic_block bb
, gimple_seq stmts
)
175 (&(((bb_predicate_p
) bb
->aux
)->predicate_gimplified_stmts
), stmts
);
178 /* Initializes to TRUE the predicate of basic block BB. */
181 init_bb_predicate (basic_block bb
)
183 bb
->aux
= XNEW (struct bb_predicate_s
);
184 set_bb_predicate_gimplified_stmts (bb
, NULL
);
185 set_bb_predicate (bb
, boolean_true_node
);
188 /* Free the predicate of basic block BB. */
191 free_bb_predicate (basic_block bb
)
195 if (!bb_has_predicate (bb
))
198 /* Release the SSA_NAMEs created for the gimplification of the
200 stmts
= bb_predicate_gimplified_stmts (bb
);
203 gimple_stmt_iterator i
;
205 for (i
= gsi_start (stmts
); !gsi_end_p (i
); gsi_next (&i
))
206 free_stmt_operands (gsi_stmt (i
));
213 /* Free the predicate of BB and reinitialize it with the true
217 reset_bb_predicate (basic_block bb
)
219 free_bb_predicate (bb
);
220 init_bb_predicate (bb
);
223 /* Returns a new SSA_NAME of type TYPE that is assigned the value of
224 the expression EXPR. Inserts the statement created for this
225 computation before GSI and leaves the iterator GSI at the same
229 ifc_temp_var (tree type
, tree expr
, gimple_stmt_iterator
*gsi
)
231 tree new_name
= make_temp_ssa_name (type
, NULL
, "_ifc_");
232 gimple stmt
= gimple_build_assign (new_name
, expr
);
233 gsi_insert_before (gsi
, stmt
, GSI_SAME_STMT
);
237 /* Return true when COND is a true predicate. */
240 is_true_predicate (tree cond
)
242 return (cond
== NULL_TREE
243 || cond
== boolean_true_node
244 || integer_onep (cond
));
247 /* Returns true when BB has a predicate that is not trivial: true or
251 is_predicated (basic_block bb
)
253 return !is_true_predicate (bb_predicate (bb
));
256 /* Parses the predicate COND and returns its comparison code and
257 operands OP0 and OP1. */
259 static enum tree_code
260 parse_predicate (tree cond
, tree
*op0
, tree
*op1
)
264 if (TREE_CODE (cond
) == SSA_NAME
265 && is_gimple_assign (s
= SSA_NAME_DEF_STMT (cond
)))
267 if (TREE_CODE_CLASS (gimple_assign_rhs_code (s
)) == tcc_comparison
)
269 *op0
= gimple_assign_rhs1 (s
);
270 *op1
= gimple_assign_rhs2 (s
);
271 return gimple_assign_rhs_code (s
);
274 else if (gimple_assign_rhs_code (s
) == TRUTH_NOT_EXPR
)
276 tree op
= gimple_assign_rhs1 (s
);
277 tree type
= TREE_TYPE (op
);
278 enum tree_code code
= parse_predicate (op
, op0
, op1
);
280 return code
== ERROR_MARK
? ERROR_MARK
281 : invert_tree_comparison (code
, HONOR_NANS (TYPE_MODE (type
)));
287 if (TREE_CODE_CLASS (TREE_CODE (cond
)) == tcc_comparison
)
289 *op0
= TREE_OPERAND (cond
, 0);
290 *op1
= TREE_OPERAND (cond
, 1);
291 return TREE_CODE (cond
);
297 /* Returns the fold of predicate C1 OR C2 at location LOC. */
300 fold_or_predicates (location_t loc
, tree c1
, tree c2
)
302 tree op1a
, op1b
, op2a
, op2b
;
303 enum tree_code code1
= parse_predicate (c1
, &op1a
, &op1b
);
304 enum tree_code code2
= parse_predicate (c2
, &op2a
, &op2b
);
306 if (code1
!= ERROR_MARK
&& code2
!= ERROR_MARK
)
308 tree t
= maybe_fold_or_comparisons (code1
, op1a
, op1b
,
314 return fold_build2_loc (loc
, TRUTH_OR_EXPR
, boolean_type_node
, c1
, c2
);
317 /* Returns true if N is either a constant or a SSA_NAME. */
320 constant_or_ssa_name (tree n
)
322 switch (TREE_CODE (n
))
335 /* Returns either a COND_EXPR or the folded expression if the folded
336 expression is a MIN_EXPR, a MAX_EXPR, an ABS_EXPR,
337 a constant or a SSA_NAME. */
340 fold_build_cond_expr (tree type
, tree cond
, tree rhs
, tree lhs
)
342 tree rhs1
, lhs1
, cond_expr
;
343 cond_expr
= fold_ternary (COND_EXPR
, type
, cond
,
346 if (cond_expr
== NULL_TREE
)
347 return build3 (COND_EXPR
, type
, cond
, rhs
, lhs
);
349 STRIP_USELESS_TYPE_CONVERSION (cond_expr
);
351 if (constant_or_ssa_name (cond_expr
))
354 if (TREE_CODE (cond_expr
) == ABS_EXPR
)
356 rhs1
= TREE_OPERAND (cond_expr
, 1);
357 STRIP_USELESS_TYPE_CONVERSION (rhs1
);
358 if (constant_or_ssa_name (rhs1
))
359 return build1 (ABS_EXPR
, type
, rhs1
);
362 if (TREE_CODE (cond_expr
) == MIN_EXPR
363 || TREE_CODE (cond_expr
) == MAX_EXPR
)
365 lhs1
= TREE_OPERAND (cond_expr
, 0);
366 STRIP_USELESS_TYPE_CONVERSION (lhs1
);
367 rhs1
= TREE_OPERAND (cond_expr
, 1);
368 STRIP_USELESS_TYPE_CONVERSION (rhs1
);
369 if (constant_or_ssa_name (rhs1
)
370 && constant_or_ssa_name (lhs1
))
371 return build2 (TREE_CODE (cond_expr
), type
, lhs1
, rhs1
);
373 return build3 (COND_EXPR
, type
, cond
, rhs
, lhs
);
376 /* Add condition NC to the predicate list of basic block BB. */
379 add_to_predicate_list (basic_block bb
, tree nc
)
383 if (is_true_predicate (nc
))
386 if (!is_predicated (bb
))
390 bc
= bb_predicate (bb
);
391 bc
= fold_or_predicates (EXPR_LOCATION (bc
), nc
, bc
);
392 if (is_true_predicate (bc
))
394 reset_bb_predicate (bb
);
399 /* Allow a TRUTH_NOT_EXPR around the main predicate. */
400 if (TREE_CODE (bc
) == TRUTH_NOT_EXPR
)
401 tp
= &TREE_OPERAND (bc
, 0);
404 if (!is_gimple_condexpr (*tp
))
407 *tp
= force_gimple_operand_1 (*tp
, &stmts
, is_gimple_condexpr
, NULL_TREE
);
408 add_bb_predicate_gimplified_stmts (bb
, stmts
);
410 set_bb_predicate (bb
, bc
);
413 /* Add the condition COND to the previous condition PREV_COND, and add
414 this to the predicate list of the destination of edge E. LOOP is
415 the loop to be if-converted. */
418 add_to_dst_predicate_list (struct loop
*loop
, edge e
,
419 tree prev_cond
, tree cond
)
421 if (!flow_bb_inside_loop_p (loop
, e
->dest
))
424 if (!is_true_predicate (prev_cond
))
425 cond
= fold_build2 (TRUTH_AND_EXPR
, boolean_type_node
,
428 add_to_predicate_list (e
->dest
, cond
);
431 /* Return true if one of the successor edges of BB exits LOOP. */
434 bb_with_exit_edge_p (struct loop
*loop
, basic_block bb
)
439 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
440 if (loop_exit_edge_p (loop
, e
))
446 /* Return true when PHI is if-convertible. PHI is part of loop LOOP
447 and it belongs to basic block BB.
449 PHI is not if-convertible if:
450 - it has more than 2 arguments.
452 When the flag_tree_loop_if_convert_stores is not set, PHI is not
454 - a virtual PHI is immediately used in another PHI node,
455 - there is a virtual PHI in a BB other than the loop->header. */
458 if_convertible_phi_p (struct loop
*loop
, basic_block bb
, gimple phi
)
460 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
462 fprintf (dump_file
, "-------------------------\n");
463 print_gimple_stmt (dump_file
, phi
, 0, TDF_SLIM
);
466 if (bb
!= loop
->header
&& gimple_phi_num_args (phi
) != 2)
468 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
469 fprintf (dump_file
, "More than two phi node args.\n");
473 if (flag_tree_loop_if_convert_stores
)
476 /* When the flag_tree_loop_if_convert_stores is not set, check
477 that there are no memory writes in the branches of the loop to be
479 if (virtual_operand_p (gimple_phi_result (phi
)))
481 imm_use_iterator imm_iter
;
484 if (bb
!= loop
->header
)
486 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
487 fprintf (dump_file
, "Virtual phi not on loop->header.\n");
491 FOR_EACH_IMM_USE_FAST (use_p
, imm_iter
, gimple_phi_result (phi
))
493 if (gimple_code (USE_STMT (use_p
)) == GIMPLE_PHI
)
495 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
496 fprintf (dump_file
, "Difficult to handle this virtual phi.\n");
505 /* Records the status of a data reference. This struct is attached to
506 each DR->aux field. */
509 /* -1 when not initialized, 0 when false, 1 when true. */
510 int written_at_least_once
;
512 /* -1 when not initialized, 0 when false, 1 when true. */
513 int rw_unconditionally
;
516 #define IFC_DR(DR) ((struct ifc_dr *) (DR)->aux)
517 #define DR_WRITTEN_AT_LEAST_ONCE(DR) (IFC_DR (DR)->written_at_least_once)
518 #define DR_RW_UNCONDITIONALLY(DR) (IFC_DR (DR)->rw_unconditionally)
520 /* Returns true when the memory references of STMT are read or written
521 unconditionally. In other words, this function returns true when
522 for every data reference A in STMT there exist other accesses to
523 a data reference with the same base with predicates that add up (OR-up) to
524 the true predicate: this ensures that the data reference A is touched
525 (read or written) on every iteration of the if-converted loop. */
528 memrefs_read_or_written_unconditionally (gimple stmt
,
529 vec
<data_reference_p
> drs
)
532 data_reference_p a
, b
;
533 tree ca
= bb_predicate (gimple_bb (stmt
));
535 for (i
= 0; drs
.iterate (i
, &a
); i
++)
536 if (DR_STMT (a
) == stmt
)
539 int x
= DR_RW_UNCONDITIONALLY (a
);
547 for (j
= 0; drs
.iterate (j
, &b
); j
++)
549 tree ref_base_a
= DR_REF (a
);
550 tree ref_base_b
= DR_REF (b
);
552 if (DR_STMT (b
) == stmt
)
555 while (TREE_CODE (ref_base_a
) == COMPONENT_REF
556 || TREE_CODE (ref_base_a
) == IMAGPART_EXPR
557 || TREE_CODE (ref_base_a
) == REALPART_EXPR
)
558 ref_base_a
= TREE_OPERAND (ref_base_a
, 0);
560 while (TREE_CODE (ref_base_b
) == COMPONENT_REF
561 || TREE_CODE (ref_base_b
) == IMAGPART_EXPR
562 || TREE_CODE (ref_base_b
) == REALPART_EXPR
)
563 ref_base_b
= TREE_OPERAND (ref_base_b
, 0);
565 if (!operand_equal_p (ref_base_a
, ref_base_b
, 0))
567 tree cb
= bb_predicate (gimple_bb (DR_STMT (b
)));
569 if (DR_RW_UNCONDITIONALLY (b
) == 1
570 || is_true_predicate (cb
)
571 || is_true_predicate (ca
572 = fold_or_predicates (EXPR_LOCATION (cb
), ca
, cb
)))
574 DR_RW_UNCONDITIONALLY (a
) = 1;
575 DR_RW_UNCONDITIONALLY (b
) = 1;
584 DR_RW_UNCONDITIONALLY (a
) = 0;
592 /* Returns true when the memory references of STMT are unconditionally
593 written. In other words, this function returns true when for every
594 data reference A written in STMT, there exist other writes to the
595 same data reference with predicates that add up (OR-up) to the true
596 predicate: this ensures that the data reference A is written on
597 every iteration of the if-converted loop. */
600 write_memrefs_written_at_least_once (gimple stmt
,
601 vec
<data_reference_p
> drs
)
604 data_reference_p a
, b
;
605 tree ca
= bb_predicate (gimple_bb (stmt
));
607 for (i
= 0; drs
.iterate (i
, &a
); i
++)
608 if (DR_STMT (a
) == stmt
612 int x
= DR_WRITTEN_AT_LEAST_ONCE (a
);
620 for (j
= 0; drs
.iterate (j
, &b
); j
++)
621 if (DR_STMT (b
) != stmt
623 && same_data_refs_base_objects (a
, b
))
625 tree cb
= bb_predicate (gimple_bb (DR_STMT (b
)));
627 if (DR_WRITTEN_AT_LEAST_ONCE (b
) == 1
628 || is_true_predicate (cb
)
629 || is_true_predicate (ca
= fold_or_predicates (EXPR_LOCATION (cb
),
632 DR_WRITTEN_AT_LEAST_ONCE (a
) = 1;
633 DR_WRITTEN_AT_LEAST_ONCE (b
) = 1;
641 DR_WRITTEN_AT_LEAST_ONCE (a
) = 0;
649 /* Return true when the memory references of STMT won't trap in the
650 if-converted code. There are two things that we have to check for:
652 - writes to memory occur to writable memory: if-conversion of
653 memory writes transforms the conditional memory writes into
654 unconditional writes, i.e. "if (cond) A[i] = foo" is transformed
655 into "A[i] = cond ? foo : A[i]", and as the write to memory may not
656 be executed at all in the original code, it may be a readonly
657 memory. To check that A is not const-qualified, we check that
658 there exists at least an unconditional write to A in the current
661 - reads or writes to memory are valid memory accesses for every
662 iteration. To check that the memory accesses are correctly formed
663 and that we are allowed to read and write in these locations, we
664 check that the memory accesses to be if-converted occur at every
665 iteration unconditionally. */
668 ifcvt_memrefs_wont_trap (gimple stmt
, vec
<data_reference_p
> refs
)
670 return write_memrefs_written_at_least_once (stmt
, refs
)
671 && memrefs_read_or_written_unconditionally (stmt
, refs
);
674 /* Wrapper around gimple_could_trap_p refined for the needs of the
675 if-conversion. Try to prove that the memory accesses of STMT could
676 not trap in the innermost loop containing STMT. */
679 ifcvt_could_trap_p (gimple stmt
, vec
<data_reference_p
> refs
)
681 if (gimple_vuse (stmt
)
682 && !gimple_could_trap_p_1 (stmt
, false, false)
683 && ifcvt_memrefs_wont_trap (stmt
, refs
))
686 return gimple_could_trap_p (stmt
);
689 /* Return true when STMT is if-convertible.
691 GIMPLE_ASSIGN statement is not if-convertible if,
694 - LHS is not var decl. */
697 if_convertible_gimple_assign_stmt_p (gimple stmt
,
698 vec
<data_reference_p
> refs
)
700 tree lhs
= gimple_assign_lhs (stmt
);
703 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
705 fprintf (dump_file
, "-------------------------\n");
706 print_gimple_stmt (dump_file
, stmt
, 0, TDF_SLIM
);
709 if (!is_gimple_reg_type (TREE_TYPE (lhs
)))
712 /* Some of these constrains might be too conservative. */
713 if (stmt_ends_bb_p (stmt
)
714 || gimple_has_volatile_ops (stmt
)
715 || (TREE_CODE (lhs
) == SSA_NAME
716 && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs
))
717 || gimple_has_side_effects (stmt
))
719 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
720 fprintf (dump_file
, "stmt not suitable for ifcvt\n");
724 if (flag_tree_loop_if_convert_stores
)
726 if (ifcvt_could_trap_p (stmt
, refs
))
728 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
729 fprintf (dump_file
, "tree could trap...\n");
735 if (gimple_assign_rhs_could_trap_p (stmt
))
737 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
738 fprintf (dump_file
, "tree could trap...\n");
742 bb
= gimple_bb (stmt
);
744 if (TREE_CODE (lhs
) != SSA_NAME
745 && bb
!= bb
->loop_father
->header
746 && !bb_with_exit_edge_p (bb
->loop_father
, bb
))
748 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
750 fprintf (dump_file
, "LHS is not var\n");
751 print_gimple_stmt (dump_file
, stmt
, 0, TDF_SLIM
);
759 /* Return true when STMT is if-convertible.
761 A statement is if-convertible if:
762 - it is an if-convertible GIMPLE_ASSIGN,
763 - it is a GIMPLE_LABEL or a GIMPLE_COND. */
766 if_convertible_stmt_p (gimple stmt
, vec
<data_reference_p
> refs
)
768 switch (gimple_code (stmt
))
776 return if_convertible_gimple_assign_stmt_p (stmt
, refs
);
780 tree fndecl
= gimple_call_fndecl (stmt
);
783 int flags
= gimple_call_flags (stmt
);
784 if ((flags
& ECF_CONST
)
785 && !(flags
& ECF_LOOPING_CONST_OR_PURE
)
786 /* We can only vectorize some builtins at the moment,
787 so restrict if-conversion to those. */
788 && DECL_BUILT_IN (fndecl
))
795 /* Don't know what to do with 'em so don't do anything. */
796 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
798 fprintf (dump_file
, "don't know what to do\n");
799 print_gimple_stmt (dump_file
, stmt
, 0, TDF_SLIM
);
808 /* Return true when BB is if-convertible. This routine does not check
809 basic block's statements and phis.
811 A basic block is not if-convertible if:
812 - it is non-empty and it is after the exit block (in BFS order),
813 - it is after the exit block but before the latch,
814 - its edges are not normal.
816 EXIT_BB is the basic block containing the exit of the LOOP. BB is
820 if_convertible_bb_p (struct loop
*loop
, basic_block bb
, basic_block exit_bb
)
825 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
826 fprintf (dump_file
, "----------[%d]-------------\n", bb
->index
);
828 if (EDGE_COUNT (bb
->preds
) > 2
829 || EDGE_COUNT (bb
->succs
) > 2)
834 if (bb
!= loop
->latch
)
836 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
837 fprintf (dump_file
, "basic block after exit bb but before latch\n");
840 else if (!empty_block_p (bb
))
842 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
843 fprintf (dump_file
, "non empty basic block after exit bb\n");
846 else if (bb
== loop
->latch
848 && !dominated_by_p (CDI_DOMINATORS
, bb
, exit_bb
))
850 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
851 fprintf (dump_file
, "latch is not dominated by exit_block\n");
856 /* Be less adventurous and handle only normal edges. */
857 FOR_EACH_EDGE (e
, ei
, bb
->succs
)
858 if (e
->flags
& (EDGE_EH
| EDGE_ABNORMAL
| EDGE_IRREDUCIBLE_LOOP
))
860 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
861 fprintf (dump_file
, "Difficult to handle edges\n");
865 /* At least one incoming edge has to be non-critical as otherwise edge
866 predicates are not equal to basic-block predicates of the edge
868 if (EDGE_COUNT (bb
->preds
) > 1
869 && bb
!= loop
->header
)
872 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
873 if (EDGE_COUNT (e
->src
->succs
) == 1)
877 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
878 fprintf (dump_file
, "only critical predecessors\n");
886 /* Return true when all predecessor blocks of BB are visited. The
887 VISITED bitmap keeps track of the visited blocks. */
890 pred_blocks_visited_p (basic_block bb
, bitmap
*visited
)
894 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
895 if (!bitmap_bit_p (*visited
, e
->src
->index
))
901 /* Get body of a LOOP in suitable order for if-conversion. It is
902 caller's responsibility to deallocate basic block list.
903 If-conversion suitable order is, breadth first sort (BFS) order
904 with an additional constraint: select a block only if all its
905 predecessors are already selected. */
908 get_loop_body_in_if_conv_order (const struct loop
*loop
)
910 basic_block
*blocks
, *blocks_in_bfs_order
;
913 unsigned int index
= 0;
914 unsigned int visited_count
= 0;
916 gcc_assert (loop
->num_nodes
);
917 gcc_assert (loop
->latch
!= EXIT_BLOCK_PTR
);
919 blocks
= XCNEWVEC (basic_block
, loop
->num_nodes
);
920 visited
= BITMAP_ALLOC (NULL
);
922 blocks_in_bfs_order
= get_loop_body_in_bfs_order (loop
);
925 while (index
< loop
->num_nodes
)
927 bb
= blocks_in_bfs_order
[index
];
929 if (bb
->flags
& BB_IRREDUCIBLE_LOOP
)
931 free (blocks_in_bfs_order
);
932 BITMAP_FREE (visited
);
937 if (!bitmap_bit_p (visited
, bb
->index
))
939 if (pred_blocks_visited_p (bb
, &visited
)
940 || bb
== loop
->header
)
942 /* This block is now visited. */
943 bitmap_set_bit (visited
, bb
->index
);
944 blocks
[visited_count
++] = bb
;
950 if (index
== loop
->num_nodes
951 && visited_count
!= loop
->num_nodes
)
955 free (blocks_in_bfs_order
);
956 BITMAP_FREE (visited
);
960 /* Returns true when the analysis of the predicates for all the basic
961 blocks in LOOP succeeded.
963 predicate_bbs first allocates the predicates of the basic blocks.
964 These fields are then initialized with the tree expressions
965 representing the predicates under which a basic block is executed
966 in the LOOP. As the loop->header is executed at each iteration, it
967 has the "true" predicate. Other statements executed under a
968 condition are predicated with that condition, for example
975 S1 will be predicated with "x", and
976 S2 will be predicated with "!x". */
979 predicate_bbs (loop_p loop
)
983 for (i
= 0; i
< loop
->num_nodes
; i
++)
984 init_bb_predicate (ifc_bbs
[i
]);
986 for (i
= 0; i
< loop
->num_nodes
; i
++)
988 basic_block bb
= ifc_bbs
[i
];
990 gimple_stmt_iterator itr
;
992 /* The loop latch is always executed and has no extra conditions
993 to be processed: skip it. */
994 if (bb
== loop
->latch
)
996 reset_bb_predicate (loop
->latch
);
1000 cond
= bb_predicate (bb
);
1002 for (itr
= gsi_start_bb (bb
); !gsi_end_p (itr
); gsi_next (&itr
))
1004 gimple stmt
= gsi_stmt (itr
);
1006 switch (gimple_code (stmt
))
1017 edge true_edge
, false_edge
;
1018 location_t loc
= gimple_location (stmt
);
1019 tree c
= fold_build2_loc (loc
, gimple_cond_code (stmt
),
1021 gimple_cond_lhs (stmt
),
1022 gimple_cond_rhs (stmt
));
1024 /* Add new condition into destination's predicate list. */
1025 extract_true_false_edges_from_block (gimple_bb (stmt
),
1026 &true_edge
, &false_edge
);
1028 /* If C is true, then TRUE_EDGE is taken. */
1029 add_to_dst_predicate_list (loop
, true_edge
,
1030 unshare_expr (cond
),
1033 /* If C is false, then FALSE_EDGE is taken. */
1034 c2
= build1_loc (loc
, TRUTH_NOT_EXPR
,
1035 boolean_type_node
, unshare_expr (c
));
1036 add_to_dst_predicate_list (loop
, false_edge
,
1037 unshare_expr (cond
), c2
);
1044 /* Not handled yet in if-conversion. */
1049 /* If current bb has only one successor, then consider it as an
1050 unconditional goto. */
1051 if (single_succ_p (bb
))
1053 basic_block bb_n
= single_succ (bb
);
1055 /* The successor bb inherits the predicate of its
1056 predecessor. If there is no predicate in the predecessor
1057 bb, then consider the successor bb as always executed. */
1058 if (cond
== NULL_TREE
)
1059 cond
= boolean_true_node
;
1061 add_to_predicate_list (bb_n
, cond
);
1065 /* The loop header is always executed. */
1066 reset_bb_predicate (loop
->header
);
1067 gcc_assert (bb_predicate_gimplified_stmts (loop
->header
) == NULL
1068 && bb_predicate_gimplified_stmts (loop
->latch
) == NULL
);
1073 /* Return true when LOOP is if-convertible. This is a helper function
1074 for if_convertible_loop_p. REFS and DDRS are initialized and freed
1075 in if_convertible_loop_p. */
1078 if_convertible_loop_p_1 (struct loop
*loop
,
1079 vec
<loop_p
> *loop_nest
,
1080 vec
<data_reference_p
> *refs
,
1085 basic_block exit_bb
= NULL
;
1087 /* Don't if-convert the loop when the data dependences cannot be
1088 computed: the loop won't be vectorized in that case. */
1089 res
= compute_data_dependences_for_loop (loop
, true, loop_nest
, refs
, ddrs
);
1093 calculate_dominance_info (CDI_DOMINATORS
);
1095 /* Allow statements that can be handled during if-conversion. */
1096 ifc_bbs
= get_loop_body_in_if_conv_order (loop
);
1099 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1100 fprintf (dump_file
, "Irreducible loop\n");
1104 for (i
= 0; i
< loop
->num_nodes
; i
++)
1106 basic_block bb
= ifc_bbs
[i
];
1108 if (!if_convertible_bb_p (loop
, bb
, exit_bb
))
1111 if (bb_with_exit_edge_p (loop
, bb
))
1115 res
= predicate_bbs (loop
);
1119 if (flag_tree_loop_if_convert_stores
)
1121 data_reference_p dr
;
1123 for (i
= 0; refs
->iterate (i
, &dr
); i
++)
1125 dr
->aux
= XNEW (struct ifc_dr
);
1126 DR_WRITTEN_AT_LEAST_ONCE (dr
) = -1;
1127 DR_RW_UNCONDITIONALLY (dr
) = -1;
1131 for (i
= 0; i
< loop
->num_nodes
; i
++)
1133 basic_block bb
= ifc_bbs
[i
];
1134 gimple_stmt_iterator itr
;
1136 for (itr
= gsi_start_phis (bb
); !gsi_end_p (itr
); gsi_next (&itr
))
1137 if (!if_convertible_phi_p (loop
, bb
, gsi_stmt (itr
)))
1140 /* Check the if-convertibility of statements in predicated BBs. */
1141 if (is_predicated (bb
))
1142 for (itr
= gsi_start_bb (bb
); !gsi_end_p (itr
); gsi_next (&itr
))
1143 if (!if_convertible_stmt_p (gsi_stmt (itr
), *refs
))
1148 fprintf (dump_file
, "Applying if-conversion\n");
1153 /* Return true when LOOP is if-convertible.
1154 LOOP is if-convertible if:
1156 - it has two or more basic blocks,
1157 - it has only one exit,
1158 - loop header is not the exit edge,
1159 - if its basic blocks and phi nodes are if convertible. */
1162 if_convertible_loop_p (struct loop
*loop
)
1167 vec
<data_reference_p
> refs
;
1170 /* Handle only innermost loop. */
1171 if (!loop
|| loop
->inner
)
1173 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1174 fprintf (dump_file
, "not innermost loop\n");
1178 /* If only one block, no need for if-conversion. */
1179 if (loop
->num_nodes
<= 2)
1181 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1182 fprintf (dump_file
, "less than 2 basic blocks\n");
1186 /* More than one loop exit is too much to handle. */
1187 if (!single_exit (loop
))
1189 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1190 fprintf (dump_file
, "multiple exits\n");
1194 /* If one of the loop header's edge is an exit edge then do not
1195 apply if-conversion. */
1196 FOR_EACH_EDGE (e
, ei
, loop
->header
->succs
)
1197 if (loop_exit_edge_p (loop
, e
))
1202 stack_vec
<loop_p
, 3> loop_nest
;
1203 res
= if_convertible_loop_p_1 (loop
, &loop_nest
, &refs
, &ddrs
);
1205 if (flag_tree_loop_if_convert_stores
)
1207 data_reference_p dr
;
1210 for (i
= 0; refs
.iterate (i
, &dr
); i
++)
1214 loop_nest
.release ();
1215 free_data_refs (refs
);
1216 free_dependence_relations (ddrs
);
1220 /* Basic block BB has two predecessors. Using predecessor's bb
1221 predicate, set an appropriate condition COND for the PHI node
1222 replacement. Return the true block whose phi arguments are
1223 selected when cond is true. LOOP is the loop containing the
1224 if-converted region, GSI is the place to insert the code for the
1228 find_phi_replacement_condition (basic_block bb
, tree
*cond
,
1229 gimple_stmt_iterator
*gsi
)
1231 edge first_edge
, second_edge
;
1234 gcc_assert (EDGE_COUNT (bb
->preds
) == 2);
1235 first_edge
= EDGE_PRED (bb
, 0);
1236 second_edge
= EDGE_PRED (bb
, 1);
1238 /* Prefer an edge with a not negated predicate.
1239 ??? That's a very weak cost model. */
1240 tmp_cond
= bb_predicate (first_edge
->src
);
1241 gcc_assert (tmp_cond
);
1242 if (TREE_CODE (tmp_cond
) == TRUTH_NOT_EXPR
)
1246 tmp_edge
= first_edge
;
1247 first_edge
= second_edge
;
1248 second_edge
= tmp_edge
;
1251 /* Check if the edge we take the condition from is not critical.
1252 We know that at least one non-critical edge exists. */
1253 if (EDGE_COUNT (first_edge
->src
->succs
) > 1)
1255 *cond
= bb_predicate (second_edge
->src
);
1257 if (TREE_CODE (*cond
) == TRUTH_NOT_EXPR
)
1258 *cond
= TREE_OPERAND (*cond
, 0);
1260 /* Select non loop header bb. */
1261 first_edge
= second_edge
;
1264 *cond
= bb_predicate (first_edge
->src
);
1266 /* Gimplify the condition to a valid cond-expr conditonal operand. */
1267 *cond
= force_gimple_operand_gsi_1 (gsi
, unshare_expr (*cond
),
1268 is_gimple_condexpr
, NULL_TREE
,
1269 true, GSI_SAME_STMT
);
1271 return first_edge
->src
;
1274 /* Replace a scalar PHI node with a COND_EXPR using COND as condition.
1275 This routine does not handle PHI nodes with more than two
1279 S1: A = PHI <x1(1), x2(5)>
1281 S2: A = cond ? x1 : x2;
1283 The generated code is inserted at GSI that points to the top of
1284 basic block's statement list. When COND is true, phi arg from
1285 TRUE_BB is selected. */
1288 predicate_scalar_phi (gimple phi
, tree cond
,
1289 basic_block true_bb
,
1290 gimple_stmt_iterator
*gsi
)
1294 tree rhs
, res
, arg
, scev
;
1296 gcc_assert (gimple_code (phi
) == GIMPLE_PHI
1297 && gimple_phi_num_args (phi
) == 2);
1299 res
= gimple_phi_result (phi
);
1300 /* Do not handle virtual phi nodes. */
1301 if (virtual_operand_p (res
))
1304 bb
= gimple_bb (phi
);
1306 if ((arg
= degenerate_phi_result (phi
))
1307 || ((scev
= analyze_scalar_evolution (gimple_bb (phi
)->loop_father
,
1309 && !chrec_contains_undetermined (scev
)
1311 && (arg
= gimple_phi_arg_def (phi
, 0))))
1316 /* Use condition that is not TRUTH_NOT_EXPR in conditional modify expr. */
1317 if (EDGE_PRED (bb
, 1)->src
== true_bb
)
1319 arg_0
= gimple_phi_arg_def (phi
, 1);
1320 arg_1
= gimple_phi_arg_def (phi
, 0);
1324 arg_0
= gimple_phi_arg_def (phi
, 0);
1325 arg_1
= gimple_phi_arg_def (phi
, 1);
1328 /* Build new RHS using selected condition and arguments. */
1329 rhs
= fold_build_cond_expr (TREE_TYPE (res
), unshare_expr (cond
),
1333 new_stmt
= gimple_build_assign (res
, rhs
);
1334 gsi_insert_before (gsi
, new_stmt
, GSI_SAME_STMT
);
1335 update_stmt (new_stmt
);
1337 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1339 fprintf (dump_file
, "new phi replacement stmt\n");
1340 print_gimple_stmt (dump_file
, new_stmt
, 0, TDF_SLIM
);
1344 /* Replaces in LOOP all the scalar phi nodes other than those in the
1345 LOOP->header block with conditional modify expressions. */
1348 predicate_all_scalar_phis (struct loop
*loop
)
1351 unsigned int orig_loop_num_nodes
= loop
->num_nodes
;
1354 for (i
= 1; i
< orig_loop_num_nodes
; i
++)
1357 tree cond
= NULL_TREE
;
1358 gimple_stmt_iterator gsi
, phi_gsi
;
1359 basic_block true_bb
= NULL
;
1362 if (bb
== loop
->header
)
1365 phi_gsi
= gsi_start_phis (bb
);
1366 if (gsi_end_p (phi_gsi
))
1369 /* BB has two predecessors. Using predecessor's aux field, set
1370 appropriate condition for the PHI node replacement. */
1371 gsi
= gsi_after_labels (bb
);
1372 true_bb
= find_phi_replacement_condition (bb
, &cond
, &gsi
);
1374 while (!gsi_end_p (phi_gsi
))
1376 phi
= gsi_stmt (phi_gsi
);
1377 predicate_scalar_phi (phi
, cond
, true_bb
, &gsi
);
1378 release_phi_node (phi
);
1379 gsi_next (&phi_gsi
);
1382 set_phi_nodes (bb
, NULL
);
1386 /* Insert in each basic block of LOOP the statements produced by the
1387 gimplification of the predicates. */
1390 insert_gimplified_predicates (loop_p loop
)
1394 for (i
= 0; i
< loop
->num_nodes
; i
++)
1396 basic_block bb
= ifc_bbs
[i
];
1399 if (!is_predicated (bb
))
1401 /* Do not insert statements for a basic block that is not
1402 predicated. Also make sure that the predicate of the
1403 basic block is set to true. */
1404 reset_bb_predicate (bb
);
1408 stmts
= bb_predicate_gimplified_stmts (bb
);
1411 if (flag_tree_loop_if_convert_stores
)
1413 /* Insert the predicate of the BB just after the label,
1414 as the if-conversion of memory writes will use this
1416 gimple_stmt_iterator gsi
= gsi_after_labels (bb
);
1417 gsi_insert_seq_before (&gsi
, stmts
, GSI_SAME_STMT
);
1421 /* Insert the predicate of the BB at the end of the BB
1422 as this would reduce the register pressure: the only
1423 use of this predicate will be in successor BBs. */
1424 gimple_stmt_iterator gsi
= gsi_last_bb (bb
);
1427 || stmt_ends_bb_p (gsi_stmt (gsi
)))
1428 gsi_insert_seq_before (&gsi
, stmts
, GSI_SAME_STMT
);
1430 gsi_insert_seq_after (&gsi
, stmts
, GSI_SAME_STMT
);
1433 /* Once the sequence is code generated, set it to NULL. */
1434 set_bb_predicate_gimplified_stmts (bb
, NULL
);
1439 /* Predicate each write to memory in LOOP.
1441 This function transforms control flow constructs containing memory
1444 | for (i = 0; i < N; i++)
1448 into the following form that does not contain control flow:
1450 | for (i = 0; i < N; i++)
1451 | A[i] = cond ? expr : A[i];
1453 The original CFG looks like this:
1460 | if (i < N) goto bb_5 else goto bb_2
1464 | cond = some_computation;
1465 | if (cond) goto bb_3 else goto bb_4
1477 insert_gimplified_predicates inserts the computation of the COND
1478 expression at the beginning of the destination basic block:
1485 | if (i < N) goto bb_5 else goto bb_2
1489 | cond = some_computation;
1490 | if (cond) goto bb_3 else goto bb_4
1494 | cond = some_computation;
1503 predicate_mem_writes is then predicating the memory write as follows:
1510 | if (i < N) goto bb_5 else goto bb_2
1514 | if (cond) goto bb_3 else goto bb_4
1518 | cond = some_computation;
1519 | A[i] = cond ? expr : A[i];
1527 and finally combine_blocks removes the basic block boundaries making
1528 the loop vectorizable:
1532 | if (i < N) goto bb_5 else goto bb_1
1536 | cond = some_computation;
1537 | A[i] = cond ? expr : A[i];
1538 | if (i < N) goto bb_5 else goto bb_4
1547 predicate_mem_writes (loop_p loop
)
1549 unsigned int i
, orig_loop_num_nodes
= loop
->num_nodes
;
1551 for (i
= 1; i
< orig_loop_num_nodes
; i
++)
1553 gimple_stmt_iterator gsi
;
1554 basic_block bb
= ifc_bbs
[i
];
1555 tree cond
= bb_predicate (bb
);
1559 if (is_true_predicate (cond
))
1563 if (TREE_CODE (cond
) == TRUTH_NOT_EXPR
)
1566 cond
= TREE_OPERAND (cond
, 0);
1569 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1570 if ((stmt
= gsi_stmt (gsi
))
1571 && gimple_assign_single_p (stmt
)
1572 && gimple_vdef (stmt
))
1574 tree lhs
= gimple_assign_lhs (stmt
);
1575 tree rhs
= gimple_assign_rhs1 (stmt
);
1576 tree type
= TREE_TYPE (lhs
);
1578 lhs
= ifc_temp_var (type
, unshare_expr (lhs
), &gsi
);
1579 rhs
= ifc_temp_var (type
, unshare_expr (rhs
), &gsi
);
1586 cond
= force_gimple_operand_gsi_1 (&gsi
, unshare_expr (cond
),
1587 is_gimple_condexpr
, NULL_TREE
,
1588 true, GSI_SAME_STMT
);
1589 rhs
= fold_build_cond_expr (type
, unshare_expr (cond
), rhs
, lhs
);
1590 gimple_assign_set_rhs1 (stmt
, ifc_temp_var (type
, rhs
, &gsi
));
1596 /* Remove all GIMPLE_CONDs and GIMPLE_LABELs of all the basic blocks
1597 other than the exit and latch of the LOOP. Also resets the
1598 GIMPLE_DEBUG information. */
1601 remove_conditions_and_labels (loop_p loop
)
1603 gimple_stmt_iterator gsi
;
1606 for (i
= 0; i
< loop
->num_nodes
; i
++)
1608 basic_block bb
= ifc_bbs
[i
];
1610 if (bb_with_exit_edge_p (loop
, bb
)
1611 || bb
== loop
->latch
)
1614 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); )
1615 switch (gimple_code (gsi_stmt (gsi
)))
1619 gsi_remove (&gsi
, true);
1623 /* ??? Should there be conditional GIMPLE_DEBUG_BINDs? */
1624 if (gimple_debug_bind_p (gsi_stmt (gsi
)))
1626 gimple_debug_bind_reset_value (gsi_stmt (gsi
));
1627 update_stmt (gsi_stmt (gsi
));
1638 /* Combine all the basic blocks from LOOP into one or two super basic
1639 blocks. Replace PHI nodes with conditional modify expressions. */
1642 combine_blocks (struct loop
*loop
)
1644 basic_block bb
, exit_bb
, merge_target_bb
;
1645 unsigned int orig_loop_num_nodes
= loop
->num_nodes
;
1650 remove_conditions_and_labels (loop
);
1651 insert_gimplified_predicates (loop
);
1652 predicate_all_scalar_phis (loop
);
1654 if (flag_tree_loop_if_convert_stores
)
1655 predicate_mem_writes (loop
);
1657 /* Merge basic blocks: first remove all the edges in the loop,
1658 except for those from the exit block. */
1660 for (i
= 0; i
< orig_loop_num_nodes
; i
++)
1663 free_bb_predicate (bb
);
1664 if (bb_with_exit_edge_p (loop
, bb
))
1666 gcc_assert (exit_bb
== NULL
);
1670 gcc_assert (exit_bb
!= loop
->latch
);
1672 for (i
= 1; i
< orig_loop_num_nodes
; i
++)
1676 for (ei
= ei_start (bb
->preds
); (e
= ei_safe_edge (ei
));)
1678 if (e
->src
== exit_bb
)
1685 if (exit_bb
!= NULL
)
1687 if (exit_bb
!= loop
->header
)
1689 /* Connect this node to loop header. */
1690 make_edge (loop
->header
, exit_bb
, EDGE_FALLTHRU
);
1691 set_immediate_dominator (CDI_DOMINATORS
, exit_bb
, loop
->header
);
1694 /* Redirect non-exit edges to loop->latch. */
1695 FOR_EACH_EDGE (e
, ei
, exit_bb
->succs
)
1697 if (!loop_exit_edge_p (loop
, e
))
1698 redirect_edge_and_branch (e
, loop
->latch
);
1700 set_immediate_dominator (CDI_DOMINATORS
, loop
->latch
, exit_bb
);
1704 /* If the loop does not have an exit, reconnect header and latch. */
1705 make_edge (loop
->header
, loop
->latch
, EDGE_FALLTHRU
);
1706 set_immediate_dominator (CDI_DOMINATORS
, loop
->latch
, loop
->header
);
1709 merge_target_bb
= loop
->header
;
1710 for (i
= 1; i
< orig_loop_num_nodes
; i
++)
1712 gimple_stmt_iterator gsi
;
1713 gimple_stmt_iterator last
;
1717 if (bb
== exit_bb
|| bb
== loop
->latch
)
1720 /* Make stmts member of loop->header. */
1721 for (gsi
= gsi_start_bb (bb
); !gsi_end_p (gsi
); gsi_next (&gsi
))
1722 gimple_set_bb (gsi_stmt (gsi
), merge_target_bb
);
1724 /* Update stmt list. */
1725 last
= gsi_last_bb (merge_target_bb
);
1726 gsi_insert_seq_after (&last
, bb_seq (bb
), GSI_NEW_STMT
);
1727 set_bb_seq (bb
, NULL
);
1729 delete_basic_block (bb
);
1732 /* If possible, merge loop header to the block with the exit edge.
1733 This reduces the number of basic blocks to two, to please the
1734 vectorizer that handles only loops with two nodes. */
1736 && exit_bb
!= loop
->header
1737 && can_merge_blocks_p (loop
->header
, exit_bb
))
1738 merge_blocks (loop
->header
, exit_bb
);
1744 /* If-convert LOOP when it is legal. For the moment this pass has no
1745 profitability analysis. Returns true when something changed. */
1748 tree_if_conversion (struct loop
*loop
)
1750 bool changed
= false;
1753 if (!if_convertible_loop_p (loop
)
1754 || !dbg_cnt (if_conversion_tree
))
1757 /* Now all statements are if-convertible. Combine all the basic
1758 blocks into one huge basic block doing the if-conversion
1760 combine_blocks (loop
);
1762 if (flag_tree_loop_if_convert_stores
)
1763 mark_virtual_operands_for_renaming (cfun
);
1772 for (i
= 0; i
< loop
->num_nodes
; i
++)
1773 free_bb_predicate (ifc_bbs
[i
]);
1782 /* Tree if-conversion pass management. */
1785 main_tree_if_conversion (void)
1789 bool changed
= false;
1792 if (number_of_loops (cfun
) <= 1)
1795 FOR_EACH_LOOP (li
, loop
, 0)
1796 if (flag_tree_loop_if_convert
== 1
1797 || flag_tree_loop_if_convert_stores
== 1
1798 || flag_tree_loop_vectorize
1799 || loop
->force_vect
)
1800 changed
|= tree_if_conversion (loop
);
1803 todo
|= TODO_cleanup_cfg
;
1805 if (changed
&& flag_tree_loop_if_convert_stores
)
1806 todo
|= TODO_update_ssa_only_virtuals
;
1808 #ifdef ENABLE_CHECKING
1812 gcc_assert (!bb
->aux
);
1819 /* Returns true when the if-conversion pass is enabled. */
1822 gate_tree_if_conversion (void)
1824 return (((flag_tree_loop_vectorize
|| cfun
->has_force_vect_loops
)
1825 && flag_tree_loop_if_convert
!= 0)
1826 || flag_tree_loop_if_convert
== 1
1827 || flag_tree_loop_if_convert_stores
== 1);
1832 const pass_data pass_data_if_conversion
=
1834 GIMPLE_PASS
, /* type */
1836 OPTGROUP_NONE
, /* optinfo_flags */
1837 true, /* has_gate */
1838 true, /* has_execute */
1839 TV_NONE
, /* tv_id */
1840 ( PROP_cfg
| PROP_ssa
), /* properties_required */
1841 0, /* properties_provided */
1842 0, /* properties_destroyed */
1843 0, /* todo_flags_start */
1844 ( TODO_verify_stmts
| TODO_verify_flow
1845 | TODO_verify_ssa
), /* todo_flags_finish */
1848 class pass_if_conversion
: public gimple_opt_pass
1851 pass_if_conversion (gcc::context
*ctxt
)
1852 : gimple_opt_pass (pass_data_if_conversion
, ctxt
)
1855 /* opt_pass methods: */
1856 bool gate () { return gate_tree_if_conversion (); }
1857 unsigned int execute () { return main_tree_if_conversion (); }
1859 }; // class pass_if_conversion
1864 make_pass_if_conversion (gcc::context
*ctxt
)
1866 return new pass_if_conversion (ctxt
);