|
GCC Middle and Back End API Reference
|
#include "config.h"#include "system.h"#include "coretypes.h"#include "backend.h"#include "rtl.h"#include "tree.h"#include "gimple.h"#include "cfghooks.h"#include "tree-pass.h"#include "memmodel.h"#include "tm_p.h"#include "ssa.h"#include "tree-pretty-print.h"#include "fold-const.h"#include "cfganal.h"#include "gimple-iterator.h"#include "gimple-fold.h"#include "gimplify-me.h"#include "tree-cfg.h"#include "tree-ssa.h"#include "tree-ssa-ifcombine.h"#include "attribs.h"#include "asan.h"#include "bitmap.h"#include "cfgloop.h"
Data Structures | |
| struct | ifcombine_mark_ssa_name_t |
Macros | |
| #define | LOGICAL_OP_NON_SHORT_CIRCUIT |
| #define LOGICAL_OP_NON_SHORT_CIRCUIT |
Combining of if-expressions on trees. Copyright (C) 2007-2026 Free Software Foundation, Inc. Contributed by Richard Guenther <rguenther@suse.de> This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>.
rtl is needed only because arm back-end requires it for BRANCH_COST.
|
static |
Return true if BB guards entry to a loop: a successor edge reaches a loop header BB does not belong to, directly or through a single-successor preheader. Combining the scalar conditions guarding a loop into a single boolean leaves the number-of-iterations analysis unable to prove the loop runs at least once, pessimizing later loop passes such as ivopts.
References bb_guards_loop_p(), bb_loop_header_p(), CDI_DOMINATORS, dominated_by_p(), FOR_EACH_EDGE, single_succ(), single_succ_p(), and basic_block_def::succs.
Referenced by bb_guards_loop_p(), and ifcombine_ifandif().
|
static |
Verify if the basic block BB does not have side-effects. Return true in this case, else false.
References bb_no_side_effects_p(), dyn_cast(), FOR_EACH_SSA_TREE_OPERAND, gimple_assign_lhs(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_could_trap_p(), gimple_has_side_effects(), gimple_vdef(), gsi_end_p(), gsi_next(), gsi_start_bb(), gsi_stmt(), integer_minus_onep(), INTEGRAL_TYPE_P, is_a(), is_gimple_call(), is_gimple_debug(), ssa_name_maybe_undef_p(), SSA_OP_USE, TREE_CODE, TREE_TYPE, and TYPE_OVERFLOW_UNDEFINED.
Referenced by bb_no_side_effects_p(), and tree_ssa_ifcombine_bb().
|
static |
Returns true if inner_cond_bb contains just the condition or 1/2 statements that define lhs or rhs with an integer conversion.
References can_combine_bbs_with_short_circuit(), CONVERT_EXPR_CODE_P, gimple_assign_lhs(), gimple_assign_rhs_code(), gsi_next_nondebug(), gsi_one_before_end_p(), gsi_start_nondebug_after_labels_bb(), gsi_stmt(), i, and is_gimple_assign().
Referenced by can_combine_bbs_with_short_circuit(), and ifcombine_ifandif().
|
static |
Return true if BB is an empty forwarder block to TO_BB.
References empty_block_p(), forwarder_block_to(), single_succ(), and single_succ_p().
Referenced by forwarder_block_to(), and tree_ssa_ifcombine_bb().
Return the best representative SSA name for CANDIDATE which is used in a bit test.
References CONVERT_EXPR_CODE_P, get_name_for_bit_test(), gimple_assign_rhs1(), gimple_assign_rhs_code(), has_single_use(), is_gimple_assign(), SSA_NAME_DEF_STMT, TREE_CODE, TREE_TYPE, and TYPE_PRECISION.
Referenced by get_name_for_bit_test(), recognize_bits_test(), and recognize_single_bit_test().
|
static |
If-convert on a and pattern with a common else block. The inner if is specified by its INNER_COND_BB, the outer by OUTER_COND_BB. inner_inv, outer_inv indicate whether the conditions are inverted. Returns true if the edges to the common else basic-block were merged.
References bb_guards_loop_p(), boolean_type_node, build_int_cst(), can_combine_bbs_with_short_circuit(), combine_comparisons(), dump_file, fold_build1, fold_build2, fold_build2_loc(), fold_convert, fold_truth_andor_for_ifcombine(), gimple_bb(), gimple_build(), gimple_cond_code(), gimple_cond_lhs(), gimple_cond_rhs(), gimple_could_trap_p(), gimple_location(), gsi_for_stmt(), gsi_last_bb(), GSI_SAME_STMT, HONOR_NANS(), ifcombine_ifandif(), ifcombine_replace_cond(), invert_tree_comparison(), LOGICAL_OP_NON_SHORT_CIRCUIT, loop_exits_from_bb_p(), basic_block_def::loop_father, maybe_fold_and_comparisons(), NULL_TREE, operand_equal_p(), POINTER_TYPE_P, print_generic_expr(), recognize_bits_test(), recognize_single_bit_test(), safe_dyn_cast(), sanitize_coverage_p(), single_pred(), SSA_NAME_OCCURS_IN_ABNORMAL_PHI, TREE_CODE, TREE_TYPE, TYPE_PRECISION, UNKNOWN_LOCATION, and unsigned_type_for().
Referenced by ifcombine_ifandif(), and tree_ssa_ifcombine_bb_1().
|
static |
Set NAME's bit in USED if OUTER dominates it.
References bitmap_set_bit, CDI_DOMINATORS, dominated_by_p(), gimple_bb(), ifcombine_mark_ssa_name(), SSA_NAME_DEF_STMT, SSA_NAME_IS_DEFAULT_DEF, SSA_NAME_VERSION, and TREE_CODE.
Referenced by ifcombine_mark_ssa_name(), ifcombine_mark_ssa_name_walk(), and ifcombine_replace_cond().
Mark in DATA->used any SSA_NAMEs used in *t.
References ifcombine_mark_ssa_name(), ifcombine_mark_ssa_name_walk(), and NULL.
Referenced by ifcombine_mark_ssa_name_walk(), and ifcombine_replace_cond().
|
static |
Replace the conditions in INNER_COND and OUTER_COND with COND and COND2. COND and COND2 are computed for insertion at INNER_COND, with OUTER_COND replaced with a constant, but if there are intervening blocks, it's best to adjust COND for insertion at OUTER_COND, placing COND2 at INNER_COND.
References a, bitmap_bit_p, bitmap_empty_p(), bitmap_tree_view(), boolean_false_node, boolean_true_node, canonicalize_cond_expr_cond(), dyn_cast(), end(), fold_build1, FOR_EACH_PHI_ARG, FOR_EACH_SSA_TREE_OPERAND, FOR_EACH_VEC_ELT, force_gimple_operand_gsi_1(), gcc_assert, gimple_bb(), gimple_build_assign(), gimple_cond_set_condition_from_tree(), gimple_phi_arg_def(), gimple_phi_arg_location(), gimple_phi_num_args(), gimple_phi_result(), gimple_set_location(), gsi_end_p(), gsi_for_phi(), gsi_for_stmt(), gsi_insert_before(), gsi_last_bb(), gsi_move_before(), GSI_NEW_STMT, gsi_next(), gsi_prev(), GSI_SAME_STMT, gsi_start_bb(), gsi_start_phis(), gsi_stmt(), i, ifcombine_mark_ssa_name(), ifcombine_mark_ssa_name_walk(), ifcombine_replace_cond(), ifcombine_rewrite_to_defined_overflow(), is_gimple_condexpr_for_cond(), NULL, remove_phi_node(), reset_flow_sensitive_info(), reset_flow_sensitive_info_in_bb(), single_pred(), SSA_NAME_VERSION, SSA_OP_DEF, SSA_OP_USE, TREE_CODE, TREE_OPERAND, TREE_TYPE, update_profile_after_ifcombine(), update_stmt(), USE_FROM_PTR, and walk_tree.
Referenced by ifcombine_ifandif(), and ifcombine_replace_cond().
|
inlinestatic |
Rewrite a stmt, that presumably used to be guarded by conditions that could avoid undefined overflow, into one that has well-defined overflow, so that it won't invoke undefined behavior once the guarding conditions change.
References gimple_needing_rewrite_undefined(), gsi_stmt(), ifcombine_rewrite_to_defined_overflow(), and rewrite_to_defined_unconditional().
Referenced by ifcombine_replace_cond(), and ifcombine_rewrite_to_defined_overflow().
|
static |
Return FALSE iff the COND_BB ends with a conditional whose result is not a known constant.
References CONSTANT_CLASS_P, gimple_cond_lhs(), gimple_cond_rhs(), gsi_last_bb(), known_succ_p(), and safe_dyn_cast().
Referenced by known_succ_p(), recognize_if_then_else(), tree_ssa_ifcombine_bb(), and update_profile_after_ifcombine().
| gimple_opt_pass * make_pass_tree_ifcombine | ( | gcc::context * | ctxt | ) |
References make_pass_tree_ifcombine().
Referenced by make_pass_empty_loop(), and make_pass_tree_ifcombine().
Recognize a bit test pattern in a GIMPLE_COND and its defining statements. Store the name being tested in *NAME and the bits in *BITS. The COND_EXPR computes *NAME & *BITS. Returns true if the pattern matched, false otherwise.
References get_name_for_bit_test(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_cond_code(), gimple_cond_lhs(), gimple_cond_rhs(), integer_zerop(), is_gimple_assign(), recognize_bits_test(), SSA_NAME_DEF_STMT, and TREE_CODE.
Referenced by ifcombine_ifandif(), and recognize_bits_test().
| bool recognize_if_then_else | ( | basic_block | cond_bb, |
| basic_block * | then_bb, | ||
| basic_block * | else_bb, | ||
| bool | succs_any = false ) |
This pass combines COND_EXPRs to simplify control flow. It currently recognizes bit tests and comparisons in chains that represent logical and or logical or of two COND_EXPRs. It does so by walking basic blocks in a approximate reverse post-dominator order and trying to match CFG patterns that represent logical and or logical or of two COND_EXPRs. Transformations are done if the COND_EXPR conditions match either 1. two single bit tests X & (1 << Yn) (for logical and) 2. two bit tests X & Yn (for logical or) 3. two comparisons X OPn Y (for logical or) To simplify this pass, removing basic blocks and dead code is left to CFG cleanup and DCE.
Recognize a if-then-else CFG pattern starting to match with the COND_BB basic-block containing the COND_EXPR. If !SUCCS_ANY, the condition must not resolve to a constant for a match. Returns true if the pattern matched, false otherwise. In case of a !SUCCS_ANY match, the recognized then end else blocks are stored to *THEN_BB and *ELSE_BB. If *THEN_BB and/or *ELSE_BB are already set, they are required to match the then and else basic-blocks to make the pattern match. If SUCCS_ANY, *THEN_BB and *ELSE_BB will not be filled in, and they will be found to match even if reversed.
Copyright (C) 2026 Free Software Foundation, Inc. This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>.
References EDGE_COUNT, EDGE_SUCC, known_succ_p(), recognize_if_then_else(), and basic_block_def::succs.
Referenced by apply_clusters(), recognize_if_then_else(), tree_ssa_ifcombine_bb(), and tree_ssa_ifcombine_bb_1().
Recognize a single bit test pattern in GIMPLE_COND and its defining statements. Store the name being tested in *NAME and the bit in *BIT. The GIMPLE_COND computes *NAME & (1 << *BIT). Returns true if the pattern matched, false otherwise.
References build_int_cst(), CONVERT_EXPR_CODE_P, get_name_for_bit_test(), gimple_assign_lhs(), gimple_assign_rhs1(), gimple_assign_rhs2(), gimple_assign_rhs_code(), gimple_assign_ssa_name_copy_p(), gimple_cond_code(), gimple_cond_lhs(), gimple_cond_rhs(), integer_onep(), integer_pow2p(), integer_type_node, integer_zero_node, integer_zerop(), is_gimple_assign(), recognize_single_bit_test(), SSA_NAME_DEF_STMT, TREE_CODE, tree_log2(), TREE_TYPE, and TYPE_PRECISION.
Referenced by ifcombine_ifandif(), and recognize_single_bit_test().
|
static |
Verify if all PHI node arguments in DEST for edges from BB1 or BB2 to DEST are the same. This makes the CFG merge point free from side-effects. Return true in this case, else false.
References find_edge(), gsi_end_p(), gsi_next(), gsi_start_phis(), operand_equal_p(), gphi_iterator::phi(), PHI_ARG_DEF_FROM_EDGE, and same_phi_args_p().
Referenced by same_phi_args_p(), tree_ssa_ifcombine_bb(), and tree_ssa_ifcombine_bb_1().
| bool tree_ssa_ifcombine_bb | ( | basic_block | inner_cond_bb | ) |
Recognize a CFG pattern and dispatch to the appropriate if-conversion helper. We start with BB as the innermost worker basic-block. Returns true if a transformation was done.
References bb_no_side_effects_p(), forwarder_block_to(), known_succ_p(), NULL, recognize_if_then_else(), same_phi_args_p(), single_pred(), single_pred_p(), single_succ_p(), tree_ssa_ifcombine_bb(), and tree_ssa_ifcombine_bb_1().
Referenced by tail_merge_optimize(), and tree_ssa_ifcombine_bb().
|
static |
Helper function for tree_ssa_ifcombine_bb. Recognize a CFG pattern and dispatch to the appropriate if-conversion helper for a particular set of INNER_COND_BB, OUTER_COND_BB, THEN_BB and ELSE_BB. PHI_PRED_BB should be one of INNER_COND_BB, THEN_BB or ELSE_BB. OUTER_SUCC_BB is the successor of OUTER_COND_BB on the path towards INNER_COND_BB.
References ifcombine_ifandif(), recognize_if_then_else(), same_phi_args_p(), and tree_ssa_ifcombine_bb_1().
Referenced by tree_ssa_ifcombine_bb(), and tree_ssa_ifcombine_bb_1().
|
static |
Update profile after code in either outer_cond_bb or inner_cond_bb was adjusted so that it has no condition.
References profile_probability::always(), basic_block_def::count, EDGE_SUCC, profile_probability::even(), find_edge(), gcc_assert, known_succ_p(), profile_probability::never(), single_pred(), single_pred_p(), and update_profile_after_ifcombine().
Referenced by ifcombine_replace_cond(), and update_profile_after_ifcombine().