https://gcc.gnu.org/g:97eff72160946ca89bd548fa2655802361dfa8fb

commit 97eff72160946ca89bd548fa2655802361dfa8fb
Author: Alexandre Oliva <ol...@gnu.org>
Date:   Thu Dec 19 00:19:34 2024 -0300

    add options to control ifcombine

Diff:
---
 gcc/common.opt            | 12 ++++++++++++
 gcc/tree-ssa-ifcombine.cc | 37 +++++++++++++++++++++++++------------
 2 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index 1b72826d44b1..aa5ad7974112 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1241,6 +1241,18 @@ fcode-hoisting
 Common Var(flag_code_hoisting) Optimization
 Enable code hoisting.
 
+fcombine-conditionals
+Common Var(flag_tree_ifcombine) Init(-1) Optimization
+Combine conditionals, with the ifcombine optimization pass.
+
+fcombine-field-conditionals
+Common Var(flag_tree_ifcombine_fieldmerge) Init(-1) Optimization
+Combine conditionals involving separate fields
+
+fcombine-noncontiguous-conditionals
+Common Var(flag_tree_ifcombine_noncontig) Init(-1) Optimization
+Combine conditionals from noncontiguous blocks
+
 fcombine-stack-adjustments
 Common Var(flag_combine_stack_adjustments) Optimization
 Looks for opportunities to reduce stack adjustments and stack references.
diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc
index c9399a106945..108fa5b17dac 100644
--- a/gcc/tree-ssa-ifcombine.cc
+++ b/gcc/tree-ssa-ifcombine.cc
@@ -972,18 +972,19 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool 
inner_inv,
                                            gimple_cond_lhs (outer_cond),
                                            gimple_cond_rhs (outer_cond),
                                            gimple_bb (outer_cond)))
-         && !(t = (fold_truth_andor_for_ifcombine
-                   (TRUTH_ANDIF_EXPR, boolean_type_node,
-                    gimple_location (outer_cond),
-                    outer_cond_code,
-                    gimple_cond_lhs (outer_cond),
-                    gimple_cond_rhs (outer_cond),
-                    gimple_location (inner_cond),
-                    inner_cond_code,
-                    gimple_cond_lhs (inner_cond),
-                    gimple_cond_rhs (inner_cond),
-                    single_pred (inner_cond_bb) != outer_cond_bb
-                    ? &ts : 0))))
+         && !(flag_tree_ifcombine_fieldmerge
+              && (t = (fold_truth_andor_for_ifcombine
+                       (TRUTH_ANDIF_EXPR, boolean_type_node,
+                        gimple_location (outer_cond),
+                        outer_cond_code,
+                        gimple_cond_lhs (outer_cond),
+                        gimple_cond_rhs (outer_cond),
+                        gimple_location (inner_cond),
+                        inner_cond_code,
+                        gimple_cond_lhs (inner_cond),
+                        gimple_cond_rhs (inner_cond),
+                        single_pred (inner_cond_bb) != outer_cond_bb
+                        ? &ts : 0)))))
        {
          /* Only combine conditions in this fallback case if the blocks are
             neighbors.  */
@@ -1255,6 +1256,9 @@ tree_ssa_ifcombine_bb (basic_block inner_cond_bb)
       /* Record the exit path taken by the outer condition.  */
       if (!exit_bb)
        {
+         if (!flag_tree_ifcombine_noncontig)
+           break;
+
          /* If we have removed the outer condition entirely, we need not
             commit to an exit block yet, it's as if we'd merged the blocks and
             were starting afresh.  This is sound as long as we never replace
@@ -1369,6 +1373,15 @@ public:
   {}
 
   /* opt_pass methods: */
+  bool gate (function *) final override {
+    if (!flag_tree_ifcombine)
+      return false;
+
+    if (flag_tree_ifcombine_noncontig == -1)
+      flag_tree_ifcombine_noncontig = (optimize >= 2 || optimize_size);
+
+    return flag_tree_ifcombine;
+  }
   unsigned int execute (function *) final override;
 
 }; // class pass_tree_ifcombine

Reply via email to